Project

General

Profile

« Previous | Next » 

Revision 8f53e513

Added by Leszek Koltunski almost 4 years ago

Progress with the Dino.

View differences:

src/main/java/org/distorted/objects/RubikCube.java
152 152
    return FACE_COLORS.length;
153 153
    }
154 154

  
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

  
157
  int getNumCubitFaces()
158
    {
159
    return FACE_COLORS.length;
160
    }
161

  
155 162
///////////////////////////////////////////////////////////////////////////////////////////////////
156 163

  
157 164
  float getScreenRatio()
src/main/java/org/distorted/objects/RubikDino.java
23 23
import android.graphics.Canvas;
24 24
import android.graphics.Paint;
25 25

  
26
import org.distorted.library.effect.MatrixEffectMove;
27
import org.distorted.library.effect.MatrixEffectQuaternion;
28
import org.distorted.library.effect.MatrixEffectRotate;
29
import org.distorted.library.effect.MatrixEffectScale;
30
import org.distorted.library.effect.VertexEffectDeform;
31
import org.distorted.library.effect.VertexEffectMove;
32
import org.distorted.library.effect.VertexEffectRotate;
33
import org.distorted.library.effect.VertexEffectScale;
34
import org.distorted.library.effect.VertexEffectSink;
26 35
import org.distorted.library.main.DistortedEffects;
27 36
import org.distorted.library.main.DistortedTexture;
28 37
import org.distorted.library.mesh.MeshBase;
38
import org.distorted.library.mesh.MeshJoined;
29 39
import org.distorted.library.mesh.MeshRectangles;
40
import org.distorted.library.mesh.MeshTriangles;
41
import org.distorted.library.type.Static1D;
30 42
import org.distorted.library.type.Static3D;
31 43
import org.distorted.library.type.Static4D;
32 44

  
......
34 46

  
35 47
public class RubikDino extends RubikObject
36 48
{
37
  static final float SQ3 = (float)Math.sqrt(3);
49
  private static final float SQ2 = (float)Math.sqrt(2);
50
  private static final float SQ3 = (float)Math.sqrt(3);
51
  private static final float ANGLE_FACES = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
38 52

  
39 53
  // the four rotation axis of a RubikDino. Must be normalized.
40 54
  static final Static3D[] AXIS = new Static3D[]
......
47 61

  
48 62
  private static final int[] FACE_COLORS = new int[]
49 63
         {
50
           0xffffff00, 0xffffffff,   // AXIS[0]right (right-YELLOW) AXIS[0]left (left  -WHITE)
51
           0xff0000ff, 0xff00ff00,   // AXIS[1]right (top  -BLUE  ) AXIS[1]left (bottom-GREEN)
52
           0xffff0000, 0xffb5651d    // AXIS[2]right (front-RED   ) AXIS[2]left (back  -BROWN)
64
           0xffffff00, 0xffffffff,   // (right-YELLOW) (left  -WHITE)
65
           0xff0000ff, 0xff00ff00,   // (top  -BLUE  ) (bottom-GREEN)
66
           0xffff0000, 0xffb5651d    // (front-RED   ) (back  -BROWN)
53 67
         };
54 68

  
55 69
  // All legal rotation quats of a RubikDino
56 70
  private static final Static4D[] QUATS = new Static4D[]
57 71
         {
58 72
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
73
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
74
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
75
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
59 76
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
60
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
61
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
62
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
63 77
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
78
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
64 79
           new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
80
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
65 81
           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
66
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f ),
67
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
68
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
69
           new Static4D(  0.0f, -1.0f,  0.0f,  0.0f )
82
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
83
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
70 84
         };
71 85

  
72
  private static MeshBase[] mMeshes;
86
  // centers of the 12 edges. Must be in the same order like QUATs above.
87
  private static final Static3D[] CENTERS = new Static3D[]
88
         {
89
           new Static3D( 0.0f, 0.5f, 0.5f ),
90
           new Static3D( 0.0f,-0.5f, 0.5f ),
91
           new Static3D( 0.0f, 0.5f,-0.5f ),
92
           new Static3D( 0.0f,-0.5f,-0.5f ),
93
           new Static3D( 0.5f, 0.5f, 0.0f ),
94
           new Static3D( 0.5f, 0.0f, 0.5f ),
95
           new Static3D(-0.5f, 0.0f,-0.5f ),
96
           new Static3D( 0.5f,-0.5f, 0.0f ),
97
           new Static3D( 0.5f, 0.0f,-0.5f ),
98
           new Static3D(-0.5f,-0.5f, 0.0f ),
99
           new Static3D(-0.5f, 0.5f, 0.0f ),
100
           new Static3D(-0.5f, 0.0f, 0.5f )
101
         };
102

  
103
  private static MeshBase mMesh;
73 104

  
74 105
///////////////////////////////////////////////////////////////////////////////////////////////////
75 106

  
......
79 110
    super(size, 60, quat, texture, mesh, effects, moves, RubikObjectList.DINO, res, scrWidth);
80 111
    }
81 112

  
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

  
115
  private MeshBase createTetrahedronMesh()
116
    {
117
    final float SQ2 = (float)Math.sqrt(2);
118
    final float SQ3 = (float)Math.sqrt(3);
119
    final int MESHES=4;
120

  
121
    int association = 1;
122
    MeshBase[] meshes = new MeshTriangles[MESHES];
123

  
124
    meshes[0] = new MeshTriangles(9);
125
    meshes[0].setEffectAssociation(0,association,0);
126

  
127
    for(int i=1; i<MESHES; i++)
128
      {
129
      association <<= 1;
130
      meshes[i] = meshes[0].copy(true);
131
      meshes[i].setEffectAssociation(0,association,0);
132
      }
133

  
134
    MeshBase result = new MeshJoined(meshes);
135

  
136
    Static3D a0 = new Static3D(         0,        1,       0 );
137
    Static3D a1 = new Static3D(         0,  -1.0f/3, 2*SQ2/3 );
138
    Static3D a2 = new Static3D(-SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
139
    Static3D a3 = new Static3D( SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
140

  
141
    float tetraHeight = SQ2*SQ3/3;
142
    float d1 = 0.75f*tetraHeight;
143
    float d2 =-0.10f*tetraHeight;
144
    float d3 = 0.20f*tetraHeight;
145

  
146
    Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
147
    Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
148
    Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
149
    Static3D dCen3 = new Static3D( d1*a3.get0(), d1*a3.get1(), d1*a3.get2() );
150

  
151
    Static3D dVec0 = new Static3D( d2*a0.get0(), d2*a0.get1(), d2*a0.get2() );
152
    Static3D dVec1 = new Static3D( d2*a1.get0(), d2*a1.get1(), d2*a1.get2() );
153
    Static3D dVec2 = new Static3D( d2*a2.get0(), d2*a2.get1(), d2*a2.get2() );
154
    Static3D dVec3 = new Static3D( d2*a3.get0(), d2*a3.get1(), d2*a3.get2() );
155

  
156
    Static4D dReg  = new Static4D(0,0,0,d3);
157
    Static1D dRad  = new Static1D(1);
158

  
159
    Static1D angle  = new Static1D(ANGLE_FACES);
160
    Static3D axis1  = new Static3D(  -1, 0,      0);
161
    Static3D axis2  = new Static3D(0.5f, 0, -SQ3/2);
162
    Static3D axis3  = new Static3D(0.5f, 0, +SQ3/2);
163
    Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
164
    Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
165

  
166
    Static3D center = new Static3D(0,0,0);
167
    Static4D region = new Static4D(0,0,0,0.6f);
168

  
169
    VertexEffectScale   effect1 = new VertexEffectScale ( new Static3D(1,SQ3/2,1) );
170
    VertexEffectRotate  effect2 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
171
    VertexEffectMove    effect3 = new VertexEffectMove  ( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
172
    VertexEffectRotate  effect4 = new VertexEffectRotate( new Static1D(180), new Static3D(0,0,1), center1 );
173
    VertexEffectRotate  effect5 = new VertexEffectRotate( angle, axis1, center1 );
174
    VertexEffectRotate  effect6 = new VertexEffectRotate( angle, axis2, center2 );
175
    VertexEffectRotate  effect7 = new VertexEffectRotate( angle, axis3, center2 );
176

  
177
    VertexEffectDeform  effect8 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
178
    VertexEffectDeform  effect9 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
179
    VertexEffectDeform  effect10= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
180
    VertexEffectDeform  effect11= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
181

  
182
    VertexEffectSink effect12= new VertexEffectSink( new Static1D(1.3f), center, region );
183

  
184
    effect4.setMeshAssociation(14,-1);  // apply to mesh[1], [2] and [3]
185
    effect5.setMeshAssociation( 2,-1);  // apply only to mesh[1]
186
    effect6.setMeshAssociation( 4,-1);  // apply only to mesh[2]
187
    effect7.setMeshAssociation( 8,-1);  // apply only to mesh[3]
188

  
189
    result.apply(effect1);
190
    result.apply(effect2);
191
    result.apply(effect3);
192
    result.apply(effect4);
193
    result.apply(effect5);
194
    result.apply(effect6);
195
    result.apply(effect7);
196
    result.apply(effect8);
197
    result.apply(effect9);
198
    result.apply(effect10);
199
    result.apply(effect11);
200
    result.apply(effect12);
201

  
202
    result.mergeEffComponents();
203

  
204
    return result;
205
    }
206

  
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

  
209
  private void createBasicMesh()
210
    {
211
    mMesh = createTetrahedronMesh();
212

  
213
    Static3D axis = new Static3D(1,0,0);
214
    Static3D cent = new Static3D(0,0,0);
215

  
216
    MatrixEffectMove   moveEffect = new MatrixEffectMove  ( new Static3D(0.0f,SQ3*SQ2/12,SQ3/6) );
217
    MatrixEffectRotate rot1Effect = new MatrixEffectRotate( new Static1D(180+ANGLE_FACES/2), axis, cent);
218
    MatrixEffectScale  scalEffect = new MatrixEffectScale ( new Static3D(1.0f, SQ2/2, SQ2*SQ3/6) );
219
    MatrixEffectRotate rot2Effect = new MatrixEffectRotate( new Static1D(-45), axis, cent);
220

  
221
    mMesh.apply(moveEffect,0xffffffff,0);
222
    mMesh.apply(rot1Effect,0xffffffff,0);
223
    mMesh.apply(scalEffect,0xffffffff,0);
224
    mMesh.apply(rot2Effect,0xffffffff,0);
225
    }
226

  
82 227
///////////////////////////////////////////////////////////////////////////////////////////////////
83 228

  
84 229
  float getScreenRatio()
85 230
    {
86
    return 0.5f;
231
    return 1.0f;
87 232
    }
88 233

  
89 234
///////////////////////////////////////////////////////////////////////////////////////////////////
......
102 247

  
103 248
///////////////////////////////////////////////////////////////////////////////////////////////////
104 249

  
105
  Static3D[] getCubitPositions(int size)
250
  int getNumCubitFaces()
106 251
    {
107
    // TODO
252
    return 4;
253
    }
254

  
255
///////////////////////////////////////////////////////////////////////////////////////////////////
108 256

  
109
    return null;
257
  Static3D[] getCubitPositions(int size)
258
    {
259
    return CENTERS;
110 260
    }
111 261

  
112 262
///////////////////////////////////////////////////////////////////////////////////////////////////
113 263

  
114 264
  MeshBase createCubitMesh(int cubit)
115 265
    {
116
    // TODO
266
    if( mMesh==null ) createBasicMesh();
267

  
268
    MeshBase mesh = mMesh.copy(true);
269
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[cubit], new Static3D(0,0,0) );
270
    mesh.apply(quat,0xffffffff,0);
117 271

  
118
    return null;
272
    return mesh;
119 273
    }
120 274

  
121 275
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/RubikObject.java
58 58
  private static final float MAX_SIZE_CHANGE = 1.3f;
59 59
  private static final float MIN_SIZE_CHANGE = 0.8f;
60 60

  
61
  private static boolean mCreateFromDMesh = true;
61
  private static boolean mCreateFromDMesh = false;
62 62

  
63 63
  private static final Static3D CENTER = new Static3D(0,0,0);
64 64
  static final int INTERIOR_COLOR = 0xff000000;
......
68 68
  final Static3D[] ROTATION_AXIS;
69 69
  final Static4D[] QUATS;
70 70
  final int NUM_FACES;
71
  final int NUM_CUBIT_FACES;
71 72

  
72 73
  private static float mInitScreenRatio,mObjectScreenRatio;
73 74

  
......
116 117
    mObjectScreenRatio = getScreenRatio();
117 118
    mInitScreenRatio = mObjectScreenRatio;
118 119
    NUM_FACES = getNumFaces();
120
    NUM_CUBIT_FACES = getNumCubitFaces();
119 121

  
120 122
    mSize = size;
121 123
    computeStartAndStep(mOrigPos);
......
494 496

  
495 497
    for(int cubit=0; cubit<NUM_CUBITS; cubit++)
496 498
      {
497
      final Static4D[] maps = new Static4D[NUM_FACES];
499
      final Static4D[] maps = new Static4D[NUM_CUBIT_FACES];
498 500

  
499 501
      if( 2*ROTATION_AXIS.length == NUM_FACES )  // i.e. there are faces on both ends of the axis (cube)
500 502
        {
501
        for(int i=0; i<NUM_FACES; i++)
503
        for(int i=0; i<NUM_CUBIT_FACES; i++)
502 504
          {
503 505
          belongs = isOnFace(cubit, i/2, i%2==0 ? mSize-1:0 );
504 506
          maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
......
506 508
        }
507 509
      else if( ROTATION_AXIS.length == NUM_FACES )  // just a single face on the right end of an axis (pyraminx)
508 510
        {
509
        for(int i=0; i<NUM_FACES; i++)
511
        for(int i=0; i<NUM_CUBIT_FACES; i++)
510 512
          {
511 513
          belongs = isOnFace(cubit, i, 0 );
512 514
          maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
513 515
          }
514 516
        }
517
      else if( 3*ROTATION_AXIS.length == 2*NUM_FACES ) // Dino  TODO
518
        {
519
        for(int i=0; i<NUM_CUBIT_FACES; i++)
520
          {
521
          belongs = true;//isOnFace(cubit, i, 0 );
522
          maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
523
          }
524
        }
515 525

  
516
      mMesh.setTextureMap(maps,NUM_FACES*cubit);
526
      mMesh.setTextureMap(maps,NUM_CUBIT_FACES*cubit);
517 527
      }
518 528
    }
519 529

  
......
522 532
  public void setTextureMap(int cubit, int face, int newColor)
523 533
    {
524 534
    final float ratio = 1.0f/(NUM_FACES+1);
525
    final Static4D[] maps = new Static4D[NUM_FACES];
535
    final Static4D[] maps = new Static4D[NUM_CUBIT_FACES];
526 536

  
527 537
    maps[face] = new Static4D( newColor*ratio, 0.0f, ratio, 1.0f);
528
    mMesh.setTextureMap(maps,NUM_FACES*cubit);
538
    mMesh.setTextureMap(maps,NUM_CUBIT_FACES*cubit);
529 539
    }
530 540

  
531 541
///////////////////////////////////////////////////////////////////////////////////////////////////
......
700 710
  abstract Static3D[] getCubitPositions(int size);
701 711
  abstract Static4D[] getQuats();
702 712
  abstract int getNumFaces();
713
  abstract int getNumCubitFaces();
703 714
  abstract MeshBase createCubitMesh(int cubit);
704 715
  abstract void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side);
705 716
  public abstract Static3D[] getRotationAxis();
src/main/java/org/distorted/objects/RubikPyraminx.java
209 209
    return FACE_COLORS.length;
210 210
    }
211 211

  
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

  
214
  int getNumCubitFaces()
215
    {
216
    return FACE_COLORS.length;
217
    }
218

  
212 219
///////////////////////////////////////////////////////////////////////////////////////////////////
213 220

  
214 221
  float getScreenRatio()

Also available in: Unified diff