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