Revision f291130e
Added by Leszek Koltunski over 5 years ago
src/main/java/org/distorted/effect/TransitionEffect.java | ||
---|---|---|
33 | 33 |
{ |
34 | 34 |
public enum Type |
35 | 35 |
{ |
36 |
/** |
|
37 |
* No transition effect at all, just detach the old cube and attach the new one straight away. |
|
38 |
*/ |
|
39 |
EMPTY (TransitionEffectEmpty.class), |
|
40 |
/** |
|
41 |
* Gradually make the old cube more and more transparent until it disappears, then make the new one appear. |
|
42 |
*/ |
|
36 |
EMPTY (TransitionEffectEmpty.class ), |
|
43 | 37 |
DISAPPEAR (TransitionEffectDisappear.class), |
44 |
/**
|
|
45 |
* Move the old cube to the right and the new one from the left.
|
|
46 |
*/
|
|
47 |
MOVE (TransitionEffectMove.class);
|
|
38 |
MOVE (TransitionEffectMove.class ),
|
|
39 |
ROUND (TransitionEffectRound.class ),
|
|
40 |
SCALE (TransitionEffectScale.class ),
|
|
41 |
; |
|
48 | 42 |
|
49 | 43 |
private final Class<? extends TransitionEffect> effectClass; |
50 | 44 |
|
... | ... | |
54 | 48 |
} |
55 | 49 |
} |
56 | 50 |
|
57 |
private final int MOVE_POSITION; |
|
58 |
private long mDisappearID, mAppearID; |
|
51 |
private final int FAKE_EFFECT_ID = -1; |
|
52 |
|
|
53 |
private int mOldCubeEffectNumber , mNewCubeEffectNumber; |
|
54 |
private int mOldCubeEffectReturned, mNewCubeEffectReturned; |
|
55 |
|
|
59 | 56 |
private EffectListener mListener; |
60 | 57 |
private DistortedScreen mScreen; |
61 |
private RubikCube mOld, mNew;
|
|
58 |
private RubikCube mOldCube, mNewCube;
|
|
62 | 59 |
|
63 |
Effect mDisappear, mAppear; |
|
60 |
Effect[] mOldCubeEffects, mNewCubeEffects; |
|
61 |
int[] mOldCubeEffectPosition, mNewCubeEffectPosition; |
|
64 | 62 |
|
65 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
66 | 64 |
|
67 |
TransitionEffect(int position)
|
|
65 |
TransitionEffect() |
|
68 | 66 |
{ |
69 |
MOVE_POSITION = position; |
|
67 |
mOldCubeEffectReturned = 0; |
|
68 |
mNewCubeEffectReturned = 0; |
|
70 | 69 |
} |
71 | 70 |
|
72 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
73 |
// whenever we get the message that the old cube completely disappeared, make the new one appear |
|
74 |
// The calling RubikRenderer will get the message that this (final) transition is over and do whatever |
|
75 |
// it wants to do with this. |
|
76 | 72 |
|
77 | 73 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID) |
78 | 74 |
{ |
79 |
if( effectID == mDisappearID ) |
|
75 |
//android.util.Log.e("transition", "transition effect "+System.currentTimeMillis()); |
|
76 |
|
|
77 |
for(int i=0; i<mOldCubeEffectNumber; i++) |
|
80 | 78 |
{ |
81 |
mScreen.detach(mOld); |
|
82 |
mOld.remove(mDisappearID); |
|
83 |
mOld.deregisterForMessages(this); |
|
79 |
long id = mOldCubeEffects[i].getID(); |
|
80 |
|
|
81 |
if( effectID == id ) |
|
82 |
{ |
|
83 |
//android.util.Log.e("transition", i+" old effect "+System.currentTimeMillis()); |
|
84 |
|
|
85 |
mOldCubeEffectReturned++; |
|
86 |
mOldCube.remove(id); |
|
87 |
|
|
88 |
if( mOldCubeEffectReturned == mOldCubeEffectNumber ) |
|
89 |
{ |
|
90 |
mScreen.detach(mOldCube); |
|
91 |
mOldCube.deregisterForMessages(this); |
|
92 |
|
|
93 |
for(int j=0; j<mOldCubeEffectNumber; j++) |
|
94 |
{ |
|
95 |
mNewCube.apply(mNewCubeEffects[j],mNewCubeEffectPosition[j]); |
|
96 |
} |
|
97 |
mScreen.attach(mNewCube); |
|
98 |
} |
|
99 |
break; |
|
100 |
} |
|
101 |
} |
|
84 | 102 |
|
85 |
mNew.apply(mAppear,MOVE_POSITION); |
|
86 |
mNew.registerForMessages(mListener); |
|
87 |
mScreen.attach(mNew); |
|
103 |
for(int i=0; i<mNewCubeEffectNumber; i++) |
|
104 |
{ |
|
105 |
long id = mNewCubeEffects[i].getID(); |
|
106 |
|
|
107 |
if( effectID == id ) |
|
108 |
{ |
|
109 |
//android.util.Log.e("transition", i+" new effect "+System.currentTimeMillis()); |
|
110 |
|
|
111 |
mNewCubeEffectReturned++; |
|
112 |
mNewCube.remove(id); |
|
113 |
|
|
114 |
if( mNewCubeEffectReturned == mNewCubeEffectNumber ) |
|
115 |
{ |
|
116 |
mNewCube.deregisterForMessages(this); |
|
117 |
mListener.effectMessage(null, FAKE_EFFECT_ID, 0); |
|
118 |
} |
|
119 |
break; |
|
120 |
} |
|
88 | 121 |
} |
89 | 122 |
} |
90 | 123 |
|
... | ... | |
93 | 126 |
public long start(DistortedScreen screen, RubikCube oldCube, RubikCube newCube,EffectListener listener) |
94 | 127 |
{ |
95 | 128 |
mScreen = screen; |
96 |
mNew = newCube;
|
|
97 |
mOld = oldCube;
|
|
129 |
mNewCube = newCube;
|
|
130 |
mOldCube = oldCube;
|
|
98 | 131 |
mListener = listener; |
99 | 132 |
|
100 |
mDisappearID = mDisappear.getID(); |
|
101 |
mAppearID = mAppear.getID(); |
|
133 |
if( mOldCubeEffects!=null ) |
|
134 |
{ |
|
135 |
mOldCubeEffectNumber = mOldCubeEffects.length; |
|
136 |
} |
|
137 |
else |
|
138 |
{ |
|
139 |
throw new RuntimeException("Old Cube Effects not created!"); |
|
140 |
} |
|
141 |
|
|
142 |
if( mNewCubeEffects!=null ) |
|
143 |
{ |
|
144 |
mNewCubeEffectNumber = mNewCubeEffects.length; |
|
145 |
} |
|
146 |
else |
|
147 |
{ |
|
148 |
throw new RuntimeException("New Cube Effects not created!"); |
|
149 |
} |
|
150 |
|
|
151 |
for(int i=0; i<mOldCubeEffectNumber; i++) |
|
152 |
{ |
|
153 |
mOldCube.apply(mOldCubeEffects[i],mOldCubeEffectPosition[i]); |
|
154 |
} |
|
102 | 155 |
|
103 |
mOld.apply(mDisappear,MOVE_POSITION);
|
|
104 |
mOld.registerForMessages(this);
|
|
156 |
mOldCube.registerForMessages(this);
|
|
157 |
mNewCube.registerForMessages(this);
|
|
105 | 158 |
|
106 |
return mAppearID;
|
|
159 |
return FAKE_EFFECT_ID;
|
|
107 | 160 |
} |
108 | 161 |
|
109 | 162 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/effect/TransitionEffectDisappear.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.effect; |
21 | 21 |
|
22 |
import org.distorted.library.effect.Effect; |
|
22 | 23 |
import org.distorted.library.effect.FragmentEffectAlpha; |
23 | 24 |
import org.distorted.library.type.Dynamic1D; |
24 | 25 |
import org.distorted.library.type.Static1D; |
... | ... | |
29 | 30 |
{ |
30 | 31 |
TransitionEffectDisappear() |
31 | 32 |
{ |
32 |
super(-1); |
|
33 |
|
|
34 | 33 |
final int DURATION_IN_MILLIS = 1000; |
35 | 34 |
|
36 |
Dynamic1D disappearDyn = new Dynamic1D(DURATION_IN_MILLIS, 0.5f); |
|
37 |
disappearDyn.add(new Static1D(1.0f)); |
|
38 |
disappearDyn.add(new Static1D(0.0f)); |
|
39 |
mDisappear = new FragmentEffectAlpha(disappearDyn); |
|
35 |
mOldCubeEffectPosition = new int[] {-1}; |
|
36 |
mOldCubeEffects = new Effect[mOldCubeEffectPosition.length]; |
|
37 |
|
|
38 |
Dynamic1D oldCube0 = new Dynamic1D(DURATION_IN_MILLIS, 0.5f); |
|
39 |
oldCube0.add(new Static1D(1.0f)); |
|
40 |
oldCube0.add(new Static1D(0.0f)); |
|
41 |
mOldCubeEffects[0] = new FragmentEffectAlpha(oldCube0); |
|
42 |
|
|
43 |
mNewCubeEffectPosition = new int[] {-1}; |
|
44 |
mNewCubeEffects = new Effect[mNewCubeEffectPosition.length]; |
|
40 | 45 |
|
41 |
Dynamic1D appearDyn = new Dynamic1D(DURATION_IN_MILLIS, 0.5f);
|
|
42 |
appearDyn.add(new Static1D(0.0f));
|
|
43 |
appearDyn.add(new Static1D(1.0f));
|
|
44 |
mAppear = new FragmentEffectAlpha(appearDyn);
|
|
46 |
Dynamic1D newCube0 = new Dynamic1D(DURATION_IN_MILLIS, 0.5f);
|
|
47 |
newCube0.add(new Static1D(0.0f));
|
|
48 |
newCube0.add(new Static1D(1.0f));
|
|
49 |
mNewCubeEffects[0] = new FragmentEffectAlpha(newCube0);
|
|
45 | 50 |
} |
46 | 51 |
|
47 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/effect/TransitionEffectEmpty.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.effect; |
21 | 21 |
|
22 |
import org.distorted.library.effect.Effect; |
|
22 | 23 |
import org.distorted.library.effect.MatrixEffectMove; |
23 | 24 |
import org.distorted.library.type.Dynamic3D; |
24 | 25 |
import org.distorted.library.type.Static3D; |
... | ... | |
29 | 30 |
{ |
30 | 31 |
TransitionEffectEmpty() |
31 | 32 |
{ |
32 |
super(-1); |
|
33 |
|
|
34 | 33 |
final int DURATION_IN_MILLIS = 1; |
35 | 34 |
|
36 |
Dynamic3D disappearDyn = new Dynamic3D(DURATION_IN_MILLIS, 0.5f); |
|
37 |
disappearDyn.add(new Static3D(0,0,0)); |
|
38 |
mDisappear = new MatrixEffectMove(disappearDyn); |
|
35 |
mOldCubeEffectPosition = new int[] {-1}; |
|
36 |
mOldCubeEffects = new Effect[mOldCubeEffectPosition.length]; |
|
37 |
|
|
38 |
Dynamic3D oldCube0 = new Dynamic3D(DURATION_IN_MILLIS, 0.5f); |
|
39 |
oldCube0.add(new Static3D(0,0,0)); |
|
40 |
mOldCubeEffects[0] = new MatrixEffectMove(oldCube0); |
|
41 |
|
|
42 |
mNewCubeEffectPosition = new int[] {-1}; |
|
43 |
mNewCubeEffects = new Effect[mNewCubeEffectPosition.length]; |
|
39 | 44 |
|
40 |
Dynamic3D appearDyn = new Dynamic3D(DURATION_IN_MILLIS, 0.5f);
|
|
41 |
appearDyn.add(new Static3D(0,0,0));
|
|
42 |
mAppear = new MatrixEffectMove(appearDyn);
|
|
45 |
Dynamic3D newCube0 = new Dynamic3D(DURATION_IN_MILLIS, 0.5f);
|
|
46 |
newCube0.add(new Static3D(0,0,0));
|
|
47 |
mNewCubeEffects[0] = new MatrixEffectMove(newCube0);
|
|
43 | 48 |
} |
44 | 49 |
|
45 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/effect/TransitionEffectMove.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.effect; |
21 | 21 |
|
22 |
import org.distorted.library.effect.Effect; |
|
22 | 23 |
import org.distorted.library.effect.MatrixEffectMove; |
23 | 24 |
import org.distorted.library.type.Dynamic3D; |
24 | 25 |
import org.distorted.library.type.Static3D; |
... | ... | |
31 | 32 |
{ |
32 | 33 |
TransitionEffectMove() |
33 | 34 |
{ |
34 |
super(2); |
|
35 |
|
|
36 | 35 |
final int DURATION_IN_MILLIS = 1000; |
37 | 36 |
|
38 |
Dynamic3D disappearDyn = new Dynamic3D(DURATION_IN_MILLIS, 0.5f); |
|
39 |
disappearDyn.add(new Static3D(0,0,0)); |
|
40 |
disappearDyn.add(new Static3D(TEXTURE_SIZE,0,0)); |
|
41 |
mDisappear = new MatrixEffectMove(disappearDyn); |
|
37 |
mOldCubeEffectPosition = new int[] {2}; |
|
38 |
mOldCubeEffects = new Effect[mOldCubeEffectPosition.length]; |
|
39 |
|
|
40 |
Dynamic3D oldCube0 = new Dynamic3D(DURATION_IN_MILLIS, 0.5f); |
|
41 |
oldCube0.add(new Static3D(0,0,0)); |
|
42 |
oldCube0.add(new Static3D(TEXTURE_SIZE,0,0)); |
|
43 |
mOldCubeEffects[0] = new MatrixEffectMove(oldCube0); |
|
44 |
|
|
45 |
mNewCubeEffectPosition = new int[] {2}; |
|
46 |
mNewCubeEffects = new Effect[mNewCubeEffectPosition.length]; |
|
42 | 47 |
|
43 |
Dynamic3D appearDyn = new Dynamic3D(DURATION_IN_MILLIS, 0.5f);
|
|
44 |
appearDyn.add(new Static3D(-TEXTURE_SIZE,0,0));
|
|
45 |
appearDyn.add(new Static3D(0,0,0));
|
|
46 |
mAppear = new MatrixEffectMove(appearDyn);
|
|
48 |
Dynamic3D newCube0 = new Dynamic3D(DURATION_IN_MILLIS, 0.5f);
|
|
49 |
newCube0.add(new Static3D(-TEXTURE_SIZE,0,0));
|
|
50 |
newCube0.add(new Static3D(0,0,0));
|
|
51 |
mNewCubeEffects[0] = new MatrixEffectMove(newCube0);
|
|
47 | 52 |
} |
48 | 53 |
|
49 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
106 | 106 |
break; |
107 | 107 |
} |
108 | 108 |
|
109 |
markButton(size); |
|
110 |
|
|
111 | 109 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
112 |
view.setNewCubeSize(size); |
|
110 |
boolean success = view.setNewCubeSize(size); |
|
111 |
|
|
112 |
if( success ) |
|
113 |
{ |
|
114 |
markButton(size); |
|
115 |
} |
|
113 | 116 |
} |
114 | 117 |
|
115 | 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikCube.java | ||
---|---|---|
24 | 24 |
import android.graphics.Paint; |
25 | 25 |
|
26 | 26 |
import org.distorted.library.effect.Effect; |
27 |
import org.distorted.library.effect.EffectType; |
|
27 | 28 |
import org.distorted.library.effect.MatrixEffectMove; |
28 | 29 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
29 | 30 |
import org.distorted.library.effect.MatrixEffectRotate; |
... | ... | |
181 | 182 |
|
182 | 183 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
183 | 184 |
|
184 |
public void apply(Effect effect) |
|
185 |
public void apply(Effect effect, int position)
|
|
185 | 186 |
{ |
186 | 187 |
for(int x=0; x<mSize; x++) |
187 | 188 |
for(int y=0; y<mSize; y++) |
... | ... | |
189 | 190 |
{ |
190 | 191 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
191 | 192 |
{ |
192 |
mEffects[x][y][z].apply(effect); |
|
193 |
mEffects[x][y][z].apply(effect, position);
|
|
193 | 194 |
} |
194 | 195 |
} |
195 | 196 |
} |
196 | 197 |
|
197 | 198 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
198 | 199 |
|
199 |
public void apply(Effect effect, int position)
|
|
200 |
public void remove(long effectID)
|
|
200 | 201 |
{ |
201 | 202 |
for(int x=0; x<mSize; x++) |
202 | 203 |
for(int y=0; y<mSize; y++) |
... | ... | |
204 | 205 |
{ |
205 | 206 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
206 | 207 |
{ |
207 |
mEffects[x][y][z].apply(effect, position);
|
|
208 |
mEffects[x][y][z].abortById(effectID);
|
|
208 | 209 |
} |
209 | 210 |
} |
210 | 211 |
} |
211 | 212 |
|
212 | 213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
213 | 214 |
|
214 |
public void remove(long effectID)
|
|
215 |
public int getNumEffects(EffectType type)
|
|
215 | 216 |
{ |
216 |
for(int x=0; x<mSize; x++) |
|
217 |
for(int y=0; y<mSize; y++) |
|
218 |
for(int z=0; z<mSize; z++) |
|
219 |
{ |
|
220 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
|
221 |
{ |
|
222 |
mEffects[x][y][z].abortById(effectID); |
|
223 |
} |
|
224 |
} |
|
217 |
return mEffects[0][0][0].getNumEffects(type); |
|
225 | 218 |
} |
226 | 219 |
|
227 | 220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikRenderer.java | ||
---|---|---|
22 | 22 |
import android.opengl.GLSurfaceView; |
23 | 23 |
|
24 | 24 |
import org.distorted.effect.TransitionEffect; |
25 |
import org.distorted.library.effect.EffectType; |
|
25 | 26 |
import org.distorted.library.effect.VertexEffectSink; |
26 | 27 |
import org.distorted.library.main.DistortedEffects; |
27 | 28 |
import org.distorted.library.main.DistortedLibrary; |
... | ... | |
131 | 132 |
|
132 | 133 |
try |
133 | 134 |
{ |
134 |
TransitionEffect effect = TransitionEffect.create(TransitionEffect.Type.EMPTY);
|
|
135 |
TransitionEffect effect = TransitionEffect.create(TransitionEffect.Type.ROUND);
|
|
135 | 136 |
mTransitionEffectID = effect.start(mScreen,mOldCube,mNewCube,this); |
136 | 137 |
} |
137 | 138 |
catch(Exception ex) |
... | ... | |
150 | 151 |
{ |
151 | 152 |
if( effectID == mRotationFinishedID ) |
152 | 153 |
{ |
154 |
//android.util.Log.e("renderer", "rotation finished"); |
|
155 |
|
|
153 | 156 |
mRemoveRotation = true; |
154 | 157 |
} |
155 | 158 |
else if( effectID == mTransitionEffectID ) |
156 | 159 |
{ |
160 |
/* |
|
161 |
int nM = mNewCube.getNumEffects(EffectType.MATRIX); |
|
162 |
int nV = mNewCube.getNumEffects(EffectType.VERTEX); |
|
163 |
int nF = mNewCube.getNumEffects(EffectType.FRAGMENT); |
|
164 |
int nP = mNewCube.getNumEffects(EffectType.POSTPROCESS); |
|
165 |
|
|
166 |
android.util.Log.d("renderer", "transition finished, new cube effects= "+nM+","+nV+","+nF+","+nP); |
|
167 |
|
|
168 |
int oM = mOldCube.getNumEffects(EffectType.MATRIX); |
|
169 |
int oV = mOldCube.getNumEffects(EffectType.VERTEX); |
|
170 |
int oF = mOldCube.getNumEffects(EffectType.FRAGMENT); |
|
171 |
int oP = mOldCube.getNumEffects(EffectType.POSTPROCESS); |
|
172 |
|
|
173 |
android.util.Log.d("renderer", "transition finished, old cube effects= "+oM+","+oV+","+oF+","+oP); |
|
174 |
*/ |
|
157 | 175 |
mCanRotate = true; |
158 | 176 |
mCanDrag = true; |
159 |
mNewCube.remove(mTransitionEffectID); |
|
160 |
mNewCube.deregisterForMessages(this); |
|
161 | 177 |
} |
162 | 178 |
} |
163 | 179 |
|
... | ... | |
218 | 234 |
|
219 | 235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
220 | 236 |
|
221 |
void createCube(int newSize)
|
|
237 |
boolean createCube(int newSize)
|
|
222 | 238 |
{ |
223 |
mNextCubeSize = newSize; |
|
239 |
if( mCanDrag && mCanRotate ) |
|
240 |
{ |
|
241 |
mNextCubeSize = newSize; |
|
242 |
return true; |
|
243 |
} |
|
244 |
|
|
245 |
android.util.Log.e("renderer", "cannot change, drag="+mCanDrag+" rotate="+mCanRotate); |
|
246 |
|
|
247 |
return false; |
|
224 | 248 |
} |
225 | 249 |
|
226 | 250 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikSurfaceView.java | ||
---|---|---|
162 | 162 |
|
163 | 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
164 | 164 |
|
165 |
void setNewCubeSize(int newCubeSize)
|
|
165 |
boolean setNewCubeSize(int newCubeSize)
|
|
166 | 166 |
{ |
167 |
mRenderer.createCube(newCubeSize); |
|
167 |
return mRenderer.createCube(newCubeSize);
|
|
168 | 168 |
} |
169 | 169 |
|
170 | 170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Progress with DistortedCube.