Project

General

Profile

« Previous | Next » 

Revision e844c116

Added by Leszek Koltunski about 4 years ago

Beginnings of Pyraminx.

View differences:

src/main/java/org/distorted/effect/scramble/ScrambleEffect.java
70 70
  private long mDurationSingleTurn;
71 71
  private Random mRnd;
72 72
  private RubikObject mObject;
73
  private int mNumAxis;
74
  private int mBasicAngle;
73 75

  
74 76
  Effect[] mNodeEffects;
75 77
  int[] mNodeEffectPosition;
......
82 84
  ScrambleEffect()
83 85
    {
84 86
    mRnd = new Random( System.currentTimeMillis() );
85
    mLastVector = 3;
87
    mLastVector = -2;
86 88
    }
87 89

  
88 90
///////////////////////////////////////////////////////////////////////////////////////////////////
......
93 95
///////////////////////////////////////////////////////////////////////////////////////////////////
94 96
// first compute how many out of 'numScrambles' are double turns (this will matter when we compute
95 97
// the time a single quarter-turn takes!
98
//
99
// Only works for
100
// basicAngle==4, i.e. something whose rotations are by 90 degrees (RubikCube) or
101
// basicAngle==3, i.e. something whose rotations are by 120 degrees (a Pyramix) or
102
// basicAngle==2, i.e. something whose rotations are by 180 degrees (is there something like that?)
96 103

  
97 104
  private void createBaseEffects(int duration, int numScrambles)
98 105
    {
......
100 107

  
101 108
    mNumDoubleScramblesLeft=0;
102 109

  
103
    for(int i=0; i<numScrambles; i++)
110
    if( mBasicAngle>=4 )
104 111
      {
105
      if( (mRnd.nextInt() % 3) == 0 )
112
      for(int i=0; i<numScrambles; i++)
106 113
        {
107
        mNumDoubleScramblesLeft++;
114
        if( (mRnd.nextInt() % 3) == 0 )
115
          {
116
          mNumDoubleScramblesLeft++;
117
          }
108 118
        }
109 119
      }
110 120

  
......
114 124
    }
115 125

  
116 126
///////////////////////////////////////////////////////////////////////////////////////////////////
127
// only works if basicAngle<=4, i.e. wont work for something whose basic rotations are by less
128
// than 90 degrees.
117 129

  
118 130
  private void addNewScramble()
119 131
    {
120 132
    if( mNumScramblesLeft>0 )
121 133
      {
122
      if( mLastVector == 3 )
134
      if( mLastVector == -2 )
123 135
        {
124
        mLastVector = mRnd.nextInt(3);
136
        mLastVector = mRnd.nextInt(mNumAxis);
125 137
        }
126 138
      else
127 139
        {
128
        int newVector = mRnd.nextInt(2);
129

  
130
        switch(mLastVector)
131
          {
132
          case 0: mLastVector = (newVector==0 ? 1:2); break;
133
          case 1: mLastVector = (newVector==0 ? 0:2); break;
134
          case 2: mLastVector = (newVector==0 ? 0:1); break;
135
          }
140
        int newVector = mRnd.nextInt(mNumAxis-1);
141
        mLastVector = (newVector>=mLastVector ? newVector+1 : newVector);
136 142
        }
137 143

  
138 144
      int row  = mRnd.nextInt(mObject.getSize());
......
162 168
    }
163 169

  
164 170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
// only works for basicAngle==4, i.e. RubikCube or basicAngle==3, i.e. a Pyramix.
165 172

  
166 173
  private int randomizeAngle()
167 174
    {
......
301 308

  
302 309
    mObject.solve();
303 310

  
311
    mNumAxis    = mObject.getNumAxis();
312
    mBasicAngle = mObject.getBasicAngle();
313

  
304 314
    int numScrambles = renderer.getNumScrambles();
305 315
    int dura = (int)(duration*Math.pow(numScrambles,0.6f));
306 316
    createBaseEffects(dura,numScrambles);
src/main/java/org/distorted/object/Cubit.java
47 47
  private Static3D mRotationAxis;
48 48
  private MatrixEffectRotate mRotateEffect;
49 49
  private Static3D mCurrentPosition;
50
  private int mNumAxis;
50 51

  
51 52
  Dynamic1D mRotationAngle;
52 53
  DistortedNode mNode;
......
155 156

  
156 157

  
157 158
///////////////////////////////////////////////////////////////////////////////////////////////////
158
// TODO: this is only right in case of RubikCube
159
// cast current position on axis; use mStart and mStep to compute the rotation row for each axis.
159 160

  
160 161
  private void computeRotationRow()
161 162
    {
162
    mRotationRow[0] = (int)mCurrentPosition.get0();
163
    mRotationRow[1] = (int)mCurrentPosition.get1();
164
    mRotationRow[2] = (int)mCurrentPosition.get2();
163
    float tmp;
164
    Static3D axis;
165
    float x = mCurrentPosition.get0();
166
    float y = mCurrentPosition.get1();
167
    float z = mCurrentPosition.get2();
168

  
169
    for(int i=0; i<mNumAxis; i++)
170
      {
171
      axis = mParent.ROTATION_AXIS[i];
172
      tmp = x*axis.get0() + y*axis.get1() + z*axis.get2();
173
      mRotationRow[i] = (int)( (tmp-mParent.mStart)/mParent.mStep + 0.5f );
174
      }
165 175
    }
166 176

  
167 177
///////////////////////////////////////////////////////////////////////////////////////////////////
......
184 194
    mCurrentPosition = position;
185 195
    mRotateEffect    = new MatrixEffectRotate(mRotationAngle, mRotationAxis, matrCenter);
186 196

  
187
    mRotationRow = new int[mParent.ROTATION_AXIS.length];
197
    mNumAxis     = mParent.ROTATION_AXIS.length;
198
    mRotationRow = new int[mNumAxis];
188 199
    computeRotationRow();
189 200

  
190 201
    mEffect = new DistortedEffects();
src/main/java/org/distorted/object/RubikCube.java
38 38

  
39 39
class RubikCube extends RubikObject
40 40
{
41
  // the three rotation axis of a RubikCube
41
  // the three rotation axis of a RubikCube. Must be normalized.
42 42
  private static final Static3D[] AXIS = new Static3D[]
43 43
         {
44 44
           new Static3D(1,0,0),
......
171 171

  
172 172
    return new MeshJoined(meshes);
173 173
    }
174

  
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176
// PUBLIC API
177

  
178
  public int getBasicAngle()
179
    {
180
    return 4;
181
    }
174 182
}
src/main/java/org/distorted/object/RubikObject.java
58 58
  private Static4D mQuatAccumulated;
59 59
  private Cubit[] mCubits;
60 60

  
61
  float mStart, mStep;
61 62
  int mSize;
62 63

  
63 64
  Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
......
84 85

  
85 86
    mSize = size;
86 87

  
88
    computeStartAndStep(positions);
89

  
87 90
    mRotationAngleStatic = new Static1D(0);
88 91
    mRotationAngleMiddle = new Static1D(0);
89 92
    mRotationAngleFinal  = new Static1D(0);
......
148 151
    mesh.setTextureMap(maps);
149 152
    }
150 153

  
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

  
156
  private void computeStartAndStep(Static3D[] pos)
157
    {
158
    float min = Float.MAX_VALUE;
159
    float max = Float.MIN_VALUE;
160
    float axisX = ROTATION_AXIS[0].get0();
161
    float axisY = ROTATION_AXIS[0].get1();
162
    float axisZ = ROTATION_AXIS[0].get2();
163
    float tmp;
164

  
165
    for(int i=0; i<NUM_CUBITS; i++)
166
      {
167
      tmp = pos[i].get0()*axisX + pos[i].get1()*axisY + pos[i].get2()*axisZ;
168
      if( tmp<min ) min=tmp;
169
      if( tmp>max ) max=tmp;
170
      }
171

  
172
    mStart = min;
173
    mStep  = (max-min+1.0f)/mSize;
174
    }
175

  
151 176
///////////////////////////////////////////////////////////////////////////////////////////////////
152 177

  
153 178
  private boolean belongsToRotation( int cubit, int axis, int row)
......
396 421

  
397 422
///////////////////////////////////////////////////////////////////////////////////////////////////
398 423

  
399
  public int getNumRotations()
424
  public int getNumAxis()
400 425
    {
401 426
    return ROTATION_AXIS.length;
402 427
    }
......
409 434
  abstract void createFaceTexture(Canvas canvas, Paint paint, int face);
410 435
  abstract MeshBase createCubitMesh(int vertices);
411 436
  abstract Static3D[] getRotationAxis();
437
  public abstract int getBasicAngle();
412 438
  }
src/main/java/org/distorted/object/RubikPyraminx.java
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.object;
21

  
22
import android.graphics.Canvas;
23
import android.graphics.Paint;
24

  
25
import org.distorted.library.main.DistortedEffects;
26
import org.distorted.library.main.DistortedTexture;
27
import org.distorted.library.mesh.MeshBase;
28
import org.distorted.library.mesh.MeshRectangles;
29
import org.distorted.library.type.Static3D;
30
import org.distorted.library.type.Static4D;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
public class RubikPyraminx extends RubikObject
35
{
36
  private static final Static3D[] AXIS = new Static3D[]
37
         {
38
           new Static3D(                     0,                       0,       1 ),
39
           new Static3D( (float)Math.sqrt(6)/3,  -(float)Math.sqrt(3)/3, -1.0f/3 ),
40
           new Static3D(-(float)Math.sqrt(6)/3,  -(float)Math.sqrt(3)/3, -1.0f/3 ),
41
           new Static3D(                     0, 2*(float)Math.sqrt(2)/3, -1.0f/3 )
42
         };
43

  
44
  private static final int[] FACE_COLORS = new int[]
45
         {
46
           0xffffff00, 0xff00ff00,  // AXIS[0]right (YELLOW) AXIS[1]right (GREEN )
47
           0xff0000ff, 0xffff0000   // AXIS[2]right (BLUE  ) AXIS[3]right (RED   )
48
         };
49

  
50
  private static final float[] LEGALQUATS = new float[]
51
         {
52
         // TODO;
53
         };
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects)
58
    {
59
    super(size,quatCur,quatAcc,texture,mesh,effects);
60
    }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
// TODO
64

  
65
  Static3D[] getCubitPositions(int size)
66
    {
67
    return null;
68
    }
69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

  
72
  float[] getLegalQuats()
73
    {
74
    return LEGALQUATS;
75
    }
76

  
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

  
79
  int getNumFaces()
80
    {
81
    return FACE_COLORS.length;
82
    }
83

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

  
86
  Static3D[] getRotationAxis()
87
    {
88
    return AXIS;
89
    }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

  
93
  void createFaceTexture(Canvas canvas, Paint paint, int face)
94
    {
95
    // TODO
96
    }
97

  
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
// TODO
100

  
101
  MeshBase createCubitMesh(int vertices)
102
    {
103
    return null;
104
    }
105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
// PUBLIC API
108

  
109
  public int getBasicAngle()
110
    {
111
    return 3;
112
    }
113
}

Also available in: Unified diff