Project

General

Profile

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

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

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.effect.scramble;
21

    
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.effect.MatrixEffectQuaternion;
25
import org.distorted.library.type.Dynamic;
26
import org.distorted.library.type.Dynamic3D;
27
import org.distorted.library.type.DynamicQuat;
28
import org.distorted.library.type.Static3D;
29
import org.distorted.library.type.Static4D;
30

    
31
import java.util.Random;
32

    
33
import static org.distorted.object.RubikObject.NODE_FBO_SIZE;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class ScrambleEffectRotations extends ScrambleEffect
38
  {
39
  private Random mRnd = new Random(0);
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  public void createEffects(int duration, int numScrambles)
58
    {
59
    mCubeEffectNumber   = 2;
60
    mNodeEffectNumber   = 0;
61
    mCubeEffectPosition = new int[] {6,7};
62
    mCubeEffects        = new Effect[mCubeEffectPosition.length];
63

    
64
    mRnd.setSeed(System.currentTimeMillis());
65

    
66
    int numRandomPoints = (int)(Math.pow(numScrambles,0.7f));
67

    
68
    DynamicQuat dq = new DynamicQuat(duration, 0.5f);
69
    dq.setMode(Dynamic.MODE_PATH);
70
    dq.add(new Static4D(0,0,0,1));
71

    
72
    for(int point=0; point<numRandomPoints; point++)
73
      {
74
      dq.add(generateNewRandomPoint());
75
      }
76

    
77
    dq.add(new Static4D(0,0,0,1));
78

    
79
    mCubeEffects[0] = new MatrixEffectQuaternion(dq, new Static3D(0,0,0));
80

    
81
    float Z = NODE_FBO_SIZE /3;
82

    
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
    mCubeEffects[1] = new MatrixEffectMove(d0);
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
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
  }
(3-3/3)