Project

General

Profile

« Previous | Next » 

Revision 6a96e571

Added by Leszek Koltunski over 3 years ago

Cubit creation: center the textures. Add octahedron.

View differences:

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

  
20 20
package org.distorted.examples.meshfile;
21 21

  
22
import org.distorted.library.effect.MatrixEffect;
23 22
import org.distorted.library.effect.MatrixEffectMove;
24 23
import org.distorted.library.effect.MatrixEffectQuaternion;
25 24
import org.distorted.library.effect.MatrixEffectScale;
......
50 49
  private static class StickerInfo
51 50
    {
52 51
    double[] vertices;
52
    double dx,dy;
53 53
    }
54 54

  
55 55
  private static class FaceInfo
......
607 607
    return ret;
608 608
    }
609 609

  
610
///////////////////////////////////////////////////////////////////////////////////////////////////
611

  
612
  private void centerTextures()
613
    {
614
    int numStickers = mStickerInfo.size();
615
    StickerInfo info;
616

  
617
    for(int sticker=0; sticker<numStickers; sticker++)
618
      {
619
      double minX = Double.MAX_VALUE;
620
      double minY = Double.MAX_VALUE;
621
      double maxX =-Double.MAX_VALUE;
622
      double maxY =-Double.MAX_VALUE;
623

  
624
      info = mStickerInfo.get(sticker);
625
      double[] vert = info.vertices;
626
      int numVert = vert.length/2;
627

  
628
      for ( int v=0; v<numVert; v++)
629
        {
630
        double x = vert[2*v  ];
631
        double y = vert[2*v+1];
632

  
633
        if (x < minX) minX = x;
634
        if (y < minY) minY = y;
635
        if (x > maxX) maxX = x;
636
        if (y > maxY) maxY = y;
637
        }
638

  
639
      info.dx = info.dy = 0.0;
640

  
641
      if( minX<-0.5 ) info.dx = minX + 0.5;
642
      if( minY<-0.5 ) info.dy = minY + 0.5;
643
      if( maxX> 0.5 ) info.dx = maxX - 0.5;
644
      if( maxY> 0.5 ) info.dy = maxY - 0.5;
645

  
646
      for ( int v=0; v<numVert; v++)
647
        {
648
        vert[2*v  ] -= info.dx;
649
        vert[2*v+1] -= info.dy;
650
        }
651
      }
652
    }
653

  
610 654
///////////////////////////////////////////////////////////////////////////////////////////////////
611 655

  
612 656
  private void prepareFaceInfo( final double[][] vertices, final int[][] indexes)
......
632 676

  
633 677
      mFaceInfo.add(newInfo);
634 678
      }
679

  
680
    centerTextures();
635 681
    }
636 682

  
637 683
///////////////////////////////////////////////////////////////////////////////////////////////////
......
736 782
                              final float[][] bands    , final int[]   bandIndexes,
737 783
                              final float[][] corners  , final int[]   cornerIndexes)
738 784
    {
739
    int EFFECTS_PER_FACE = 3;
740

  
741 785
    prepareFaceInfo(vertices,vertIndexes);
742 786

  
743 787
    int numFaces = vertIndexes.length;
......
765 809
      }
766 810

  
767 811
    MeshBase mesh = new MeshJoined(meshes);
768
    MatrixEffect[] effects = new MatrixEffect[EFFECTS_PER_FACE*numFaces];
769 812
    Static3D center = new Static3D(0,0,0);
770 813

  
771 814
    for(int face=0; face<numFaces; face++)
772 815
      {
773 816
      int assoc = (1<<face);
774 817
      fInfo = mFaceInfo.get(face);
818
      sInfo = mStickerInfo.get(fInfo.sticker);
775 819

  
820
      float dx = (float)sInfo.dx;
821
      float dy = (float)sInfo.dy;
776 822
      float vx = (float)fInfo.vx;
777 823
      float vy = (float)fInfo.vy;
778 824
      float vz = (float)fInfo.vz;
......
782 828
      float qz = (float)fInfo.qz;
783 829
      float qw = (float)fInfo.qw;
784 830

  
831
      Static3D move2D= new Static3D(dx,dy,0.0f);
785 832
      Static3D move3D= new Static3D(vx,vy,vz);
786 833
      Static3D scale = new Static3D(sc,sc, fInfo.flip ? -sc : sc);
787 834
      Static4D quat  = new Static4D(qx,qy,qz,qw);
788 835

  
789
      effects[EFFECTS_PER_FACE*face  ] = new MatrixEffectScale(scale);
790
      effects[EFFECTS_PER_FACE*face+1] = new MatrixEffectQuaternion(quat,center);
791
      effects[EFFECTS_PER_FACE*face+2] = new MatrixEffectMove(move3D);
792

  
793
      mesh.apply(effects[EFFECTS_PER_FACE*face  ],assoc,-1);
794
      mesh.apply(effects[EFFECTS_PER_FACE*face+1],assoc,-1);
795
      mesh.apply(effects[EFFECTS_PER_FACE*face+2],assoc,-1);
836
      mesh.apply(new MatrixEffectMove(move2D)           ,assoc,-1);
837
      mesh.apply(new MatrixEffectScale(scale)           ,assoc,-1);
838
      mesh.apply(new MatrixEffectQuaternion(quat,center),assoc,-1);
839
      mesh.apply(new MatrixEffectMove(move3D)           ,assoc,-1);
796 840
      }
797 841

  
798 842
    prepareAndRoundCorners(mesh, vertices, vertIndexes, corners, cornerIndexes);
src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
252 252

  
253 253
    private void createMesh()
254 254
      {
255
      int mode = 2;
255
      int mode = 0;
256 256
      double[][] vertices = null;
257 257
      int[][] vertIndexes = null;
258 258
      float[][] bands     = null;
......
288 288

  
289 289
        bands = new float[][]
290 290
          {
291
              {0.05f,45,0.6f,0.5f,5,  2,2}
291
              {0.05f,40,0.5f,0.2f,5,  2,2}
292 292
          };
293 293

  
294 294
        bandIndexes = new int[] { 0,0,0,0,0,0 };
......
358 358

  
359 359
        bands = new float[][]
360 360
          {
361
              {0.028f,30,0.166f,0.8f,7,  2,5},
362
              {0.028f,30,0.166f,0.8f,7,  1,2}
361
              {0.028f,30,0.25f,0.1f,7,  2,5},
362
              {0.001f,30,0.25f,0.1f,7,  1,2}
363 363
          };
364 364

  
365 365
        bandIndexes = new int[] { 0,1,1,0 };
......
372 372
        cornerIndexes = new int[] { 0,0,0,0 };
373 373
        }
374 374

  
375
      ///// OCTAHEDRON ////////////////////////////////////////////////////////////////////////////
376

  
377
      else if( mode==3 )
378
        {
379
        vertices = new double[][]
380
          {
381
              { 0.5,   0.0, 0.5},
382
              { 0.5,   0.0,-0.5},
383
              {-0.5,   0.0,-0.5},
384
              {-0.5,   0.0, 0.5},
385
              { 0.0, SQ2/2, 0.0},
386
              { 0.0,-SQ2/2, 0.0},
387
          };
388

  
389
        vertIndexes = new int[][]
390
          {
391
              {3,0,4},   // counterclockwise!
392
              {0,1,4},
393
              {1,2,4},
394
              {2,3,4},
395
              {5,0,3},
396
              {5,1,0},
397
              {5,2,1},
398
              {5,3,2}
399
          };
400

  
401
        bands = new float[][]
402
          {
403
             {0.05f,17,0.5f,0.2f,5,  2,2}
404
          };
405

  
406
        bandIndexes = new int[] { 0,0,0,0,0,0,0,0 };
407

  
408
        corners = new float[][]
409
          {
410
              { 0.03f, 0.12f }
411
          };
412

  
413
        cornerIndexes = new int[] { 0,0,0,0,0,0 };
414
        }
415

  
375 416
      FactoryCubit factory = FactoryCubit.getInstance();
376 417
      mMesh = factory.createRoundedSolid(vertices, vertIndexes, bands, bandIndexes, corners, cornerIndexes);
377 418

  

Also available in: Unified diff