Project

General

Profile

« Previous | Next » 

Revision b32444ee

Added by Leszek Koltunski about 4 years ago

More work on making new types of RubikObjects easily creatable.

View differences:

src/main/java/org/distorted/object/RubikCube.java
25 25

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

  
35 36
class RubikCube extends RubikObject
36 37
{
37
  private static final Static4D mapFront, mapBack, mapLeft, mapRight, mapTop, mapBottom, mapBlack;
38

  
39
  static
40
    {
41
    // 3x2 bitmap = 6 squares:
42
    //
43
    // RED     GREEN   BLUE
44
    // YELLOW  WHITE   BROWN
45

  
46
    final float ze = 0.0f;
47
    final float ot = 1.0f/3.0f;
48
    final float tt = 2.0f/3.0f;
49
    final float oh = 1.0f/2.0f;
50
    final float of = 1.0f/40.0f;
51

  
52
    mapFront = new Static4D(ze,oh, ze+ot,oh+oh);
53
    mapBack  = new Static4D(tt,ze, tt+ot,ze+oh);
54
    mapLeft  = new Static4D(ot,ze, ot+ot,ze+oh);
55
    mapRight = new Static4D(ze,ze, ze+ot,ze+oh);
56
    mapTop   = new Static4D(tt,oh, tt+ot,oh+oh);
57
    mapBottom= new Static4D(ot,oh, ot+ot,oh+oh);
58

  
59
    mapBlack = new Static4D(ze,ze, ze+of,ze+of);
60
    }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
// i.e. size^3 - (size-2)^3 - number of cubits in the outside wall of the Cube (we don't create or
64
// render the inside)
65

  
66
  int getNumCubits(int size)
67
    {
68
    return size>1 ? 6*size*size - 12*size + 8 : 1;
69
    }
70

  
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

  
73 38
  int[][] getCubitPositions(int size)
74 39
    {
75 40
    int[][] tmp = new int[getNumCubits(size)][3];
......
93 58
    return tmp;
94 59
    }
95 60

  
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
// i.e. size^3 - (size-2)^3 - number of cubits in the outside wall of the Cube (we don't create or
63
// render the inside)
64

  
65
  int getNumCubits(int size)
66
    {
67
    return size>1 ? 6*size*size - 12*size + 8 : 1;
68
    }
69

  
96 70
///////////////////////////////////////////////////////////////////////////////////////////////////
97 71
// All legal rotation quats of a RubikCube of any size must have all four of their components
98 72
// equal to either 0, 1, -1, 0.5, -0.5 or +-sqrt(2)/2.
......
168 142

  
169 143
///////////////////////////////////////////////////////////////////////////////////////////////////
170 144

  
171
  MeshCubes createMesh(int vertices,int x, int y, int z)
145
  private static final Static4D mapFront, mapBack, mapLeft, mapRight, mapTop, mapBottom, mapBlack;
146

  
147
  static
148
    {
149
    // 3x2 bitmap = 6 squares:
150
    //
151
    // RED     GREEN   BLUE
152
    // YELLOW  WHITE   BROWN
153

  
154
    final float ze = 0.0f;
155
    final float ot = 1.0f/3.0f;
156
    final float tt = 2.0f/3.0f;
157
    final float oh = 1.0f/2.0f;
158
    final float of = 1.0f/40.0f;
159

  
160
    mapFront = new Static4D(ze,oh, ze+ot,oh+oh);
161
    mapBack  = new Static4D(tt,ze, tt+ot,ze+oh);
162
    mapLeft  = new Static4D(ot,ze, ot+ot,ze+oh);
163
    mapRight = new Static4D(ze,ze, ze+ot,ze+oh);
164
    mapTop   = new Static4D(tt,oh, tt+ot,oh+oh);
165
    mapBottom= new Static4D(ot,oh, ot+ot,oh+oh);
166

  
167
    mapBlack = new Static4D(ze,ze, ze+of,ze+of);
168
    }
169

  
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

  
172
  MeshBase createCubitMesh(int vertices, int x, int y, int z)
172 173
    {
173 174
    Static4D tmpLeft  = (x==       0 ? mapLeft  :mapBlack);
174 175
    Static4D tmpRight = (x== mSize-1 ? mapRight :mapBlack);

Also available in: Unified diff