Revision 789769bd
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/bandaged/BandagedCreatorTouchControl.java | ||
---|---|---|
26 | 26 |
private final int mNumFaces; |
27 | 27 |
|
28 | 28 |
private float[] mDist3D; |
29 |
private int mLastTouchedFace; |
|
30 | 29 |
|
31 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
32 | 31 |
// Convert the 3D point3D into a 2D point on the same face surface, but in a different |
... | ... | |
128 | 127 |
mCamera[1] = rotatedCamera.get1()/mObjectRatio; |
129 | 128 |
mCamera[2] = rotatedCamera.get2()/mObjectRatio; |
130 | 129 |
|
131 |
for( mLastTouchedFace=0; mLastTouchedFace<mNumFaces; mLastTouchedFace++)
|
|
130 |
for( int face=0; face<mNumFaces; face++)
|
|
132 | 131 |
{ |
133 |
if( faceIsVisible(mLastTouchedFace) )
|
|
132 |
if( faceIsVisible(face) )
|
|
134 | 133 |
{ |
135 |
castTouchPointOntoFace(mLastTouchedFace, mTouch);
|
|
134 |
castTouchPointOntoFace(face, mTouch);
|
|
136 | 135 |
|
137 |
float ax = mFaceAxis[mLastTouchedFace].get0();
|
|
138 |
float ay = mFaceAxis[mLastTouchedFace].get1();
|
|
139 |
float az = mFaceAxis[mLastTouchedFace].get2();
|
|
136 |
float ax = mFaceAxis[face].get0();
|
|
137 |
float ay = mFaceAxis[face].get1();
|
|
138 |
float az = mFaceAxis[face].get2();
|
|
140 | 139 |
|
141 | 140 |
convertTo2Dcoords(mTouch, ax,ay,az, mPoint2D); |
142 | 141 |
|
143 |
if( mObject.isInsideFace(mLastTouchedFace,mPoint2D) ) return true;
|
|
142 |
if( mObject.isInsideFace(face,mPoint2D) ) return true;
|
|
144 | 143 |
} |
145 | 144 |
} |
146 | 145 |
|
... | ... | |
197 | 196 |
|
198 | 197 |
if( !touched ) return -1; |
199 | 198 |
|
200 |
return mObject.whichCubitTouched(mLastTouchedFace,mPoint2D[0],mPoint2D[1]);
|
|
199 |
return mObject.whichCubitTouched(mTouch);
|
|
201 | 200 |
} |
202 | 201 |
} |
203 | 202 |
|
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 | 25 |
private BandagedCubit[] mCubits; |
27 | 26 |
|
28 | 27 |
final int[] mSize; |
... | ... | |
38 | 37 |
mScreen = screen; |
39 | 38 |
mSize = new int[3]; |
40 | 39 |
mDist2D = getDist2D(); |
41 |
mTmp = new float[3]; |
|
42 | 40 |
Static3D[] axis = getFaceAxis(); |
43 | 41 |
int numAxis = axis.length; |
44 | 42 |
mFaceAxis = new float[numAxis][]; |
... | ... | |
55 | 53 |
abstract boolean isAdjacent(float dx, float dy, float dz); |
56 | 54 |
abstract int computeProjectionAngle(); |
57 | 55 |
abstract boolean tryChangeObject(int x, int y, int z); |
58 |
abstract void getTouchedPosition(float[] output, int face, float pointX, float pointY); |
|
59 | 56 |
abstract boolean isInsideFace(int face, float[] p); |
60 | 57 |
abstract TwistyObject createObject(int mode, float scale ); |
61 | 58 |
abstract MeshBase createMesh(int variant, float[] pos, boolean round); |
62 | 59 |
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
int[] getSize() |
|
66 |
{ |
|
67 |
return mSize; |
|
68 |
} |
|
69 |
|
|
70 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
71 | 61 |
|
72 | 62 |
void createCubits(Static4D quatT, Static4D quatA, Static3D scale) |
... | ... | |
244 | 234 |
|
245 | 235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
246 | 236 |
|
247 |
int whichCubitTouched(int face, float pointX, float pointY)
|
|
237 |
int whichCubitTouched(float[] point3D)
|
|
248 | 238 |
{ |
249 |
getTouchedPosition(mTmp, face, pointX, pointY); |
|
239 |
float x = point3D[0]*mMax; |
|
240 |
float y = point3D[1]*mMax; |
|
241 |
float z = point3D[2]*mMax; |
|
242 |
|
|
243 |
int minIndex = -1; |
|
244 |
float minDist = Float.MAX_VALUE; |
|
250 | 245 |
|
251 | 246 |
for(int c=0; c<mNumCubits; c++) |
252 | 247 |
if( mCubits[c].isAttached() ) |
... | ... | |
256 | 251 |
|
257 | 252 |
for(int p=0; p<len; p++) |
258 | 253 |
{ |
259 |
float dx = pos[3*p ]-mTmp[0]; |
|
260 |
float dy = pos[3*p+1]-mTmp[1]; |
|
261 |
float dz = pos[3*p+2]-mTmp[2]; |
|
262 |
|
|
263 |
if( dx*dx + dy*dy + dz*dz < 0.01f ) return c; |
|
254 |
float dx = pos[3*p ]-x; |
|
255 |
float dy = pos[3*p+1]-y; |
|
256 |
float dz = pos[3*p+2]-z; |
|
257 |
float dist = dx*dx + dy*dy + dz*dz; |
|
258 |
|
|
259 |
if( dist<minDist ) |
|
260 |
{ |
|
261 |
minDist = dist; |
|
262 |
minIndex = c; |
|
263 |
} |
|
264 | 264 |
} |
265 | 265 |
} |
266 | 266 |
|
267 |
android.util.Log.e("D", "whichCubitTouched: IMPOSSIBLE!!"); |
|
268 |
return -1; |
|
267 |
return minIndex; |
|
269 | 268 |
} |
270 | 269 |
|
271 | 270 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/bandaged/BandagedObjectPyraminx.java | ||
---|---|---|
138 | 138 |
return dx*dx + dy*dy + dz*dz < (SQ3/4)*1.01f; |
139 | 139 |
} |
140 | 140 |
|
141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
142 |
// TODO |
|
143 |
|
|
144 |
void getTouchedPosition(float[] output, int face, float pointX, float pointY) |
|
145 |
{ |
|
146 |
|
|
147 |
} |
|
148 |
|
|
149 | 141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
150 | 142 |
|
151 | 143 |
float[][][] getPositions() |
Also available in: Unified diff
Progress with BandagedObjectPyraminx.