Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_MIRROR;
13

    
14
import org.distorted.library.effect.EffectName;
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17
import org.distorted.objectlib.helpers.ObjectFaceShape;
18
import org.distorted.objectlib.helpers.ObjectShape;
19
import org.distorted.objectlib.helpers.ObjectSignature;
20
import org.distorted.objectlib.helpers.ObjectVertexEffects;
21
import org.distorted.objectlib.main.InitAssets;
22
import org.distorted.objectlib.main.InitData;
23
import org.distorted.objectlib.main.ObjectSignatures;
24
import org.distorted.objectlib.main.ObjectType;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

    
28
public class TwistyCamouflage extends TwistyBandagedAbstract
29
{
30
  private static final float SIZE_CORRECTION = 1.18f;
31

    
32
  public static final float[][] CAM_333 = new float[][]
33
    {
34
      getCenters( -1.0f, 1.0f, 1.0f, 2, 2, 2),
35

    
36
      getCenters(  0.5f, 1.0f, 1.0f, 1, 2, 2),
37
      getCenters(  1.5f, 1.0f, 1.0f, 1, 2, 2),
38
      getCenters( -1.0f,-0.5f, 1.0f, 2, 1, 2),
39
      getCenters( -1.0f,-1.5f, 1.0f, 2, 1, 2),
40
      getCenters( -1.0f, 1.0f,-0.5f, 2, 2, 1),
41
      getCenters( -1.0f, 1.0f,-1.5f, 2, 2, 1),
42

    
43
      getCenters( -1.0f,-1.5f,-0.5f, 2, 1, 1),
44
      getCenters( -1.0f,-1.5f,-1.5f, 2, 1, 1),
45
      getCenters( -1.5f,-0.5f,-0.5f, 1, 1, 1), // center
46
      getCenters( -1.0f,-0.5f,-1.5f, 2, 1, 1),
47
      getCenters(  0.5f, 1.0f,-1.5f, 1, 2, 1),
48
      getCenters(  1.5f, 1.0f,-1.5f, 1, 2, 1),
49
      getCenters(  0.5f, 1.5f,-0.5f, 1, 1, 1), // center
50
      getCenters(  1.5f, 1.0f,-0.5f, 1, 2, 1),
51
      getCenters(  0.5f,-0.5f, 1.5f, 1, 1, 1), // center
52
      getCenters(  1.5f,-0.5f, 1.0f, 1, 1, 2),
53
      getCenters(  0.5f,-1.5f, 1.0f, 1, 1, 2),
54
      getCenters(  1.5f,-1.5f, 1.0f, 1, 1, 2),
55

    
56
      getCenters(  0.5f,-0.5f,-1.5f, 1, 1, 1),
57
      getCenters(  1.5f,-0.5f,-1.5f, 1, 1, 1),
58
      getCenters(  0.5f,-1.5f,-1.5f, 1, 1, 1),
59
      getCenters(  1.5f,-1.5f,-1.5f, 1, 1, 1),
60
      getCenters(  0.5f,-1.5f,-0.5f, 1, 1, 1),
61
      getCenters(  1.5f,-0.5f,-0.5f, 1, 1, 1),
62
      getCenters(  1.5f,-1.5f,-0.5f, 1, 1, 1),
63
    };
64

    
65
  private static final int[][] DIMS = new int[][]
66
    {
67
      {2,2,2},
68
      {1,2,2},
69
      {2,1,2},
70
      {2,2,1},
71
      {2,1,1},
72
      {1,2,1},
73
      {1,1,2},
74
      {1,1,1},
75
    };
76

    
77
  private static final float[][] OFFSETS = new float[][]
78
    {
79
      { 0.0f, 0.0f, 0.0f},
80
      { 0.5f, 0.0f, 0.0f},
81
      {-0.5f, 0.0f, 0.0f},
82
      { 0.0f, 0.5f, 0.0f},
83
      { 0.0f,-0.5f, 0.0f},
84
      { 0.0f, 0.0f, 0.5f},
85
      { 0.0f, 0.0f,-0.5f},
86
      { 0.0f,-0.5f,-0.5f},
87
      { 0.5f, 0.0f,-0.5f},
88
      { 0.5f,-0.5f, 0.0f},
89
      { 0.5f,-0.5f,-0.5f},
90
    };
91

    
92
  private int[] mDimsIndices, mOffsIndices;
93
  private int[][] mEdges;
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  private static float[] getCenters( float x, float y, float z, int xd, int yd, int zd )
98
    {
99
    float XS = 0.5f*(1-xd) + x;
100
    float YS = 0.5f*(1-yd) + y;
101
    float ZS = 0.5f*(1-zd) + z;
102

    
103
    int index=0;
104
    float[] result = new float[3*xd*yd*zd];
105

    
106
    for(int i=0; i<xd; i++)
107
      for(int j=0; j<yd; j++)
108
        for(int k=0; k<zd; k++)
109
          {
110
          result[3*index  ] = XS+i;
111
          result[3*index+1] = YS+j;
112
          result[3*index+2] = ZS+k;
113
          index++;
114
          }
115

    
116
    return result;
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
  public TwistyCamouflage(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
122
    {
123
    super(meshState, iconMode, SIZE_CORRECTION*(data.getNumLayers()[0]+data.getNumLayers()[1]+data.getNumLayers()[2])/3.0f,
124
          quat, move, scale, data, asset);
125
    }
126

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

    
129
  @Override
130
  public int getInternalColor()
131
    {
132
    return 0xff333333;
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  public int[][] getScrambleEdges()
138
    {
139
    if( mEdges==null )
140
      {
141
      mEdges = new int[][]
142
        {
143
          {0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0}
144
        };
145
      }
146

    
147
    return mEdges;
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  @Override
153
  public int[][] getScrambleAlgorithms()
154
    {
155
    return new int[][]
156
      {
157
        // VTS' algorithm1: ('swap 2 edges and 2 pairs of centers')
158
        {2, 2, 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,  2, 2,-1,
160
         0, 4, 1,  1, 1, 1,  0, 4,-1,  1, 1,-1,  0, 4, 1,
161
         1, 1, 1,  0, 4,-1,  1, 1,-1,  0, 4, 1,  0, 8, 1,
162
         1, 1, 2,  2, 1, 1,  1, 1,-2,  2, 1,-1,  1, 1, 2,
163
         0, 4,-1,  2, 2, 1,  0, 4, 1,  1, 1, 2,  2, 1, 1,
164
         1, 1,-2,  2, 1,-1,  1, 1, 2,  0, 4,-1,  2, 2,-2},
165

    
166
        // algorithm1 rotated around the corner
167
        {1, 2, 1,  0, 4,-1,  2, 1,-1,  0, 4, 1,  2, 1, 1,
168
         0, 4,-1,  2, 1,-1,  0, 4, 1,  2, 1, 1,  1, 2,-1,
169
         2, 1,-1,  0, 4,-1,  2, 1, 1,  0, 4, 1,  2, 1,-1,
170
         0, 4,-1,  2, 1, 1,  0, 4, 1,  2, 2,-1,  2, 1,-1,
171
         0, 4,-2,  1, 1, 1,  0, 4, 2,  1, 1,-1,  0, 4,-2,
172
         2, 1, 1,  1, 2, 1,  2, 1,-1,  0, 4,-2,  1, 1, 1,
173
         0, 4, 2,  1, 1,-1,  0, 4,-2,  2, 1, 1,  1, 2,-2},
174

    
175
        // algorithm1 rotated again around the corner
176
        {0, 4,-1,  2, 1, 1,  1, 1,-1,  2, 1,-1,  1, 1, 1,
177
         2, 1, 1,  1, 1,-1,  2, 1,-1,  1, 1, 1,  0, 4, 1,
178
         1, 1,-1,  2, 1, 1,  1, 1, 1,  2, 1,-1,  1, 1,-1,
179
         2, 1, 1,  1, 1, 1,  2, 1,-1,  1, 2,-1,  1, 1,-1,
180
         2, 1, 2,  0, 4,-1,  2, 1,-2,  0, 4, 1,  2, 1, 2,
181
         1, 1, 1,  0, 4,-1,  1, 1,-1,  2, 1, 2,  0, 4,-1,
182
         2, 1,-2,  0, 4, 1,  2, 1, 2,  1, 1, 1,  0, 4, 2},
183

    
184
       // VTS' algorithm2: swap two 221 edges
185
        {2, 4, 1,  1, 1, 1,  2, 4,-1,  1, 1,-1,  1, 4, 1,
186
         2, 4,-2,  0, 4,-1,  2, 4, 2,  0, 4, 1,  2, 4,-2,
187
         1, 4,-1,  0, 4,-1,  1, 4, 1,  2, 4,-2,  0, 4,-1,
188
         2, 4, 2,  0, 4, 1,  2, 4,-2,  1, 4,-1,  0, 4,-2,
189
         1, 1, 1,  2, 4, 1,  1, 1,-1,  2, 4,-1},
190

    
191
       // algorithm2 rotated around the corner
192
        {0, 1,-1,  2, 1, 1,  0, 1, 1,  2, 1,-1,  2, 4, 1,
193
         0, 1, 2,  1, 1, 1,  0, 1,-2,  1, 1,-1,  0, 1, 2,
194
         2, 4,-1,  1, 2, 1,  2, 4, 1,  0, 1, 2,  1, 1, 1,
195
         0, 1,-2,  1, 1,-1,  0, 1, 2,  2, 4,-1,  1, 2, 2,
196
         2, 1, 1,  0, 1,-1,  2, 1,-1,  0, 1, 1},
197

    
198
       // algorithm2 rotated again around the corner
199
        {1, 4, 1,  0, 4,-1,  1, 4,-1,  0, 4, 1,  0, 1,-1,
200
         1, 4,-2,  2, 1, 1,  1, 4, 2,  2, 1,-1,  1, 4,-2,
201
         0, 1, 1,  2, 2, 1,  0, 1,-1,  1, 4,-2,  2, 1, 1,
202
         1, 4, 2,  2, 1,-1,  1, 4,-2,  0, 1, 1,  2, 2, 2,
203
         0, 4,-1,  1, 4, 1,  0, 4, 1,  1, 4,-1},
204

    
205
       // VTS' algorithm3: swap two 221 blocks
206
        {2, 4,-2,  0, 4,-1,  2, 4, 2,  0, 4, 1,  2, 4,-2,
207
         1, 4,-1,  0, 4,-1,  1, 4, 1,  2, 4,-2,  0, 4,-1,
208
         2, 4, 2,  0, 4, 1,  2, 4,-2,  1, 4,-1,  0, 4, 2,
209
         1, 4, 1 },
210

    
211
       // algorithm3 rotated around the corner
212
        {0, 1,-2,  1, 1, 1,  0, 1,-2,  1, 1,-1,  0, 1, 2,
213
         2, 4,-1,  1, 2, 1,  2, 4, 1,  0, 1, 2,  1, 1, 1,
214
         0, 1,-2,  1, 1,-1,  0, 1, 2,  2, 4,-1,  1, 4,-2,
215
         2, 4, 1 },
216

    
217
       // algorithm3 rotated again around the corner
218
        {1, 4, 2,  2, 1, 1,  1, 4, 2,  2, 1,-1,  1, 4,-2,
219
         0, 1, 1,  2, 2, 1,  0, 1,-1,  1, 4,-2,  2, 1, 1,
220
         1, 4, 2,  2, 1,-1,  1, 4,-2,  0, 1, 1,  2, 2,-2,
221
         0, 1,-1 }
222
      };
223
    }
224

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

    
227
  private int getDimsIndex(int variant)
228
    {
229
    if( mPosition==null ) mPosition = getInitData().getPos();
230

    
231
    if( mPosition==CAM_333 )
232
      {
233
      if( mDimsIndices==null ) mDimsIndices = new int[]
234
                                   { 0,
235
                                     1,0,2,0,3,0,
236
                                     3,0,7,2,1,0,7,3,7,2,1,0,
237
                                     6,2,1,0,5,4,3 };
238
      }
239

    
240
    return mDimsIndices[variant];
241
    }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

    
245
  private int getOffsetsIndex(int variant)
246
    {
247
    if( mPosition==null ) mPosition = getInitData().getPos();
248

    
249
    if( mPosition==CAM_333 )
250
      {
251
      if( mOffsIndices==null ) mOffsIndices = new int[]
252
                                   { 0,
253
                                     0,1,0,4,0,6,
254
                                     4,7,0,6,6,8,0,1,0,1,4,9,
255
                                     6,8,7,10,4,1,9 };
256
      }
257

    
258
    return mOffsIndices[variant];
259
    }
260

    
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262

    
263
  private float[][] getVertices(int variant)
264
    {
265
    int indexD = getDimsIndex(variant);
266

    
267
    int X=DIMS[indexD][0];
268
    int Y=DIMS[indexD][1];
269
    int Z=DIMS[indexD][2];
270

    
271
    int indexO = getOffsetsIndex(variant);
272

    
273
    float XF = OFFSETS[indexO][0];
274
    float YF = OFFSETS[indexO][1];
275
    float ZF = OFFSETS[indexO][2];
276

    
277
    return new float[][]
278
      {
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
        {-0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF},
286
        {-0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF}
287
      };
288
    }
289

    
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291
// PUBLIC API
292

    
293
  public int getTouchControlType()
294
    {
295
    return TC_CHANGING_MIRROR;
296
    }
297

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

    
300
  public float[] getDist3D(int[] numLayers)
301
    {
302
    float x = numLayers[0];
303
    float y = numLayers[1];
304
    float z = numLayers[2];
305
    float a = SIZE_CORRECTION*(x+y+z)/1.5f;
306

    
307
    return new float[] {(x+2)/a,x/a,y/a,(y+2)/a,z/a,(z+2)/a};
308
    }
309

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

    
312
  public Static4D getCubitQuats(int cubit, int[] numLayers)
313
    {
314
    return mObjectQuats[0];
315
    }
316

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

    
319
  public ObjectShape getObjectShape(int variant)
320
    {
321
    int[][] indices =
322
        {
323
          {2,3,1,0},
324
          {7,6,4,5},
325
          {4,0,1,5},
326
          {7,3,2,6},
327
          {6,2,0,4},
328
          {3,7,5,1},
329
        };
330

    
331
    return new ObjectShape( getVertices(variant), indices);
332
    }
333

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

    
336
  public ObjectFaceShape getObjectFaceShape(int variant)
337
    {
338
    int index = getDimsIndex(variant);
339

    
340
    int X = DIMS[index][0];
341
    int Y = DIMS[index][1];
342
    int Z = DIMS[index][2];
343

    
344
    float height     = isInIconMode() ? 0.001f : 0.03f;
345
    int[] bandIndices= { 0,0,1,1,2,2 };
346

    
347
    int maxXY = Math.max(X,Y);
348
    int maxXZ = Math.max(X,Z);
349
    int maxYZ = Math.max(Y,Z);
350

    
351
    int angle = 45;
352
    float R = 0.10f;
353
    float S = 0.25f;
354
    float N = 4;
355

    
356
    float[][] bands =
357
        {
358
          {height/maxYZ,angle,R,S,N,0,0},
359
          {height/maxXZ,angle,R,S,N,0,0},
360
          {height/maxXY,angle,R,S,N,0,0}
361
        };
362

    
363
    return new ObjectFaceShape(bands,bandIndices,null);
364
    }
365

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

    
368
  public ObjectVertexEffects getVertexEffects(int variant)
369
    {
370
    boolean round = false;
371
    float[][] vertices = getVertices(variant);
372
    float A = -0.03f;
373

    
374
    float[][] variables =
375
        {
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
          { 0,-A,-A, A, 1  },
383
          { 0,-A,-A,-A, 1  },
384
        };
385

    
386
    String name = EffectName.DEFORM.name();
387
    float[] reg = {0,0,0,0.10f};
388

    
389
    String[] names = {name,name,name,name,name,name,name,name};
390
    float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg};
391
    boolean[] uses = {round,round,round,round,round,round,round,round};
392

    
393
    return new ObjectVertexEffects(names,variables,vertices,regions,uses);
394
    }
395

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397

    
398
  public int getCubitVariant(int cubit, int[] numLayers)
399
    {
400
    if( mPosition==null ) mPosition = getInitData().getPos();
401

    
402
    if( mPosition==CAM_333 )
403
      {
404
      return cubit;
405
      }
406

    
407
    return 0;
408
    }
409

    
410
///////////////////////////////////////////////////////////////////////////////////////////////////
411

    
412
  public int getNumCubitVariants(int[] numLayers)
413
    {
414
    if( mPosition==null ) mPosition = getInitData().getPos();
415

    
416
    if( mPosition==CAM_333 ) return 26;
417

    
418
    return 0;
419
    }
420

    
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422

    
423
  public float getStickerRadius()
424
    {
425
    return 0.18f;
426
    }
427

    
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429

    
430
  public float getStickerStroke()
431
    {
432
    return isInIconMode() ? 0.30f : 0.18f;
433
    }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

    
437
  public String getShortName()
438
    {
439
    if( mPosition==null ) mPosition = getInitData().getPos();
440

    
441
    if( mPosition==CAM_333 ) return ObjectType.CA_333.name();
442

    
443
    return null;
444
    }
445

    
446
///////////////////////////////////////////////////////////////////////////////////////////////////
447

    
448
  public ObjectSignature getSignature()
449
    {
450
    if( mSignature==null )
451
      {
452
      if( mPosition==null ) mPosition = getInitData().getPos();
453
      if( mPosition==CAM_333 ) mSignature = new ObjectSignature(ObjectSignatures.CA_333);
454
      }
455
    return mSignature;
456
    }
457

    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

    
460
  public String getObjectName()
461
    {
462
    if( mPosition==null ) mPosition = getInitData().getPos();
463

    
464
    if( mPosition==CAM_333 ) return "Camouflage 3x3x3";
465

    
466
    return "Camouflage";
467
    }
468

    
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470

    
471
  public String getInventor()
472
    {
473
    return "Guan Yang";
474
    }
475

    
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477

    
478
  public int getYearOfInvention()
479
    {
480
    return 2013;
481
    }
482

    
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484

    
485
  public int getComplexity()
486
    {
487
    if( mPosition==null ) mPosition = getInitData().getPos();
488

    
489
    if( mPosition==CAM_333 ) return 4;
490

    
491
    return 0;
492
    }
493

    
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495

    
496
  public String[][] getTutorials()
497
    {
498
    if( mPosition==null ) mPosition = getInitData().getPos();
499

    
500
    if( mPosition==CAM_333 )
501
      {
502
      return new String[][]{
503
                            {"gb","f9zmpCfg25k","3x3x3 Camouflage Part 1","Superantoniovivaldi"},
504
                            {"gb","O8pGyi5Juxk","3x3x3 Camouflage Part 2","Superantoniovivaldi"},
505
                            {"es","V1RPBIzEwp4","Tutorial 3x3 Camouflage","Manu rubiks"},
506
                            {"ru","DRGNOSw5pPc","Как собрать 3х3х3 camouflage","Илья Топор-Гилка"},
507
                            {"fr","9BfI1Fcbcl8","Résolution du Camouflage Cube","Skieur Cubb"},
508
                            {"pl","uEVvR2jDdI0","Camouflage 3x3x3 Tutorial","MrUK"},
509
                           };
510
      }
511

    
512
    return null;
513
    }
514
}
(5-5/47)