Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / bandaged / BandagedObjectSkewb.java @ 26175a13

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

    
14
import org.distorted.library.main.DistortedScreen;
15
import org.distorted.library.mesh.MeshBase;
16
import org.distorted.library.type.Static3D;
17
import org.distorted.objectlib.main.InitData;
18
import org.distorted.objectlib.main.TwistyObject;
19
import org.distorted.objectlib.shape.ShapeHexahedron;
20
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

    
24
public class BandagedObjectSkewb extends BandagedObject
25
{
26
  float[][] getRotAxis()
27
    {
28
    return new float[][]
29
      {
30
        { SQ3/3, SQ3/3, SQ3/3 },
31
        { SQ3/3, SQ3/3,-SQ3/3 },
32
        { SQ3/3,-SQ3/3, SQ3/3 },
33
        { SQ3/3,-SQ3/3,-SQ3/3 },
34
      };
35
    }
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
  float getDist2D()
40
    {
41
    return 0.5f;
42
    }
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
  int[] getColors()
47
    {
48
    return ShapeHexahedron.FACE_COLORS;
49
    }
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  boolean isAdjacent(float x1, float y1, float z1, float x2, float y2, float z2 )
54
    {
55
    float dx = x1-x2;
56
    float dy = y1-y2;
57
    float dz = z1-z2;
58

    
59
    if( dx*dx + dy*dy + dz*dz < 2*1.01f )
60
      {
61
      float s = 0.25f*mSize[0]*mSize[0];
62
      return (x1==x2 && x1*x1==s) || (y1==y2 && y1*y1==s) || (z1==z2 && z1*z1==s);
63
      }
64

    
65
    return false;
66
    }
67

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

    
70
  float[][][] getPositions()
71
    {
72
    FactoryBandagedSkewb factory = FactoryBandagedSkewb.getInstance();
73
    return factory.getPositions(mSize);
74
    }
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
  MeshBase createMesh(float[] pos, boolean round)
79
    {
80
    FactoryBandagedSkewb factory = FactoryBandagedSkewb.getInstance();
81
    return factory.createMesh(pos,mSize,false,round);
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
// PUBLIC API
86

    
87
  public BandagedObjectSkewb(DistortedScreen screen, int minSize, int maxSize)
88
    {
89
    super(screen,minSize,maxSize);
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  public float getScreenRatio()
95
    {
96
    return 0.5f;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  public float[] getDist3D()
102
    {
103
    float d = 0.5f;
104
    return new float[] {d,d,d,d,d,d};
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  public Static3D[] getFaceAxis()
110
    {
111
    return TouchControlHexahedron.FACE_AXIS;
112
    }
113

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

    
116
  private float[][] getCuts(int[] numLayers)
117
    {
118
    float[] c = numLayers[0]==2 ? (new float[] {0.0f}) : (new float[] {-SQ3/4, SQ3/4});
119
    return new float[][] {c,c,c,c};
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
  public boolean tryChangeObject(int x, int y, int z)
125
    {
126
    if( mSize[0]!=x && x>= mMinSize && x<=mMaxSize )
127
      {
128
      mSize[0] = x;
129
      mSize[1] = x;
130
      mSize[2] = x;
131
      mSize[3] = x;
132

    
133
      mMax = x;
134
      int numCor = FactoryBandagedSkewb.numCorners(x);
135
      int numEdg = FactoryBandagedSkewb.numEdges(x);
136
      int numCen = FactoryBandagedSkewb.numCenters(x);
137
      mNumCubits = numCor + numEdg + numCen;
138
      mCuts = getCuts(mSize);
139
      return true;
140
      }
141
    else if( mCuts==null )
142
      {
143
      mMax = 2;
144
      int numCor = FactoryBandagedSkewb.numCorners(mMax);
145
      int numEdg = FactoryBandagedSkewb.numEdges(mMax);
146
      int numCen = FactoryBandagedSkewb.numCenters(mMax);
147
      mNumCubits = numCor + numEdg + numCen;
148
      mCuts = getCuts(mSize);
149
      return true;
150
      }
151
    return false;
152
    }
153

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

    
156
  public int computeProjectionAngle()
157
    {
158
    return 40;
159
    }
160

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
  public boolean isInsideFace(int face, float[] p)
164
    {
165
    return ( p[0]<=mDist2D && p[0]>=-mDist2D && p[1]<=mDist2D && p[1]>=-mDist2D );
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
  public TwistyObject createObject(int mode, float size)
171
    {
172
    float[][] pos = getCubitPositions();
173
    InitData data = new InitData( mSize,pos);
174
    return null;//new TwistyBandagedPyraminx( TwistyObject.MESH_NICE, mode, ShapeTetrahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null );
175
    }
176
}
(8-8/15)