Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyGhostTest.java @ a0ef8a1d

1 5df97ecb leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
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 a0ef8a1d leszek
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_MIRROR;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD;
14 5df97ecb leszek
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CUBOID;
15
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
16
17
import org.distorted.library.effect.EffectName;
18
import org.distorted.library.type.Static3D;
19
import org.distorted.library.type.Static4D;
20
import org.distorted.objectlib.helpers.FactoryCubit;
21
import org.distorted.objectlib.helpers.ObjectFaceShape;
22
import org.distorted.objectlib.helpers.ObjectShape;
23
import org.distorted.objectlib.helpers.ObjectVertexEffects;
24
import org.distorted.objectlib.main.InitAssets;
25
import org.distorted.objectlib.main.InitData;
26
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
27
import org.distorted.objectlib.shape.ShapeHexahedron;
28
import org.distorted.objectlib.signature.ObjectSignature;
29
import org.distorted.objectlib.touchcontrol.TouchControlCuboids;
30
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33
public class TwistyGhostTest extends ShapeHexahedron
34
{
35
  private static final int GHOST_ANGLE = 30;
36
37
  static final Static3D[] ROT_AXIS = new Static3D[]
38
         {
39
           new Static3D(1,0,0),
40
           new Static3D(0,1,0),
41
           new Static3D(0,0,1)
42
         };
43
44
  private int[][] mEdges;
45
  private float[][] mCuts;
46
  private int[][] mBasicAngle;
47
  private int[] mQuatIndex;
48
  private float[][] mPosition;
49
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
52
  public TwistyGhostTest(int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
53
    {
54
    super(iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
55
    }
56
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58
59
  @Override
60
  public int getGhostAngle()
61
    {
62
    return GHOST_ANGLE;
63
    }
64
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
67
  public int[][] getScrambleEdges()
68
    {
69
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
70
    return mEdges;
71
    }
72
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
75
  private float[][] getVertices(int variant)
76
    {
77
    float D = variant==0 ? 0.0f : (float)Math.tan( (Math.PI*GHOST_ANGLE)/180 );
78
79
    return new float[][]
80
          {
81
              { 0.5f, 0.5f-D, 0.5f   },
82
              { 0.5f, 0.5f  ,-0.5f   },
83
              { 0.5f,-0.5f  , 0.5f   },
84
              { 0.5f,-0.5f  ,-0.5f-D },
85
              {-0.5f, 0.5f-D, 0.5f   },
86
              {-0.5f, 0.5f  ,-0.5f   },
87
              {-0.5f,-0.5f  , 0.5f   },
88
              {-0.5f,-0.5f  ,-0.5f-D },
89
          };
90
    }
91
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93
94
  public ObjectShape getObjectShape(int variant)
95
    {
96
    int[][] indices =
97
          {
98
              {2,3,1,0},
99
              {7,6,4,5},
100
              {4,0,1,5},
101
              {7,3,2,6},
102
              {6,2,0,4},
103
              {3,7,5,1}
104
          };
105
106
    return new ObjectShape(getVertices(variant), indices);
107
    }
108
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
111
  public ObjectFaceShape getObjectFaceShape(int variant)
112
    {
113
    float height = isInIconMode() ? 0.001f : 0.045f;
114
    int angle = 35;
115
    float R = 0.5f;
116
    float S = 0.7f;
117
118
    float[][] bands  =
119
         {
120
             {height,angle,R,S,6,2,2},
121
             {0.001f,angle,R,S,6,2,2},
122
         };
123
124
    int[] indices = new int[] {1,0,1,0,1,0};
125
126
    return new ObjectFaceShape(bands,indices, null);
127
    }
128
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130
131
  public ObjectVertexEffects getVertexEffects(int variant)
132
    {
133
    if( variant==0 )
134
      {
135
      float[][] corners = {{0.036f, 0.12f}};
136
      float[][] centers = {{0.0f, 0.0f, 0.0f}};
137
      int[] indices = {0, 0, 0, 0, 0, 0, 0, 0};
138
      return FactoryCubit.generateVertexEffect(getVertices(variant), corners, indices, centers, indices);
139
      }
140
    else
141
      {
142
      float[][] corners = {{0.036f, 0.12f}};
143
      float[][] centers = {{0,0,0}};
144
      int[] indices = {0,0,0,0,0,0,0,0};
145
      float[][] vertices = getVertices(variant);
146
      int numEff = vertices.length+1;
147
      String[] names = new String[numEff];
148
      float[][] vars = new float[numEff][];
149
      float[][] cents= new float[numEff][];
150
      float[][] regs = new float[numEff][];
151
      boolean[] uses = new boolean[numEff];
152
      String NAME = EffectName.DEFORM.name();
153
154
      for(int i=0; i<numEff-1; i++)
155
        {
156
        int index = indices[i];
157
158
        float[] ce = centers[index];
159
        float[] ve = vertices[i];
160
        float S = corners[index][0];
161
        float R = corners[index][1];
162
163
        float CX = ve[0];
164
        float CY = ve[1];
165
        float CZ = ve[2];
166
        float X = S*(ce[0]-CX);
167
        float Y = S*(ce[1]-CY);
168
        float Z = S*(ce[2]-CZ);
169
170
        names[i]= NAME;
171
        vars[i] = new float[] { 0, X,Y,Z, 1 };
172
        cents[i]= new float[] { CX, CY, CZ };
173
        regs[i] = new float[] { 0,0,0, R };
174
        uses[i] = false;
175
        }
176
177
      names[numEff-1] = EffectName.VERTEX_ROTATE.name();
178
      vars[numEff-1]  = new float[] { 0,-GHOST_ANGLE,1,0,0 };  // see VertexEffect.constructEffect
179
      cents[numEff-1] = new float[] { 0.0f,0.5f,-0.5f };
180
      regs[numEff-1]  = new float[] { 0,0,0,0 };
181
      uses[numEff-1]  = true;
182
183
      return new ObjectVertexEffects(names,vars,cents,regs,uses);
184
      }
185
    }
186
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188
189
  public float[][] getCubitPositions(int[] numLayers)
190
    {
191
    if( mPosition==null )
192
      {
193
      final float D = 0.5f;
194
195
      mPosition = new float[][]
196
        {
197
          {-D,-D,-D },
198
          {-D,-D, D },
199
          {-D, D,-D },
200
          {-D, D, D },
201
202
          { D,-D,-D },
203
          { D,-D, D },
204
          { D, D,-D },
205
          { D, D, D },
206
        };
207
      }
208
209
    return mPosition;
210
    }
211
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213
214
  public Static4D getCubitQuats(int cubit, int[] numLayers)
215
    {
216
    if( mQuatIndex==null ) mQuatIndex = new int[] { 0,1,3,2,3,0,2,1 };
217
    return mObjectQuats[mQuatIndex[cubit]];
218
    }
219
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221
222
  public int getNumCubitVariants(int[] numLayers)
223
    {
224
    return 2;
225
    }
226
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228
229
  public int getCubitVariant(int cubit, int[] numLayers)
230
    {
231
    return cubit<4 ? 0:1;
232
    }
233
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235
236
  public float[][] getCuts(int[] numLayers)
237
    {
238
    if( mCuts==null )
239
      {
240
      float[] c = {0};
241
      mCuts = new float[][] { c,c,c };
242
      }
243
244
    return mCuts;
245
    }
246
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248
249
  public boolean[][] getLayerRotatable(int[] numLayers)
250
    {
251
    boolean[] r = new boolean[] {true,true};
252
    return new boolean[][] { r,r,r };
253
    }
254
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256
257
  public int getTouchControlType()
258
    {
259 a0ef8a1d leszek
    return TC_CHANGING_SHAPEMOD;
260 5df97ecb leszek
    }
261
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263
264
  public int getTouchControlSplit()
265
    {
266
    return TYPE_NOT_SPLIT;
267
    }
268
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270
271
  public int[][][] getEnabled()
272
    {
273
    return new int[][][] { {{1,2}},{{1,2}},{{0,2}},{{0,2}},{{0,1}},{{0,1}} };
274
    }
275
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277
278
  public float[] getDist3D(int[] numLayers)
279
    {
280
    return new float[] { 0.5f,0.5f,0.5f,0.5f,0.5f,0.5f };
281
    }
282
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284
285
  public Static3D[] getFaceAxis()
286
    {
287
    return TouchControlCuboids.FACE_AXIS;
288
    }
289
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291
292
  public float getStickerRadius()
293
    {
294
    return 0.10f;
295
    }
296
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298
299
  public float getStickerStroke()
300
    {
301
    return isInIconMode() ? 0.16f : 0.08f ;
302
    }
303
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305
306
  public float[][][] getStickerAngles()
307
    {
308
    return null;
309
    }
310
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312
// PUBLIC API
313
314
  public Static3D[] getRotationAxis()
315
    {
316
    return ROT_AXIS;
317
    }
318
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320
321
  public String getShortName()
322
    {
323
    return "TEST";
324
    }
325
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327
328
  public ObjectSignature getSignature()
329
    {
330
    return new ObjectSignature(1000);
331
    }
332
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334
335
  public int[][] getBasicAngles()
336
    {
337
    if( mBasicAngle==null )
338
      {
339
      int[] a = {4,4};
340
      mBasicAngle = new int[][] { a,a,a };
341
      }
342
    return mBasicAngle;
343
    }
344
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346
347
  public String getObjectName()
348
    {
349
    return "Ghost Test";
350
    }
351
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353
354
  public String getInventor()
355
    {
356
    return "Leszek";
357
    }
358
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360
361
  public int getYearOfInvention()
362
    {
363
    return 2023;
364
    }
365
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367
368
  public int getComplexity()
369
    {
370
    return 1;
371
    }
372
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374
375
  public String[][] getTutorials()
376
    {
377
    return null;
378
    }
379
}