Project

General

Profile

« Previous | Next » 

Revision 6155e738

Added by Leszek Koltunski 10 months ago

progress with FactoryBandagedMegaminx.

View differences:

src/main/java/org/distorted/objectlib/bandaged/BandagedElement.java
11 11

  
12 12
///////////////////////////////////////////////////////////////////////////////////////////////////
13 13

  
14
import org.distorted.library.type.Static4D;
15

  
14 16
public class BandagedElement
15 17
  {
16 18
  private final float[] mPos;
17 19
  private final int mVariant;
20
  private final Static4D mQuat;
18 21

  
19 22
///////////////////////////////////////////////////////////////////////////////////////////////////
20 23

  
21
  BandagedElement(float[] pos, int index, int variant)
24
  BandagedElement(float[] pos, int index, int variant, Static4D quat )
22 25
    {
23 26
    mPos = new float[] { pos[index], pos[index+1], pos[index+2] };
27
    mQuat = quat;
24 28
    mVariant = variant;
25 29
    }
26 30

  
......
31 35
    return mPos;
32 36
    }
33 37

  
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

  
40
  Static4D getQuat()
41
    {
42
    return mQuat;
43
    }
44

  
34 45
///////////////////////////////////////////////////////////////////////////////////////////////////
35 46

  
36 47
  int getVariant()
src/main/java/org/distorted/objectlib/bandaged/FactoryBandaged.java
15 15
import static org.distorted.objectlib.objects.TwistyBandagedCuboid.REGION_SIZE;
16 16
import static org.distorted.objectlib.objects.TwistyBandagedCuboid.STRENGTH;
17 17

  
18
import org.distorted.library.helpers.QuatHelper;
18 19
import org.distorted.library.mesh.MeshBase;
19 20
import org.distorted.library.type.Static3D;
21
import org.distorted.library.type.Static4D;
20 22
import org.distorted.objectlib.helpers.FactoryCubit;
21 23
import org.distorted.objectlib.helpers.ObjectFaceShape;
22 24
import org.distorted.objectlib.helpers.ObjectShape;
......
111 113
      }
112 114
    }
113 115

  
116
  public static Static4D QUAT = new Static4D(0,0,0,1);
117

  
114 118
  private ArrayList<float[]> mTmpArray;
119
  private ArrayList<float[][]> mVertexArray;
120
  private BandagedElement[] mElements;
121
  private Static3D[] mNormals;
115 122
  private float[] mDist3D;
116 123
  private int[][] mFaceBelongsBitmap;
117 124
  private float[][] mDiaAxis;
118 125
  private float[][] mMinMax;
119

  
120
  BandagedElement[] mElements;
121
  ArrayList<float[][]> mVertexArray;
122

  
123
  int[][] mBandIndices;
124
  float[][][] mVertices;
125
  int[][][][] mIndices;
126
  float[][] mMove;
127
  int mNumElements;
128
  int mNumFaces;
129
  int mNumAxis;
130
  Static3D[] mNormals;
131

  
132
  int[] mNumLayers;
126
  private int mNumFaces;
127
  private int mNumElements;
128
  private float[][] mMove;
129
  private int[][][][] mIndices;
130
  private float[][][] mVertices;
131
  private int[][] mBandIndices;
132
  private int[] mNumLayers;
133
  private float[] mTmp;
133 134

  
134 135
///////////////////////////////////////////////////////////////////////////////////////////////////
135 136

  
......
141 142
///////////////////////////////////////////////////////////////////////////////////////////////////
142 143

  
143 144
  abstract Static3D[] getNormals();
145
  abstract Static4D getElementQuat(int element, int[] numLayers);
144 146
  abstract float[][] getDiameterAxis();
145
  abstract float[] getDist3D();
146
  abstract float[][] getBands(boolean iconMode);
147
  abstract int getElementVariant(float x, float y, float z);
147
  abstract float[] getDist3D(int[] numLayers);
148
  abstract float[][] getBands(boolean iconMode, int[] numLayers);
149
  abstract int getElementVariant(int[] numLayers, float x, float y, float z);
148 150
  abstract int diameterMap(float diameter);
149
  abstract float[][] getVertices(int variant);
150
  abstract int[][] getIndices(int variant);
151
  abstract int getNumAxis();
151
  abstract float[][] getVertices(int[] numLayers, int variant);
152
  abstract int[][] getIndices(int[] numLayers, int variant);
152 153

  
153 154
///////////////////////////////////////////////////////////////////////////////////////////////////
154 155

  
......
563 564

  
564 565
///////////////////////////////////////////////////////////////////////////////////////////////////
565 566

  
566
  private float[] buildFaceVertices(float[][] vertices, int[] indices, float[] pos)
567
  private float[] buildFaceVertices(float[][] vertices, int[] indices, float[] pos, Static4D quat)
567 568
    {
568 569
    int num = indices.length;
569 570
    float[] ret = new float[3*num];
......
571 572
    for(int i=0; i<num; i++)
572 573
      {
573 574
      float[] v = vertices[indices[i]];
574
      ret[3*i  ] = v[0] + pos[0];
575
      ret[3*i+1] = v[1] + pos[1];
576
      ret[3*i+2] = v[2] + pos[2];
575
      QuatHelper.rotateVectorByQuat(mTmp,v[0],v[1],v[2],1,quat);
576

  
577
      ret[3*i  ] = mTmp[0] + pos[0];
578
      ret[3*i+1] = mTmp[1] + pos[1];
579
      ret[3*i+2] = mTmp[2] + pos[2];
577 580
      }
578 581

  
579 582
    return ret;
......
755 758
  private void fillUpVertexArray()
756 759
    {
757 760
    ArrayList<BandagedCubitFace> list = new ArrayList<>();
761
    mTmp = new float[4];
758 762

  
759 763
    for(int e=0; e<mNumElements; e++)
760 764
      {
761
      int variant = mElements[e].getVariant();
762
      float[][] verts = getVertices(variant);
763
      int[][] inds = getIndices(variant);
764
      float[] pos = mElements[e].getPos();
765
      BandagedElement element = mElements[e];
766
      int variant = element.getVariant();
767
      float[] pos = element.getPos();
768
      Static4D quat = element.getQuat();
769

  
770
      float[][] verts = getVertices(mNumLayers,variant);
771
      int[][] inds = getIndices(mNumLayers,variant);
765 772

  
766 773
      for( int[] ind : inds)
767 774
        {
768
        float[] vertices = buildFaceVertices(verts,ind,pos);
775
        float[] vertices = buildFaceVertices(verts,ind,pos,quat);
769 776
        BandagedCubitFace face = new BandagedCubitFace(vertices);
770 777
        list.add(face);
771 778
        }
......
807 814
    mNumLayers = numLayers;
808 815
    mNormals   = getNormals();
809 816
    mNumFaces  = mNormals.length;
810
    mDist3D    = getDist3D();
811
    mNumAxis   = getNumAxis();
817
    mDist3D    = getDist3D(mNumLayers);
812 818
    mDiaAxis   = getDiameterAxis();
813 819
    mMinMax    = new float[mDiaAxis.length][2];
814 820
    }
......
823 829
    mElements = new BandagedElement[mNumElements];
824 830
    for(int i=0; i<mNumElements; i++)
825 831
      {
826
      int elementVariant = getElementVariant(pos[3*i],pos[3*i+1],pos[3*i+2]);
827
      mElements[i] = new BandagedElement(pos, 3*i, elementVariant);
832
      int elementVariant = getElementVariant(mNumLayers, pos[3*i],pos[3*i+1],pos[3*i+2]);
833
      Static4D quat = getElementQuat(i,mNumLayers);
834
      mElements[i] = new BandagedElement(pos, 3*i, elementVariant, quat);
828 835
      }
829 836

  
830 837
    fillUpVertexArray();
......
842 849

  
843 850
  public ObjectFaceShape createIrregularFaceShape(int variant, boolean iconMode)
844 851
    {
845
    float[][] bands = getBands(iconMode);
852
    float[][] bands = getBands(iconMode, mNumLayers);
846 853

  
847 854
    if( mBandIndices[variant]==null )
848 855
      {
src/main/java/org/distorted/objectlib/bandaged/FactoryBandagedCuboid.java
10 10
package org.distorted.objectlib.bandaged;
11 11

  
12 12
import org.distorted.library.type.Static3D;
13
import org.distorted.library.type.Static4D;
13 14
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
14 15

  
15 16
///////////////////////////////////////////////////////////////////////////////////////////////////
......
37 38

  
38 39
///////////////////////////////////////////////////////////////////////////////////////////////////
39 40

  
40
  public float[][] getVertices(int variant)
41
  public Static4D getElementQuat(int element, int[] numLayers)
42
    {
43
    return QUAT;
44
    }
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
  public float[][] getVertices(int[] numLayers, int variant)
41 49
    {
42 50
    if( mVertices==null )
43 51
      mVertices = new float[][]
......
57 65

  
58 66
///////////////////////////////////////////////////////////////////////////////////////////////////
59 67

  
60
  public int[][] getIndices(int variant)
68
  public int[][] getIndices(int[] numLayers, int variant)
61 69
    {
62 70
    if( mIndices==null )
63 71
      mIndices = new int[][]
......
75 83

  
76 84
///////////////////////////////////////////////////////////////////////////////////////////////////
77 85

  
78
  public int getElementVariant(float x, float y, float z)
86
  public int getElementVariant(int[] numLayers, float x, float y, float z)
79 87
     {
80 88
     return 0;
81 89
     }
......
87 95
    return TouchControlHexahedron.FACE_AXIS;
88 96
    }
89 97

  
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

  
92
  public int getNumAxis()
93
    {
94
    return 3;
95
    }
96

  
97 98
///////////////////////////////////////////////////////////////////////////////////////////////////
98 99

  
99 100
  public float[][] getDiameterAxis()
......
110 111

  
111 112
///////////////////////////////////////////////////////////////////////////////////////////////////
112 113

  
113
  public float[] getDist3D()
114
  public float[] getDist3D(int[] numLayers)
114 115
    {
115
    float dx = mNumLayers[0]/2.0f;
116
    float dy = mNumLayers[1]/2.0f;
117
    float dz = mNumLayers[2]/2.0f;
116
    float dx = numLayers[0]/2.0f;
117
    float dy = numLayers[1]/2.0f;
118
    float dz = numLayers[2]/2.0f;
118 119

  
119 120
    return new float[] {dx,dx,dy,dy,dz,dz};
120 121
    }
121 122

  
122 123
///////////////////////////////////////////////////////////////////////////////////////////////////
123 124

  
124
  public float[][] getBands(boolean iconMode)
125
  public float[][] getBands(boolean iconMode, int[] numLayers)
125 126
    {
126
    int sum = mNumLayers[0]+mNumLayers[1]+mNumLayers[2];
127
    int sum = numLayers[0]+numLayers[1]+numLayers[2];
127 128

  
128 129
    float height= iconMode ? 0.001f : 0.05f;
129 130
    int[] angle = {65,54,43,35,30,26,23,21};
src/main/java/org/distorted/objectlib/bandaged/FactoryBandagedMegaminx.java
19 19
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.SIN54;
20 20

  
21 21
import org.distorted.library.type.Static3D;
22
import org.distorted.library.type.Static4D;
22 23
import org.distorted.objectlib.objects.TwistyDodecahedron;
23 24
import org.distorted.objectlib.touchcontrol.TouchControlDodecahedron;
24 25

  
......
276 277

  
277 278
///////////////////////////////////////////////////////////////////////////////////////////////////
278 279

  
279
  public float[][] getVertices(int variant)
280
  public float[][] getVertices(int[] numLayers, int variant)
280 281
    {
281 282
    if( mVertices==null ) mVertices = new float[1+3+4+4][][];
282 283

  
283
    switch( mNumLayers[0] )
284
    switch( numLayers[0] )
284 285
      {
285 286
      case 0: return verticesKilominx(variant);
286 287
      case 1: return verticesMegaminx(variant);
......
392 393

  
393 394
///////////////////////////////////////////////////////////////////////////////////////////////////
394 395

  
395
  public int[][] getIndices(int variant)
396
  public int[][] getIndices(int[] numLayers, int variant)
396 397
    {
397 398
    if( mIndices==null ) mIndices = new int[1+3+4+4][][];
398 399

  
399
    switch( mNumLayers[0] )
400
    switch( numLayers[0] )
400 401
      {
401 402
      case 0: return indicesKilominx(variant);
402 403
      case 1: return indicesMegaminx(variant);
......
457 458

  
458 459
///////////////////////////////////////////////////////////////////////////////////////////////////
459 460

  
460
  public int getElementVariant(float x, float y, float z)
461
  public int getElementVariant(int[] numLayers, float x, float y, float z)
461 462
    {
462
    int size = mNumLayers[0];
463
    int size = numLayers[0];
463 464

  
464 465
    float CENT_DIST_SQ = TouchControlDodecahedron.DIST3D;
465 466
    float CORN_DIST_SQ = (18+6*SQ5)/16;
......
513 514
    }
514 515

  
515 516
///////////////////////////////////////////////////////////////////////////////////////////////////
517
// TODO
516 518

  
517
  public Static3D[] getNormals()
519
  public Static4D getElementQuat(int element, int[] numLayers)
518 520
    {
519
    return TouchControlDodecahedron.FACE_AXIS;
521
    return QUAT;
520 522
    }
521 523

  
522 524
///////////////////////////////////////////////////////////////////////////////////////////////////
523 525

  
524
  public int getNumAxis()
526
  public Static3D[] getNormals()
525 527
    {
526
    return 6;
528
    return TouchControlDodecahedron.FACE_AXIS;
527 529
    }
528 530

  
529 531
///////////////////////////////////////////////////////////////////////////////////////////////////
530 532

  
531
  public float[] getDist3D()
533
  public float[] getDist3D(int[] numLayers)
532 534
    {
533
    final float d = TouchControlDodecahedron.DIST3D*mNumLayers[0];
534
    return new float[] {d,d,d,d,d,d};
535
    final float d = TouchControlDodecahedron.DIST3D*numLayers[0];
536
    return new float[] {d,d,d,d,d,d,d,d,d,d,d,d};
535 537
    }
536 538

  
537 539
///////////////////////////////////////////////////////////////////////////////////////////////////
......
571 573

  
572 574
///////////////////////////////////////////////////////////////////////////////////////////////////
573 575

  
574
  public float[][] getBands(boolean iconMode)
576
  public float[][] getBands(boolean iconMode, int[] numLayers)
575 577
    {
576 578
    float height= iconMode ? 0.001f : 0.04f;
577 579
    int[] angle = {68,56,50,43,39,35,32,30,28,26,25};
......
579 581
    float S     = 0.5f;
580 582
    int extraI  = 0;
581 583
    int extraV  = 0;
582
    int numVertA= mNumLayers[0]>=4 ? 4 : 5;
583
    int numVertI= mNumLayers[0]>=4 ? 2 : 3;
584
    int numVertA= numLayers[0]>=4 ? 4 : 5;
585
    int numVertI= numLayers[0]>=4 ? 2 : 3;
584 586

  
585 587
    return new float[][] { {  0.001f    ,angle[ 0],R,S,numVertI,extraV,extraI},
586 588
                           {height      ,angle[ 1],R,S,numVertA,extraV,extraI},
src/main/java/org/distorted/objectlib/bandaged/FactoryBandagedPyraminx.java
12 12
import static org.distorted.objectlib.main.TwistyObject.SQ2;
13 13

  
14 14
import org.distorted.library.type.Static3D;
15
import org.distorted.library.type.Static4D;
15 16
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
16 17

  
17 18
///////////////////////////////////////////////////////////////////////////////////////////////////
......
39 40

  
40 41
///////////////////////////////////////////////////////////////////////////////////////////////////
41 42

  
42
  public float[][] getVertices(int variant)
43
  public Static4D getElementQuat(int element, int[] numLayers)
44
    {
45
    return QUAT;
46
    }
47

  
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

  
50
  public float[][] getVertices(int[] numLayers, int variant)
43 51
    {
44 52
    if( mVertices==null ) mVertices = new float[2][][];
45 53

  
......
61 69

  
62 70
///////////////////////////////////////////////////////////////////////////////////////////////////
63 71

  
64
  public int[][] getIndices(int variant)
72
  public int[][] getIndices(int[] numLayers, int variant)
65 73
    {
66 74
    if( mIndices==null ) mIndices = new int[2][][];
67 75

  
......
95 103

  
96 104
///////////////////////////////////////////////////////////////////////////////////////////////////
97 105

  
98
  public int getElementVariant(float x, float y, float z)
106
  public int getElementVariant(int[] numLayers, float x, float y, float z)
99 107
    {
100
    return isOctahedron(mNumLayers[0],y) ? 0 : 1;
108
    return isOctahedron(numLayers[0],y) ? 0 : 1;
101 109
    }
102 110

  
103 111
///////////////////////////////////////////////////////////////////////////////////////////////////
......
107 115
    return TouchControlTetrahedron.FACE_AXIS;
108 116
    }
109 117

  
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

  
112
  public int getNumAxis()
113
    {
114
    return 4;
115
    }
116

  
117 118
///////////////////////////////////////////////////////////////////////////////////////////////////
118 119
// normalized 'edges' of the tetrahedron.
119 120

  
......
141 142

  
142 143
///////////////////////////////////////////////////////////////////////////////////////////////////
143 144

  
144
  public float[] getDist3D()
145
  public float[] getDist3D(int[] numLayers)
145 146
    {
146
    final float d = TouchControlTetrahedron.DIST3D*mNumLayers[0];
147
    final float d = TouchControlTetrahedron.DIST3D*numLayers[0];
147 148
    return new float[] {d,d,d,d};
148 149
    }
149 150

  
150 151
///////////////////////////////////////////////////////////////////////////////////////////////////
151 152

  
152
  public float[][] getBands(boolean iconMode)
153
  public float[][] getBands(boolean iconMode, int[] numLayers)
153 154
    {
154 155
    float height= iconMode ? 0.001f : 0.055f;
155 156
    int[] angle = {68,56,50,43,39,35,32,30,28,26,25};
......
157 158
    float S     = 0.5f;
158 159
    int extraI  = 0;
159 160
    int extraV  = 0;
160
    int numVertA= mNumLayers[0]>=5 ? 4 : 5;
161
    int numVertI= mNumLayers[0]>=5 ? 2 : 3;
161
    int numVertA= numLayers[0]>=5 ? 4 : 5;
162
    int numVertI= numLayers[0]>=5 ? 2 : 3;
162 163

  
163 164
    return new float[][] { {  0.001f    ,angle[ 0],R,S,numVertI,extraV,extraI},
164 165
                           {height      ,angle[ 1],R,S,numVertA,extraV,extraI},
src/main/java/org/distorted/objectlib/objects/TwistyBandagedCuboid.java
508 508

  
509 509
    if( dim!=null )
510 510
      {
511
      int[] numLayers = getNumLayers();
511 512
      boolean iconMode = isInIconMode();
512
      float[][] bands = factory.getBands(iconMode);
513
      float[][] bands = factory.getBands(iconMode,numLayers);
513 514

  
514 515
      int X = dim[0];
515 516
      int Y = dim[1];
src/main/java/org/distorted/objectlib/objects/TwistyBandagedPyraminx.java
180 180

  
181 181
    if( type>=0 )
182 182
      {
183
      int[] numLayers = getNumLayers();
183 184
      boolean iconMode = isInIconMode();
184
      float[][] bands = factory.getBands(iconMode);
185
      float[][] bands = factory.getBands(iconMode,numLayers);
185 186
      int numFaces = type==TET_1 ? 4:8;
186 187
      int[] bandIndices= new int[numFaces];
187 188
      for(int i=0; i<numFaces; i++) bandIndices[i] = 1;

Also available in: Unified diff