Revision 68f6046c
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/objects/CubitFactory.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.objects; |
21 | 21 |
|
22 |
import org.distorted.library.effect.VertexEffect; |
|
22 | 23 |
import org.distorted.library.effect.VertexEffectDeform; |
23 | 24 |
import org.distorted.library.effect.VertexEffectMove; |
24 | 25 |
import org.distorted.library.effect.VertexEffectRotate; |
... | ... | |
37 | 38 |
{ |
38 | 39 |
private static final float SQ2 = (float)Math.sqrt(2); |
39 | 40 |
private static final float SQ3 = (float)Math.sqrt(3); |
41 |
private static final float SQ6 = (float)Math.sqrt(6); |
|
40 | 42 |
|
41 | 43 |
private static CubitFactory mThis; |
42 | 44 |
|
... | ... | |
1063 | 1065 |
|
1064 | 1066 |
mesh.mergeEffComponents(); |
1065 | 1067 |
|
1068 |
return mesh; |
|
1069 |
} |
|
1070 |
|
|
1071 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1072 |
// Redi cube |
|
1073 |
|
|
1074 |
private void roundCorners(MeshBase mesh) |
|
1075 |
{ |
|
1076 |
float cX = 0.0f; |
|
1077 |
float cY = -0.75f; |
|
1078 |
float cZ = -0.75f; |
|
1079 |
|
|
1080 |
float d1=-0.05f; |
|
1081 |
float d2=-0.05f; |
|
1082 |
float r0= 0.20f; |
|
1083 |
float r1= 0.20f; |
|
1084 |
|
|
1085 |
Static3D vert0 = new Static3D( 0.5f, 0.0f, 0.0f); |
|
1086 |
Static3D vert1 = new Static3D(-0.5f, 0.0f, 0.0f); |
|
1087 |
Static3D vert2 = new Static3D( 0.0f, 0.0f,-1.5f); |
|
1088 |
Static3D vert3 = new Static3D( 0.0f,-1.5f, 0.0f); |
|
1089 |
|
|
1090 |
Static3D vec0 = new Static3D( d1*(+0.5f-cX), d1*(+0.0f-cY), d1*(+0.0f-cZ)); |
|
1091 |
Static3D vec1 = new Static3D( d1*(-0.5f-cX), d1*(+0.0f-cY), d1*(+0.0f-cZ)); |
|
1092 |
Static3D vec2 = new Static3D( d2*(+0.0f-cX), d2*(+0.0f-cY), d2*(-1.5f-cZ)); |
|
1093 |
Static3D vec3 = new Static3D( d2*(+0.0f-cX), d2*(-1.5f-cY), d2*(+0.0f-cZ)); |
|
1094 |
|
|
1095 |
Static1D radius = new Static1D(0.5f); |
|
1096 |
Static4D reg0 = new Static4D(0,0,0,r0); |
|
1097 |
Static4D reg1 = new Static4D(0,0,0,r1); |
|
1098 |
|
|
1099 |
VertexEffect effect0= new VertexEffectDeform(vec0,radius,vert0,reg0); |
|
1100 |
VertexEffect effect1= new VertexEffectDeform(vec1,radius,vert1,reg0); |
|
1101 |
VertexEffect effect2= new VertexEffectDeform(vec2,radius,vert2,reg1); |
|
1102 |
VertexEffect effect3= new VertexEffectDeform(vec3,radius,vert3,reg1); |
|
1103 |
|
|
1104 |
mesh.apply(effect0); |
|
1105 |
mesh.apply(effect1); |
|
1106 |
mesh.apply(effect2); |
|
1107 |
mesh.apply(effect3); |
|
1108 |
} |
|
1109 |
|
|
1110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1111 |
|
|
1112 |
MeshBase createRediEdgeMesh() |
|
1113 |
{ |
|
1114 |
final int MESHES=6; |
|
1115 |
|
|
1116 |
float D = 0.02f; |
|
1117 |
float F = 0.25f; |
|
1118 |
|
|
1119 |
float[] bands0 = { 1.0f , 0, |
|
1120 |
1.0f-2*D, D*0.25f, |
|
1121 |
1.0f-4*D, D*0.35f, |
|
1122 |
1.0f-8*D, D*0.6f, |
|
1123 |
0.60f , D*1.0f, |
|
1124 |
0.30f , D*1.375f, |
|
1125 |
0.0f , D*1.4f }; |
|
1126 |
|
|
1127 |
float[] vertices0 = { -F,+F, -F,-F, 0, -2*F, +F,-F, +F,+F }; |
|
1128 |
|
|
1129 |
MeshBase[] meshes = new MeshPolygon[MESHES]; |
|
1130 |
meshes[0] = new MeshPolygon(vertices0, bands0, 2, 2); |
|
1131 |
meshes[0].setEffectAssociation(0,1,0); |
|
1132 |
meshes[1] = meshes[0].copy(true); |
|
1133 |
meshes[1].setEffectAssociation(0,2,0); |
|
1134 |
|
|
1135 |
float[] bands1 = { 1.0f , 0, |
|
1136 |
0.90f , D, |
|
1137 |
0.0f , D }; |
|
1138 |
|
|
1139 |
float[] vertices1 = { -F/2, +F/2, -F/2, -1.5f*F, 1.5f*F, +F/2 }; |
|
1140 |
|
|
1141 |
meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2); |
|
1142 |
meshes[2].setEffectAssociation(0,4,0); |
|
1143 |
meshes[3] = meshes[2].copy(true); |
|
1144 |
meshes[3].setEffectAssociation(0,8,0); |
|
1145 |
|
|
1146 |
float[] bands2 = { 1.0f , 0, |
|
1147 |
0.90f , D, |
|
1148 |
0.0f , D }; |
|
1149 |
|
|
1150 |
float[] vertices2 = { -0.5f*SQ2, SQ6/8, -0.75f*SQ2, -SQ6/8, +0.75f*SQ2, -SQ6/8, +0.5f*SQ2, SQ6/8 }; |
|
1151 |
|
|
1152 |
meshes[4] = new MeshPolygon(vertices2, bands2, 1, 1); |
|
1153 |
meshes[4].setEffectAssociation(0,16,0); |
|
1154 |
meshes[5] = meshes[4].copy(true); |
|
1155 |
meshes[5].setEffectAssociation(0,32,0); |
|
1156 |
|
|
1157 |
MeshBase mesh = new MeshJoined(meshes); |
|
1158 |
|
|
1159 |
Static3D move0 = new Static3D(0.0f, -0.5f, 0.0f); |
|
1160 |
Static3D move1 = new Static3D(0.25f, -0.25f, 0.0f); |
|
1161 |
Static3D move2 = new Static3D(0.5f, 0.0f, 0.0f); |
|
1162 |
Static3D move3 = new Static3D(0.0f, (SQ3-6)/8, (SQ3-6)/8); |
|
1163 |
Static3D flipZ = new Static3D(1,1,-1); |
|
1164 |
Static3D flipX = new Static3D(-1,1,1); |
|
1165 |
Static3D scale = new Static3D(2,2,2); |
|
1166 |
Static3D cent0 = new Static3D(0,0, 0); |
|
1167 |
Static3D cent1 = new Static3D(0,0, -1.5f); |
|
1168 |
Static3D axisX = new Static3D(1,0, 0); |
|
1169 |
Static3D axisY = new Static3D(0,1, 0); |
|
1170 |
Static3D axis = new Static3D(0,SQ2/2,-SQ2/2); |
|
1171 |
Static1D angle1= new Static1D(90); |
|
1172 |
Static1D angle2= new Static1D(45); |
|
1173 |
Static1D angle3= new Static1D( (float)(180/Math.PI*Math.acos(SQ3/3)) ); |
|
1174 |
|
|
1175 |
VertexEffect effect0 = new VertexEffectScale(scale); |
|
1176 |
VertexEffect effect1 = new VertexEffectMove(move0); |
|
1177 |
VertexEffect effect2 = new VertexEffectScale(flipZ); |
|
1178 |
VertexEffect effect3 = new VertexEffectRotate(angle1,axisX,cent0); |
|
1179 |
VertexEffect effect4 = new VertexEffectMove(move1); |
|
1180 |
VertexEffect effect5 = new VertexEffectRotate(angle1,axisY,cent0); |
|
1181 |
VertexEffect effect6 = new VertexEffectMove(move2); |
|
1182 |
VertexEffect effect7 = new VertexEffectScale(flipX); |
|
1183 |
VertexEffect effect8 = new VertexEffectRotate(angle2,axisX,cent0); |
|
1184 |
VertexEffect effect9 = new VertexEffectMove(move3); |
|
1185 |
VertexEffect effect10= new VertexEffectRotate(angle3,axis ,cent1); |
|
1186 |
VertexEffect effect11= new VertexEffectScale(flipX); |
|
1187 |
|
|
1188 |
effect0.setMeshAssociation(15,-1); // meshes 0,1,2,3 |
|
1189 |
effect1.setMeshAssociation( 3,-1); // meshes 0,1 |
|
1190 |
effect2.setMeshAssociation( 2,-1); // mesh 1 |
|
1191 |
effect3.setMeshAssociation( 2,-1); // mesh 1 |
|
1192 |
effect4.setMeshAssociation(12,-1); // meshes 2,3 |
|
1193 |
effect5.setMeshAssociation(60,-1); // meshes 2,3,4,5 |
|
1194 |
effect6.setMeshAssociation(12,-1); // meshes 2,3 |
|
1195 |
effect7.setMeshAssociation( 8,-1); // mesh 3 |
|
1196 |
effect8.setMeshAssociation(48,-1); // meshes 4,5 |
|
1197 |
effect9.setMeshAssociation(48,-1); // meshes 4,5 |
|
1198 |
effect10.setMeshAssociation(48,-1); // meshes 4,5 |
|
1199 |
effect11.setMeshAssociation(32,-1); // mesh 5 |
|
1200 |
|
|
1201 |
mesh.apply(effect0); |
|
1202 |
mesh.apply(effect1); |
|
1203 |
mesh.apply(effect2); |
|
1204 |
mesh.apply(effect3); |
|
1205 |
mesh.apply(effect4); |
|
1206 |
mesh.apply(effect5); |
|
1207 |
mesh.apply(effect6); |
|
1208 |
mesh.apply(effect7); |
|
1209 |
mesh.apply(effect8); |
|
1210 |
mesh.apply(effect9); |
|
1211 |
mesh.apply(effect10); |
|
1212 |
mesh.apply(effect11); |
|
1213 |
|
|
1214 |
roundCorners(mesh); |
|
1215 |
|
|
1216 |
mesh.mergeEffComponents(); |
|
1217 |
|
|
1066 | 1218 |
return mesh; |
1067 | 1219 |
} |
1068 | 1220 |
} |
src/main/java/org/distorted/objects/MovementRedi.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 MovementRedi 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 |
MovementRedi() |
|
41 |
{ |
|
42 |
super(TwistyRedi.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 |
// _____________ |
|
61 |
// | \ 0 / | |
|
62 |
// | \ / | |
|
63 |
// | 3 | | 1 | |
|
64 |
// | / \ | |
|
65 |
// | / 2 \ | |
|
66 |
// ------------- |
|
67 |
|
|
68 |
private int getQuarter(float[] touchPoint) |
|
69 |
{ |
|
70 |
boolean p0 = touchPoint[1] >= touchPoint[0]; |
|
71 |
boolean p1 = touchPoint[1] >=-touchPoint[0]; |
|
72 |
|
|
73 |
if( p0 ) return p1 ? 0:3; |
|
74 |
else return p1 ? 1:2; |
|
75 |
} |
|
76 |
|
|
77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
|
|
79 |
boolean isInsideFace(int face, float[] p) |
|
80 |
{ |
|
81 |
return ( p[0]<=DIST2D && p[0]>=-DIST2D && p[1]<=DIST2D && p[1]>=-DIST2D ); |
|
82 |
} |
|
83 |
|
|
84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 |
|
|
86 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
87 |
{ |
|
88 |
enabled[0] = 2; |
|
89 |
|
|
90 |
int quarter = getQuarter(touchPoint); |
|
91 |
|
|
92 |
switch(face) |
|
93 |
{ |
|
94 |
case 0: switch(quarter) |
|
95 |
{ |
|
96 |
case 0: enabled[1]=0; enabled[2]=1; break; |
|
97 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
98 |
case 2: enabled[1]=2; enabled[2]=3; break; |
|
99 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
100 |
} |
|
101 |
break; |
|
102 |
case 1: switch(quarter) |
|
103 |
{ |
|
104 |
case 0: enabled[1]=2; enabled[2]=3; break; |
|
105 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
106 |
case 2: enabled[1]=0; enabled[2]=1; break; |
|
107 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
108 |
} |
|
109 |
break; |
|
110 |
case 2: switch(quarter) |
|
111 |
{ |
|
112 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
113 |
case 1: enabled[1]=0; enabled[2]=1; break; |
|
114 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
115 |
case 3: enabled[1]=2; enabled[2]=3; break; |
|
116 |
} |
|
117 |
break; |
|
118 |
case 3: switch(quarter) |
|
119 |
{ |
|
120 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
121 |
case 1: enabled[1]=2; enabled[2]=3; break; |
|
122 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
123 |
case 3: enabled[1]=0; enabled[2]=1; break; |
|
124 |
} |
|
125 |
break; |
|
126 |
case 4: switch(quarter) |
|
127 |
{ |
|
128 |
case 0: enabled[1]=0; enabled[2]=3; break; |
|
129 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
130 |
case 2: enabled[1]=1; enabled[2]=2; break; |
|
131 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
132 |
} |
|
133 |
break; |
|
134 |
case 5: switch(quarter) |
|
135 |
{ |
|
136 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
137 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
138 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
139 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
140 |
} |
|
141 |
break; |
|
142 |
} |
|
143 |
} |
|
144 |
} |
src/main/java/org/distorted/objects/ObjectList.java | ||
---|---|---|
101 | 101 |
new MovementHelicopter(), |
102 | 102 |
2 |
103 | 103 |
), |
104 |
|
|
105 |
REDI ( |
|
106 |
new int[][] { |
|
107 |
{3 , 11, R.raw.heli, R.drawable.ui_small_heli, R.drawable.ui_medium_heli, R.drawable.ui_big_heli, R.drawable.ui_huge_heli} , |
|
108 |
}, |
|
109 |
TwistyRedi.class, |
|
110 |
new MovementRedi(), |
|
111 |
3 |
|
112 |
), |
|
104 | 113 |
; |
105 | 114 |
|
106 | 115 |
public static final int NUM_OBJECTS = values().length; |
... | ... | |
480 | 489 |
case 4: return new TwistyDino4 (size, quat, texture, mesh, effects, moves, res, scrWidth); |
481 | 490 |
case 5: return new TwistySkewb (size, quat, texture, mesh, effects, moves, res, scrWidth); |
482 | 491 |
case 6: return new TwistyHelicopter(size, quat, texture, mesh, effects, moves, res, scrWidth); |
492 |
case 7: return new TwistyRedi (size, quat, texture, mesh, effects, moves, res, scrWidth); |
|
483 | 493 |
} |
484 | 494 |
|
485 | 495 |
return null; |
src/main/java/org/distorted/objects/TwistyObject.java | ||
---|---|---|
69 | 69 |
private static final float MAX_SIZE_CHANGE = 1.35f; |
70 | 70 |
private static final float MIN_SIZE_CHANGE = 0.8f; |
71 | 71 |
|
72 |
private static boolean mCreateFromDMesh = true;
|
|
72 |
private static boolean mCreateFromDMesh = false;
|
|
73 | 73 |
|
74 | 74 |
private static final Static3D CENTER = new Static3D(0,0,0); |
75 | 75 |
private static final int POST_ROTATION_MILLISEC = 500; |
src/main/java/org/distorted/objects/TwistyRedi.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 TwistyRedi extends TwistyObject |
|
42 |
{ |
|
43 |
private static final float SQ2 = (float)Math.sqrt(2); |
|
44 |
private static final float SQ3 = (float)Math.sqrt(3); |
|
45 |
|
|
46 |
private static final int FACES_PER_CUBIT =6; |
|
47 |
|
|
48 |
// the four rotation axis of a RubikRedi. Must be normalized. |
|
49 |
static final Static3D[] ROT_AXIS = new Static3D[] |
|
50 |
{ |
|
51 |
new Static3D(+SQ3/3,+SQ3/3,+SQ3/3), |
|
52 |
new Static3D(+SQ3/3,+SQ3/3,-SQ3/3), |
|
53 |
new Static3D(+SQ3/3,-SQ3/3,+SQ3/3), |
|
54 |
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3) |
|
55 |
}; |
|
56 |
|
|
57 |
private static final int[] FACE_COLORS = new int[] |
|
58 |
{ |
|
59 |
COLOR_YELLOW, COLOR_WHITE, |
|
60 |
COLOR_BLUE , COLOR_GREEN, |
|
61 |
COLOR_RED , COLOR_BROWN |
|
62 |
}; |
|
63 |
|
|
64 |
// All legal rotation quats of a RubikRedi |
|
65 |
private static final Static4D[] QUATS = new Static4D[] |
|
66 |
{ |
|
67 |
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ), |
|
68 |
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ), |
|
69 |
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ), |
|
70 |
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ), |
|
71 |
|
|
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 |
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f ), |
|
78 |
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ), |
|
79 |
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f ) |
|
80 |
}; |
|
81 |
|
|
82 |
private static final float DIST_CORNER = 1.0f; |
|
83 |
private static final float DIST_EDGE = 1.5f; |
|
84 |
|
|
85 |
// centers of the 8 corners + 12 edges ( i.e. of the all 20 cubits) |
|
86 |
private static final Static3D[] CENTERS = new Static3D[] |
|
87 |
{ |
|
88 |
new Static3D( DIST_CORNER, DIST_CORNER, DIST_CORNER ), |
|
89 |
new Static3D( DIST_CORNER, DIST_CORNER,-DIST_CORNER ), |
|
90 |
new Static3D( DIST_CORNER,-DIST_CORNER, DIST_CORNER ), |
|
91 |
new Static3D( DIST_CORNER,-DIST_CORNER,-DIST_CORNER ), |
|
92 |
new Static3D(-DIST_CORNER, DIST_CORNER, DIST_CORNER ), |
|
93 |
new Static3D(-DIST_CORNER, DIST_CORNER,-DIST_CORNER ), |
|
94 |
new Static3D(-DIST_CORNER,-DIST_CORNER, DIST_CORNER ), |
|
95 |
new Static3D(-DIST_CORNER,-DIST_CORNER,-DIST_CORNER ), |
|
96 |
|
|
97 |
new Static3D( 0.0f, DIST_EDGE, DIST_EDGE ), |
|
98 |
new Static3D( DIST_EDGE, 0.0f, DIST_EDGE ), |
|
99 |
new Static3D( 0.0f,-DIST_EDGE, DIST_EDGE ), |
|
100 |
new Static3D(-DIST_EDGE, 0.0f, DIST_EDGE ), |
|
101 |
new Static3D( DIST_EDGE, DIST_EDGE, 0.0f ), |
|
102 |
new Static3D( DIST_EDGE,-DIST_EDGE, 0.0f ), |
|
103 |
new Static3D(-DIST_EDGE,-DIST_EDGE, 0.0f ), |
|
104 |
new Static3D(-DIST_EDGE, DIST_EDGE, 0.0f ), |
|
105 |
new Static3D( 0.0f, DIST_EDGE,-DIST_EDGE ), |
|
106 |
new Static3D( DIST_EDGE, 0.0f,-DIST_EDGE ), |
|
107 |
new Static3D( 0.0f,-DIST_EDGE,-DIST_EDGE ), |
|
108 |
new Static3D(-DIST_EDGE, 0.0f,-DIST_EDGE ) |
|
109 |
}; |
|
110 |
|
|
111 |
// Colors of the faces of cubits. |
|
112 |
// YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 BROWN 5 |
|
113 |
// YELLOW 6 WHITE 7 BLUE 8 GREEN 9 RED 10 BROWN 11 |
|
114 |
private static final int[][] mFaceMap = new int[][] |
|
115 |
{ |
|
116 |
{ 0,12, 2,12, 4,12 }, |
|
117 |
{ 0,12, 5,12, 2,12 }, |
|
118 |
{ 0,12, 4,12, 3,12 }, |
|
119 |
{ 0,12, 3,12, 5,12 }, |
|
120 |
{ 4,12, 2,12, 1,12 }, |
|
121 |
{ 1,12, 2,12, 5,12 }, |
|
122 |
{ 1,12, 3,12, 4,12 }, |
|
123 |
{ 5,12, 3,12, 1,12 }, |
|
124 |
|
|
125 |
{ 10, 8,12,12,12,12 }, |
|
126 |
{ 6,10,12,12,12,12 }, |
|
127 |
{ 10, 9,12,12,12,12 }, |
|
128 |
{ 7,10,12,12,12,12 }, |
|
129 |
{ 8, 6,12,12,12,12 }, |
|
130 |
{ 9, 6,12,12,12,12 }, |
|
131 |
{ 9, 7,12,12,12,12 }, |
|
132 |
{ 8, 7,12,12,12,12 }, |
|
133 |
{ 11, 8,12,12,12,12 }, |
|
134 |
{ 6,11,12,12,12,12 }, |
|
135 |
{ 11, 9,12,12,12,12 }, |
|
136 |
{ 7,11,12,12,12,12 }, |
|
137 |
}; |
|
138 |
|
|
139 |
private static MeshBase mCornerMesh, mEdgeMesh; |
|
140 |
|
|
141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
142 |
|
|
143 |
TwistyRedi(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh, |
|
144 |
DistortedEffects effects, int[][] moves, Resources res, int scrWidth) |
|
145 |
{ |
|
146 |
super(size, 60, quat, texture, mesh, effects, moves, ObjectList.REDI, res, scrWidth); |
|
147 |
} |
|
148 |
|
|
149 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
150 |
|
|
151 |
float getScreenRatio() |
|
152 |
{ |
|
153 |
return 0.50f; |
|
154 |
} |
|
155 |
|
|
156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
157 |
|
|
158 |
Static4D[] getQuats() |
|
159 |
{ |
|
160 |
return QUATS; |
|
161 |
} |
|
162 |
|
|
163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
164 |
|
|
165 |
int getNumFaces() |
|
166 |
{ |
|
167 |
return FACE_COLORS.length; |
|
168 |
} |
|
169 |
|
|
170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
171 |
|
|
172 |
boolean shouldResetTextureMaps() |
|
173 |
{ |
|
174 |
return false; |
|
175 |
} |
|
176 |
|
|
177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
178 |
|
|
179 |
int getNumStickerTypes() |
|
180 |
{ |
|
181 |
return 2; |
|
182 |
} |
|
183 |
|
|
184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
185 |
|
|
186 |
float getBasicStep() |
|
187 |
{ |
|
188 |
return SQ3; |
|
189 |
} |
|
190 |
|
|
191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
192 |
|
|
193 |
int getNumCubitFaces() |
|
194 |
{ |
|
195 |
return FACES_PER_CUBIT; |
|
196 |
} |
|
197 |
|
|
198 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
199 |
|
|
200 |
Static3D[] getCubitPositions(int size) |
|
201 |
{ |
|
202 |
return CENTERS; |
|
203 |
} |
|
204 |
|
|
205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
206 |
|
|
207 |
private Static4D getQuat(int cubit) |
|
208 |
{ |
|
209 |
switch(cubit) |
|
210 |
{ |
|
211 |
case 0: return QUATS[0]; // unit quat |
|
212 |
case 1: return new Static4D( SQ2/2,0,0,SQ2/2); // 90 along X |
|
213 |
case 2: return new Static4D(-SQ2/2,0,0,SQ2/2); // -90 along X |
|
214 |
case 3: return QUATS[1]; // 180 along X |
|
215 |
case 4: return new Static4D(0, SQ2/2,0,SQ2/2); // 90 along Y |
|
216 |
case 5: return QUATS[2]; // 180 along Y |
|
217 |
case 6: return QUATS[3]; // 180 along Z |
|
218 |
case 7: return new Static4D(SQ2/2,0,-SQ2/2,0); // 180 along (SQ2/2,0,-SQ2/2) |
|
219 |
|
|
220 |
case 8: return QUATS[0]; |
|
221 |
case 9: return QUATS[5]; |
|
222 |
case 10: return QUATS[3]; |
|
223 |
case 11: return QUATS[11]; |
|
224 |
case 12: return QUATS[4]; |
|
225 |
case 13: return QUATS[7]; |
|
226 |
case 14: return QUATS[9]; |
|
227 |
case 15: return QUATS[10]; |
|
228 |
case 16: return QUATS[2]; |
|
229 |
case 17: return QUATS[8]; |
|
230 |
case 18: return QUATS[1]; |
|
231 |
case 19: return QUATS[6]; |
|
232 |
} |
|
233 |
|
|
234 |
return null; |
|
235 |
} |
|
236 |
|
|
237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
238 |
|
|
239 |
MeshBase createCubitMesh(int cubit) |
|
240 |
{ |
|
241 |
MeshBase mesh; |
|
242 |
|
|
243 |
if( cubit<8 ) |
|
244 |
{ |
|
245 |
if( mCornerMesh==null ) mCornerMesh = CubitFactory.getInstance().createCubeMesh(0); |
|
246 |
mesh = mCornerMesh.copy(true); |
|
247 |
} |
|
248 |
else |
|
249 |
{ |
|
250 |
if( mEdgeMesh==null ) mEdgeMesh = CubitFactory.getInstance().createRediEdgeMesh(); |
|
251 |
mesh = mEdgeMesh.copy(true); |
|
252 |
} |
|
253 |
|
|
254 |
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) ); |
|
255 |
mesh.apply(quat,0xffffffff,0); |
|
256 |
|
|
257 |
return mesh; |
|
258 |
} |
|
259 |
|
|
260 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
261 |
|
|
262 |
int getFaceColor(int cubit, int cubitface, int size) |
|
263 |
{ |
|
264 |
return mFaceMap[cubit][cubitface]; |
|
265 |
} |
|
266 |
|
|
267 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
268 |
|
|
269 |
void createFaceTexture(Canvas canvas, Paint paint, int face, int left) |
|
270 |
{ |
|
271 |
int COLORS = FACE_COLORS.length; |
|
272 |
|
|
273 |
if( face<COLORS ) |
|
274 |
{ |
|
275 |
float F = 0.5f; |
|
276 |
float R = 0.10f; |
|
277 |
float S = 0.10f; |
|
278 |
float[] vertices = { -F,-F, +F,-F, +F,+F, -F,+F}; |
|
279 |
|
|
280 |
drawRoundedPolygon(canvas, paint, left, vertices, S, FACE_COLORS[face], R); |
|
281 |
} |
|
282 |
else |
|
283 |
{ |
|
284 |
float F = 0.25f; |
|
285 |
float R = 0.05f; |
|
286 |
float S = 0.05f; |
|
287 |
float[] vertices = { -F,+F, -F,-F, 0, -2*F, +F,-F, +F,+F }; |
|
288 |
|
|
289 |
drawRoundedPolygon(canvas, paint, left, vertices, S, FACE_COLORS[face-COLORS], R); |
|
290 |
} |
|
291 |
} |
|
292 |
|
|
293 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
294 |
|
|
295 |
float returnMultiplier() |
|
296 |
{ |
|
297 |
return 2.0f; |
|
298 |
} |
|
299 |
|
|
300 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
301 |
|
|
302 |
float[] getRowChances() |
|
303 |
{ |
|
304 |
float[] chances = new float[3]; |
|
305 |
|
|
306 |
chances[0] = 0.5f; |
|
307 |
chances[1] = 0.5f; |
|
308 |
chances[2] = 1.0f; |
|
309 |
|
|
310 |
return chances; |
|
311 |
} |
|
312 |
|
|
313 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
314 |
// PUBLIC API |
|
315 |
|
|
316 |
public Static3D[] getRotationAxis() |
|
317 |
{ |
|
318 |
return ROT_AXIS; |
|
319 |
} |
|
320 |
|
|
321 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
322 |
|
|
323 |
public int getBasicAngle() |
|
324 |
{ |
|
325 |
return 3; |
|
326 |
} |
|
327 |
|
|
328 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
329 |
|
|
330 |
public int randomizeNewRotAxis(Random rnd, int oldRotAxis) |
|
331 |
{ |
|
332 |
int numAxis = ROTATION_AXIS.length; |
|
333 |
|
|
334 |
if( oldRotAxis == START_AXIS ) |
|
335 |
{ |
|
336 |
return rnd.nextInt(numAxis); |
|
337 |
} |
|
338 |
else |
|
339 |
{ |
|
340 |
int newVector = rnd.nextInt(numAxis-1); |
|
341 |
return (newVector>=oldRotAxis ? newVector+1 : newVector); |
|
342 |
} |
|
343 |
} |
|
344 |
|
|
345 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
346 |
|
|
347 |
public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis) |
|
348 |
{ |
|
349 |
return (oldRotAxis==START_AXIS) ? (rnd.nextFloat()<=0.5f ? 0:2) : (oldRotAxis+newRotAxis==3 ? 2-oldRow : oldRow); |
|
350 |
} |
|
351 |
|
|
352 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
353 |
// remember about the double cover or unit quaternions! |
|
354 |
|
|
355 |
private int mulQuat(int q1, int q2) |
|
356 |
{ |
|
357 |
Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]); |
|
358 |
|
|
359 |
float rX = result.get0(); |
|
360 |
float rY = result.get1(); |
|
361 |
float rZ = result.get2(); |
|
362 |
float rW = result.get3(); |
|
363 |
|
|
364 |
final float MAX_ERROR = 0.1f; |
|
365 |
float dX,dY,dZ,dW; |
|
366 |
|
|
367 |
for(int i=0; i<QUATS.length; i++) |
|
368 |
{ |
|
369 |
dX = QUATS[i].get0() - rX; |
|
370 |
dY = QUATS[i].get1() - rY; |
|
371 |
dZ = QUATS[i].get2() - rZ; |
|
372 |
dW = QUATS[i].get3() - rW; |
|
373 |
|
|
374 |
if( dX<MAX_ERROR && dX>-MAX_ERROR && |
|
375 |
dY<MAX_ERROR && dY>-MAX_ERROR && |
|
376 |
dZ<MAX_ERROR && dZ>-MAX_ERROR && |
|
377 |
dW<MAX_ERROR && dW>-MAX_ERROR ) return i; |
|
378 |
|
|
379 |
dX = QUATS[i].get0() + rX; |
|
380 |
dY = QUATS[i].get1() + rY; |
|
381 |
dZ = QUATS[i].get2() + rZ; |
|
382 |
dW = QUATS[i].get3() + rW; |
|
383 |
|
|
384 |
if( dX<MAX_ERROR && dX>-MAX_ERROR && |
|
385 |
dY<MAX_ERROR && dY>-MAX_ERROR && |
|
386 |
dZ<MAX_ERROR && dZ>-MAX_ERROR && |
|
387 |
dW<MAX_ERROR && dW>-MAX_ERROR ) return i; |
|
388 |
} |
|
389 |
|
|
390 |
return -1; |
|
391 |
} |
|
392 |
|
|
393 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
394 |
// The Redi is solved if and only if: |
|
395 |
// |
|
396 |
// ?? |
|
397 |
|
|
398 |
public boolean isSolved() |
|
399 |
{ |
|
400 |
int q = CUBITS[0].mQuatIndex; |
|
401 |
|
|
402 |
if ( CUBITS[1].mQuatIndex == q && |
|
403 |
CUBITS[2].mQuatIndex == q && |
|
404 |
CUBITS[3].mQuatIndex == q && |
|
405 |
CUBITS[4].mQuatIndex == q && |
|
406 |
CUBITS[5].mQuatIndex == q && |
|
407 |
CUBITS[6].mQuatIndex == q && |
|
408 |
CUBITS[7].mQuatIndex == q ) |
|
409 |
{ |
|
410 |
|
|
411 |
return true; |
|
412 |
} |
|
413 |
|
|
414 |
return false; |
|
415 |
} |
|
416 |
|
|
417 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
418 |
// only needed for solvers - there are no Redi solvers ATM) |
|
419 |
|
|
420 |
public String retObjectString() |
|
421 |
{ |
|
422 |
return ""; |
|
423 |
} |
|
424 |
} |
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
613 | 613 |
|
614 | 614 |
mPlayLayout.removeAllViews(); |
615 | 615 |
|
616 |
int realSize= ObjectList.getSizeIndex(mObject,mSize); |
|
617 | 616 |
RubikScores scores = RubikScores.getInstance(); |
618 | 617 |
|
619 | 618 |
for(int i=0; i<maxLevel; i++) |
... | ... | |
624 | 623 |
button.setText(levels[i]); |
625 | 624 |
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize); |
626 | 625 |
|
627 |
int icon = scores.isSolved(mObject, realSize, i) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
|
626 |
int icon = scores.isSolved(mObject, sizeIndex, i) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
|
628 | 627 |
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0); |
629 | 628 |
|
630 | 629 |
button.setOnClickListener( new View.OnClickListener() |
Also available in: Unified diff
Add the Redi Cube: part1.