Project

General

Profile

« Previous | Next » 

Revision 8da6b1c9

Added by Leszek Koltunski over 2 years ago

Changes to the Cube cubits; new cube meshes.

View differences:

src/main/java/org/distorted/objectlib/main/Movement.java
105 105

  
106 106
      for( int face=0; face<mNumFaceAxis; face++)
107 107
        {
108
        convertTo2Dcoords( mPoint, mFaceAxis[face], mCastedRotAxis[face][casted]);
108
        convertTo2Dcoords( mPoint, face, mCastedRotAxis[face][casted]);
109 109
        normalize2D(mCastedRotAxis[face][casted]);
110 110

  
111 111
        fx = mFaceAxis[face].get0();
......
176 176

  
177 177
///////////////////////////////////////////////////////////////////////////////////////////////////
178 178

  
179
  private boolean faceIsVisible(Static3D faceAxis)
179
  private boolean faceIsVisible(int index)
180 180
    {
181
    Static3D faceAxis = mFaceAxis[index];
181 182
    float castCameraOnAxis = mCamera[0]*faceAxis.get0() + mCamera[1]*faceAxis.get1() + mCamera[2]*faceAxis.get2();
182 183
    return castCameraOnAxis > mDistanceCenterFace3D;
183 184
    }
......
190 191
//
191 192
// output = camera + alpha*(point-camera), where alpha = [dist-axis*camera] / [axis*(point-camera)]
192 193

  
193
  private void castTouchPointOntoFace(Static3D faceAxis, float[] output)
194
  private void castTouchPointOntoFace(int index, float[] output)
194 195
    {
196
    Static3D faceAxis = mFaceAxis[index];
197

  
195 198
    float d0 = mPoint[0]-mCamera[0];
196 199
    float d1 = mPoint[1]-mCamera[1];
197 200
    float d2 = mPoint[2]-mCamera[2];
......
222 225
// mean that the distance between the center of the Object and its faces is 0) - then we arbitrarily
223 226
// decide that 2D Y = (0,0,-1) in the North Pole and (0,0,1) in the South Pole)
224 227

  
225
  private void convertTo2Dcoords(float[] point3D, Static3D faceAxis, float[] output)
228
  private void convertTo2Dcoords(float[] point3D, int index , float[] output)
226 229
    {
230
    Static3D faceAxis = mFaceAxis[index];
231

  
227 232
    float y0,y1,y2; // base Y vector of the 2D coord system
228 233
    float a0 = faceAxis.get0();
229 234
    float a1 = faceAxis.get1();
......
421 426

  
422 427
    for( mLastTouchedFace=0; mLastTouchedFace<mNumFaceAxis; mLastTouchedFace++)
423 428
      {
424
      if( faceIsVisible(mFaceAxis[mLastTouchedFace]) )
429
      if( faceIsVisible(mLastTouchedFace) )
425 430
        {
426
        castTouchPointOntoFace(mFaceAxis[mLastTouchedFace], mTouch);
427
        convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedFace], mPoint2D);
431
        castTouchPointOntoFace(mLastTouchedFace, mTouch);
432
        convertTo2Dcoords(mTouch, mLastTouchedFace, mPoint2D);
428 433
        if( isInsideFace(mLastTouchedFace,mPoint2D) ) return true;
429 434
        }
430 435
      }
......
440 445
    mPoint[1] = rotatedTouchPoint.get1()/objectRatio;
441 446
    mPoint[2] = rotatedTouchPoint.get2()/objectRatio;
442 447

  
443
    castTouchPointOntoFace(mFaceAxis[mLastTouchedFace], mTouch);
444
    convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedFace], mMove2D);
448
    castTouchPointOntoFace(mLastTouchedFace, mTouch);
449
    convertTo2Dcoords(mTouch, mLastTouchedFace, mMove2D);
445 450

  
446 451
    mMove2D[0] -= mPoint2D[0];
447 452
    mMove2D[1] -= mPoint2D[1];
src/main/java/org/distorted/objectlib/main/Movement12.java
33 33
  public static final float SIN54    = (SQ5+1)/4;
34 34
  public static final float COS54    = (float)(Math.sqrt(10-2*SQ5)/4);
35 35

  
36
  public static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5);
37
  public static final float DIST2D = (SIN54/COS54)/2;
36
  public  static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5);
37
  private static final float DIST2D = (SIN54/COS54)/2;
38 38

  
39 39
  public static final Static3D[] FACE_AXIS = new Static3D[]
40 40
         {
src/main/java/org/distorted/objectlib/main/Movement4.java
26 26

  
27 27
public class Movement4 extends Movement
28 28
{
29
  public static final float DIST3D = SQ6/12;
30
  public static final float DIST2D = SQ3/6;
29
  private static final float DIST3D = SQ6/12;
30
  private static final float DIST2D = SQ3/6;
31 31

  
32 32
  public static final Static3D[] FACE_AXIS = new Static3D[]
33 33
         {
src/main/java/org/distorted/objectlib/main/Movement6.java
26 26

  
27 27
public class Movement6 extends Movement
28 28
{
29
  public static final float DIST3D = 0.5f;
30
  public static final float DIST2D = 0.5f;
29
  private static final float DIST3D = 0.5f;
30
  private static final float DIST2D = 0.5f;
31 31

  
32 32
  public static final Static3D[] FACE_AXIS = new Static3D[]
33 33
         {
src/main/java/org/distorted/objectlib/main/Movement8.java
26 26

  
27 27
public class Movement8 extends Movement
28 28
{
29
  public static final float DIST3D = SQ6/6;
30
  public static final float DIST2D = SQ3/6;
29
  private static final float DIST3D = SQ6/6;
30
  private static final float DIST2D = SQ3/6;
31 31

  
32 32
  public static final Static3D[] FACE_AXIS = new Static3D[]
33 33
         {
src/main/java/org/distorted/objectlib/objects/TwistyCube.java
186 186
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status], mQuats);
187 187
    }
188 188

  
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

  
191
  private int getNumCornersAndEdges(int numLayers)
192
    {
193
    return numLayers==1 ? 1 : 12*(numLayers-2) + 8;
194
    }
195

  
189 196
///////////////////////////////////////////////////////////////////////////////////////////////////
190 197

  
191 198
  protected ObjectShape getObjectShape(int cubit, int numLayers)
......
233 240
    return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
234 241
    }
235 242

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
  protected float[][] getCubitPositions(int numLayers)
246
    {
247
    if( numLayers==1 ) return new float[][] {{ 0.0f, 0.0f, 0.0f }};
248

  
249
    int numCubits = getNumCornersAndEdges(numLayers) + 6*(numLayers-2)*(numLayers-2);
250
    float[][] tmp = new float[numCubits][];
251

  
252
    final float LEN = 0.5f*(numLayers-1);
253
    int currentPosition = 0;
254

  
255
    tmp[currentPosition++] = new float[] {-LEN,-LEN,-LEN};
256
    tmp[currentPosition++] = new float[] {-LEN,-LEN,+LEN};
257
    tmp[currentPosition++] = new float[] {-LEN,+LEN,-LEN};
258
    tmp[currentPosition++] = new float[] {-LEN,+LEN,+LEN};
259
    tmp[currentPosition++] = new float[] {+LEN,-LEN,-LEN};
260
    tmp[currentPosition++] = new float[] {+LEN,-LEN,+LEN};
261
    tmp[currentPosition++] = new float[] {+LEN,+LEN,-LEN};
262
    tmp[currentPosition++] = new float[] {+LEN,+LEN,+LEN};
263

  
264
    for(int i=1; i<numLayers-1; i++)
265
      tmp[currentPosition++] = new float[] { i-LEN,  -LEN,  -LEN };
266
    for(int i=1; i<numLayers-1; i++)
267
      tmp[currentPosition++] = new float[] { i-LEN,  -LEN,  +LEN };
268
    for(int i=1; i<numLayers-1; i++)
269
      tmp[currentPosition++] = new float[] { i-LEN,  +LEN,  -LEN };
270
    for(int i=1; i<numLayers-1; i++)
271
      tmp[currentPosition++] = new float[] { i-LEN,  +LEN,  +LEN };
272
    for(int i=1; i<numLayers-1; i++)
273
      tmp[currentPosition++] = new float[] {  -LEN, i-LEN,  -LEN };
274
    for(int i=1; i<numLayers-1; i++)
275
      tmp[currentPosition++] = new float[] {  -LEN, i-LEN,  +LEN };
276
    for(int i=1; i<numLayers-1; i++)
277
      tmp[currentPosition++] = new float[] {  +LEN, i-LEN,  -LEN };
278
    for(int i=1; i<numLayers-1; i++)
279
      tmp[currentPosition++] = new float[] {  +LEN, i-LEN,  +LEN };
280
    for(int i=1; i<numLayers-1; i++)
281
      tmp[currentPosition++] = new float[] {  -LEN,  -LEN, i-LEN };
282
    for(int i=1; i<numLayers-1; i++)
283
      tmp[currentPosition++] = new float[] {  -LEN,  +LEN, i-LEN };
284
    for(int i=1; i<numLayers-1; i++)
285
      tmp[currentPosition++] = new float[] {  +LEN,  -LEN, i-LEN };
286
    for(int i=1; i<numLayers-1; i++)
287
      tmp[currentPosition++] = new float[] {  +LEN,  +LEN, i-LEN };
288

  
289
    for(int y=1; y<numLayers-1; y++)
290
      for(int z=1; z<numLayers-1; z++)
291
        tmp[currentPosition++] = new float[] {+LEN,y-LEN,z-LEN};
292

  
293
    for(int y=1; y<numLayers-1; y++)
294
      for(int z=1; z<numLayers-1; z++)
295
        tmp[currentPosition++] = new float[] {-LEN,y-LEN,z-LEN};
296

  
297
    for(int x=1; x<numLayers-1; x++)
298
      for(int z=1; z<numLayers-1; z++)
299
        tmp[currentPosition++] = new float[] {x-LEN,+LEN,z-LEN};
300

  
301
    for(int x=1; x<numLayers-1; x++)
302
      for(int z=1; z<numLayers-1; z++)
303
        tmp[currentPosition++] = new float[] {x-LEN,-LEN,z-LEN};
304

  
305
    for(int x=1; x<numLayers-1; x++)
306
      for(int y=1; y<numLayers-1; y++)
307
        tmp[currentPosition++] = new float[] {x-LEN,y-LEN,+LEN};
308

  
309
    for(int x=1; x<numLayers-1; x++)
310
      for(int y=1; y<numLayers-1; y++)
311
        tmp[currentPosition++] = new float[] {x-LEN,y-LEN,-LEN};
312

  
313
    return tmp;
314
    }
315

  
236 316
///////////////////////////////////////////////////////////////////////////////////////////////////
237 317

  
238 318
  protected Static4D getQuat(int cubit, int numLayers)
239 319
    {
240 320
    if( mQuats ==null ) initializeQuats();
321

  
322
    int num = cubit - getNumCornersAndEdges(numLayers);
323

  
324
    if( num>=0 )
325
      {
326
      int face = num/((numLayers-2)*(numLayers-2));
327

  
328
      switch(face)
329
        {
330
        case 0: return mQuats[13];
331
        case 1: return mQuats[12];
332
        case 2: return mQuats[ 8];
333
        case 3: return mQuats[ 9];
334
        case 4: return mQuats[ 0];
335
        case 5: return mQuats[ 1];
336
        }
337
      }
338

  
241 339
    return mQuats[0];
242 340
    }
243 341

  
......
245 343

  
246 344
  protected int getNumCubitVariants(int numLayers)
247 345
    {
248
    return 1;
346
    return numLayers>2 ? 2:1;
249 347
    }
250 348

  
251 349
///////////////////////////////////////////////////////////////////////////////////////////////////
252 350

  
253 351
  protected int getCubitVariant(int cubit, int numLayers)
254 352
    {
255
    return 0;
353
    return cubit < getNumCornersAndEdges(numLayers) ? 0 : 1;
354
    }
355

  
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

  
358
  protected int getFaceColor(int cubit, int cubitface, int numLayers)
359
    {
360
    int cornersAndEdges = getNumCornersAndEdges(numLayers);
361

  
362
    if( cubit<cornersAndEdges )
363
      {
364
      return CUBITS[cubit].getRotRow(cubitface/2) == (cubitface%2==0 ? (1<<(numLayers-1)):1) ? cubitface : NUM_TEXTURES;
365
      }
366
    else
367
      {
368
      int numCentersPerFace = (numLayers-2)*(numLayers-2);
369
      return cubitface == 4 ? (cubit-cornersAndEdges)/numCentersPerFace : NUM_TEXTURES;
370
      }
256 371
    }
257 372

  
258 373
///////////////////////////////////////////////////////////////////////////////////////////////////
......
284 399
    return mStickers[face/NUM_FACE_COLORS];
285 400
    }
286 401

  
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288

  
289
  protected float[][] getCubitPositions(int numLayers)
290
    {
291
    int numCubits = numLayers>1 ? 6*numLayers*numLayers - 12*numLayers + 8 : 1;
292
    float[][] tmp = new float[numCubits][];
293

  
294
    float diff = 0.5f*(numLayers-1);
295
    int currentPosition = 0;
296

  
297
    for(int x = 0; x<numLayers; x++)
298
      for(int y = 0; y<numLayers; y++)
299
        for(int z = 0; z<numLayers; z++)
300
          if( x==0 || x==numLayers-1 || y==0 || y==numLayers-1 || z==0 || z==numLayers-1 )
301
            {
302
            tmp[currentPosition++] = new float[] {x-diff,y-diff,z-diff};
303
            }
304

  
305
    return tmp;
306
    }
307

  
308 402
///////////////////////////////////////////////////////////////////////////////////////////////////
309 403

  
310 404
  protected Static4D[] getQuats()
......
370 464
    return 6;
371 465
    }
372 466

  
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

  
375
  protected int getFaceColor(int cubit, int cubitface, int numLayers)
376
    {
377
    return CUBITS[cubit].getRotRow(cubitface/2) == (cubitface%2==0 ? (1<<(numLayers-1)):1) ? cubitface : NUM_TEXTURES;
378
    }
379

  
380 467
///////////////////////////////////////////////////////////////////////////////////////////////////
381 468
// PUBLIC API
382 469

  

Also available in: Unified diff