Project

General

Profile

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

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

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.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 dx, float dy, float dz)
85
    {
86
    return dx*dx + dy*dy + dz*dz < (SQ3/4)*1.01f;
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

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

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

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

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
// PUBLIC API
107

    
108
  public BandagedObjectOctahedron(DistortedScreen screen)
109
    {
110
    super(screen);
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  public float getScreenRatio()
116
    {
117
    return 0.64f;
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

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

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

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

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

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

    
146
      mMax = x;
147
      int numOcta = FactoryBandagedOctahedron.getNumOctahedrons(x);
148
      int numTetra= FactoryBandagedOctahedron.getNumTetrahedrons(x);
149
      mNumCubits = numOcta + numTetra;
150
      mCuts = getCuts(mSize);
151
      return true;
152
      }
153

    
154
    return false;
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  public int computeProjectionAngle()
160
    {
161
    return 40;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

    
166
  public boolean isInsideFace(int face, float[] p)
167
    {
168
    float y = (isFaceInverted(face) ? p[1] : -p[1]);
169
    float x = p[0];
170
    return (y >= -mDist2D) && (y <= mDist2D*(2-6*x)) && (y <= mDist2D*(2+6*x));
171
    }
172

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

    
175
  public TwistyObject createObject(int mode, float size)
176
    {
177
    float[][] pos = getCubitPositions();
178
    InitData data = new InitData( mSize,pos);
179
    return new TwistyBandagedDiamond( TwistyObject.MESH_NICE, mode, ShapeTetrahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null );
180
    }
181
}
(6-6/13)