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.scramble;
|
21
|
|
22
|
import java.util.Random;
|
23
|
|
24
|
import org.distorted.library.effect.Effect;
|
25
|
import org.distorted.library.effect.MatrixEffectMove;
|
26
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
27
|
import org.distorted.library.type.Dynamic;
|
28
|
import org.distorted.library.type.Dynamic3D;
|
29
|
import org.distorted.library.type.DynamicQuat;
|
30
|
import org.distorted.library.type.Static3D;
|
31
|
import org.distorted.library.type.Static4D;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class ScrambleEffectRotations extends ScrambleEffect
|
36
|
{
|
37
|
private final Random mRndGen = new Random(0);
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
private Static4D generateNewRandomPoint()
|
42
|
{
|
43
|
float x = mRndGen.nextFloat();
|
44
|
float y = mRndGen.nextFloat();
|
45
|
float z = mRndGen.nextFloat();
|
46
|
float w = mRndGen.nextFloat();
|
47
|
|
48
|
float len = (float)Math.sqrt(x*x + y*y + z*z + w*w);
|
49
|
|
50
|
return new Static4D( x/len, y/len, z/len, w/len);
|
51
|
}
|
52
|
|
53
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54
|
|
55
|
public void createEffects(int duration, int numScrambles)
|
56
|
{
|
57
|
mCubeEffectNumber = 2;
|
58
|
mNodeEffectNumber = 0;
|
59
|
mCubeEffectPosition = new int[] {2,3};
|
60
|
mCubeEffects = new Effect[mCubeEffectPosition.length];
|
61
|
|
62
|
mRndGen.setSeed(System.currentTimeMillis());
|
63
|
|
64
|
int numRandomPoints = (int)(Math.pow(numScrambles,0.7f));
|
65
|
|
66
|
DynamicQuat dq = new DynamicQuat(duration, 0.5f);
|
67
|
dq.setMode(Dynamic.MODE_PATH);
|
68
|
dq.add(new Static4D(0,0,0,1));
|
69
|
|
70
|
for(int point=0; point<numRandomPoints; point++)
|
71
|
{
|
72
|
dq.add(generateNewRandomPoint());
|
73
|
}
|
74
|
|
75
|
dq.add(new Static4D(0,0,0,1));
|
76
|
|
77
|
mCubeEffects[0] = new MatrixEffectQuaternion(dq, new Static3D(0,0,0));
|
78
|
|
79
|
float Z = mObject.getNodeWidth()/3.0f;
|
80
|
|
81
|
Dynamic3D d0 = new Dynamic3D(duration, 0.5f);
|
82
|
d0.setMode(Dynamic.MODE_PATH);
|
83
|
d0.add(new Static3D( 0, 0, 0));
|
84
|
d0.add(new Static3D( 0, 0,-Z));
|
85
|
d0.add(new Static3D( 0, 0, 0));
|
86
|
mCubeEffects[1] = new MatrixEffectMove(d0);
|
87
|
}
|
88
|
|
89
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90
|
|
91
|
public void effectFinishedPlugin(final long effectID)
|
92
|
{
|
93
|
|
94
|
}
|
95
|
|
96
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97
|
// Enable all effects used in this Effect. Called by reflection from the parent class.
|
98
|
|
99
|
@SuppressWarnings("unused")
|
100
|
static void enable()
|
101
|
{
|
102
|
|
103
|
}
|
104
|
}
|