Project

General

Profile

« Previous | Next » 

Revision 6c295be1

Added by Leszek Koltunski 12 months ago

Progress with BandagedObjectPyraminx.

View differences:

src/main/java/org/distorted/bandaged/BandagedObjectPyraminx.java
9 9

  
10 10
package org.distorted.bandaged;
11 11

  
12
import static org.distorted.objectlib.main.TwistyObject.SQ2;
12 13
import static org.distorted.objectlib.main.TwistyObject.SQ3;
13 14
import static org.distorted.objectlib.main.TwistyObject.SQ6;
14 15

  
......
31 32
     super(screen);
32 33
     }
33 34

  
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

  
37
  private boolean isFaceInverted(int face)
38
    {
39
    return face>1;
40
    }
41

  
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

  
44
  private void addTetrahedralLattice(int size, float[][] pos)
45
    {
46
    final float DX = 1.0f;
47
    final float DY = SQ2/2;
48
    final float DZ = 1.0f;
49

  
50
    float startX = 0.0f;
51
    float startY =-DY*(size-1)/2;
52
    float startZ = DZ*(size-1)/2;
53

  
54
    int index = 0;
55

  
56
    for(int layer=0; layer<size; layer++)
57
      {
58
      float currX = startX;
59
      float currY = startY;
60

  
61
      for(int x=0; x<layer+1; x++)
62
        {
63
        float currZ = startZ;
64

  
65
        for(int z=0; z<size-layer; z++)
66
          {
67
          pos[index] = new float[] {currX,currY,currZ};
68
          index++;
69
          currZ -= DZ;
70
          }
71

  
72
        currX += DX;
73
        }
74

  
75
      startX-=DX/2;
76
      startY+=DY;
77
      startZ-=DZ/2;
78
      }
79
    }
80

  
34 81
///////////////////////////////////////////////////////////////////////////////////////////////////
35 82

  
36 83
   float[] getDist3D()
......
85 132
     }
86 133

  
87 134
///////////////////////////////////////////////////////////////////////////////////////////////////
88
// TODO
89 135

  
90 136
  boolean isAdjacent(float dx, float dy, float dz)
91 137
    {
92
    return false;
138
    return dx*dx + dy*dy + dz*dz < (SQ3/4)*1.01f;
93 139
    }
94 140

  
95 141
///////////////////////////////////////////////////////////////////////////////////////////////////
96 142
// TODO
97 143

  
98
  float[][] getPositions()
144
  void getTouchedPosition(float[] output, int face, float pointX, float pointY)
99 145
    {
100
    return null;
146

  
101 147
    }
102 148

  
103 149
///////////////////////////////////////////////////////////////////////////////////////////////////
104
// TODO
105 150

  
106
  void getTouchedPosition(float[] output, int face, float pointX, float pointY)
151
  float[][][] getPositions()
107 152
    {
153
    int num = mSize[0];
154
    int numO= (num-1)*num*(num+1)/6;
155
    int numT= (num+1)*num*(num+2)/6;
156

  
157
    float[][] retO = new float[numO][];
158
    float[][] retT = new float[numT][];
108 159

  
160
    addTetrahedralLattice(num-1,retO);
161
    addTetrahedralLattice(num  ,retT);
162

  
163
    return new float[][][] { retO,retT };
109 164
    }
110 165

  
111 166
///////////////////////////////////////////////////////////////////////////////////////////////////
112
// TODO
113 167

  
114 168
  boolean isInsideFace(int face, float[] p)
115 169
    {
116
    return false;
170
    float y = (isFaceInverted(face) ? p[1] : -p[1]);
171
    float x = p[0];
172
    return (y >= -mDist2D) && (y <= mDist2D*(2-6*x)) && (y <= mDist2D*(2+6*x));
117 173
    }
118 174

  
119 175
///////////////////////////////////////////////////////////////////////////////////////////////////
120 176

  
121
  MeshBase createMesh(float[] pos, boolean round)
177
  MeshBase createMesh(int variant, float[] pos, boolean round)
122 178
     {
123 179
     FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
124
     return factory.createMesh(pos,mSize[0],false,round);
180
     return factory.createMesh(variant,pos,mSize[0],false,round);
125 181
     }
126 182

  
127 183
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff