Project

General

Profile

Download (5.64 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorRenderer.java @ 77efd5ad

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.bandaged;
21

    
22
import javax.microedition.khronos.egl.EGLConfig;
23
import javax.microedition.khronos.opengles.GL10;
24

    
25
import android.opengl.GLSurfaceView;
26

    
27
import org.distorted.library.main.DistortedLibrary;
28
import org.distorted.library.main.DistortedNode;
29
import org.distorted.library.main.DistortedScreen;
30

    
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
37
{
38
   private final GLSurfaceView mView;
39
   private final DistortedScreen mScreen;
40
   private final Static3D mScale;
41

    
42
   private final float[][] POSITIONS = new float[][]
43
        {
44
          {-1.0f, +1.0f, +1.0f},
45
          {-1.0f, +1.0f, +0.0f},
46
          {-1.0f, +1.0f, -1.0f},
47
          {-1.0f,  0.0f, +1.0f},
48
          {-1.0f,  0.0f, +0.0f},
49
          {-1.0f,  0.0f, -1.0f},
50
          {-1.0f, -1.0f, +1.0f},
51
          {-1.0f, -1.0f, +0.0f},
52
          {-1.0f, -1.0f, -1.0f},
53
          { 0.0f, -1.0f, +1.0f},
54
          { 0.0f, -1.0f, +0.0f},
55
          { 0.0f, +1.0f, +1.0f},
56
          { 0.0f, +1.0f, +0.0f},
57
          { 0.0f, +1.0f, -1.0f},
58
          { 0.0f,  0.0f, +1.0f},
59
          { 0.0f,  0.0f, -1.0f},
60
          { 1.0f, +1.0f, +1.0f},
61
          { 1.0f, +1.0f, +0.0f},
62
          { 1.0f, +1.0f, -1.0f},
63
          { 1.0f,  0.0f, +1.0f},
64
          { 1.0f,  0.0f, +0.0f},
65
          { 1.0f, -1.0f, +1.0f},
66
          { 1.0f,  0.0f, -1.0f },
67
          { 1.0f, -1.0f, -1.0f },
68
          { 1.0f, -1.0f, +0.0f },
69
          { 0.0f, -1.0f, -1.0f },
70
        };
71

    
72
   Static4D mQuat1, mQuat2;
73
   int mScreenMin;
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
   BandagedCreatorRenderer(BandagedCreatorView v)
78
     {
79
     final float BRIGHTNESS = 0.333f;
80

    
81
     mQuat1 = new Static4D(0,0,0,1);
82
     mQuat2 = new Static4D(0,0,0,1);
83

    
84
     mView = v;
85

    
86
     mScreen = new DistortedScreen();
87
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
88
     mScale= new Static3D(1,1,1);
89

    
90
     BandagedCubit cubit = new BandagedCubit(POSITIONS[0], mQuat1, mQuat2, mScale);
91
     DistortedNode node = cubit.getNode();
92
     mScreen.attach(node);
93
     }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
/*
97
   private BandagedCubit[] createCubits()
98
     {
99
     int len = POSITIONS.length;
100
     BandagedCubit[] cubits = new BandagedCubit[len];
101

    
102
     for(int c=0; c<len; c++)
103
       {
104
       cubits[c] = new BandagedCubit(POSITIONS[c],mQuat1,mQuat2,mScale);
105
       DistortedNode node = cubits[c].getNode();
106
       mScreen.attach(node);
107
       }
108

    
109
     return cubits;
110
     }
111
*/
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
   @Override
115
   public void onDrawFrame(GL10 glUnused)
116
     {
117
     long time = System.currentTimeMillis();
118
     mScreen.render(time);
119
     }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
   @Override
124
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
125
      {
126
      final float Q = 0.3f;
127

    
128
      if( width<height ) mScale.set( Q*width,   Q*width, 1 );
129
      else               mScale.set( Q*height, Q*height, 1 );
130

    
131
      mScreenMin = Math.min(width, height);
132
      mScreen.resize(width,height);
133
      }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
   @Override
138
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
139
      {
140
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
141
      }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
   public void distortedException(Exception ex)
146
     {
147
     android.util.Log.e("CREATOR", "unexpected exception: "+ex.getMessage() );
148
     }
149
}
(2-2/10)