Project

General

Profile

« Previous | Next » 

Revision 10585385

Added by Leszek Koltunski almost 4 years ago

More progreess porting RubikCube.

View differences:

src/main/java/org/distorted/main/RubikRenderer.java
49 49
     mView = v;
50 50
     mScreen = new DistortedScreen();
51 51
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
52
     mScreen.showFPS();
52 53
     }
53 54

  
54 55
///////////////////////////////////////////////////////////////////////////////////////////////////
......
77 78
   @Override
78 79
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
79 80
      {
80
      DistortedLibrary.setMax(EffectType.VERTEX,15);
81
      DistortedLibrary.setMax(EffectType.VERTEX,25);    // 24 Cube Quats + Rotate
81 82
      VertexEffectRotate.enable();
82 83
      BaseEffect.Type.enableEffects();
83 84

  
src/main/java/org/distorted/objects/Cubit.java
64 64
//
65 65
// We also have to remember that the group of unit quaternions is a double-cover of rotations
66 66
// in 3D ( q represents the same rotation as -q ) - so invert if needed.
67

  
67
/*
68 68
  private void normalizeScrambleQuat(Static4D quat)
69 69
    {
70 70
    final float MAX_ERROR = 0.0001f;
......
121 121

  
122 122
    quat.set(x,y,z,w);
123 123
    }
124

  
124
*/
125 125
///////////////////////////////////////////////////////////////////////////////////////////////////
126 126

  
127 127
  private void modifyCurrentPosition(Static4D quat)
......
284 284
  void removeRotationNow(Static4D quat)
285 285
    {
286 286
    mQuatScramble.set(RubikSurfaceView.quatMultiply(quat,mQuatScramble));
287
    normalizeScrambleQuat( mQuatScramble );
287
 //   normalizeScrambleQuat( mQuatScramble );
288 288
    modifyCurrentPosition(quat);
289 289
    }
290 290

  
src/main/java/org/distorted/objects/RubikCube.java
39 39

  
40 40
class RubikCube extends RubikObject
41 41
{
42
  static final float SQ2 = (float)Math.sqrt(2);
43

  
42 44
  // the three rotation axis of a RubikCube. Must be normalized.
43 45
  static final Static3D[] AXIS = new Static3D[]
44 46
         {
......
54 56
           0xffff0000, 0xffb5651d    // AXIS[2]right (front-RED   ) AXIS[2]left (back  -BROWN)
55 57
         };
56 58

  
57
  // All legal rotation quats of a RubikCube of any size must have all four of their components
58
  // equal to either 0, +-1, +-0.5 or +-sqrt(2)/2.
59
  // All legal rotation quats of a RubikCube of any size.
59 60
  // Here's how to compute this:
60 61
  // 1) compute how many rotations there are (RubikCube of any size = 24)
61 62
  // 2) take the AXIS, angles of rotation (90 in RubikCube's case) compute the basic quaternions
62 63
  // (i.e. rotations of 1 basic angle along each of the axis) and from there start semi-randomly
63 64
  // multiplying them and eventually you'll find all (24) legal rotations.
64
  // 3) linear scan through those shows that the only floats in those 24 quats are those 7 given
65
  // below.
66
  //
67 65
  // Example program in C, res/raw/compute_quats.c , is included.
68
  private static final float[] LEGALQUATS = new float[]
66
  private static final Static4D[] QUATS = new Static4D[]
69 67
         {
70
           0.0f ,
71
           0.5f ,
72
          -0.5f ,
73
           1.0f ,
74
          -1.0f ,
75
           0.5f*((float)Math.sqrt(2)) ,
76
          -0.5f*((float)Math.sqrt(2))
68
         new Static4D(  0.0f,   0.0f,   0.0f,   1.0f),
69
         new Static4D(  1.0f,   0.0f,   0.0f,   0.0f),
70
         new Static4D(  0.0f,   1.0f,   0.0f,   0.0f),
71
         new Static4D(  0.0f,   0.0f,   1.0f,   0.0f),
72

  
73
         new Static4D( SQ2/2,  SQ2/2,  0.0f ,   0.0f),
74
         new Static4D( SQ2/2, -SQ2/2,  0.0f ,   0.0f),
75
         new Static4D( SQ2/2,   0.0f,  SQ2/2,   0.0f),
76
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,   0.0f),
77
         new Static4D( SQ2/2,   0.0f,   0.0f,  SQ2/2),
78
         new Static4D( SQ2/2,   0.0f,   0.0f, -SQ2/2),
79
         new Static4D(  0.0f,  SQ2/2,  SQ2/2,   0.0f),
80
         new Static4D(  0.0f,  SQ2/2, -SQ2/2,   0.0f),
81
         new Static4D(  0.0f,  SQ2/2,   0.0f,  SQ2/2),
82
         new Static4D(  0.0f,  SQ2/2,   0.0f, -SQ2/2),
83
         new Static4D(  0.0f,   0.0f,  SQ2/2,  SQ2/2),
84
         new Static4D(  0.0f,   0.0f,  SQ2/2, -SQ2/2),
85

  
86
         new Static4D(  0.5f,   0.5f,   0.5f,   0.5f),
87
         new Static4D(  0.5f,   0.5f,  -0.5f,   0.5f),
88
         new Static4D(  0.5f,   0.5f,  -0.5f,  -0.5f),
89
         new Static4D(  0.5f,  -0.5f,   0.5f,  -0.5f),
90
         new Static4D( -0.5f,  -0.5f,  -0.5f,   0.5f),
91
         new Static4D( -0.5f,   0.5f,  -0.5f,  -0.5f),
92
         new Static4D( -0.5f,   0.5f,   0.5f,  -0.5f),
93
         new Static4D( -0.5f,   0.5f,   0.5f,   0.5f)
77 94
         };
78 95

  
79 96
  private static MeshBase mMesh = null;
......
121 138

  
122 139
///////////////////////////////////////////////////////////////////////////////////////////////////
123 140

  
124
  float[] getLegalQuats()
141
  Static4D[] getQuats()
125 142
    {
126
    return LEGALQUATS;
143
    return QUATS;
127 144
    }
128 145

  
129 146
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/RubikObject.java
30 30
import org.distorted.library.effect.MatrixEffectMove;
31 31
import org.distorted.library.effect.MatrixEffectQuaternion;
32 32
import org.distorted.library.effect.MatrixEffectScale;
33
import org.distorted.library.effect.VertexEffectQuaternion;
33 34
import org.distorted.library.effect.VertexEffectRotate;
34 35
import org.distorted.library.main.DistortedEffects;
35 36
import org.distorted.library.main.DistortedNode;
......
53 54
  private static final int POST_ROTATION_MILLISEC = 500;
54 55
  private static final int TEXTURE_HEIGHT = 128;
55 56

  
56
  final float[] LEGAL_QUATS;
57 57
  final Static3D[] ROTATION_AXIS;
58 58
  final int NUM_FACES;
59 59

  
......
95 95
    mList = list;
96 96
    mOrigPos = getCubitPositions(size);
97 97

  
98
    LEGAL_QUATS = getLegalQuats();
98
    Static4D[] quats = getQuats();
99 99
    NUM_CUBITS  = mOrigPos.length;
100 100
    ROTATION_AXIS = getRotationAxis();
101 101
    OBJECT_SCREEN_RATIO = getScreenRatio();
......
131 131
      mCubits[i] = new Cubit(this,mOrigPos[i]);
132 132
      cubitMesh[i] = createCubitMesh(i);
133 133
      cubitMesh[i].apply(new MatrixEffectMove(mOrigPos[i]),1,0);
134
      cubitMesh[i].setEffectAssociation(0, mCubits[i].computeAssociation(), i);
134
      cubitMesh[i].setEffectAssociation(0, mCubits[i].computeAssociation(), 0);
135 135
      }
136 136

  
137 137
    mMesh = new MeshJoined(cubitMesh);
......
139 139
    resetAllTextureMaps();
140 140

  
141 141
    mEffects = new DistortedEffects();
142

  
143
    int num_quats = quats.length;
144
    for(int q=0; q<num_quats; q++)
145
      {
146
      VertexEffectQuaternion vq = new VertexEffectQuaternion(quats[q],CENTER);
147
      vq.setMeshAssociation(0,q);
148
      mEffects.apply(vq);
149
      }
150

  
142 151
    mEffects.apply(mRotateEffect);
143 152
    mEffects.apply(mQuatAEffect);
144 153
    mEffects.apply(mQuatCEffect);
......
383 392
  public void releaseResources()
384 393
    {
385 394
    mTexture.markForDeletion();
386

  
387
    // TODO ?
388 395
    }
389 396

  
390 397
///////////////////////////////////////////////////////////////////////////////////////////////////
......
614 621

  
615 622
  abstract float getScreenRatio();
616 623
  abstract Static3D[] getCubitPositions(int size);
617
  abstract float[] getLegalQuats();
624
  abstract Static4D[] getQuats();
618 625
  abstract int getNumFaces();
619 626
  abstract MeshBase createCubitMesh(int cubit);
620 627
  abstract void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side);
src/main/java/org/distorted/objects/RubikPyraminx.java
43 43
{
44 44
  private static final float SQ2 = (float)Math.sqrt(2);
45 45
  private static final float SQ3 = (float)Math.sqrt(3);
46
  private static final float SQ6 = (float)Math.sqrt(6);
46 47

  
47 48
  static final Static3D[] AXIS = new Static3D[]
48 49
         {
......
59 60
         };
60 61

  
61 62
  // computed with res/raw/compute_quats.c
62
  private static final float[] LEGALQUATS = new float[]
63
  private static final Static4D[] QUATS = new Static4D[]
63 64
         {
64
           0.0f, 1.0f, -1.0f, 0.5f, -0.5f, SQ2/2, -SQ2/2, SQ3/2, -SQ3/2,
65
           SQ3/3, -SQ3/3, SQ3/6, -SQ3/6, SQ2*SQ3/3, -SQ2*SQ3/3, SQ2*SQ3/6, -SQ2*SQ3/6
65
           new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
66
           new Static4D(  0.0f,  SQ3/2,   0.0f,  0.5f),
67
           new Static4D( SQ2/2, -SQ3/6, -SQ6/6,  0.5f),
68
           new Static4D(-SQ2/2, -SQ3/6, -SQ6/6,  0.5f),
69
           new Static4D(  0.0f, -SQ3/6,  SQ6/3,  0.5f),
70
           new Static4D(  0.0f,  SQ3/2,   0.0f, -0.5f),
71
           new Static4D( SQ2/2, -SQ3/6, -SQ6/6, -0.5f),
72
           new Static4D(-SQ2/2, -SQ3/6, -SQ6/6, -0.5f),
73
           new Static4D(  0.0f, -SQ3/6,  SQ6/3, -0.5f),
74
           new Static4D( SQ2/2, -SQ3/3,  SQ6/6,  0.0f),
75
           new Static4D(  0.0f, -SQ3/3, -SQ6/3,  0.0f),
76
           new Static4D(-SQ2/2, -SQ3/3,  SQ6/6,  0.0f)
66 77
         };
67 78

  
68 79
  private int[] mRotArray;
......
184 195

  
185 196
///////////////////////////////////////////////////////////////////////////////////////////////////
186 197

  
187
  float[] getLegalQuats()
198
  Static4D[] getQuats()
188 199
    {
189
    return LEGALQUATS;
200
    return QUATS;
190 201
    }
191 202

  
192 203
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff