Revision 470820a7
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/objects/Cubit.java | ||
---|---|---|
27 | 27 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
28 | 28 |
import org.distorted.library.effect.MatrixEffectRotate; |
29 | 29 |
import org.distorted.library.main.DistortedEffects; |
30 |
import org.distorted.library.main.DistortedNode; |
|
31 |
import org.distorted.library.mesh.MeshBase; |
|
32 | 30 |
import org.distorted.library.message.EffectListener; |
33 | 31 |
import org.distorted.library.type.Dynamic1D; |
34 | 32 |
import org.distorted.library.type.Static1D; |
... | ... | |
41 | 39 |
class Cubit |
42 | 40 |
{ |
43 | 41 |
private static final int POST_ROTATION_MILLISEC = 500; |
44 |
private static final Static3D matrCenter = new Static3D(0,0,0);
|
|
42 |
private static final Static3D MATRIX_CENTER = new Static3D(0,0,0);
|
|
45 | 43 |
|
46 | 44 |
private final Static3D mOrigPosition; |
47 | 45 |
|
48 | 46 |
private RubikObject mParent; |
49 |
private MeshBase mMesh; |
|
50 | 47 |
private Static3D mRotationAxis; |
51 | 48 |
private MatrixEffectRotate mRotateEffect; |
52 | 49 |
private Static3D mCurrentPosition; |
53 | 50 |
private int mNumAxis; |
54 | 51 |
private Dynamic1D mRotationAngle; |
55 | 52 |
|
56 |
DistortedNode mNode; |
|
57 | 53 |
DistortedEffects mEffect; |
58 | 54 |
Static4D mQuatScramble; |
59 | 55 |
float[] mRotationRow; |
60 | 56 |
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
Cubit(RubikObject parent, Static3D position) |
|
60 |
{ |
|
61 |
float x = position.get0(); |
|
62 |
float y = position.get1(); |
|
63 |
float z = position.get2(); |
|
64 |
|
|
65 |
Static3D vector = new Static3D(x,y,z); |
|
66 |
|
|
67 |
mParent = parent; |
|
68 |
mOrigPosition = new Static3D(x,y,z); |
|
69 |
mQuatScramble = new Static4D(0,0,0,1); |
|
70 |
mRotationAngle = new Dynamic1D(); |
|
71 |
mRotationAxis = new Static3D(1,0,0); |
|
72 |
mCurrentPosition = position; |
|
73 |
mRotateEffect = new MatrixEffectRotate(mRotationAngle, mRotationAxis, MATRIX_CENTER); |
|
74 |
|
|
75 |
mNumAxis = mParent.ROTATION_AXIS.length; |
|
76 |
mRotationRow = new float[mNumAxis]; |
|
77 |
computeRotationRow(); |
|
78 |
|
|
79 |
mEffect = new DistortedEffects(); |
|
80 |
mEffect.apply( new MatrixEffectMove(vector) ); |
|
81 |
mEffect.apply( new MatrixEffectQuaternion(mQuatScramble, MATRIX_CENTER)); |
|
82 |
mEffect.apply(mRotateEffect); |
|
83 |
mEffect.apply(mParent.mQuatAEffect); |
|
84 |
mEffect.apply(mParent.mQuatCEffect); |
|
85 |
mEffect.apply(mParent.mScaleEffect); |
|
86 |
} |
|
87 |
|
|
61 | 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | 89 |
// Because of quatMultiplication, errors can accumulate - so to avoid this, we |
63 | 90 |
// correct the value of the 'scramble' quat to what it should be - one of the legal quats from the |
... | ... | |
163 | 190 |
} |
164 | 191 |
} |
165 | 192 |
|
166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
167 |
|
|
168 |
Cubit(RubikObject parent, MeshBase mesh, Static3D position) |
|
169 |
{ |
|
170 |
float x = position.get0(); |
|
171 |
float y = position.get1(); |
|
172 |
float z = position.get2(); |
|
173 |
|
|
174 |
Static3D vector = new Static3D(x,y,z); |
|
175 |
|
|
176 |
mParent = parent; |
|
177 |
mMesh = mesh; |
|
178 |
mOrigPosition = new Static3D(x,y,z); |
|
179 |
mQuatScramble = new Static4D(0,0,0,1); |
|
180 |
mRotationAngle = new Dynamic1D(); |
|
181 |
mRotationAxis = new Static3D(1,0,0); |
|
182 |
mCurrentPosition = position; |
|
183 |
mRotateEffect = new MatrixEffectRotate(mRotationAngle, mRotationAxis, matrCenter); |
|
184 |
|
|
185 |
mNumAxis = mParent.ROTATION_AXIS.length; |
|
186 |
mRotationRow = new float[mNumAxis]; |
|
187 |
computeRotationRow(); |
|
188 |
|
|
189 |
mEffect = new DistortedEffects(); |
|
190 |
mEffect.apply( new MatrixEffectMove(vector) ); |
|
191 |
mEffect.apply( new MatrixEffectQuaternion(mQuatScramble, matrCenter)); |
|
192 |
mEffect.apply(mRotateEffect); |
|
193 |
mEffect.apply(mParent.mQuatAEffect); |
|
194 |
mEffect.apply(mParent.mQuatCEffect); |
|
195 |
mEffect.apply(mParent.mScaleEffect); |
|
196 |
|
|
197 |
mNode = new DistortedNode(mParent.mTexture,mEffect,mMesh); |
|
198 |
} |
|
199 |
|
|
200 | 193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
201 | 194 |
|
202 | 195 |
void savePreferences(SharedPreferences.Editor editor) |
... | ... | |
357 | 350 |
} |
358 | 351 |
} |
359 | 352 |
|
360 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
361 |
// all DistortedTextures, DistortedNodes, DistortedFramebuffers, DistortedScreens and all types of |
|
362 |
// Meshes HAVE TO be markedForDeletion when they are no longer needed- otherwise we have a major |
|
363 |
// memory leak. |
|
364 |
|
|
365 |
void releaseResources() |
|
366 |
{ |
|
367 |
mMesh.markForDeletion(); |
|
368 |
mNode.markForDeletion(); |
|
369 |
} |
|
370 |
|
|
371 | 353 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
372 | 354 |
|
373 | 355 |
void solve() |
... | ... | |
395 | 377 |
|
396 | 378 |
return dx*dx + dy*dy + dz*dz; |
397 | 379 |
} |
398 |
|
|
399 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
400 |
|
|
401 |
int getColorIndex(int face) |
|
402 |
{ |
|
403 |
Static4D texMap = mMesh.getTextureMap(face); |
|
404 |
return (int)(texMap.get0() / texMap.get2()); |
|
405 |
} |
|
406 |
|
|
407 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
408 |
|
|
409 |
MeshBase getMesh() |
|
410 |
{ |
|
411 |
return mMesh; |
|
412 |
} |
|
413 | 380 |
} |
Also available in: Unified diff
Begin porting RubikCube to the new SingleMesh library. This will make rendering much faster - e.g. in case of Cube 5, instead of 98 renders of individual Cubits, there will be one render of the whole Mesh.