Revision 49cd8581
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/objects/FactoryCubit.java | ||
---|---|---|
39 | 39 |
private static final float SQ3 = (float)Math.sqrt(3); |
40 | 40 |
private static final float SQ6 = (float)Math.sqrt(6); |
41 | 41 |
|
42 |
private static final float IVY_D = 0.05f; |
|
43 |
private static final int IVY_N = 8; |
|
44 |
|
|
42 | 45 |
private static final Static1D RADIUS = new Static1D(1); |
43 | 46 |
|
44 | 47 |
private static FactoryCubit mThis; |
... | ... | |
495 | 498 |
return new MeshJoined(meshes); |
496 | 499 |
} |
497 | 500 |
|
501 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
502 |
|
|
503 |
MeshBase createFacesIvyCorner() |
|
504 |
{ |
|
505 |
MeshBase mesh = createFacesSkewbCorner(); |
|
506 |
mesh.addEmptyTexComponent(); |
|
507 |
return mesh; |
|
508 |
} |
|
509 |
|
|
510 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
511 |
|
|
512 |
MeshBase createFacesIvyFace() |
|
513 |
{ |
|
514 |
MeshBase[] meshes = new MeshBase[2]; |
|
515 |
|
|
516 |
final float angle = (float)Math.PI/(2*IVY_N); |
|
517 |
float[] vertices = new float[4*IVY_N]; |
|
518 |
|
|
519 |
for(int i=0; i<IVY_N; i++) |
|
520 |
{ |
|
521 |
float sin = (float)Math.sin(i*angle); |
|
522 |
float cos = (float)Math.cos(i*angle); |
|
523 |
|
|
524 |
vertices[2*i ] = 0.5f-cos; |
|
525 |
vertices[2*i+1 ] = 0.5f-sin; |
|
526 |
vertices[2*i +2*IVY_N] = cos-0.5f; |
|
527 |
vertices[2*i+1+2*IVY_N] = sin-0.5f; |
|
528 |
} |
|
529 |
|
|
530 |
float[] bands0 = computeBands(+0.08f,35,0.5f,0.7f,6); |
|
531 |
float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2); |
|
532 |
|
|
533 |
meshes[0] = new MeshPolygon(vertices,bands0,1,1); |
|
534 |
meshes[0].setEffectAssociation(0,1,0); |
|
535 |
meshes[1] = new MeshPolygon(vertices,bands1,0,0); |
|
536 |
meshes[1].setEffectAssociation(0,2,0); |
|
537 |
|
|
538 |
return new MeshJoined(meshes); |
|
539 |
} |
|
540 |
|
|
498 | 541 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
499 | 542 |
// EFFECTS |
500 | 543 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
896 | 939 |
return effect; |
897 | 940 |
} |
898 | 941 |
|
942 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
943 |
|
|
944 |
VertexEffect[] createVertexEffectsIvyCorner() |
|
945 |
{ |
|
946 |
return createVertexEffectsSkewbCorner(); |
|
947 |
} |
|
948 |
|
|
899 | 949 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
900 | 950 |
// OBJECTS |
901 | 951 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1145 | 1195 |
|
1146 | 1196 |
mesh.mergeEffComponents(); |
1147 | 1197 |
|
1198 |
return mesh; |
|
1199 |
} |
|
1200 |
|
|
1201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1202 |
|
|
1203 |
MeshBase createIvyCornerMesh() |
|
1204 |
{ |
|
1205 |
MeshBase mesh = createFacesIvyCorner(); |
|
1206 |
VertexEffect[] effects = createVertexEffectsIvyCorner(); |
|
1207 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1208 |
|
|
1209 |
Static3D center = new Static3D(-0.5f,-0.5f,-0.5f); |
|
1210 |
Static3D[] vertices = new Static3D[4]; |
|
1211 |
vertices[0] = new Static3D(+0.5f,+0.5f,+0.5f); |
|
1212 |
vertices[1] = new Static3D(-0.5f,+0.5f,+0.5f); |
|
1213 |
vertices[2] = new Static3D(+0.5f,+0.5f,-0.5f); |
|
1214 |
vertices[3] = new Static3D(+0.5f,-0.5f,+0.5f); |
|
1215 |
|
|
1216 |
roundCorners(mesh,center,vertices,0.06f,0.12f); |
|
1217 |
|
|
1218 |
mesh.mergeEffComponents(); |
|
1219 |
|
|
1220 |
return mesh; |
|
1221 |
} |
|
1222 |
|
|
1223 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1224 |
|
|
1225 |
MeshBase createIvyFaceMesh() |
|
1226 |
{ |
|
1227 |
MeshBase mesh = createFacesIvyFace(); |
|
1228 |
|
|
1229 |
Static3D center = new Static3D(0.0f,0.0f,-0.5f); |
|
1230 |
Static3D[] vertices = new Static3D[2]; |
|
1231 |
vertices[0] = new Static3D(+SQ2/2 -IVY_D,-SQ2/2 +IVY_D,+0.0f); |
|
1232 |
vertices[1] = new Static3D(-SQ2/2 +IVY_D,+SQ2/2 -IVY_D,+0.0f); |
|
1233 |
|
|
1234 |
roundCorners(mesh,center,vertices,0.06f,0.12f); |
|
1235 |
|
|
1236 |
mesh.mergeEffComponents(); |
|
1237 |
mesh.addEmptyTexComponent(); |
|
1238 |
mesh.addEmptyTexComponent(); |
|
1239 |
mesh.addEmptyTexComponent(); |
|
1240 |
mesh.addEmptyTexComponent(); |
|
1241 |
mesh.addEmptyTexComponent(); |
|
1242 |
|
|
1148 | 1243 |
return mesh; |
1149 | 1244 |
} |
1150 | 1245 |
} |
src/main/java/org/distorted/objects/FactorySticker.java | ||
---|---|---|
157 | 157 |
} |
158 | 158 |
} |
159 | 159 |
} |
160 |
|
|
161 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
162 |
// TODO |
|
163 |
|
|
164 |
void drawIvyCornerSticker(Canvas canvas, Paint paint, int left, int top, int color, float R) |
|
165 |
{ |
|
166 |
paint.setColor(color); |
|
167 |
paint.setStyle(Paint.Style.FILL); |
|
168 |
|
|
169 |
canvas.drawRect(left,top,left+TEXTURE_HEIGHT,top+TEXTURE_HEIGHT,paint); |
|
170 |
|
|
171 |
} |
|
172 |
|
|
173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
174 |
// TODO |
|
175 |
|
|
176 |
void drawIvyCenterSticker(Canvas canvas, Paint paint, int left, int top, int color, float R) |
|
177 |
{ |
|
178 |
paint.setColor(color); |
|
179 |
paint.setStyle(Paint.Style.FILL); |
|
180 |
|
|
181 |
canvas.drawRect(left,top,left+TEXTURE_HEIGHT,top+TEXTURE_HEIGHT,paint); |
|
182 |
} |
|
160 | 183 |
} |
src/main/java/org/distorted/objects/MovementIvy.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.objects; |
|
21 |
|
|
22 |
import org.distorted.library.type.Static3D; |
|
23 |
|
|
24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 |
|
|
26 |
class MovementIvy extends Movement |
|
27 |
{ |
|
28 |
static final float DIST3D = 0.25f; |
|
29 |
static final float DIST2D = 0.25f; |
|
30 |
|
|
31 |
static final Static3D[] FACE_AXIS = new Static3D[] |
|
32 |
{ |
|
33 |
new Static3D(1,0,0), new Static3D(-1,0,0), |
|
34 |
new Static3D(0,1,0), new Static3D(0,-1,0), |
|
35 |
new Static3D(0,0,1), new Static3D(0,0,-1) |
|
36 |
}; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
MovementIvy() |
|
41 |
{ |
|
42 |
super(TwistyIvy.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D); |
|
43 |
} |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
int computeRowFromOffset(int face, int size, float offset) |
|
48 |
{ |
|
49 |
return offset<DIST2D ? 0:1; |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
public float returnRotationFactor(int size, int row) |
|
55 |
{ |
|
56 |
return 1.0f; |
|
57 |
} |
|
58 |
|
|
59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
// faces 0,1,2,3 --> / |
|
61 |
// faces 4,5 --> \ |
|
62 |
|
|
63 |
private boolean isTopHalf(int face, float[] touchPoint) |
|
64 |
{ |
|
65 |
if( face==4 || face==5 ) return touchPoint[1] >=-touchPoint[0]; |
|
66 |
else return touchPoint[1] >= touchPoint[0]; |
|
67 |
} |
|
68 |
|
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
70 |
|
|
71 |
boolean isInsideFace(int face, float[] p) |
|
72 |
{ |
|
73 |
return ( p[0]<=DIST2D && p[0]>=-DIST2D && p[1]<=DIST2D && p[1]>=-DIST2D ); |
|
74 |
} |
|
75 |
|
|
76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 |
// 0 +++ |
|
78 |
// 1 ++- |
|
79 |
// 2 +-+ |
|
80 |
// 3 +-- |
|
81 |
|
|
82 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
83 |
{ |
|
84 |
enabled[0] = 1; |
|
85 |
|
|
86 |
boolean isTop = isTopHalf(face,touchPoint); |
|
87 |
|
|
88 |
switch(face) |
|
89 |
{ |
|
90 |
case 0: enabled[1] = isTop ? 0:3; break; |
|
91 |
case 1: enabled[1] = isTop ? 2:1; break; |
|
92 |
case 2: enabled[1] = isTop ? 2:0; break; |
|
93 |
case 3: enabled[1] = isTop ? 1:3; break; |
|
94 |
case 4: enabled[1] = isTop ? 0:1; break; |
|
95 |
case 5: enabled[1] = isTop ? 2:3; break; |
|
96 |
} |
|
97 |
} |
|
98 |
} |
src/main/java/org/distorted/objects/ObjectList.java | ||
---|---|---|
111 | 111 |
new MovementSkewb(), |
112 | 112 |
3 |
113 | 113 |
), |
114 |
|
|
115 |
IVY ( |
|
116 |
new int[][] { |
|
117 |
{2 , 8, R.raw.skewb, R.drawable.ui_small_skewb, R.drawable.ui_medium_skewb, R.drawable.ui_big_skewb, R.drawable.ui_huge_skewb} , |
|
118 |
}, |
|
119 |
TwistyIvy.class, |
|
120 |
new MovementIvy(), |
|
121 |
3 |
|
122 |
), |
|
114 | 123 |
; |
115 | 124 |
|
116 | 125 |
public static final int NUM_OBJECTS = values().length; |
... | ... | |
491 | 500 |
case 5: return new TwistyRedi (size, quat, texture, mesh, effects, moves, res, scrWidth); |
492 | 501 |
case 6: return new TwistyHelicopter(size, quat, texture, mesh, effects, moves, res, scrWidth); |
493 | 502 |
case 7: return new TwistySkewb (size, quat, texture, mesh, effects, moves, res, scrWidth); |
503 |
case 8: return new TwistyIvy (size, quat, texture, mesh, effects, moves, res, scrWidth); |
|
494 | 504 |
} |
495 | 505 |
|
496 | 506 |
return null; |
src/main/java/org/distorted/objects/TwistyIvy.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.objects; |
|
21 |
|
|
22 |
import android.content.res.Resources; |
|
23 |
import android.graphics.Canvas; |
|
24 |
import android.graphics.Paint; |
|
25 |
|
|
26 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
|
27 |
import org.distorted.library.main.DistortedEffects; |
|
28 |
import org.distorted.library.main.DistortedTexture; |
|
29 |
import org.distorted.library.mesh.MeshBase; |
|
30 |
import org.distorted.library.mesh.MeshSquare; |
|
31 |
import org.distorted.library.type.Static3D; |
|
32 |
import org.distorted.library.type.Static4D; |
|
33 |
import org.distorted.main.RubikSurfaceView; |
|
34 |
|
|
35 |
import java.util.Random; |
|
36 |
|
|
37 |
import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS; |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
public class TwistyIvy extends TwistyObject |
|
42 |
{ |
|
43 |
private static final int FACES_PER_CUBIT =7; |
|
44 |
|
|
45 |
// the four rotation axis of a RubikIvy. Must be normalized. |
|
46 |
static final Static3D[] ROT_AXIS = new Static3D[] |
|
47 |
{ |
|
48 |
new Static3D(+SQ3/3,+SQ3/3,+SQ3/3), |
|
49 |
new Static3D(+SQ3/3,+SQ3/3,-SQ3/3), |
|
50 |
new Static3D(+SQ3/3,-SQ3/3,+SQ3/3), |
|
51 |
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3) |
|
52 |
}; |
|
53 |
|
|
54 |
private static final int[] FACE_COLORS = new int[] |
|
55 |
{ |
|
56 |
COLOR_YELLOW, COLOR_WHITE, |
|
57 |
COLOR_BLUE , COLOR_GREEN, |
|
58 |
COLOR_RED , COLOR_BROWN |
|
59 |
}; |
|
60 |
|
|
61 |
// All legal rotation quats of a RubikIvy |
|
62 |
private static final Static4D[] QUATS = new Static4D[] |
|
63 |
{ |
|
64 |
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ), |
|
65 |
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ), |
|
66 |
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ), |
|
67 |
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ), |
|
68 |
|
|
69 |
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ), |
|
70 |
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ), |
|
71 |
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f ), |
|
72 |
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f ), |
|
73 |
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ), |
|
74 |
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f ), |
|
75 |
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ), |
|
76 |
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f ) |
|
77 |
}; |
|
78 |
|
|
79 |
private static final int[][] mCornerMap = |
|
80 |
{ |
|
81 |
{ 4, 2, 0, 12,12,12,12 }, |
|
82 |
{ 5, 2, 1, 12,12,12,12 }, |
|
83 |
{ 4, 3, 1, 12,12,12,12 }, |
|
84 |
{ 5, 3, 0, 12,12,12,12 }, |
|
85 |
}; |
|
86 |
|
|
87 |
private static final int[][] mCenterMap = |
|
88 |
{ |
|
89 |
{ 6, 12,12,12,12,12,12 }, |
|
90 |
{ 7, 12,12,12,12,12,12 }, |
|
91 |
{ 8, 12,12,12,12,12,12 }, |
|
92 |
{ 9, 12,12,12,12,12,12 }, |
|
93 |
{ 10, 12,12,12,12,12,12 }, |
|
94 |
{ 11, 12,12,12,12,12,12 }, |
|
95 |
}; |
|
96 |
|
|
97 |
private static MeshBase mCornerMesh, mFaceMesh; |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
TwistyIvy(int size, Static4D quat, DistortedTexture texture, |
|
102 |
MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth) |
|
103 |
{ |
|
104 |
super(size, size, 60, quat, texture, mesh, effects, moves, ObjectList.IVY, res, scrWidth); |
|
105 |
} |
|
106 |
|
|
107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
108 |
|
|
109 |
float getScreenRatio() |
|
110 |
{ |
|
111 |
return 1.0f; |
|
112 |
} |
|
113 |
|
|
114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
115 |
|
|
116 |
Static4D[] getQuats() |
|
117 |
{ |
|
118 |
return QUATS; |
|
119 |
} |
|
120 |
|
|
121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
122 |
|
|
123 |
int getNumFaces() |
|
124 |
{ |
|
125 |
return FACE_COLORS.length; |
|
126 |
} |
|
127 |
|
|
128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
129 |
|
|
130 |
boolean shouldResetTextureMaps() |
|
131 |
{ |
|
132 |
return false; |
|
133 |
} |
|
134 |
|
|
135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
136 |
|
|
137 |
int getNumStickerTypes() |
|
138 |
{ |
|
139 |
return 2; |
|
140 |
} |
|
141 |
|
|
142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
143 |
|
|
144 |
float[] getCuts(int numLayers) |
|
145 |
{ |
|
146 |
float[] cuts = new float[1]; |
|
147 |
cuts[0] = 0.0f; |
|
148 |
|
|
149 |
return cuts; |
|
150 |
} |
|
151 |
|
|
152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
153 |
|
|
154 |
int getNumCubitFaces() |
|
155 |
{ |
|
156 |
return FACES_PER_CUBIT; |
|
157 |
} |
|
158 |
|
|
159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
160 |
|
|
161 |
Static3D[] getCubitPositions(int numLayers) |
|
162 |
{ |
|
163 |
final float DIST_CORNER = (numLayers-1)*0.50f; |
|
164 |
final float DIST_CENTER = (numLayers-1)*0.50f; |
|
165 |
|
|
166 |
final Static3D[] CENTERS = new Static3D[10]; |
|
167 |
|
|
168 |
CENTERS[0] = new Static3D( DIST_CORNER, DIST_CORNER, DIST_CORNER ); |
|
169 |
CENTERS[1] = new Static3D(-DIST_CORNER, DIST_CORNER,-DIST_CORNER ); |
|
170 |
CENTERS[2] = new Static3D(-DIST_CORNER,-DIST_CORNER, DIST_CORNER ); |
|
171 |
CENTERS[3] = new Static3D( DIST_CORNER,-DIST_CORNER,-DIST_CORNER ); |
|
172 |
CENTERS[4] = new Static3D( DIST_CENTER, 0, 0 ); |
|
173 |
CENTERS[5] = new Static3D(-DIST_CENTER, 0, 0 ); |
|
174 |
CENTERS[6] = new Static3D( 0, DIST_CENTER, 0 ); |
|
175 |
CENTERS[7] = new Static3D( 0,-DIST_CENTER, 0 ); |
|
176 |
CENTERS[8] = new Static3D( 0, 0, DIST_CENTER ); |
|
177 |
CENTERS[9] = new Static3D( 0, 0,-DIST_CENTER ); |
|
178 |
|
|
179 |
return CENTERS; |
|
180 |
} |
|
181 |
|
|
182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
183 |
|
|
184 |
private int getQuat(int cubit) |
|
185 |
{ |
|
186 |
switch(cubit) |
|
187 |
{ |
|
188 |
case 0: return 0; |
|
189 |
case 1: return 2; |
|
190 |
case 2: return 3; |
|
191 |
case 3: return 1; |
|
192 |
|
|
193 |
case 4: return 8; |
|
194 |
case 5: return 11; |
|
195 |
case 6: return 10; |
|
196 |
case 7: return 9; |
|
197 |
case 8: return 0; |
|
198 |
case 9: return 2; |
|
199 |
} |
|
200 |
|
|
201 |
return 0; |
|
202 |
} |
|
203 |
|
|
204 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
205 |
|
|
206 |
MeshBase createCubitMesh(int cubit) |
|
207 |
{ |
|
208 |
MeshBase mesh; |
|
209 |
|
|
210 |
if( cubit<4 ) |
|
211 |
{ |
|
212 |
if( mCornerMesh==null ) mCornerMesh = FactoryCubit.getInstance().createIvyCornerMesh(); |
|
213 |
mesh = mCornerMesh.copy(true); |
|
214 |
} |
|
215 |
else |
|
216 |
{ |
|
217 |
if( mFaceMesh==null ) mFaceMesh = FactoryCubit.getInstance().createIvyFaceMesh(); |
|
218 |
mesh = mFaceMesh.copy(true); |
|
219 |
} |
|
220 |
|
|
221 |
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[getQuat(cubit)], new Static3D(0,0,0) ); |
|
222 |
mesh.apply(quat,0xffffffff,0); |
|
223 |
|
|
224 |
return mesh; |
|
225 |
} |
|
226 |
|
|
227 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
228 |
|
|
229 |
int getFaceColor(int cubit, int cubitface, int numLayers) |
|
230 |
{ |
|
231 |
if( cubit<4 ) |
|
232 |
{ |
|
233 |
return mCornerMap[cubit][cubitface]; |
|
234 |
} |
|
235 |
else |
|
236 |
{ |
|
237 |
return mCenterMap[cubit-4][cubitface]; |
|
238 |
} |
|
239 |
} |
|
240 |
|
|
241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
242 |
|
|
243 |
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top) |
|
244 |
{ |
|
245 |
int COLORS = FACE_COLORS.length; |
|
246 |
FactorySticker factory = FactorySticker.getInstance(); |
|
247 |
float R = 0.05f; |
|
248 |
|
|
249 |
if( face<COLORS ) |
|
250 |
{ |
|
251 |
factory.drawIvyCornerSticker(canvas, paint, left, top, FACE_COLORS[face%COLORS], R); |
|
252 |
} |
|
253 |
else |
|
254 |
{ |
|
255 |
factory.drawIvyCenterSticker(canvas, paint, left, top, FACE_COLORS[face%COLORS], R); |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
260 |
|
|
261 |
float returnMultiplier() |
|
262 |
{ |
|
263 |
return 2.0f; |
|
264 |
} |
|
265 |
|
|
266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
267 |
|
|
268 |
float[] getRowChances() |
|
269 |
{ |
|
270 |
float[] chances = new float[2]; |
|
271 |
chances[0] = 0.5f; |
|
272 |
chances[1] = 1.0f; |
|
273 |
|
|
274 |
return chances; |
|
275 |
} |
|
276 |
|
|
277 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
278 |
// PUBLIC API |
|
279 |
|
|
280 |
public Static3D[] getRotationAxis() |
|
281 |
{ |
|
282 |
return ROT_AXIS; |
|
283 |
} |
|
284 |
|
|
285 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
286 |
|
|
287 |
public int getBasicAngle() |
|
288 |
{ |
|
289 |
return 3; |
|
290 |
} |
|
291 |
|
|
292 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
293 |
|
|
294 |
public int randomizeNewRotAxis(Random rnd, int oldRotAxis) |
|
295 |
{ |
|
296 |
int numAxis = ROTATION_AXIS.length; |
|
297 |
|
|
298 |
if( oldRotAxis == START_AXIS ) |
|
299 |
{ |
|
300 |
return rnd.nextInt(numAxis); |
|
301 |
} |
|
302 |
else |
|
303 |
{ |
|
304 |
int newVector = rnd.nextInt(numAxis-1); |
|
305 |
return (newVector>=oldRotAxis ? newVector+1 : newVector); |
|
306 |
} |
|
307 |
} |
|
308 |
|
|
309 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
310 |
|
|
311 |
public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis) |
|
312 |
{ |
|
313 |
float rowFloat = rnd.nextFloat(); |
|
314 |
|
|
315 |
for(int row=0; row<mRowChances.length; row++) |
|
316 |
{ |
|
317 |
if( rowFloat<=mRowChances[row] ) return row; |
|
318 |
} |
|
319 |
|
|
320 |
return 0; |
|
321 |
} |
|
322 |
|
|
323 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
324 |
// remember about the double cover or unit quaternions! |
|
325 |
|
|
326 |
private int mulQuat(int q1, int q2) |
|
327 |
{ |
|
328 |
Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]); |
|
329 |
|
|
330 |
float rX = result.get0(); |
|
331 |
float rY = result.get1(); |
|
332 |
float rZ = result.get2(); |
|
333 |
float rW = result.get3(); |
|
334 |
|
|
335 |
final float MAX_ERROR = 0.1f; |
|
336 |
float dX,dY,dZ,dW; |
|
337 |
|
|
338 |
for(int i=0; i<QUATS.length; i++) |
|
339 |
{ |
|
340 |
dX = QUATS[i].get0() - rX; |
|
341 |
dY = QUATS[i].get1() - rY; |
|
342 |
dZ = QUATS[i].get2() - rZ; |
|
343 |
dW = QUATS[i].get3() - rW; |
|
344 |
|
|
345 |
if( dX<MAX_ERROR && dX>-MAX_ERROR && |
|
346 |
dY<MAX_ERROR && dY>-MAX_ERROR && |
|
347 |
dZ<MAX_ERROR && dZ>-MAX_ERROR && |
|
348 |
dW<MAX_ERROR && dW>-MAX_ERROR ) return i; |
|
349 |
|
|
350 |
dX = QUATS[i].get0() + rX; |
|
351 |
dY = QUATS[i].get1() + rY; |
|
352 |
dZ = QUATS[i].get2() + rZ; |
|
353 |
dW = QUATS[i].get3() + rW; |
|
354 |
|
|
355 |
if( dX<MAX_ERROR && dX>-MAX_ERROR && |
|
356 |
dY<MAX_ERROR && dY>-MAX_ERROR && |
|
357 |
dZ<MAX_ERROR && dZ>-MAX_ERROR && |
|
358 |
dW<MAX_ERROR && dW>-MAX_ERROR ) return i; |
|
359 |
} |
|
360 |
|
|
361 |
return -1; |
|
362 |
} |
|
363 |
|
|
364 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
365 |
// The Ivy is solved if and only if: |
|
366 |
// |
|
367 |
// 1) all 4 of its corner cubits are rotated with the same quat |
|
368 |
// 2) all its face cubits are rotated with the same quat like the corner ones, |
|
369 |
// and optionally they also might be upside down. |
|
370 |
// |
|
371 |
// i.e. |
|
372 |
// cubits [4] and [5] - might be extra QUAT[1] |
|
373 |
// cubits [6] and [7] - might be extra QUAT[2] |
|
374 |
// cubits [8] and [9] - might be extra QUAT[3] |
|
375 |
|
|
376 |
public boolean isSolved() |
|
377 |
{ |
|
378 |
int q1,q = CUBITS[0].mQuatIndex; |
|
379 |
|
|
380 |
if( CUBITS[1].mQuatIndex == q && |
|
381 |
CUBITS[2].mQuatIndex == q && |
|
382 |
CUBITS[3].mQuatIndex == q ) |
|
383 |
{ |
|
384 |
q1 = mulQuat(q,1); |
|
385 |
if( CUBITS[4].mQuatIndex != q && CUBITS[4].mQuatIndex != q1 ) return false; |
|
386 |
if( CUBITS[5].mQuatIndex != q && CUBITS[5].mQuatIndex != q1 ) return false; |
|
387 |
|
|
388 |
q1 = mulQuat(q,2); |
|
389 |
if( CUBITS[6].mQuatIndex != q && CUBITS[6].mQuatIndex != q1 ) return false; |
|
390 |
if( CUBITS[7].mQuatIndex != q && CUBITS[7].mQuatIndex != q1 ) return false; |
|
391 |
|
|
392 |
q1 = mulQuat(q,3); |
|
393 |
if( CUBITS[8].mQuatIndex != q && CUBITS[8].mQuatIndex != q1 ) return false; |
|
394 |
if( CUBITS[9].mQuatIndex != q && CUBITS[9].mQuatIndex != q1 ) return false; |
|
395 |
|
|
396 |
return true; |
|
397 |
} |
|
398 |
|
|
399 |
return false; |
|
400 |
} |
|
401 |
|
|
402 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
403 |
// only needed for solvers - there are no Ivy solvers ATM) |
|
404 |
|
|
405 |
public String retObjectString() |
|
406 |
{ |
|
407 |
return ""; |
|
408 |
} |
|
409 |
} |
src/main/java/org/distorted/objects/TwistyObject.java | ||
---|---|---|
78 | 78 |
private static final float MAX_SIZE_CHANGE = 1.35f; |
79 | 79 |
private static final float MIN_SIZE_CHANGE = 0.8f; |
80 | 80 |
|
81 |
private static boolean mCreateFromDMesh = true;
|
|
81 |
private static boolean mCreateFromDMesh = false;
|
|
82 | 82 |
|
83 | 83 |
private static final Static3D CENTER = new Static3D(0,0,0); |
84 | 84 |
private static final int POST_ROTATION_MILLISEC = 500; |
Also available in: Unified diff
Beginnings of the Ivy Cube.