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/BandagedObject.java
22 22
{
23 23
    private final DistortedScreen mScreen;
24 24
    private final float[][] mFaceAxis;
25
    private final float[] mTmp;
26
    private BandagedCubit[] mCubits;
27

  
25 28
    final int[] mSize;
26 29
    final float mDist2D;
27 30

  
28
    BandagedCubit[] mCubits;
29 31
    int mMax;
30 32
    int mNumCubits;
31 33

  
......
36 38
     mScreen = screen;
37 39
     mSize = new int[3];
38 40
     mDist2D = getDist2D();
39

  
41
     mTmp = new float[3];
40 42
     Static3D[] axis = getFaceAxis();
41 43
     int numAxis = axis.length;
42 44
     mFaceAxis = new float[numAxis][];
......
49 51
   abstract float[] getDist3D();
50 52
   abstract int[] getColors();
51 53
   abstract Static3D[] getFaceAxis();
52
   abstract void createCubits(Static4D quatT, Static4D quatA, Static3D scale);
53
   abstract boolean isAdjacent(float[] pos1, float[] pos2);
54
   abstract float[][] getPositions();
55
   abstract boolean isAdjacent(float dx, float dy, float dz);
54 56
   abstract int computeProjectionAngle();
55 57
   abstract boolean tryChangeObject(int x, int y, int z);
56
   abstract void stretchPoint(int face, float[] output);
57
   abstract int whichCubitTouched(int face, float pointX, float pointY);
58
   abstract void getTouchedPosition(float[] output, int face, float pointX, float pointY);
58 59
   abstract boolean isInsideFace(int face, float[] p);
59 60
   abstract TwistyObject createObject(int mode, float scale );
60 61
   abstract MeshBase createMesh(float[] pos, boolean round);
......
66 67
     return mSize;
67 68
     }
68 69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

  
72
   void createCubits(Static4D quatT, Static4D quatA, Static3D scale)
73
     {
74
     mCubits = new BandagedCubit[mNumCubits];
75
     int c=0;
76
     for(float[] p : getPositions() ) mCubits[c++] = new BandagedCubit(this,p,quatT,quatA,scale,false);
77
     }
78

  
69 79
///////////////////////////////////////////////////////////////////////////////////////////////////
70 80

  
71 81
   int computeMapsIndex(float[] faceAx)
......
223 233
    {
224 234
    if( index>=0 && index<mNumCubits && mCubits[index]!=null ) mCubits[index].setUnmarked();
225 235
    }
236

  
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

  
239
  int whichCubitTouched(int face, float pointX, float pointY)
240
    {
241
    getTouchedPosition(mTmp, face, pointX, pointY);
242

  
243
    for(int c=0; c<mNumCubits; c++)
244
      if( mCubits[c].isAttached() )
245
        {
246
        float[] pos = mCubits[c].getPosition();
247
        int len = pos.length/3;
248

  
249
        for(int p=0; p<len; p++)
250
          if( pos[3*p]==mTmp[0] && pos[3*p+1]==mTmp[1] && pos[3*p+2]==mTmp[2] ) return c;
251
        }
252

  
253
    android.util.Log.e("D", "whichCubitTouched: IMPOSSIBLE!!");
254
    return -1;
255
    }
256

  
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

  
259
  boolean isAdjacent(float[] pos1, float[] pos2)
260
     {
261
     int len1 = pos1.length/3;
262
     int len2 = pos2.length/3;
263

  
264
     for(int i=0; i<len1; i++)
265
       for(int j=0; j<len2; j++)
266
         {
267
         float dx = pos1[3*i  ] - pos2[3*j  ];
268
         float dy = pos1[3*i+1] - pos2[3*j+1];
269
         float dz = pos1[3*i+2] - pos2[3*j+2];
270

  
271
         if( isAdjacent(dx,dy,dz) ) return true;
272
         }
273

  
274
     return false;
275
     }
226 276
}

Also available in: Unified diff