Revision 584f7954
Added by Leszek Koltunski over 5 years ago
src/main/java/org/distorted/effect/AppearEffect.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.Effect; |
|
23 |
import org.distorted.library.main.DistortedEffects; |
|
24 |
import org.distorted.library.main.DistortedScreen; |
|
25 |
import org.distorted.library.message.EffectListener; |
|
26 |
import org.distorted.magic.RubikCube; |
|
27 |
|
|
28 |
import java.lang.reflect.Method; |
|
29 |
|
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
public abstract class AppearEffect implements EffectListener |
|
33 |
{ |
|
34 |
public enum Type |
|
35 |
{ |
|
36 |
NONE (AppearEffectNone.class ), |
|
37 |
TRANSPARENCY (AppearEffectTransparency.class), |
|
38 |
MOVE (AppearEffectMove.class ), |
|
39 |
ROUND (AppearEffectRound.class ), |
|
40 |
SCALE (AppearEffectScale.class ), |
|
41 |
; |
|
42 |
|
|
43 |
private final Class<? extends AppearEffect> effectClass; |
|
44 |
|
|
45 |
Type(Class<? extends AppearEffect> effectClass) |
|
46 |
{ |
|
47 |
this.effectClass = effectClass; |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
public static final int NUM_EFFECTS = Type.values().length; |
|
52 |
private static final Type[] types; |
|
53 |
|
|
54 |
static |
|
55 |
{ |
|
56 |
int i=0; |
|
57 |
|
|
58 |
types = new Type[NUM_EFFECTS]; |
|
59 |
|
|
60 |
for(Type type: Type.values()) |
|
61 |
{ |
|
62 |
types[i] = type; |
|
63 |
i++; |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
private final int FAKE_EFFECT_ID = -1; |
|
68 |
|
|
69 |
private EffectListener mListener; |
|
70 |
private RubikCube mCube; |
|
71 |
private int mCubeEffectNumber, mNodeEffectNumber, mEffectFinished, mEffectReturned; |
|
72 |
|
|
73 |
DistortedScreen mScreen; |
|
74 |
Effect[] mCubeEffects; |
|
75 |
int[] mCubeEffectPosition; |
|
76 |
Effect[] mNodeEffects; |
|
77 |
int[] mNodeEffectPosition; |
|
78 |
|
|
79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 |
|
|
81 |
AppearEffect() |
|
82 |
{ |
|
83 |
mEffectReturned = 0; |
|
84 |
} |
|
85 |
|
|
86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
87 |
|
|
88 |
abstract int createEffects(int duration); |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
92 |
public static Type getType(int ordinal) |
|
93 |
{ |
|
94 |
return types[ordinal]; |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
public void effectFinished(final long effectID) |
|
100 |
{ |
|
101 |
for(int i=0; i<mCubeEffectNumber; i++) |
|
102 |
{ |
|
103 |
long id = mCubeEffects[i].getID(); |
|
104 |
|
|
105 |
if( effectID == id ) |
|
106 |
{ |
|
107 |
effectReturned(); |
|
108 |
mCube.remove(id); |
|
109 |
break; |
|
110 |
} |
|
111 |
} |
|
112 |
for(int i=0; i<mNodeEffectNumber; i++) |
|
113 |
{ |
|
114 |
long id = mNodeEffects[i].getID(); |
|
115 |
|
|
116 |
if( effectID == id ) |
|
117 |
{ |
|
118 |
effectReturned(); |
|
119 |
mCube.getEffects().abortById(id); |
|
120 |
break; |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
126 |
|
|
127 |
private void effectReturned() |
|
128 |
{ |
|
129 |
mEffectReturned++; |
|
130 |
|
|
131 |
if( mEffectReturned == mEffectFinished ) |
|
132 |
{ |
|
133 |
mListener.effectFinished(FAKE_EFFECT_ID); |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
138 |
|
|
139 |
public long start(int duration, DistortedScreen screen, RubikCube cube, EffectListener listener) |
|
140 |
{ |
|
141 |
mScreen = screen; |
|
142 |
mCube = cube; |
|
143 |
mListener = listener; |
|
144 |
|
|
145 |
mEffectFinished = createEffects(duration); |
|
146 |
|
|
147 |
mCubeEffectNumber = ( mCubeEffects!=null ) ? mCubeEffects.length : 0; |
|
148 |
mNodeEffectNumber = ( mNodeEffects!=null ) ? mNodeEffects.length : 0; |
|
149 |
|
|
150 |
if( mCubeEffectNumber==0 && mNodeEffectNumber==0 ) |
|
151 |
{ |
|
152 |
throw new RuntimeException("Cube and Node Effects both not created!"); |
|
153 |
} |
|
154 |
|
|
155 |
for(int i=0; i<mCubeEffectNumber; i++) |
|
156 |
{ |
|
157 |
mCube.apply(mCubeEffects[i],mCubeEffectPosition[i]); |
|
158 |
mCubeEffects[i].notifyWhenFinished(this); |
|
159 |
} |
|
160 |
|
|
161 |
DistortedEffects nodeEffects = mCube.getEffects(); |
|
162 |
|
|
163 |
for(int i=0; i<mNodeEffectNumber; i++) |
|
164 |
{ |
|
165 |
nodeEffects.apply(mNodeEffects[i],mNodeEffectPosition[i]); |
|
166 |
mNodeEffects[i].notifyWhenFinished(this); |
|
167 |
} |
|
168 |
|
|
169 |
mScreen.attach(mCube); |
|
170 |
|
|
171 |
return FAKE_EFFECT_ID; |
|
172 |
} |
|
173 |
|
|
174 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
175 |
|
|
176 |
public static AppearEffect create(Type type) throws InstantiationException, IllegalAccessException |
|
177 |
{ |
|
178 |
return type.effectClass.newInstance(); |
|
179 |
} |
|
180 |
|
|
181 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
182 |
|
|
183 |
public static void enableEffects() |
|
184 |
{ |
|
185 |
Method method=null; |
|
186 |
|
|
187 |
for(Type type: Type.values()) |
|
188 |
{ |
|
189 |
Class<? extends AppearEffect> cls = type.effectClass; |
|
190 |
|
|
191 |
try |
|
192 |
{ |
|
193 |
method = cls.getMethod("enable"); |
|
194 |
} |
|
195 |
catch(NoSuchMethodException ex) |
|
196 |
{ |
|
197 |
android.util.Log.e("AppearEffect", "exception getting method: "+ex.getMessage()); |
|
198 |
} |
|
199 |
|
|
200 |
try |
|
201 |
{ |
|
202 |
method.invoke(null); |
|
203 |
} |
|
204 |
catch(Exception ex) |
|
205 |
{ |
|
206 |
android.util.Log.e("AppearEffect", "exception invoking method: "+ex.getMessage()); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
} |
src/main/java/org/distorted/effect/AppearEffectMove.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.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 AppearEffectMove extends AppearEffect |
|
30 |
{ |
|
31 |
public int createEffects(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 = new int[] {1}; |
|
38 |
mNodeEffects = new Effect[mNodeEffectPosition.length]; |
|
39 |
|
|
40 |
Dynamic3D d0 = new Dynamic3D(duration, 0.5f); |
|
41 |
d0.add(new Static3D(-xmove,0,0)); |
|
42 |
d0.add(new Static3D( 0,0,0)); |
|
43 |
mNodeEffects[0] = new MatrixEffectMove(d0); |
|
44 |
|
|
45 |
return 1; |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
// Enable all effects used in this Appear. Called by reflection from the parent class. |
|
50 |
// Matrix Effects do not have to be enabled. |
|
51 |
|
|
52 |
@SuppressWarnings("unused") |
|
53 |
static void enable() |
|
54 |
{ |
|
55 |
|
|
56 |
} |
|
57 |
} |
|
58 |
|
src/main/java/org/distorted/effect/AppearEffectNone.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.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 AppearEffectNone extends AppearEffect |
|
30 |
{ |
|
31 |
public int createEffects(int duration) |
|
32 |
{ |
|
33 |
mCubeEffectPosition = new int[] {-1}; |
|
34 |
mCubeEffects = new Effect[mCubeEffectPosition.length]; |
|
35 |
|
|
36 |
Dynamic3D d0 = new Dynamic3D(1,0.5f); |
|
37 |
d0.add(new Static3D(0,0,0)); |
|
38 |
mCubeEffects[0] = new MatrixEffectMove(d0); |
|
39 |
|
|
40 |
return 1; |
|
41 |
} |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
// enable all effects used in this Appear (here: none). Called by reflection from the parent class. |
|
45 |
|
|
46 |
@SuppressWarnings("unused") |
|
47 |
static void enable() |
|
48 |
{ |
|
49 |
|
|
50 |
} |
|
51 |
} |
src/main/java/org/distorted/effect/AppearEffectRound.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.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.magic.RubikRenderer.TEXTURE_SIZE; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
class AppearEffectRound extends AppearEffect |
|
34 |
{ |
|
35 |
public int createEffects(int duration) |
|
36 |
{ |
|
37 |
float X = TEXTURE_SIZE/3; |
|
38 |
|
|
39 |
mCubeEffectPosition = new int[] {6,7}; |
|
40 |
mCubeEffects = new Effect[mCubeEffectPosition.length]; |
|
41 |
|
|
42 |
Dynamic3D d0 = new Dynamic3D(duration, 0.5f); |
|
43 |
d0.add(new Static3D( 0.01f, 0.01f, 0.01f)); |
|
44 |
d0.add(new Static3D( 1.00f, 1.00f, 1.00f)); |
|
45 |
mCubeEffects[0] = new MatrixEffectScale(d0); |
|
46 |
|
|
47 |
Dynamic3D d1 = new Dynamic3D(duration, 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[1] = new MatrixEffectMove(d1); |
|
53 |
|
|
54 |
return 2; |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
// Enable all effects used in this Appear. Called by reflection from the parent class. |
|
59 |
// Matrix Effects do not have to be enabled. |
|
60 |
|
|
61 |
@SuppressWarnings("unused") |
|
62 |
static void enable() |
|
63 |
{ |
|
64 |
|
|
65 |
} |
|
66 |
} |
|
67 |
|
src/main/java/org/distorted/effect/AppearEffectScale.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.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 AppearEffectScale extends AppearEffect |
|
30 |
{ |
|
31 |
public int createEffects(int duration) |
|
32 |
{ |
|
33 |
mCubeEffectPosition = new int[] {6}; |
|
34 |
mCubeEffects = new Effect[mCubeEffectPosition.length]; |
|
35 |
|
|
36 |
Dynamic3D d0 = new Dynamic3D(duration, 0.5f); |
|
37 |
d0.add(new Static3D(0.01f, 0.01f, 0.01f)); |
|
38 |
d0.add(new Static3D(1.00f, 1.00f, 1.00f)); |
|
39 |
mCubeEffects[0] = new MatrixEffectScale(d0); |
|
40 |
|
|
41 |
return 1; |
|
42 |
} |
|
43 |
|
|
44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
45 |
// Enable all effects used in this Appear. Called by reflection from the parent class. |
|
46 |
// Matrix Effects do not have to be enabled. |
|
47 |
|
|
48 |
@SuppressWarnings("unused") |
|
49 |
static void enable() |
|
50 |
{ |
|
51 |
|
|
52 |
} |
|
53 |
} |
|
54 |
|
src/main/java/org/distorted/effect/AppearEffectTransparency.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.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 AppearEffectTransparency extends AppearEffect |
|
34 |
{ |
|
35 |
public int createEffects(int duration) |
|
36 |
{ |
|
37 |
mCubeEffectPosition = new int[] {-1}; |
|
38 |
mCubeEffects = new Effect[mCubeEffectPosition.length]; |
|
39 |
|
|
40 |
Dynamic1D d0 = new Dynamic1D(duration, 0.5f); |
|
41 |
d0.add(new Static1D(0.0f)); |
|
42 |
d0.add(new Static1D(1.0f)); |
|
43 |
mCubeEffects[0] = new FragmentEffectAlpha(d0); |
|
44 |
|
|
45 |
mNodeEffectPosition = new int[] {-1}; |
|
46 |
mNodeEffects = new Effect[mNodeEffectPosition.length]; |
|
47 |
|
|
48 |
int w = mScreen.getWidth(); |
|
49 |
int h = mScreen.getHeight(); |
|
50 |
int min = w<h ? w:h; |
|
51 |
|
|
52 |
float init_amplitude = min/15.0f; |
|
53 |
float end_amplitude = 0.0f; |
|
54 |
float length = min/15.0f; |
|
55 |
float init_phase = 0.0f; |
|
56 |
float end_phase = 360.0f; |
|
57 |
float alpha = 30.0f; |
|
58 |
float beta = 90.0f; |
|
59 |
|
|
60 |
Dynamic5D d1 = new Dynamic5D(duration, 0.5f); |
|
61 |
d1.add(new Static5D( init_amplitude, length, init_phase, alpha, beta) ); |
|
62 |
d1.add(new Static5D( end_amplitude , length, end_phase , alpha, beta) ); |
|
63 |
Static3D center = new Static3D(min*0.5f,min*0.5f,0); |
|
64 |
mNodeEffects[0] = new VertexEffectWave(d1, center, null); |
|
65 |
|
|
66 |
return 2; |
|
67 |
} |
|
68 |
|
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
70 |
// Enable all effects used in this Appear. Called by reflection from the parent class. |
|
71 |
|
|
72 |
@SuppressWarnings("unused") |
|
73 |
static void enable() |
|
74 |
{ |
|
75 |
FragmentEffectAlpha.enable(); |
|
76 |
VertexEffectWave.enable(); |
|
77 |
} |
|
78 |
} |
src/main/java/org/distorted/effect/DisappearEffect.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.Effect; |
|
23 |
import org.distorted.library.main.DistortedEffects; |
|
24 |
import org.distorted.library.main.DistortedScreen; |
|
25 |
import org.distorted.library.message.EffectListener; |
|
26 |
import org.distorted.magic.RubikCube; |
|
27 |
|
|
28 |
import java.lang.reflect.Method; |
|
29 |
|
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
public abstract class DisappearEffect implements EffectListener |
|
33 |
{ |
|
34 |
public enum Type |
|
35 |
{ |
|
36 |
NONE (DisappearEffectNone.class ), |
|
37 |
TRANSPARENCY (DisappearEffectTransparency.class), |
|
38 |
MOVE (DisappearEffectMove.class ), |
|
39 |
ROUND (DisappearEffectRound.class ), |
|
40 |
SCALE (DisappearEffectScale.class ), |
|
41 |
; |
|
42 |
|
|
43 |
private final Class<? extends DisappearEffect> effectClass; |
|
44 |
|
|
45 |
Type(Class<? extends DisappearEffect> effectClass) |
|
46 |
{ |
|
47 |
this.effectClass = effectClass; |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
public static final int NUM_EFFECTS = Type.values().length; |
|
52 |
private static final Type[] types; |
|
53 |
|
|
54 |
static |
|
55 |
{ |
|
56 |
int i=0; |
|
57 |
|
|
58 |
types = new Type[NUM_EFFECTS]; |
|
59 |
|
|
60 |
for(Type type: Type.values()) |
|
61 |
{ |
|
62 |
types[i] = type; |
|
63 |
i++; |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
private final int FAKE_EFFECT_ID = -2; |
|
68 |
|
|
69 |
private EffectListener mListener; |
|
70 |
private RubikCube mCube; |
|
71 |
private int mCubeEffectNumber, mNodeEffectNumber, mEffectFinished, mEffectReturned; |
|
72 |
|
|
73 |
DistortedScreen mScreen; |
|
74 |
Effect[] mCubeEffects; |
|
75 |
int[] mCubeEffectPosition; |
|
76 |
Effect[] mNodeEffects; |
|
77 |
int[] mNodeEffectPosition; |
|
78 |
|
|
79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 |
|
|
81 |
DisappearEffect() |
|
82 |
{ |
|
83 |
mEffectReturned = 0; |
|
84 |
} |
|
85 |
|
|
86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
87 |
|
|
88 |
abstract int createEffects(int duration); |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
92 |
public static Type getType(int ordinal) |
|
93 |
{ |
|
94 |
return types[ordinal]; |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
public void effectFinished(final long effectID) |
|
100 |
{ |
|
101 |
for(int i=0; i<mCubeEffectNumber; i++) |
|
102 |
{ |
|
103 |
long id = mCubeEffects[i].getID(); |
|
104 |
|
|
105 |
if( effectID == id ) |
|
106 |
{ |
|
107 |
effectReturned(); |
|
108 |
mCube.remove(id); |
|
109 |
break; |
|
110 |
} |
|
111 |
} |
|
112 |
for(int i=0; i<mNodeEffectNumber; i++) |
|
113 |
{ |
|
114 |
long id = mNodeEffects[i].getID(); |
|
115 |
|
|
116 |
if( effectID == id ) |
|
117 |
{ |
|
118 |
effectReturned(); |
|
119 |
mCube.getEffects().abortById(id); |
|
120 |
break; |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
126 |
|
|
127 |
private void effectReturned() |
|
128 |
{ |
|
129 |
mEffectReturned++; |
|
130 |
|
|
131 |
if( mEffectReturned == mEffectFinished ) |
|
132 |
{ |
|
133 |
mListener.effectFinished(FAKE_EFFECT_ID); |
|
134 |
} |
|
135 |
|
|
136 |
if( mEffectReturned == mCubeEffectNumber+mNodeEffectNumber ) |
|
137 |
{ |
|
138 |
mScreen.detach(mCube); |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
143 |
|
|
144 |
public long start(int duration, DistortedScreen screen, RubikCube cube, EffectListener listener) |
|
145 |
{ |
|
146 |
mScreen = screen; |
|
147 |
mCube = cube; |
|
148 |
mListener = listener; |
|
149 |
|
|
150 |
mEffectFinished = createEffects(duration); |
|
151 |
|
|
152 |
mCubeEffectNumber = ( mCubeEffects!=null ) ? mCubeEffects.length : 0; |
|
153 |
mNodeEffectNumber = ( mNodeEffects!=null ) ? mNodeEffects.length : 0; |
|
154 |
|
|
155 |
if( mCubeEffectNumber==0 && mNodeEffectNumber==0 ) |
|
156 |
{ |
|
157 |
throw new RuntimeException("Cube and Node Effects both not created!"); |
|
158 |
} |
|
159 |
|
|
160 |
for(int i=0; i<mCubeEffectNumber; i++) |
|
161 |
{ |
|
162 |
mCube.apply(mCubeEffects[i],mCubeEffectPosition[i]); |
|
163 |
mCubeEffects[i].notifyWhenFinished(this); |
|
164 |
} |
|
165 |
|
|
166 |
DistortedEffects nodeEffects = mCube.getEffects(); |
|
167 |
|
|
168 |
for(int i=0; i<mNodeEffectNumber; i++) |
|
169 |
{ |
|
170 |
nodeEffects.apply(mNodeEffects[i],mNodeEffectPosition[i]); |
|
171 |
mNodeEffects[i].notifyWhenFinished(this); |
|
172 |
} |
|
173 |
|
|
174 |
return FAKE_EFFECT_ID; |
|
175 |
} |
|
176 |
|
|
177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
178 |
|
|
179 |
public static DisappearEffect create(Type type) throws InstantiationException, IllegalAccessException |
|
180 |
{ |
|
181 |
return type.effectClass.newInstance(); |
|
182 |
} |
|
183 |
|
|
184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
185 |
|
|
186 |
public static void enableEffects() |
|
187 |
{ |
|
188 |
Method method=null; |
|
189 |
|
|
190 |
for(Type type: Type.values()) |
|
191 |
{ |
|
192 |
Class<? extends DisappearEffect> cls = type.effectClass; |
|
193 |
|
|
194 |
try |
|
195 |
{ |
|
196 |
method = cls.getMethod("enable"); |
|
197 |
} |
|
198 |
catch(NoSuchMethodException ex) |
|
199 |
{ |
|
200 |
android.util.Log.e("DisappearEffect", "exception getting method: "+ex.getMessage()); |
|
201 |
} |
|
202 |
|
|
203 |
try |
|
204 |
{ |
|
205 |
method.invoke(null); |
|
206 |
} |
|
207 |
catch(Exception ex) |
|
208 |
{ |
|
209 |
android.util.Log.e("DisappearEffect", "exception invoking method: "+ex.getMessage()); |
|
210 |
} |
|
211 |
} |
|
212 |
} |
|
213 |
} |
src/main/java/org/distorted/effect/DisappearEffectMove.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.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 DisappearEffectMove extends DisappearEffect |
|
30 |
{ |
|
31 |
public int createEffects(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 = new int[] {1}; |
|
38 |
mNodeEffects = new Effect[mNodeEffectPosition.length]; |
|
39 |
|
|
40 |
Dynamic3D d0 = new Dynamic3D(duration, 0.5f); |
|
41 |
d0.add(new Static3D( 0,0,0)); |
|
42 |
d0.add(new Static3D(xmove,0,0)); |
|
43 |
mNodeEffects[0] = new MatrixEffectMove(d0); |
|
44 |
|
|
45 |
return 1; |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
// Enable all effects used in this Appear. Called by reflection from the parent class. |
|
50 |
// Matrix Effects do not have to be enabled. |
|
51 |
|
|
52 |
@SuppressWarnings("unused") |
|
53 |
static void enable() |
|
54 |
{ |
|
55 |
|
|
56 |
} |
|
57 |
} |
|
58 |
|
src/main/java/org/distorted/effect/DisappearEffectNone.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.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 DisappearEffectNone extends DisappearEffect |
|
30 |
{ |
|
31 |
public int createEffects(int duration) |
|
32 |
{ |
|
33 |
mCubeEffectPosition = new int[] {-1}; |
|
34 |
mCubeEffects = new Effect[mCubeEffectPosition.length]; |
|
35 |
|
|
36 |
Dynamic3D d0 = new Dynamic3D(1,0.5f); |
|
37 |
d0.add(new Static3D(0,0,0)); |
|
38 |
mCubeEffects[0] = new MatrixEffectMove(d0); |
|
39 |
|
|
40 |
return 1; |
|
41 |
} |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
// enable all effects used in this Appear (here: none). Called by reflection from the parent class. |
|
45 |
|
|
46 |
@SuppressWarnings("unused") |
|
47 |
static void enable() |
|
48 |
{ |
|
49 |
|
|
50 |
} |
|
51 |
} |
src/main/java/org/distorted/effect/DisappearEffectRound.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.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.magic.RubikRenderer.TEXTURE_SIZE; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
class DisappearEffectRound extends DisappearEffect |
|
34 |
{ |
|
35 |
public int createEffects(int duration) |
|
36 |
{ |
|
37 |
float X = TEXTURE_SIZE/3; |
|
38 |
|
|
39 |
mCubeEffectPosition = new int[] {6,7}; |
|
40 |
mCubeEffects = new Effect[mCubeEffectPosition.length]; |
|
41 |
|
|
42 |
Dynamic3D d0 = new Dynamic3D(duration, 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] = new MatrixEffectScale(d0); |
|
46 |
|
|
47 |
Dynamic3D d1 = new Dynamic3D(duration, 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[1] = new MatrixEffectMove(d1); |
|
53 |
|
|
54 |
return 2; |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
// Enable all effects used in this Appear. Called by reflection from the parent class. |
|
59 |
// Matrix Effects do not have to be enabled. |
|
60 |
|
|
61 |
@SuppressWarnings("unused") |
|
62 |
static void enable() |
|
63 |
{ |
|
64 |
|
|
65 |
} |
|
66 |
} |
|
67 |
|
src/main/java/org/distorted/effect/DisappearEffectScale.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.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 DisappearEffectScale extends DisappearEffect |
|
30 |
{ |
|
31 |
public int createEffects(int duration) |
|
32 |
{ |
|
33 |
mCubeEffectPosition = new int[] {6}; |
|
34 |
mCubeEffects = new Effect[mCubeEffectPosition.length]; |
|
35 |
|
|
36 |
Dynamic3D d0 = new Dynamic3D(duration, 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] = new MatrixEffectScale(d0); |
|
40 |
|
|
41 |
return 1; |
|
42 |
} |
|
43 |
|
|
44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
45 |
// Enable all effects used in this Appear. Called by reflection from the parent class. |
|
46 |
// Matrix Effects do not have to be enabled. |
|
47 |
|
|
48 |
@SuppressWarnings("unused") |
|
49 |
static void enable() |
|
50 |
{ |
|
51 |
|
|
52 |
} |
|
53 |
} |
|
54 |
|
src/main/java/org/distorted/effect/DisappearEffectTransparency.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.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 DisappearEffectTransparency extends DisappearEffect |
|
34 |
{ |
|
35 |
public int createEffects(int duration) |
|
36 |
{ |
|
37 |
mCubeEffectPosition = new int[] {-1}; |
|
38 |
mCubeEffects = new Effect[mCubeEffectPosition.length]; |
|
39 |
|
|
40 |
Dynamic1D d0 = new Dynamic1D(duration, 0.5f); |
|
41 |
d0.add(new Static1D(1.0f)); |
|
42 |
d0.add(new Static1D(0.0f)); |
|
43 |
mCubeEffects[0] = new FragmentEffectAlpha(d0); |
|
44 |
|
|
45 |
mNodeEffectPosition = new int[] {-1}; |
|
46 |
mNodeEffects = new Effect[mNodeEffectPosition.length]; |
|
47 |
|
|
48 |
int w = mScreen.getWidth(); |
|
49 |
int h = mScreen.getHeight(); |
|
50 |
int min = w<h ? w:h; |
|
51 |
|
|
52 |
float init_amplitude = 0.0f; |
|
53 |
float end_amplitude = min/15.0f; |
|
54 |
float length = min/15.0f; |
|
55 |
float init_phase = 360.0f; |
|
56 |
float end_phase = 0.0f; |
|
57 |
float alpha = 30.0f; |
|
58 |
float beta = 90.0f; |
|
59 |
|
|
60 |
Dynamic5D d1 = new Dynamic5D(duration, 0.5f); |
|
61 |
d1.add(new Static5D( init_amplitude, length, init_phase, alpha, beta) ); |
|
62 |
d1.add(new Static5D( end_amplitude , length, end_phase , alpha, beta) ); |
|
63 |
Static3D center = new Static3D(min*0.5f,min*0.5f,0); |
|
64 |
mNodeEffects[0] = new VertexEffectWave(d1, center, null); |
|
65 |
|
|
66 |
return 2; |
|
67 |
} |
|
68 |
|
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
70 |
// Enable all effects used in this Appear. Called by reflection from the parent class. |
|
71 |
|
|
72 |
@SuppressWarnings("unused") |
|
73 |
static void enable() |
|
74 |
{ |
|
75 |
FragmentEffectAlpha.enable(); |
|
76 |
VertexEffectWave.enable(); |
|
77 |
} |
|
78 |
} |
src/main/java/org/distorted/effect/SizeChangeEffect.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 |
import org.distorted.library.effect.Effect; |
|
25 |
import org.distorted.library.main.DistortedEffects; |
|
26 |
import org.distorted.library.main.DistortedScreen; |
|
27 |
import org.distorted.library.message.EffectListener; |
|
28 |
import org.distorted.magic.RubikCube; |
|
29 |
|
|
30 |
import java.lang.reflect.Method; |
|
31 |
|
|
32 |
public abstract class SizeChangeEffect implements EffectListener |
|
33 |
{ |
|
34 |
public enum Type |
|
35 |
{ |
|
36 |
NONE (SizeChangeEffectAppearNone.class , SizeChangeEffectDisappearNone.class ), |
|
37 |
TRANSPARENCY (SizeChangeEffectAppearTransparency.class, SizeChangeEffectDisappearTransparency.class), |
|
38 |
MOVE (SizeChangeEffectAppearMove.class , SizeChangeEffectDisappearMove.class ), |
|
39 |
ROUND (SizeChangeEffectAppearRound.class , SizeChangeEffectDisappearRound.class ), |
|
40 |
SCALE (SizeChangeEffectAppearScale.class , SizeChangeEffectDisappearScale.class ), |
|
41 |
; |
|
42 |
|
|
43 |
final Class<? extends SizeChangeEffectAppear > appear; |
|
44 |
final Class<? extends SizeChangeEffectDisappear> disappear; |
|
45 |
|
|
46 |
Type(Class<? extends SizeChangeEffectAppear> appear, Class<? extends SizeChangeEffectDisappear> disappear ) |
|
47 |
{ |
|
48 |
this.appear = appear; |
|
49 |
this.disappear = disappear; |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
private static int NUM_EFFECTS = Type.values().length; |
|
54 |
private static final Type[] types; |
|
55 |
|
|
56 |
static |
|
57 |
{ |
|
58 |
int i=0; |
|
59 |
types = new Type[NUM_EFFECTS]; |
|
60 |
|
|
61 |
for(Type type: Type.values()) |
|
62 |
{ |
|
63 |
types[i++] = type; |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
private EffectListener mListener; |
|
68 |
private int mCubeEffectNumber, mNodeEffectNumber, mEffectFinished, mEffectReturned; |
|
69 |
private int mFakeEffectID; |
|
70 |
|
|
71 |
RubikCube mCube; |
|
72 |
DistortedScreen mScreen; |
|
73 |
Effect[] mCubeEffects; |
|
74 |
int[] mCubeEffectPosition; |
|
75 |
Effect[] mNodeEffects; |
|
76 |
int[] mNodeEffectPosition; |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
SizeChangeEffect(int id) |
|
81 |
{ |
|
82 |
mEffectReturned = 0; |
|
83 |
mFakeEffectID = id; |
|
84 |
} |
|
85 |
|
|
86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
87 |
|
|
88 |
public static Type getType(int index) |
|
89 |
{ |
|
90 |
return types[index]; |
|
91 |
} |
|
92 |
|
|
93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
94 |
|
|
95 |
public static String[] getNames() |
|
96 |
{ |
|
97 |
String[] names = new String[NUM_EFFECTS]; |
|
98 |
|
|
99 |
for( int i=0; i<NUM_EFFECTS; i++) |
|
100 |
{ |
|
101 |
names[i] = types[i].name(); |
|
102 |
} |
|
103 |
|
|
104 |
return names; |
|
105 |
} |
|
106 |
|
|
107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
108 |
|
|
109 |
abstract int createEffects(int duration); |
|
110 |
abstract void effectsEnd(); |
|
111 |
abstract void startEnd(); |
|
112 |
|
|
113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
114 |
|
|
115 |
public void effectFinished(final long effectID) |
|
116 |
{ |
|
117 |
for(int i=0; i<mCubeEffectNumber; i++) |
|
118 |
{ |
|
119 |
long id = mCubeEffects[i].getID(); |
|
120 |
|
|
121 |
if( effectID == id ) |
|
122 |
{ |
|
123 |
mEffectReturned++; |
|
124 |
|
|
125 |
if( mEffectReturned == mEffectFinished ) |
|
126 |
{ |
|
127 |
mListener.effectFinished(mFakeEffectID); |
|
128 |
} |
|
129 |
|
|
130 |
if( mEffectReturned == mCubeEffectNumber+mNodeEffectNumber ) |
|
131 |
{ |
|
132 |
effectsEnd(); |
|
133 |
} |
|
134 |
|
|
135 |
mCube.remove(id); |
|
136 |
break; |
|
137 |
} |
|
138 |
} |
|
139 |
for(int i=0; i<mNodeEffectNumber; i++) |
|
140 |
{ |
|
141 |
long id = mNodeEffects[i].getID(); |
|
142 |
|
|
143 |
if( effectID == id ) |
|
144 |
{ |
|
145 |
mEffectReturned++; |
|
146 |
|
|
147 |
if( mEffectReturned == mEffectFinished ) |
|
148 |
{ |
|
149 |
mListener.effectFinished(mFakeEffectID); |
|
150 |
} |
|
151 |
|
|
152 |
if( mEffectReturned == mCubeEffectNumber+mNodeEffectNumber ) |
|
153 |
{ |
|
154 |
effectsEnd(); |
|
155 |
} |
|
156 |
|
|
157 |
mCube.getEffects().abortById(id); |
|
158 |
break; |
|
159 |
} |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
164 |
|
|
165 |
public long start(int duration, DistortedScreen screen, RubikCube cube, EffectListener listener) |
|
166 |
{ |
|
167 |
mScreen = screen; |
|
168 |
mCube = cube; |
|
169 |
mListener = listener; |
|
170 |
|
|
171 |
mEffectFinished = createEffects(duration); |
|
172 |
|
|
173 |
mCubeEffectNumber = ( mCubeEffects!=null ) ? mCubeEffects.length : 0; |
|
174 |
mNodeEffectNumber = ( mNodeEffects!=null ) ? mNodeEffects.length : 0; |
|
175 |
|
|
176 |
if( mCubeEffectNumber==0 && mNodeEffectNumber==0 ) |
|
177 |
{ |
|
178 |
throw new RuntimeException("Cube and Node Effects both not created!"); |
|
179 |
} |
|
180 |
|
|
181 |
for(int i=0; i<mCubeEffectNumber; i++) |
|
182 |
{ |
|
183 |
mCube.apply(mCubeEffects[i],mCubeEffectPosition[i]); |
|
184 |
mCubeEffects[i].notifyWhenFinished(this); |
|
185 |
} |
|
186 |
|
|
187 |
DistortedEffects nodeEffects = mCube.getEffects(); |
|
188 |
|
|
189 |
for(int i=0; i<mNodeEffectNumber; i++) |
|
190 |
{ |
|
191 |
nodeEffects.apply(mNodeEffects[i],mNodeEffectPosition[i]); |
|
192 |
mNodeEffects[i].notifyWhenFinished(this); |
|
193 |
} |
|
194 |
|
|
195 |
startEnd(); |
|
196 |
|
|
197 |
return mFakeEffectID; |
|
198 |
} |
|
199 |
|
|
200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 |
|
|
202 |
public static void enableEffects() |
|
203 |
{ |
|
204 |
Method method=null; |
|
205 |
|
|
206 |
for(Type type: Type.values()) |
|
207 |
{ |
|
208 |
try |
|
209 |
{ |
|
210 |
method = type.appear.getMethod("enable"); |
|
211 |
} |
|
212 |
catch(NoSuchMethodException ex) |
|
213 |
{ |
|
214 |
android.util.Log.e("SizeChangeEffect", "exception getting method: "+ex.getMessage()); |
|
215 |
} |
|
216 |
|
|
217 |
try |
|
218 |
{ |
|
219 |
method.invoke(null); |
|
220 |
} |
|
221 |
catch(Exception ex) |
|
222 |
{ |
|
223 |
android.util.Log.e("SizeChangeEffect", "exception invoking method: "+ex.getMessage()); |
|
224 |
} |
|
225 |
|
|
226 |
try |
|
227 |
{ |
|
228 |
method = type.disappear.getMethod("enable"); |
|
229 |
} |
|
230 |
catch(NoSuchMethodException ex) |
|
231 |
{ |
|
232 |
android.util.Log.e("SizeChangeEffect", "exception getting method: "+ex.getMessage()); |
|
233 |
} |
|
234 |
|
|
235 |
try |
|
236 |
{ |
|
237 |
method.invoke(null); |
|
238 |
} |
|
239 |
catch(Exception ex) |
|
240 |
{ |
|
241 |
android.util.Log.e("SizeChangeEffect", "exception invoking method: "+ex.getMessage()); |
|
242 |
} |
|
243 |
} |
|
244 |
} |
|
245 |
} |
src/main/java/org/distorted/effect/SizeChangeEffectAppear.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 abstract class SizeChangeEffectAppear extends SizeChangeEffect |
|
25 |
{ |
|
26 |
SizeChangeEffectAppear() |
|
27 |
{ |
|
28 |
super(-1); |
|
29 |
} |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
public static SizeChangeEffectAppear create(Type type) throws InstantiationException, IllegalAccessException |
|
34 |
{ |
|
35 |
return type.appear.newInstance(); |
|
36 |
} |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
void effectsEnd() |
|
41 |
{ |
|
42 |
|
|
43 |
} |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
void startEnd() |
|
48 |
{ |
|
49 |
mScreen.attach(mCube); |
|
50 |
} |
|
51 |
} |
src/main/java/org/distorted/effect/SizeChangeEffectAppearMove.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.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 SizeChangeEffectAppearMove extends SizeChangeEffectAppear |
|
30 |
{ |
|
31 |
public int createEffects(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 = new int[] {1}; |
|
38 |
mNodeEffects = new Effect[mNodeEffectPosition.length]; |
|
39 |
|
|
40 |
Dynamic3D d0 = new Dynamic3D(duration, 0.5f); |
|
41 |
d0.add(new Static3D(-xmove,0,0)); |
|
42 |
d0.add(new Static3D( 0,0,0)); |
|
43 |
mNodeEffects[0] = new MatrixEffectMove(d0); |
|
44 |
|
|
45 |
return 1; |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
// Enable all effects used in this Appear. Called by reflection from the parent class. |
|
50 |
// Matrix Effects do not have to be enabled. |
|
51 |
|
|
52 |
@SuppressWarnings("unused") |
|
53 |
static void enable() |
|
54 |
{ |
|
55 |
|
|
56 |
} |
|
57 |
} |
|
58 |
|
src/main/java/org/distorted/effect/SizeChangeEffectAppearNone.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
Also available in: Unified diff
- adjust SizeChangeEffects
- implement first two UnscrambleEffects