1 |
a7012218
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2019 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
fdec60a3
|
Leszek Koltunski
|
// This file is part of Magic Cube. //
|
5 |
a7012218
|
Leszek Koltunski
|
// //
|
6 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
a7012218
|
Leszek Koltunski
|
// 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 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
a7012218
|
Leszek Koltunski
|
// 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 |
fdec60a3
|
Leszek Koltunski
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
a7012218
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.effects.solve;
|
21 |
a7012218
|
Leszek Koltunski
|
|
22 |
584f7954
|
Leszek Koltunski
|
import org.distorted.library.effect.Effect;
|
23 |
ff065f8f
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectRotate;
|
24 |
|
|
import org.distorted.library.type.Dynamic;
|
25 |
|
|
import org.distorted.library.type.Dynamic1D;
|
26 |
|
|
import org.distorted.library.type.Static1D;
|
27 |
584f7954
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
28 |
47ba5ddc
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
29 |
584f7954
|
Leszek Koltunski
|
|
30 |
bee1d997
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31 |
|
|
|
32 |
2ecf0c21
|
Leszek Koltunski
|
public class SolveEffectSpin extends SolveEffect
|
33 |
a7012218
|
Leszek Koltunski
|
{
|
34 |
47ba5ddc
|
Leszek Koltunski
|
private static Static4D quatMultiply( Static4D quat1, Static4D quat2 )
|
35 |
584f7954
|
Leszek Koltunski
|
{
|
36 |
348dfe69
|
Leszek Koltunski
|
float qx = quat1.get0();
|
37 |
|
|
float qy = quat1.get1();
|
38 |
|
|
float qz = quat1.get2();
|
39 |
|
|
float qw = quat1.get3();
|
40 |
584f7954
|
Leszek Koltunski
|
|
41 |
348dfe69
|
Leszek Koltunski
|
float rx = quat2.get0();
|
42 |
|
|
float ry = quat2.get1();
|
43 |
|
|
float rz = quat2.get2();
|
44 |
|
|
float rw = quat2.get3();
|
45 |
ff065f8f
|
Leszek Koltunski
|
|
46 |
47ba5ddc
|
Leszek Koltunski
|
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);
|
52 |
086a24d0
|
Leszek Koltunski
|
}
|
53 |
|
|
|
54 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
47ba5ddc
|
Leszek Koltunski
|
// rotate 'vector' by quat^(-1) ( i.e. return (quat^-1)*vector*quat )
|
56 |
584f7954
|
Leszek Koltunski
|
|
57 |
47ba5ddc
|
Leszek Koltunski
|
private static Static4D rotateVectorByInvertedQuat(Static4D vector, Static4D quat)
|
58 |
|
|
{
|
59 |
348dfe69
|
Leszek Koltunski
|
float qx = quat.get0();
|
60 |
|
|
float qy = quat.get1();
|
61 |
|
|
float qz = quat.get2();
|
62 |
|
|
float qw = quat.get3();
|
63 |
47ba5ddc
|
Leszek Koltunski
|
|
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)
|
73 |
086a24d0
|
Leszek Koltunski
|
{
|
74 |
f61fc32c
|
Leszek Koltunski
|
mCubeEffectPosition[phase] = new int[] {0};
|
75 |
47ba5ddc
|
Leszek Koltunski
|
mCubeEffects[phase] = new Effect[mCubeEffectPosition[0].length];
|
76 |
584f7954
|
Leszek Koltunski
|
|
77 |
27a70eae
|
Leszek Koltunski
|
Static4D quaternion = mObject.getRotationQuat(); // always rotate around
|
78 |
47ba5ddc
|
Leszek Koltunski
|
Static4D tmpAxis = new Static4D(0,1,0,0); // vert axis no matter
|
79 |
|
|
Static4D rotated = rotateVectorByInvertedQuat(tmpAxis,quaternion); // how cube is rotated
|
80 |
|
|
|
81 |
348dfe69
|
Leszek Koltunski
|
Static3D axis = new Static3D(rotated.get0(), rotated.get1(), rotated.get2());
|
82 |
ff065f8f
|
Leszek Koltunski
|
Static3D center= new Static3D(0,0,0);
|
83 |
|
|
|
84 |
47ba5ddc
|
Leszek Koltunski
|
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});
|
111 |
584f7954
|
Leszek Koltunski
|
}
|
112 |
|
|
|
113 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114 |
|
|
// Enable all effects used in this Effect. Called by reflection from the parent class.
|
115 |
|
|
|
116 |
|
|
@SuppressWarnings("unused")
|
117 |
|
|
static void enable()
|
118 |
|
|
{
|
119 |
a7012218
|
Leszek Koltunski
|
|
120 |
584f7954
|
Leszek Koltunski
|
}
|
121 |
a7012218
|
Leszek Koltunski
|
}
|