Revision b32444ee
Added by Leszek Koltunski almost 5 years ago
src/main/java/org/distorted/object/Cubit.java | ||
---|---|---|
26 | 26 |
import org.distorted.library.effect.MatrixEffectRotate; |
27 | 27 |
import org.distorted.library.main.DistortedEffects; |
28 | 28 |
import org.distorted.library.main.DistortedNode; |
29 |
import org.distorted.library.mesh.MeshCubes;
|
|
29 |
import org.distorted.library.mesh.MeshBase;
|
|
30 | 30 |
import org.distorted.library.message.EffectListener; |
31 | 31 |
import org.distorted.library.type.Dynamic1D; |
32 | 32 |
import org.distorted.library.type.Static1D; |
... | ... | |
43 | 43 |
private final Static3D mOrigPosition; |
44 | 44 |
|
45 | 45 |
private RubikObject mParent; |
46 |
private MeshCubes mCube;
|
|
46 |
private MeshBase mMesh;
|
|
47 | 47 |
private Static3D mRotationAxis; |
48 | 48 |
private MatrixEffectRotate mRotateEffect; |
49 | 49 |
|
... | ... | |
153 | 153 |
|
154 | 154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
155 | 155 |
|
156 |
Cubit(RubikObject parent, MeshCubes mesh, Static3D position)
|
|
156 |
Cubit(RubikObject parent, MeshBase mesh, Static3D position)
|
|
157 | 157 |
{ |
158 | 158 |
float x = position.get0(); |
159 | 159 |
float y = position.get1(); |
... | ... | |
164 | 164 |
Static3D vector = new Static3D(TS*(x-nc), TS*(y-nc), TS*(z-nc)); |
165 | 165 |
|
166 | 166 |
mParent = parent; |
167 |
mCube = mesh;
|
|
167 |
mMesh = mesh;
|
|
168 | 168 |
mOrigPosition = new Static3D(x,y,z); |
169 | 169 |
mQuatScramble = new Static4D(0,0,0,1); |
170 | 170 |
mRotationAngle = new Dynamic1D(); |
... | ... | |
182 | 182 |
mEffect.apply(mParent.mScaleEffect); |
183 | 183 |
mEffect.apply(mParent.mMoveEffect); |
184 | 184 |
|
185 |
mNode = new DistortedNode(mParent.mTexture,mEffect,mCube);
|
|
185 |
mNode = new DistortedNode(mParent.mTexture,mEffect,mMesh);
|
|
186 | 186 |
} |
187 | 187 |
|
188 | 188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
267 | 267 |
|
268 | 268 |
void releaseResources() |
269 | 269 |
{ |
270 |
mCube.markForDeletion();
|
|
270 |
mMesh.markForDeletion();
|
|
271 | 271 |
mNode.markForDeletion(); |
272 | 272 |
} |
273 | 273 |
|
src/main/java/org/distorted/object/RubikCube.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import org.distorted.library.main.DistortedEffects; |
27 | 27 |
import org.distorted.library.main.DistortedTexture; |
28 |
import org.distorted.library.mesh.MeshBase; |
|
28 | 29 |
import org.distorted.library.mesh.MeshCubes; |
29 | 30 |
import org.distorted.library.mesh.MeshRectangles; |
30 | 31 |
import org.distorted.library.type.Static3D; |
... | ... | |
34 | 35 |
|
35 | 36 |
class RubikCube extends RubikObject |
36 | 37 |
{ |
37 |
private static final Static4D mapFront, mapBack, mapLeft, mapRight, mapTop, mapBottom, mapBlack; |
|
38 |
|
|
39 |
static |
|
40 |
{ |
|
41 |
// 3x2 bitmap = 6 squares: |
|
42 |
// |
|
43 |
// RED GREEN BLUE |
|
44 |
// YELLOW WHITE BROWN |
|
45 |
|
|
46 |
final float ze = 0.0f; |
|
47 |
final float ot = 1.0f/3.0f; |
|
48 |
final float tt = 2.0f/3.0f; |
|
49 |
final float oh = 1.0f/2.0f; |
|
50 |
final float of = 1.0f/40.0f; |
|
51 |
|
|
52 |
mapFront = new Static4D(ze,oh, ze+ot,oh+oh); |
|
53 |
mapBack = new Static4D(tt,ze, tt+ot,ze+oh); |
|
54 |
mapLeft = new Static4D(ot,ze, ot+ot,ze+oh); |
|
55 |
mapRight = new Static4D(ze,ze, ze+ot,ze+oh); |
|
56 |
mapTop = new Static4D(tt,oh, tt+ot,oh+oh); |
|
57 |
mapBottom= new Static4D(ot,oh, ot+ot,oh+oh); |
|
58 |
|
|
59 |
mapBlack = new Static4D(ze,ze, ze+of,ze+of); |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
// i.e. size^3 - (size-2)^3 - number of cubits in the outside wall of the Cube (we don't create or |
|
64 |
// render the inside) |
|
65 |
|
|
66 |
int getNumCubits(int size) |
|
67 |
{ |
|
68 |
return size>1 ? 6*size*size - 12*size + 8 : 1; |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
|
|
73 | 38 |
int[][] getCubitPositions(int size) |
74 | 39 |
{ |
75 | 40 |
int[][] tmp = new int[getNumCubits(size)][3]; |
... | ... | |
93 | 58 |
return tmp; |
94 | 59 |
} |
95 | 60 |
|
61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
62 |
// i.e. size^3 - (size-2)^3 - number of cubits in the outside wall of the Cube (we don't create or |
|
63 |
// render the inside) |
|
64 |
|
|
65 |
int getNumCubits(int size) |
|
66 |
{ |
|
67 |
return size>1 ? 6*size*size - 12*size + 8 : 1; |
|
68 |
} |
|
69 |
|
|
96 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
97 | 71 |
// All legal rotation quats of a RubikCube of any size must have all four of their components |
98 | 72 |
// equal to either 0, 1, -1, 0.5, -0.5 or +-sqrt(2)/2. |
... | ... | |
168 | 142 |
|
169 | 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
170 | 144 |
|
171 |
MeshCubes createMesh(int vertices,int x, int y, int z) |
|
145 |
private static final Static4D mapFront, mapBack, mapLeft, mapRight, mapTop, mapBottom, mapBlack; |
|
146 |
|
|
147 |
static |
|
148 |
{ |
|
149 |
// 3x2 bitmap = 6 squares: |
|
150 |
// |
|
151 |
// RED GREEN BLUE |
|
152 |
// YELLOW WHITE BROWN |
|
153 |
|
|
154 |
final float ze = 0.0f; |
|
155 |
final float ot = 1.0f/3.0f; |
|
156 |
final float tt = 2.0f/3.0f; |
|
157 |
final float oh = 1.0f/2.0f; |
|
158 |
final float of = 1.0f/40.0f; |
|
159 |
|
|
160 |
mapFront = new Static4D(ze,oh, ze+ot,oh+oh); |
|
161 |
mapBack = new Static4D(tt,ze, tt+ot,ze+oh); |
|
162 |
mapLeft = new Static4D(ot,ze, ot+ot,ze+oh); |
|
163 |
mapRight = new Static4D(ze,ze, ze+ot,ze+oh); |
|
164 |
mapTop = new Static4D(tt,oh, tt+ot,oh+oh); |
|
165 |
mapBottom= new Static4D(ot,oh, ot+ot,oh+oh); |
|
166 |
|
|
167 |
mapBlack = new Static4D(ze,ze, ze+of,ze+of); |
|
168 |
} |
|
169 |
|
|
170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
171 |
|
|
172 |
MeshBase createCubitMesh(int vertices, int x, int y, int z) |
|
172 | 173 |
{ |
173 | 174 |
Static4D tmpLeft = (x== 0 ? mapLeft :mapBlack); |
174 | 175 |
Static4D tmpRight = (x== mSize-1 ? mapRight :mapBlack); |
src/main/java/org/distorted/object/RubikObject.java | ||
---|---|---|
29 | 29 |
import org.distorted.library.main.DistortedEffects; |
30 | 30 |
import org.distorted.library.main.DistortedNode; |
31 | 31 |
import org.distorted.library.main.DistortedTexture; |
32 |
import org.distorted.library.mesh.MeshCubes;
|
|
32 |
import org.distorted.library.mesh.MeshBase;
|
|
33 | 33 |
import org.distorted.library.mesh.MeshRectangles; |
34 | 34 |
import org.distorted.library.message.EffectListener; |
35 | 35 |
import org.distorted.library.type.Dynamic1D; |
... | ... | |
47 | 47 |
|
48 | 48 |
private static final int POST_ROTATION_MILLISEC = 500; |
49 | 49 |
private final int NUM_CUBITS; |
50 |
private final int[][] CUBIT_POSITIONS; |
|
51 | 50 |
private int mRotRow; |
52 | 51 |
private Static3D mRotAxis; |
53 | 52 |
private Static3D mMove, mScale, mNodeMove, mNodeScale; |
54 | 53 |
private Static4D mQuatAccumulated; |
55 | 54 |
private DistortedTexture mNodeTexture; |
55 |
private Cubit[] mCubits; |
|
56 | 56 |
|
57 | 57 |
int mSize; |
58 | 58 |
|
... | ... | |
65 | 65 |
MatrixEffectQuaternion mQuatCEffect; |
66 | 66 |
MatrixEffectQuaternion mQuatAEffect; |
67 | 67 |
|
68 |
private Cubit[] mCubits; |
|
69 |
|
|
70 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
71 | 69 |
|
72 | 70 |
RubikObject(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects) |
... | ... | |
75 | 73 |
|
76 | 74 |
LEGAL_QUATS = getLegalQuats(); |
77 | 75 |
NUM_CUBITS = getNumCubits(size); |
78 |
CUBIT_POSITIONS = getCubitPositions(size); |
|
79 | 76 |
|
80 | 77 |
mNodeTexture = texture; |
81 | 78 |
mSize = size; |
... | ... | |
107 | 104 |
effects.apply(nodeScaleEffect); |
108 | 105 |
effects.apply(nodeMoveEffect); |
109 | 106 |
|
110 |
|
|
111 | 107 |
mCubits = new Cubit[NUM_CUBITS]; |
112 |
|
|
113 | 108 |
mTexture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE); |
114 | 109 |
|
115 | 110 |
int vertices = (int)(24.0f/mSize + 2.0f); |
111 |
int[][] positions = getCubitPositions(size); |
|
116 | 112 |
|
117 | 113 |
for(int i=0; i<NUM_CUBITS; i++) |
118 | 114 |
{ |
119 |
int x = CUBIT_POSITIONS[i][0];
|
|
120 |
int y = CUBIT_POSITIONS[i][1];
|
|
121 |
int z = CUBIT_POSITIONS[i][2];
|
|
115 |
int x = positions[i][0];
|
|
116 |
int y = positions[i][1];
|
|
117 |
int z = positions[i][2];
|
|
122 | 118 |
|
123 |
mCubits[i] = new Cubit( this ,createMesh(vertices,x,y,z), new Static3D(x,y,z) ); |
|
119 |
mCubits[i] = new Cubit( this ,createCubitMesh(vertices,x,y,z), new Static3D(x,y,z) );
|
|
124 | 120 |
attach(mCubits[i].mNode); |
125 | 121 |
} |
126 | 122 |
} |
... | ... | |
359 | 355 |
abstract int[][] getCubitPositions(int size); |
360 | 356 |
abstract float[] getLegalQuats(); |
361 | 357 |
abstract boolean belongsToRotation(Static3D position, Static3D axis, int row); |
362 |
abstract MeshCubes createMesh(int vertices,int x, int y, int z);
|
|
358 |
abstract MeshBase createCubitMesh(int vertices, int x, int y, int z);
|
|
363 | 359 |
|
364 | 360 |
public abstract void createTexture(); |
365 | 361 |
} |
src/main/java/org/distorted/object/RubikObjectList.java | ||
---|---|---|
86 | 86 |
{ |
87 | 87 |
DistortedTexture texture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE); |
88 | 88 |
DistortedEffects effects = new DistortedEffects(); |
89 |
MeshRectangles mesh = new MeshRectangles(20,20); |
|
89 |
MeshRectangles mesh = new MeshRectangles(20,20); // mesh of the node, not of the cubits
|
|
90 | 90 |
|
91 | 91 |
return new RubikCube(mObjectSize, quatCur, quatAcc, texture, mesh, effects); |
92 | 92 |
} |
Also available in: Unified diff
More work on making new types of RubikObjects easily creatable.