1 |
a62aa9d7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2019 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
fdec60a3
|
Leszek Koltunski
|
// This file is part of Magic Cube. //
|
5 |
a62aa9d7
|
Leszek Koltunski
|
// //
|
6 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
a62aa9d7
|
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 |
a62aa9d7
|
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 |
a62aa9d7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.effects.scramble;
|
21 |
a62aa9d7
|
Leszek Koltunski
|
|
22 |
|
|
import org.distorted.library.effect.Effect;
|
23 |
|
|
import org.distorted.library.effect.MatrixEffectMove;
|
24 |
30b68322
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
25 |
a62aa9d7
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic;
|
26 |
|
|
import org.distorted.library.type.Dynamic3D;
|
27 |
30b68322
|
Leszek Koltunski
|
import org.distorted.library.type.DynamicQuat;
|
28 |
a62aa9d7
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
29 |
30b68322
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
30 |
|
|
|
31 |
|
|
import java.util.Random;
|
32 |
a62aa9d7
|
Leszek Koltunski
|
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
|
|
|
35 |
|
|
public class ScrambleEffectRotations extends ScrambleEffect
|
36 |
|
|
{
|
37 |
30b68322
|
Leszek Koltunski
|
private Random mRnd = new Random(0);
|
38 |
a62aa9d7
|
Leszek Koltunski
|
|
39 |
47ba5ddc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
|
41 |
|
|
private Static4D generateNewRandomPoint()
|
42 |
|
|
{
|
43 |
|
|
float x = mRnd.nextFloat();
|
44 |
|
|
float y = mRnd.nextFloat();
|
45 |
|
|
float z = mRnd.nextFloat();
|
46 |
|
|
float w = mRnd.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 |
a62aa9d7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54 |
|
|
|
55 |
e4db5995
|
Leszek Koltunski
|
public void createEffects(int duration, int numScrambles)
|
56 |
a62aa9d7
|
Leszek Koltunski
|
{
|
57 |
e8764a49
|
Leszek Koltunski
|
mCubeEffectNumber = 2;
|
58 |
|
|
mNodeEffectNumber = 0;
|
59 |
a4472437
|
Leszek Koltunski
|
mCubeEffectPosition = new int[] {2,3};
|
60 |
e8764a49
|
Leszek Koltunski
|
mCubeEffects = new Effect[mCubeEffectPosition.length];
|
61 |
a62aa9d7
|
Leszek Koltunski
|
|
62 |
30b68322
|
Leszek Koltunski
|
mRnd.setSeed(System.currentTimeMillis());
|
63 |
|
|
|
64 |
e4db5995
|
Leszek Koltunski
|
int numRandomPoints = (int)(Math.pow(numScrambles,0.7f));
|
65 |
|
|
|
66 |
30b68322
|
Leszek Koltunski
|
DynamicQuat dq = new DynamicQuat(duration, 0.5f);
|
67 |
|
|
dq.setMode(Dynamic.MODE_PATH);
|
68 |
|
|
dq.add(new Static4D(0,0,0,1));
|
69 |
e4db5995
|
Leszek Koltunski
|
|
70 |
|
|
for(int point=0; point<numRandomPoints; point++)
|
71 |
|
|
{
|
72 |
|
|
dq.add(generateNewRandomPoint());
|
73 |
|
|
}
|
74 |
|
|
|
75 |
30b68322
|
Leszek Koltunski
|
dq.add(new Static4D(0,0,0,1));
|
76 |
|
|
|
77 |
e8764a49
|
Leszek Koltunski
|
mCubeEffects[0] = new MatrixEffectQuaternion(dq, new Static3D(0,0,0));
|
78 |
30b68322
|
Leszek Koltunski
|
|
79 |
5b893eee
|
Leszek Koltunski
|
float Z = mObject.getNodeSize()/3.0f;
|
80 |
a62aa9d7
|
Leszek Koltunski
|
|
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 |
e8764a49
|
Leszek Koltunski
|
mCubeEffects[1] = new MatrixEffectMove(d0);
|
87 |
30b68322
|
Leszek Koltunski
|
}
|
88 |
|
|
|
89 |
a62aa9d7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
|
|
}
|