Revision afd7e804
Added by Leszek Koltunski 12 months ago
src/main/java/org/distorted/bandaged/BandagedCubit.java | ||
---|---|---|
26 | 26 |
import org.distorted.library.type.Static1D; |
27 | 27 |
import org.distorted.library.type.Static3D; |
28 | 28 |
import org.distorted.library.type.Static4D; |
29 |
import org.distorted.objectlib.helpers.FactoryBandagedCubit; |
|
30 | 29 |
import org.distorted.objectlib.helpers.FactoryCubit; |
31 | 30 |
|
32 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_BLUE; |
|
33 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_GREEN; |
|
34 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_ORANGE; |
|
35 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_RED; |
|
36 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_WHITE; |
|
37 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_YELLOW; |
|
38 |
|
|
39 | 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 | 32 |
|
41 | 33 |
public class BandagedCubit |
... | ... | |
46 | 38 |
private static Bitmap mBitmap; |
47 | 39 |
private static Static4D[] mTextureMaps; |
48 | 40 |
|
41 |
private final BandagedObject mObject; |
|
49 | 42 |
private final DistortedNode mNode; |
50 | 43 |
private final DistortedEffects mEffects; |
51 | 44 |
private final DistortedTexture mTexture; |
52 | 45 |
private final Static3D mMove; |
53 | 46 |
private final boolean mRoundCorners; |
54 |
private final int mX, mY, mZ; |
|
55 | 47 |
|
56 | 48 |
private float mUnscaledX, mUnscaledY, mUnscaledZ; |
57 | 49 |
private float[] mPosition; |
... | ... | |
60 | 52 |
|
61 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | 54 |
|
63 |
private static void createBitmap() |
|
55 |
private static void createBitmap(int[] colors)
|
|
64 | 56 |
{ |
65 |
final int[] FACE_COLORS = new int[] |
|
66 |
{ |
|
67 |
COLOR_YELLOW, COLOR_WHITE, |
|
68 |
COLOR_BLUE , COLOR_GREEN, |
|
69 |
COLOR_RED , COLOR_ORANGE |
|
70 |
}; |
|
71 |
final int NUM = FACE_COLORS.length; |
|
57 |
final int NUM = colors.length; |
|
72 | 58 |
final int SIZE= 32; |
73 | 59 |
|
74 | 60 |
mTextureMaps = new Static4D[NUM]; |
... | ... | |
80 | 66 |
|
81 | 67 |
for(int color=0; color<NUM; color++) |
82 | 68 |
{ |
83 |
paint.setColor(FACE_COLORS[color]);
|
|
69 |
paint.setColor(colors[color]);
|
|
84 | 70 |
canvas.drawRect(color*SIZE, 0, (color+1)*SIZE, SIZE, paint); |
85 | 71 |
mTextureMaps[color] = new Static4D( ((float)color)/NUM, 0.0f, 1.0f/NUM, 1.0f ); |
86 | 72 |
} |
87 | 73 |
} |
88 | 74 |
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
// (x,y,z) == |
|
91 |
// |
|
92 |
// ( 1,0,0) --> 0 |
|
93 |
// (-1,0,0) --> 1 |
|
94 |
// (0, 1,0) --> 2 |
|
95 |
// (0,-1,0) --> 3 |
|
96 |
// (0,0, 1) --> 4 |
|
97 |
// (0,0,-1) --> 5 |
|
98 |
|
|
99 |
private int computeMapsIndex(float x, float y, float z) |
|
100 |
{ |
|
101 |
int ix = x>0 ? (int)(x+0.5f) : (int)(x-0.5f); |
|
102 |
int iy = y>0 ? (int)(y+0.5f) : (int)(y-0.5f); |
|
103 |
int iz = z>0 ? (int)(z+0.5f) : (int)(z-0.5f); |
|
104 |
|
|
105 |
if( ix== 1 ) return 0; |
|
106 |
if( ix==-1 ) return 1; |
|
107 |
if( iy== 1 ) return 2; |
|
108 |
if( iy==-1 ) return 3; |
|
109 |
if( iz== 1 ) return 4; |
|
110 |
if( iz==-1 ) return 5; |
|
111 |
|
|
112 |
return 0; |
|
113 |
} |
|
114 |
|
|
115 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
116 | 76 |
|
117 | 77 |
private void resetTextureMaps(MeshBase mesh) |
... | ... | |
124 | 84 |
{ |
125 | 85 |
Static4D q = fact.getQuaternion(i); |
126 | 86 |
QuatHelper.rotateVectorByQuat(mTmp,0,0,1,0,q); |
127 |
int index = computeMapsIndex(mTmp[0], mTmp[1], mTmp[2]);
|
|
87 |
int index = mObject.computeMapsIndex(mTmp);
|
|
128 | 88 |
maps[i] = mTextureMaps[index]; |
129 | 89 |
} |
130 | 90 |
|
... | ... | |
156 | 116 |
// PUBLIC API |
157 | 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
158 | 118 |
|
159 |
public BandagedCubit(float[] position, int x, int y, int z, Static4D quat1,
|
|
119 |
public BandagedCubit(BandagedObject object, float[] position, Static4D quat1,
|
|
160 | 120 |
Static4D quat2, Static3D scale, boolean roundCorners) |
161 | 121 |
{ |
162 |
mX = x; |
|
163 |
mY = y; |
|
164 |
mZ = z; |
|
122 |
mObject = object; |
|
165 | 123 |
mRoundCorners = roundCorners; |
166 | 124 |
mPosition = position; |
167 | 125 |
mIsAttached = true; |
... | ... | |
169 | 127 |
|
170 | 128 |
computeMove(mPosition); |
171 | 129 |
mMove = new Static3D(0,0,0); |
172 |
|
|
173 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
174 |
MeshBase mesh = factory.createMesh(mPosition,mX,mY,mZ,false,mRoundCorners); |
|
130 |
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners); |
|
175 | 131 |
|
176 | 132 |
mTexture = new DistortedTexture(); |
177 |
if( mBitmap==null ) createBitmap(); |
|
133 |
if( mBitmap==null ) createBitmap(mObject.getColors());
|
|
178 | 134 |
mTexture.setTextureAlreadyInverted(mBitmap); |
179 | 135 |
|
180 | 136 |
resetTextureMaps(mesh); |
... | ... | |
207 | 163 |
|
208 | 164 |
computeMove(tmpPosition); |
209 | 165 |
mPosition = tmpPosition; |
210 |
|
|
211 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
212 |
MeshBase mesh = factory.createMesh(mPosition,mX,mY,mZ,false,mRoundCorners); |
|
166 |
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners); |
|
213 | 167 |
resetTextureMaps(mesh); |
214 | 168 |
mNode.setMesh(mesh); |
215 | 169 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
... | ... | |
229 | 183 |
mPosition[2] = z; |
230 | 184 |
|
231 | 185 |
computeMove(mPosition); |
232 |
|
|
233 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
234 |
MeshBase mesh = factory.createMesh(mPosition,mX,mY,mZ,false,mRoundCorners); |
|
186 |
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners); |
|
235 | 187 |
resetTextureMaps(mesh); |
236 | 188 |
mNode.setMesh(mesh); |
237 | 189 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
... | ... | |
241 | 193 |
|
242 | 194 |
public void recreateBitmap() |
243 | 195 |
{ |
244 |
if( mBitmap==null ) createBitmap(); |
|
196 |
if( mBitmap==null ) createBitmap(mObject.getColors());
|
|
245 | 197 |
mTexture.setTextureAlreadyInverted(mBitmap); |
246 | 198 |
} |
247 | 199 |
|
Also available in: Unified diff
Everything about the nature of an object being bandaged should now hopefully be abstracted out in the single class - 'BandagedObject'