Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyTestGhost.java @ 361fd0de

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.signature.ObjectSignature;
27
import org.distorted.objectlib.touchcontrol.TouchControlCuboids;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

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

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

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

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

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

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

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

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

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

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

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

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

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

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

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

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

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

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

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

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

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

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

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

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

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

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

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

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

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

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

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

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

    
215
    return mPosition;
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

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

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

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

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

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

    
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

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

    
251
    return mCuts;
252
    }
253

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

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

    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

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

    
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

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

    
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

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

    
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

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

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

    
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

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

    
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

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

    
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311

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

    
317
///////////////////////////////////////////////////////////////////////////////////////////////////
318

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

    
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325
// PUBLIC API
326

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

    
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

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

    
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340

    
341
  public ObjectSignature getSignature()
342
    {
343
    return new ObjectSignature(1000);
344
    }
345

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

    
348
  public int[][] getBasicAngles()
349
    {
350
    if( mBasicAngle==null )
351
      {
352
      int[] a1 = {4,4,4,4};
353
      int[] a2 = {2,2};
354
      mBasicAngle = new int[][] { a1,a2,a2 };
355
      }
356
    return mBasicAngle;
357
    }
358

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360

    
361
  public String getObjectName()
362
    {
363
    return "Ghost Test";
364
    }
365

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

    
368
  public String getInventor()
369
    {
370
    return "Leszek";
371
    }
372

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

    
375
  public int getYearOfInvention()
376
    {
377
    return 2023;
378
    }
379

    
380
///////////////////////////////////////////////////////////////////////////////////////////////////
381

    
382
  public float getComplexity()
383
    {
384
    return 1;
385
    }
386

    
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388

    
389
  public String[][] getTutorials()
390
    {
391
    return null;
392
    }
393
}
(52-52/57)