Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / bandaged / BandagedObjectCuboid.java @ d2e06841

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 org.distorted.library.main.DistortedScreen;
13
import org.distorted.library.mesh.MeshBase;
14
import org.distorted.library.type.Static3D;
15
import org.distorted.objectlib.main.InitData;
16
import org.distorted.objectlib.main.TwistyObject;
17
import org.distorted.objectlib.objects.TwistyBandagedCuboid;
18
import org.distorted.objectlib.shape.ShapeHexahedron;
19
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
20

    
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22

    
23
public class BandagedObjectCuboid extends BandagedObject
24
{
25
  private float[][] getCuts(int[] numLayers)
26
    {
27
    float[][] ret = new float[3][];
28

    
29
    for(int axis=0; axis<3; axis++)
30
      {
31
      int len = numLayers[axis];
32
      float start = (2-len)*0.5f;
33

    
34
      if( len>=2 )
35
        {
36
        ret[axis] = new float[len-1];
37
        for(int i=0; i<len-1; i++) ret[axis][i] = start+i;
38
        }
39
      }
40

    
41
    return ret;
42
    }
43

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

    
46
  float[][] getRotAxis()
47
    {
48
    return new float[][]
49
      {
50
        {1,0,0},
51
        {0,1,0},
52
        {0,0,1},
53
      };
54
    }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  float getDist2D()
59
     {
60
     return 0.5f;
61
     }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  int[] getColors()
66
     {
67
     return ShapeHexahedron.FACE_COLORS;
68
     }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  boolean isAdjacent(float dx, float dy, float dz)
73
    {
74
    return dx*dx + dy*dy + dz*dz <= 1;
75
    }
76

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

    
79
  float[][][] getPositions()
80
    {
81
    FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance();
82
    return factory.getPositions(mSize);
83
    }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
  MeshBase createMesh(float[] pos, boolean round)
88
     {
89
     FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance();
90
     return factory.createMesh(pos,mSize,false,round);
91
     }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
// PUBLIC API
95

    
96
  public BandagedObjectCuboid(DistortedScreen screen)
97
     {
98
     super(screen);
99
     }
100

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

    
103
  public float getScreenRatio()
104
     {
105
     return 0.5f;
106
     }
107

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

    
110
  public float[] getDist3D()
111
     {
112
     float max = mMax;
113

    
114
     float x = 0.5f*(mSize[0]/max);
115
     float y = 0.5f*(mSize[1]/max);
116
     float z = 0.5f*(mSize[2]/max);
117

    
118
     return new float[] {x,x,y,y,z,z};
119
     }
120

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

    
123
  public Static3D[] getFaceAxis()
124
     {
125
     return TouchControlHexahedron.FACE_AXIS;
126
     }
127

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

    
130
  public boolean isInsideFace(int face, float[] p)
131
     {
132
     float max = mMax;
133

    
134
     switch(face/2)
135
        {
136
        case 0: p[0] *= (max/mSize[2]); p[1] *= (max/mSize[1]); break;
137
        case 1: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[2]); break;
138
        case 2: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[1]); break;
139
        }
140

    
141
     return ( p[0]<=mDist2D && p[0]>=-mDist2D && p[1]<=mDist2D && p[1]>=-mDist2D );
142
     }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
  public int computeProjectionAngle()
147
     {
148
     float quot1 = mSize[2]/ (float)mSize[0];
149
     float quot2 = mSize[2]/ (float)mSize[1];
150
     float quot3 = mSize[0]/ (float)mSize[2];
151
     float quot4 = mSize[0]/ (float)mSize[1];
152

    
153
     float quot5 = Math.max(quot1,quot2);
154
     float quot6 = Math.max(quot3,quot4);
155
     float quot7 = Math.max(quot5,quot6);
156

    
157
          if( quot7<=1.0f ) return 120;
158
     else if( quot7<=1.5f ) return 90;
159
     else if( quot7<=2.0f ) return 60;
160
     else                   return 30;
161
     }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  public boolean tryChangeObject(int x, int y, int z)
166
     {
167
     if( mSize[0]!=x || mSize[1]!=y || mSize[2]!=z )
168
        {
169
        mSize[0] = x;
170
        mSize[1] = y;
171
        mSize[2] = z;
172
        mMax = x>y ? Math.max(x,z) : Math.max(y,z);
173
        mNumCubits = ( x<=1 || y<=1 || z<=1 ) ? x*y*z : x*y*z-(x-2)*(y-2)*(z-2);
174
        mCuts = getCuts(mSize);
175
        return true;
176
        }
177

    
178
     return false;
179
     }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  public TwistyObject createObject(int mode, float size)
184
     {
185
     float[][] pos = getCubitPositions();
186
     InitData data = new InitData( mSize,pos);
187
     return new TwistyBandagedCuboid( TwistyObject.MESH_NICE, mode, ShapeHexahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null );
188
     }
189
}
(4-4/11)