Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / helpers / FactoryBandagedCuboid.java @ 49cfdaa6

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.helpers;
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 float[] elementVertices(int ax, boolean left, int element)
31
    {
32
    float[] pos = mElements[element].getPos();
33
    float[] ret = new float[12];
34

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

    
132
    return ret;
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
// (vertices,indices) define a cubit face, i.e. a connected subset of the NxN grid.
137
// Return its 'diameter', i.e. max(width,height)
138

    
139
  public float faceDiameter(float[][] vertices, int[][] indices)
140
    {
141
    float maxX = -Float.MAX_VALUE;
142
    float minX =  Float.MAX_VALUE;
143
    float maxY = -Float.MAX_VALUE;
144
    float minY =  Float.MAX_VALUE;
145
    float maxZ = -Float.MAX_VALUE;
146
    float minZ =  Float.MAX_VALUE;
147

    
148
    for (int[] ind : indices)
149
      for(int index : ind)
150
        {
151
        float[] v = vertices[index];
152

    
153
        if (v[0] > maxX) maxX = v[0];
154
        if (v[0] < minX) minX = v[0];
155
        if (v[1] > maxY) maxY = v[1];
156
        if (v[1] < minY) minY = v[1];
157
        if (v[2] > maxZ) maxZ = v[2];
158
        if (v[2] < minZ) minZ = v[2];
159
        }
160

    
161
    float diffX = maxX-minX;
162
    float diffY = maxY-minY;
163
    float diffZ = maxZ-minZ;
164

    
165
    return diffX>diffY ? Math.max(diffX,diffZ) : Math.max(diffY,diffZ);
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169
// PUBLIC API
170

    
171
  public static FactoryBandagedCuboid getInstance()
172
    {
173
    if( mThis==null ) mThis = new FactoryBandagedCuboid();
174
    return mThis;
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  public float[][] getCuts(int[] numLayers)
180
    {
181
    int numAxis = numLayers.length;
182
    float[][] cuts = new float[numAxis][];
183

    
184
    for(int axis=0; axis<numAxis; axis++)
185
      {
186
      int len = numLayers[axis];
187
      float start = 1-len*0.5f;
188

    
189
      if( len>=2 )
190
        {
191
        cuts[axis] = new float[len-1];
192
        for(int i=0; i<len-1; i++) cuts[axis][i] = start+i;
193
        }
194
      }
195

    
196
    return cuts;
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
  public Static3D[] getNormals()
202
    {
203
    return TouchControlHexahedron.FACE_AXIS;
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  public float[][] getRotAxis()
209
    {
210
    return new float[][] { {1,0,0},{0,1,0},{0,0,1} };
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
  public float[] getDist3D()
216
    {
217
    float dx = mNumLayers[0]/2.0f;
218
    float dy = mNumLayers[1]/2.0f;
219
    float dz = mNumLayers[2]/2.0f;
220

    
221
    return new float[] {dx,dx,dy,dy,dz,dz};
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  public float[][] getBands(boolean iconMode)
227
    {
228
    float height= iconMode ? 0.001f : 0.048f;
229
    int[] angle = {60,50,40,32,28,23};
230
    float R     = 0.3f;
231
    float S     = 0.5f;
232
    int extraI  = 0;
233
    int extraV  = 0;
234

    
235
    int sum = mNumLayers[0]+mNumLayers[1]+mNumLayers[2];
236
    int numVertA= sum>=19 ? 3 : (sum>=16 ? 4:5);
237
    int numVertI= sum>=13 ? 2 : 3;
238

    
239
    return new float[][] { {  0.001f,angle[0],R,S,numVertI,extraV,extraI},
240
                           {height  ,angle[1],R,S,numVertA,extraV,extraI},
241
                           {height/2,angle[2],R,S,numVertA,extraV,extraI},
242
                           {height/3,angle[3],R,S,numVertA,extraV,extraI},
243
                           {height/4,angle[4],R,S,numVertA,extraV,extraI},
244
                           {height/5,angle[5],R,S,numVertA,extraV,extraI} };
245
    }
246
  }
(4-4/17)