Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / bandaged / BandagedObjectSkewb.java @ 1eafa9c6

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.TwistyObject;
18
import org.distorted.objectlib.metadata.Metadata;
19
import org.distorted.objectlib.objects.TwistyBandagedSkewb;
20
import org.distorted.objectlib.shape.ShapeHexahedron;
21
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
22

    
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24

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

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

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

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

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

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

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

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

    
66
    return false;
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

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

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

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

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
// PUBLIC API
87

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

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

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

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

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

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

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

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

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

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

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

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

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  public int computeProjectionAngle()
158
    {
159
    return 90;
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

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

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

    
171
  public TwistyObject createObject(int mode, float size)
172
    {
173
    float[][] pos = getCubitPositions();
174
    Metadata meta = new Metadata(null,mSize,0,pos,0);
175
    return new TwistyBandagedSkewb( mode, ShapeHexahedron.DEFAULT_ROT, new Static3D(0,0,0), size, meta, null );
176
    }
177
}
(8-8/15)