Project

General

Profile

« Previous | Next » 

Revision 57ef6378

Added by Leszek Koltunski over 2 years ago

Float vertices - scratchbook

View differences:

src/main/java/org/distorted/objectlib/helpers/FactoryCubit.java
41 41
  private static final Static1D RADIUS = new Static1D(1);
42 42
  private static FactoryCubit mThis;
43 43

  
44
  private static final double[] mBuffer = new double[3];
45
  private static final double[] mQuat1  = new double[4];
46
  private static final double[] mQuat2  = new double[4];
47
  private static final double[] mQuat3  = new double[4];
48
  private static final double[] mQuat4  = new double[4];
44
  private static final float[] mBuffer = new float[3];
45
  private static final float[] mQuat1  = new float[4];
46
  private static final float[] mQuat2  = new float[4];
47
  private static final float[] mQuat3  = new float[4];
48
  private static final float[] mQuat4  = new float[4];
49 49

  
50 50
  private static class StickerCoords
51 51
    {
52
    double[] vertices;
52
    float[] vertices;
53 53
    }
54 54

  
55 55
  private static class FaceTransform
56 56
    {
57 57
    int sticker;
58
    double vx,vy,vz;
59
    double scale;
60
    double qx,qy,qz,qw;
58
    float vx,vy,vz;
59
    float scale;
60
    float qx,qy,qz,qw;
61 61
    boolean flip;
62 62
    }
63 63

  
......
140 140

  
141 141
///////////////////////////////////////////////////////////////////////////////////////////////////
142 142

  
143
  private boolean areColinear(double[][] vertices, int index1, int index2, int index3)
143
  private boolean areColinear(float[][] vertices, int index1, int index2, int index3)
144 144
    {
145
    double x1 = vertices[index1][0];
146
    double y1 = vertices[index1][1];
147
    double z1 = vertices[index1][2];
148
    double x2 = vertices[index2][0];
149
    double y2 = vertices[index2][1];
150
    double z2 = vertices[index2][2];
151
    double x3 = vertices[index3][0];
152
    double y3 = vertices[index3][1];
153
    double z3 = vertices[index3][2];
145
    float x1 = vertices[index1][0];
146
    float y1 = vertices[index1][1];
147
    float z1 = vertices[index1][2];
148
    float x2 = vertices[index2][0];
149
    float y2 = vertices[index2][1];
150
    float z2 = vertices[index2][2];
151
    float x3 = vertices[index3][0];
152
    float y3 = vertices[index3][1];
153
    float z3 = vertices[index3][2];
154 154

  
155
    double v1x = x2-x1;
156
    double v1y = y2-y1;
157
    double v1z = z2-z1;
158
    double v2x = x3-x1;
159
    double v2y = y3-y1;
160
    double v2z = z3-z1;
155
    float v1x = x2-x1;
156
    float v1y = y2-y1;
157
    float v1z = z2-z1;
158
    float v2x = x3-x1;
159
    float v2y = y3-y1;
160
    float v2z = z3-z1;
161 161

  
162 162
    double A = Math.sqrt( (v1x*v1x+v1y*v1y+v1z*v1z) / (v2x*v2x+v2y*v2y+v2z*v2z) );
163 163

  
......
166 166

  
167 167
///////////////////////////////////////////////////////////////////////////////////////////////////
168 168

  
169
  private void computeNormalVector(double[][] vertices, int index1, int index2, int index3)
169
  private void computeNormalVector(float[][] vertices, int index1, int index2, int index3)
170 170
    {
171
    double x1 = vertices[index1][0];
172
    double y1 = vertices[index1][1];
173
    double z1 = vertices[index1][2];
174
    double x2 = vertices[index2][0];
175
    double y2 = vertices[index2][1];
176
    double z2 = vertices[index2][2];
177
    double x3 = vertices[index3][0];
178
    double y3 = vertices[index3][1];
179
    double z3 = vertices[index3][2];
171
    float x1 = vertices[index1][0];
172
    float y1 = vertices[index1][1];
173
    float z1 = vertices[index1][2];
174
    float x2 = vertices[index2][0];
175
    float y2 = vertices[index2][1];
176
    float z2 = vertices[index2][2];
177
    float x3 = vertices[index3][0];
178
    float y3 = vertices[index3][1];
179
    float z3 = vertices[index3][2];
180 180

  
181
    double v1x = x2-x1;
182
    double v1y = y2-y1;
183
    double v1z = z2-z1;
184
    double v2x = x3-x1;
185
    double v2y = y3-y1;
186
    double v2z = z3-z1;
181
    float v1x = x2-x1;
182
    float v1y = y2-y1;
183
    float v1z = z2-z1;
184
    float v2x = x3-x1;
185
    float v2y = y3-y1;
186
    float v2z = z3-z1;
187 187

  
188 188
    mBuffer[0] = v1y*v2z - v2y*v1z;
189 189
    mBuffer[1] = v1z*v2x - v2z*v1x;
......
199 199
///////////////////////////////////////////////////////////////////////////////////////////////////
200 200
// return quat1*quat2
201 201

  
202
  private static void quatMultiply( double[] quat1, double[] quat2, double[] result )
202
  private static void quatMultiply( float[] quat1, float[] quat2, float[] result )
203 203
    {
204
    double qx = quat1[0];
205
    double qy = quat1[1];
206
    double qz = quat1[2];
207
    double qw = quat1[3];
204
    float qx = quat1[0];
205
    float qy = quat1[1];
206
    float qz = quat1[2];
207
    float qw = quat1[3];
208 208

  
209
    double rx = quat2[0];
210
    double ry = quat2[1];
211
    double rz = quat2[2];
212
    double rw = quat2[3];
209
    float rx = quat2[0];
210
    float ry = quat2[1];
211
    float rz = quat2[2];
212
    float rw = quat2[3];
213 213

  
214 214
    result[0] = rw*qx - rz*qy + ry*qz + rx*qw;
215 215
    result[1] = rw*qy + rz*qx + ry*qw - rx*qz;
......
219 219

  
220 220
///////////////////////////////////////////////////////////////////////////////////////////////////
221 221

  
222
  private void fitInSquare(FaceTransform info, double[][] vert3D)
222
  private void fitInSquare(FaceTransform info, float[][] vert3D)
223 223
    {
224
    double minX = Double.MAX_VALUE;
225
    double maxX =-Double.MAX_VALUE;
226
    double minY = Double.MAX_VALUE;
227
    double maxY =-Double.MAX_VALUE;
224
    float minX = Float.MAX_VALUE;
225
    float maxX =-Float.MAX_VALUE;
226
    float minY = Float.MAX_VALUE;
227
    float maxY =-Float.MAX_VALUE;
228 228

  
229
    for (double[] vert : vert3D)
229
    for (float[] vert : vert3D)
230 230
      {
231
      double x = vert[0];
232
      double y = vert[1];
231
      float x = vert[0];
232
      float y = vert[1];
233 233

  
234 234
      if (x > maxX) maxX = x;
235 235
      if (x < minX) minX = x;
......
242 242
    minY = minY<0 ? -minY:minY;
243 243
    maxY = maxY<0 ? -maxY:maxY;
244 244

  
245
    double max1 = Math.max(minX,minY);
246
    double max2 = Math.max(maxX,maxY);
247
    double max3 = Math.max(max1,max2);
245
    float max1 = Math.max(minX,minY);
246
    float max2 = Math.max(maxX,maxY);
247
    float max3 = Math.max(max1,max2);
248 248

  
249
    info.scale = max3/0.5;
249
    info.scale = max3/0.5f;
250 250

  
251 251
    int len = vert3D.length;
252 252
    StickerCoords sInfo = new StickerCoords();
253
    sInfo.vertices = new double[2*len];
253
    sInfo.vertices = new float[2*len];
254 254

  
255 255
    for( int vertex=0; vertex<len; vertex++ )
256 256
      {
......
266 266

  
267 267
///////////////////////////////////////////////////////////////////////////////////////////////////
268 268

  
269
  private FaceTransform constructNewTransform(final double[][] vert3D)
269
  private FaceTransform constructNewTransform(final float[][] vert3D)
270 270
    {
271 271
    FaceTransform ft = new FaceTransform();
272 272

  
......
276 276
    ft.vz = 0.0f;
277 277
    int len = vert3D.length;
278 278

  
279
    for (double[] vert : vert3D)
279
    for (float[] vert : vert3D)
280 280
      {
281 281
      ft.vx += vert[0];
282 282
      ft.vy += vert[1];
......
316 316
    computeNormalVector(vert3D,0,1,foundIndex);
317 317

  
318 318
    // rotate so that the normal vector becomes (0,0,1)
319
    double axisX, axisY, axisZ;
319
    float axisX, axisY, axisZ;
320 320

  
321 321
    if( mBuffer[0]!=0.0f || mBuffer[1]!=0.0f )
322 322
      {
......
324 324
      axisY =  mBuffer[0];
325 325
      axisZ = 0.0f;
326 326

  
327
      double axiLen = axisX*axisX + axisY*axisY;
328
      axiLen = Math.sqrt(axiLen);
327
      float axiLen = axisX*axisX + axisY*axisY;
328
      axiLen = (float)Math.sqrt(axiLen);
329 329
      axisX /= axiLen;
330 330
      axisY /= axiLen;
331 331
      axisZ /= axiLen;
......
337 337
      axisZ = 0.0f;
338 338
      }
339 339

  
340
    double cosTheta = mBuffer[2];
341
    double sinTheta = Math.sqrt(1-cosTheta*cosTheta);
342
    double sinHalfTheta = computeSinHalf(cosTheta);
343
    double cosHalfTheta = computeCosHalf(sinTheta,cosTheta);
340
    float cosTheta = mBuffer[2];
341
    float sinTheta = (float)Math.sqrt(1-cosTheta*cosTheta);
342
    float sinHalfTheta = computeSinHalf(cosTheta);
343
    float cosHalfTheta = computeCosHalf(sinTheta,cosTheta);
344 344

  
345 345
    mQuat1[0] = axisX*sinHalfTheta;
346 346
    mQuat1[1] = axisY*sinHalfTheta;
......
351 351
    mQuat2[2] =-axisZ*sinHalfTheta;
352 352
    mQuat2[3] = cosHalfTheta;
353 353

  
354
    for (double[] vert : vert3D)
354
    for (float[] vert : vert3D)
355 355
      {
356 356
      quatMultiply(mQuat1, vert  , mQuat3);
357 357
      quatMultiply(mQuat3, mQuat2, vert  );
......
371 371

  
372 372
///////////////////////////////////////////////////////////////////////////////////////////////////
373 373

  
374
  private void rotateAllVertices(double[] result, int len, double[] vertices, double sin, double cos)
374
  private void rotateAllVertices(float[] result, int len, float[] vertices, float sin, float cos)
375 375
    {
376 376
    for(int i=0; i<len; i++)
377 377
      {
......
382 382

  
383 383
///////////////////////////////////////////////////////////////////////////////////////////////////
384 384

  
385
  private double computeScale(double[] v1, double[] v2, int v1i, int v2i)
385
  private float computeScale(float[] v1, float[] v2, int v1i, int v2i)
386 386
    {
387
    double v1x = v1[2*v1i];
388
    double v1y = v1[2*v1i+1];
389
    double v2x = v2[2*v2i];
390
    double v2y = v2[2*v2i+1];
387
    float v1x = v1[2*v1i];
388
    float v1y = v1[2*v1i+1];
389
    float v2x = v2[2*v2i];
390
    float v2y = v2[2*v2i+1];
391 391

  
392
    double lenSq1 = v1x*v1x + v1y*v1y;
393
    double lenSq2 = v2x*v2x + v2y*v2y;
392
    float lenSq1 = v1x*v1x + v1y*v1y;
393
    float lenSq2 = v2x*v2x + v2y*v2y;
394 394

  
395
    return Math.sqrt(lenSq2/lenSq1);
395
    return (float)Math.sqrt(lenSq2/lenSq1);
396 396
    }
397 397

  
398 398
///////////////////////////////////////////////////////////////////////////////////////////////////
399 399
// valid for 0<angle<2*PI
400 400

  
401
  private double computeSinHalf(double cos)
401
  private float computeSinHalf(float cos)
402 402
    {
403
    return Math.sqrt((1-cos)/2);
403
    return (float)Math.sqrt((1-cos)/2);
404 404
    }
405 405

  
406 406
///////////////////////////////////////////////////////////////////////////////////////////////////
407 407
// valid for 0<angle<2*PI
408 408

  
409
  private double computeCosHalf(double sin, double cos)
409
  private float computeCosHalf(float sin, float cos)
410 410
    {
411
    double cosHalf = Math.sqrt((1+cos)/2);
411
    float cosHalf = (float)Math.sqrt((1+cos)/2);
412 412
    return sin<0 ? -cosHalf : cosHalf;
413 413
    }
414 414

  
......
425 425

  
426 426
///////////////////////////////////////////////////////////////////////////////////////////////////
427 427

  
428
  private boolean isScaledVersionOf(double[] newVert, double[] oldVert, int len, int vertex, boolean inverted)
428
  private boolean isScaledVersionOf(float[] newVert, float[] oldVert, int len, int vertex, boolean inverted)
429 429
    {
430 430
    int newZeroIndex = computeRotatedIndex(0,len,vertex,inverted);
431
    double EPSILON = 0.001;
432
    double scale = computeScale(newVert,oldVert,newZeroIndex,0);
431
    float EPSILON = 0.001f;
432
    float scale = computeScale(newVert,oldVert,newZeroIndex,0);
433 433

  
434 434
    for(int i=1; i<len; i++)
435 435
      {
436 436
      int index = computeRotatedIndex(i,len,vertex,inverted);
437 437

  
438
      double horz = oldVert[2*i  ] - scale*newVert[2*index  ];
439
      double vert = oldVert[2*i+1] - scale*newVert[2*index+1];
438
      float horz = oldVert[2*i  ] - scale*newVert[2*index  ];
439
      float vert = oldVert[2*i+1] - scale*newVert[2*index+1];
440 440

  
441 441
      if( horz>EPSILON || horz<-EPSILON || vert>EPSILON || vert<-EPSILON ) return false;
442 442
      }
......
446 446

  
447 447
///////////////////////////////////////////////////////////////////////////////////////////////////
448 448

  
449
  private void mirrorAllVertices(double[] output, int len, double[] input)
449
  private void mirrorAllVertices(float[] output, int len, float[] input)
450 450
    {
451 451
    for(int vertex=0; vertex<len; vertex++)
452 452
      {
......
457 457

  
458 458
///////////////////////////////////////////////////////////////////////////////////////////////////
459 459

  
460
  private void correctInfo(FaceTransform info, double scale, double sin, double cos, int oldSticker, boolean flip)
460
  private void correctInfo(FaceTransform info, float scale, float sin, float cos, int oldSticker, boolean flip)
461 461
    {
462 462
    mStickerCoords.remove(info.sticker);
463 463

  
......
470 470
    mQuat1[2] = info.qz;
471 471
    mQuat1[3] = info.qw;
472 472

  
473
    double sinHalf = computeSinHalf(cos);
474
    double cosHalf = computeCosHalf(sin,cos);
473
    float sinHalf = computeSinHalf(cos);
474
    float cosHalf = computeCosHalf(sin,cos);
475 475

  
476 476
    if( flip )
477 477
      {
......
480 480
      mQuat3[2] = sinHalf;
481 481
      mQuat3[3] = cosHalf;
482 482

  
483
      mQuat4[0] = 1.0;
484
      mQuat4[1] = 0.0;
485
      mQuat4[2] = 0.0;
486
      mQuat4[3] = 0.0;
483
      mQuat4[0] = 1.0f;
484
      mQuat4[1] = 0.0f;
485
      mQuat4[2] = 0.0f;
486
      mQuat4[3] = 0.0f;
487 487

  
488 488
      quatMultiply( mQuat3, mQuat4, mQuat2 );
489 489
      }
......
520 520

  
521 521
///////////////////////////////////////////////////////////////////////////////////////////////////
522 522

  
523
  private boolean foundVertex(FaceTransform info, double[] buffer, int len, double[] newVert,
524
                              double[] oldVert, double lenFirstOld, int oldSticker, boolean inverted)
523
  private boolean foundVertex(FaceTransform info, float[] buffer, int len, float[] newVert,
524
                              float[] oldVert, float lenFirstOld, int oldSticker, boolean inverted)
525 525
    {
526 526
    for(int vertex=0; vertex<len; vertex++)
527 527
      {
528
      double newX = newVert[2*vertex  ];
529
      double newY = newVert[2*vertex+1];
530
      double lenIthNew = Math.sqrt(newX*newX + newY*newY);
531
      double cos = QuatHelper.computeCos( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
532
      double sin = QuatHelper.computeSin( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
528
      float newX = newVert[2*vertex  ];
529
      float newY = newVert[2*vertex+1];
530
      float lenIthNew = (float)Math.sqrt(newX*newX + newY*newY);
531
      float cos = (float)QuatHelper.computeCos( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
532
      float sin = (float)QuatHelper.computeSin( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
533 533

  
534 534
      rotateAllVertices(buffer,len,newVert,sin,cos);
535 535

  
536 536
      if( isScaledVersionOf(buffer,oldVert,len,vertex,inverted) )
537 537
        {
538 538
        int newZeroIndex = computeRotatedIndex(0,len,vertex,inverted);
539
        double scale = computeScale(oldVert,newVert,0,newZeroIndex);
539
        float scale = computeScale(oldVert,newVert,0,newZeroIndex);
540 540
        correctInfo(info,scale,sin,cos,oldSticker,inverted);
541 541
        return true;
542 542
        }
......
551 551
    {
552 552
    StickerCoords sNewInfo = mStickerCoords.get(newInfo.sticker);
553 553
    StickerCoords sOldInfo = mStickerCoords.get(oldInfo.sticker);
554
    double[] newVert = sNewInfo.vertices;
555
    double[] oldVert = sOldInfo.vertices;
554
    float[] newVert = sNewInfo.vertices;
555
    float[] oldVert = sOldInfo.vertices;
556 556
    int oldLen = oldVert.length;
557 557
    int newLen = newVert.length;
558 558

  
559 559
    if( oldLen == newLen )
560 560
      {
561 561
      int oldSticker = oldInfo.sticker;
562
      double[] buffer1 = new double[oldLen];
563
      double lenFirstOld = Math.sqrt(oldVert[0]*oldVert[0] + oldVert[1]*oldVert[1]);
562
      float[] buffer1 = new float[oldLen];
563
      float lenFirstOld = (float)Math.sqrt(oldVert[0]*oldVert[0] + oldVert[1]*oldVert[1]);
564 564
      if( foundVertex(newInfo, buffer1, oldLen/2, newVert, oldVert, lenFirstOld, oldSticker, false) ) return true;
565
      double[] buffer2 = new double[oldLen];
565
      float[] buffer2 = new float[oldLen];
566 566
      mirrorAllVertices(buffer2, newLen/2, newVert);
567 567
      if( foundVertex(newInfo, buffer1, oldLen/2, buffer2, oldVert, lenFirstOld, oldSticker, true ) ) return true;
568 568
      }
......
572 572

  
573 573
///////////////////////////////////////////////////////////////////////////////////////////////////
574 574

  
575
  private double[][] constructVert(double[][] vertices, int[] index)
575
  private float[][] constructVert(float[][] vertices, int[] index)
576 576
    {
577 577
    int len = index.length;
578
    double[][] ret = new double[len][4];
578
    float[][] ret = new float[len][4];
579 579

  
580 580
    for(int i=0; i<len; i++)
581 581
      {
......
590 590

  
591 591
///////////////////////////////////////////////////////////////////////////////////////////////////
592 592

  
593
  private void prepareAndRoundCorners(MeshBase mesh, double[][] vertices,
593
  private void prepareAndRoundCorners(MeshBase mesh, float[][] vertices,
594 594
                                      float[][] corners, int[] cornerIndexes,
595 595
                                      float[][] centers, int[] centerIndexes )
596 596
    {
......
773 773

  
774 774
///////////////////////////////////////////////////////////////////////////////////////////////////
775 775

  
776
  public void createNewFaceTransform( final double[][] vertices, final int[][] indexes)
776
  public void createNewFaceTransform( final float[][] vertices, final int[][] indexes)
777 777
    {
778 778
    FaceTransform ft;
779 779
    int numNew = mNewFaceTransf.size();
......
791 791
      {
792 792
      boolean collapsed = false;
793 793

  
794
      double[][] vert = constructVert(vertices, indexes[face]);
794
      float[][] vert = constructVert(vertices, indexes[face]);
795 795
      FaceTransform newT = constructNewTransform(vert);
796 796

  
797 797
      for (int old=0; !collapsed && old<numOld; old++)
......
815 815

  
816 816
  public void createNewFaceTransform(final ObjectShape shape)
817 817
    {
818
    double[][] vertices = shape.getVertices();
818
    float[][] vertices = shape.getVertices();
819 819
    int[][] indices = shape.getVertIndices();
820 820
    createNewFaceTransform(vertices,indices);
821 821
    }
822 822

  
823 823
///////////////////////////////////////////////////////////////////////////////////////////////////
824 824

  
825
  private void computeConvexityCenter(double[] out, float[] in, FaceTransform ft)
825
  private void computeConvexityCenter(float[] out, float[] in, FaceTransform ft)
826 826
    {
827 827
    if( in==null )
828 828
      {
......
858 858

  
859 859
  public MeshBase createRoundedSolid(final ObjectShape shape)
860 860
    {
861
    double[][] vertices     = shape.getVertices();
861
    float[][] vertices      = shape.getVertices();
862 862
    int[][] vertIndexes     = shape.getVertIndices();
863 863
    float[][] bands         = shape.getBands();
864 864
    int[]   bandIndexes     = shape.getBandIndices();
......
875 875

  
876 876
///////////////////////////////////////////////////////////////////////////////////////////////////
877 877

  
878
  public MeshBase createRoundedSolid(final double[][] vertices, final int[][] vertIndexes,
879
                                     final float[][] bands    , final int[]   bandIndexes,
880
                                     final float[][] corners  , final int[]   cornerIndexes,
881
                                     final float[][] centers  , final int[]   centerIndexes,
882
                                     final int numComponents  , final float[] convexityCenter )
878
  public MeshBase createRoundedSolid(final float[][] vertices, final int[][] vertIndexes,
879
                                     final float[][] bands   , final int[]   bandIndexes,
880
                                     final float[][] corners , final int[]   cornerIndexes,
881
                                     final float[][] centers , final int[]   centerIndexes,
882
                                     final int numComponents , final float[] convexityCenter )
883 883
    {
884 884
    int numFaces = vertIndexes.length;
885 885
    float[] band, bandsComputed;
886 886
    MeshBase[] meshes = new MeshBase[numFaces];
887 887
    FaceTransform fInfo;
888 888
    StickerCoords sInfo;
889
    double[] convexXY = new double[4];
889
    float[] convexXY = new float[4];
890 890

  
891 891
    for(int face=0; face<numFaces; face++)
892 892
      {
893 893
      fInfo = mNewFaceTransf.get(face);
894 894
      sInfo = mStickerCoords.get(fInfo.sticker);
895 895

  
896
      double[] verts = sInfo.vertices;
897
      int lenVerts = verts.length;
898
      float[] vertsFloat = new float[lenVerts];
899
      for(int i=0; i<lenVerts; i++) vertsFloat[i] = (float)verts[i];
896
      float[] verts = sInfo.vertices;
900 897

  
901 898
      computeConvexityCenter(convexXY,convexityCenter,fInfo);
902 899

  
900
android.util.Log.e("D", "convexX="+convexXY[0]+" converY="+convexXY[1]);
901

  
903 902
      band = bands[bandIndexes[face]];
904 903
      bandsComputed = computeBands( band[0], (int)band[1], band[2], band[3], (int)band[4]);
905
      meshes[face] = new MeshPolygon(vertsFloat,bandsComputed,(int)band[5],(int)band[6], (float)convexXY[0], (float)convexXY[1]);
904
      meshes[face] = new MeshPolygon(verts,bandsComputed,(int)band[5],(int)band[6], convexXY[0], convexXY[1]);
906 905
      meshes[face].setEffectAssociation(0,(1<<face),0);
907 906
      }
908 907

  
......
914 913
      int assoc = (1<<face);
915 914
      fInfo = mNewFaceTransf.get(face);
916 915

  
917
      float vx = (float)fInfo.vx;
918
      float vy = (float)fInfo.vy;
919
      float vz = (float)fInfo.vz;
920
      float sc = (float)fInfo.scale;
921
      float qx = (float)fInfo.qx;
922
      float qy = (float)fInfo.qy;
923
      float qz = (float)fInfo.qz;
924
      float qw = (float)fInfo.qw;
916
      float vx = fInfo.vx;
917
      float vy = fInfo.vy;
918
      float vz = fInfo.vz;
919
      float sc = fInfo.scale;
920
      float qx = fInfo.qx;
921
      float qy = fInfo.qy;
922
      float qz = fInfo.qz;
923
      float qw = fInfo.qw;
925 924

  
926 925
      Static3D scale = new Static3D(sc,sc, fInfo.flip ? -sc : sc);
927 926
      Static3D move3D= new Static3D(vx,vy,vz);
src/main/java/org/distorted/objectlib/helpers/ObjectShape.java
25 25

  
26 26
public class ObjectShape
27 27
  {
28
  private final double[][] mVertices;
28
  private final float[][] mVertices;
29 29
  private final int[][] mVertIndices;
30 30
  private final int[] mBandIndices;
31 31
  private final float[][] mCorners;
......
39 39

  
40 40
///////////////////////////////////////////////////////////////////////////////////////////////////
41 41

  
42
  public ObjectShape(double[][] vertices, int[][] vertIndices, float[][] bands, int[] bandIndices,
42
  public ObjectShape(float[][] vertices, int[][] vertIndices, float[][] bands, int[] bandIndices,
43 43
                     float[][] corners, int[] cornIndices, float[][] centers, int[] centIndices,
44 44
                     int numComponents, float[] convexityCenter)
45 45
    {
......
71 71

  
72 72
///////////////////////////////////////////////////////////////////////////////////////////////////
73 73

  
74
  public double[][] getVertices()
74
  public float[][] getVertices()
75 75
    {
76 76
    return mVertices;
77 77
    }
src/main/java/org/distorted/objectlib/json/JsonReader.java
144 144
    mNumCubitVariants = object.length();
145 145
    mVariantFaceColor = new int[mNumCubitVariants][];
146 146
    mShapes = new ObjectShape[mNumCubitVariants];
147
    double[][][] verts = new double[mNumCubitVariants][][];
147
    float[][][] verts     = new float[mNumCubitVariants][][];
148
    float[][][] bands     = new float[mNumCubitVariants][][];
149
    float[][][] corners   = new float[mNumCubitVariants][][];
150
    float[][][] centers   = new float[mNumCubitVariants][][];
151
    float[][] convexity   = new float[mNumCubitVariants][];
148 152
    int[][] cornerIndices = new int[mNumCubitVariants][];
149 153
    int[][] centerIndices = new int[mNumCubitVariants][];
150
    int[][] bandIndices = new int[mNumCubitVariants][];
154
    int[][] bandIndices   = new int[mNumCubitVariants][];
151 155
    int[][][] vertIndices = new int[mNumCubitVariants][][];
152
    float[][][] bands = new float[mNumCubitVariants][][];
153
    float[][][] corners = new float[mNumCubitVariants][][];
154
    float[][][] centers = new float[mNumCubitVariants][][];
155
    float[][] convexity = new float[mNumCubitVariants][];
156 156

  
157 157
    mNumCubitFaces = -1;
158 158

  
......
163 163
      ////// vertices /////////////////////////////////////////////////
164 164
      JSONArray jsonVertices= jsonShape.getJSONArray("vertices");
165 165
      int numVertices = jsonVertices.length();
166
      verts[i] = new double[numVertices][3];
166
      verts[i] = new float[numVertices][3];
167 167
      cornerIndices[i] = new int[numVertices];
168 168
      centerIndices[i] = new int[numVertices];
169 169

  
170 170
      for(int j=0; j<numVertices; j++)
171 171
        {
172 172
        JSONObject vert = jsonVertices.getJSONObject(j);
173
        verts[i][j][0] = vert.getDouble("x");
174
        verts[i][j][1] = vert.getDouble("y");
175
        verts[i][j][2] = vert.getDouble("z");
173
        verts[i][j][0] = (float)vert.getDouble("x");
174
        verts[i][j][1] = (float)vert.getDouble("y");
175
        verts[i][j][2] = (float)vert.getDouble("z");
176 176
        cornerIndices[i][j] = vert.getInt("cornerIndex");
177 177
        centerIndices[i][j] = vert.getInt("centerIndex");
178 178
        }
src/main/java/org/distorted/objectlib/json/JsonWriter.java
190 190

  
191 191
///////////////////////////////////////////////////////////////////////////////////////////////////
192 192

  
193
  private JSONArray generateVertices(double[][] vertices, int[] cornerIndices, int[] centerIndices) throws JSONException
193
  private JSONArray generateVertices(float[][] vertices, int[] cornerIndices, int[] centerIndices) throws JSONException
194 194
    {
195 195
    JSONArray array = new JSONArray();
196 196
    int numVertices = vertices.length;
......
250 250
      ObjectShape shape = object.getObjectShape(i);
251 251

  
252 252
      float[] convexity  = shape.getConvexityCenter();
253
      double[][] vertices= shape.getVertices();
253
      float[][] vertices = shape.getVertices();
254 254
      int[][] vertIndices= shape.getVertIndices();
255 255
      float[][] bands    = shape.getBands();
256 256
      int[] bandIndices  = shape.getBandIndices();
src/main/java/org/distorted/objectlib/main/ObjectControl.java
27 27
import android.view.MotionEvent;
28 28

  
29 29
import org.distorted.library.main.QuatHelper;
30
import org.distorted.library.type.Static2D;
31 30
import org.distorted.library.type.Static4D;
32 31

  
33 32
import org.distorted.objectlib.helpers.BlockController;
......
64 63

  
65 64
    private float mRotAngle, mInitDistance;
66 65
    private float mStartRotX, mStartRotY;
67
    private float mAxisX, mAxisY;
68 66
    private float mRotationFactor;
69 67
    private int mLastCubitColor, mLastCubit;
70 68
    private int mCurrentAxis, mCurrentRow;
......
80 78
    private final boolean mIsAutomatic;
81 79

  
82 80
    private boolean mIsLocked, mRemLocked;
81
    private final int[] mBuffer;
82
    private final float[] mAxis;
83 83

  
84 84
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
85 85
    private static final Static4D mTemp= new Static4D(0,0,0,1);
86 86

  
87 87
    private static boolean mForcedIconMode = false;
88 88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
91
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
92

  
93
    private void computeCurrentAxis(Static4D axis)
94
      {
95
      Static4D result = QuatHelper.rotateVectorByQuat(axis, mQuat);
96

  
97
      mAxisX =result.get0();
98
      mAxisY =result.get1();
99

  
100
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
101
      mAxisX /= len;
102
      mAxisY /= len;
103
      }
104

  
105 89
///////////////////////////////////////////////////////////////////////////////////////////////////
106 90

  
107 91
    private void addSpeedProbe(float x, float y)
......
162 146

  
163 147
///////////////////////////////////////////////////////////////////////////////////////////////////
164 148

  
165
    private void replaceMode(TwistyObject object, boolean down)
149
    private void replaceMode(boolean down)
166 150
      {
167 151
      mBeginningRotation= false;
168 152

  
......
170 154
        {
171 155
        int color = mInterface.getCurrentColor();
172 156
        float[] point = mTouchControl.getTouchedPoint3D();
157
        TwistyObject object = mPreRender.getObject();
173 158
        mLastCubit = object.getCubit(point);
174 159
        mLastCubitColor = mInterface.cubitIsLocked(mLastCubit);
175 160
        int face;
......
213 198
        }
214 199
      else
215 200
        {
216
        TwistyObject object = mPreRender.getObject();
217
        CAMERA_POINT.set2( object==null ? 1.21f : mObjectNode.getCameraDist() );
218

  
201
        CAMERA_POINT.set2( mObjectNode.getCameraDist() );
219 202
        Static4D touchPoint = new Static4D(x, y, 0, 0);
220 203
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
221 204
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
222 205

  
223
        if( object!=null && mTouchControl !=null && mTouchControl.faceTouched(rotatedTouchPoint,rotatedCamera) )
206
        if( mTouchControl!=null && mTouchControl.objectTouched(rotatedTouchPoint,rotatedCamera) )
224 207
          {
225 208
          mDragging           = false;
226 209
          mContinuingRotation = false;
227 210

  
228
          if( mode==MODE_ROTATE )
229
            {
230
            mBeginningRotation= !mPreRender.isTouchBlocked();
231
            }
232
          else if( mode==MODE_REPLACE ) replaceMode(object,down);
211
               if( mode==MODE_ROTATE  ) mBeginningRotation = !mPreRender.isTouchBlocked();
212
          else if( mode==MODE_REPLACE ) replaceMode(down);
233 213
          }
234 214
        else
235 215
          {
......
311 291
      {
312 292
      float dx = x-mStartRotX;
313 293
      float dy = y-mStartRotY;
314
      float alpha = dx*mAxisX + dy*mAxisY;
315
      float x2 = dx - alpha*mAxisX;
316
      float y2 = dy - alpha*mAxisY;
294
      float alpha = dx*mAxis[0] + dy*mAxis[1];
295
      float x2 = dx - alpha*mAxis[0];
296
      float y2 = dy - alpha*mAxis[1];
317 297

  
318 298
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
319 299

  
320 300
      // we have the length of 1D vector 'angle', now the direction:
321
      float tmp = mAxisY==0 ? -mAxisX*y2 : mAxisY*x2;
301
      float tmp = mAxis[1]==0 ? -mAxis[0]*y2 : mAxis[1]*x2;
322 302

  
323 303
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
324 304
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
......
339 319

  
340 320
      Static4D touchPoint = new Static4D(x, y, 0, 0);
341 321
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
342
      Static2D res = mTouchControl.newRotation(rotatedTouchPoint);
322
      mTouchControl.newRotation(mBuffer,rotatedTouchPoint);
343 323

  
344
      mCurrentAxis = (int)res.get0();
345
      mCurrentRow  = (int)res.get1();
324
      mCurrentAxis = mBuffer[0];
325
      mCurrentRow  = mBuffer[1];
346 326

  
347
      computeCurrentAxis( mTouchControl.getCastedRotAxis(mCurrentAxis) );
327
      mTouchControl.getCastedRotAxis(mAxis,mQuat,mCurrentAxis);
348 328
      mRotationFactor = mTouchControl.returnRotationFactor(numLayers,mCurrentRow);
349 329

  
350 330
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
......
573 553
      {
574 554
      mIsAutomatic = false;
575 555

  
556
      mBuffer = new int[2];
557
      mAxis   = new float[2];
558

  
576 559
      mLastCubitColor = -1;
577 560
      mCurrRotSpeed   = 0.0f;
578 561

  
src/main/java/org/distorted/objectlib/main/TwistyObject.java
230 230
    setObjectRatioNow(scale,720);
231 231

  
232 232
    MatrixEffectScale scaleEffect = new MatrixEffectScale(mObjectScale);
233
    MatrixEffectQuaternion quatEffect  = new MatrixEffectQuaternion(mQuat, CENTER);
233
    MatrixEffectQuaternion quatEffect = new MatrixEffectQuaternion(mQuat, CENTER);
234 234
    MatrixEffectMove moveEffect = new MatrixEffectMove(move);
235 235

  
236 236
    mNumTexCols = NUM_STICKERS_IN_ROW;
......
1304 1304
      }
1305 1305
    }
1306 1306

  
1307
///////////////////////////////////////////////////////////////////////////////////////////////////
1308

  
1309
  public int getCubitQuatIndex(int cubit)
1310
    {
1311
    return CUBITS[cubit].mQuatIndex;
1312
    }
1313

  
1307 1314
///////////////////////////////////////////////////////////////////////////////////////////////////
1308 1315

  
1309 1316
  public Bitmap getStickerBitmap()
......
1329 1336

  
1330 1337
  public TouchControl getMovement()
1331 1338
    {
1332
    if( mTouchControl ==null )
1339
    if( mTouchControl==null )
1333 1340
      {
1334
      int[] numLayers = getNumLayers();
1335
      if( mCuts==null ) getCuts(numLayers);
1336
      if( mLayerRotatable==null ) mLayerRotatable = getLayerRotatable(numLayers);
1337
      if( mEnabled==null ) mEnabled = getEnabled();
1338

  
1339
      int movementType = getMovementType();
1340
      int movementSplit= getMovementSplit();
1341

  
1342
      switch(movementType)
1341
      switch(getMovementType())
1343 1342
        {
1344
        case TC_TETRAHEDRON : mTouchControl = new TouchControlTetrahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
1343
        case TC_TETRAHEDRON : mTouchControl = new TouchControlTetrahedron(this);
1345 1344
                              break;
1346
        case TC_HEXAHEDRON  : mTouchControl = new TouchControlHexahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
1345
        case TC_HEXAHEDRON  : mTouchControl = new TouchControlHexahedron(this);
1347 1346
                              break;
1348
        case TC_OCTAHEDRON  : mTouchControl = new TouchControlOctahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
1347
        case TC_OCTAHEDRON  : mTouchControl = new TouchControlOctahedron(this);
1349 1348
                              break;
1350
        case TC_DODECAHEDRON: mTouchControl = new TouchControlDodecahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
1349
        case TC_DODECAHEDRON: mTouchControl = new TouchControlDodecahedron(this);
1351 1350
                              break;
1352
        case TC_CUBOID      : float[] dist3D = getDist3D(numLayers);
1353
                              mTouchControl = new TouchControlCuboids(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled,dist3D);
1351
        case TC_CUBOID      : int[] numLayers = getNumLayers();
1352
                              mTouchControl = new TouchControlCuboids(this,getDist3D(numLayers));
1354 1353
                              break;
1355 1354
        }
1356 1355
      }
src/main/java/org/distorted/objectlib/objects/TwistyBandagedAbstract.java
176 176
    int maxXZ = Math.max(X,Z);
177 177
    int maxYZ = Math.max(Y,Z);
178 178

  
179
    double[][] vertices =
179
    float[][] vertices =
180 180
      {
181 181
        {+0.5f*X,+0.5f*Y,+0.5f*Z},
182 182
        {+0.5f*X,+0.5f*Y,-0.5f*Z},
src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java
228 228
        default: num = 5; extraI = 0; extraV = 0; height = 0.045f; break;
229 229
        }
230 230

  
231
    double[][] vertices = new double[][]
231
    float[][] vertices = new float[][]
232 232
          {
233
              { 0.5, 0.5, 0.5 },
234
              { 0.5, 0.5,-0.5 },
235
              { 0.5,-0.5, 0.5 },
236
              { 0.5,-0.5,-0.5 },
237
              {-0.5, 0.5, 0.5 },
238
              {-0.5, 0.5,-0.5 },
239
              {-0.5,-0.5, 0.5 },
240
              {-0.5,-0.5,-0.5 },
233
              { 0.5f, 0.5f, 0.5f },
234
              { 0.5f, 0.5f,-0.5f },
235
              { 0.5f,-0.5f, 0.5f },
236
              { 0.5f,-0.5f,-0.5f },
237
              {-0.5f, 0.5f, 0.5f },
238
              {-0.5f, 0.5f,-0.5f },
239
              {-0.5f,-0.5f, 0.5f },
240
              {-0.5f,-0.5f,-0.5f },
241 241
          };
242 242

  
243 243
    int[][] vert_indices = new int[][]
src/main/java/org/distorted/objectlib/objects/TwistyDiamond.java
387 387

  
388 388
    if( variant==0 )
389 389
      {
390
      double[][] vertices = new double[][]
390
      float[][] vertices = new float[][]
391 391
          {
392
             { 0.5,   0.0, 0.5},
393
             { 0.5,   0.0,-0.5},
394
             {-0.5,   0.0,-0.5},
395
             {-0.5,   0.0, 0.5},
396
             { 0.0, SQ2/2, 0.0},
397
             { 0.0,-SQ2/2, 0.0}
392
             { 0.5f,  0.0f, 0.5f},
393
             { 0.5f,  0.0f,-0.5f},
394
             {-0.5f,  0.0f,-0.5f},
395
             {-0.5f,  0.0f, 0.5f},
396
             { 0.0f, SQ2/2, 0.0f},
397
             { 0.0f,-SQ2/2, 0.0f}
398 398
          };
399 399

  
400 400
      int[][] vert_indices = new int[][]
......
419 419
      }
420 420
    else
421 421
      {
422
      double[][] vertices = new double[][] { {-0.5, SQ2/4, 0.0}, { 0.5, SQ2/4, 0.0}, { 0.0,-SQ2/4, 0.5}, { 0.0,-SQ2/4,-0.5} };
423
      int[][] vert_indices = new int[][]  { {2,1,0}, {2,3,1}, {3,2,0}, {3,0,1} };
422
      float[][] vertices  = new float[][] { {-0.5f, SQ2/4, 0.0f}, { 0.5f, SQ2/4, 0.0f}, { 0.0f,-SQ2/4, 0.5f}, { 0.0f,-SQ2/4,-0.5f} };
423
      int[][] vert_indices= new int[][]  { {2,1,0}, {2,3,1}, {3,2,0}, {3,0,1} };
424 424
      float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
425 425
      int[] bandIndices   = new int[] { 0,0,0,0 };
426 426
      float[][] corners   = new float[][] { {0.08f,0.15f} };
src/main/java/org/distorted/objectlib/objects/TwistyDino.java
194 194

  
195 195
  public ObjectShape getObjectShape(int variant)
196 196
    {
197
    double[][] vertices = new double[][] { {-1.5, 0.0, 0.0},{ 1.5, 0.0, 0.0},{ 0.0,-1.5, 0.0},{ 0.0, 0.0,-1.5} };
197
    float[][] vertices  = new float[][] { {-1.5f, 0.0f, 0.0f},{ 1.5f, 0.0f, 0.0f},{ 0.0f,-1.5f, 0.0f},{ 0.0f, 0.0f,-1.5f} };
198 198
    int[][] vert_indices= new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
199 199
    float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
200 200
    int[] bandIndices   = new int[] { 0,0,1,1 };
src/main/java/org/distorted/objectlib/objects/TwistyHelicopter.java
289 289
    {
290 290
    if( variant==0 )
291 291
      {
292
      double[][] vertices = new double[][]
292
      float[][] vertices = new float[][]
293 293
          {
294 294
            {-1.50f, 0.00f, 0.00f},
295 295
            { 0.00f,-1.50f, 0.00f},
......
318 318
      }
319 319
    else
320 320
      {
321
      double[][] vertices = new double[][]
321
      float[][] vertices = new float[][]
322 322
          {
323 323
            { 0.50f, 0.50f, 0.00f },
324 324
            {-1.00f, 0.50f, 0.00f },
src/main/java/org/distorted/objectlib/objects/TwistyIvy.java
237 237
    if( variant==0 )
238 238
      {
239 239
      final float angle = (float)Math.PI/(2*IVY_N);
240
      final float CORR  = 1.0f - 2*IVY_D;
240
      final float CORR  = 1-2*IVY_D;
241 241

  
242
      float[][] centers= new float[][] { {-1.0f,-1.0f,-1.0f} };
243
      float[][] corners= new float[][] { {0.05f,0.20f}, {0.04f,0.20f} };
242
      float[][] centers  = new float[][] { {-1.0f,-1.0f,-1.0f} };
243
      float[][] corners  = new float[][] { {0.05f,0.20f}, {0.04f,0.20f} };
244
      float[][] vertices = new float[3*(IVY_N+1)+4][3];
244 245
      int[] cornerIndices= new int[3*(IVY_N+1)+4];
245 246
      int[] centerIndices= new int[3*(IVY_N+1)+4];
246
      double[][] vertices= new double[3*(IVY_N+1)+4][3];
247 247
      int[][] vertIndices= new int[6][IVY_N+4];
248 248
      int[] bandIndices  = new int[] { 0,0,0,1,1,1 };
249 249

  
......
269 269
      centerIndices[2] = 0;
270 270
      centerIndices[3] = 0;
271 271

  
272
      vertices[0][0] = 0.0;
273
      vertices[0][1] = 0.0;
274
      vertices[0][2] = 0.0;
275
      vertices[1][0] =-2.0;
276
      vertices[1][1] = 0.0;
277
      vertices[1][2] = 0.0;
278
      vertices[2][0] = 0.0;
279
      vertices[2][1] =-2.0;
280
      vertices[2][2] = 0.0;
281
      vertices[3][0] = 0.0;
282
      vertices[3][1] = 0.0;
283
      vertices[3][2] =-2.0;
272
      vertices[0][0] = 0;
273
      vertices[0][1] = 0;
274
      vertices[0][2] = 0;
275
      vertices[1][0] =-2;
276
      vertices[1][1] = 0;
277
      vertices[1][2] = 0;
278
      vertices[2][0] = 0;
279
      vertices[2][1] =-2;
280
      vertices[2][2] = 0;
281
      vertices[3][0] = 0;
282
      vertices[3][1] = 0;
283
      vertices[3][2] =-2;
284 284

  
285 285
      vertIndices[0][0] = 2;
286 286
      vertIndices[0][1] = 0;
......
309 309

  
310 310
      for(int i=0; i<=IVY_N; i++)
311 311
        {
312
        double cos1 = Math.cos((IVY_N-i)*angle);
313
        double sin1 = Math.sin((IVY_N-i)*angle);
314
        double cos2 = Math.cos((      i)*angle);
315
        double sin2 = Math.sin((      i)*angle);
312
        float cos1 = (float)Math.cos((IVY_N-i)*angle);
313
        float sin1 = (float)Math.sin((IVY_N-i)*angle);
314
        float cos2 = (float)Math.cos((      i)*angle);
315
        float sin2 = (float)Math.sin((      i)*angle);
316 316

  
317
        vertices[N1+i][0] = CORR*(2*cos1-1.0) - 1.0;
318
        vertices[N1+i][1] = CORR*(2*sin1-1.0) - 1.0;
319
        vertices[N1+i][2] = 0.0;
317
        vertices[N1+i][0] = CORR*(2*cos1-1) - 1;
318
        vertices[N1+i][1] = CORR*(2*sin1-1) - 1;
319
        vertices[N1+i][2] = 0;
320 320

  
321
        vertices[N2+i][0] = 0.0;
322
        vertices[N2+i][1] = CORR*(2*sin2-1.0) - 1.0;
323
        vertices[N2+i][2] = CORR*(2*cos2-1.0) - 1.0;
321
        vertices[N2+i][0] = 0;
322
        vertices[N2+i][1] = CORR*(2*sin2-1) - 1;
323
        vertices[N2+i][2] = CORR*(2*cos2-1) - 1;
324 324

  
325
        vertices[N3+i][0] = CORR*(2*cos2-1.0) - 1.0;
326
        vertices[N3+i][1] = 0.0;
327
        vertices[N3+i][2] = CORR*(2*sin2-1.0) - 1.0;
325
        vertices[N3+i][0] = CORR*(2*cos2-1) - 1;
326
        vertices[N3+i][1] = 0;
327
        vertices[N3+i][2] = CORR*(2*sin2-1) - 1;
328 328

  
329 329
        vertIndices[0][i+3] = N1 + i;
330 330
        vertIndices[1][i+3] = N2 + i;
......
334 334
        vertIndices[5][i+3] = N3 + i;
335 335
        }
336 336

  
337
      float C = 1.0f - SQ2/2;
337
      float C = 1-SQ2/2;
338 338
      float[] convexCenter = new float[] {-C,-C,-C};
339 339
      return new ObjectShape(vertices,vertIndices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), convexCenter);
340 340
      }
341 341
    else
342 342
      {
343 343
      final float angle = (float)Math.PI/(2*IVY_N);
344
      final float CORR  = 1.0f - 2*IVY_D;
345
      double[][] vertices = new double[2*IVY_N][3];
344
      final float CORR  = 1-2*IVY_D;
345
      float[][] vertices = new float[2*IVY_N][3];
346 346
      int[][] vert_indices = new int[2][2*IVY_N];
347 347

  
348 348
      int[] bandIndices= new int[] { 0,1 };
......
352 352

  
353 353
      for(int i=0; i<IVY_N; i++)
354 354
        {
355
        double sin = Math.sin(i*angle);
356
        double cos = Math.cos(i*angle);
355
        float sin = (float)Math.sin(i*angle);
356
        float cos = (float)Math.cos(i*angle);
357 357

  
358
        vertices[i      ][0] = CORR*(1.0f-2*cos);
359
        vertices[i      ][1] = CORR*(1.0f-2*sin);
358
        vertices[i      ][0] = CORR*(1-2*cos);
359
        vertices[i      ][1] = CORR*(1-2*sin);
360 360
        vertices[i      ][2] = 0;
361
        vertices[i+IVY_N][0] = CORR*(2*cos-1.0f);
362
        vertices[i+IVY_N][1] = CORR*(2*sin-1.0f);
361
        vertices[i+IVY_N][0] = CORR*(2*cos-1);
362
        vertices[i+IVY_N][1] = CORR*(2*sin-1);
363 363
        vertices[i+IVY_N][2] = 0;
364 364
        }
365 365

  
src/main/java/org/distorted/objectlib/objects/TwistyJing.java
249 249

  
250 250
    if( variant==0 )
251 251
      {
252
      double[][] vertices = new double[][]
252
      float[][] vertices = new float[][]
253 253
          {
254
             { 0.0, 0.0, 0.0 },
254
             {   0,   0,   0 },
255 255
             {   X,   Y,   Z },
256
             { 0.0, 2*Y, 2*Z },
256
             {   0, 2*Y, 2*Z },
257 257
             {  -X,   Y,   Z },
258
             { 0.0, 0.0,    -F },
258
             {   0,   0,    -F },
259 259
             {   X,   Y,   Z-F },
260
             { 0.0, 2*Y, 2*Z-F },
260
             {   0, 2*Y, 2*Z-F },
261 261
             {  -X,   Y,   Z-F },
262 262
          };
263 263
      int[][] vert_indices = new int[][]
......
280 280
      }
281 281
    else if( variant==1 )
282 282
      {
283
      double[][] vertices = new double[][]
283
      float[][] vertices = new float[][]
284 284
          {
285
             { 0.0, 0.0,     G },
285
             {   0,   0,     G },
286 286
             {   X,   Y,   Z+G },
287
             { 0.0, 2*Y, 2*Z+G },
287
             {   0, 2*Y, 2*Z+G },
288 288
             {  -X,   Y,   Z+G },
289
             { 0.0, 0.0,    -G },
289
             {   0,   0,    -G },
290 290
             {   X,   Y,  -Z-G },
291
             { 0.0, 2*Y,-2*Z-G },
291
             {   0, 2*Y,-2*Z-G },
292 292
             {  -X,   Y,  -Z-G },
293 293
          };
294 294
      int[][] vert_indices = new int[][]
......
311 311
      }
312 312
    else
313 313
      {
314
      double[][] vertices = new double[][]
314
      float[][] vertices = new float[][]
315 315
          {
316
             {    0.0,     -2*Y2/3,   -2*Z2/3 },
317
             {      X2,       Y2/3,      Z2/3 },
318
             {     -X2,       Y2/3,      Z2/3 },
319
             {    0.0,     -2*Y2/3,-2*Z2/3+2*D*Z2 },
320
             {  X2-D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
321
             { -X2+D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
316
             {        0,   -2*Y2/3,       -2*Z2/3 },
317
             {       X2,      Y2/3,          Z2/3 },
318
             {      -X2,      Y2/3,          Z2/3 },
319
             {        0,   -2*Y2/3,-2*Z2/3+2*D*Z2 },
320
             {  X2-D*X2, Y2/3-D*Y2,     Z2/3+D*Z2 },
321
             { -X2+D*X2, Y2/3-D*Y2,     Z2/3+D*Z2 },
322 322
          };
323 323
      int[][] vert_indices = new int[][]
324 324
          {
src/main/java/org/distorted/objectlib/objects/TwistyKilominx.java
322 322
      float width = numL/(numL-1.0f);
323 323
      float A = (2*SQ3/3)*SIN54;
324 324
      float B = 0.4f;
325
      double X = width*COS18*SIN_HALFD;
326
      double Y = width*SIN18;
327
      double Z = width*COS18*COS_HALFD;
325
      float X = width*COS18*SIN_HALFD;
326
      float Y = width*SIN18;
327
      float Z = width*COS18*COS_HALFD;
328 328

  
329
      double[][] vertices = new double[][]
329
      float[][] vertices = new float[][]
330 330
        {
331
            { 0.0, 0.0      , 0.0 },
331
            {   0,   0      ,   0 },
332 332
            {   X,   Y      ,  -Z },
333
            { 0.0, 2*Y      ,-2*Z },
333
            {   0, 2*Y      ,-2*Z },
334 334
            {  -X,   Y      ,  -Z },
335
            { 0.0, 0.0-width, 0.0 },
335
            {   0,   0-width,   0 },
336 336
            {   X,   Y-width,  -Z },
337
            { 0.0, 2*Y-width,-2*Z },
337
            {   0, 2*Y-width,-2*Z },
338 338
            {  -X,   Y-width,  -Z },
339 339
        };
340 340

  
......
370 370
      float width = tmpVal + (type/2)*tmpVal*SIN18;
371 371
      boolean left = (type%2)==0;
372 372

  
373
      double X = height*SIN_HALFD;
374
      double Y = height*SIN18/COS18;
375
      double Z = height*COS_HALFD;
373
      float X = height*SIN_HALFD;
374
      float Y = height*SIN18/COS18;
375
      float Z = height*COS_HALFD;
376 376

  
377
      double[][] vertices = new double[][]
377
      float[][] vertices = new float[][]
378 378
        {
379
            { 0.0, 0.0   , 0.0 },
379
            {   0,   0   ,   0 },
380 380
            {   X,   Y   ,  -Z },
381
            { 0.0, 2*Y   ,-2*Z },
381
            {   0, 2*Y   ,-2*Z },
382 382
            {  -X,   Y   ,  -Z },
383
            { 0.0, -width, 0.0 },
383
            {   0, -width,   0 },
384 384
            {   X, -width,  -Z },
385
            { 0.0, -width,-2*Z },
385
            {   0, -width,-2*Z },
386 386
            {  -X, -width,  -Z },
387 387
        };
388 388

  
......
434 434
    else
435 435
      {
436 436
      float width = (1+0.5f*(numL-3)*SIN18)*numL/(numL-1);
437

  
438
      double X = width*COS18*SIN_HALFD;
439
      double Y = width*SIN18;
440
      double Z = width*COS18*COS_HALFD;
441
      double H = width*(SIN54/COS54);
442
      double H3= H/COS_HALFD;
443
      double X3= H*SIN_HALFD;
444
      double Z3= H*COS_HALFD;
445
      double C = 1/(COS54*Math.sqrt(2-2*SIN18));
437
      float X = width*COS18*SIN_HALFD;
438
      float Y = width*SIN18;
439
      float Z = width*COS18*COS_HALFD;
440
      float H = width*(SIN54/COS54);
441
      float H3= H/COS_HALFD;
442
      float X3= H*SIN_HALFD;
443
      float Z3= H*COS_HALFD;
444
      float C = 1/(COS54*(float)Math.sqrt(2-2*SIN18));
446 445
      int N = small ? 4 : 3;
447 446
      int E = small ? 1 : 0;
448 447

  
449
      double[][] vertices = new double[][]
448
      float[][] vertices = new float[][]
450 449
        {
451
            { 0.0, 0.0  ,   0.0 },
450
            {   0,   0  ,     0 },
452 451
            {   X,   Y  ,    -Z },
453
            { 0.0,C*2*Y ,-2*C*Z },
452
            {   0,C*2*Y ,-2*C*Z },
454 453
            {  -X,   Y  ,    -Z },
455
            { 0.0,-width,   0.0 },
454
            {   0,-width,     0 },
456 455
            {  X3,-width,   -Z3 },
457
            { 0.0,-width,   -H3 },
456
            {   0,-width,   -H3 },
458 457
            { -X3,-width,   -Z3 }
459 458
        };
460 459

  
src/main/java/org/distorted/objectlib/objects/TwistyMegaminx.java
264 264
      float width = numL*(0.5f-MEGA_D)/(0.5f*(numL-1));
265 265
      float A = (2*SQ3/3)*SIN54;
266 266
      float B = 0.4f;
267
      double X = width*COS18*SIN_HALFD;
268
      double Y = width*SIN18;
269
      double Z = width*COS18*COS_HALFD;
267
      float X = width*COS18*SIN_HALFD;
268
      float Y = width*SIN18;
269
      float Z = width*COS18*COS_HALFD;
270 270

  
271
      double[][] vertices = new double[][]
271
      float[][] vertices = new float[][]
272 272
        {
273
            { 0.0, 0.0      , 0.0 },
273
            {   0,   0      ,   0 },
274 274
            {   X,   Y      ,  -Z },
275
            { 0.0, 2*Y      ,-2*Z },
275
            {   0, 2*Y      ,-2*Z },
276 276
            {  -X,   Y      ,  -Z },
277
            { 0.0, 0.0-width, 0.0 },
277
            {   0,   0-width,   0 },
278 278
            {   X,   Y-width,  -Z },
279
            { 0.0, 2*Y-width,-2*Z },
279
            {   0, 2*Y-width,-2*Z },
280 280
            {  -X,   Y-width,  -Z },
281 281
        };
282 282

  
......
310 310
      float height= numL*(0.5f-MEGA_D)*COS18/((numL-1)*0.5f);
311 311
      float width = numL*2*MEGA_D + 2*type*height*SIN18/COS18;
312 312

  
313
      double W = width/2;
314
      double X = height*SIN_HALFD;
315
      double Y = height*SIN18/COS18;
316
      double Z = height*COS_HALFD;
313
      float W = width/2;
314
      float X = height*SIN_HALFD;
315
      float Y = height*SIN18/COS18;
316
      float Z = height*COS_HALFD;
317 317

  
318
      double[][] vertices = new double[][]
318
      float[][] vertices = new float[][]
319 319
        {
320
            { 0.0,   W   , 0.0 },
320
            {   0,   W   ,   0 },
321 321
            {   X, W+Y   ,  -Z },
322
            { 0.0, W+2*Y ,-2*Z },
322
            {   0, W+2*Y ,-2*Z },
323 323
            {  -X, W+Y   ,  -Z },
324
            { 0.0,  -W   , 0.0 },
324
            {   0,  -W   ,   0 },
325 325
            {   X,-W-Y   ,  -Z },
326
            { 0.0,-W-2*Y ,-2*Z },
326
            {   0,-W-2*Y ,-2*Z },
327 327
            {  -X,-W-Y   ,  -Z },
328 328
        };
329 329

  
......
355 355
    else
356 356
      {
357 357
      float width = 2*numL*(MEGA_D+(0.5f-MEGA_D)*SIN18);
358
      final double V = 0.83;   // ??
358
      final float V = 0.83f;   // ??
359 359
      final double ANGLE = V*Math.PI;
360
      final double cosA  = Math.cos(ANGLE);
361
      final double sinA  = Math.sin(ANGLE);
360
      final float cosA  = (float)Math.cos(ANGLE);
361
      final float sinA  = (float)Math.sin(ANGLE);
362 362

  
363 363
      float R  = 0.5f*width/COS54;
364 364
      float X1 = R*COS54;
......
366 366
      float X2 = R*COS18;
367 367
      float Y2 = R*SIN18;
368 368

  
369
      double[][] vertices = new double[][]
369
      float[][] vertices = new float[][]
370 370
        {
371 371
          {-X1,+Y1*sinA, Y1*cosA},
372 372
          {-X2,-Y2*sinA,-Y2*cosA},
373
          {0.0f,-R*sinA, -R*cosA},
373
          { 0 ,-R*sinA, -R*cosA},
374 374
          {+X2,-Y2*sinA,-Y2*cosA},
375 375
          {+X1,+Y1*sinA, Y1*cosA}
376 376
        };
src/main/java/org/distorted/objectlib/objects/TwistyMirror.java
441 441
    float ZL = -0.5f - (zrow==     0 ? DZ : 0);
442 442
    float ZR = +0.5f - (zrow==numL-1 ? DZ : 0);
443 443

  
444
    double[][] vertices = new double[][]
444
    float[][] vertices = new float[][]
445 445
          {
446 446
              { XR, YR, ZR },
447 447
              { XR, YR, ZL },
src/main/java/org/distorted/objectlib/objects/TwistyPyraminx.java
337 337

  
338 338
    if( variant==0 )
339 339
      {
340
      double[][] vertices = new double[][] { { 0.5,0.0,0.5},{ 0.5,0.0,-0.5},{-0.5,0.0,-0.5},{-0.5,0.0,0.5},{ 0.0,SQ2/2,0.0},{ 0.0,-SQ2/2,0.0} };
340
      float[][] vertices = new float[][] { { 0.5f,0.0f,0.5f},{ 0.5f,0.0f,-0.5f},{-0.5f,0.0f,-0.5f},{-0.5f,0.0f,0.5f},{ 0.0f,SQ2/2,0.0f},{ 0.0f,-SQ2/2,0.0f} };
341 341
      int[][] vert_indices = new int[][] { {3,0,4},{0,1,4},{1,2,4},{2,3,4},{5,0,3},{5,1,0},{5,2,1},{5,3,2} };
342 342
      int N = numL==3? 6 : 5;
343 343
      int E = numL==3? 2 : 1;
......
351 351
      }
352 352
    else
353 353
      {
354
      double[][] vertices = new double[][] { {-0.5, SQ2/4, 0.0},{ 0.5, SQ2/4, 0.0},{ 0.0,-SQ2/4, 0.5},{ 0.0,-SQ2/4,-0.5} };
354
      float[][] vertices = new float[][] { {-0.5f, SQ2/4, 0.0f},{ 0.5f, SQ2/4, 0.0f},{ 0.0f,-SQ2/4, 0.5f},{ 0.0f,-SQ2/4,-0.5f} };
355 355
      int[][] vert_indices = new int[][] { {2,1,0},{3,0,1},{3,2,0},{2,3,1} };
356 356
      int N = numL==3? 6 : 5;
357 357
      int E = numL==3? 2 : 1;
src/main/java/org/distorted/objectlib/objects/TwistyRedi.java
251 251
    {
252 252
    if( variant==0 )
253 253
      {
254
      double[][] vertices = new double[][]
254
      float[][] vertices = new float[][]
255 255
          {
256 256
             { 0.0f, 0.0f, 0.0f },
257 257
             {-0.5f, 0.5f, 0.5f },
......
287 287
      }
288 288
    else
289 289
      {
290
      double[][] vertices = new double[][]
290
      float[][] vertices = new float[][]
291 291
          {
292 292
             {-0.5f, 0.0f, 0.0f},
293 293
             { 0.5f, 0.0f, 0.0f},
src/main/java/org/distorted/objectlib/objects/TwistyRex.java
267 267
    if( variant==0 )
268 268
      {
269 269
      float G = (1-REX_D)*SQ2/2;
270
      double[][] vertices ={{-0.10f,0.70f,0},{-0.70f,0.10f,0},{+0.65f,-0.71f,0},{+0.71f,-0.65f,0}};
270
      float[][] vertices ={{-0.10f,0.70f,0},{-0.70f,0.10f,0},{+0.65f,-0.71f,0},{+0.71f,-0.65f,0}};
271 271
      int[][] vertIndexes = { {0,1,2,3},{3,2,1,0} };
272 272
      float[][] centers= new float[][] { {0.0f,0.0f,-G} };
273 273
      float[][] corners= new float[][] { {0.03f,0.30f} };
......
280 280
    else if( variant==1 )
281 281
      {
282 282
      float G = 3*REX_D;
283
      double[][] vertices= { { -G, 0, 0 },{ 0, -G, 0 },{ +G, 0, 0 },{ 0,+G,0 } };
283
      float[][] vertices= { { -G, 0, 0 },{ 0, -G, 0 },{ +G, 0, 0 },{ 0,+G,0 } };
284 284
      int[][] vertIndexes= { {0,1,2,3},{3,2,1,0} };
285 285
      int[] indices= {-1,-1,-1,-1};
286 286
      int[] bandIndices= new int[] { 0,1 };
......
293 293
      float E = 1.5f - 3*REX_D;
294 294
      float F = 1.5f;
295 295
      float G = (float)Math.sqrt(E*E+F*F);
296
      double[][] vertices = { { -F, 0, 0 },{  0,-E, 0 },{ +F, 0, 0 },{  0, 0,-E } };
296
      float[][] vertices = { { -F, 0, 0 },{  0,-E, 0 },{ +F, 0, 0 },{  0, 0,-E } };
297 297
      int[][] vertIndexes = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
298 298
      float[][] centers= new float[][] { {0.0f,-1.5f,-1.5f} };
299 299
      float[][] corners= new float[][] { {0.06f,0.20f} };
src/main/java/org/distorted/objectlib/objects/TwistySkewb.java
422 422

  
423 423
    if( variant==0 )
424 424
      {
425
      double[][] vertices = new double[][] { {-1,0,0},{0,-1,0},{0,0,-1},{-1,-1,-1},{0,0,0} };
425
      float[][] vertices = new float[][] { {-1,0,0},{0,-1,0},{0,0,-1},{-1,-1,-1},{0,0,0} };
426 426
      int[][] vert_indices = new int[][] { {0,1,4},{2,0,4},{1,2,4},{3,1,0},{3,2,1},{3,0,2} };
427 427
      int N = numL==2 ? 7:5;
428 428
      int E1= numL==2 ? 3:2;
......
437 437
      }
438 438
    else if( variant==1 )
439 439
      {
440
      double[][] vertices = new double[][] { {-1,0,0},{1,0,0},{0,-1,0},{0,0,-1} };
440
      float[][] vertices = new float[][] { {-1,0,0},{1,0,0},{0,-1,0},{0,0,-1} };
441 441
      int[][] vert_indices = new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
442 442
      int N = numL==2 ? 7:5;
443 443
      int E = numL==2 ? 5:2;
......
451 451
      }
452 452
    else
453 453
      {
454
      double[][] vertices = new double[][] { {-1,0,0},{0,-1,0},{1,0,0},{0,1,0},{0,0,-1} };
454
      float[][] vertices = new float[][] { {-1,0,0},{0,-1,0},{1,0,0},{0,1,0},{0,0,-1} };
455 455
      int[][] vert_indices = new int[][] { {0,1,2,3},{4,1,0},{4,2,1},{4,3,2},{4,0,3} };
456 456
      int N = numL==2 ? 7:6;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff