Revision 9208e27b
Added by Leszek Koltunski over 5 years ago
src/main/java/org/distorted/effect/TransitionEffect.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.effect; |
21 | 21 |
|
22 |
import org.distorted.library.effect.Effect; |
|
22 | 23 |
import org.distorted.library.main.DistortedScreen; |
23 | 24 |
import org.distorted.library.message.EffectListener; |
25 |
import org.distorted.library.message.EffectMessage; |
|
24 | 26 |
import org.distorted.magic.RubikCube; |
25 | 27 |
|
26 | 28 |
import java.lang.reflect.Method; |
27 | 29 |
|
28 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
29 | 31 |
|
30 |
public abstract class TransitionEffect |
|
32 |
public abstract class TransitionEffect implements EffectListener
|
|
31 | 33 |
{ |
32 | 34 |
public enum Type |
33 | 35 |
{ |
... | ... | |
38 | 40 |
/** |
39 | 41 |
* Gradually make the old cube more and more transparent until it disappears, then make the new one appear. |
40 | 42 |
*/ |
41 |
DISAPPEAR (TransitionEffectDisappear.class); |
|
43 |
DISAPPEAR (TransitionEffectDisappear.class), |
|
44 |
/** |
|
45 |
* Move the old cube to the right and the new one from the left. |
|
46 |
*/ |
|
47 |
MOVE (TransitionEffectMove.class); |
|
42 | 48 |
|
43 | 49 |
private final Class<? extends TransitionEffect> effectClass; |
44 | 50 |
|
... | ... | |
48 | 54 |
} |
49 | 55 |
} |
50 | 56 |
|
57 |
private final int MOVE_POSITION; |
|
58 |
private long mDisappearID, mAppearID; |
|
59 |
private EffectListener mListener; |
|
60 |
private DistortedScreen mScreen; |
|
61 |
private RubikCube mOld, mNew; |
|
62 |
|
|
63 |
Effect mDisappear, mAppear; |
|
64 |
|
|
65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 |
|
|
67 |
TransitionEffect(int position) |
|
68 |
{ |
|
69 |
MOVE_POSITION = position; |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
// whenever we get the message that the old cube completely disappeared, make the new one appear |
|
74 |
// The calling RubikRenderer will get the message that this (final) transition is over and do whatever |
|
75 |
// it wants to do with this. |
|
76 |
|
|
77 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID) |
|
78 |
{ |
|
79 |
if( effectID == mDisappearID ) |
|
80 |
{ |
|
81 |
mScreen.detach(mOld); |
|
82 |
mOld.remove(mDisappearID); |
|
83 |
mOld.deregisterForMessages(this); |
|
84 |
|
|
85 |
mNew.apply(mAppear,MOVE_POSITION); |
|
86 |
mNew.registerForMessages(mListener); |
|
87 |
mScreen.attach(mNew); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
51 | 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
52 | 92 |
|
53 |
public abstract long prepare(EffectListener listener); |
|
54 |
public abstract void start(DistortedScreen screen, RubikCube oldCube, RubikCube newCube); |
|
93 |
public long start(DistortedScreen screen, RubikCube oldCube, RubikCube newCube,EffectListener listener) |
|
94 |
{ |
|
95 |
mScreen = screen; |
|
96 |
mNew = newCube; |
|
97 |
mOld = oldCube; |
|
98 |
mListener = listener; |
|
99 |
|
|
100 |
mDisappearID = mDisappear.getID(); |
|
101 |
mAppearID = mAppear.getID(); |
|
102 |
|
|
103 |
mOld.apply(mDisappear,MOVE_POSITION); |
|
104 |
mOld.registerForMessages(this); |
|
105 |
|
|
106 |
return mAppearID; |
|
107 |
} |
|
55 | 108 |
|
56 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
57 | 110 |
|
58 |
public static TransitionEffect createEffect(Type type) throws InstantiationException, IllegalAccessException
|
|
111 |
public static TransitionEffect create(Type type) throws InstantiationException, IllegalAccessException |
|
59 | 112 |
{ |
60 | 113 |
return type.effectClass.newInstance(); |
61 | 114 |
} |
src/main/java/org/distorted/effect/TransitionEffectDisappear.java | ||
---|---|---|
20 | 20 |
package org.distorted.effect; |
21 | 21 |
|
22 | 22 |
import org.distorted.library.effect.FragmentEffectAlpha; |
23 |
import org.distorted.library.main.DistortedScreen; |
|
24 |
import org.distorted.library.message.EffectListener; |
|
25 |
import org.distorted.library.message.EffectMessage; |
|
26 | 23 |
import org.distorted.library.type.Dynamic1D; |
27 | 24 |
import org.distorted.library.type.Static1D; |
28 |
import org.distorted.magic.RubikCube; |
|
29 | 25 |
|
30 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
31 | 27 |
|
32 |
class TransitionEffectDisappear extends TransitionEffect implements EffectListener
|
|
28 |
class TransitionEffectDisappear extends TransitionEffect |
|
33 | 29 |
{ |
34 |
private static final int DURATION_IN_MILLIS = 1000; |
|
35 |
|
|
36 |
private EffectListener mListener; |
|
37 |
private FragmentEffectAlpha mDisappear, mAppear; |
|
38 |
private DistortedScreen mScreen; |
|
39 |
private RubikCube mOld, mNew; |
|
40 |
|
|
41 |
private long mDisappearID; |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
|
|
45 | 30 |
TransitionEffectDisappear() |
46 | 31 |
{ |
32 |
super(-1); |
|
47 | 33 |
|
48 |
} |
|
49 |
|
|
50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
51 |
// enable all effects we are using in this Transition. |
|
52 |
// called by reflection from the parent class. |
|
53 |
|
|
54 |
@SuppressWarnings("unused") |
|
55 |
static void enable() |
|
56 |
{ |
|
57 |
FragmentEffectAlpha.enable(); |
|
58 |
} |
|
34 |
final int DURATION_IN_MILLIS = 1000; |
|
59 | 35 |
|
60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
|
|
62 |
public long prepare(EffectListener listener) |
|
63 |
{ |
|
64 |
mListener = listener; |
|
65 |
|
|
66 |
Dynamic1D disappearDyn = new Dynamic1D(DURATION_IN_MILLIS, 0.5f); // this means - linearily change the |
|
67 |
disappearDyn.add(new Static1D(1.0f)); // alpha of the old cube from 1.0 (100%) |
|
68 |
disappearDyn.add(new Static1D(0.0f)); // to 0.0 (0%) within DURATION millisecs. |
|
36 |
Dynamic1D disappearDyn = new Dynamic1D(DURATION_IN_MILLIS, 0.5f); |
|
37 |
disappearDyn.add(new Static1D(1.0f)); |
|
38 |
disappearDyn.add(new Static1D(0.0f)); |
|
69 | 39 |
mDisappear = new FragmentEffectAlpha(disappearDyn); |
70 | 40 |
|
71 |
Dynamic1D appearDyn = new Dynamic1D(DURATION_IN_MILLIS, 0.5f); // the opposite - make the new cube
|
|
72 |
appearDyn.add(new Static1D(0.0f)); // more and more opaque.
|
|
73 |
appearDyn.add(new Static1D(1.0f)); //
|
|
41 |
Dynamic1D appearDyn = new Dynamic1D(DURATION_IN_MILLIS, 0.5f); |
|
42 |
appearDyn.add(new Static1D(0.0f)); |
|
43 |
appearDyn.add(new Static1D(1.0f)); |
|
74 | 44 |
mAppear = new FragmentEffectAlpha(appearDyn); |
75 |
|
|
76 |
mDisappearID = mDisappear.getID(); |
|
77 |
|
|
78 |
return mAppear.getID(); |
|
79 | 45 |
} |
80 | 46 |
|
81 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
82 |
// At the start, oldCube is attached to the screen, new is not. |
|
83 |
// Gradually make the old cube disappear and wait for the message that this is done. |
|
84 |
|
|
85 |
public void start(DistortedScreen screen, RubikCube oldCube, RubikCube newCube) |
|
86 |
{ |
|
87 |
mScreen = screen; |
|
88 |
mNew = newCube; |
|
89 |
mOld = oldCube; |
|
90 |
|
|
91 |
mOld.apply(mDisappear); |
|
92 |
mOld.registerForMessages(this); |
|
93 |
} |
|
94 |
|
|
95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
96 |
// whenever we get the message that the old cube completely disappeared, make the new one appear |
|
97 |
// The calling RubikRenderer will get the message that this (final) transition is over and do whatever |
|
98 |
// it wants to do with this. |
|
48 |
// enable all effects used in this Transition. |
|
49 |
// called by reflection from the parent class. |
|
99 | 50 |
|
100 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID) |
|
51 |
@SuppressWarnings("unused") |
|
52 |
static void enable() |
|
101 | 53 |
{ |
102 |
if( effectID == mDisappearID ) |
|
103 |
{ |
|
104 |
mScreen.detachAll(); |
|
105 |
mNew.attachToScreen(mScreen); |
|
106 |
mNew.apply(mAppear); |
|
107 |
mOld.deregisterForMessages(this); |
|
108 |
mNew.registerForMessages(mListener); |
|
109 |
} |
|
54 |
FragmentEffectAlpha.enable(); |
|
110 | 55 |
} |
111 | 56 |
} |
src/main/java/org/distorted/effect/TransitionEffectEmpty.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.effect; |
21 | 21 |
|
22 |
import org.distorted.library.main.DistortedScreen;
|
|
23 |
import org.distorted.library.message.EffectListener;
|
|
24 |
import org.distorted.magic.RubikCube;
|
|
22 |
import org.distorted.library.effect.MatrixEffectMove;
|
|
23 |
import org.distorted.library.type.Dynamic3D;
|
|
24 |
import org.distorted.library.type.Static3D;
|
|
25 | 25 |
|
26 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
27 | 27 |
|
28 | 28 |
class TransitionEffectEmpty extends TransitionEffect |
29 | 29 |
{ |
30 |
private static final int FAKE_EFFECT_ID = -1; |
|
31 |
|
|
32 |
private EffectListener mListener; |
|
33 |
|
|
34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
35 |
|
|
36 | 30 |
TransitionEffectEmpty() |
37 | 31 |
{ |
32 |
super(-1); |
|
33 |
|
|
34 |
final int DURATION_IN_MILLIS = 1; |
|
38 | 35 |
|
36 |
Dynamic3D disappearDyn = new Dynamic3D(DURATION_IN_MILLIS, 0.5f); |
|
37 |
disappearDyn.add(new Static3D(0,0,0)); |
|
38 |
mDisappear = new MatrixEffectMove(disappearDyn); |
|
39 |
|
|
40 |
Dynamic3D appearDyn = new Dynamic3D(DURATION_IN_MILLIS, 0.5f); |
|
41 |
appearDyn.add(new Static3D(0,0,0)); |
|
42 |
mAppear = new MatrixEffectMove(appearDyn); |
|
39 | 43 |
} |
40 | 44 |
|
41 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
42 |
// enable all effects we are using in this Transition (here: none).
|
|
46 |
// enable all effects used in this Transition (here: none).
|
|
43 | 47 |
// called by reflection from the parent class. |
44 | 48 |
|
45 | 49 |
@SuppressWarnings("unused") |
... | ... | |
47 | 51 |
{ |
48 | 52 |
|
49 | 53 |
} |
50 |
|
|
51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
52 |
// return a fake effect ID (because there's no real effect here - empty transition! |
|
53 |
|
|
54 |
public long prepare(EffectListener listener) |
|
55 |
{ |
|
56 |
mListener = listener; |
|
57 |
return FAKE_EFFECT_ID; |
|
58 |
} |
|
59 |
|
|
60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
// we just detach the old cube, attach the new one and manually send a message with the '-1' id |
|
62 |
// back to the listener (RubikRenderer) |
|
63 |
|
|
64 |
public void start(DistortedScreen screen, RubikCube oldCube, RubikCube newCube) |
|
65 |
{ |
|
66 |
screen.detachAll(); |
|
67 |
newCube.attachToScreen(screen); |
|
68 |
|
|
69 |
mListener.effectMessage(null, FAKE_EFFECT_ID, 0); |
|
70 |
} |
|
71 | 54 |
} |
src/main/java/org/distorted/effect/TransitionEffectMove.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.MatrixEffectMove; |
|
23 |
import org.distorted.library.type.Dynamic3D; |
|
24 |
import org.distorted.library.type.Static3D; |
|
25 |
|
|
26 |
import static org.distorted.magic.RubikRenderer.TEXTURE_SIZE; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
class TransitionEffectMove extends TransitionEffect |
|
31 |
{ |
|
32 |
TransitionEffectMove() |
|
33 |
{ |
|
34 |
super(2); |
|
35 |
|
|
36 |
final int DURATION_IN_MILLIS = 1000; |
|
37 |
|
|
38 |
Dynamic3D disappearDyn = new Dynamic3D(DURATION_IN_MILLIS, 0.5f); |
|
39 |
disappearDyn.add(new Static3D(0,0,0)); |
|
40 |
disappearDyn.add(new Static3D(TEXTURE_SIZE,0,0)); |
|
41 |
mDisappear = new MatrixEffectMove(disappearDyn); |
|
42 |
|
|
43 |
Dynamic3D appearDyn = new Dynamic3D(DURATION_IN_MILLIS, 0.5f); |
|
44 |
appearDyn.add(new Static3D(-TEXTURE_SIZE,0,0)); |
|
45 |
appearDyn.add(new Static3D(0,0,0)); |
|
46 |
mAppear = new MatrixEffectMove(appearDyn); |
|
47 |
} |
|
48 |
|
|
49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
// enable all effects used in this Transition. Called by reflection from the parent class. |
|
51 |
// Matrix Effects do not have to be enabled. |
|
52 |
|
|
53 |
@SuppressWarnings("unused") |
|
54 |
static void enable() |
|
55 |
{ |
|
56 |
|
|
57 |
} |
|
58 |
} |
|
59 |
|
src/main/java/org/distorted/magic/RubikCube.java | ||
---|---|---|
31 | 31 |
import org.distorted.library.effect.VertexEffectSink; |
32 | 32 |
import org.distorted.library.main.DistortedEffects; |
33 | 33 |
import org.distorted.library.main.DistortedNode; |
34 |
import org.distorted.library.main.DistortedScreen; |
|
35 | 34 |
import org.distorted.library.main.DistortedTexture; |
36 | 35 |
import org.distorted.library.mesh.MeshCubes; |
36 |
import org.distorted.library.mesh.MeshQuad; |
|
37 | 37 |
import org.distorted.library.message.EffectListener; |
38 | 38 |
import org.distorted.library.type.Dynamic1D; |
39 | 39 |
import org.distorted.library.type.Static1D; |
... | ... | |
42 | 42 |
|
43 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 44 |
|
45 |
public class RubikCube |
|
45 |
public class RubikCube extends DistortedNode
|
|
46 | 46 |
{ |
47 | 47 |
private static final int POST_ROTATION_MILLISEC = 500; |
48 | 48 |
private static final int TEXTURE_SIZE = 100; |
... | ... | |
60 | 60 |
private Static3D[][][] mCurrentPosition; |
61 | 61 |
private MatrixEffectRotate[][][] mRotateEffect; |
62 | 62 |
private Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal; |
63 |
private Static3D mMove, mScale; |
|
63 |
private Static3D mMove, mScale, mNodeMove, mNodeScale;
|
|
64 | 64 |
private DistortedTexture mTexture; |
65 | 65 |
private DistortedEffects mEffectsListeningForNow; |
66 | 66 |
|
67 | 67 |
private int mRotAxis, mRotRow; |
68 | 68 |
private int mSize; |
69 | 69 |
|
70 |
private DistortedTexture mNodeTexture; |
|
71 |
|
|
70 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
71 | 73 |
|
72 |
RubikCube(int size, Static4D quatC, Static4D quatA) |
|
74 |
RubikCube(int size, Static4D quatC, Static4D quatA, DistortedTexture texture, MeshQuad mesh, DistortedEffects effects)
|
|
73 | 75 |
{ |
76 |
super(texture,effects,mesh); |
|
77 |
|
|
78 |
mNodeTexture = texture; |
|
79 |
|
|
74 | 80 |
mSize = size; |
75 | 81 |
|
76 | 82 |
mRotationAngleStatic = new Static1D(0); |
77 | 83 |
mRotationAngleMiddle = new Static1D(0); |
78 | 84 |
mRotationAngleFinal = new Static1D(0); |
79 | 85 |
|
80 |
mMove = new Static3D(0,0,0); |
|
81 |
mScale= new Static3D(1,1,1); |
|
86 |
mMove = new Static3D(0,0,0); |
|
87 |
mScale = new Static3D(1,1,1); |
|
88 |
mNodeMove = new Static3D(0,0,0); |
|
89 |
mNodeScale= new Static3D(1,1,1); |
|
82 | 90 |
|
83 | 91 |
mRotAxis= RubikSurfaceView.VECTX; |
84 | 92 |
mTexture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE); |
... | ... | |
103 | 111 |
MatrixEffectQuaternion quatCEffect = new MatrixEffectQuaternion(quatC, center); |
104 | 112 |
MatrixEffectQuaternion quatAEffect = new MatrixEffectQuaternion(quatA, center); |
105 | 113 |
|
114 |
MatrixEffectMove nodeMoveEffect = new MatrixEffectMove(mNodeMove); |
|
115 |
MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale); |
|
116 |
|
|
117 |
effects.apply(nodeMoveEffect); |
|
118 |
effects.apply(nodeScaleEffect); |
|
119 |
|
|
106 | 120 |
// 3x2 bitmap = 6 squares: |
107 | 121 |
// |
108 | 122 |
// RED GREEN BLUE |
... | ... | |
157 | 171 |
mEffects[x][y][z].apply(mRotateEffect[x][y][z]); |
158 | 172 |
mEffects[x][y][z].apply( new MatrixEffectQuaternion(mQuatScramble[x][y][z], center)); |
159 | 173 |
mEffects[x][y][z].apply( new MatrixEffectMove(cubeVectors[x][y][z]) ); |
174 |
|
|
175 |
mNodes[x][y][z] = new DistortedNode(mTexture,mEffects[x][y][z],mCubes[x][y][z]); |
|
176 |
|
|
177 |
attach(mNodes[x][y][z]); |
|
160 | 178 |
} |
161 | 179 |
} |
162 | 180 |
} |
163 | 181 |
|
164 | 182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
165 | 183 |
|
166 |
public void attachToScreen(DistortedScreen screen)
|
|
184 |
public void apply(Effect effect)
|
|
167 | 185 |
{ |
168 | 186 |
for(int x=0; x<mSize; x++) |
169 | 187 |
for(int y=0; y<mSize; y++) |
... | ... | |
171 | 189 |
{ |
172 | 190 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
173 | 191 |
{ |
174 |
mNodes[x][y][z] = new DistortedNode(mTexture,mEffects[x][y][z],mCubes[x][y][z]); |
|
175 |
screen.attach(mNodes[x][y][z]); |
|
192 |
mEffects[x][y][z].apply(effect); |
|
176 | 193 |
} |
177 | 194 |
} |
178 | 195 |
} |
179 | 196 |
|
180 | 197 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
181 | 198 |
|
182 |
public void apply(Effect effect) |
|
199 |
public void apply(Effect effect, int position)
|
|
183 | 200 |
{ |
184 | 201 |
for(int x=0; x<mSize; x++) |
185 | 202 |
for(int y=0; y<mSize; y++) |
... | ... | |
187 | 204 |
{ |
188 | 205 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
189 | 206 |
{ |
190 |
mEffects[x][y][z].apply(effect); |
|
207 |
mEffects[x][y][z].apply(effect, position); |
|
208 |
} |
|
209 |
} |
|
210 |
} |
|
211 |
|
|
212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
213 |
|
|
214 |
public void remove(long effectID) |
|
215 |
{ |
|
216 |
for(int x=0; x<mSize; x++) |
|
217 |
for(int y=0; y<mSize; y++) |
|
218 |
for(int z=0; z<mSize; z++) |
|
219 |
{ |
|
220 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
|
221 |
{ |
|
222 |
mEffects[x][y][z].abortById(effectID); |
|
191 | 223 |
} |
192 | 224 |
} |
193 | 225 |
} |
... | ... | |
454 | 486 |
|
455 | 487 |
void recomputeScaleFactor(int screenWidth, int screenHeight, float size) |
456 | 488 |
{ |
457 |
float scaleFactor = size/(TEXTURE_SIZE*mSize); |
|
458 |
|
|
459 |
mMove.set( (screenWidth-scaleFactor*TEXTURE_SIZE)/2 , (screenHeight-scaleFactor*TEXTURE_SIZE)/2 , -scaleFactor*TEXTURE_SIZE/2 ); |
|
489 |
int texW = mNodeTexture.getWidth(); |
|
490 |
int texH = mNodeTexture.getHeight(); |
|
491 |
|
|
492 |
if( (float)texH/texW > (float)screenHeight/screenWidth ) |
|
493 |
{ |
|
494 |
int w = (screenHeight*texW)/texH; |
|
495 |
float factor = (float)screenHeight/texH; |
|
496 |
mNodeMove.set((screenWidth-w)*0.5f ,0, 0); |
|
497 |
mNodeScale.set(factor,factor,factor); |
|
498 |
} |
|
499 |
else |
|
500 |
{ |
|
501 |
int h = (screenWidth*texH)/texW; |
|
502 |
float factor = (float)screenWidth/texW; |
|
503 |
mNodeMove.set(0,(screenHeight-h)*0.5f,0); |
|
504 |
mNodeScale.set(factor,factor,factor); |
|
505 |
} |
|
506 |
|
|
507 |
float scaleFactor = (size/(TEXTURE_SIZE*mSize)) * (float)texW/(screenWidth>screenHeight ? screenHeight:screenWidth); |
|
508 |
|
|
509 |
mMove.set( (texW-scaleFactor*TEXTURE_SIZE)/2 , (texH-scaleFactor*TEXTURE_SIZE)/2 , -scaleFactor*TEXTURE_SIZE/2 ); |
|
460 | 510 |
mScale.set(scaleFactor,scaleFactor,scaleFactor); |
461 | 511 |
} |
462 | 512 |
|
src/main/java/org/distorted/magic/RubikRenderer.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import org.distorted.effect.TransitionEffect; |
25 | 25 |
import org.distorted.library.effect.VertexEffectSink; |
26 |
import org.distorted.library.main.DistortedEffects; |
|
26 | 27 |
import org.distorted.library.main.DistortedLibrary; |
27 | 28 |
import org.distorted.library.main.DistortedScreen; |
29 |
import org.distorted.library.main.DistortedTexture; |
|
30 |
import org.distorted.library.mesh.MeshQuad; |
|
28 | 31 |
import org.distorted.library.message.EffectListener; |
29 | 32 |
import org.distorted.library.message.EffectMessage; |
30 | 33 |
import org.distorted.library.type.Static4D; |
... | ... | |
34 | 37 |
|
35 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
36 | 39 |
|
37 |
class RubikRenderer implements GLSurfaceView.Renderer, EffectListener |
|
40 |
public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener
|
|
38 | 41 |
{ |
39 | 42 |
private static final float CUBE_SCREEN_RATIO = 0.5f; |
40 | 43 |
private static final float CAMERA_DISTANCE = 0.6f; // 0.6 of the length of max(scrHeight,scrWidth) |
44 |
public static final int TEXTURE_SIZE = 600; |
|
41 | 45 |
|
42 | 46 |
private RubikSurfaceView mView; |
43 | 47 |
private DistortedScreen mScreen; |
... | ... | |
52 | 56 |
|
53 | 57 |
private int mScreenWidth, mScreenHeight; |
54 | 58 |
|
59 |
private MeshQuad mMesh; |
|
60 |
|
|
55 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 62 |
|
57 | 63 |
RubikRenderer(RubikSurfaceView v) |
... | ... | |
79 | 85 |
|
80 | 86 |
mCanRotate = true; |
81 | 87 |
mCanDrag = true; |
88 |
|
|
89 |
mMesh= new MeshQuad(); |
|
82 | 90 |
} |
83 | 91 |
|
84 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
123 | 131 |
|
124 | 132 |
try |
125 | 133 |
{ |
126 |
TransitionEffect effect = TransitionEffect.createEffect(TransitionEffect.Type.DISAPPEAR); |
|
127 |
mTransitionEffectID = effect.prepare(this); |
|
128 |
effect.start(mScreen,mOldCube,mNewCube); |
|
134 |
TransitionEffect effect = TransitionEffect.create(TransitionEffect.Type.EMPTY); |
|
135 |
mTransitionEffectID = effect.start(mScreen,mOldCube,mNewCube,this); |
|
129 | 136 |
} |
130 | 137 |
catch(Exception ex) |
131 | 138 |
{ |
... | ... | |
149 | 156 |
{ |
150 | 157 |
mCanRotate = true; |
151 | 158 |
mCanDrag = true; |
159 |
mNewCube.remove(mTransitionEffectID); |
|
160 |
mNewCube.deregisterForMessages(this); |
|
152 | 161 |
} |
153 | 162 |
} |
154 | 163 |
|
... | ... | |
176 | 185 |
{ |
177 | 186 |
mNewCube.createTexture(); |
178 | 187 |
mScreen.detachAll(); |
179 |
mNewCube.attachToScreen(mScreen);
|
|
188 |
mScreen.attach(mNewCube);
|
|
180 | 189 |
|
181 | 190 |
VertexEffectSink.enable(); |
182 | 191 |
TransitionEffect.enableEffects(); |
... | ... | |
225 | 234 |
if( mOldCube!=null ) mOldCube.releaseResources(); |
226 | 235 |
mOldCube = mNewCube; |
227 | 236 |
|
228 |
mNewCube = new RubikCube(newSize, mQuatCurrent, mQuatAccumulated); |
|
237 |
DistortedTexture texture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE); |
|
238 |
DistortedEffects effects = new DistortedEffects(); |
|
239 |
|
|
240 |
mNewCube = new RubikCube(newSize, mQuatCurrent, mQuatAccumulated, texture, mMesh, effects); |
|
229 | 241 |
mNewCube.createTexture(); |
230 | 242 |
|
231 | 243 |
if( mScreenWidth!=0 ) |
Also available in: Unified diff
Progress with DistortedCube.