Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / bandaged / BandagedObjectOctahedron.java @ ae9d9227

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.TwistyObject;
19
import org.distorted.objectlib.metadata.Metadata;
20
import org.distorted.objectlib.objects.TwistyBandagedDiamond;
21
import org.distorted.objectlib.shape.ShapeOctahedron;
22
import org.distorted.objectlib.shape.ShapeTetrahedron;
23
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
24

    
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

    
27
public class BandagedObjectOctahedron extends BandagedObject
28
{
29
  private boolean isFaceInverted(int face)
30
    {
31
    return (face%2)==0;
32
    }
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
  private float[][] getCuts(int[] numLayers)
37
    {
38
    int numL = numLayers[0];
39
    if( numL<2 ) return null;
40
    float[][] ret = new float[4][numL-1];
41
    float cut = (SQ6/6)*(2-numL);
42

    
43
    for(int i=0; i<numL-1; i++)
44
      {
45
      ret[0][i] = cut;
46
      ret[1][i] = cut;
47
      ret[2][i] = cut;
48
      ret[3][i] = cut;
49
      cut += SQ6/3;
50
      }
51

    
52
    return ret;
53
    }
54

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

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

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
  float getDist2D()
71
    {
72
    return SQ3/6;
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  int[] getColors()
78
    {
79
    return ShapeOctahedron.FACE_COLORS;
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  boolean isAdjacent(float x1, float y1, float z1, float x2, float y2, float z2 )
85
    {
86
    float dx = x1-x2;
87
    float dy = y1-y2;
88
    float dz = z1-z2;
89

    
90
    return dx*dx + dy*dy + dz*dz < (SQ3/4)*1.01f;
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
  float[][][] getPositions()
96
    {
97
    FactoryBandagedOctahedron factory = FactoryBandagedOctahedron.getInstance();
98
    return factory.getPositions(mSize);
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  MeshBase createMesh(float[] pos, boolean round)
104
    {
105
    FactoryBandagedOctahedron factory = FactoryBandagedOctahedron.getInstance();
106
    return factory.createMesh(pos,mSize,false,round);
107
    }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
// PUBLIC API
111

    
112
  public BandagedObjectOctahedron(DistortedScreen screen, int minSize, int maxSize)
113
    {
114
    super(screen,minSize,maxSize);
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  public float getScreenRatio()
120
    {
121
    return 0.64f;
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  public float[] getDist3D()
127
    {
128
    float d = SQ6/6;
129
    return new float[] {d,d,d,d,d,d,d,d};
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  public Static3D[] getFaceAxis()
135
    {
136
    return TouchControlOctahedron.FACE_AXIS;
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

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

    
150
      mMax = x;
151
      int numOcta = FactoryBandagedOctahedron.getNumOctahedrons(x);
152
      int numTetra= FactoryBandagedOctahedron.getNumTetrahedrons(x);
153
      mNumCubits = numOcta + numTetra;
154
      mCuts = getCuts(mSize);
155
      return true;
156
      }
157
    else if( mCuts==null )
158
      {
159
      mMax = 2;
160
      int numOcta = FactoryBandagedOctahedron.getNumOctahedrons(mMax);
161
      int numTetra= FactoryBandagedOctahedron.getNumTetrahedrons(mMax);
162
      mNumCubits = numOcta + numTetra;
163
      mCuts = getCuts(mSize);
164
      return true;
165
      }
166
    return false;
167
    }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

    
171
  public int computeProjectionAngle()
172
    {
173
    return 40;
174
    }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

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

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

    
187
  public TwistyObject createObject(int mode, float size)
188
    {
189
    float[][] pos = getCubitPositions();
190
    Metadata meta = new Metadata(null,mSize,0,pos);
191
    return new TwistyBandagedDiamond( mode, ShapeTetrahedron.DEFAULT_ROT, new Static3D(0,0,0), size, meta, null );
192
    }
193
}
(6-6/15)