1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 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.objectlib.effects.solve;
|
21
|
|
22
|
import org.distorted.library.effect.Effect;
|
23
|
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
|
import org.distorted.library.type.Static3D;
|
28
|
import org.distorted.library.type.Static4D;
|
29
|
|
30
|
import static org.distorted.library.main.QuatHelper.rotateVectorByInvertedQuat;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
public class SolveEffectSpin extends SolveEffect
|
35
|
{
|
36
|
private void createEffects(int phase, int duration, int[] points)
|
37
|
{
|
38
|
mCubeEffectPosition[phase] = new int[] {0};
|
39
|
mCubeEffects[phase] = new Effect[mCubeEffectPosition[0].length];
|
40
|
|
41
|
Static4D quaternion = mObject.getRotationQuat(); // always rotate around
|
42
|
Static4D tmpAxis = new Static4D(0,1,0,0); // vert axis no matter
|
43
|
Static4D rotated = rotateVectorByInvertedQuat(tmpAxis,quaternion); // how cube is rotated
|
44
|
|
45
|
Static3D axis = new Static3D(rotated.get0(), rotated.get1(), rotated.get2());
|
46
|
Static3D center= new Static3D(0,0,0);
|
47
|
|
48
|
Dynamic1D d = new Dynamic1D(duration/2, 1.0f);
|
49
|
d.setMode(Dynamic.MODE_JUMP);
|
50
|
d.setConvexity(0.0f); // otherwise speed of the rotation would be strangely uneven
|
51
|
|
52
|
d.add( new Static1D(36*points[0]) );
|
53
|
d.add( new Static1D(36*points[1]) );
|
54
|
d.add( new Static1D(36*points[2]) );
|
55
|
d.add( new Static1D(36*points[3]) );
|
56
|
d.add( new Static1D(36*points[4]) );
|
57
|
|
58
|
mCubeEffects[phase][0] = new MatrixEffectRotate(d,axis,center);
|
59
|
}
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
// PUBLIC API
|
63
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64
|
|
65
|
public void createEffectsPhase0(int duration)
|
66
|
{
|
67
|
createEffects(0,duration,new int[] {0,1,3,6,10});
|
68
|
}
|
69
|
|
70
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71
|
|
72
|
public void createEffectsPhase1(int duration)
|
73
|
{
|
74
|
createEffects(1,duration,new int[] {0,4,7,9,10});
|
75
|
}
|
76
|
|
77
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78
|
// Enable all effects used in this Effect. Called by reflection from the parent class.
|
79
|
|
80
|
@SuppressWarnings("unused")
|
81
|
static void enable()
|
82
|
{
|
83
|
|
84
|
}
|
85
|
}
|