Revision 9208e27b
Added by Leszek Koltunski about 5 years ago
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 |
|
Also available in: Unified diff
Progress with DistortedCube.