Revision ea9b68db
Added by Leszek Koltunski almost 5 years ago
src/main/java/org/distorted/examples/earth/EarthSurfaceView.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
class EarthSurfaceView extends GLSurfaceView |
35 | 35 |
{ |
36 |
private final static int DIRECTION_SENSITIVITY= 12; |
|
36 | 37 |
private int mX, mY; |
37 | 38 |
private EarthRenderer 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 |
|
src/main/java/org/distorted/examples/flag/FlagRenderer.java | ||
---|---|---|
102 | 102 |
Static3D center= new Static3D(0,0,0); |
103 | 103 |
|
104 | 104 |
effects.apply( new MatrixEffectScale(mScale)); |
105 |
effects.apply( new MatrixEffectQuaternion(mQuat1, center) ); |
|
106 | 105 |
effects.apply( new MatrixEffectQuaternion(mQuat2, center) ); |
106 |
effects.apply( new MatrixEffectQuaternion(mQuat1, center) ); |
|
107 | 107 |
|
108 | 108 |
mScreen = new DistortedScreen(); |
109 | 109 |
mScreen.attach(mTexture, effects, mesh ); |
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 |
|
src/main/java/org/distorted/examples/generic/GenericSurfaceView.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
class GenericSurfaceView extends GLSurfaceView |
32 | 32 |
{ |
33 |
private final static int DIRECTION_SENSITIVITY= 12; |
|
33 | 34 |
private int mX, mY; |
34 | 35 |
private GenericRenderer mRenderer; |
35 | 36 |
|
... | ... | |
56 | 57 |
return mRenderer; |
57 | 58 |
} |
58 | 59 |
|
60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
|
|
62 |
private void resetQuats() |
|
63 |
{ |
|
64 |
float qx = mRenderer.mQuat1.get0(); |
|
65 |
float qy = mRenderer.mQuat1.get1(); |
|
66 |
float qz = mRenderer.mQuat1.get2(); |
|
67 |
float qw = mRenderer.mQuat1.get3(); |
|
68 |
|
|
69 |
float rx = mRenderer.mQuat2.get0(); |
|
70 |
float ry = mRenderer.mQuat2.get1(); |
|
71 |
float rz = mRenderer.mQuat2.get2(); |
|
72 |
float rw = mRenderer.mQuat2.get3(); |
|
73 |
|
|
74 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
75 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
76 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
77 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
78 |
|
|
79 |
mRenderer.mQuat1.set(0f, 0f, 0f, 1f); |
|
80 |
mRenderer.mQuat2.set(tx, ty, tz, tw); |
|
81 |
} |
|
82 |
|
|
59 | 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
60 | 84 |
|
61 | 85 |
@Override |
... | ... | |
90 | 114 |
mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA); |
91 | 115 |
} |
92 | 116 |
} |
117 |
|
|
118 |
if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mRenderer.mScreenMin*mRenderer.mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) ) |
|
119 |
{ |
|
120 |
mX = x; |
|
121 |
mY = y; |
|
122 |
resetQuats(); |
|
123 |
} |
|
93 | 124 |
break; |
94 | 125 |
|
95 | 126 |
case MotionEvent.ACTION_UP : mX = -1; |
96 | 127 |
mY = -1; |
97 |
|
|
98 |
float qx = mRenderer.mQuat1.get0(); |
|
99 |
float qy = mRenderer.mQuat1.get1(); |
|
100 |
float qz = mRenderer.mQuat1.get2(); |
|
101 |
float qw = mRenderer.mQuat1.get3(); |
|
102 |
|
|
103 |
float rx = mRenderer.mQuat2.get0(); |
|
104 |
float ry = mRenderer.mQuat2.get1(); |
|
105 |
float rz = mRenderer.mQuat2.get2(); |
|
106 |
float rw = mRenderer.mQuat2.get3(); |
|
107 |
|
|
108 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
109 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
110 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
111 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
112 |
|
|
113 |
mRenderer.mQuat1.set(0f, 0f, 0f, 1f); |
|
114 |
mRenderer.mQuat2.set(tx, ty, tz, tw); |
|
115 |
|
|
128 |
resetQuats(); |
|
116 | 129 |
break; |
117 | 130 |
} |
118 | 131 |
|
src/main/java/org/distorted/examples/inflate/InflateRenderer.java | ||
---|---|---|
88 | 88 |
|
89 | 89 |
mEffects = new DistortedEffects(); |
90 | 90 |
mEffects.apply( new MatrixEffectScale(mScale)); |
91 |
mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) ); |
|
92 | 91 |
mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) ); |
92 |
mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) ); |
|
93 | 93 |
mEffects.apply( new FragmentEffectAlpha(mAlpha)); |
94 | 94 |
|
95 | 95 |
mScreen = new DistortedScreen(); |
src/main/java/org/distorted/examples/inflate/InflateSurfaceView.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
class InflateSurfaceView extends GLSurfaceView |
35 | 35 |
{ |
36 |
private final static int DIRECTION_SENSITIVITY= 12; |
|
36 | 37 |
private int mX, mY; |
37 | 38 |
private InflateRenderer 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 |
|
src/main/java/org/distorted/examples/meshjoin/MeshJoinRenderer.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.graphics.Bitmap; |
23 | 23 |
import android.graphics.BitmapFactory; |
24 |
import android.graphics.Canvas; |
|
25 |
import android.graphics.Paint; |
|
24 | 26 |
import android.opengl.GLSurfaceView; |
25 | 27 |
|
26 | 28 |
import org.distorted.examples.R; |
... | ... | |
29 | 31 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
30 | 32 |
import org.distorted.library.effect.MatrixEffectRotate; |
31 | 33 |
import org.distorted.library.effect.MatrixEffectScale; |
34 |
import org.distorted.library.effect.VertexEffectSink; |
|
32 | 35 |
import org.distorted.library.main.DistortedEffects; |
33 | 36 |
import org.distorted.library.main.DistortedLibrary; |
34 | 37 |
import org.distorted.library.main.DistortedScreen; |
35 | 38 |
import org.distorted.library.main.DistortedTexture; |
36 | 39 |
import org.distorted.library.mesh.MeshBase; |
37 | 40 |
import org.distorted.library.mesh.MeshJoined; |
38 |
import org.distorted.library.mesh.MeshQuad; |
|
39 |
import org.distorted.library.mesh.MeshRectangles; |
|
40 |
import org.distorted.library.mesh.MeshSphere; |
|
41 | 41 |
import org.distorted.library.mesh.MeshTriangles; |
42 |
import org.distorted.library.type.Dynamic1D; |
|
42 | 43 |
import org.distorted.library.type.DynamicQuat; |
43 | 44 |
import org.distorted.library.type.Static1D; |
44 | 45 |
import org.distorted.library.type.Static3D; |
... | ... | |
73 | 74 |
mScale= new Static3D(1,1,1); |
74 | 75 |
Static3D center=new Static3D(0,0,0); |
75 | 76 |
|
77 |
Dynamic1D sink = new Dynamic1D(5000,0.0f); |
|
78 |
sink.add( new Static1D(0.5f) ); |
|
79 |
sink.add( new Static1D(2.0f) ); |
|
80 |
|
|
76 | 81 |
mQuat1 = new Static4D(0,0,0,1); // unity |
77 | 82 |
mQuat2 = new Static4D(0,0,0,1); // quaternions |
78 | 83 |
|
... | ... | |
86 | 91 |
mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) ); |
87 | 92 |
mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) ); |
88 | 93 |
mEffects.apply( new MatrixEffectScale(mScale)); |
94 |
mEffects.apply( new VertexEffectSink( sink, center, new Static4D(0,0,0,0.75f) ) ); |
|
95 |
|
|
96 |
mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
|
89 | 97 |
} |
90 | 98 |
|
91 | 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
99 | 107 |
|
100 | 108 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
101 | 109 |
{ |
102 |
final float SCALE = 0.6f;
|
|
110 |
final float SCALE = 0.7f;
|
|
103 | 111 |
mScreenMin = width<height ? width:height; |
104 | 112 |
float factor = SCALE*mScreenMin; |
105 | 113 |
mScale.set(factor,factor,factor); |
... | ... | |
110 | 118 |
|
111 | 119 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
112 | 120 |
{ |
113 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.grid);
|
|
121 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.pyraminx);
|
|
114 | 122 |
Bitmap bitmap; |
115 | 123 |
|
116 | 124 |
try |
... | ... | |
127 | 135 |
} |
128 | 136 |
|
129 | 137 |
if( mTexture==null ) mTexture = new DistortedTexture(); |
130 |
mTexture.setTexture(bitmap);
|
|
138 |
mTexture.setTexture( createTetrahedronTexture(bitmap) );
|
|
131 | 139 |
|
132 | 140 |
if( mMesh==null ) mMesh = createJoinedTetrahedron(); |
133 | 141 |
|
134 |
// mMesh.setShowNormals(true);
|
|
142 |
//mMesh.setShowNormals(true);
|
|
135 | 143 |
|
136 | 144 |
mScreen.detachAll(); |
137 | 145 |
mScreen.attach(mTexture,mEffects,mMesh); |
138 | 146 |
|
147 |
VertexEffectSink.enable(); |
|
148 |
|
|
139 | 149 |
try |
140 | 150 |
{ |
141 | 151 |
DistortedLibrary.onCreate(mView.getContext()); |
... | ... | |
146 | 156 |
} |
147 | 157 |
} |
148 | 158 |
|
149 |
|
|
150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
151 |
|
|
152 |
private MeshBase createJoinedDoubleQuad() |
|
153 |
{ |
|
154 |
MeshBase[] meshes = new MeshBase[2]; |
|
155 |
meshes[0] = new MeshQuad(); |
|
156 |
meshes[1] = new MeshQuad(); |
|
157 |
|
|
158 |
MatrixEffect[] effects0 = new MatrixEffect[1]; |
|
159 |
effects0[0] = new MatrixEffectMove( new Static3D(0,+0.6f,0)); |
|
160 |
|
|
161 |
meshes[0].apply(effects0); |
|
162 |
|
|
163 |
MatrixEffect[] effects1 = new MatrixEffect[1]; |
|
164 |
effects1[0] = new MatrixEffectMove( new Static3D(0,-0.6f,0)); |
|
165 |
|
|
166 |
meshes[1].apply(effects1); |
|
167 |
|
|
168 |
return new MeshJoined(meshes); |
|
169 |
} |
|
170 |
|
|
171 | 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
172 | 160 |
|
173 |
private MeshBase createJoinedSphereAndTriangle()
|
|
161 |
private Bitmap createTetrahedronTexture(Bitmap input)
|
|
174 | 162 |
{ |
175 |
MeshBase[] meshes = new MeshBase[2];
|
|
176 |
meshes[0] = new MeshSphere(5);
|
|
177 |
meshes[1] = new MeshTriangles(5);
|
|
163 |
final int[] FACE_COLORS = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
|
|
164 |
final int FACES=FACE_COLORS.length;
|
|
165 |
int height = input.getHeight();
|
|
178 | 166 |
|
179 |
MatrixEffect[] effects0 = new MatrixEffect[2]; |
|
180 |
effects0[0] = new MatrixEffectScale( new Static3D(0.5f, 1.0f, 0.5f) ); |
|
181 |
effects0[1] = new MatrixEffectMove( new Static3D(+0.25f,0,0)); |
|
167 |
Bitmap result = Bitmap.createBitmap(FACES*height,height, Bitmap.Config.ARGB_8888); |
|
168 |
Canvas canvas = new Canvas(result); |
|
169 |
Paint paint = new Paint(); |
|
170 |
paint.setStyle(Paint.Style.FILL); |
|
182 | 171 |
|
183 |
meshes[0].apply(effects0); |
|
184 |
|
|
185 |
MatrixEffect[] effects1 = new MatrixEffect[2]; |
|
186 |
effects1[0] = new MatrixEffectScale( new Static3D(0.5f, 1.0f, 0.5f) ); |
|
187 |
effects1[1] = new MatrixEffectMove( new Static3D(-0.25f,0,0)); |
|
188 |
|
|
189 |
meshes[1].apply(effects1); |
|
190 |
|
|
191 |
return new MeshJoined(meshes); |
|
192 |
} |
|
193 |
|
|
194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 |
for(int i=0; i<FACES; i++) |
|
173 |
{ |
|
174 |
paint.setColor(FACE_COLORS[i]); |
|
175 |
canvas.drawRect(i*height,0,(i+1)*height,height,paint); |
|
176 |
canvas.drawBitmap(input,i*height,0,null); |
|
177 |
} |
|
195 | 178 |
|
196 |
private MeshBase createJoinedCube() |
|
197 |
{ |
|
198 |
final int MESHES=6; |
|
199 |
|
|
200 |
Static3D axisY = new Static3D(0,1,0); |
|
201 |
Static3D axisX = new Static3D(1,0,0); |
|
202 |
Static3D center = new Static3D(0,0,0); |
|
203 |
Static1D angle = new Static1D(0); |
|
204 |
|
|
205 |
MatrixEffect[] effectsY = new MatrixEffect[2]; |
|
206 |
effectsY[0] = new MatrixEffectMove(new Static3D(0,0,+0.5f)); |
|
207 |
effectsY[1] = new MatrixEffectRotate( angle, axisY, center ); |
|
208 |
|
|
209 |
MeshBase[] meshes = new MeshRectangles[MESHES]; |
|
210 |
for(int i=0; i<MESHES; i++) meshes[i] = new MeshRectangles(5,5); |
|
211 |
|
|
212 |
angle.set(0); |
|
213 |
meshes[0].apply(effectsY); |
|
214 |
angle.set(90); |
|
215 |
meshes[1].apply(effectsY); |
|
216 |
angle.set(180); |
|
217 |
meshes[2].apply(effectsY); |
|
218 |
angle.set(270); |
|
219 |
meshes[3].apply(effectsY); |
|
220 |
|
|
221 |
MatrixEffect[] effectsX = new MatrixEffect[2]; |
|
222 |
effectsX[0] = new MatrixEffectMove(new Static3D(0,0,+0.5f)); |
|
223 |
effectsX[1] = new MatrixEffectRotate( angle, axisX, center ); |
|
224 |
|
|
225 |
angle.set( 90); |
|
226 |
meshes[4].apply(effectsX); |
|
227 |
angle.set(-90); |
|
228 |
meshes[5].apply(effectsX); |
|
229 |
|
|
230 |
MeshJoined result = new MeshJoined(meshes); |
|
231 |
|
|
232 |
Static4D[] maps = new Static4D[MESHES]; |
|
233 |
|
|
234 |
maps[0] = new Static4D(3.0f/8, 3.0f/8, 2.0f/8, 2.0f/8); |
|
235 |
maps[1] = new Static4D(5.0f/8, 1.0f/8, 2.0f/8, 2.0f/8); |
|
236 |
maps[2] = new Static4D(1.0f/8, 5.0f/8, 2.0f/8, 2.0f/8); |
|
237 |
maps[3] = new Static4D(1.0f/8, 3.0f/8, 2.0f/8, 2.0f/8); |
|
238 |
maps[4] = new Static4D(3.0f/8, 1.0f/8, 2.0f/8, 2.0f/8); |
|
239 |
maps[5] = new Static4D(1.0f/8, 1.0f/8, 2.0f/8, 2.0f/8); |
|
240 |
|
|
241 |
result.setTextureMap(maps); |
|
242 | 179 |
return result; |
243 | 180 |
} |
244 | 181 |
|
... | ... | |
251 | 188 |
final int MESHES=4; |
252 | 189 |
|
253 | 190 |
MeshBase[] meshes = new MeshTriangles[MESHES]; |
254 |
for(int i=0; i<MESHES; i++) meshes[i] = new MeshTriangles(5);
|
|
191 |
for(int i=0; i<MESHES; i++) meshes[i] = new MeshTriangles(10);
|
|
255 | 192 |
|
256 | 193 |
MatrixEffect[] effects0 = new MatrixEffect[3]; |
257 | 194 |
effects0[0] = new MatrixEffectScale( new Static3D(1,SQ3/2,1) ); |
... | ... | |
279 | 216 |
axis.set2(SQ3/2); |
280 | 217 |
meshes[3].apply(effects1); |
281 | 218 |
|
282 |
return new MeshJoined(meshes); |
|
219 |
Static4D[] textureMaps = new Static4D[MESHES]; |
|
220 |
|
|
221 |
for(int i=0; i<MESHES; i++) textureMaps[i] = new Static4D(i*0.25f,0.0f,0.25f,0.866f); |
|
222 |
|
|
223 |
MeshBase result = new MeshJoined(meshes); |
|
224 |
result.setTextureMap(textureMaps); |
|
225 |
|
|
226 |
return result; |
|
283 | 227 |
} |
284 | 228 |
} |
src/main/java/org/distorted/examples/meshjoin/MeshJoinSurfaceView.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
class MeshJoinSurfaceView extends GLSurfaceView |
31 | 31 |
{ |
32 |
private final static int DIRECTION_SENSITIVITY= 12; |
|
32 | 33 |
private int mX, mY; |
33 | 34 |
private MeshJoinRenderer mRenderer; |
34 | 35 |
|
... | ... | |
56 | 57 |
} |
57 | 58 |
|
58 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
59 |
|
|
60 |
|
|
61 |
private void resetQuats() |
|
62 |
{ |
|
63 |
float qx = mRenderer.mQuat1.get0(); |
|
64 |
float qy = mRenderer.mQuat1.get1(); |
|
65 |
float qz = mRenderer.mQuat1.get2(); |
|
66 |
float qw = mRenderer.mQuat1.get3(); |
|
67 |
|
|
68 |
float rx = mRenderer.mQuat2.get0(); |
|
69 |
float ry = mRenderer.mQuat2.get1(); |
|
70 |
float rz = mRenderer.mQuat2.get2(); |
|
71 |
float rw = mRenderer.mQuat2.get3(); |
|
72 |
|
|
73 |
// This is quaternion multiplication. (tx,ty,tz,tw) |
|
74 |
// is now equal to (qx,qy,qz,qw)*(rx,ry,rz,rw) |
|
75 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
76 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
77 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
78 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
79 |
|
|
80 |
// The point of this is so that there are always |
|
81 |
// exactly 2 quaternions: Quat1 representing the rotation |
|
82 |
// accumulating only since the last screen touch, and Quat2 |
|
83 |
// which remembers the combined effect of all previous |
|
84 |
// swipes. |
|
85 |
// We cannot be accumulating an ever-growing list of quaternions |
|
86 |
// and add a new one every time user swipes the screen - there |
|
87 |
// is a limited number of slots in the EffectQueueMatrix! |
|
88 |
mRenderer.mQuat1.set(0f, 0f, 0f, 1f); |
|
89 |
mRenderer.mQuat2.set(tx, ty, tz, tw); |
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
60 | 94 |
@Override public boolean onTouchEvent(MotionEvent event) |
61 | 95 |
{ |
62 | 96 |
int action = event.getAction(); |
... | ... | |
87 | 121 |
|
88 | 122 |
mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA); |
89 | 123 |
} |
90 |
} |
|
124 |
} |
|
125 |
|
|
126 |
if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mRenderer.mScreenMin*mRenderer.mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) ) |
|
127 |
{ |
|
128 |
mX = x; |
|
129 |
mY = y; |
|
130 |
resetQuats(); |
|
131 |
} |
|
132 |
|
|
91 | 133 |
break; |
92 | 134 |
|
93 | 135 |
case MotionEvent.ACTION_UP : mX = -1; |
94 | 136 |
mY = -1; |
95 |
|
|
96 |
float qx = mRenderer.mQuat1.get0(); |
|
97 |
float qy = mRenderer.mQuat1.get1(); |
|
98 |
float qz = mRenderer.mQuat1.get2(); |
|
99 |
float qw = mRenderer.mQuat1.get3(); |
|
100 |
|
|
101 |
float rx = mRenderer.mQuat2.get0(); |
|
102 |
float ry = mRenderer.mQuat2.get1(); |
|
103 |
float rz = mRenderer.mQuat2.get2(); |
|
104 |
float rw = mRenderer.mQuat2.get3(); |
|
105 |
|
|
106 |
// This is quaternion multiplication. (tx,ty,tz,tw) |
|
107 |
// is now equal to (qx,qy,qz,qw)*(rx,ry,rz,rw) |
|
108 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
109 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
110 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
111 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
112 |
|
|
113 |
// The point of this is so that there are always |
|
114 |
// exactly 2 quaternions: Quat1 representing the rotation |
|
115 |
// accumulating only since the last screen touch, and Quat2 |
|
116 |
// which remembers the combined effect of all previous |
|
117 |
// swipes. |
|
118 |
// We cannot be accumulating an ever-growing list of quaternions |
|
119 |
// and add a new one every time user swipes the screen - there |
|
120 |
// is a limited number of slots in the EffectQueueMatrix! |
|
121 |
mRenderer.mQuat1.set(0f, 0f, 0f, 1f); |
|
122 |
mRenderer.mQuat2.set(tx, ty, tz, tw); |
|
123 |
|
|
137 |
resetQuats(); |
|
124 | 138 |
break; |
125 | 139 |
} |
126 | 140 |
|
src/main/java/org/distorted/examples/multiblur/MultiblurSurfaceView.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
class MultiblurSurfaceView extends GLSurfaceView |
35 | 35 |
{ |
36 |
private final static int DIRECTION_SENSITIVITY= 12; |
|
36 | 37 |
private int mX, mY; |
37 | 38 |
private MultiblurRenderer 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 |
|
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 |
|
src/main/java/org/distorted/examples/triblur/TriblurSurfaceView.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
class TriblurSurfaceView extends GLSurfaceView |
35 | 35 |
{ |
36 |
private final static int DIRECTION_SENSITIVITY= 12; |
|
36 | 37 |
private int mX, mY; |
37 | 38 |
private TriblurRenderer 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.