Revision 98904e45
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/main/RubikRenderer.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
import org.distorted.effects.BaseEffect; |
26 | 26 |
import org.distorted.library.effect.EffectType; |
27 |
import org.distorted.library.effect.VertexEffectQuaternion; |
|
27 | 28 |
import org.distorted.library.effect.VertexEffectRotate; |
28 | 29 |
import org.distorted.library.main.DistortedLibrary; |
29 | 30 |
import org.distorted.library.main.DistortedScreen; |
... | ... | |
80 | 81 |
{ |
81 | 82 |
DistortedLibrary.setMax(EffectType.VERTEX,25); // 24 Cube Quats + Rotate |
82 | 83 |
VertexEffectRotate.enable(); |
84 |
VertexEffectQuaternion.enable(); |
|
83 | 85 |
BaseEffect.Type.enableEffects(); |
84 | 86 |
|
85 | 87 |
try |
src/main/java/org/distorted/objects/Cubit.java | ||
---|---|---|
60 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 61 |
// Because of quatMultiplication, errors can accumulate - so to avoid this, we |
62 | 62 |
// correct the value of the 'scramble' quat to what it should be - one of the legal quats from the |
63 |
// list LEGAL_QUATS.
|
|
63 |
// list QUATS. |
|
64 | 64 |
// |
65 | 65 |
// We also have to remember that the group of unit quaternions is a double-cover of rotations |
66 | 66 |
// in 3D ( q represents the same rotation as -q ) - so invert if needed. |
67 |
/* |
|
68 |
private void normalizeScrambleQuat(Static4D quat) |
|
69 |
{ |
|
70 |
final float MAX_ERROR = 0.0001f; |
|
71 | 67 |
|
68 |
private int normalizeScrambleQuat(Static4D quat) |
|
69 |
{ |
|
72 | 70 |
float x = quat.get0(); |
73 | 71 |
float y = quat.get1(); |
74 | 72 |
float z = quat.get2(); |
75 | 73 |
float w = quat.get3(); |
76 |
float diff; |
|
74 |
float xd,yd,zd,wd; |
|
75 |
float diff, mindiff = Float.MAX_VALUE; |
|
76 |
int ret=0; |
|
77 |
int num_quats = mParent.QUATS.length; |
|
78 |
Static4D qt; |
|
77 | 79 |
|
78 |
for(float legal: mParent.LEGAL_QUATS)
|
|
80 |
for(int q=0; q<num_quats; q++)
|
|
79 | 81 |
{ |
80 |
diff = x-legal; |
|
81 |
if( diff*diff<MAX_ERROR ) x = legal; |
|
82 |
diff = y-legal; |
|
83 |
if( diff*diff<MAX_ERROR ) y = legal; |
|
84 |
diff = z-legal; |
|
85 |
if( diff*diff<MAX_ERROR ) z = legal; |
|
86 |
diff = w-legal; |
|
87 |
if( diff*diff<MAX_ERROR ) w = legal; |
|
88 |
} |
|
82 |
qt = mParent.QUATS[q]; |
|
89 | 83 |
|
90 |
if( w<0 ) |
|
91 |
{ |
|
92 |
w = -w; |
|
93 |
z = -z; |
|
94 |
y = -y; |
|
95 |
x = -x; |
|
96 |
} |
|
97 |
else if( w==0 ) |
|
98 |
{ |
|
99 |
if( z<0 ) |
|
84 |
xd = x - qt.get0(); |
|
85 |
yd = y - qt.get1(); |
|
86 |
zd = z - qt.get2(); |
|
87 |
wd = w - qt.get3(); |
|
88 |
|
|
89 |
diff = xd*xd + yd*yd + zd*zd + wd*wd; |
|
90 |
|
|
91 |
if( diff < mindiff ) |
|
100 | 92 |
{ |
101 |
z = -z; |
|
102 |
y = -y; |
|
103 |
x = -x; |
|
93 |
ret = q; |
|
94 |
mindiff = diff; |
|
104 | 95 |
} |
105 |
else if( z==0 ) |
|
96 |
|
|
97 |
xd = x + qt.get0(); |
|
98 |
yd = y + qt.get1(); |
|
99 |
zd = z + qt.get2(); |
|
100 |
wd = w + qt.get3(); |
|
101 |
|
|
102 |
diff = xd*xd + yd*yd + zd*zd + wd*wd; |
|
103 |
|
|
104 |
if( diff < mindiff ) |
|
106 | 105 |
{ |
107 |
if( y<0 ) |
|
108 |
{ |
|
109 |
y = -y; |
|
110 |
x = -x; |
|
111 |
} |
|
112 |
else if( y==0 ) |
|
113 |
{ |
|
114 |
if( x<0 ) |
|
115 |
{ |
|
116 |
x = -x; |
|
117 |
} |
|
118 |
} |
|
106 |
ret = q; |
|
107 |
mindiff = diff; |
|
119 | 108 |
} |
120 | 109 |
} |
121 | 110 |
|
122 |
quat.set(x,y,z,w);
|
|
111 |
return ret;
|
|
123 | 112 |
} |
124 |
*/ |
|
113 |
|
|
125 | 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
126 | 115 |
|
127 | 116 |
private void modifyCurrentPosition(Static4D quat) |
... | ... | |
281 | 270 |
|
282 | 271 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
283 | 272 |
|
284 |
void removeRotationNow(Static4D quat)
|
|
273 |
int removeRotationNow(Static4D quat)
|
|
285 | 274 |
{ |
286 | 275 |
mQuatScramble.set(RubikSurfaceView.quatMultiply(quat,mQuatScramble)); |
287 |
// normalizeScrambleQuat( mQuatScramble ); |
|
276 |
int index = normalizeScrambleQuat( mQuatScramble ); |
|
277 |
mQuatScramble.set(mParent.QUATS[index]); |
|
278 |
|
|
288 | 279 |
modifyCurrentPosition(quat); |
280 |
|
|
281 |
return index; |
|
289 | 282 |
} |
290 | 283 |
|
291 | 284 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/RubikObject.java | ||
---|---|---|
55 | 55 |
private static final int TEXTURE_HEIGHT = 128; |
56 | 56 |
|
57 | 57 |
final Static3D[] ROTATION_AXIS; |
58 |
final Static4D[] QUATS; |
|
58 | 59 |
final int NUM_FACES; |
59 | 60 |
|
60 | 61 |
static float OBJECT_SCREEN_RATIO; |
... | ... | |
95 | 96 |
mList = list; |
96 | 97 |
mOrigPos = getCubitPositions(size); |
97 | 98 |
|
98 |
Static4D[] quats = getQuats();
|
|
99 |
QUATS = getQuats();
|
|
99 | 100 |
NUM_CUBITS = mOrigPos.length; |
100 | 101 |
ROTATION_AXIS = getRotationAxis(); |
101 | 102 |
OBJECT_SCREEN_RATIO = getScreenRatio(); |
... | ... | |
140 | 141 |
|
141 | 142 |
mEffects = new DistortedEffects(); |
142 | 143 |
|
143 |
int num_quats = quats.length;
|
|
144 |
int num_quats = QUATS.length;
|
|
144 | 145 |
for(int q=0; q<num_quats; q++) |
145 | 146 |
{ |
146 |
VertexEffectQuaternion vq = new VertexEffectQuaternion(quats[q],CENTER);
|
|
147 |
VertexEffectQuaternion vq = new VertexEffectQuaternion(QUATS[q],CENTER);
|
|
147 | 148 |
vq.setMeshAssociation(0,q); |
148 | 149 |
mEffects.apply(vq); |
149 | 150 |
} |
... | ... | |
263 | 264 |
Static4D quat; |
264 | 265 |
int axis, rowBitmap, angle; |
265 | 266 |
int corr = (360/getBasicAngle()); |
267 |
int index; |
|
266 | 268 |
|
267 | 269 |
for(int[] move: moves) |
268 | 270 |
{ |
... | ... | |
274 | 276 |
for(int j=0; j<NUM_CUBITS; j++) |
275 | 277 |
if( belongsToRotation(j,axis,rowBitmap) ) |
276 | 278 |
{ |
277 |
mCubits[j].removeRotationNow(quat); |
|
279 |
index = mCubits[j].removeRotationNow(quat); |
|
280 |
mMesh.setEffectAssociation(j,mCubits[j].computeAssociation(),index); |
|
278 | 281 |
} |
279 | 282 |
} |
280 | 283 |
} |
... | ... | |
412 | 415 |
|
413 | 416 |
public void solve() |
414 | 417 |
{ |
415 |
for(int i=0; i<NUM_CUBITS; i++) mCubits[i].solve(); |
|
418 |
for(int i=0; i<NUM_CUBITS; i++) |
|
419 |
{ |
|
420 |
mCubits[i].solve(); |
|
421 |
mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0); |
|
422 |
} |
|
416 | 423 |
} |
417 | 424 |
|
418 | 425 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
561 | 568 |
for(int i=0; i<NUM_CUBITS; i++) |
562 | 569 |
if( belongsToRotation(i,mRotAxis,mRotRowBitmap) ) |
563 | 570 |
{ |
564 |
mCubits[i].removeRotationNow(quat); |
|
571 |
int index = mCubits[i].removeRotationNow(quat); |
|
572 |
mMesh.setEffectAssociation(i,mCubits[i].computeAssociation(),index); |
|
565 | 573 |
} |
566 | 574 |
} |
567 | 575 |
|
Also available in: Unified diff
More progreess porting RubikCube. Rotation mostly working now.