Project

General

Profile

« Previous | Next » 

Revision 40ab026e

Added by Leszek Koltunski almost 4 years ago

In library: allow a mixture of a deep and shallow copy of a Mesh ( mVertAttribs1 might be copied deeply or shallowly, mVertAttribs2 are always copied deeeply).
Port RubikCube to the new library.

View differences:

src/main/java/org/distorted/main/RubikRenderer.java
23 23
import android.opengl.GLSurfaceView;
24 24

  
25 25
import org.distorted.effects.BaseEffect;
26
import org.distorted.library.effect.EffectType;
26 27
import org.distorted.library.effect.VertexEffectSink;
27 28
import org.distorted.library.main.DistortedLibrary;
28 29
import org.distorted.library.main.DistortedScreen;
......
73 74
   @Override
74 75
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
75 76
      {
77
      DistortedLibrary.setMax(EffectType.VERTEX,12);
76 78
      VertexEffectSink.enable();
77 79
      BaseEffect.Type.enableEffects();
78 80

  
......
101 103
        else
102 104
          {
103 105
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
104
          crashlytics.setCustomKey("DistortedError", message );
105
          crashlytics.setCustomKey("GLversion"     , version );
106
          crashlytics.setCustomKey("GLSLrenderer"  , renderer);
107 106
          crashlytics.log("DistortedError: " +message );
108 107
          crashlytics.log("GLversion"        +version );
109 108
          crashlytics.log("GLSLrenderer"     +renderer);
src/main/java/org/distorted/objects/Cubit.java
353 353
    else
354 354
      {
355 355
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
356
      crashlytics.setCustomKey("getAngle", "points in RotationAngle: "+pointNum );
357 356
      crashlytics.log("points in RotationAngle: "+pointNum);
358 357
      return 0;
359 358
      }
src/main/java/org/distorted/objects/RubikCube.java
22 22
import android.graphics.Canvas;
23 23
import android.graphics.Paint;
24 24

  
25
import org.distorted.library.effect.MatrixEffect;
26
import org.distorted.library.effect.MatrixEffectMove;
27
import org.distorted.library.effect.MatrixEffectRotate;
25
import org.distorted.library.effect.VertexEffectMove;
26
import org.distorted.library.effect.VertexEffectRotate;
28 27
import org.distorted.library.effect.VertexEffectSink;
29 28
import org.distorted.library.main.DistortedEffects;
30 29
import org.distorted.library.main.DistortedTexture;
......
76 75
          -0.5f*((float)Math.sqrt(2))
77 76
         };
78 77

  
78
  private static MeshBase mMesh = null;
79

  
79 80
///////////////////////////////////////////////////////////////////////////////////////////////////
80 81

  
81 82
  RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects, int[][] moves)
......
162 163

  
163 164
  MeshBase createCubitMesh(int cubit, int vertices)
164 165
    {
165
    final int MESHES=6;
166
    if( mMesh==null )
167
      {
168
      final int MESHES=6;
169
      int association = 1;
170
      MeshBase[] meshes = new MeshRectangles[MESHES];
171
      meshes[0] = new MeshRectangles(vertices,vertices);
172
      meshes[0].setEffectAssociation(0,association);
166 173

  
167
    Static3D axisY  = new Static3D(0,1,0);
168
    Static3D axisX  = new Static3D(1,0,0);
169
    Static3D center = new Static3D(0,0,0);
170
    Static1D angle  = new Static1D(0);
171

  
172
    MatrixEffect[] effectsY = new MatrixEffect[2];
173
    effectsY[0] = new MatrixEffectMove(new Static3D(0,0,+0.5f));
174
    effectsY[1] = new MatrixEffectRotate( angle, axisY, center );
175

  
176
    MeshBase[] meshes = new MeshRectangles[MESHES];
177
    for(int i=0; i<MESHES; i++) meshes[i] = new MeshRectangles(vertices,vertices);
178

  
179
    angle.set(0);
180
    meshes[4].apply(effectsY);  // front
181
    angle.set(90);
182
    meshes[0].apply(effectsY);  // right
183
    angle.set(180);
184
    meshes[5].apply(effectsY);  // back
185
    angle.set(270);
186
    meshes[1].apply(effectsY);  // left
187

  
188
    MatrixEffect[] effectsX = new MatrixEffect[2];
189
    effectsX[0] = new MatrixEffectMove(new Static3D(0,0,+0.5f));
190
    effectsX[1] = new MatrixEffectRotate( angle, axisX, center );
191

  
192
    angle.set( 90);
193
    meshes[3].apply(effectsX);  // bottom
194
    angle.set(-90);
195
    meshes[2].apply(effectsX);  // top
196

  
197
    return new MeshJoined(meshes);
174
      for(int i=1; i<MESHES; i++)
175
        {
176
        association <<=1;
177
        meshes[i] = meshes[0].copy(true);
178
        meshes[i].setEffectAssociation(0,association);
179
        }
180

  
181
      mMesh = new MeshJoined(meshes);
182

  
183
      Static3D axisY   = new Static3D(0,1,0);
184
      Static3D axisX   = new Static3D(1,0,0);
185
      Static3D center  = new Static3D(0,0,0);
186
      Static1D angle90 = new Static1D(90);
187
      Static1D angle180= new Static1D(180);
188
      Static1D angle270= new Static1D(270);
189

  
190
      VertexEffectMove   effect0 = new VertexEffectMove(new Static3D(0,0,+0.5f));
191
      effect0.setMeshAssociation(63);  // all 6 sides
192
      VertexEffectRotate effect1 = new VertexEffectRotate( angle180, axisX, center );
193
      effect1.setMeshAssociation(32);  // back
194
      VertexEffectRotate effect2 = new VertexEffectRotate( angle90 , axisX, center );
195
      effect2.setMeshAssociation(8);  // bottom
196
      VertexEffectRotate effect3 = new VertexEffectRotate( angle270, axisX, center );
197
      effect3.setMeshAssociation(4);  // top
198
      VertexEffectRotate effect4 = new VertexEffectRotate( angle270, axisY, center );
199
      effect4.setMeshAssociation(2);  // left
200
      VertexEffectRotate effect5 = new VertexEffectRotate( angle90 , axisY, center );
201
      effect5.setMeshAssociation(1);  // right
202

  
203
      mMesh.apply(effect0);
204
      mMesh.apply(effect1);
205
      mMesh.apply(effect2);
206
      mMesh.apply(effect3);
207
      mMesh.apply(effect4);
208
      mMesh.apply(effect5);
209
      }
210

  
211
    return mMesh.copy(false);
198 212
    }
199 213

  
200 214
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/RubikPyraminx.java
22 22
import android.graphics.Canvas;
23 23
import android.graphics.Paint;
24 24

  
25
import org.distorted.library.effect.MatrixEffect;
26
import org.distorted.library.effect.MatrixEffectMove;
27
import org.distorted.library.effect.MatrixEffectRotate;
28
import org.distorted.library.effect.MatrixEffectScale;
25
import org.distorted.library.effect.VertexEffectDeform;
26
import org.distorted.library.effect.VertexEffectMove;
27
import org.distorted.library.effect.VertexEffectRotate;
28
import org.distorted.library.effect.VertexEffectScale;
29 29
import org.distorted.library.effect.VertexEffectSink;
30 30
import org.distorted.library.main.DistortedEffects;
31 31
import org.distorted.library.main.DistortedTexture;
......
66 66
         };
67 67

  
68 68
  private int[] mRotArray;
69
  private static MatrixEffectRotate[][] ROTATION;
69
  private static VertexEffectRotate[] ROTATION;
70

  
71
  private static MeshBase mMesh =null;
72
  private static MeshBase[] mMeshRotated = new MeshBase[AXIS.length];
70 73

  
71 74
  static
72 75
    {
73 76
    Static3D center = new Static3D(0,0,0);
74 77
    Static1D angle  = new Static1D(180.0f);
75 78

  
76
    ROTATION = new MatrixEffectRotate[AXIS.length][1];
79
    ROTATION = new VertexEffectRotate[AXIS.length];
77 80

  
78 81
    for(int i=0; i<AXIS.length; i++)
79 82
      {
80
      ROTATION[i][0] = new MatrixEffectRotate( angle, AXIS[i], center);
83
      ROTATION[i] = new VertexEffectRotate( angle, AXIS[i], center);
84
      mMeshRotated[i] = null;
81 85
      }
82 86
    }
83 87

  
......
210 214

  
211 215
///////////////////////////////////////////////////////////////////////////////////////////////////
212 216

  
213
  MeshBase createCubitMesh(int cubit, int vertices)
217
  private MeshBase createStaticMesh(int cubit, int vertices)
214 218
    {
219
    final float SQ2 = (float)Math.sqrt(2);
220
    final float SQ3 = (float)Math.sqrt(3);
215 221
    final float angleFaces = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
216 222
    final int MESHES=4;
217 223

  
224
    int association = 1;
218 225
    MeshBase[] meshes = new MeshTriangles[MESHES];
219
    for(int i=0; i<MESHES; i++) meshes[i] = new MeshTriangles(5);
220

  
221
    MatrixEffect[] effects0 = new MatrixEffect[3];
222
    effects0[0] = new MatrixEffectScale( new Static3D(1,SQ3/2,1) );
223
    effects0[1] = new MatrixEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
224
    effects0[2] = new MatrixEffectMove( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
225

  
226
    meshes[0].apply(effects0);
227

  
228
    Static1D angle = new Static1D(angleFaces);
229
    Static3D axis  = new Static3D(-1,0,0);
230
    Static3D center= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
231 226

  
232
    MatrixEffect[] effects1 = new MatrixEffect[5];
233
    effects1[0] = effects0[0];
234
    effects1[1] = effects0[1];
235
    effects1[2] = effects0[2];
236
    effects1[3] = new MatrixEffectRotate( new Static1D(180), new Static3D(0,0,1), center );
237
    effects1[4] = new MatrixEffectRotate( angle, axis, center );
238
    meshes[1].apply(effects1);
227
    meshes[0] = new MeshTriangles(5);
228
    meshes[0].setEffectAssociation(0,association);
239 229

  
240
    axis.set(0.5f,0,-SQ3/2);
241
    center.set2(SQ3/3);
242
    meshes[2].apply(effects1);
243

  
244
    axis.set2(SQ3/2);
245
    meshes[3].apply(effects1);
230
    for(int i=1; i<MESHES; i++)
231
      {
232
      association <<= 1;
233
      meshes[i] = meshes[0].copy(true);
234
      meshes[i].setEffectAssociation(0,association);
235
      }
246 236

  
247
    MeshJoined result = new MeshJoined(meshes);
237
    Static4D[] textureMaps = new Static4D[MESHES];
238
    for(int i=0; i<MESHES; i++) textureMaps[i] = new Static4D(i*0.25f,0.0f,0.25f,1.0f);
239
    MeshBase result = new MeshJoined(meshes);
240
    result.setTextureMap(textureMaps);
241

  
242
    Static3D a0 = new Static3D(         0,        1,       0 );
243
    Static3D a1 = new Static3D(         0,  -1.0f/3, 2*SQ2/3 );
244
    Static3D a2 = new Static3D(-SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
245
    Static3D a3 = new Static3D( SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
246

  
247
    float tetraHeight = SQ2*SQ3/3;
248
    float d1 = 0.75f*tetraHeight;
249
    float d2 =-0.10f*tetraHeight;
250
    float d3 = 0.20f*tetraHeight;
251

  
252
    Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
253
    Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
254
    Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
255
    Static3D dCen3 = new Static3D( d1*a3.get0(), d1*a3.get1(), d1*a3.get2() );
256

  
257
    Static3D dVec0 = new Static3D( d2*a0.get0(), d2*a0.get1(), d2*a0.get2() );
258
    Static3D dVec1 = new Static3D( d2*a1.get0(), d2*a1.get1(), d2*a1.get2() );
259
    Static3D dVec2 = new Static3D( d2*a2.get0(), d2*a2.get1(), d2*a2.get2() );
260
    Static3D dVec3 = new Static3D( d2*a3.get0(), d2*a3.get1(), d2*a3.get2() );
261

  
262
    Static4D dReg  = new Static4D(0,0,0,d3);
263
    Static1D dRad  = new Static1D(1);
264

  
265
    Static1D angle  = new Static1D(angleFaces);
266
    Static3D axis1  = new Static3D(  -1, 0,      0);
267
    Static3D axis2  = new Static3D(0.5f, 0, -SQ3/2);
268
    Static3D axis3  = new Static3D(0.5f, 0, +SQ3/2);
269
    Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
270
    Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
271

  
272
    VertexEffectScale effect1 = new VertexEffectScale ( new Static3D(1,SQ3/2,1) );
273
    VertexEffectRotate  effect2 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
274
    VertexEffectMove effect3 = new VertexEffectMove  ( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
275
    VertexEffectRotate  effect4 = new VertexEffectRotate( new Static1D(180), new Static3D(0,0,1), center1 );
276
    VertexEffectRotate  effect5 = new VertexEffectRotate( angle, axis1, center1 );
277
    VertexEffectRotate  effect6 = new VertexEffectRotate( angle, axis2, center2 );
278
    VertexEffectRotate  effect7 = new VertexEffectRotate( angle, axis3, center2 );
279

  
280
    VertexEffectDeform effect8 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
281
    VertexEffectDeform effect9 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
282
    VertexEffectDeform effect10= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
283
    VertexEffectDeform effect11= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
284

  
285
    effect1.setMeshAssociation(15);  // apply to all 4 meshes
286
    effect2.setMeshAssociation(15);  // apply to all 4 meshes
287
    effect3.setMeshAssociation(15);  // apply to all 4 meshes
288
    effect4.setMeshAssociation(14);  // apply to mesh[1], [2] and [3]
289
    effect5.setMeshAssociation( 2);  // apply only to mesh[1]
290
    effect6.setMeshAssociation( 4);  // apply only to mesh[2]
291
    effect7.setMeshAssociation( 8);  // apply only to mesh[3]
292
    effect8.setMeshAssociation(15);  // apply to all 4 meshes
293
    effect9.setMeshAssociation(15);  // apply to all 4 meshes
294
    effect10.setMeshAssociation(15); // apply to all 4 meshes
295
    effect11.setMeshAssociation(15); // apply to all 4 meshes
296

  
297
    result.apply(effect1);
298
    result.apply(effect2);
299
    result.apply(effect3);
300
    result.apply(effect4);
301
    result.apply(effect5);
302
    result.apply(effect6);
303
    result.apply(effect7);
304
    result.apply(effect8);
305
    result.apply(effect9);
306
    result.apply(effect10);
307
    result.apply(effect11);
248 308

  
249 309
    if( mRotArray[cubit]>=0 )
250 310
      {
......
254 314
    return result;
255 315
    }
256 316

  
317
///////////////////////////////////////////////////////////////////////////////////////////////////
318

  
319
  MeshBase createCubitMesh(int cubit, int vertices)
320
    {
321
    int kind = mRotArray[cubit];
322

  
323
    if( kind>=0 )
324
      {
325
      if( mMeshRotated[kind]==null ) mMeshRotated[kind] = createStaticMesh(cubit,vertices);
326
      return mMeshRotated[kind].copy(false);
327
      }
328
    else
329
      {
330
      if( mMesh==null ) mMesh = createStaticMesh(cubit,vertices);
331
      return mMesh.copy(false);
332
      }
333
    }
334

  
257 335
///////////////////////////////////////////////////////////////////////////////////////////////////
258 336

  
259 337
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side)

Also available in: Unified diff