Project

General

Profile

« Previous | Next » 

Revision 4d883a92

Added by Leszek Koltunski about 3 years ago

Cubit creation: bugfixes. Cube, Tetrahedron, Dino cubits - all work.

View differences:

src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
38 38

  
39 39
class FactoryCubit
40 40
  {
41
  private static final float[] mBuffer = new float[3];
42
  private static final float[] mQuat1  = new float[4];
43
  private static final float[] mQuat2  = new float[4];
44
  private static final float[] mQuat3  = new float[4];
41
  private static final double[] mBuffer = new double[3];
42
  private static final double[] mQuat1  = new double[4];
43
  private static final double[] mQuat2  = new double[4];
44
  private static final double[] mQuat3  = new double[4];
45 45

  
46 46
  private static final Static1D RADIUS = new Static1D(1);
47 47

  
......
49 49

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

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

  
......
211 211

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

  
214
  private boolean areColinear(float[][] vertices, int index1, int index2, int index3)
214
  private boolean areColinear(double[][] vertices, int index1, int index2, int index3)
215 215
    {
216
    float x1 = vertices[index1][0];
217
    float y1 = vertices[index1][1];
218
    float z1 = vertices[index1][2];
219
    float x2 = vertices[index2][0];
220
    float y2 = vertices[index2][1];
221
    float z2 = vertices[index2][2];
222
    float x3 = vertices[index3][0];
223
    float y3 = vertices[index3][1];
224
    float z3 = vertices[index3][2];
225

  
226
    float v1x = x2-x1;
227
    float v1y = y2-y1;
228
    float v1z = z2-z1;
229
    float v2x = x3-x1;
230
    float v2y = y3-y1;
231
    float v2z = z3-z1;
232

  
233
    float A = (float)Math.sqrt( (v1x*v1x+v1y*v1y+v1z*v1z) / (v2x*v2x+v2y*v2y+v2z*v2z) );
216
    double x1 = vertices[index1][0];
217
    double y1 = vertices[index1][1];
218
    double z1 = vertices[index1][2];
219
    double x2 = vertices[index2][0];
220
    double y2 = vertices[index2][1];
221
    double z2 = vertices[index2][2];
222
    double x3 = vertices[index3][0];
223
    double y3 = vertices[index3][1];
224
    double z3 = vertices[index3][2];
225

  
226
    double v1x = x2-x1;
227
    double v1y = y2-y1;
228
    double v1z = z2-z1;
229
    double v2x = x3-x1;
230
    double v2y = y3-y1;
231
    double v2z = z3-z1;
232

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

  
235 235
    return (v1x==A*v2x && v1y==A*v2y && v1z==A*v2z);
236 236
    }
237 237

  
238 238
///////////////////////////////////////////////////////////////////////////////////////////////////
239 239

  
240
  private void computeNormalVector(float[][] vertices, int index1, int index2, int index3)
240
  private void computeNormalVector(double[][] vertices, int index1, int index2, int index3)
241 241
    {
242
    float x1 = vertices[index1][0];
243
    float y1 = vertices[index1][1];
244
    float z1 = vertices[index1][2];
245
    float x2 = vertices[index2][0];
246
    float y2 = vertices[index2][1];
247
    float z2 = vertices[index2][2];
248
    float x3 = vertices[index3][0];
249
    float y3 = vertices[index3][1];
250
    float z3 = vertices[index3][2];
251

  
252
    float v1x = x2-x1;
253
    float v1y = y2-y1;
254
    float v1z = z2-z1;
255
    float v2x = x3-x1;
256
    float v2y = y3-y1;
257
    float v2z = z3-z1;
242
    double x1 = vertices[index1][0];
243
    double y1 = vertices[index1][1];
244
    double z1 = vertices[index1][2];
245
    double x2 = vertices[index2][0];
246
    double y2 = vertices[index2][1];
247
    double z2 = vertices[index2][2];
248
    double x3 = vertices[index3][0];
249
    double y3 = vertices[index3][1];
250
    double z3 = vertices[index3][2];
251

  
252
    double v1x = x2-x1;
253
    double v1y = y2-y1;
254
    double v1z = z2-z1;
255
    double v2x = x3-x1;
256
    double v2y = y3-y1;
257
    double v2z = z3-z1;
258 258

  
259 259
    mBuffer[0] = v1y*v2z - v2y*v1z;
260 260
    mBuffer[1] = v1z*v2x - v2z*v1x;
261 261
    mBuffer[2] = v1x*v2y - v2x*v1y;
262 262

  
263
    float len = mBuffer[0]*mBuffer[0] + mBuffer[1]*mBuffer[1] + mBuffer[2]*mBuffer[2];
264
    len = (float)Math.sqrt(len);
263
    double len = mBuffer[0]*mBuffer[0] + mBuffer[1]*mBuffer[1] + mBuffer[2]*mBuffer[2];
264
    len = Math.sqrt(len);
265 265
    mBuffer[0] /= len;
266 266
    mBuffer[1] /= len;
267 267
    mBuffer[2] /= len;
......
270 270
///////////////////////////////////////////////////////////////////////////////////////////////////
271 271
// return quat1*quat2
272 272

  
273
  private static void quatMultiply( float[] quat1, float[] quat2, float[] result )
273
  private static void quatMultiply( double[] quat1, double[] quat2, double[] result )
274 274
    {
275
    float qx = quat1[0];
276
    float qy = quat1[1];
277
    float qz = quat1[2];
278
    float qw = quat1[3];
275
    double qx = quat1[0];
276
    double qy = quat1[1];
277
    double qz = quat1[2];
278
    double qw = quat1[3];
279 279

  
280
    float rx = quat2[0];
281
    float ry = quat2[1];
282
    float rz = quat2[2];
283
    float rw = quat2[3];
280
    double rx = quat2[0];
281
    double ry = quat2[1];
282
    double rz = quat2[2];
283
    double rw = quat2[3];
284 284

  
285 285
    result[0] = rw*qx - rz*qy + ry*qz + rx*qw;
286 286
    result[1] = rw*qy + rz*qx + ry*qw - rx*qz;
......
290 290

  
291 291
///////////////////////////////////////////////////////////////////////////////////////////////////
292 292

  
293
  private void fitInSquare(FaceInfo info, float[][] vert3D)
293
  private void fitInSquare(FaceInfo info, double[][] vert3D)
294 294
    {
295
    float minX = Float.MAX_VALUE;
296
    float maxX =-Float.MAX_VALUE;
297
    float minY = Float.MAX_VALUE;
298
    float maxY =-Float.MAX_VALUE;
295
    double minX = Double.MAX_VALUE;
296
    double maxX =-Double.MAX_VALUE;
297
    double minY = Double.MAX_VALUE;
298
    double maxY =-Double.MAX_VALUE;
299 299

  
300
    for (float[] vert : vert3D)
300
    for (double[] vert : vert3D)
301 301
      {
302
      float x = vert[0];
303
      float y = vert[1];
302
      double x = vert[0];
303
      double y = vert[1];
304 304

  
305 305
      if (x > maxX) maxX = x;
306 306
      if (x < minX) minX = x;
......
312 312

  
313 313
    int len = vert3D.length;
314 314
    StickerInfo sInfo = new StickerInfo();
315
    sInfo.vertices = new float[2*len];
315
    sInfo.vertices = new double[2*len];
316 316

  
317 317
    for( int vertex=0; vertex<len; vertex++ )
318 318
      {
......
328 328

  
329 329
///////////////////////////////////////////////////////////////////////////////////////////////////
330 330

  
331
  private void constructNew(FaceInfo info, final float[][] vert3D)
331
  private void constructNew(FaceInfo info, final double[][] vert3D)
332 332
    {
333 333
    // compute center of gravity
334 334
    info.vx = 0.0f;
......
336 336
    info.vz = 0.0f;
337 337
    int len = vert3D.length;
338 338

  
339
    for (float[] vert : vert3D)
339
    for (double[] vert : vert3D)
340 340
      {
341 341
      info.vx += vert[0];
342 342
      info.vy += vert[1];
......
376 376
    computeNormalVector(vert3D,0,1,foundIndex);
377 377

  
378 378
    // rotate so that the normal vector becomes (0,0,1)
379
    float axisX, axisY, axisZ;
379
    double axisX, axisY, axisZ;
380 380

  
381 381
    if( mBuffer[0]!=0.0f || mBuffer[1]!=0.0f )
382 382
      {
......
384 384
      axisY =  mBuffer[0];
385 385
      axisZ = 0.0f;
386 386

  
387
      float axiLen = axisX*axisX + axisY*axisY;
388
      axiLen = (float)Math.sqrt(axiLen);
387
      double axiLen = axisX*axisX + axisY*axisY;
388
      axiLen = Math.sqrt(axiLen);
389 389
      axisX /= axiLen;
390 390
      axisY /= axiLen;
391 391
      axisZ /= axiLen;
......
397 397
      axisZ = 0.0f;
398 398
      }
399 399

  
400
    float cosTheta = mBuffer[2];
401
    float sinHalfTheta = (float)Math.sqrt(0.5f*(1-cosTheta));
402
    float cosHalfTheta = (float)Math.sqrt(0.5f*(1+cosTheta));
400
    double cosTheta = mBuffer[2];
401
    double sinTheta = Math.sqrt(1-cosTheta*cosTheta);
402
    double sinHalfTheta = computeSinHalf(cosTheta);
403
    double cosHalfTheta = computeCosHalf(sinTheta,cosTheta);
403 404

  
404 405
    mQuat1[0] = axisX*sinHalfTheta;
405 406
    mQuat1[1] = axisY*sinHalfTheta;
......
410 411
    mQuat2[2] =-axisZ*sinHalfTheta;
411 412
    mQuat2[3] = cosHalfTheta;
412 413

  
413
    for (float[] vert : vert3D)
414
    for (double[] vert : vert3D)
414 415
      {
415 416
      quatMultiply(mQuat1, vert  , mQuat3);
416 417
      quatMultiply(mQuat3, mQuat2, vert  );
......
428 429

  
429 430
///////////////////////////////////////////////////////////////////////////////////////////////////
430 431

  
431
  private float computeCos(float x1, float y1, float x2, float y2, float len1, float len2)
432
  private double computeCos(double oldX, double oldY, double newX, double newY, double len1, double len2)
432 433
    {
433
    float ret =  (x1*x2+y1*y2) / (len1*len2);
434
    double ret =  (oldX*newX+oldY*newY) / (len1*len2);
434 435

  
435
    if( ret> 1.0f ) return  1.0f;
436
    if( ret<-1.0f ) return -1.0f;
436
    if( ret> 1.0f ) return  1.0;
437
    if( ret<-1.0f ) return -1.0;
437 438

  
438 439
    return ret;
439 440
    }
440 441

  
441 442
///////////////////////////////////////////////////////////////////////////////////////////////////
442
// sin of (signed!) angle between vectors (x1,y1) and (x2,y2), counterclockwise!
443
// sin of (signed!) angle between vectors 'old' and 'new', counterclockwise!
443 444

  
444
  private float computeSin(float x1, float y1, float x2, float y2, float len1, float len2)
445
  private double computeSin(double oldX, double oldY, double newX, double newY, double len1, double len2)
445 446
    {
446
    float ret = (x2*y1-x1*y2) / (len1*len2);
447
    double ret = (newX*oldY-oldX*newY) / (len1*len2);
447 448

  
448
    if( ret> 1.0f ) return  1.0f;
449
    if( ret<-1.0f ) return -1.0f;
449
    if( ret> 1.0f ) return  1.0;
450
    if( ret<-1.0f ) return -1.0;
450 451

  
451 452
    return ret;
452 453
    }
453 454

  
454 455
///////////////////////////////////////////////////////////////////////////////////////////////////
455 456

  
456
  private void rotateAllVertices(float[] result, int len, float[] vertices, float sin, float cos)
457
  private void rotateAllVertices(double[] result, int len, double[] vertices, double sin, double cos)
457 458
    {
458 459
    for(int i=0; i<len; i++)
459 460
      {
......
464 465

  
465 466
///////////////////////////////////////////////////////////////////////////////////////////////////
466 467

  
467
  private boolean isScaledVersionOf(float[] v1, float[] v2, int len)
468
  private double computeScale(double[] v1, double[] v2)
468 469
    {
469
    float EPSILON = 0.001f;
470
    float scale = v1[0]!=0.0f ? v2[0]/v1[0] : v2[1]/v1[1];
470
    double lenSq1 = v1[0]*v1[0] + v1[1]*v1[1];
471
    double lenSq2 = v2[0]*v2[0] + v2[1]*v2[1];
472

  
473
    return Math.sqrt(lenSq2/lenSq1);
474
    }
475

  
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477

  
478
  private double computeSinHalf(double cos)
479
    {
480
    return Math.sqrt((1-cos)/2);
481
    }
482

  
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484

  
485
  private double computeCosHalf(double sin, double cos)
486
    {
487
    double cosHalf = Math.sqrt((1+cos)/2);
488
    return sin<0 ? -cosHalf : cosHalf;
489
    }
490

  
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492

  
493
  private boolean isScaledVersionOf(double[] newVert, double[] oldVert, int len)
494
    {
495
    double EPSILON = 0.001;
496
    double scale = computeScale(newVert,oldVert);
471 497

  
472 498
    for(int i=1; i<len; i++)
473 499
      {
474
      float horz = v2[2*i  ] - scale*v1[2*i  ];
475
      float vert = v2[2*i+1] - scale*v1[2*i+1];
500
      double horz = oldVert[2*i  ] - scale*newVert[2*i  ];
501
      double vert = oldVert[2*i+1] - scale*newVert[2*i+1];
476 502

  
477 503
      if( horz>EPSILON || horz<-EPSILON || vert>EPSILON || vert<-EPSILON ) return false;
478 504
      }
......
482 508

  
483 509
///////////////////////////////////////////////////////////////////////////////////////////////////
484 510

  
485
  private void mirrorAllVertices(float[] output, int len, float[] input)
511
  private void mirrorAllVertices(double[] output, int len, double[] input)
486 512
    {
487 513
    for(int vertex=0; vertex<len; vertex++)
488 514
      {
......
493 519

  
494 520
///////////////////////////////////////////////////////////////////////////////////////////////////
495 521

  
496
  private void correctInfo(FaceInfo info, float scale, float cos, int oldSticker, boolean flip)
522
  private void correctInfo(FaceInfo info, double scale, double sin, double cos, int oldSticker, boolean flip)
497 523
    {
498 524
    mStickerInfo.remove(info.sticker);
499 525

  
......
506 532
    mQuat1[2] = info.qz;
507 533
    mQuat1[3] = info.qw;
508 534

  
509
    float sinHalf = (float)Math.sqrt(0.5f*(1-cos));
510
    float cosHalf = (float)Math.sqrt(0.5f*(1+cos));
535
    double sinHalf = computeSinHalf(cos);
536
    double cosHalf = computeCosHalf(sin,cos);
511 537

  
512 538
    mQuat2[0] = 0.0f;
513 539
    mQuat2[1] = 0.0f;
......
524 550

  
525 551
///////////////////////////////////////////////////////////////////////////////////////////////////
526 552

  
527
  private boolean foundVertex(FaceInfo info, float[] buffer, int len, float[] preVert,
528
                              float[] newVert, float lenVert, int oldSticker, boolean inverted)
553
  private boolean foundVertex(FaceInfo info, double[] buffer, int len, double[] newVert,
554
                              double[] oldVert, double lenFirstOld, int oldSticker, boolean inverted)
529 555
    {
530 556
    for(int vertex=0; vertex<len; vertex++)
531 557
      {
532
      float xR = preVert[2*vertex  ];
533
      float yR = preVert[2*vertex+1];
534
      float lenRotV = (float)Math.sqrt(xR*xR+yR*yR);
535
      float cos = computeCos(xR,yR,newVert[0],newVert[1], lenRotV, lenVert);
536
      float sin = computeSin(xR,yR,newVert[0],newVert[1], lenRotV, lenVert);
558
      double newX = newVert[2*vertex  ];
559
      double newY = newVert[2*vertex+1];
560
      double lenIthNew = Math.sqrt(newX*newX + newY*newY);
561
      double cos = computeCos( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
562
      double sin = computeSin( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
537 563

  
538 564
      rotateAllVertices(buffer,len,newVert,sin,cos);
539 565

  
540
      if( isScaledVersionOf(buffer,preVert,len) )
566
      if( isScaledVersionOf(buffer,oldVert,len) )
541 567
        {
542
        float scale = preVert[0]!=0.0f ? buffer[0]/preVert[0] : buffer[1]/preVert[1];
543
        correctInfo(info,scale,cos,oldSticker,inverted);
568
        double scale = computeScale(oldVert,newVert);
569
        correctInfo(info,scale,sin,cos,oldSticker,inverted);
544 570
        return true;
545 571
        }
546 572
      }
......
550 576

  
551 577
///////////////////////////////////////////////////////////////////////////////////////////////////
552 578

  
553
  private boolean successfullyCollapsedStickers(final FaceInfo newInfo, final FaceInfo preInfo)
579
  private boolean successfullyCollapsedStickers(final FaceInfo newInfo, final FaceInfo oldInfo)
554 580
    {
555 581
    StickerInfo sNewInfo = mStickerInfo.get(newInfo.sticker);
556
    StickerInfo sPreInfo = mStickerInfo.get(preInfo.sticker);
557
    int len = sPreInfo.vertices.length;
558
    float[] newVert = sNewInfo.vertices;
582
    StickerInfo sOldInfo = mStickerInfo.get(oldInfo.sticker);
583
    double[] newVert = sNewInfo.vertices;
584
    double[] oldVert = sOldInfo.vertices;
585
    int oldLen = oldVert.length;
586
    int newLen = newVert.length;
559 587

  
560
    if( len == newVert.length )
588
    if( oldLen == newLen )
561 589
      {
562
      int oldSticker = preInfo.sticker;
563
      float[] tmp1 = new float[len];
564
      float lenVert = (float)Math.sqrt(newVert[0]*newVert[0] + newVert[1]*newVert[1]);
565
      if( foundVertex(newInfo, tmp1, len/2, sPreInfo.vertices, newVert, lenVert, oldSticker, false) ) return true;
566
      float[] tmp2 = new float[len];
567
      mirrorAllVertices(tmp2,len/2,sPreInfo.vertices);
568
      if( foundVertex(newInfo, tmp1, len/2, tmp2             , newVert, lenVert, oldSticker, true ) ) return true;
590
      int oldSticker = oldInfo.sticker;
591
      double[] buffer1 = new double[oldLen];
592
      double lenFirstOld = Math.sqrt(newVert[0]*newVert[0] + newVert[1]*newVert[1]);
593
      if( foundVertex(newInfo, buffer1, oldLen/2, newVert, oldVert, lenFirstOld, oldSticker, false) ) return true;
594
      double[] buffer2 = new double[oldLen];
595
      mirrorAllVertices(buffer2, newLen/2, newVert);
596
      if( foundVertex(newInfo, buffer1, oldLen/2, buffer2, oldVert, lenFirstOld, oldSticker, true ) ) return true;
569 597
      }
570 598

  
571 599
    return false;
......
573 601

  
574 602
///////////////////////////////////////////////////////////////////////////////////////////////////
575 603

  
576
  private float[][] constructVert(float[][] vertices, int[] index)
604
  private double[][] constructVert(double[][] vertices, int[] index)
577 605
    {
578 606
    int len = index.length;
579
    float[][] ret = new float[len][4];
607
    double[][] ret = new double[len][4];
580 608

  
581 609
    for(int i=0; i<len; i++)
582 610
      {
......
591 619

  
592 620
///////////////////////////////////////////////////////////////////////////////////////////////////
593 621

  
594
  private void prepareFaceInfo( final float[][] vertices, final int[][] indexes)
622
  private void prepareFaceInfo( final double[][] vertices, final int[][] indexes)
595 623
    {
596 624
    mFaceInfo.clear();
597 625
    mStickerInfo.clear();
598 626

  
599 627
    int numFaces = indexes.length;
600
    FaceInfo preInfo;
628
    FaceInfo oldInfo;
601 629

  
602 630
    for(int face=0; face<numFaces; face++)
603 631
      {
604 632
      FaceInfo newInfo = new FaceInfo();
605 633
      int[] index = indexes[face];
606
      float[][] vert = constructVert(vertices,index);
634
      double[][] vert = constructVert(vertices,index);
607 635
      constructNew(newInfo,vert);
608 636

  
609 637
      for(int previous=0; previous<face; previous++)
610 638
        {
611
        preInfo = mFaceInfo.get(previous);
612
        if( successfullyCollapsedStickers(newInfo,preInfo) ) break;
639
        oldInfo = mFaceInfo.get(previous);
640
        if( successfullyCollapsedStickers(newInfo,oldInfo) ) break;
613 641
        }
614 642

  
615 643
      mFaceInfo.add(newInfo);
......
618 646

  
619 647
///////////////////////////////////////////////////////////////////////////////////////////////////
620 648

  
621
  private void prepareAndRoundCorners(MeshBase mesh, float[][] vertices, int[][] vertIndexes,
649
  private void prepareAndRoundCorners(MeshBase mesh, double[][] vertices, int[][] vertIndexes,
622 650
                                      float[][] corners, int[] cornerIndexes )
623 651
    {
624 652
    int numNeig, lenFV;
......
626 654
    int[] verts = new int[2*(lenV-1)];
627 655
    Static3D[] staticVert = new Static3D[1];
628 656
    Static3D center = new Static3D(0,0,0);
629
    float cx, cy, cz;
630
    float[] singleV;
657
    double cx, cy, cz;
658
    double[] singleV;
631 659

  
632 660
    for(int v=0; v<lenV; v++)
633 661
      {
......
660 688
        cy += singleV[1];
661 689
        cz += singleV[2];
662 690
        }
663
      center.set(cx/numNeig - vertices[v][0],cy/numNeig - vertices[v][1],cz/numNeig - vertices[v][2]);
691
      center.set( (float)(cx/numNeig - vertices[v][0]),
692
                  (float)(cy/numNeig - vertices[v][1]),
693
                  (float)(cz/numNeig - vertices[v][2]));
664 694

  
665 695
      // round Corners
666
      staticVert[0] = new Static3D(vertices[v][0], vertices[v][1], vertices[v][2]);
696
      staticVert[0] = new Static3D( (float)vertices[v][0], (float)vertices[v][1], (float)vertices[v][2]);
667 697

  
668 698
      int corn = cornerIndexes[v];
669 699
      float strength = corners[corn][0];
......
712 742

  
713 743
///////////////////////////////////////////////////////////////////////////////////////////////////
714 744

  
715
  MeshBase createRoundedSolid(final float[][] vertices, final int[][] vertIndexes,
716
                              final float[][] bands   , final int[]   bandIndexes,
717
                              final float[][] corners , final int[]   cornerIndexes)
745
  MeshBase createRoundedSolid(final double[][] vertices, final int[][] vertIndexes,
746
                              final float[][] bands    , final int[]   bandIndexes,
747
                              final float[][] corners  , final int[]   cornerIndexes)
718 748
    {
719 749
    int EFFECTS_PER_FACE = 3;
720 750

  
......
733 763
      fInfo = mFaceInfo.get(face);
734 764
      sInfo = mStickerInfo.get(fInfo.sticker);
735 765

  
766
      double[] verts = sInfo.vertices;
767
      int lenVerts = verts.length;
768
      float[] vertsFloat = new float[lenVerts];
769
      for(int i=0; i<lenVerts; i++) vertsFloat[i] = (float)verts[i];
770

  
736 771
      band = bands[bandIndexes[face]];
737 772
      bandsComputed = computeBands( band[0], (int)band[1], band[2], band[3], (int)band[4]);
738
      meshes[face] = new MeshPolygon(sInfo.vertices,bandsComputed,(int)band[5],(int)band[6]);
773
      meshes[face] = new MeshPolygon(vertsFloat,bandsComputed,(int)band[5],(int)band[6]);
739 774
      meshes[face].setEffectAssociation(0,(1<<face),0);
740 775
      }
741 776

  
......
748 783
      int assoc = (1<<face);
749 784
      fInfo = mFaceInfo.get(face);
750 785

  
751
      Static3D move3D= new Static3D(fInfo.vx,fInfo.vy,fInfo.vz);
752
      Static3D scale = new Static3D(fInfo.scale,fInfo.scale, fInfo.flip ? -fInfo.scale : fInfo.scale);
753
      Static4D quat  = new Static4D(fInfo.qx,fInfo.qy,fInfo.qz,fInfo.qw);
786
      float vx = (float)fInfo.vx;
787
      float vy = (float)fInfo.vy;
788
      float vz = (float)fInfo.vz;
789
      float sc = (float)fInfo.scale;
790
      float qx = (float)fInfo.qx;
791
      float qy = (float)fInfo.qy;
792
      float qz = (float)fInfo.qz;
793
      float qw = (float)fInfo.qw;
794

  
795
      Static3D move3D= new Static3D(vx,vy,vz);
796
      Static3D scale = new Static3D(sc,sc, fInfo.flip ? -sc : sc);
797
      Static4D quat  = new Static4D(qx,qy,qz,qw);
754 798

  
755 799
      effects[EFFECTS_PER_FACE*face  ] = new MatrixEffectScale(scale);
756 800
      effects[EFFECTS_PER_FACE*face+1] = new MatrixEffectQuaternion(quat,center);
src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
38 38
import org.distorted.library.main.DistortedTexture;
39 39
import org.distorted.library.mesh.MeshBase;
40 40
import org.distorted.library.mesh.MeshFile;
41
import org.distorted.library.mesh.MeshPolygon;
42 41
import org.distorted.library.type.DynamicQuat;
43 42
import org.distorted.library.type.Static3D;
44 43
import org.distorted.library.type.Static4D;
......
249 248
      return bitmap;
250 249
      }
251 250

  
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

  
254
  private MeshBase createStaticMesh()
255
    {
256
    final float IVY_D = 0.10f;
257
    final int   IVY_N = 8;
258

  
259
    final float angle = (float)Math.PI/(2*IVY_N);
260
    final float CORR  = 1.0f - IVY_D*SQ2;
261
    final float DIST  = 0.4f;
262
    final float CORR2 = 0.5f;
263
    float[] vertices = new float[2*(IVY_N+1)+6];
264

  
265
    vertices[0] = ( 0.5f      -DIST)*CORR2;
266
    vertices[1] = (-0.5f+IVY_D-DIST)*CORR2;
267
    vertices[2] = ( 0.5f      -DIST)*CORR2;
268
    vertices[3] = ( 0.5f      -DIST)*CORR2;
269
    vertices[4] = (-0.5f+IVY_D-DIST)*CORR2;
270
    vertices[5] = ( 0.5f      -DIST)*CORR2;
271

  
272
    for(int i=0; i<=IVY_N; i++)
273
      {
274
      float ang = (IVY_N-i)*angle;
275
      float sin = (float)Math.sin(ang);
276
      float cos = (float)Math.cos(ang);
277

  
278
      vertices[2*i+6] = (CORR*(cos-0.5f)-DIST)*CORR2;
279
      vertices[2*i+7] = (CORR*(sin-0.5f)-DIST)*CORR2;
280
      }
281

  
282
    float[] bands = new float[] {1.0f, 0.0f, 0.5f, 0.03f, 0.0f, 0.05f};
283

  
284
    MeshBase mesh = new MeshPolygon(vertices,bands,0,0);
285
    mesh.setShowNormals(true);
286

  
287
    return mesh;
288
    }
289

  
290 251
///////////////////////////////////////////////////////////////////////////////////////////////////
291 252

  
292 253
    private void createMesh()
293 254
      {
294 255
      int mode = 2;
295
      float[][] vertices  = null;
256
      double[][] vertices = null;
296 257
      int[][] vertIndexes = null;
297 258
      float[][] bands     = null;
298 259
      int[] bandIndexes   = null;
299 260
      float[][] corners   = null;
300 261
      int[] cornerIndexes = null;
301 262

  
302
      if( mode==0 ) // CUBE
263
      ///// CUBE ////////////////////////////////////////////////////////////////////////////////
264

  
265
      if( mode==0 )
303 266
        {
304
        vertices = new float[][]
267
        vertices = new double[][]
305 268
          {
306
              { 0.5f, 0.5f, 0.5f },
307
              { 0.5f, 0.5f,-0.5f },
308
              { 0.5f,-0.5f, 0.5f },
309
              { 0.5f,-0.5f,-0.5f },
310
              {-0.5f, 0.5f, 0.5f },
311
              {-0.5f, 0.5f,-0.5f },
312
              {-0.5f,-0.5f, 0.5f },
313
              {-0.5f,-0.5f,-0.5f },
269
              { 0.5, 0.5, 0.5 },
270
              { 0.5, 0.5,-0.5 },
271
              { 0.5,-0.5, 0.5 },
272
              { 0.5,-0.5,-0.5 },
273
              {-0.5, 0.5, 0.5 },
274
              {-0.5, 0.5,-0.5 },
275
              {-0.5,-0.5, 0.5 },
276
              {-0.5,-0.5,-0.5 },
314 277
          };
315 278

  
316 279
        vertIndexes = new int[][]
......
337 300

  
338 301
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
339 302
        }
340
      else if( mode==1 ) // TETRAHEDRON
303

  
304
      ///// TETRAHEDRON //////////////////////////////////////////////////////////////////////////
305

  
306
      else if( mode==1 )
341 307
        {
342
        vertices = new float[][]
308
        vertices = new double[][]
343 309
          {
344
              {-0.5f, SQ2/4, 0.0f},
345
              { 0.5f, SQ2/4, 0.0f},
346
              { 0.0f,-SQ2/4, 0.5f},
347
              { 0.0f,-SQ2/4,-0.5f}
310
              {-0.5, SQ2/4, 0.0},
311
              { 0.5, SQ2/4, 0.0},
312
              { 0.0,-SQ2/4, 0.5},
313
              { 0.0,-SQ2/4,-0.5}
348 314
          };
349 315

  
350 316
        vertIndexes = new int[][]
......
369 335

  
370 336
        cornerIndexes = new int[] { 0,0,0,0 };
371 337
        }
372
      else if( mode==2 )  // DINO
338

  
339
      ///// DINO ////////////////////////////////////////////////////////////////////////////////
340

  
341
      else if( mode==2 )
373 342
        {
374
        vertices = new float[][]
343
        vertices = new double[][]
375 344
          {
376
              {-0.5f, 0.0f, 0.0f},
377
              { 0.5f, 0.0f, 0.0f},
378
              { 0.0f,-0.5f, 0.0f},
379
              { 0.0f, 0.0f,-0.5f}
345
              {-0.5, 0.0, 0.0},
346
              { 0.5, 0.0, 0.0},
347
              { 0.0,-0.5, 0.0},
348
              { 0.0, 0.0,-0.5}
380 349
          };
381 350

  
382 351
        vertIndexes = new int[][]

Also available in: Unified diff