Revision ea9b68db
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/examples/flag/FlagSurfaceView.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
class FlagSurfaceView extends GLSurfaceView |
32 | 32 |
{ |
33 |
private final static int DIRECTION_SENSITIVITY= 12; |
|
33 | 34 |
private int mX, mY; |
34 | 35 |
private FlagRenderer mRenderer; |
35 | 36 |
|
... | ... | |
59 | 60 |
return mRenderer; |
60 | 61 |
} |
61 | 62 |
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
private void resetQuats() |
|
66 |
{ |
|
67 |
float qx = mRenderer.mQuat1.get0(); |
|
68 |
float qy = mRenderer.mQuat1.get1(); |
|
69 |
float qz = mRenderer.mQuat1.get2(); |
|
70 |
float qw = mRenderer.mQuat1.get3(); |
|
71 |
|
|
72 |
float rx = mRenderer.mQuat2.get0(); |
|
73 |
float ry = mRenderer.mQuat2.get1(); |
|
74 |
float rz = mRenderer.mQuat2.get2(); |
|
75 |
float rw = mRenderer.mQuat2.get3(); |
|
76 |
|
|
77 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
78 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
79 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
80 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
81 |
|
|
82 |
mRenderer.mQuat1.set(0f, 0f, 0f, 1f); |
|
83 |
mRenderer.mQuat2.set(tx, ty, tz, tw); |
|
84 |
} |
|
85 |
|
|
62 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
63 | 87 |
|
64 | 88 |
@Override public boolean onTouchEvent(MotionEvent event) |
... | ... | |
91 | 115 |
|
92 | 116 |
mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA); |
93 | 117 |
} |
94 |
} |
|
118 |
} |
|
119 |
if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mRenderer.mScreenMin*mRenderer.mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) ) |
|
120 |
{ |
|
121 |
mX = x; |
|
122 |
mY = y; |
|
123 |
resetQuats(); |
|
124 |
} |
|
95 | 125 |
break; |
96 | 126 |
|
97 | 127 |
case MotionEvent.ACTION_UP : mX = -1; |
98 | 128 |
mY = -1; |
99 |
|
|
100 |
float qx = mRenderer.mQuat1.get0(); |
|
101 |
float qy = mRenderer.mQuat1.get1(); |
|
102 |
float qz = mRenderer.mQuat1.get2(); |
|
103 |
float qw = mRenderer.mQuat1.get3(); |
|
104 |
|
|
105 |
float rx = mRenderer.mQuat2.get0(); |
|
106 |
float ry = mRenderer.mQuat2.get1(); |
|
107 |
float rz = mRenderer.mQuat2.get2(); |
|
108 |
float rw = mRenderer.mQuat2.get3(); |
|
109 |
|
|
110 |
// This is quaternion multiplication. (tx.ty.tz.tw) |
|
111 |
// is now equal to (qx,qy,qz,qw)*(rx,ry,rz,rw) |
|
112 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
113 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
114 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
115 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
116 |
|
|
117 |
// The point of this is so that there are always |
|
118 |
// exactly 2 quaternions: Quat1 representing the rotation |
|
119 |
// accumulating only since the last screen touch, and Quat2 |
|
120 |
// which remembers the combined effect of all previous |
|
121 |
// swipes. |
|
122 |
// We cannot be accumulating an ever-growing list of quaternions |
|
123 |
// and add a new one every time user swipes the screen - there |
|
124 |
// is a limited number of slots in the EffectQueueMatrix! |
|
125 |
mRenderer.mQuat1.set(0f, 0f, 0f, 1f); |
|
126 |
mRenderer.mQuat2.set(tx, ty, tz, tw); |
|
127 |
|
|
129 |
resetQuats(); |
|
128 | 130 |
break; |
129 | 131 |
} |
130 | 132 |
|
Also available in: Unified diff
Progress with MeshJoin app.
Fix rotating in some apps.