Project

General

Profile

« Previous | Next » 

Revision 6a96e571

Added by Leszek Koltunski about 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);

Also available in: Unified diff