Revision 434f2f5a
Added by Leszek Koltunski over 5 years ago
src/main/java/org/distorted/effect/CubeEffect.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effect; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public interface CubeEffect |
|
25 |
{ |
|
26 |
|
|
27 |
} |
src/main/java/org/distorted/effect/TransitionEffect.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effect; |
|
21 |
|
|
22 |
import org.distorted.library.main.DistortedScreen; |
|
23 |
import org.distorted.library.message.EffectListener; |
|
24 |
import org.distorted.magic.RubikCube; |
|
25 |
|
|
26 |
import java.lang.reflect.Method; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
public abstract class TransitionEffect |
|
31 |
{ |
|
32 |
public enum Type |
|
33 |
{ |
|
34 |
/** |
|
35 |
* No transition effect at all, just detach the old cube and attach the new one straight away. |
|
36 |
*/ |
|
37 |
EMPTY (TransitionEffectEmpty.class), |
|
38 |
/** |
|
39 |
* Gradually make the old cube more and more transparent until it disappears, then make the new one appear. |
|
40 |
*/ |
|
41 |
DISAPPEAR (TransitionEffectDisappear.class); |
|
42 |
|
|
43 |
private final Class<? extends TransitionEffect> effectClass; |
|
44 |
|
|
45 |
Type(Class<? extends TransitionEffect> effectClass) |
|
46 |
{ |
|
47 |
this.effectClass = effectClass; |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
52 |
|
|
53 |
public abstract long prepare(EffectListener listener); |
|
54 |
public abstract void start(DistortedScreen screen, RubikCube oldCube, RubikCube newCube); |
|
55 |
|
|
56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
public static TransitionEffect createEffect(Type type) throws InstantiationException, IllegalAccessException |
|
59 |
{ |
|
60 |
return type.effectClass.newInstance(); |
|
61 |
} |
|
62 |
|
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
public static void enableEffects() |
|
66 |
{ |
|
67 |
Method method=null; |
|
68 |
|
|
69 |
for(Type type: Type.values()) |
|
70 |
{ |
|
71 |
Class<? extends TransitionEffect> cls = type.effectClass; |
|
72 |
|
|
73 |
try |
|
74 |
{ |
|
75 |
method = cls.getMethod("enable"); |
|
76 |
} |
|
77 |
catch(NoSuchMethodException ex) |
|
78 |
{ |
|
79 |
android.util.Log.e("transitionEffect", "exception getting method: "+ex.getMessage()); |
|
80 |
} |
|
81 |
|
|
82 |
try |
|
83 |
{ |
|
84 |
method.invoke(null); |
|
85 |
} |
|
86 |
catch(Exception ex) |
|
87 |
{ |
|
88 |
android.util.Log.e("transitionEffect", "exception invoking method: "+ex.getMessage()); |
|
89 |
} |
|
90 |
} |
|
91 |
} |
|
92 |
} |
src/main/java/org/distorted/effect/TransitionEffectDisappear.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effect; |
|
21 |
|
|
22 |
import org.distorted.library.effect.FragmentEffectAlpha; |
|
23 |
import org.distorted.library.main.DistortedScreen; |
|
24 |
import org.distorted.library.message.EffectListener; |
|
25 |
import org.distorted.library.message.EffectMessage; |
|
26 |
import org.distorted.library.type.Dynamic1D; |
|
27 |
import org.distorted.library.type.Static1D; |
|
28 |
import org.distorted.magic.RubikCube; |
|
29 |
|
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
class TransitionEffectDisappear extends TransitionEffect implements EffectListener |
|
33 |
{ |
|
34 |
private static final int DURATION_IN_MILLIS = 1000; |
|
35 |
|
|
36 |
private EffectListener mListener; |
|
37 |
private FragmentEffectAlpha mDisappear, mAppear; |
|
38 |
private DistortedScreen mScreen; |
|
39 |
private RubikCube mOld, mNew; |
|
40 |
|
|
41 |
private long mDisappearID; |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
|
|
45 |
TransitionEffectDisappear() |
|
46 |
{ |
|
47 |
|
|
48 |
} |
|
49 |
|
|
50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
51 |
// enable all effects we are using in this Transition. |
|
52 |
// called by reflection from the parent class. |
|
53 |
|
|
54 |
@SuppressWarnings("unused") |
|
55 |
static void enable() |
|
56 |
{ |
|
57 |
FragmentEffectAlpha.enable(); |
|
58 |
} |
|
59 |
|
|
60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
|
|
62 |
public long prepare(EffectListener listener) |
|
63 |
{ |
|
64 |
mListener = listener; |
|
65 |
|
|
66 |
Dynamic1D disappearDyn = new Dynamic1D(DURATION_IN_MILLIS, 0.5f); // this means - linearily change the |
|
67 |
disappearDyn.add(new Static1D(1.0f)); // alpha of the old cube from 1.0 (100%) |
|
68 |
disappearDyn.add(new Static1D(0.0f)); // to 0.0 (0%) within DURATION millisecs. |
|
69 |
mDisappear = new FragmentEffectAlpha(disappearDyn); |
|
70 |
|
|
71 |
Dynamic1D appearDyn = new Dynamic1D(DURATION_IN_MILLIS, 0.5f); // the opposite - make the new cube |
|
72 |
appearDyn.add(new Static1D(0.0f)); // more and more opaque. |
|
73 |
appearDyn.add(new Static1D(1.0f)); // |
|
74 |
mAppear = new FragmentEffectAlpha(appearDyn); |
|
75 |
|
|
76 |
mDisappearID = mDisappear.getID(); |
|
77 |
|
|
78 |
return mAppear.getID(); |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
// At the start, oldCube is attached to the screen, new is not. |
|
83 |
// Gradually make the old cube disappear and wait for the message that this is done. |
|
84 |
|
|
85 |
public void start(DistortedScreen screen, RubikCube oldCube, RubikCube newCube) |
|
86 |
{ |
|
87 |
mScreen = screen; |
|
88 |
mNew = newCube; |
|
89 |
mOld = oldCube; |
|
90 |
|
|
91 |
mOld.apply(mDisappear); |
|
92 |
mOld.registerForMessages(this); |
|
93 |
} |
|
94 |
|
|
95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
96 |
// whenever we get the message that the old cube completely disappeared, make the new one appear |
|
97 |
// The calling RubikRenderer will get the message that this (final) transition is over and do whatever |
|
98 |
// it wants to do with this. |
|
99 |
|
|
100 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID) |
|
101 |
{ |
|
102 |
if( effectID == mDisappearID ) |
|
103 |
{ |
|
104 |
mScreen.detachAll(); |
|
105 |
mNew.attachToScreen(mScreen); |
|
106 |
mNew.apply(mAppear); |
|
107 |
mOld.deregisterForMessages(this); |
|
108 |
mNew.registerForMessages(mListener); |
|
109 |
} |
|
110 |
} |
|
111 |
} |
src/main/java/org/distorted/effect/TransitionEffectEmpty.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effect; |
|
21 |
|
|
22 |
import org.distorted.library.main.DistortedScreen; |
|
23 |
import org.distorted.library.message.EffectListener; |
|
24 |
import org.distorted.magic.RubikCube; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
class TransitionEffectEmpty extends TransitionEffect |
|
29 |
{ |
|
30 |
private static final int FAKE_EFFECT_ID = -1; |
|
31 |
|
|
32 |
private EffectListener mListener; |
|
33 |
|
|
34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
35 |
|
|
36 |
TransitionEffectEmpty() |
|
37 |
{ |
|
38 |
|
|
39 |
} |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
// enable all effects we are using in this Transition (here: none). |
|
43 |
// called by reflection from the parent class. |
|
44 |
|
|
45 |
@SuppressWarnings("unused") |
|
46 |
static void enable() |
|
47 |
{ |
|
48 |
|
|
49 |
} |
|
50 |
|
|
51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
52 |
// return a fake effect ID (because there's no real effect here - empty transition! |
|
53 |
|
|
54 |
public long prepare(EffectListener listener) |
|
55 |
{ |
|
56 |
mListener = listener; |
|
57 |
return FAKE_EFFECT_ID; |
|
58 |
} |
|
59 |
|
|
60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
// we just detach the old cube, attach the new one and manually send a message with the '-1' id |
|
62 |
// back to the listener (RubikRenderer) |
|
63 |
|
|
64 |
public void start(DistortedScreen screen, RubikCube oldCube, RubikCube newCube) |
|
65 |
{ |
|
66 |
screen.detachAll(); |
|
67 |
newCube.attachToScreen(screen); |
|
68 |
|
|
69 |
mListener.effectMessage(null, FAKE_EFFECT_ID, 0); |
|
70 |
} |
|
71 |
} |
src/main/java/org/distorted/magic/RubikCube.java | ||
---|---|---|
23 | 23 |
import android.graphics.Canvas; |
24 | 24 |
import android.graphics.Paint; |
25 | 25 |
|
26 |
import org.distorted.library.effect.Effect; |
|
26 | 27 |
import org.distorted.library.effect.MatrixEffectMove; |
27 | 28 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
28 | 29 |
import org.distorted.library.effect.MatrixEffectRotate; |
... | ... | |
41 | 42 |
|
42 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
43 | 44 |
|
44 |
class RubikCube |
|
45 |
public class RubikCube
|
|
45 | 46 |
{ |
46 | 47 |
private static final int POST_ROTATION_MILLISEC = 500; |
47 | 48 |
private static final int TEXTURE_SIZE = 100; |
... | ... | |
57 | 58 |
private Static3D[][][] mRotationAxis; |
58 | 59 |
private Dynamic1D[][][] mRotationAngle; |
59 | 60 |
private Static3D[][][] mCurrentPosition; |
61 |
private MatrixEffectRotate[][][] mRotateEffect; |
|
60 | 62 |
private Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal; |
63 |
private Static3D mMove, mScale; |
|
61 | 64 |
private DistortedTexture mTexture; |
62 | 65 |
private DistortedEffects mEffectsListeningForNow; |
63 | 66 |
|
... | ... | |
66 | 69 |
|
67 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 71 |
|
69 |
RubikCube(int size, Static3D move, Static3D scale, Static4D quatC, Static4D quatA)
|
|
72 |
RubikCube(int size, Static4D quatC, Static4D quatA) |
|
70 | 73 |
{ |
71 | 74 |
mSize = size; |
72 | 75 |
|
... | ... | |
74 | 77 |
mRotationAngleMiddle = new Static1D(0); |
75 | 78 |
mRotationAngleFinal = new Static1D(0); |
76 | 79 |
|
80 |
mMove = new Static3D(0,0,0); |
|
81 |
mScale= new Static3D(1,1,1); |
|
82 |
|
|
77 | 83 |
mRotAxis= RubikSurfaceView.VECTX; |
78 | 84 |
mTexture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE); |
79 | 85 |
|
... | ... | |
84 | 90 |
mRotationAxis = new Static3D[mSize][mSize][mSize]; |
85 | 91 |
mRotationAngle = new Dynamic1D[mSize][mSize][mSize]; |
86 | 92 |
mCurrentPosition= new Static3D[mSize][mSize][mSize]; |
93 |
mRotateEffect = new MatrixEffectRotate[mSize][mSize][mSize]; |
|
87 | 94 |
|
88 | 95 |
Static3D[][][] cubeVectors = new Static3D[mSize][mSize][mSize]; |
89 | 96 |
|
... | ... | |
91 | 98 |
Static4D region = new Static4D(0,0,0, TEXTURE_SIZE*0.72f); |
92 | 99 |
|
93 | 100 |
VertexEffectSink sinkEffect = new VertexEffectSink( new Static1D(getSinkStrength()), center, region ); |
94 |
MatrixEffectMove moveEffect = new MatrixEffectMove(move); |
|
95 |
MatrixEffectScale scaleEffect = new MatrixEffectScale(scale);
|
|
101 |
MatrixEffectMove moveEffect = new MatrixEffectMove(mMove);
|
|
102 |
MatrixEffectScale scaleEffect = new MatrixEffectScale(mScale);
|
|
96 | 103 |
MatrixEffectQuaternion quatCEffect = new MatrixEffectQuaternion(quatC, center); |
97 | 104 |
MatrixEffectQuaternion quatAEffect = new MatrixEffectQuaternion(quatA, center); |
98 | 105 |
|
... | ... | |
139 | 146 |
mRotationAngle[x][y][z] = new Dynamic1D(); |
140 | 147 |
mRotationAxis[x][y][z] = new Static3D(1,0,0); |
141 | 148 |
mCurrentPosition[x][y][z] = new Static3D(x,y,z); |
149 |
mRotateEffect[x][y][z] = new MatrixEffectRotate(mRotationAngle[x][y][z], mRotationAxis[x][y][z], center); |
|
142 | 150 |
|
143 | 151 |
mEffects[x][y][z] = new DistortedEffects(); |
144 | 152 |
mEffects[x][y][z].apply(sinkEffect); |
... | ... | |
146 | 154 |
mEffects[x][y][z].apply(scaleEffect); |
147 | 155 |
mEffects[x][y][z].apply(quatCEffect); |
148 | 156 |
mEffects[x][y][z].apply(quatAEffect); |
149 |
mEffects[x][y][z].apply( new MatrixEffectRotate( mRotationAngle[x][y][z], mRotationAxis[x][y][z], center));
|
|
157 |
mEffects[x][y][z].apply(mRotateEffect[x][y][z]);
|
|
150 | 158 |
mEffects[x][y][z].apply( new MatrixEffectQuaternion(mQuatScramble[x][y][z], center)); |
151 | 159 |
mEffects[x][y][z].apply( new MatrixEffectMove(cubeVectors[x][y][z]) ); |
152 | 160 |
} |
... | ... | |
155 | 163 |
|
156 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
157 | 165 |
|
158 |
void attachToScreen(DistortedScreen screen) |
|
166 |
public void attachToScreen(DistortedScreen screen)
|
|
159 | 167 |
{ |
160 | 168 |
for(int x=0; x<mSize; x++) |
161 | 169 |
for(int y=0; y<mSize; y++) |
... | ... | |
169 | 177 |
} |
170 | 178 |
} |
171 | 179 |
|
180 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
181 |
|
|
182 |
public void apply(Effect effect) |
|
183 |
{ |
|
184 |
for(int x=0; x<mSize; x++) |
|
185 |
for(int y=0; y<mSize; y++) |
|
186 |
for(int z=0; z<mSize; z++) |
|
187 |
{ |
|
188 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
|
189 |
{ |
|
190 |
mEffects[x][y][z].apply(effect); |
|
191 |
} |
|
192 |
} |
|
193 |
} |
|
194 |
|
|
195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
196 |
|
|
197 |
public void registerForMessages(EffectListener listener) |
|
198 |
{ |
|
199 |
mEffects[0][0][0].registerForMessages(listener); |
|
200 |
} |
|
201 |
|
|
202 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
203 |
|
|
204 |
public void deregisterForMessages(EffectListener listener) |
|
205 |
{ |
|
206 |
mEffects[0][0][0].deregisterForMessages(listener); |
|
207 |
} |
|
208 |
|
|
172 | 209 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
173 | 210 |
// all DistortedTextures, DistortedNodes, DistortedFramebuffers, DistortedScreens and all types of |
174 | 211 |
// Meshes HAVE TO be markedForDeletion when they are no longer needed- otherwise we have a major |
... | ... | |
242 | 279 |
|
243 | 280 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
244 | 281 |
|
245 |
void finishRotationNow(EffectListener listener)
|
|
282 |
long finishRotationNow(EffectListener listener)
|
|
246 | 283 |
{ |
247 | 284 |
boolean first = true; |
248 | 285 |
float startingAngle = mRotationAngleStatic.get1(); |
249 | 286 |
int nearestAngleInDegrees = computeNearestAngle(startingAngle); |
287 |
long effectID=0; |
|
250 | 288 |
|
251 | 289 |
mRotationAngleFinal.set1(nearestAngleInDegrees); |
252 | 290 |
mRotationAngleMiddle.set1( nearestAngleInDegrees + (nearestAngleInDegrees-startingAngle)*0.2f ); |
... | ... | |
267 | 305 |
first = false; |
268 | 306 |
mEffectsListeningForNow = mEffects[x][y][z]; |
269 | 307 |
mEffectsListeningForNow.registerForMessages(listener); |
308 |
effectID = mRotateEffect[x][y][z].getID(); |
|
270 | 309 |
} |
271 | 310 |
} |
272 | 311 |
} |
312 |
|
|
313 |
return effectID; |
|
273 | 314 |
} |
274 | 315 |
|
275 | 316 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
411 | 452 |
|
412 | 453 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
413 | 454 |
|
414 |
float getTextureSize() |
|
415 |
{ |
|
416 |
return TEXTURE_SIZE; |
|
417 |
} |
|
455 |
void recomputeScaleFactor(int screenWidth, int screenHeight, float size) |
|
456 |
{ |
|
457 |
float scaleFactor = size/(TEXTURE_SIZE*mSize); |
|
458 |
|
|
459 |
mMove.set( (screenWidth-scaleFactor*TEXTURE_SIZE)/2 , (screenHeight-scaleFactor*TEXTURE_SIZE)/2 , -scaleFactor*TEXTURE_SIZE/2 ); |
|
460 |
mScale.set(scaleFactor,scaleFactor,scaleFactor); |
|
461 |
} |
|
418 | 462 |
|
419 | 463 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
420 | 464 |
|
src/main/java/org/distorted/magic/RubikRenderer.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.opengl.GLSurfaceView; |
23 | 23 |
|
24 |
import org.distorted.effect.TransitionEffect; |
|
24 | 25 |
import org.distorted.library.effect.VertexEffectSink; |
25 | 26 |
import org.distorted.library.main.DistortedLibrary; |
26 | 27 |
import org.distorted.library.main.DistortedScreen; |
27 | 28 |
import org.distorted.library.message.EffectListener; |
28 | 29 |
import org.distorted.library.message.EffectMessage; |
29 |
import org.distorted.library.type.Static3D; |
|
30 | 30 |
import org.distorted.library.type.Static4D; |
31 | 31 |
|
32 | 32 |
import javax.microedition.khronos.egl.EGLConfig; |
... | ... | |
41 | 41 |
|
42 | 42 |
private RubikSurfaceView mView; |
43 | 43 |
private DistortedScreen mScreen; |
44 |
private Static3D mMove, mScale; |
|
45 | 44 |
private Static4D mQuatCurrent, mQuatAccumulated; |
46 | 45 |
private Static4D mTempCurrent, mTempAccumulated; |
47 | 46 |
private float mCubeSizeInScreenSpace; |
48 | 47 |
private int mNextCubeSize; |
48 |
private long mRotationFinishedID, mTransitionEffectID; |
|
49 | 49 |
private boolean mFinishRotation, mRemoveRotation, mFinishDragCurrent, mFinishDragAccumulated; |
50 |
private boolean mCanRotate; |
|
51 |
private RubikCube mCube; |
|
50 |
private boolean mCanRotate, mCanDrag;
|
|
51 |
private RubikCube mOldCube, mNewCube;
|
|
52 | 52 |
|
53 | 53 |
private int mScreenWidth, mScreenHeight; |
54 | 54 |
|
... | ... | |
60 | 60 |
|
61 | 61 |
mScreen = new DistortedScreen(); |
62 | 62 |
|
63 |
mOldCube = null; |
|
64 |
mNewCube = null; |
|
65 |
|
|
63 | 66 |
mTempCurrent = new Static4D(0,0,0,1); |
64 | 67 |
mTempAccumulated = initializeQuat(); |
65 | 68 |
mQuatCurrent = new Static4D(0,0,0,1); |
... | ... | |
67 | 70 |
|
68 | 71 |
mScreenWidth = mScreenHeight = 0; |
69 | 72 |
|
70 |
mMove = new Static3D(0,0,0); |
|
71 |
mScale = new Static3D(1,1,1); |
|
72 |
|
|
73 | 73 |
mFinishRotation = false; |
74 | 74 |
mRemoveRotation = false; |
75 | 75 |
mFinishDragCurrent = false; |
... | ... | |
78 | 78 |
mNextCubeSize= 0; |
79 | 79 |
|
80 | 80 |
mCanRotate = true; |
81 |
mCanDrag = true; |
|
81 | 82 |
} |
82 | 83 |
|
83 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
104 | 105 |
{ |
105 | 106 |
mCanRotate = false; |
106 | 107 |
mFinishRotation=false; |
107 |
mCube.finishRotationNow(this); |
|
108 |
mRotationFinishedID = mNewCube.finishRotationNow(this);
|
|
108 | 109 |
} |
109 | 110 |
|
110 | 111 |
if( mRemoveRotation ) |
111 | 112 |
{ |
112 | 113 |
mRemoveRotation=false; |
113 |
mCube.removeRotationNow(this); |
|
114 |
mNewCube.removeRotationNow(this);
|
|
114 | 115 |
mCanRotate = true; |
115 | 116 |
} |
116 | 117 |
|
117 | 118 |
if( mNextCubeSize!=0 ) |
118 | 119 |
{ |
120 |
mCanDrag = false; |
|
121 |
mCanRotate = false; |
|
119 | 122 |
createCubeNow(mNextCubeSize); |
120 |
mScreen.detachAll(); |
|
121 |
mCube.attachToScreen(mScreen); |
|
123 |
|
|
124 |
try |
|
125 |
{ |
|
126 |
TransitionEffect effect = TransitionEffect.createEffect(TransitionEffect.Type.DISAPPEAR); |
|
127 |
mTransitionEffectID = effect.prepare(this); |
|
128 |
effect.start(mScreen,mOldCube,mNewCube); |
|
129 |
} |
|
130 |
catch(Exception ex) |
|
131 |
{ |
|
132 |
android.util.Log.e("Renderer", "failed to create TransitionEffect, exception: "+ex.getMessage()); |
|
133 |
} |
|
134 |
|
|
122 | 135 |
mNextCubeSize = 0; |
123 |
mCanRotate = true; // it can happen that we have just changed the size of the cube while |
|
124 |
// finishing rotation and never removed it! |
|
125 | 136 |
} |
126 | 137 |
} |
127 | 138 |
|
... | ... | |
130 | 141 |
|
131 | 142 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID) |
132 | 143 |
{ |
133 |
switch(em) |
|
134 |
{ |
|
135 |
case EFFECT_FINISHED: mRemoveRotation = true; break; |
|
136 |
} |
|
144 |
if( effectID == mRotationFinishedID ) |
|
145 |
{ |
|
146 |
mRemoveRotation = true; |
|
147 |
} |
|
148 |
else if( effectID == mTransitionEffectID ) |
|
149 |
{ |
|
150 |
mCanRotate = true; |
|
151 |
mCanDrag = true; |
|
152 |
} |
|
137 | 153 |
} |
138 | 154 |
|
139 | 155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
158 | 174 |
|
159 | 175 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
160 | 176 |
{ |
161 |
mCube.createTexture(); |
|
177 |
mNewCube.createTexture();
|
|
162 | 178 |
mScreen.detachAll(); |
163 |
mCube.attachToScreen(mScreen); |
|
179 |
mNewCube.attachToScreen(mScreen);
|
|
164 | 180 |
|
165 | 181 |
VertexEffectSink.enable(); |
182 |
TransitionEffect.enableEffects(); |
|
166 | 183 |
|
167 | 184 |
try |
168 | 185 |
{ |
... | ... | |
201 | 218 |
|
202 | 219 |
void createCubeNow(int newSize) |
203 | 220 |
{ |
204 |
int oldSize = mCube==null ? 0 : mCube.getSize();
|
|
221 |
int oldSize = mNewCube==null ? 0 : mNewCube.getSize();
|
|
205 | 222 |
|
206 | 223 |
if( oldSize!=newSize ) |
207 | 224 |
{ |
208 |
if( mCube!=null ) mCube.releaseResources(); |
|
209 |
mCube = new RubikCube(newSize, mMove, mScale, mQuatCurrent, mQuatAccumulated); |
|
210 |
mCube.createTexture(); |
|
225 |
if( mOldCube!=null ) mOldCube.releaseResources(); |
|
226 |
mOldCube = mNewCube; |
|
227 |
|
|
228 |
mNewCube = new RubikCube(newSize, mQuatCurrent, mQuatAccumulated); |
|
229 |
mNewCube.createTexture(); |
|
211 | 230 |
|
212 | 231 |
if( mScreenWidth!=0 ) |
213 | 232 |
{ |
... | ... | |
221 | 240 |
private void recomputeScaleFactor(int screenWidth, int screenHeight) |
222 | 241 |
{ |
223 | 242 |
mCubeSizeInScreenSpace = CUBE_SCREEN_RATIO*(screenWidth>screenHeight ? screenHeight:screenWidth); |
224 |
float texSize = mCube.getTextureSize(); |
|
225 |
float scaleFactor = mCubeSizeInScreenSpace/(texSize*mCube.getSize()); |
|
226 |
|
|
227 |
mMove.set( (screenWidth-scaleFactor*texSize)/2 , (screenHeight-scaleFactor*texSize)/2 , -scaleFactor*texSize/2 ); |
|
228 |
mScale.set(scaleFactor,scaleFactor,scaleFactor); |
|
243 |
mNewCube.recomputeScaleFactor(screenWidth, screenHeight, mCubeSizeInScreenSpace); |
|
229 | 244 |
} |
230 | 245 |
|
231 | 246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
249 | 264 |
return mCanRotate; |
250 | 265 |
} |
251 | 266 |
|
267 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
268 |
|
|
269 |
boolean canDrag() |
|
270 |
{ |
|
271 |
return mCanDrag; |
|
272 |
} |
|
273 |
|
|
252 | 274 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
253 | 275 |
|
254 | 276 |
RubikCube getCube() |
255 | 277 |
{ |
256 |
return mCube; |
|
278 |
return mNewCube;
|
|
257 | 279 |
} |
258 | 280 |
|
259 | 281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikSurfaceView.java | ||
---|---|---|
115 | 115 |
} |
116 | 116 |
else |
117 | 117 |
{ |
118 |
mDragging = true;
|
|
118 |
mDragging = mRenderer.canDrag();
|
|
119 | 119 |
mBeginningRotation = false; |
120 | 120 |
mContinuingRotation = false; |
121 | 121 |
} |
Also available in: Unified diff
DistortedCube: progress with abstract Transition Effects.