Project

General

Profile

« Previous | Next » 

Revision 30b68322

Added by Leszek Koltunski about 5 years ago

library: Fix DynamicQuat
cube app: progress with ScrambleEffects

View differences:

src/main/java/org/distorted/effect/ScrambleEffect.java
221 221
    {
222 222
    for(int i=0; i<mCubeEffectNumber[flavour]; i++)
223 223
      {
224
      android.util.Log.e("scramble", "applying cube effect "+mCubeEffects[flavour][i].getName());
224
      //android.util.Log.e("scramble", "applying cube effect "+mCubeEffects[flavour][i].getName());
225 225

  
226 226
      mCube.apply(mCubeEffects[flavour][i],mCubeEffectPosition[flavour][i]);
227 227
      mCubeEffects[flavour][i].notifyWhenFinished(this);
......
242 242
    {
243 243
    for(int i=0; i<mCubeEffectNumber[flavour]; i++)
244 244
      {
245
      android.util.Log.e("scramble", "removing cube effect "+mCubeEffects[flavour][i].getName());
245
      //android.util.Log.e("scramble", "removing cube effect "+mCubeEffects[flavour][i].getName());
246 246

  
247 247
      mCube.remove(mCubeEffects[flavour][i].getID());
248 248
      }
src/main/java/org/distorted/effect/ScrambleEffectRotations.java
21 21

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

  
31
import java.util.Random;
27 32

  
28 33
import static org.distorted.magic.RubikRenderer.TEXTURE_SIZE;
29 34

  
......
31 36

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

  
35 41
///////////////////////////////////////////////////////////////////////////////////////////////////
36 42

  
37 43
  public void createEffects(int duration)
38 44
    {
39
    mCubeEffectNumber[EFFECT_FLAVOUR_PLUGIN]   = 1;
45
    mCubeEffectNumber[EFFECT_FLAVOUR_PLUGIN]   = 2;
40 46
    mNodeEffectNumber[EFFECT_FLAVOUR_PLUGIN]   = 0;
41
    mCubeEffectPosition[EFFECT_FLAVOUR_PLUGIN] = new int[] {6};
47
    mCubeEffectPosition[EFFECT_FLAVOUR_PLUGIN] = new int[] {6,7};
42 48
    mCubeEffects[EFFECT_FLAVOUR_PLUGIN]        = new Effect[mCubeEffectPosition[EFFECT_FLAVOUR_PLUGIN].length];
43 49

  
50
    mRnd.setSeed(System.currentTimeMillis());
51

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

  
60
    mCubeEffects[EFFECT_FLAVOUR_PLUGIN][0] = new MatrixEffectQuaternion(dq, new Static3D(0,0,0));
61

  
44 62
    float Z = TEXTURE_SIZE/3;
45 63

  
46 64
    Dynamic3D d0 = new Dynamic3D(duration, 0.5f);
......
48 66
    d0.add(new Static3D( 0, 0, 0));
49 67
    d0.add(new Static3D( 0, 0,-Z));
50 68
    d0.add(new Static3D( 0, 0, 0));
51
    mCubeEffects[EFFECT_FLAVOUR_PLUGIN][0] = new MatrixEffectMove(d0);
69
    mCubeEffects[EFFECT_FLAVOUR_PLUGIN][1] = new MatrixEffectMove(d0);
70
    }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

  
74
  private Static4D generateNewRandomPoint()
75
    {
76
    float x = mRnd.nextFloat();
77
    float y = mRnd.nextFloat();
78
    float z = mRnd.nextFloat();
79
    float w = mRnd.nextFloat();
80

  
81
    float len = (float)Math.sqrt(x*x + y*y + z*z + w*w);
82

  
83
    return new Static4D( x/len, y/len, z/len, w/len);
52 84
    }
53 85

  
54 86
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/magic/RubikActivity.java
45 45

  
46 46
    public static final int DEFAULT_SIZECHANGE_POS = 20;
47 47
    public static final int DEFAULT_UNSCRAMBLE_POS = 20;
48
    public static final int DEFAULT_SCRAMBLE_POS   = 20;
48
    public static final int DEFAULT_SCRAMBLE_POS   =100;
49 49
    public static final int DEFAULT_SIZECHANGE_TYPE= 1;
50 50
    public static final int DEFAULT_UNSCRAMBLE_TYPE= 1;
51 51
    public static final int DEFAULT_SCRAMBLE_TYPE  = 0;
src/main/java/org/distorted/magic/RubikCube.java
30 30
import org.distorted.library.effect.MatrixEffectRotate;
31 31
import org.distorted.library.effect.MatrixEffectScale;
32 32
import org.distorted.library.effect.VertexEffectSink;
33
import org.distorted.library.effectqueue.EffectQueue;
33 34
import org.distorted.library.main.DistortedEffects;
34 35
import org.distorted.library.main.DistortedNode;
35 36
import org.distorted.library.main.DistortedTexture;
......
71 72

  
72 73
///////////////////////////////////////////////////////////////////////////////////////////////////
73 74

  
74
    RubikCube(int size, Static4D quatC, Static4D quatA, DistortedTexture texture, MeshFlat mesh, DistortedEffects effects)
75
    RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshFlat mesh, DistortedEffects effects)
75 76
      {
76 77
      super(texture,effects,mesh);
77 78

  
......
109 110
      VertexEffectSink        sinkEffect = new VertexEffectSink( new Static1D(getSinkStrength()), sinkCenter, region );
110 111
      MatrixEffectMove        moveEffect = new MatrixEffectMove(mMove);
111 112
      MatrixEffectScale      scaleEffect = new MatrixEffectScale(mScale);
112
      MatrixEffectQuaternion quatCEffect = new MatrixEffectQuaternion(quatC, matrCenter);
113
      MatrixEffectQuaternion quatAEffect = new MatrixEffectQuaternion(quatA, matrCenter);
113
      MatrixEffectQuaternion quatCEffect = new MatrixEffectQuaternion(quatCur, matrCenter);
114
      MatrixEffectQuaternion quatAEffect = new MatrixEffectQuaternion(quatAcc, matrCenter);
114 115

  
115 116
      MatrixEffectMove       nodeMoveEffect  = new MatrixEffectMove(mNodeMove);
116 117
      MatrixEffectScale      nodeScaleEffect = new MatrixEffectScale(mNodeScale);
......
224 225
              }
225 226
      }
226 227

  
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

  
230
    public String print_effects()
231
      {
232
      String str="";
233

  
234
      EffectQueue[] effects = mEffects[0][0][0].getQueues();
235
      EffectQueue matrix      = effects[0];
236
      EffectQueue vertex      = effects[1];
237
      EffectQueue fragment    = effects[2];
238
      EffectQueue postprocess = effects[3];
239

  
240
      str+="MATRIX: ";
241
      int m_len = matrix.getNumEffects();
242
      for(int i=0; i<m_len; i++)
243
        {
244
        str+=(" "+matrix.getEffect(i).getName()+"("+matrix.getEffect(i).getID()+")" );
245
        }
246
      str+='\n';
247

  
248
      str+="VERTEX: ";
249
      int v_len = vertex.getNumEffects();
250
      for(int i=0; i<v_len; i++)
251
        {
252
        str+=(" "+vertex.getEffect(i).getName()+"("+matrix.getEffect(i).getID()+")" );
253
        }
254
      str+='\n';
255

  
256
      str+="FRAGMENT: ";
257
      int f_len = fragment.getNumEffects();
258
      for(int i=0; i<f_len; i++)
259
        {
260
        str+=(" "+fragment.getEffect(i).getName()+"("+matrix.getEffect(i).getID()+")" );
261
        }
262
      str+='\n';
263

  
264
      str+="POSTPROCESS: ";
265
      int p_len = postprocess.getNumEffects();
266
      for(int i=0; i<p_len; i++)
267
        {
268
        str+=(" "+postprocess.getEffect(i).getName()+"("+matrix.getEffect(i).getID()+")" );
269
        }
270
      str+='\n';
271

  
272
      return str;
273
      }
227 274
///////////////////////////////////////////////////////////////////////////////////////////////////
228 275

  
229 276
    public int getNumEffects(EffectType type)
src/main/res/layout/settings.xml
105 105
        android:gravity="center|fill_horizontal"
106 106
        android:layout_marginLeft="10dp"
107 107
        android:layout_marginRight="10dp"
108
        android:layout_marginBottom="10dp"
108 109
        android:background="@color/grey"
109 110
        android:orientation="vertical">
110 111

  

Also available in: Unified diff