Project

General

Profile

« Previous | Next » 

Revision 94cc96ff

Added by Leszek Koltunski about 5 years ago

Improve the Rubik App.

View differences:

src/main/java/org/distorted/examples/rubik/RubikRenderer.java
29 29
import org.distorted.library.effect.MatrixEffectQuaternion;
30 30
import org.distorted.library.effect.MatrixEffectScale;
31 31
import org.distorted.library.effect.PostprocessEffectGlow;
32
import org.distorted.library.effect.VertexEffectSink;
32 33
import org.distorted.library.main.Distorted;
33 34
import org.distorted.library.main.DistortedEffects;
34 35
import org.distorted.library.main.DistortedScreen;
......
45 46

  
46 47
class RubikRenderer implements GLSurfaceView.Renderer
47 48
{
48
            static final int NUM_CUBES = 3;
49
    private static final int VERTICES  = 5;
49
            static final int NUM_CUBES =   6;
50
    private static final int VERTICES  =  10;
50 51
    private static final int SIZE      = 200;
51 52

  
52 53
    private static final float CUBE_SCREEN_RATIO = 0.5f;
......
64 65
    private Static1D mGlowRadius;
65 66
    private Static4D mGlowColor;
66 67

  
67
    Static4D mQuatCurrent, mQuatAccumulated;
68
    private Static4D mQuatCurrent, mQuatAccumulated;
69
    private Static4D mTempCurrent, mTempAccumulated;
68 70
    int mScreenMin;
69 71

  
70 72
///////////////////////////////////////////////////////////////////////////////////////////////////
......
76 78
      mScreen = new DistortedScreen();
77 79
      mScreen.setProjection(90.0f, 0.1f);
78 80

  
79
      mQuatCurrent     = new Static4D(           0,         0,           0,          1);  // unity quaternion
80
      mQuatAccumulated = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);  // something semi-random that looks good
81
      mTempCurrent     = new Static4D(0,0,0,1);
82
      mTempAccumulated = initializeQuat();
83
      mQuatCurrent     = new Static4D(0,0,0,1);
84
      mQuatAccumulated = initializeQuat();
81 85

  
82 86
      mCubes = new MeshCubes[NUM_CUBES][NUM_CUBES][NUM_CUBES];
83 87
      mEffects = new DistortedEffects[NUM_CUBES][NUM_CUBES][NUM_CUBES];
84 88
      Static3D[][][] cubeVectors = new Static3D[NUM_CUBES][NUM_CUBES][NUM_CUBES];
85 89

  
90
      VertexEffectSink sink = new VertexEffectSink( new Static1D(3.0f),
91
                                                    new Static3D(SIZE*0.5f, SIZE*0.5f, SIZE*0.5f),
92
                                                    new Static4D(0,0,0, SIZE*0.72f) );
86 93
      mMove  = new Static3D(0,0,0);
87 94
      mScale = new Static3D(1,1,1);
88 95
      mCenter= new Static3D(0,0,0);
......
123 130
        for(int y = 0; y< NUM_CUBES; y++)
124 131
          for(int z = 0; z< NUM_CUBES; z++)
125 132
            {
126
            tmpLeft  = (x==          0 ? mapLeft  :mapBlack);
133
            tmpLeft  = (x==            0 ? mapLeft  :mapBlack);
127 134
            tmpRight = (x== NUM_CUBES -1 ? mapRight :mapBlack);
128 135
            tmpFront = (z== NUM_CUBES -1 ? mapFront :mapBlack);
129
            tmpBack  = (z==          0 ? mapBack  :mapBlack);
136
            tmpBack  = (z==            0 ? mapBack  :mapBlack);
130 137
            tmpTop   = (y== NUM_CUBES -1 ? mapTop   :mapBlack);
131
            tmpBottom= (y==          0 ? mapBottom:mapBlack);
138
            tmpBottom= (y==            0 ? mapBottom:mapBlack);
132 139

  
133 140
            mCubes[x][y][z] = new MeshCubes(VERTICES,VERTICES,VERTICES, tmpFront, tmpBack, tmpLeft, tmpRight, tmpTop, tmpBottom);
134 141

  
......
136 143

  
137 144
            mEffects[x][y][z] = new DistortedEffects();
138 145

  
146
            mEffects[x][y][z].apply(sink);
139 147
            mEffects[x][y][z].apply(move);
140 148
            mEffects[x][y][z].apply(scale);
141 149
            mEffects[x][y][z].apply(quat1);
......
149 157
    public void onDrawFrame(GL10 glUnused) 
150 158
      {
151 159
      mScreen.render( System.currentTimeMillis() );
160

  
161
      mQuatCurrent.set(mTempCurrent);
162
      mQuatAccumulated.set(mTempAccumulated);
152 163
      }
153 164

  
154 165
///////////////////////////////////////////////////////////////////////////////////////////////////
......
224 235
             mScreen.attach(mTexture,mEffects[x][y][z],mCubes[x][y][z]);
225 236

  
226 237
      PostprocessEffectGlow.enable();
238
      VertexEffectSink.enable();
227 239

  
228 240
      try
229 241
        {
......
290 302

  
291 303
      mEffects[mLastCol][mLastRow][mLastSli].apply(new PostprocessEffectGlow(mGlowRadius,mGlowColor));
292 304
      }
305

  
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307
// Initial rotation of the cube. Something semi-random that looks good.
308

  
309
    Static4D initializeQuat()
310
      {
311
      return new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
312
      }
313

  
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315

  
316
    void setQuatCurrent(Static4D current)
317
      {
318
      mTempCurrent.set(current);
319
      }
320

  
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322

  
323
    void setQuatAccumulated(Static4D accumulated)
324
      {
325
      mTempAccumulated.set(accumulated);
326
      }
293 327
}

Also available in: Unified diff