Revision f61fc32c
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/effects/BaseEffect.java | ||
---|---|---|
24 | 24 |
import android.content.SharedPreferences; |
25 | 25 |
|
26 | 26 |
import org.distorted.effects.scramble.ScrambleEffect; |
27 |
import org.distorted.effects.sizechange.SizeChangeEffect;
|
|
27 |
import org.distorted.effects.objectchange.ObjectChangeEffect;
|
|
28 | 28 |
import org.distorted.effects.solve.SolveEffect; |
29 | 29 |
import org.distorted.effects.win.WinEffect; |
30 | 30 |
import org.distorted.library.main.DistortedScreen; |
... | ... | |
37 | 37 |
{ |
38 | 38 |
public enum Type |
39 | 39 |
{ |
40 |
SIZECHANGE ( 20, 1, R.string.sizechange_effect , SizeChangeEffect.class),
|
|
40 |
SIZECHANGE ( 20, 1, R.string.objectchange_effect, ObjectChangeEffect.class),
|
|
41 | 41 |
SOLVE ( 20, 1, R.string.solve_effect , SolveEffect.class ), |
42 | 42 |
SCRAMBLE ( 60, 1, R.string.scramble_effect , ScrambleEffect.class ), |
43 | 43 |
WIN ( 20, 1, R.string.win_effect , WinEffect.class ), |
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffect.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.objectchange; |
|
21 |
|
|
22 |
import org.distorted.effects.BaseEffect; |
|
23 |
import org.distorted.library.effect.Effect; |
|
24 |
import org.distorted.library.main.DistortedEffects; |
|
25 |
import org.distorted.library.main.DistortedScreen; |
|
26 |
import org.distorted.library.message.EffectListener; |
|
27 |
import org.distorted.main.RubikPostRender; |
|
28 |
import org.distorted.objects.RubikObject; |
|
29 |
|
|
30 |
import java.lang.reflect.Method; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
public abstract class ObjectChangeEffect extends BaseEffect implements EffectListener |
|
35 |
{ |
|
36 |
public enum Type |
|
37 |
{ |
|
38 |
NONE (ObjectChangeEffectNone.class ), |
|
39 |
TRANSPARENCY (ObjectChangeEffectTransparency.class), |
|
40 |
MOVE (ObjectChangeEffectMove.class ), |
|
41 |
ROUND (ObjectChangeEffectRound.class ), |
|
42 |
SCALE (ObjectChangeEffectScale.class ), |
|
43 |
; |
|
44 |
|
|
45 |
final Class<? extends ObjectChangeEffect> effect; |
|
46 |
|
|
47 |
Type(Class<? extends ObjectChangeEffect> effect) |
|
48 |
{ |
|
49 |
this.effect= effect; |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
private static int NUM_EFFECTS = Type.values().length; |
|
54 |
private static final int NUM_PHASES = 2; |
|
55 |
private static final int FAKE_EFFECT_ID = -1; |
|
56 |
private static final Type[] types; |
|
57 |
|
|
58 |
static |
|
59 |
{ |
|
60 |
int i=0; |
|
61 |
types = new Type[NUM_EFFECTS]; |
|
62 |
|
|
63 |
for(Type type: Type.values()) |
|
64 |
{ |
|
65 |
types[i++] = type; |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
private EffectListener mListener; |
|
70 |
private int mDuration; |
|
71 |
private int[] mEffectReturned; |
|
72 |
private int[] mCubeEffectNumber, mNodeEffectNumber; |
|
73 |
private int[] mEffectFinished; |
|
74 |
private boolean[] mPhaseActive; |
|
75 |
private RubikObject[] mObject; |
|
76 |
|
|
77 |
DistortedScreen mScreen; |
|
78 |
Effect[][] mCubeEffects; |
|
79 |
int[][] mCubeEffectPosition; |
|
80 |
Effect[][] mNodeEffects; |
|
81 |
int[][] mNodeEffectPosition; |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
ObjectChangeEffect() |
|
86 |
{ |
|
87 |
mPhaseActive = new boolean[NUM_PHASES]; |
|
88 |
mEffectReturned = new int[NUM_PHASES]; |
|
89 |
mCubeEffectNumber = new int[NUM_PHASES]; |
|
90 |
mNodeEffectNumber = new int[NUM_PHASES]; |
|
91 |
mEffectFinished = new int[NUM_PHASES]; |
|
92 |
mCubeEffectPosition = new int[NUM_PHASES][]; |
|
93 |
mNodeEffectPosition = new int[NUM_PHASES][]; |
|
94 |
mCubeEffects = new Effect[NUM_PHASES][]; |
|
95 |
mNodeEffects = new Effect[NUM_PHASES][]; |
|
96 |
mObject = new RubikObject[NUM_PHASES]; |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
abstract int createEffectsPhase0(int duration); |
|
102 |
abstract int createEffectsPhase1(int duration); |
|
103 |
|
|
104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
105 |
|
|
106 |
private void effectFinishedPhase(final long effectID, int phase) |
|
107 |
{ |
|
108 |
for(int i=0; i<mCubeEffectNumber[phase]; i++) |
|
109 |
{ |
|
110 |
long id = mCubeEffects[phase][i].getID(); |
|
111 |
|
|
112 |
if( effectID == id ) |
|
113 |
{ |
|
114 |
effectReturned(phase); |
|
115 |
mObject[phase].remove(id); |
|
116 |
return; |
|
117 |
} |
|
118 |
} |
|
119 |
for(int i=0; i<mNodeEffectNumber[phase]; i++) |
|
120 |
{ |
|
121 |
long id = mNodeEffects[phase][i].getID(); |
|
122 |
|
|
123 |
if( effectID == id ) |
|
124 |
{ |
|
125 |
effectReturned(phase); |
|
126 |
mObject[phase].getEffects().abortById(id); |
|
127 |
return; |
|
128 |
} |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
133 |
|
|
134 |
private void effectReturned(int phase) |
|
135 |
{ |
|
136 |
mEffectReturned[phase]++; |
|
137 |
|
|
138 |
if( mEffectReturned[phase] == mEffectFinished[phase] ) |
|
139 |
{ |
|
140 |
switch(phase) |
|
141 |
{ |
|
142 |
case 0: mPhaseActive[1] = true; |
|
143 |
mEffectFinished[1] = createEffectsPhase1(mDuration); |
|
144 |
assignEffects(1); |
|
145 |
mScreen.attach(mObject[1]); |
|
146 |
break; |
|
147 |
case 1: mListener.effectFinished(FAKE_EFFECT_ID); |
|
148 |
break; |
|
149 |
} |
|
150 |
} |
|
151 |
if( mEffectReturned[phase] == mCubeEffectNumber[phase]+mNodeEffectNumber[phase] ) |
|
152 |
{ |
|
153 |
switch(phase) |
|
154 |
{ |
|
155 |
case 0: mPhaseActive[0] = false; |
|
156 |
mScreen.detach(mObject[0]); |
|
157 |
break; |
|
158 |
case 1: mPhaseActive[1] = false; |
|
159 |
break; |
|
160 |
} |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
165 |
|
|
166 |
private void assignEffects(int phase) |
|
167 |
{ |
|
168 |
mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0; |
|
169 |
mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0; |
|
170 |
|
|
171 |
if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 ) |
|
172 |
{ |
|
173 |
throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!"); |
|
174 |
} |
|
175 |
|
|
176 |
for(int i=0; i<mCubeEffectNumber[phase]; i++) |
|
177 |
{ |
|
178 |
mObject[phase].apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]); |
|
179 |
mCubeEffects[phase][i].notifyWhenFinished(this); |
|
180 |
} |
|
181 |
|
|
182 |
DistortedEffects nodeEffects = mObject[phase].getEffects(); |
|
183 |
|
|
184 |
for(int i=0; i<mNodeEffectNumber[phase]; i++) |
|
185 |
{ |
|
186 |
nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]); |
|
187 |
mNodeEffects[phase][i].notifyWhenFinished(this); |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
192 |
// PUBLIC API |
|
193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
194 |
|
|
195 |
public void effectFinished(final long effectID) |
|
196 |
{ |
|
197 |
if( mPhaseActive[0] ) effectFinishedPhase(effectID,0); |
|
198 |
if( mPhaseActive[1] ) effectFinishedPhase(effectID,1); |
|
199 |
} |
|
200 |
|
|
201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
202 |
|
|
203 |
@SuppressWarnings("unused") |
|
204 |
public static String[] getNames() |
|
205 |
{ |
|
206 |
String[] names = new String[NUM_EFFECTS]; |
|
207 |
|
|
208 |
for( int i=0; i<NUM_EFFECTS; i++) |
|
209 |
{ |
|
210 |
names[i] = types[i].name(); |
|
211 |
} |
|
212 |
|
|
213 |
return names; |
|
214 |
} |
|
215 |
|
|
216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
217 |
|
|
218 |
@SuppressWarnings("unused") |
|
219 |
public static ObjectChangeEffect create(int ordinal) throws InstantiationException, IllegalAccessException |
|
220 |
{ |
|
221 |
return types[ordinal].effect.newInstance(); |
|
222 |
} |
|
223 |
|
|
224 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
225 |
|
|
226 |
@SuppressWarnings("unused") |
|
227 |
public long start(int duration, DistortedScreen screen, RubikPostRender post) |
|
228 |
{ |
|
229 |
mScreen = screen; |
|
230 |
mObject[0]= post.getOldObject(); |
|
231 |
mObject[1]= post.getObject(); |
|
232 |
mListener = post; |
|
233 |
mDuration = duration; |
|
234 |
|
|
235 |
if( mObject[0]!=null ) |
|
236 |
{ |
|
237 |
mPhaseActive[0] = true; |
|
238 |
mEffectFinished[0] = createEffectsPhase0(mDuration); |
|
239 |
assignEffects(0); |
|
240 |
} |
|
241 |
else |
|
242 |
{ |
|
243 |
mPhaseActive[1] = true; |
|
244 |
mEffectFinished[1] = createEffectsPhase1(mDuration); |
|
245 |
assignEffects(1); |
|
246 |
mScreen.attach(mObject[1]); |
|
247 |
} |
|
248 |
|
|
249 |
return FAKE_EFFECT_ID; |
|
250 |
} |
|
251 |
|
|
252 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
253 |
|
|
254 |
@SuppressWarnings("unused") |
|
255 |
public static void enableEffects() |
|
256 |
{ |
|
257 |
Method method; |
|
258 |
|
|
259 |
for(Type type: Type.values()) |
|
260 |
{ |
|
261 |
try |
|
262 |
{ |
|
263 |
method = type.effect.getDeclaredMethod("enable"); // enable not public, thus getDeclaredMethod |
|
264 |
} |
|
265 |
catch(NoSuchMethodException ex) |
|
266 |
{ |
|
267 |
android.util.Log.e("SizeChangeEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage()); |
|
268 |
method = null; |
|
269 |
} |
|
270 |
|
|
271 |
try |
|
272 |
{ |
|
273 |
if( method!=null ) method.invoke(null); |
|
274 |
} |
|
275 |
catch(Exception ex) |
|
276 |
{ |
|
277 |
android.util.Log.e("SizeChangeEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage()); |
|
278 |
} |
|
279 |
} |
|
280 |
} |
|
281 |
} |
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffectMove.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.objectchange; |
|
21 |
|
|
22 |
import org.distorted.library.effect.Effect; |
|
23 |
import org.distorted.library.effect.MatrixEffectMove; |
|
24 |
import org.distorted.library.type.Dynamic3D; |
|
25 |
import org.distorted.library.type.Static3D; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
class ObjectChangeEffectMove extends ObjectChangeEffect |
|
30 |
{ |
|
31 |
public int createEffectsPhase0(int duration) |
|
32 |
{ |
|
33 |
int w = mScreen.getWidth(); |
|
34 |
int h = mScreen.getHeight(); |
|
35 |
int xmove = w/2 + (w<h?w:h)/2; |
|
36 |
|
|
37 |
mNodeEffectPosition[0] = new int[] {1}; |
|
38 |
mNodeEffects[0] = new Effect[mNodeEffectPosition[0].length]; |
|
39 |
|
|
40 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
41 |
d0.add(new Static3D( 0,0,0)); |
|
42 |
d0.add(new Static3D(xmove,0,0)); |
|
43 |
mNodeEffects[0][0] = new MatrixEffectMove(d0); |
|
44 |
|
|
45 |
return 1; |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
|
|
50 |
public int createEffectsPhase1(int duration) |
|
51 |
{ |
|
52 |
int w = mScreen.getWidth(); |
|
53 |
int h = mScreen.getHeight(); |
|
54 |
int xmove = w/2 + (w<h?w:h)/2; |
|
55 |
|
|
56 |
mNodeEffectPosition[1] = new int[] {1}; |
|
57 |
mNodeEffects[1] = new Effect[mNodeEffectPosition[1].length]; |
|
58 |
|
|
59 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
60 |
d0.add(new Static3D(-xmove,0,0)); |
|
61 |
d0.add(new Static3D( 0,0,0)); |
|
62 |
mNodeEffects[1][0] = new MatrixEffectMove(d0); |
|
63 |
|
|
64 |
return 1; |
|
65 |
} |
|
66 |
|
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
69 |
// Matrix Effects do not have to be enabled. |
|
70 |
|
|
71 |
@SuppressWarnings("unused") |
|
72 |
static void enable() |
|
73 |
{ |
|
74 |
|
|
75 |
} |
|
76 |
} |
|
77 |
|
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffectNone.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.objectchange; |
|
21 |
|
|
22 |
import org.distorted.library.effect.Effect; |
|
23 |
import org.distorted.library.effect.MatrixEffectMove; |
|
24 |
import org.distorted.library.type.Dynamic3D; |
|
25 |
import org.distorted.library.type.Static3D; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
class ObjectChangeEffectNone extends ObjectChangeEffect |
|
30 |
{ |
|
31 |
public int createEffectsPhase0(int duration) |
|
32 |
{ |
|
33 |
mCubeEffectPosition[0] = new int[] {-1}; |
|
34 |
mCubeEffects[0] = new Effect[mCubeEffectPosition[0].length]; |
|
35 |
|
|
36 |
Dynamic3D d0 = new Dynamic3D(1,0.5f); |
|
37 |
d0.add(new Static3D(0,0,0)); |
|
38 |
mCubeEffects[0][0] = new MatrixEffectMove(d0); |
|
39 |
|
|
40 |
return 1; |
|
41 |
} |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
|
|
45 |
public int createEffectsPhase1(int duration) |
|
46 |
{ |
|
47 |
mCubeEffectPosition[1] = new int[] {-1}; |
|
48 |
mCubeEffects[1] = new Effect[mCubeEffectPosition[1].length]; |
|
49 |
|
|
50 |
Dynamic3D d0 = new Dynamic3D(1,0.5f); |
|
51 |
d0.add(new Static3D(0,0,0)); |
|
52 |
mCubeEffects[1][0] = new MatrixEffectMove(d0); |
|
53 |
|
|
54 |
return 1; |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
// enable all effects used in this Effect (here: none). Called by reflection from the parent class. |
|
59 |
|
|
60 |
@SuppressWarnings("unused") |
|
61 |
static void enable() |
|
62 |
{ |
|
63 |
|
|
64 |
} |
|
65 |
} |
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffectRound.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.objectchange; |
|
21 |
|
|
22 |
import org.distorted.library.effect.Effect; |
|
23 |
import org.distorted.library.effect.MatrixEffectMove; |
|
24 |
import org.distorted.library.effect.MatrixEffectScale; |
|
25 |
import org.distorted.library.type.Dynamic; |
|
26 |
import org.distorted.library.type.Dynamic3D; |
|
27 |
import org.distorted.library.type.Static3D; |
|
28 |
|
|
29 |
import static org.distorted.objects.RubikObject.NODE_FBO_SIZE; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
class ObjectChangeEffectRound extends ObjectChangeEffect |
|
34 |
{ |
|
35 |
public int createEffectsPhase0(int duration) |
|
36 |
{ |
|
37 |
float X = NODE_FBO_SIZE /3; |
|
38 |
|
|
39 |
mCubeEffectPosition[0] = new int[] {6,7}; |
|
40 |
mCubeEffects[0] = new Effect[mCubeEffectPosition[0].length]; |
|
41 |
|
|
42 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
43 |
d0.add(new Static3D( 1.00f, 1.00f, 1.00f)); |
|
44 |
d0.add(new Static3D( 0.01f, 0.01f, 0.01f)); |
|
45 |
mCubeEffects[0][0] = new MatrixEffectScale(d0); |
|
46 |
|
|
47 |
Dynamic3D d1 = new Dynamic3D(duration/2, 0.5f); |
|
48 |
d1.setMode(Dynamic.MODE_PATH); |
|
49 |
d1.add(new Static3D( 0, 0, 0)); |
|
50 |
d1.add(new Static3D(+X, 0, 0)); |
|
51 |
d1.add(new Static3D( 0, 0, 0)); |
|
52 |
mCubeEffects[0][1] = new MatrixEffectMove(d1); |
|
53 |
|
|
54 |
return 2; |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
public int createEffectsPhase1(int duration) |
|
60 |
{ |
|
61 |
float X = NODE_FBO_SIZE /3; |
|
62 |
|
|
63 |
mCubeEffectPosition[1] = new int[] {6,7}; |
|
64 |
mCubeEffects[1] = new Effect[mCubeEffectPosition[1].length]; |
|
65 |
|
|
66 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
67 |
d0.add(new Static3D( 0.01f, 0.01f, 0.01f)); |
|
68 |
d0.add(new Static3D( 1.00f, 1.00f, 1.00f)); |
|
69 |
mCubeEffects[1][0] = new MatrixEffectScale(d0); |
|
70 |
|
|
71 |
Dynamic3D d1 = new Dynamic3D(duration/2, 0.5f); |
|
72 |
d1.setMode(Dynamic.MODE_PATH); |
|
73 |
d1.add(new Static3D( 0, 0, 0)); |
|
74 |
d1.add(new Static3D(-X, 0, 0)); |
|
75 |
d1.add(new Static3D( 0, 0, 0)); |
|
76 |
mCubeEffects[1][1] = new MatrixEffectMove(d1); |
|
77 |
|
|
78 |
return 2; |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
83 |
// Matrix Effects do not have to be enabled. |
|
84 |
|
|
85 |
@SuppressWarnings("unused") |
|
86 |
static void enable() |
|
87 |
{ |
|
88 |
|
|
89 |
} |
|
90 |
} |
|
91 |
|
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffectScale.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.objectchange; |
|
21 |
|
|
22 |
import org.distorted.library.effect.Effect; |
|
23 |
import org.distorted.library.effect.MatrixEffectScale; |
|
24 |
import org.distorted.library.type.Dynamic3D; |
|
25 |
import org.distorted.library.type.Static3D; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
class ObjectChangeEffectScale extends ObjectChangeEffect |
|
30 |
{ |
|
31 |
public int createEffectsPhase0(int duration) |
|
32 |
{ |
|
33 |
mCubeEffectPosition[0] = new int[] {6}; |
|
34 |
mCubeEffects[0] = new Effect[mCubeEffectPosition[0].length]; |
|
35 |
|
|
36 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
37 |
d0.add(new Static3D(1.00f, 1.00f, 1.00f)); |
|
38 |
d0.add(new Static3D(0.01f, 0.01f, 0.01f)); |
|
39 |
mCubeEffects[0][0] = new MatrixEffectScale(d0); |
|
40 |
|
|
41 |
return 1; |
|
42 |
} |
|
43 |
|
|
44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
45 |
|
|
46 |
public int createEffectsPhase1(int duration) |
|
47 |
{ |
|
48 |
mCubeEffectPosition[1] = new int[] {6}; |
|
49 |
mCubeEffects[1] = new Effect[mCubeEffectPosition[1].length]; |
|
50 |
|
|
51 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
52 |
d0.add(new Static3D(0.01f, 0.01f, 0.01f)); |
|
53 |
d0.add(new Static3D(1.00f, 1.00f, 1.00f)); |
|
54 |
mCubeEffects[1][0] = new MatrixEffectScale(d0); |
|
55 |
|
|
56 |
return 1; |
|
57 |
} |
|
58 |
|
|
59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
61 |
// Matrix Effects do not have to be enabled. |
|
62 |
|
|
63 |
@SuppressWarnings("unused") |
|
64 |
static void enable() |
|
65 |
{ |
|
66 |
|
|
67 |
} |
|
68 |
} |
|
69 |
|
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffectTransparency.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.objectchange; |
|
21 |
|
|
22 |
import org.distorted.library.effect.Effect; |
|
23 |
import org.distorted.library.effect.FragmentEffectAlpha; |
|
24 |
import org.distorted.library.effect.VertexEffectWave; |
|
25 |
import org.distorted.library.type.Dynamic1D; |
|
26 |
import org.distorted.library.type.Dynamic5D; |
|
27 |
import org.distorted.library.type.Static1D; |
|
28 |
import org.distorted.library.type.Static3D; |
|
29 |
import org.distorted.library.type.Static5D; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
class ObjectChangeEffectTransparency extends ObjectChangeEffect |
|
34 |
{ |
|
35 |
public int createEffectsPhase0(int duration) |
|
36 |
{ |
|
37 |
mNodeEffectPosition[0] = new int[] {-1,-1}; |
|
38 |
mNodeEffects[0] = new Effect[mNodeEffectPosition[0].length]; |
|
39 |
|
|
40 |
float init_amplitude = 0.0f; |
|
41 |
float end_amplitude = 1/8.0f; |
|
42 |
float length = 1/8.0f; |
|
43 |
float init_phase = 360.0f; |
|
44 |
float end_phase = 0.0f; |
|
45 |
float alpha = 30.0f; |
|
46 |
float beta = 90.0f; |
|
47 |
|
|
48 |
Dynamic5D d1 = new Dynamic5D(duration/2, 0.5f); |
|
49 |
d1.add(new Static5D( init_amplitude, length, init_phase, alpha, beta) ); |
|
50 |
d1.add(new Static5D( end_amplitude , length, end_phase , alpha, beta) ); |
|
51 |
Static3D center = new Static3D(0,0,0); |
|
52 |
mNodeEffects[0][0] = new VertexEffectWave(d1, center, null); |
|
53 |
|
|
54 |
Dynamic1D d0 = new Dynamic1D(duration/2, 0.5f); |
|
55 |
d0.add(new Static1D(1.0f)); |
|
56 |
d0.add(new Static1D(0.0f)); |
|
57 |
mNodeEffects[0][1] = new FragmentEffectAlpha(d0); |
|
58 |
|
|
59 |
return 2; |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
public int createEffectsPhase1(int duration) |
|
65 |
{ |
|
66 |
mNodeEffectPosition[1] = new int[] {-1,-1}; |
|
67 |
mNodeEffects[1] = new Effect[mNodeEffectPosition[1].length]; |
|
68 |
|
|
69 |
float init_amplitude = 1/8.0f; |
|
70 |
float end_amplitude = 0.0f; |
|
71 |
float length = 1/8.0f; |
|
72 |
float init_phase = 0.0f; |
|
73 |
float end_phase = 360.0f; |
|
74 |
float alpha = 30.0f; |
|
75 |
float beta = 90.0f; |
|
76 |
|
|
77 |
Dynamic5D d1 = new Dynamic5D(duration/2, 0.5f); |
|
78 |
d1.add(new Static5D( init_amplitude, length, init_phase, alpha, beta) ); |
|
79 |
d1.add(new Static5D( end_amplitude , length, end_phase , alpha, beta) ); |
|
80 |
Static3D center = new Static3D(0,0,0); |
|
81 |
mNodeEffects[1][0] = new VertexEffectWave(d1, center, null); |
|
82 |
|
|
83 |
Dynamic1D d0 = new Dynamic1D(duration/2, 0.5f); |
|
84 |
d0.add(new Static1D(0.0f)); |
|
85 |
d0.add(new Static1D(1.0f)); |
|
86 |
mNodeEffects[1][1] = new FragmentEffectAlpha(d0); |
|
87 |
|
|
88 |
return 2; |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
93 |
|
|
94 |
@SuppressWarnings("unused") |
|
95 |
static void enable() |
|
96 |
{ |
|
97 |
FragmentEffectAlpha.enable(); |
|
98 |
VertexEffectWave.enable(); |
|
99 |
} |
|
100 |
} |
src/main/java/org/distorted/effects/sizechange/SizeChangeEffect.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.sizechange; |
|
21 |
|
|
22 |
import org.distorted.effects.BaseEffect; |
|
23 |
import org.distorted.library.effect.Effect; |
|
24 |
import org.distorted.library.main.DistortedEffects; |
|
25 |
import org.distorted.library.main.DistortedScreen; |
|
26 |
import org.distorted.library.message.EffectListener; |
|
27 |
import org.distorted.main.RubikPostRender; |
|
28 |
import org.distorted.objects.RubikObject; |
|
29 |
|
|
30 |
import java.lang.reflect.Method; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
public abstract class SizeChangeEffect extends BaseEffect implements EffectListener |
|
35 |
{ |
|
36 |
public enum Type |
|
37 |
{ |
|
38 |
NONE (SizeChangeEffectNone.class ), |
|
39 |
TRANSPARENCY (SizeChangeEffectTransparency.class), |
|
40 |
MOVE (SizeChangeEffectMove.class ), |
|
41 |
ROUND (SizeChangeEffectRound.class ), |
|
42 |
SCALE (SizeChangeEffectScale.class ), |
|
43 |
; |
|
44 |
|
|
45 |
final Class<? extends SizeChangeEffect> effect; |
|
46 |
|
|
47 |
Type(Class<? extends SizeChangeEffect> effect) |
|
48 |
{ |
|
49 |
this.effect= effect; |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
private static int NUM_EFFECTS = Type.values().length; |
|
54 |
private static final int NUM_PHASES = 2; |
|
55 |
private static final int FAKE_EFFECT_ID = -1; |
|
56 |
private static final Type[] types; |
|
57 |
|
|
58 |
static |
|
59 |
{ |
|
60 |
int i=0; |
|
61 |
types = new Type[NUM_EFFECTS]; |
|
62 |
|
|
63 |
for(Type type: Type.values()) |
|
64 |
{ |
|
65 |
types[i++] = type; |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
private EffectListener mListener; |
|
70 |
private int mDuration; |
|
71 |
private int[] mEffectReturned; |
|
72 |
private int[] mCubeEffectNumber, mNodeEffectNumber; |
|
73 |
private int[] mEffectFinished; |
|
74 |
private boolean[] mPhaseActive; |
|
75 |
private RubikObject[] mObject; |
|
76 |
|
|
77 |
DistortedScreen mScreen; |
|
78 |
Effect[][] mCubeEffects; |
|
79 |
int[][] mCubeEffectPosition; |
|
80 |
Effect[][] mNodeEffects; |
|
81 |
int[][] mNodeEffectPosition; |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
SizeChangeEffect() |
|
86 |
{ |
|
87 |
mPhaseActive = new boolean[NUM_PHASES]; |
|
88 |
mEffectReturned = new int[NUM_PHASES]; |
|
89 |
mCubeEffectNumber = new int[NUM_PHASES]; |
|
90 |
mNodeEffectNumber = new int[NUM_PHASES]; |
|
91 |
mEffectFinished = new int[NUM_PHASES]; |
|
92 |
mCubeEffectPosition = new int[NUM_PHASES][]; |
|
93 |
mNodeEffectPosition = new int[NUM_PHASES][]; |
|
94 |
mCubeEffects = new Effect[NUM_PHASES][]; |
|
95 |
mNodeEffects = new Effect[NUM_PHASES][]; |
|
96 |
mObject = new RubikObject[NUM_PHASES]; |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
abstract int createEffectsPhase0(int duration); |
|
102 |
abstract int createEffectsPhase1(int duration); |
|
103 |
|
|
104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
105 |
|
|
106 |
private void effectFinishedPhase(final long effectID, int phase) |
|
107 |
{ |
|
108 |
for(int i=0; i<mCubeEffectNumber[phase]; i++) |
|
109 |
{ |
|
110 |
long id = mCubeEffects[phase][i].getID(); |
|
111 |
|
|
112 |
if( effectID == id ) |
|
113 |
{ |
|
114 |
effectReturned(phase); |
|
115 |
mObject[phase].remove(id); |
|
116 |
return; |
|
117 |
} |
|
118 |
} |
|
119 |
for(int i=0; i<mNodeEffectNumber[phase]; i++) |
|
120 |
{ |
|
121 |
long id = mNodeEffects[phase][i].getID(); |
|
122 |
|
|
123 |
if( effectID == id ) |
|
124 |
{ |
|
125 |
effectReturned(phase); |
|
126 |
mObject[phase].getEffects().abortById(id); |
|
127 |
return; |
|
128 |
} |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
133 |
|
|
134 |
private void effectReturned(int phase) |
|
135 |
{ |
|
136 |
mEffectReturned[phase]++; |
|
137 |
|
|
138 |
if( mEffectReturned[phase] == mEffectFinished[phase] ) |
|
139 |
{ |
|
140 |
switch(phase) |
|
141 |
{ |
|
142 |
case 0: mPhaseActive[1] = true; |
|
143 |
mEffectFinished[1] = createEffectsPhase1(mDuration); |
|
144 |
assignEffects(1); |
|
145 |
mScreen.attach(mObject[1]); |
|
146 |
break; |
|
147 |
case 1: mListener.effectFinished(FAKE_EFFECT_ID); |
|
148 |
break; |
|
149 |
} |
|
150 |
} |
|
151 |
if( mEffectReturned[phase] == mCubeEffectNumber[phase]+mNodeEffectNumber[phase] ) |
|
152 |
{ |
|
153 |
switch(phase) |
|
154 |
{ |
|
155 |
case 0: mPhaseActive[0] = false; |
|
156 |
mScreen.detach(mObject[0]); |
|
157 |
break; |
|
158 |
case 1: mPhaseActive[1] = false; |
|
159 |
break; |
|
160 |
} |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
165 |
|
|
166 |
private void assignEffects(int phase) |
|
167 |
{ |
|
168 |
mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0; |
|
169 |
mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0; |
|
170 |
|
|
171 |
if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 ) |
|
172 |
{ |
|
173 |
throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!"); |
|
174 |
} |
|
175 |
|
|
176 |
for(int i=0; i<mCubeEffectNumber[phase]; i++) |
|
177 |
{ |
|
178 |
mObject[phase].apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]); |
|
179 |
mCubeEffects[phase][i].notifyWhenFinished(this); |
|
180 |
} |
|
181 |
|
|
182 |
DistortedEffects nodeEffects = mObject[phase].getEffects(); |
|
183 |
|
|
184 |
for(int i=0; i<mNodeEffectNumber[phase]; i++) |
|
185 |
{ |
|
186 |
nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]); |
|
187 |
mNodeEffects[phase][i].notifyWhenFinished(this); |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
192 |
// PUBLIC API |
|
193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
194 |
|
|
195 |
public void effectFinished(final long effectID) |
|
196 |
{ |
|
197 |
if( mPhaseActive[0] ) effectFinishedPhase(effectID,0); |
|
198 |
if( mPhaseActive[1] ) effectFinishedPhase(effectID,1); |
|
199 |
} |
|
200 |
|
|
201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
202 |
|
|
203 |
@SuppressWarnings("unused") |
|
204 |
public static String[] getNames() |
|
205 |
{ |
|
206 |
String[] names = new String[NUM_EFFECTS]; |
|
207 |
|
|
208 |
for( int i=0; i<NUM_EFFECTS; i++) |
|
209 |
{ |
|
210 |
names[i] = types[i].name(); |
|
211 |
} |
|
212 |
|
|
213 |
return names; |
|
214 |
} |
|
215 |
|
|
216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
217 |
|
|
218 |
@SuppressWarnings("unused") |
|
219 |
public static SizeChangeEffect create(int ordinal) throws InstantiationException, IllegalAccessException |
|
220 |
{ |
|
221 |
return types[ordinal].effect.newInstance(); |
|
222 |
} |
|
223 |
|
|
224 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
225 |
|
|
226 |
@SuppressWarnings("unused") |
|
227 |
public long start(int duration, DistortedScreen screen, RubikPostRender post) |
|
228 |
{ |
|
229 |
mScreen = screen; |
|
230 |
mObject[0]= post.getOldObject(); |
|
231 |
mObject[1]= post.getObject(); |
|
232 |
mListener = post; |
|
233 |
mDuration = duration; |
|
234 |
|
|
235 |
if( mObject[0]!=null ) |
|
236 |
{ |
|
237 |
mPhaseActive[0] = true; |
|
238 |
mEffectFinished[0] = createEffectsPhase0(mDuration); |
|
239 |
assignEffects(0); |
|
240 |
} |
|
241 |
else |
|
242 |
{ |
|
243 |
mPhaseActive[1] = true; |
|
244 |
mEffectFinished[1] = createEffectsPhase1(mDuration); |
|
245 |
assignEffects(1); |
|
246 |
mScreen.attach(mObject[1]); |
|
247 |
} |
|
248 |
|
|
249 |
return FAKE_EFFECT_ID; |
|
250 |
} |
|
251 |
|
|
252 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
253 |
|
|
254 |
@SuppressWarnings("unused") |
|
255 |
public static void enableEffects() |
|
256 |
{ |
|
257 |
Method method; |
|
258 |
|
|
259 |
for(Type type: Type.values()) |
|
260 |
{ |
|
261 |
try |
|
262 |
{ |
|
263 |
method = type.effect.getDeclaredMethod("enable"); // enable not public, thus getDeclaredMethod |
|
264 |
} |
|
265 |
catch(NoSuchMethodException ex) |
|
266 |
{ |
|
267 |
android.util.Log.e("SizeChangeEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage()); |
|
268 |
method = null; |
|
269 |
} |
|
270 |
|
|
271 |
try |
|
272 |
{ |
|
273 |
if( method!=null ) method.invoke(null); |
|
274 |
} |
|
275 |
catch(Exception ex) |
|
276 |
{ |
|
277 |
android.util.Log.e("SizeChangeEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage()); |
|
278 |
} |
|
279 |
} |
|
280 |
} |
|
281 |
} |
src/main/java/org/distorted/effects/sizechange/SizeChangeEffectMove.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.sizechange; |
|
21 |
|
|
22 |
import org.distorted.library.effect.Effect; |
|
23 |
import org.distorted.library.effect.MatrixEffectMove; |
|
24 |
import org.distorted.library.type.Dynamic3D; |
|
25 |
import org.distorted.library.type.Static3D; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
class SizeChangeEffectMove extends SizeChangeEffect |
|
30 |
{ |
|
31 |
public int createEffectsPhase0(int duration) |
|
32 |
{ |
|
33 |
int w = mScreen.getWidth(); |
|
34 |
int h = mScreen.getHeight(); |
|
35 |
int xmove = w/2 + (w<h?w:h)/2; |
|
36 |
|
|
37 |
mNodeEffectPosition[0] = new int[] {1}; |
|
38 |
mNodeEffects[0] = new Effect[mNodeEffectPosition[0].length]; |
|
39 |
|
|
40 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
41 |
d0.add(new Static3D( 0,0,0)); |
|
42 |
d0.add(new Static3D(xmove,0,0)); |
|
43 |
mNodeEffects[0][0] = new MatrixEffectMove(d0); |
|
44 |
|
|
45 |
return 1; |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
|
|
50 |
public int createEffectsPhase1(int duration) |
|
51 |
{ |
|
52 |
int w = mScreen.getWidth(); |
|
53 |
int h = mScreen.getHeight(); |
|
54 |
int xmove = w/2 + (w<h?w:h)/2; |
|
55 |
|
|
56 |
mNodeEffectPosition[1] = new int[] {1}; |
|
57 |
mNodeEffects[1] = new Effect[mNodeEffectPosition[1].length]; |
|
58 |
|
|
59 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
60 |
d0.add(new Static3D(-xmove,0,0)); |
|
61 |
d0.add(new Static3D( 0,0,0)); |
|
62 |
mNodeEffects[1][0] = new MatrixEffectMove(d0); |
|
63 |
|
|
64 |
return 1; |
|
65 |
} |
|
66 |
|
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
69 |
// Matrix Effects do not have to be enabled. |
|
70 |
|
|
71 |
@SuppressWarnings("unused") |
|
72 |
static void enable() |
|
73 |
{ |
|
74 |
|
|
75 |
} |
|
76 |
} |
|
77 |
|
src/main/java/org/distorted/effects/sizechange/SizeChangeEffectNone.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.sizechange; |
|
21 |
|
|
22 |
import org.distorted.library.effect.Effect; |
|
23 |
import org.distorted.library.effect.MatrixEffectMove; |
|
24 |
import org.distorted.library.type.Dynamic3D; |
|
25 |
import org.distorted.library.type.Static3D; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
class SizeChangeEffectNone extends SizeChangeEffect |
|
30 |
{ |
|
31 |
public int createEffectsPhase0(int duration) |
|
32 |
{ |
|
33 |
mCubeEffectPosition[0] = new int[] {-1}; |
|
34 |
mCubeEffects[0] = new Effect[mCubeEffectPosition[0].length]; |
|
35 |
|
|
36 |
Dynamic3D d0 = new Dynamic3D(1,0.5f); |
|
37 |
d0.add(new Static3D(0,0,0)); |
|
38 |
mCubeEffects[0][0] = new MatrixEffectMove(d0); |
|
39 |
|
|
40 |
return 1; |
|
41 |
} |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
|
|
45 |
public int createEffectsPhase1(int duration) |
|
46 |
{ |
|
47 |
mCubeEffectPosition[1] = new int[] {-1}; |
|
48 |
mCubeEffects[1] = new Effect[mCubeEffectPosition[1].length]; |
|
49 |
|
|
50 |
Dynamic3D d0 = new Dynamic3D(1,0.5f); |
|
51 |
d0.add(new Static3D(0,0,0)); |
|
52 |
mCubeEffects[1][0] = new MatrixEffectMove(d0); |
|
53 |
|
|
54 |
return 1; |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
// enable all effects used in this Effect (here: none). Called by reflection from the parent class. |
|
59 |
|
|
60 |
@SuppressWarnings("unused") |
|
61 |
static void enable() |
|
62 |
{ |
|
63 |
|
|
64 |
} |
|
65 |
} |
src/main/java/org/distorted/effects/sizechange/SizeChangeEffectRound.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.sizechange; |
|
21 |
|
|
22 |
import org.distorted.library.effect.Effect; |
|
23 |
import org.distorted.library.effect.MatrixEffectMove; |
|
24 |
import org.distorted.library.effect.MatrixEffectScale; |
|
25 |
import org.distorted.library.type.Dynamic; |
|
26 |
import org.distorted.library.type.Dynamic3D; |
|
27 |
import org.distorted.library.type.Static3D; |
|
28 |
|
|
29 |
import static org.distorted.objects.RubikObject.NODE_FBO_SIZE; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
class SizeChangeEffectRound extends SizeChangeEffect |
|
34 |
{ |
|
35 |
public int createEffectsPhase0(int duration) |
|
36 |
{ |
|
37 |
float X = NODE_FBO_SIZE /3; |
|
38 |
|
|
39 |
mCubeEffectPosition[0] = new int[] {6,7}; |
|
40 |
mCubeEffects[0] = new Effect[mCubeEffectPosition[0].length]; |
|
41 |
|
|
42 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
43 |
d0.add(new Static3D( 1.00f, 1.00f, 1.00f)); |
|
44 |
d0.add(new Static3D( 0.01f, 0.01f, 0.01f)); |
|
45 |
mCubeEffects[0][0] = new MatrixEffectScale(d0); |
|
46 |
|
|
47 |
Dynamic3D d1 = new Dynamic3D(duration/2, 0.5f); |
|
48 |
d1.setMode(Dynamic.MODE_PATH); |
|
49 |
d1.add(new Static3D( 0, 0, 0)); |
|
50 |
d1.add(new Static3D(+X, 0, 0)); |
|
51 |
d1.add(new Static3D( 0, 0, 0)); |
|
52 |
mCubeEffects[0][1] = new MatrixEffectMove(d1); |
|
53 |
|
|
54 |
return 2; |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
public int createEffectsPhase1(int duration) |
|
60 |
{ |
|
61 |
float X = NODE_FBO_SIZE /3; |
|
62 |
|
|
63 |
mCubeEffectPosition[1] = new int[] {6,7}; |
|
64 |
mCubeEffects[1] = new Effect[mCubeEffectPosition[1].length]; |
|
65 |
|
|
66 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
67 |
d0.add(new Static3D( 0.01f, 0.01f, 0.01f)); |
|
68 |
d0.add(new Static3D( 1.00f, 1.00f, 1.00f)); |
|
69 |
mCubeEffects[1][0] = new MatrixEffectScale(d0); |
|
70 |
|
|
71 |
Dynamic3D d1 = new Dynamic3D(duration/2, 0.5f); |
|
72 |
d1.setMode(Dynamic.MODE_PATH); |
|
73 |
d1.add(new Static3D( 0, 0, 0)); |
|
74 |
d1.add(new Static3D(-X, 0, 0)); |
|
75 |
d1.add(new Static3D( 0, 0, 0)); |
|
76 |
mCubeEffects[1][1] = new MatrixEffectMove(d1); |
|
77 |
|
|
78 |
return 2; |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
83 |
// Matrix Effects do not have to be enabled. |
|
84 |
|
|
85 |
@SuppressWarnings("unused") |
|
86 |
static void enable() |
|
87 |
{ |
|
88 |
|
|
89 |
} |
|
90 |
} |
|
91 |
|
src/main/java/org/distorted/effects/sizechange/SizeChangeEffectScale.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.sizechange; |
|
21 |
|
|
22 |
import org.distorted.library.effect.Effect; |
|
23 |
import org.distorted.library.effect.MatrixEffectScale; |
|
24 |
import org.distorted.library.type.Dynamic3D; |
|
25 |
import org.distorted.library.type.Static3D; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
class SizeChangeEffectScale extends SizeChangeEffect |
|
30 |
{ |
|
31 |
public int createEffectsPhase0(int duration) |
|
32 |
{ |
|
33 |
mCubeEffectPosition[0] = new int[] {6}; |
|
34 |
mCubeEffects[0] = new Effect[mCubeEffectPosition[0].length]; |
|
35 |
|
|
36 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
37 |
d0.add(new Static3D(1.00f, 1.00f, 1.00f)); |
|
38 |
d0.add(new Static3D(0.01f, 0.01f, 0.01f)); |
|
39 |
mCubeEffects[0][0] = new MatrixEffectScale(d0); |
|
40 |
|
|
41 |
return 1; |
|
42 |
} |
|
43 |
|
|
44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
45 |
|
|
46 |
public int createEffectsPhase1(int duration) |
|
47 |
{ |
|
48 |
mCubeEffectPosition[1] = new int[] {6}; |
|
49 |
mCubeEffects[1] = new Effect[mCubeEffectPosition[1].length]; |
|
50 |
|
|
51 |
Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f); |
|
52 |
d0.add(new Static3D(0.01f, 0.01f, 0.01f)); |
|
53 |
d0.add(new Static3D(1.00f, 1.00f, 1.00f)); |
|
54 |
mCubeEffects[1][0] = new MatrixEffectScale(d0); |
|
55 |
|
|
56 |
return 1; |
|
57 |
} |
|
58 |
|
|
59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
61 |
// Matrix Effects do not have to be enabled. |
|
62 |
|
|
63 |
@SuppressWarnings("unused") |
|
64 |
static void enable() |
|
65 |
{ |
|
66 |
|
|
67 |
} |
|
68 |
} |
|
69 |
|
src/main/java/org/distorted/effects/sizechange/SizeChangeEffectTransparency.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube 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 |
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.effects.sizechange; |
|
21 |
|
|
22 |
import org.distorted.library.effect.Effect; |
|
23 |
import org.distorted.library.effect.FragmentEffectAlpha; |
|
24 |
import org.distorted.library.effect.VertexEffectWave; |
|
25 |
import org.distorted.library.type.Dynamic1D; |
|
26 |
import org.distorted.library.type.Dynamic5D; |
|
27 |
import org.distorted.library.type.Static1D; |
|
28 |
import org.distorted.library.type.Static3D; |
|
29 |
import org.distorted.library.type.Static5D; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
class SizeChangeEffectTransparency extends SizeChangeEffect |
|
34 |
{ |
|
35 |
public int createEffectsPhase0(int duration) |
|
36 |
{ |
|
37 |
mNodeEffectPosition[0] = new int[] {-1,-1}; |
|
38 |
mNodeEffects[0] = new Effect[mNodeEffectPosition[0].length]; |
|
39 |
|
|
40 |
float init_amplitude = 0.0f; |
|
41 |
float end_amplitude = 1/8.0f; |
|
42 |
float length = 1/8.0f; |
|
43 |
float init_phase = 360.0f; |
|
44 |
float end_phase = 0.0f; |
|
45 |
float alpha = 30.0f; |
|
46 |
float beta = 90.0f; |
|
47 |
|
|
48 |
Dynamic5D d1 = new Dynamic5D(duration/2, 0.5f); |
|
49 |
d1.add(new Static5D( init_amplitude, length, init_phase, alpha, beta) ); |
|
50 |
d1.add(new Static5D( end_amplitude , length, end_phase , alpha, beta) ); |
|
51 |
Static3D center = new Static3D(0,0,0); |
|
52 |
mNodeEffects[0][0] = new VertexEffectWave(d1, center, null); |
|
53 |
|
|
54 |
Dynamic1D d0 = new Dynamic1D(duration/2, 0.5f); |
|
55 |
d0.add(new Static1D(1.0f)); |
|
56 |
d0.add(new Static1D(0.0f)); |
|
57 |
mNodeEffects[0][1] = new FragmentEffectAlpha(d0); |
|
58 |
|
|
59 |
return 2; |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
public int createEffectsPhase1(int duration) |
|
65 |
{ |
|
66 |
mNodeEffectPosition[1] = new int[] {-1,-1}; |
|
67 |
mNodeEffects[1] = new Effect[mNodeEffectPosition[1].length]; |
|
68 |
|
|
69 |
float init_amplitude = 1/8.0f; |
|
70 |
float end_amplitude = 0.0f; |
|
71 |
float length = 1/8.0f; |
|
72 |
float init_phase = 0.0f; |
|
73 |
float end_phase = 360.0f; |
|
74 |
float alpha = 30.0f; |
|
75 |
float beta = 90.0f; |
|
76 |
|
|
77 |
Dynamic5D d1 = new Dynamic5D(duration/2, 0.5f); |
|
78 |
d1.add(new Static5D( init_amplitude, length, init_phase, alpha, beta) ); |
|
79 |
d1.add(new Static5D( end_amplitude , length, end_phase , alpha, beta) ); |
|
80 |
Static3D center = new Static3D(0,0,0); |
|
81 |
mNodeEffects[1][0] = new VertexEffectWave(d1, center, null); |
|
82 |
|
|
83 |
Dynamic1D d0 = new Dynamic1D(duration/2, 0.5f); |
|
84 |
d0.add(new Static1D(0.0f)); |
|
85 |
d0.add(new Static1D(1.0f)); |
|
86 |
mNodeEffects[1][1] = new FragmentEffectAlpha(d0); |
|
87 |
|
|
88 |
return 2; |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
93 |
|
|
94 |
@SuppressWarnings("unused") |
|
95 |
static void enable() |
|
96 |
{ |
|
97 |
FragmentEffectAlpha.enable(); |
|
98 |
VertexEffectWave.enable(); |
|
99 |
} |
|
100 |
} |
src/main/java/org/distorted/effects/solve/SolveEffectSpin.java | ||
---|---|---|
71 | 71 |
|
72 | 72 |
private void createEffects(int phase, int duration, int[] points) |
73 | 73 |
{ |
74 |
mCubeEffectPosition[phase] = new int[] {3};
|
|
74 |
mCubeEffectPosition[phase] = new int[] {0};
|
|
75 | 75 |
mCubeEffects[phase] = new Effect[mCubeEffectPosition[0].length]; |
76 | 76 |
|
77 | 77 |
Static4D quaternion = mObject.getRotationQuat(); // always rotate around |
src/main/res/values-de/strings.xml | ||
---|---|---|
22 | 22 |
<string name="you">SIE</string> |
23 | 23 |
<string name="solution">Lösung</string> |
24 | 24 |
<string name="ready">Bereit?</string> |
25 |
<string name="sizechange_effect">Effekt Größenänderung</string>
|
|
25 |
<string name="objectchange_effect">Effekt Größenänderung</string>
|
|
26 | 26 |
<string name="solve_effect">Effekt Lösen</string> |
27 | 27 |
<string name="scramble_effect">Effekt Verdrehen</string> |
28 | 28 |
<string name="win_effect">Effekt Gewinnen</string> |
src/main/res/values-es/strings.xml | ||
---|---|---|
22 | 22 |
<string name="you">TÚ</string> |
23 | 23 |
<string name="solution">Solución</string> |
24 | 24 |
<string name="ready">¿Listo?</string> |
25 |
<string name="sizechange_effect">Efecto de cambio de tamaño</string> |
Also available in: Unified diff
More progreess porting RubikCube.