30 |
30 |
private int mLastTouchedFace, mNumFaceAxis;
|
31 |
31 |
private float[] mPoint, mCamera, mTouch;
|
32 |
32 |
private float[] mPoint2D, mMove2D;
|
33 |
|
private float[][][] mCastAxis;
|
|
33 |
private float[][][] mCastedRotAxis;
|
|
34 |
private Static4D[][] mCastedRotAxis4D;
|
34 |
35 |
private int[] mEnabledRotAxis;
|
35 |
36 |
private float mDistanceCenterFace3D, mDistanceCenterFace2D;
|
36 |
37 |
private Static3D[] mFaceAxis;
|
... | ... | |
59 |
60 |
mDistanceCenterFace3D = distance3D; // distance from the center of the object to each of its faces
|
60 |
61 |
mDistanceCenterFace2D = distance2D; // distance from the center of a face to its edge
|
61 |
62 |
|
62 |
|
// mCastAxis[1][2]{0,1} are the 2D coords of the 2nd axis cast onto the face defined by the
|
|
63 |
// mCastedRotAxis[1][2]{0,1} are the 2D coords of the 2nd axis cast onto the face defined by the
|
63 |
64 |
// 1st pair (axis,lr)
|
64 |
|
mCastAxis = new float[mNumFaceAxis][rotAxis.length][2];
|
|
65 |
mCastedRotAxis = new float[mNumFaceAxis][rotAxis.length][2];
|
|
66 |
mCastedRotAxis4D = new Static4D[mNumFaceAxis][rotAxis.length];
|
|
67 |
|
|
68 |
float fx,fy,fz,f;
|
65 |
69 |
|
66 |
70 |
for( int casted=0; casted<rotAxis.length; casted++)
|
67 |
71 |
{
|
... | ... | |
72 |
76 |
|
73 |
77 |
for( int face=0; face<mNumFaceAxis; face++)
|
74 |
78 |
{
|
75 |
|
convertTo2Dcoords( mPoint, mFaceAxis[face], mCastAxis[face][casted]);
|
76 |
|
normalize2D(mCastAxis[face][casted]);
|
|
79 |
convertTo2Dcoords( mPoint, mFaceAxis[face], mCastedRotAxis[face][casted]);
|
|
80 |
normalize2D(mCastedRotAxis[face][casted]);
|
|
81 |
|
|
82 |
fx = faceAxis[face].get0();
|
|
83 |
fy = faceAxis[face].get1();
|
|
84 |
fz = faceAxis[face].get2();
|
|
85 |
f = mPoint[0]*fx + mPoint[1]*fy + mPoint[2]*fz;
|
|
86 |
mCastedRotAxis4D[face][casted] = new Static4D( mPoint[0]-f*fx, mPoint[1]-f*fy, mPoint[2]-f*fz, 0);
|
77 |
87 |
}
|
78 |
88 |
}
|
79 |
89 |
}
|
... | ... | |
114 |
124 |
for(int axis=1; axis<=numAxis; axis++)
|
115 |
125 |
{
|
116 |
126 |
index = enabled[axis];
|
117 |
|
cosAngle = m0*mCastAxis[faceAxis][index][0] + m1*mCastAxis[faceAxis][index][1];
|
|
127 |
cosAngle = m0*mCastedRotAxis[faceAxis][index][0] + m1*mCastedRotAxis[faceAxis][index][1];
|
118 |
128 |
if( cosAngle<0 ) cosAngle = -cosAngle;
|
119 |
129 |
|
120 |
130 |
if( cosAngle<minCosAngle )
|
... | ... | |
271 |
281 |
|
272 |
282 |
computeEnabledAxis(mLastTouchedFace, mPoint2D, mEnabledRotAxis);
|
273 |
283 |
int rotIndex = computeRotationIndex(mLastTouchedFace, mMove2D, mEnabledRotAxis);
|
274 |
|
float offset = computeOffset(mPoint2D, mCastAxis[mLastTouchedFace][rotIndex]);
|
|
284 |
float offset = computeOffset(mPoint2D, mCastedRotAxis[mLastTouchedFace][rotIndex]);
|
275 |
285 |
|
276 |
286 |
return new Static2D(rotIndex,offset);
|
277 |
287 |
}
|
278 |
288 |
|
|
289 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
290 |
|
|
291 |
public Static4D getCastedRotAxis(int rotIndex)
|
|
292 |
{
|
|
293 |
return mCastedRotAxis4D[mLastTouchedFace][rotIndex];
|
|
294 |
}
|
|
295 |
|
279 |
296 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
280 |
297 |
|
281 |
298 |
public int getTouchedFace()
|
Fix the way we continue rotation: when rotating a layer, we need to be doing it with respect to the RotAxis which has been first casted to the touched face, and only then this casted one is casted to the surface of the screen.
Before we were casting the rotAxis directly to the screen without the intermediate casting to the face, which doesn't really work in case of the Dino: if the touched face is rotated away by quite a lot, the rotAxis is then completely counterintuitive.