Project

General

Profile

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

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

1 e7569064 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 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 10a842b0 Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_MIRROR;
13 f925d455 Leszek Koltunski
14
import org.distorted.library.effect.EffectName;
15 e7569064 Leszek Koltunski
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17 f925d455 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectFaceShape;
18
import org.distorted.objectlib.helpers.ObjectShape;
19 ae9d9227 leszek
import org.distorted.objectlib.metadata.Metadata;
20 f925d455 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectVertexEffects;
21 cf93ea4e Leszek Koltunski
import org.distorted.objectlib.main.InitAssets;
22 361fd0de leszek
import org.distorted.objectlib.metadata.ListObjects;
23 e7569064 Leszek Koltunski
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25
26
public class TwistyCamouflage extends TwistyBandagedAbstract
27
{
28 51d14921 Leszek Koltunski
  private static final float SIZE_CORRECTION = 1.18f;
29 10a842b0 Leszek Koltunski
30 e7569064 Leszek Koltunski
  public static final float[][] CAM_333 = new float[][]
31
    {
32 f925d455 Leszek Koltunski
      getCenters( -1.0f, 1.0f, 1.0f, 2, 2, 2),
33
34
      getCenters(  0.5f, 1.0f, 1.0f, 1, 2, 2),
35
      getCenters(  1.5f, 1.0f, 1.0f, 1, 2, 2),
36
      getCenters( -1.0f,-0.5f, 1.0f, 2, 1, 2),
37
      getCenters( -1.0f,-1.5f, 1.0f, 2, 1, 2),
38
      getCenters( -1.0f, 1.0f,-0.5f, 2, 2, 1),
39
      getCenters( -1.0f, 1.0f,-1.5f, 2, 2, 1),
40
41
      getCenters( -1.0f,-1.5f,-0.5f, 2, 1, 1),
42
      getCenters( -1.0f,-1.5f,-1.5f, 2, 1, 1),
43 539b46ea Leszek Koltunski
      getCenters( -1.5f,-0.5f,-0.5f, 1, 1, 1), // center
44 f925d455 Leszek Koltunski
      getCenters( -1.0f,-0.5f,-1.5f, 2, 1, 1),
45
      getCenters(  0.5f, 1.0f,-1.5f, 1, 2, 1),
46
      getCenters(  1.5f, 1.0f,-1.5f, 1, 2, 1),
47 539b46ea Leszek Koltunski
      getCenters(  0.5f, 1.5f,-0.5f, 1, 1, 1), // center
48 f925d455 Leszek Koltunski
      getCenters(  1.5f, 1.0f,-0.5f, 1, 2, 1),
49 539b46ea Leszek Koltunski
      getCenters(  0.5f,-0.5f, 1.5f, 1, 1, 1), // center
50 f925d455 Leszek Koltunski
      getCenters(  1.5f,-0.5f, 1.0f, 1, 1, 2),
51
      getCenters(  0.5f,-1.5f, 1.0f, 1, 1, 2),
52
      getCenters(  1.5f,-1.5f, 1.0f, 1, 1, 2),
53
54
      getCenters(  0.5f,-0.5f,-1.5f, 1, 1, 1),
55
      getCenters(  1.5f,-0.5f,-1.5f, 1, 1, 1),
56
      getCenters(  0.5f,-1.5f,-1.5f, 1, 1, 1),
57
      getCenters(  1.5f,-1.5f,-1.5f, 1, 1, 1),
58
      getCenters(  0.5f,-1.5f,-0.5f, 1, 1, 1),
59
      getCenters(  1.5f,-0.5f,-0.5f, 1, 1, 1),
60
      getCenters(  1.5f,-1.5f,-0.5f, 1, 1, 1),
61
    };
62
63
  private static final int[][] DIMS = new int[][]
64
    {
65
      {2,2,2},
66
      {1,2,2},
67
      {2,1,2},
68
      {2,2,1},
69
      {2,1,1},
70
      {1,2,1},
71
      {1,1,2},
72
      {1,1,1},
73 e7569064 Leszek Koltunski
    };
74
75 f925d455 Leszek Koltunski
  private static final float[][] OFFSETS = new float[][]
76
    {
77
      { 0.0f, 0.0f, 0.0f},
78
      { 0.5f, 0.0f, 0.0f},
79
      {-0.5f, 0.0f, 0.0f},
80
      { 0.0f, 0.5f, 0.0f},
81
      { 0.0f,-0.5f, 0.0f},
82
      { 0.0f, 0.0f, 0.5f},
83
      { 0.0f, 0.0f,-0.5f},
84
      { 0.0f,-0.5f,-0.5f},
85
      { 0.5f, 0.0f,-0.5f},
86
      { 0.5f,-0.5f, 0.0f},
87
      { 0.5f,-0.5f,-0.5f},
88
    };
89
90
  private int[] mDimsIndices, mOffsIndices;
91 539b46ea Leszek Koltunski
  private int[][] mEdges;
92 f925d455 Leszek Koltunski
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
95
  private static float[] getCenters( float x, float y, float z, int xd, int yd, int zd )
96
    {
97
    float XS = 0.5f*(1-xd) + x;
98
    float YS = 0.5f*(1-yd) + y;
99
    float ZS = 0.5f*(1-zd) + z;
100
101
    int index=0;
102
    float[] result = new float[3*xd*yd*zd];
103
104
    for(int i=0; i<xd; i++)
105
      for(int j=0; j<yd; j++)
106
        for(int k=0; k<zd; k++)
107
          {
108
          result[3*index  ] = XS+i;
109
          result[3*index+1] = YS+j;
110
          result[3*index+2] = ZS+k;
111
          index++;
112
          }
113
114
    return result;
115
    }
116
117 e7569064 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
118
119 ae9d9227 leszek
  public TwistyCamouflage(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
120 e7569064 Leszek Koltunski
    {
121 ae9d9227 leszek
    super(iconMode, SIZE_CORRECTION*(meta.getNumLayers()[0]+meta.getNumLayers()[1]+meta.getNumLayers()[2])/3.0f,
122
          quat, move, scale, meta, asset);
123 10a842b0 Leszek Koltunski
    }
124
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126
127
  @Override
128
  public int getInternalColor()
129
    {
130
    return 0xff333333;
131 e7569064 Leszek Koltunski
    }
132
133 7d41fc84 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
134
135
  public int[][] getScrambleEdges()
136
    {
137 539b46ea Leszek Koltunski
    if( mEdges==null )
138
      {
139
      mEdges = new int[][]
140
        {
141
          {0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0}
142
        };
143
      }
144
145
    return mEdges;
146
    }
147
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149
150
  @Override
151
  public int[][] getScrambleAlgorithms()
152
    {
153
    return new int[][]
154
      {
155
        // VTS' algorithm1: ('swap 2 edges and 2 pairs of centers')
156 ca4a3a68 Leszek Koltunski
        {2, 2, 1,  1, 1, 1,  0, 4, 1,  1, 1,-1,  0, 4,-1,
157
         1, 1, 1,  0, 4, 1,  1, 1,-1,  0, 4,-1,  2, 2,-1,
158
         0, 4, 1,  1, 1, 1,  0, 4,-1,  1, 1,-1,  0, 4, 1,
159
         1, 1, 1,  0, 4,-1,  1, 1,-1,  0, 4, 1,  0, 8, 1,
160
         1, 1, 2,  2, 1, 1,  1, 1,-2,  2, 1,-1,  1, 1, 2,
161
         0, 4,-1,  2, 2, 1,  0, 4, 1,  1, 1, 2,  2, 1, 1,
162
         1, 1,-2,  2, 1,-1,  1, 1, 2,  0, 4,-1,  2, 2,-2},
163 539b46ea Leszek Koltunski
164
        // algorithm1 rotated around the corner
165 ca4a3a68 Leszek Koltunski
        {1, 2, 1,  0, 4,-1,  2, 1,-1,  0, 4, 1,  2, 1, 1,
166
         0, 4,-1,  2, 1,-1,  0, 4, 1,  2, 1, 1,  1, 2,-1,
167
         2, 1,-1,  0, 4,-1,  2, 1, 1,  0, 4, 1,  2, 1,-1,
168
         0, 4,-1,  2, 1, 1,  0, 4, 1,  2, 2,-1,  2, 1,-1,
169
         0, 4,-2,  1, 1, 1,  0, 4, 2,  1, 1,-1,  0, 4,-2,
170
         2, 1, 1,  1, 2, 1,  2, 1,-1,  0, 4,-2,  1, 1, 1,
171
         0, 4, 2,  1, 1,-1,  0, 4,-2,  2, 1, 1,  1, 2,-2},
172 539b46ea Leszek Koltunski
173
        // algorithm1 rotated again around the corner
174 ca4a3a68 Leszek Koltunski
        {0, 4,-1,  2, 1, 1,  1, 1,-1,  2, 1,-1,  1, 1, 1,
175
         2, 1, 1,  1, 1,-1,  2, 1,-1,  1, 1, 1,  0, 4, 1,
176
         1, 1,-1,  2, 1, 1,  1, 1, 1,  2, 1,-1,  1, 1,-1,
177
         2, 1, 1,  1, 1, 1,  2, 1,-1,  1, 2,-1,  1, 1,-1,
178
         2, 1, 2,  0, 4,-1,  2, 1,-2,  0, 4, 1,  2, 1, 2,
179
         1, 1, 1,  0, 4,-1,  1, 1,-1,  2, 1, 2,  0, 4,-1,
180
         2, 1,-2,  0, 4, 1,  2, 1, 2,  1, 1, 1,  0, 4, 2},
181 539b46ea Leszek Koltunski
182
       // VTS' algorithm2: swap two 221 edges
183 ca4a3a68 Leszek Koltunski
        {2, 4, 1,  1, 1, 1,  2, 4,-1,  1, 1,-1,  1, 4, 1,
184
         2, 4,-2,  0, 4,-1,  2, 4, 2,  0, 4, 1,  2, 4,-2,
185
         1, 4,-1,  0, 4,-1,  1, 4, 1,  2, 4,-2,  0, 4,-1,
186
         2, 4, 2,  0, 4, 1,  2, 4,-2,  1, 4,-1,  0, 4,-2,
187
         1, 1, 1,  2, 4, 1,  1, 1,-1,  2, 4,-1},
188 539b46ea Leszek Koltunski
189
       // algorithm2 rotated around the corner
190 ca4a3a68 Leszek Koltunski
        {0, 1,-1,  2, 1, 1,  0, 1, 1,  2, 1,-1,  2, 4, 1,
191
         0, 1, 2,  1, 1, 1,  0, 1,-2,  1, 1,-1,  0, 1, 2,
192
         2, 4,-1,  1, 2, 1,  2, 4, 1,  0, 1, 2,  1, 1, 1,
193
         0, 1,-2,  1, 1,-1,  0, 1, 2,  2, 4,-1,  1, 2, 2,
194
         2, 1, 1,  0, 1,-1,  2, 1,-1,  0, 1, 1},
195 539b46ea Leszek Koltunski
196
       // algorithm2 rotated again around the corner
197 ca4a3a68 Leszek Koltunski
        {1, 4, 1,  0, 4,-1,  1, 4,-1,  0, 4, 1,  0, 1,-1,
198
         1, 4,-2,  2, 1, 1,  1, 4, 2,  2, 1,-1,  1, 4,-2,
199
         0, 1, 1,  2, 2, 1,  0, 1,-1,  1, 4,-2,  2, 1, 1,
200
         1, 4, 2,  2, 1,-1,  1, 4,-2,  0, 1, 1,  2, 2, 2,
201
         0, 4,-1,  1, 4, 1,  0, 4, 1,  1, 4,-1},
202 539b46ea Leszek Koltunski
203
       // VTS' algorithm3: swap two 221 blocks
204 ca4a3a68 Leszek Koltunski
        {2, 4,-2,  0, 4,-1,  2, 4, 2,  0, 4, 1,  2, 4,-2,
205
         1, 4,-1,  0, 4,-1,  1, 4, 1,  2, 4,-2,  0, 4,-1,
206
         2, 4, 2,  0, 4, 1,  2, 4,-2,  1, 4,-1,  0, 4, 2,
207
         1, 4, 1 },
208 539b46ea Leszek Koltunski
209
       // algorithm3 rotated around the corner
210 ca4a3a68 Leszek Koltunski
        {0, 1,-2,  1, 1, 1,  0, 1,-2,  1, 1,-1,  0, 1, 2,
211
         2, 4,-1,  1, 2, 1,  2, 4, 1,  0, 1, 2,  1, 1, 1,
212
         0, 1,-2,  1, 1,-1,  0, 1, 2,  2, 4,-1,  1, 4,-2,
213
         2, 4, 1 },
214 539b46ea Leszek Koltunski
215
       // algorithm3 rotated again around the corner
216 ca4a3a68 Leszek Koltunski
        {1, 4, 2,  2, 1, 1,  1, 4, 2,  2, 1,-1,  1, 4,-2,
217
         0, 1, 1,  2, 2, 1,  0, 1,-1,  1, 4,-2,  2, 1, 1,
218
         1, 4, 2,  2, 1,-1,  1, 4,-2,  0, 1, 1,  2, 2,-2,
219
         0, 1,-1 }
220 539b46ea Leszek Koltunski
      };
221 7d41fc84 Leszek Koltunski
    }
222
223 e7569064 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
224
225 f925d455 Leszek Koltunski
  private int getDimsIndex(int variant)
226 e7569064 Leszek Koltunski
    {
227 ae9d9227 leszek
    if( mPosition==null ) mPosition = getMetadata().getPos();
228 e7569064 Leszek Koltunski
229
    if( mPosition==CAM_333 )
230
      {
231 f925d455 Leszek Koltunski
      if( mDimsIndices==null ) mDimsIndices = new int[]
232
                                   { 0,
233
                                     1,0,2,0,3,0,
234 539b46ea Leszek Koltunski
                                     3,0,7,2,1,0,7,3,7,2,1,0,
235 f925d455 Leszek Koltunski
                                     6,2,1,0,5,4,3 };
236 e7569064 Leszek Koltunski
      }
237
238 f925d455 Leszek Koltunski
    return mDimsIndices[variant];
239
    }
240
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242
243
  private int getOffsetsIndex(int variant)
244
    {
245 ae9d9227 leszek
    if( mPosition==null ) mPosition = getMetadata().getPos();
246 f925d455 Leszek Koltunski
247
    if( mPosition==CAM_333 )
248
      {
249
      if( mOffsIndices==null ) mOffsIndices = new int[]
250
                                   { 0,
251
                                     0,1,0,4,0,6,
252
                                     4,7,0,6,6,8,0,1,0,1,4,9,
253
                                     6,8,7,10,4,1,9 };
254
      }
255
256
    return mOffsIndices[variant];
257
    }
258
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260
261
  private float[][] getVertices(int variant)
262
    {
263
    int indexD = getDimsIndex(variant);
264
265
    int X=DIMS[indexD][0];
266
    int Y=DIMS[indexD][1];
267
    int Z=DIMS[indexD][2];
268
269
    int indexO = getOffsetsIndex(variant);
270
271
    float XF = OFFSETS[indexO][0];
272
    float YF = OFFSETS[indexO][1];
273
    float ZF = OFFSETS[indexO][2];
274
275
    return new float[][]
276
      {
277
        { 0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF},
278
        { 0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF},
279
        { 0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF},
280
        { 0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF},
281
        {-0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF},
282
        {-0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF},
283
        {-0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF},
284
        {-0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF}
285
      };
286 e7569064 Leszek Koltunski
    }
287
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289
// PUBLIC API
290
291 f925d455 Leszek Koltunski
  public int getTouchControlType()
292
    {
293 10a842b0 Leszek Koltunski
    return TC_CHANGING_MIRROR;
294
    }
295
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297
298
  public float[] getDist3D(int[] numLayers)
299
    {
300
    float x = numLayers[0];
301
    float y = numLayers[1];
302
    float z = numLayers[2];
303
    float a = SIZE_CORRECTION*(x+y+z)/1.5f;
304
305
    return new float[] {(x+2)/a,x/a,y/a,(y+2)/a,z/a,(z+2)/a};
306 f925d455 Leszek Koltunski
    }
307
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309
310
  public Static4D getCubitQuats(int cubit, int[] numLayers)
311
    {
312
    return mObjectQuats[0];
313
    }
314
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316
317
  public ObjectShape getObjectShape(int variant)
318
    {
319
    int[][] indices =
320
        {
321
          {2,3,1,0},
322
          {7,6,4,5},
323
          {4,0,1,5},
324
          {7,3,2,6},
325
          {6,2,0,4},
326
          {3,7,5,1},
327
        };
328
329
    return new ObjectShape( getVertices(variant), indices);
330
    }
331
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333
334
  public ObjectFaceShape getObjectFaceShape(int variant)
335
    {
336
    int index = getDimsIndex(variant);
337
338
    int X = DIMS[index][0];
339
    int Y = DIMS[index][1];
340
    int Z = DIMS[index][2];
341
342
    float height     = isInIconMode() ? 0.001f : 0.03f;
343
    int[] bandIndices= { 0,0,1,1,2,2 };
344
345
    int maxXY = Math.max(X,Y);
346
    int maxXZ = Math.max(X,Z);
347
    int maxYZ = Math.max(Y,Z);
348
349 347f6cc1 Leszek Koltunski
    int angle = 20;
350
    float R = 0.80f;
351
    float S = 0.30f;
352 f925d455 Leszek Koltunski
    float N = 4;
353
354
    float[][] bands =
355
        {
356
          {height/maxYZ,angle,R,S,N,0,0},
357
          {height/maxXZ,angle,R,S,N,0,0},
358
          {height/maxXY,angle,R,S,N,0,0}
359
        };
360
361
    return new ObjectFaceShape(bands,bandIndices,null);
362
    }
363
364
///////////////////////////////////////////////////////////////////////////////////////////////////
365
366
  public ObjectVertexEffects getVertexEffects(int variant)
367
    {
368
    boolean round = false;
369
    float[][] vertices = getVertices(variant);
370
    float A = -0.03f;
371
372
    float[][] variables =
373
        {
374
          { 0, A, A, A, 1  },
375
          { 0, A, A,-A, 1  },
376
          { 0, A,-A, A, 1  },
377
          { 0, A,-A,-A, 1  },
378
          { 0,-A, A, A, 1  },
379
          { 0,-A, A,-A, 1  },
380
          { 0,-A,-A, A, 1  },
381
          { 0,-A,-A,-A, 1  },
382
        };
383
384
    String name = EffectName.DEFORM.name();
385
    float[] reg = {0,0,0,0.10f};
386
387
    String[] names = {name,name,name,name,name,name,name,name};
388
    float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg};
389
    boolean[] uses = {round,round,round,round,round,round,round,round};
390
391
    return new ObjectVertexEffects(names,variables,vertices,regions,uses);
392
    }
393
394
///////////////////////////////////////////////////////////////////////////////////////////////////
395
396
  public int getCubitVariant(int cubit, int[] numLayers)
397
    {
398 ae9d9227 leszek
    if( mPosition==null ) mPosition = getMetadata().getPos();
399 f925d455 Leszek Koltunski
400
    if( mPosition==CAM_333 )
401
      {
402
      return cubit;
403
      }
404
405
    return 0;
406
    }
407
408
///////////////////////////////////////////////////////////////////////////////////////////////////
409
410
  public int getNumCubitVariants(int[] numLayers)
411
    {
412 ae9d9227 leszek
    if( mPosition==null ) mPosition = getMetadata().getPos();
413 f925d455 Leszek Koltunski
414
    if( mPosition==CAM_333 ) return 26;
415
416
    return 0;
417
    }
418
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420
421
  public float getStickerRadius()
422
    {
423
    return 0.18f;
424
    }
425
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427
428
  public float getStickerStroke()
429
    {
430 51d14921 Leszek Koltunski
    return isInIconMode() ? 0.30f : 0.18f;
431 f925d455 Leszek Koltunski
    }
432
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434
435 e7569064 Leszek Koltunski
  public String getShortName()
436
    {
437 ae9d9227 leszek
    if( mPosition==null ) mPosition = getMetadata().getPos();
438 e7569064 Leszek Koltunski
439 361fd0de leszek
    if( mPosition==CAM_333 ) return ListObjects.CA_333.name();
440 e7569064 Leszek Koltunski
441
    return null;
442
    }
443
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445
446
  public String[][] getTutorials()
447
    {
448 ae9d9227 leszek
    if( mPosition==null ) mPosition = getMetadata().getPos();
449 e7569064 Leszek Koltunski
450
    if( mPosition==CAM_333 )
451
      {
452
      return new String[][]{
453
                            {"gb","f9zmpCfg25k","3x3x3 Camouflage Part 1","Superantoniovivaldi"},
454
                            {"gb","O8pGyi5Juxk","3x3x3 Camouflage Part 2","Superantoniovivaldi"},
455
                            {"es","V1RPBIzEwp4","Tutorial 3x3 Camouflage","Manu rubiks"},
456
                            {"ru","DRGNOSw5pPc","Как собрать 3х3х3 camouflage","Илья Топор-Гилка"},
457
                            {"fr","9BfI1Fcbcl8","Résolution du Camouflage Cube","Skieur Cubb"},
458
                            {"pl","uEVvR2jDdI0","Camouflage 3x3x3 Tutorial","MrUK"},
459
                           };
460
      }
461
462
    return null;
463
    }
464
}