Project

General

Profile

Download (3.32 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / effects / scramble / ScrambleEffectRotations.java @ 00057bb1

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.effects.scramble;
11

    
12
import java.util.Random;
13

    
14
import org.distorted.library.effect.Effect;
15
import org.distorted.library.effect.MatrixEffectMove;
16
import org.distorted.library.effect.MatrixEffectQuaternion;
17
import org.distorted.library.type.Dynamic;
18
import org.distorted.library.type.Dynamic3D;
19
import org.distorted.library.type.DynamicQuat;
20
import org.distorted.library.type.Static3D;
21
import org.distorted.library.type.Static4D;
22

    
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24

    
25
public class ScrambleEffectRotations extends ScrambleEffect
26
  {
27
  private final Random mRndGen = new Random(0);
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
  private Static4D generateNewRandomPoint()
32
    {
33
    float x = mRndGen.nextFloat();
34
    float y = mRndGen.nextFloat();
35
    float z = mRndGen.nextFloat();
36
    float w = mRndGen.nextFloat();
37

    
38
    float len = (float)Math.sqrt(x*x + y*y + z*z + w*w);
39

    
40
    return new Static4D( x/len, y/len, z/len, w/len);
41
    }
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
  public void createEffects(int duration, int numScrambles)
46
    {
47
    mCubeEffectNumber   = 2;
48
    mNodeEffectNumber   = 0;
49
    mCubeEffectPosition = new int[] {2,3};
50
    mCubeEffects        = new Effect[mCubeEffectPosition.length];
51

    
52
    mRndGen.setSeed(System.currentTimeMillis());
53

    
54
    int numRandomPoints = (int)(Math.pow(numScrambles,0.7f));
55

    
56
    DynamicQuat dq = new DynamicQuat(duration, 0.5f);
57
    dq.setMode(Dynamic.MODE_PATH);
58
    dq.add(new Static4D(0,0,0,1));
59

    
60
    for(int point=0; point<numRandomPoints; point++)
61
      {
62
      dq.add(generateNewRandomPoint());
63
      }
64

    
65
    dq.add(new Static4D(0,0,0,1));
66

    
67
    mCubeEffects[0] = new MatrixEffectQuaternion(dq, new Static3D(0,0,0));
68

    
69
    float Z = mObjectNode.getWidth()/3.0f;
70

    
71
    Dynamic3D d0 = new Dynamic3D(duration, 0.5f);
72
    d0.setMode(Dynamic.MODE_PATH);
73
    d0.add(new Static3D( 0, 0, 0));
74
    d0.add(new Static3D( 0, 0,-Z));
75
    d0.add(new Static3D( 0, 0, 0));
76
    mCubeEffects[1] = new MatrixEffectMove(d0);
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
  public void effectFinishedPlugin(final long effectID)
82
    {
83

    
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87
// Enable all effects used in this Effect. Called by reflection from the parent class.
88

    
89
  @SuppressWarnings("unused")
90
  static void enable()
91
    {
92

    
93
    }
94
  }
(3-3/3)