Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyTestGhost.java @ 8f5116ec

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.objects;
11

    
12
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
14

    
15
import org.distorted.library.effect.EffectName;
16
import org.distorted.library.type.Static3D;
17
import org.distorted.library.type.Static4D;
18
import org.distorted.objectlib.helpers.FactoryCubit;
19
import org.distorted.objectlib.helpers.ObjectFaceShape;
20
import org.distorted.objectlib.helpers.ObjectShape;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitAssets;
23
import org.distorted.objectlib.metadata.Metadata;
24
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
25
import org.distorted.objectlib.shape.ShapeHexahedron;
26
import org.distorted.objectlib.touchcontrol.TouchControlCuboids;
27

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

    
30
public class TwistyTestGhost extends ShapeHexahedron
31
{
32
  private static final int GHOST_ANGLE = 30;
33

    
34
  static final Static3D[] ROT_AXIS = new Static3D[]
35
         {
36
           new Static3D(1,0,0),
37
           new Static3D(0,1,0),
38
           new Static3D(0,0,1)
39
         };
40

    
41
  private int[][] mEdges;
42
  private float[][] mCuts;
43
  private int[][] mBasicAngle;
44
  private int[] mQuatIndex;
45
  private float[][] mPosition;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  public TwistyTestGhost(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
50
    {
51
    super(iconMode, (meta.getNumLayers()[0]+meta.getNumLayers()[1]+meta.getNumLayers()[2])/3.0f, quat, move, scale, meta, asset);
52
    }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  @Override
57
  public int getGhostAngle()
58
    {
59
    return GHOST_ANGLE;
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  public int[][] getScrambleEdges()
65
    {
66
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
67
    return mEdges;
68
    }
69

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

    
72
  private float[][] getVertices(int variant)
73
    {
74
    float D = variant==0 ? 0.0f : (float)Math.tan( (Math.PI*GHOST_ANGLE)/180 );
75

    
76
    return new float[][]
77
          {
78
              { 0.5f, 0.5f-D, 0.5f   },
79
              { 0.5f, 0.5f  ,-0.5f   },
80
              { 0.5f,-0.5f  , 0.5f   },
81
              { 0.5f,-0.5f  ,-0.5f-D },
82
              {-0.5f, 0.5f-D, 0.5f   },
83
              {-0.5f, 0.5f  ,-0.5f   },
84
              {-0.5f,-0.5f  , 0.5f   },
85
              {-0.5f,-0.5f  ,-0.5f-D },
86
          };
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

    
91
  public ObjectShape getObjectShape(int variant)
92
    {
93
    int[][] indices =
94
          {
95
              {2,3,1,0},
96
              {7,6,4,5},
97
              {4,0,1,5},
98
              {7,3,2,6},
99
              {6,2,0,4},
100
              {3,7,5,1}
101
          };
102

    
103
    return new ObjectShape(getVertices(variant), indices);
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public ObjectFaceShape getObjectFaceShape(int variant)
109
    {
110
    float height = isInIconMode() ? 0.001f : 0.045f;
111
    int angle = 35;
112
    float R = 0.5f;
113
    float S = 0.7f;
114

    
115
    float[][] bands  =
116
         {
117
             {height,angle,R,S,6,2,2},
118
             {0.001f,angle,R,S,6,2,2},
119
         };
120

    
121
    int[] indices = new int[] {1,0,1,0,1,0};
122

    
123
    return new ObjectFaceShape(bands,indices, null);
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
  public ObjectVertexEffects getVertexEffects(int variant)
129
    {
130
    if( variant==0 )
131
      {
132
      float[][] corners = {{0.036f, 0.12f}};
133
      float[][] centers = {{0.0f, 0.0f, 0.0f}};
134
      int[] indices = {0, 0, 0, 0, 0, 0, 0, 0};
135
      return FactoryCubit.generateVertexEffect(getVertices(variant), corners, indices, centers, indices);
136
      }
137
    else
138
      {
139
      float[][] corners = {{0.036f, 0.12f}};
140
      float[][] centers = {{0,0,0}};
141
      int[] indices = {0,0,0,0,0,0,0,0};
142
      float[][] vertices = getVertices(variant);
143
      int numEff = vertices.length+1;
144
      String[] names = new String[numEff];
145
      float[][] vars = new float[numEff][];
146
      float[][] cents= new float[numEff][];
147
      float[][] regs = new float[numEff][];
148
      boolean[] uses = new boolean[numEff];
149
      String NAME = EffectName.DEFORM.name();
150

    
151
      for(int i=0; i<numEff-1; i++)
152
        {
153
        int index = indices[i];
154

    
155
        float[] ce = centers[index];
156
        float[] ve = vertices[i];
157
        float S = corners[index][0];
158
        float R = corners[index][1];
159

    
160
        float CX = ve[0];
161
        float CY = ve[1];
162
        float CZ = ve[2];
163
        float X = S*(ce[0]-CX);
164
        float Y = S*(ce[1]-CY);
165
        float Z = S*(ce[2]-CZ);
166

    
167
        names[i]= NAME;
168
        vars[i] = new float[] { 0, X,Y,Z, 1 };
169
        cents[i]= new float[] { CX, CY, CZ };
170
        regs[i] = new float[] { 0,0,0, R };
171
        uses[i] = false;
172
        }
173

    
174
      names[numEff-1] = EffectName.VERTEX_ROTATE.name();
175
      vars[numEff-1]  = new float[] { 0,-GHOST_ANGLE,1,0,0 };  // see VertexEffect.constructEffect
176
      cents[numEff-1] = new float[] { 0.0f,0.5f,-0.5f };
177
      regs[numEff-1]  = new float[] { 0,0,0,0 };
178
      uses[numEff-1]  = true;
179

    
180
      return new ObjectVertexEffects(names,vars,cents,regs,uses);
181
      }
182
    }
183

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

    
186
  public float[][] getCubitPositions(int[] numLayers)
187
    {
188
    if( mPosition==null )
189
      {
190
      final float D = 0.5f;
191

    
192
      mPosition = new float[][]
193
        {
194
          {-3*D,-D,-D },
195
          {-3*D,-D, D },
196
          {-3*D, D,-D },
197
          {-3*D, D, D },
198
          {  -D,-D,-D },
199
          {  -D,-D, D },
200
          {  -D, D,-D },
201
          {  -D, D, D },
202

    
203
          {   D,-D,-D },
204
          {   D,-D, D },
205
          {   D, D,-D },
206
          {   D, D, D },
207
          { 3*D,-D,-D },
208
          { 3*D,-D, D },
209
          { 3*D, D,-D },
210
          { 3*D, D, D },
211
        };
212
      }
213

    
214
    return mPosition;
215
    }
216

    
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

    
219
  public Static4D getCubitQuats(int cubit, int[] numLayers)
220
    {
221
    if( mQuatIndex==null ) mQuatIndex = new int[] { 0,1,3,2,0,1,3,2, 3,0,2,1,3,0,2,1 };
222
    return mObjectQuats[mQuatIndex[cubit]];
223
    }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
  public int getNumCubitVariants(int[] numLayers)
228
    {
229
    return 2;
230
    }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
  public int getCubitVariant(int cubit, int[] numLayers)
235
    {
236
    return cubit<8 ? 0:1;
237
    }
238

    
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

    
241
  public float[][] getCuts(int[] numLayers)
242
    {
243
    if( mCuts==null )
244
      {
245
      float[] c1 = {-1,0,1};
246
      float[] c2 = {0};
247
      mCuts = new float[][] { c1,c2,c2 };
248
      }
249

    
250
    return mCuts;
251
    }
252

    
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

    
255
  public boolean[][] getLayerRotatable(int[] numLayers)
256
    {
257
    boolean[] r1 = new boolean[] {true,true,true,true};
258
    boolean[] r2 = new boolean[] {true,true};
259
    return new boolean[][] { r1,r2,r2 };
260
    }
261

    
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

    
264
  public int getTouchControlType()
265
    {
266
    return TC_CHANGING_SHAPEMOD;
267
    }
268

    
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270

    
271
  public int getTouchControlSplit()
272
    {
273
    return TYPE_NOT_SPLIT;
274
    }
275

    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

    
278
  public int[][][] getEnabled()
279
    {
280
    return new int[][][] { {{1,2}},{{1,2}},{{0,2}},{{0,2}},{{0,1}},{{0,1}} };
281
    }
282

    
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

    
285
  public float[] getDist3D(int[] numLayers)
286
    {
287
    float x = numLayers[0];
288
    float y = numLayers[1];
289
    float z = numLayers[2];
290
    float a = (x+y+z)/1.5f;
291

    
292
    return new float[] {x/a,x/a,y/a,y/a,z/a,z/a};
293
    }
294

    
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296

    
297
  public Static3D[] getFaceAxis()
298
    {
299
    return TouchControlCuboids.FACE_AXIS;
300
    }
301

    
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303

    
304
  public float getStickerRadius()
305
    {
306
    return 0.10f;
307
    }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

    
311
  public float getStickerStroke()
312
    {
313
    return isInIconMode() ? 0.16f : 0.08f ;
314
    }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

    
318
  public float[][][] getStickerAngles()
319
    {
320
    return null;
321
    }
322

    
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324
// PUBLIC API
325

    
326
  public Static3D[] getRotationAxis()
327
    {
328
    return ROT_AXIS;
329
    }
330

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

    
333
  public String getShortName()
334
    {
335
    return "TEST_GHO";
336
    }
337

    
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

    
340
  public int[][] getBasicAngles()
341
    {
342
    if( mBasicAngle==null )
343
      {
344
      int[] a1 = {4,4,4,4};
345
      int[] a2 = {2,2};
346
      mBasicAngle = new int[][] { a1,a2,a2 };
347
      }
348
    return mBasicAngle;
349
    }
350

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

    
353
  public String[][] getTutorials()
354
    {
355
    return null;
356
    }
357
}
(54-54/59)