Revision 47ba5ddc
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/effect/solve/SolveEffectSpin.java | ||
---|---|---|
25 | 25 |
import org.distorted.library.type.Dynamic1D; |
26 | 26 |
import org.distorted.library.type.Static1D; |
27 | 27 |
import org.distorted.library.type.Static3D; |
28 |
import org.distorted.library.type.Static4D; |
|
28 | 29 |
|
29 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
30 | 31 |
|
31 | 32 |
public class SolveEffectSpin extends SolveEffect |
32 | 33 |
{ |
33 |
public void createEffectsPhase0(int duration)
|
|
34 |
private static Static4D quatMultiply( Static4D quat1, Static4D quat2 )
|
|
34 | 35 |
{ |
35 |
mCubeEffectPosition[0] = new int[] {3}; |
|
36 |
mCubeEffects[0] = new Effect[mCubeEffectPosition[0].length]; |
|
36 |
float qx = quat1.get1(); |
|
37 |
float qy = quat1.get2(); |
|
38 |
float qz = quat1.get3(); |
|
39 |
float qw = quat1.get4(); |
|
37 | 40 |
|
38 |
Static3D axis = new Static3D(1,0,0); |
|
39 |
Static3D center= new Static3D(0,0,0); |
|
41 |
float rx = quat2.get1(); |
|
42 |
float ry = quat2.get2(); |
|
43 |
float rz = quat2.get3(); |
|
44 |
float rw = quat2.get4(); |
|
40 | 45 |
|
41 |
Dynamic1D d0 = new Dynamic1D(duration/2, 1.0f); |
|
42 |
d0.setMode(Dynamic.MODE_JUMP); |
|
43 |
d0.setConvexity(0.0f); // otherwise speed of the rotation would be strangely uneven |
|
44 |
d0.add(new Static1D( 0*36)); |
|
45 |
d0.add(new Static1D( 1*36)); |
|
46 |
d0.add(new Static1D( 3*36)); |
|
47 |
d0.add(new Static1D( 6*36)); |
|
48 |
d0.add(new Static1D(10*36)); |
|
49 |
mCubeEffects[0][0] = new MatrixEffectRotate(d0,axis,center); |
|
46 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
47 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
48 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
49 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
50 |
|
|
51 |
return new Static4D(tx,ty,tz,tw); |
|
50 | 52 |
} |
51 | 53 |
|
52 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 |
// rotate 'vector' by quat^(-1) ( i.e. return (quat^-1)*vector*quat ) |
|
53 | 56 |
|
54 |
public void createEffectsPhase1(int duration) |
|
57 |
private static Static4D rotateVectorByInvertedQuat(Static4D vector, Static4D quat) |
|
58 |
{ |
|
59 |
float qx = quat.get1(); |
|
60 |
float qy = quat.get2(); |
|
61 |
float qz = quat.get3(); |
|
62 |
float qw = quat.get4(); |
|
63 |
|
|
64 |
Static4D quatInverted= new Static4D(-qx,-qy,-qz,qw); |
|
65 |
Static4D tmp = quatMultiply(quatInverted,vector); |
|
66 |
|
|
67 |
return quatMultiply(tmp,quat); |
|
68 |
} |
|
69 |
|
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
private void createEffects(int phase, int duration, int[] points) |
|
55 | 73 |
{ |
56 |
mCubeEffectPosition[1] = new int[] {3};
|
|
57 |
mCubeEffects[1] = new Effect[mCubeEffectPosition[1].length];
|
|
74 |
mCubeEffectPosition[phase] = new int[] {3};
|
|
75 |
mCubeEffects[phase] = new Effect[mCubeEffectPosition[0].length];
|
|
58 | 76 |
|
59 |
Static3D axis = new Static3D(1,0,0); |
|
77 |
Static4D quaternion = mCube.getRotationQuat(); // always rotate around |
|
78 |
Static4D tmpAxis = new Static4D(0,1,0,0); // vert axis no matter |
|
79 |
Static4D rotated = rotateVectorByInvertedQuat(tmpAxis,quaternion); // how cube is rotated |
|
80 |
|
|
81 |
Static3D axis = new Static3D(rotated.get1(), rotated.get2(), rotated.get3()); |
|
60 | 82 |
Static3D center= new Static3D(0,0,0); |
61 | 83 |
|
62 |
Dynamic1D d1 = new Dynamic1D(duration/2, 1.0f); |
|
63 |
d1.setMode(Dynamic.MODE_JUMP); |
|
64 |
d1.setConvexity(0.0f); |
|
65 |
d1.add(new Static1D( 0*36)); |
|
66 |
d1.add(new Static1D( 4*36)); |
|
67 |
d1.add(new Static1D( 7*36)); |
|
68 |
d1.add(new Static1D( 9*36)); |
|
69 |
d1.add(new Static1D(10*36)); |
|
70 |
mCubeEffects[1][0] = new MatrixEffectRotate(d1,axis,center); |
|
84 |
Dynamic1D d = new Dynamic1D(duration/2, 1.0f); |
|
85 |
d.setMode(Dynamic.MODE_JUMP); |
|
86 |
d.setConvexity(0.0f); // otherwise speed of the rotation would be strangely uneven |
|
87 |
|
|
88 |
d.add( new Static1D(36*points[0]) ); |
|
89 |
d.add( new Static1D(36*points[1]) ); |
|
90 |
d.add( new Static1D(36*points[2]) ); |
|
91 |
d.add( new Static1D(36*points[3]) ); |
|
92 |
d.add( new Static1D(36*points[4]) ); |
|
93 |
|
|
94 |
mCubeEffects[phase][0] = new MatrixEffectRotate(d,axis,center); |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
// PUBLIC API |
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
public void createEffectsPhase0(int duration) |
|
102 |
{ |
|
103 |
createEffects(0,duration,new int[] {0,1,3,6,10}); |
|
104 |
} |
|
105 |
|
|
106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
107 |
|
|
108 |
public void createEffectsPhase1(int duration) |
|
109 |
{ |
|
110 |
createEffects(1,duration,new int[] {0,4,7,9,10}); |
|
71 | 111 |
} |
72 | 112 |
|
73 | 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
RubikCube: further fixes