Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / bandaged / FactoryBandagedCuboid.java @ db0d3a90

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.type.Static3D;
13
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
14

    
15
///////////////////////////////////////////////////////////////////////////////////////////////////
16

    
17
public class FactoryBandagedCuboid extends FactoryBandaged
18
  {
19
  private static FactoryBandagedCuboid mThis;
20

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

    
23
  private FactoryBandagedCuboid()
24
    {
25

    
26
    }
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
  public static FactoryBandagedCuboid getInstance()
31
     {
32
     if( mThis==null ) mThis = new FactoryBandagedCuboid();
33
     return mThis;
34
     }
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
  public float[] elementVertices(int ax, boolean left, int element)
39
    {
40
    float[] pos = mElements[element].getPos();
41
    float[] ret = new float[12];
42

    
43
    switch(ax)
44
      {
45
      case 0: if( left )
46
                {
47
                ret[ 0] = pos[0]-0.5f;
48
                ret[ 1] = pos[1]+0.5f;
49
                ret[ 2] = pos[2]-0.5f;
50
                ret[ 3] = pos[0]-0.5f;
51
                ret[ 4] = pos[1]-0.5f;
52
                ret[ 5] = pos[2]-0.5f;
53
                ret[ 6] = pos[0]-0.5f;
54
                ret[ 7] = pos[1]-0.5f;
55
                ret[ 8] = pos[2]+0.5f;
56
                ret[ 9] = pos[0]-0.5f;
57
                ret[10] = pos[1]+0.5f;
58
                ret[11] = pos[2]+0.5f;
59
                }
60
              else
61
                {
62
                ret[ 0] = pos[0]+0.5f;
63
                ret[ 1] = pos[1]+0.5f;
64
                ret[ 2] = pos[2]+0.5f;
65
                ret[ 3] = pos[0]+0.5f;
66
                ret[ 4] = pos[1]-0.5f;
67
                ret[ 5] = pos[2]+0.5f;
68
                ret[ 6] = pos[0]+0.5f;
69
                ret[ 7] = pos[1]-0.5f;
70
                ret[ 8] = pos[2]-0.5f;
71
                ret[ 9] = pos[0]+0.5f;
72
                ret[10] = pos[1]+0.5f;
73
                ret[11] = pos[2]-0.5f;
74
                }
75
              break;
76
      case 1: if( left )
77
                {
78
                ret[ 0] = pos[0]-0.5f;
79
                ret[ 1] = pos[1]-0.5f;
80
                ret[ 2] = pos[2]+0.5f;
81
                ret[ 3] = pos[0]-0.5f;
82
                ret[ 4] = pos[1]-0.5f;
83
                ret[ 5] = pos[2]-0.5f;
84
                ret[ 6] = pos[0]+0.5f;
85
                ret[ 7] = pos[1]-0.5f;
86
                ret[ 8] = pos[2]-0.5f;
87
                ret[ 9] = pos[0]+0.5f;
88
                ret[10] = pos[1]-0.5f;
89
                ret[11] = pos[2]+0.5f;
90
                }
91
              else
92
                {
93
                ret[ 0] = pos[0]-0.5f;
94
                ret[ 1] = pos[1]+0.5f;
95
                ret[ 2] = pos[2]-0.5f;
96
                ret[ 3] = pos[0]-0.5f;
97
                ret[ 4] = pos[1]+0.5f;
98
                ret[ 5] = pos[2]+0.5f;
99
                ret[ 6] = pos[0]+0.5f;
100
                ret[ 7] = pos[1]+0.5f;
101
                ret[ 8] = pos[2]+0.5f;
102
                ret[ 9] = pos[0]+0.5f;
103
                ret[10] = pos[1]+0.5f;
104
                ret[11] = pos[2]-0.5f;
105
                }
106
              break;
107
      case 2: if( left )
108
                {
109
                ret[ 0] = pos[0]+0.5f;
110
                ret[ 1] = pos[1]+0.5f;
111
                ret[ 2] = pos[2]-0.5f;
112
                ret[ 3] = pos[0]+0.5f;
113
                ret[ 4] = pos[1]-0.5f;
114
                ret[ 5] = pos[2]-0.5f;
115
                ret[ 6] = pos[0]-0.5f;
116
                ret[ 7] = pos[1]-0.5f;
117
                ret[ 8] = pos[2]-0.5f;
118
                ret[ 9] = pos[0]-0.5f;
119
                ret[10] = pos[1]+0.5f;
120
                ret[11] = pos[2]-0.5f;
121
                }
122
              else
123
                {
124
                ret[ 0] = pos[0]-0.5f;
125
                ret[ 1] = pos[1]+0.5f;
126
                ret[ 2] = pos[2]+0.5f;
127
                ret[ 3] = pos[0]-0.5f;
128
                ret[ 4] = pos[1]-0.5f;
129
                ret[ 5] = pos[2]+0.5f;
130
                ret[ 6] = pos[0]+0.5f;
131
                ret[ 7] = pos[1]-0.5f;
132
                ret[ 8] = pos[2]+0.5f;
133
                ret[ 9] = pos[0]+0.5f;
134
                ret[10] = pos[1]+0.5f;
135
                ret[11] = pos[2]+0.5f;
136
                }
137
              break;
138
      }
139

    
140
    return ret;
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  public int getElementVariant(int index)
146
     {
147
     return 0;
148
     }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
// (vertices,indices) define a cubit face, i.e. a connected subset of the NxN grid.
152
// Return its 'diameter', i.e. max(width,height)
153

    
154
  public float faceDiameter(float[][] vertices, int[][] indices)
155
    {
156
    float maxX = -Float.MAX_VALUE;
157
    float minX =  Float.MAX_VALUE;
158
    float maxY = -Float.MAX_VALUE;
159
    float minY =  Float.MAX_VALUE;
160
    float maxZ = -Float.MAX_VALUE;
161
    float minZ =  Float.MAX_VALUE;
162

    
163
    for (int[] ind : indices)
164
      for(int index : ind)
165
        {
166
        float[] v = vertices[index];
167

    
168
        if (v[0] > maxX) maxX = v[0];
169
        if (v[0] < minX) minX = v[0];
170
        if (v[1] > maxY) maxY = v[1];
171
        if (v[1] < minY) minY = v[1];
172
        if (v[2] > maxZ) maxZ = v[2];
173
        if (v[2] < minZ) minZ = v[2];
174
        }
175

    
176
    float diffX = maxX-minX;
177
    float diffY = maxY-minY;
178
    float diffZ = maxZ-minZ;
179

    
180
    return diffX>diffY ? Math.max(diffX,diffZ) : Math.max(diffY,diffZ);
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  public float[][] getCuts(int[] numLayers)
186
    {
187
    int numAxis = numLayers.length;
188
    float[][] cuts = new float[numAxis][];
189

    
190
    for(int axis=0; axis<numAxis; axis++)
191
      {
192
      int len = numLayers[axis];
193
      float start = 1-len*0.5f;
194

    
195
      if( len>=2 )
196
        {
197
        cuts[axis] = new float[len-1];
198
        for(int i=0; i<len-1; i++) cuts[axis][i] = start+i;
199
        }
200
      }
201

    
202
    return cuts;
203
    }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

    
207
  public Static3D[] getNormals()
208
    {
209
    return TouchControlHexahedron.FACE_AXIS;
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  public float[][] getRotAxis()
215
    {
216
    return new float[][] { {1,0,0},{0,1,0},{0,0,1} };
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
  public float[] getDist3D()
222
    {
223
    float dx = mNumLayers[0]/2.0f;
224
    float dy = mNumLayers[1]/2.0f;
225
    float dz = mNumLayers[2]/2.0f;
226

    
227
    return new float[] {dx,dx,dy,dy,dz,dz};
228
    }
229

    
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

    
232
  public float[][] getBands(boolean iconMode)
233
    {
234
    float height= iconMode ? 0.001f : 0.048f;
235
    int[] angle = {60,50,40,32,28,23};
236
    float R     = 0.3f;
237
    float S     = 0.5f;
238
    int extraI  = 0;
239
    int extraV  = 0;
240

    
241
    int sum = mNumLayers[0]+mNumLayers[1]+mNumLayers[2];
242
    int numVertA= sum>=19 ? 3 : (sum>=16 ? 4:5);
243
    int numVertI= sum>=13 ? 2 : 3;
244

    
245
    return new float[][] { {  0.001f,angle[0],R,S,numVertI,extraV,extraI},
246
                           {height  ,angle[1],R,S,numVertA,extraV,extraI},
247
                           {height/2,angle[2],R,S,numVertA,extraV,extraI},
248
                           {height/3,angle[3],R,S,numVertA,extraV,extraI},
249
                           {height/4,angle[4],R,S,numVertA,extraV,extraI},
250
                           {height/5,angle[5],R,S,numVertA,extraV,extraI} };
251
    }
252
  }
(7-7/8)