Project

General

Profile

Download (4.31 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / effect / scramble / ScrambleEffectRotations.java @ fb6a40c8

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