Project

General

Profile

« Previous | Next » 

Revision b2de7562

Added by Leszek Koltunski 12 months ago

Progress with BandagedObject.

View differences:

src/main/java/org/distorted/bandaged/BandagedObjectCuboid.java
12 12
import org.distorted.library.main.DistortedScreen;
13 13
import org.distorted.library.mesh.MeshBase;
14 14
import org.distorted.library.type.Static3D;
15
import org.distorted.library.type.Static4D;
16 15
import org.distorted.objectlib.helpers.FactoryBandagedCubit;
17 16
import org.distorted.objectlib.main.InitData;
18 17
import org.distorted.objectlib.main.TwistyObject;
......
24 23

  
25 24
public class BandagedObjectCuboid extends BandagedObject
26 25
{
27
   private final float[] mPos;
28

  
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

  
31 26
   BandagedObjectCuboid(DistortedScreen screen)
32 27
     {
33 28
     super(screen);
34
     mPos = new float[3];
35 29
     }
36 30

  
37 31
///////////////////////////////////////////////////////////////////////////////////////////////////
38 32

  
39
   boolean isAdjacent(float[] pos1, float[] pos2)
33
   float[] getDist3D()
40 34
     {
41
     int len1 = pos1.length/3;
42
     int len2 = pos2.length/3;
35
     float max = mMax;
43 36

  
44
     for(int i=0; i<len1; i++)
45
       for(int j=0; j<len2; j++)
46
         {
47
         float d0 = pos1[3*i  ] - pos2[3*j  ];
48
         float d1 = pos1[3*i+1] - pos2[3*j+1];
49
         float d2 = pos1[3*i+2] - pos2[3*j+2];
37
     float x = 0.5f*(mSize[0]/max);
38
     float y = 0.5f*(mSize[1]/max);
39
     float z = 0.5f*(mSize[2]/max);
40

  
41
     return new float[] {x,x,y,y,z,z};
42
     }
50 43

  
51
         if( d0*d0 + d1*d1 + d2*d2 == 1 ) return true;
52
         }
44
///////////////////////////////////////////////////////////////////////////////////////////////////
53 45

  
54
     return false;
46
   float getDist2D()
47
     {
48
     return 0.5f;
55 49
     }
56 50

  
57 51
///////////////////////////////////////////////////////////////////////////////////////////////////
58 52

  
59
   TwistyObject createObject(int mode, float size)
53
   int[] getColors()
60 54
     {
61
     float[][] pos = getCubitPositions();
62
     InitData data = new InitData( mSize,pos);
63
     return new TwistyBandagedCuboid( TwistyObject.MESH_NICE, mode, ShapeHexahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null );
55
     return ShapeHexahedron.FACE_COLORS;
64 56
     }
65 57

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

  
68
   boolean tryChangeObject(int x, int y, int z)
60
  Static3D[] getFaceAxis()
61
    {
62
    return TouchControlHexahedron.FACE_AXIS;
63
    }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
  boolean isAdjacent(float dx, float dy, float dz)
68
    {
69
    return dx*dx + dy*dy + dz*dz == 1;
70
    }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

  
74
  boolean tryChangeObject(int x, int y, int z)
69 75
     {
70 76
     if( mSize[0]!=x || mSize[1]!=y || mSize[2]!=z )
71 77
       {
......
82 88

  
83 89
///////////////////////////////////////////////////////////////////////////////////////////////////
84 90

  
85
   int computeProjectionAngle()
91
  int computeProjectionAngle()
86 92
     {
87 93
     float quot1 = mSize[2]/ (float)mSize[0];
88 94
     float quot2 = mSize[2]/ (float)mSize[1];
......
101 107

  
102 108
///////////////////////////////////////////////////////////////////////////////////////////////////
103 109

  
104
   float[] getDist3D()
105
     {
106
     float max = mMax;
107

  
108
     float x = 0.5f*(mSize[0]/max);
109
     float y = 0.5f*(mSize[1]/max);
110
     float z = 0.5f*(mSize[2]/max);
111

  
112
     return new float[] {x,x,y,y,z,z};
113
     }
114

  
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

  
117
   float getDist2D()
118
     {
119
     return 0.5f;
120
     }
121

  
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

  
124
   MeshBase createMesh(float[] pos, boolean round)
125
      {
126
      FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
127
      int[] size = getSize();
128
      return factory.createMesh(pos,size[0],size[1],size[2],false,round);
129
      }
130

  
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

  
133
   int[] getColors()
134
     {
135
     return ShapeHexahedron.FACE_COLORS;
136
     }
137

  
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

  
140
   void createCubits(Static4D quatT, Static4D quatA, Static3D scale)
141
     {
142
     mCubits = new BandagedCubit[mNumCubits];
143
     int c=0;
144
     int sx = mSize[0];
145
     int sy = mSize[1];
146
     int sz = mSize[2];
147

  
148
     float begX = 0.5f*(1-sx);
149
     float begY = 0.5f*(1-sy);
150
     float begZ = 0.5f*(1-sz);
151

  
152
     for(int x=0; x<sx; x++)
153
       for(int y=0; y<sy; y++)
154
          for(int z=0; z<sz; z++)
155
            if( x==0 || x==sx-1 || y==0 || y==sy-1 || z==0 || z==sz-1 )
110
  float[][] getPositions()
111
    {
112
    float[][] pos = new float[mNumCubits][];
113
    int c=0;
114
    int sx = mSize[0];
115
    int sy = mSize[1];
116
    int sz = mSize[2];
117

  
118
    float begX = 0.5f*(1-sx);
119
    float begY = 0.5f*(1-sy);
120
    float begZ = 0.5f*(1-sz);
121

  
122
    for(int x=0; x<sx; x++)
123
      for(int y=0; y<sy; y++)
124
         for(int z=0; z<sz; z++)
125
           if( x==0 || x==sx-1 || y==0 || y==sy-1 || z==0 || z==sz-1 )
156 126
              {
157
              float[] pos = new float[] { begX+x,begY+y,begZ+z };
158
              mCubits[c] = new BandagedCubit(this,pos,quatT,quatA,scale,false);
159
              c++;
127
              pos[c++] = new float[] { begX+x,begY+y,begZ+z };
160 128
              }
161
    }
162 129

  
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

  
165
  Static3D[] getFaceAxis()
166
    {
167
    return TouchControlHexahedron.FACE_AXIS;
130
    return pos;
168 131
    }
169 132

  
170 133
///////////////////////////////////////////////////////////////////////////////////////////////////
171 134

  
172
  void stretchPoint(int face, float[] output)
173
    {
174
    float max = getMaxSize();
175

  
176
    switch(face/2)
177
      {
178
      case 0: output[0] *= (max/mSize[2]); output[1] *= (max/mSize[1]); break;
179
      case 1: output[0] *= (max/mSize[0]); output[1] *= (max/mSize[2]); break;
180
      case 2: output[0] *= (max/mSize[0]); output[1] *= (max/mSize[1]); break;
181
      }
182
    }
183

  
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

  
186
  int whichCubitTouched(int face, float pointX, float pointY)
135
  void getTouchedPosition(float[] output, int face, float pointX, float pointY)
187 136
    {
188 137
    float x = mSize[0];
189 138
    float y = mSize[1];
......
191 140

  
192 141
    switch(face)
193 142
      {
194
      case 0: mPos[0] = (x-1)/2;
195
              mPos[1] = (int)( y*pointY+y/2)-(y-1)/2;
196
              mPos[2] = (int)(-z*pointX-z/2)+(z-1)/2;
143
      case 0: output[0] = (x-1)/2;
144
              output[1] = (int)( y*pointY+y/2)-(y-1)/2;
145
              output[2] = (int)(-z*pointX-z/2)+(z-1)/2;
197 146
              break;
198
      case 1: mPos[0] =-(x-1)/2;
199
              mPos[1] = (int)( y*pointY+y/2)-(y-1)/2;
200
              mPos[2] = (int)( z*pointX+z/2)-(z-1)/2;
147
      case 1: output[0] =-(x-1)/2;
148
              output[1] = (int)( y*pointY+y/2)-(y-1)/2;
149
              output[2] = (int)( z*pointX+z/2)-(z-1)/2;
201 150
              break;
202
      case 2: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2;
203
              mPos[1] = (y-1)/2;
204
              mPos[2] = (int)(-z*pointY-z/2)+(z-1)/2;
151
      case 2: output[0] = (int)( x*pointX+x/2)-(x-1)/2;
152
              output[1] = (y-1)/2;
153
              output[2] = (int)(-z*pointY-z/2)+(z-1)/2;
205 154
              break;
206
      case 3: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2;
207
              mPos[1] =-(y-1)/2;
208
              mPos[2] = (int)( z*pointY+z/2)-(z-1)/2;
155
      case 3: output[0] = (int)( x*pointX+x/2)-(x-1)/2;
156
              output[1] =-(y-1)/2;
157
              output[2] = (int)( z*pointY+z/2)-(z-1)/2;
209 158
              break;
210
      case 4: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2;
211
              mPos[1] = (int)( y*pointY+y/2)-(y-1)/2;
212
              mPos[2] = (z-1)/2;
159
      case 4: output[0] = (int)( x*pointX+x/2)-(x-1)/2;
160
              output[1] = (int)( y*pointY+y/2)-(y-1)/2;
161
              output[2] = (z-1)/2;
213 162
              break;
214
      case 5: mPos[0] = (int)(-x*pointX-x/2)+(x-1)/2;
215
              mPos[1] = (int)( y*pointY+y/2)-(y-1)/2;
216
              mPos[2] =-(z-1)/2;
163
      case 5: output[0] = (int)(-x*pointX-x/2)+(x-1)/2;
164
              output[1] = (int)( y*pointY+y/2)-(y-1)/2;
165
              output[2] =-(z-1)/2;
217 166
              break;
218 167
      }
219

  
220
    for(int c=0; c<mNumCubits; c++)
221
      if( mCubits[c].isAttached() )
222
        {
223
        float[] pos = mCubits[c].getPosition();
224
        int len = pos.length/3;
225

  
226
        for(int p=0; p<len; p++)
227
          if( pos[3*p]==mPos[0] && pos[3*p+1]==mPos[1] && pos[3*p+2]==mPos[2] ) return c;
228
        }
229

  
230
    android.util.Log.e("D", "whichCubitTouched: IMPOSSIBLE!!");
231
    return -1;
232 168
    }
233 169

  
234 170
///////////////////////////////////////////////////////////////////////////////////////////////////
235 171

  
236 172
  boolean isInsideFace(int face, float[] p)
237 173
    {
174
    float max = mMax;
175

  
176
    switch(face/2)
177
      {
178
      case 0: p[0] *= (max/mSize[2]); p[1] *= (max/mSize[1]); break;
179
      case 1: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[2]); break;
180
      case 2: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[1]); break;
181
      }
182

  
238 183
    return ( p[0]<=mDist2D && p[0]>=-mDist2D && p[1]<=mDist2D && p[1]>=-mDist2D );
239 184
    }
185

  
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

  
188
  MeshBase createMesh(float[] pos, boolean round)
189
     {
190
     FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
191
     int[] size = getSize();
192
     return factory.createMesh(pos,size[0],size[1],size[2],false,round);
193
     }
194

  
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

  
197
  TwistyObject createObject(int mode, float size)
198
     {
199
     float[][] pos = getCubitPositions();
200
     InitData data = new InitData( mSize,pos);
201
     return new TwistyBandagedCuboid( TwistyObject.MESH_NICE, mode, ShapeHexahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null );
202
     }
240 203
}

Also available in: Unified diff