Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / bandaged / BandagedObjectPyraminx.java @ a0ef8a1d

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 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.bandaged;
11

    
12
import static org.distorted.objectlib.main.TwistyObject.SQ3;
13
import static org.distorted.objectlib.main.TwistyObject.SQ6;
14

    
15
import org.distorted.library.main.DistortedScreen;
16
import org.distorted.library.mesh.MeshBase;
17
import org.distorted.library.type.Static3D;
18
import org.distorted.objectlib.main.InitData;
19
import org.distorted.objectlib.main.TwistyObject;
20
import org.distorted.objectlib.objects.TwistyBandagedPyraminx;
21
import org.distorted.objectlib.shape.ShapeTetrahedron;
22
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
23

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

    
26
public class BandagedObjectPyraminx extends BandagedObject
27
{
28
  private boolean isFaceInverted(int face)
29
    {
30
    return face>1;
31
    }
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
  private float[][] getCuts(int[] numLayers)
36
    {
37
    int numL = numLayers[0];
38
    float[][] ret = new float[4][numL-1];
39

    
40
    for(int i=0; i<numL-1; i++)
41
      {
42
      float cut = (1.0f+i-numL/4.0f)*(SQ6/3);
43
      ret[0][i] = cut;
44
      ret[1][i] = cut;
45
      ret[2][i] = cut;
46
      ret[3][i] = cut;
47
      }
48

    
49
    return ret;
50
    }
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  float[][] getRotAxis()
55
    {
56
    return new float[][]
57
      {
58
        {     0,-SQ3/3,-SQ6/3 },
59
        {     0,-SQ3/3, SQ6/3 },
60
        { SQ6/3, SQ3/3,     0 },
61
        {-SQ6/3, SQ3/3,     0 },
62
      };
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  float getDist2D()
68
    {
69
    return SQ3/6;
70
    }
71

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

    
74
  int[] getColors()
75
    {
76
    return ShapeTetrahedron.FACE_COLORS;
77
    }
78

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

    
81
  boolean isAdjacent(float x1, float y1, float z1, float x2, float y2, float z2 )
82
    {
83
    float dx = x1-x2;
84
    float dy = y1-y2;
85
    float dz = z1-z2;
86

    
87
    return dx*dx + dy*dy + dz*dz < (SQ3/4)*1.01f;
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  float[][][] getPositions()
93
    {
94
    FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
95
    return factory.getPositions(mSize);
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  MeshBase createMesh(float[] pos, boolean round)
101
    {
102
    FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
103
    return factory.createMesh(pos,mSize,false,round);
104
    }
105

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

    
109
  public BandagedObjectPyraminx(DistortedScreen screen, int minSize, int maxSize)
110
    {
111
    super(screen,minSize,maxSize);
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  public float getScreenRatio()
117
    {
118
    return 0.8f;
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  public float[] getDist3D()
124
    {
125
    float d = SQ6/12;
126
    return new float[] {d,d,d,d};
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public Static3D[] getFaceAxis()
132
    {
133
    return TouchControlTetrahedron.FACE_AXIS;
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  public boolean tryChangeObject(int x, int y, int z)
139
    {
140
    if( mSize[0]!=x && x>=mMinSize && x<=mMaxSize )
141
      {
142
      mSize[0] = x;
143
      mSize[1] = x;
144
      mSize[2] = x;
145
      mSize[3] = x;
146

    
147
      mMax = x;
148
      int numOcta = FactoryBandagedPyraminx.numEntriesInEmptyLattice(x-1);
149
      int numTetra= FactoryBandagedPyraminx.numEntriesInEmptyLattice(x);
150
      mNumCubits = numOcta + numTetra;
151
      mCuts = getCuts(mSize);
152
      return true;
153
      }
154
    else if( mCuts==null )
155
      {
156
      mMax = 1;
157
      int numOcta = FactoryBandagedPyraminx.numEntriesInEmptyLattice(x-1);
158
      int numTetra= FactoryBandagedPyraminx.numEntriesInEmptyLattice(x);
159
      mNumCubits  = numOcta + numTetra;
160
      mCuts = getCuts(mSize);
161
      return true;
162
      }
163
    return false;
164
    }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
  public int computeProjectionAngle()
169
    {
170
    return 120;
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  public boolean isInsideFace(int face, float[] p)
176
    {
177
    float y = (isFaceInverted(face) ? p[1] : -p[1]);
178
    float x = p[0];
179
    return (y >= -mDist2D) && (y <= mDist2D*(2-6*x)) && (y <= mDist2D*(2+6*x));
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
  public TwistyObject createObject(int mode, float size)
185
    {
186
    float[][] pos = getCubitPositions();
187
    InitData data = new InitData( mSize,pos);
188
    return new TwistyBandagedPyraminx( mode, ShapeTetrahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null );
189
    }
190
}
(7-7/15)