Revision 411c6285
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/object/RubikObject.java | ||
---|---|---|
20 | 20 |
package org.distorted.object; |
21 | 21 |
|
22 | 22 |
import android.content.SharedPreferences; |
23 |
import android.graphics.Bitmap; |
|
24 |
import android.graphics.Canvas; |
|
25 |
import android.graphics.Paint; |
|
23 | 26 |
|
24 | 27 |
import org.distorted.library.effect.Effect; |
25 | 28 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
... | ... | |
42 | 45 |
|
43 | 46 |
public abstract class RubikObject extends DistortedNode |
44 | 47 |
{ |
48 |
static final int TEXTURE_HEIGHT = 128; |
|
45 | 49 |
static final float OBJECT_SCREEN_RATIO = 0.5f; |
46 | 50 |
final float[] LEGAL_QUATS; |
47 | 51 |
|
... | ... | |
65 | 69 |
|
66 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
67 | 71 |
|
68 |
RubikObject(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects)
|
|
72 |
RubikObject(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture, MeshRectangles nodeMesh, DistortedEffects nodeEffects)
|
|
69 | 73 |
{ |
70 |
super(texture,effects,mesh);
|
|
74 |
super(nodeTexture,nodeEffects,nodeMesh);
|
|
71 | 75 |
|
72 | 76 |
resizeFBO(NODE_FBO_SIZE, NODE_FBO_SIZE); |
73 | 77 |
|
... | ... | |
94 | 98 |
mQuatAEffect = new MatrixEffectQuaternion(quatAcc, center); |
95 | 99 |
|
96 | 100 |
MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale); |
97 |
effects.apply(nodeScaleEffect);
|
|
101 |
nodeEffects.apply(nodeScaleEffect);
|
|
98 | 102 |
|
99 | 103 |
mCubits = new Cubit[NUM_CUBITS]; |
100 | 104 |
mTexture = new DistortedTexture(); |
... | ... | |
108 | 112 |
int y = positions[i][1]; |
109 | 113 |
int z = positions[i][2]; |
110 | 114 |
|
111 |
mCubits[i] = new Cubit( this ,createCubitMesh(vertices,x,y,z), new Static3D(x,y,z) ); |
|
115 |
MeshBase cubit = createCubitMesh(vertices); |
|
116 |
textureCubitMesh(cubit,x,y,z); |
|
117 |
|
|
118 |
mCubits[i] = new Cubit( this , cubit, new Static3D(x,y,z) ); |
|
112 | 119 |
attach(mCubits[i].mNode); |
113 | 120 |
} |
114 | 121 |
} |
... | ... | |
139 | 146 |
} |
140 | 147 |
} |
141 | 148 |
|
149 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
150 |
// the getFaceColors + final black in a horizontal strip. |
|
151 |
|
|
152 |
public void createTexture() |
|
153 |
{ |
|
154 |
Bitmap bitmap; |
|
155 |
|
|
156 |
final int numColors = getNumFaces(); |
|
157 |
|
|
158 |
Paint paint = new Paint(); |
|
159 |
bitmap = Bitmap.createBitmap( (numColors+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888); |
|
160 |
Canvas canvas = new Canvas(bitmap); |
|
161 |
|
|
162 |
paint.setAntiAlias(true); |
|
163 |
paint.setTextAlign(Paint.Align.CENTER); |
|
164 |
paint.setStyle(Paint.Style.FILL); |
|
165 |
|
|
166 |
paint.setColor(0xff000000); |
|
167 |
canvas.drawRect(0, 0, (numColors+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, paint); |
|
168 |
|
|
169 |
for(int i=0; i<numColors; i++) |
|
170 |
{ |
|
171 |
createFaceTexture(canvas,paint,i); |
|
172 |
} |
|
173 |
|
|
174 |
mTexture.setTexture(bitmap); |
|
175 |
} |
|
176 |
|
|
142 | 177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
143 | 178 |
|
144 | 179 |
public int getSize() |
... | ... | |
329 | 364 |
abstract int getNumCubits(int size); |
330 | 365 |
abstract int[][] getCubitPositions(int size); |
331 | 366 |
abstract float[] getLegalQuats(); |
332 |
abstract boolean belongsToRotation(Static3D position, Static3D axis, int row); |
|
333 |
abstract MeshBase createCubitMesh(int vertices, int x, int y, int z); |
|
367 |
abstract int getNumFaces(); |
|
368 |
abstract void createFaceTexture(Canvas canvas, Paint paint, int face); |
|
369 |
abstract MeshBase createCubitMesh(int vertices); |
|
334 | 370 |
|
335 |
public abstract void createTexture(); |
|
371 |
abstract boolean belongsToRotation(Static3D position, Static3D axis, int row); |
|
372 |
abstract void textureCubitMesh(MeshBase mesh, int x, int y, int z); |
|
336 | 373 |
} |
Also available in: Unified diff
Make RubikCube more abstract.