Project

General

Profile

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

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

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
import org.distorted.objectlib.scrambling.ObjectScrambler;
26

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

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

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

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

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

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

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

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

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

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

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

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

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

    
117
    return result;
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

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

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

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

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  @Override
139
  public int getScrambleType()
140
    {
141
    return ObjectScrambler.SCRAMBLING_ALGORITHMS;
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
  public int[][] getScrambleEdges()
147
    {
148
    if( mEdges==null )
149
      {
150
      mEdges = new int[][]
151
        {
152
          {0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0}
153
        };
154
      }
155

    
156
    return mEdges;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  @Override
162
  public int[][] getScrambleAlgorithms()
163
    {
164
    return new int[][]
165
      {
166
        // VTS' algorithm1: ('swap 2 edges and 2 pairs of centers')
167
        {2, 1, 1,  1, 0, 1,  0, 2, 1,  1, 0,-1,  0, 2,-1,
168
         1, 0, 1,  0, 2, 1,  1, 0,-1,  0, 2,-1,  2, 1,-1,
169
         0, 2, 1,  1, 0, 1,  0, 2,-1,  1, 0,-1,  0, 2, 1,
170
         1, 0, 1,  0, 2,-1,  1, 0,-1,  0, 2, 1,  0, 3, 1,
171
         1, 0, 2,  2, 0, 1,  1, 0,-2,  2, 0,-1,  1, 0, 2,
172
         0, 2,-1,  2, 1, 1,  0, 2, 1,  1, 0, 2,  2, 0, 1,
173
         1, 0,-2,  2, 0,-1,  1, 0, 2,  0, 2,-1,  2, 1,-2},
174

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

    
184
        // algorithm1 rotated again around the corner
185
        {0, 2,-1,  2, 0, 1,  1, 0,-1,  2, 0,-1,  1, 0, 1,
186
         2, 0, 1,  1, 0,-1,  2, 0,-1,  1, 0, 1,  0, 2, 1,
187
         1, 0,-1,  2, 0, 1,  1, 0, 1,  2, 0,-1,  1, 0,-1,
188
         2, 0, 1,  1, 0, 1,  2, 0,-1,  1, 1,-1,  1, 0,-1,
189
         2, 0, 2,  0, 2,-1,  2, 0,-2,  0, 2, 1,  2, 0, 2,
190
         1, 0, 1,  0, 2,-1,  1, 0,-1,  2, 0, 2,  0, 2,-1,
191
         2, 0,-2,  0, 2, 1,  2, 0, 2,  1, 0, 1,  0, 2, 2},
192

    
193
       // VTS' algorithm2: swap two 221 edges
194
        {2, 2, 1,  1, 0, 1,  2, 2,-1,  1, 0,-1,  1, 2, 1,
195
         2, 2,-2,  0, 2,-1,  2, 2, 2,  0, 2, 1,  2, 2,-2,
196
         1, 2,-1,  0, 2,-1,  1, 2, 1,  2, 2,-2,  0, 2,-1,
197
         2, 2, 2,  0, 2, 1,  2, 2,-2,  1, 2,-1,  0, 2,-2,
198
         1, 0, 1,  2, 2, 1,  1, 0,-1,  2, 2, -1},
199

    
200
       // algorithm2 rotated around the corner
201
        {0, 0,-1,  2, 0, 1,  0, 0, 1,  2, 0,-1,  2, 2, 1,
202
         0, 0, 2,  1, 0, 1,  0, 0,-2,  1, 0,-1,  0, 0, 2,
203
         2, 2,-1,  1, 1, 1,  2, 2, 1,  0, 0, 2,  1, 0, 1,
204
         0, 0,-2,  1, 0,-1,  0, 0, 2,  2, 2,-1,  1, 1, 2,
205
         2, 0, 1,  0, 0,-1,  2, 0,-1,  0, 0, 1},
206

    
207
       // algorithm2 rotated again around the corner
208
        {1, 2, 1,  0, 2,-1,  1, 2,-1,  0, 2, 1,  0, 0,-1,
209
         1, 2,-2,  2, 0, 1,  1, 2, 2,  2, 0,-1,  1, 2,-2,
210
         0, 0, 1,  2, 1, 1,  0, 0,-1,  1, 2,-2,  2, 0, 1,
211
         1, 2, 2,  2, 0,-1,  1, 2,-2,  0, 0, 1,  2, 1, 2,
212
         0, 2,-1,  1, 2, 1,  0, 2, 1,  1, 2,-1},
213

    
214
       // VTS' algorithm3: swap two 221 blocks
215
        {2, 2,-2,  0, 2,-1,  2, 2, 2,  0, 2, 1,  2, 2,-2,
216
         1, 2,-1,  0, 2,-1,  1, 2, 1,  2, 2,-2,  0, 2,-1,
217
         2, 2, 2,  0, 2, 1,  2, 2,-2,  1, 2,-1,  0, 2, 2,
218
         1, 2, 1 },
219

    
220
       // algorithm3 rotated around the corner
221
        {0, 0,-2,  1, 0, 1,  0, 0,-2,  1, 0,-1,  0, 0, 2,
222
         2, 2,-1,  1, 1, 1,  2, 2, 1,  0, 0, 2,  1, 0, 1,
223
         0, 0,-2,  1, 0,-1,  0, 0, 2,  2, 2,-1,  1, 1,-2,
224
         2, 2, 1 },
225

    
226
       // algorithm3 rotated again around the corner
227
        {1, 2, 2,  2, 0, 1,  1, 2, 2,  2, 0,-1,  1, 2,-2,
228
         0, 0, 1,  2, 1, 1,  0, 0,-1,  1, 2,-2,  2, 0, 1,
229
         1, 2, 2,  2, 0,-1,  1, 2,-2,  0, 0, 1,  2, 1,-2,
230
         0, 0,-1 }
231
      };
232
    }
233

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

    
236
  private int getDimsIndex(int variant)
237
    {
238
    if( mPosition==null ) mPosition = getInitData().getPos();
239

    
240
    if( mPosition==CAM_333 )
241
      {
242
      if( mDimsIndices==null ) mDimsIndices = new int[]
243
                                   { 0,
244
                                     1,0,2,0,3,0,
245
                                     3,0,7,2,1,0,7,3,7,2,1,0,
246
                                     6,2,1,0,5,4,3 };
247
      }
248

    
249
    return mDimsIndices[variant];
250
    }
251

    
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

    
254
  private int getOffsetsIndex(int variant)
255
    {
256
    if( mPosition==null ) mPosition = getInitData().getPos();
257

    
258
    if( mPosition==CAM_333 )
259
      {
260
      if( mOffsIndices==null ) mOffsIndices = new int[]
261
                                   { 0,
262
                                     0,1,0,4,0,6,
263
                                     4,7,0,6,6,8,0,1,0,1,4,9,
264
                                     6,8,7,10,4,1,9 };
265
      }
266

    
267
    return mOffsIndices[variant];
268
    }
269

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

    
272
  private float[][] getVertices(int variant)
273
    {
274
    int indexD = getDimsIndex(variant);
275

    
276
    int X=DIMS[indexD][0];
277
    int Y=DIMS[indexD][1];
278
    int Z=DIMS[indexD][2];
279

    
280
    int indexO = getOffsetsIndex(variant);
281

    
282
    float XF = OFFSETS[indexO][0];
283
    float YF = OFFSETS[indexO][1];
284
    float ZF = OFFSETS[indexO][2];
285

    
286
    return new float[][]
287
      {
288
        { 0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF},
289
        { 0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF},
290
        { 0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF},
291
        { 0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF},
292
        {-0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF},
293
        {-0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF},
294
        {-0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF},
295
        {-0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF}
296
      };
297
    }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300
// PUBLIC API
301

    
302
  public int getTouchControlType()
303
    {
304
    return TC_CHANGING_MIRROR;
305
    }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

    
309
  public float[] getDist3D(int[] numLayers)
310
    {
311
    float x = numLayers[0];
312
    float y = numLayers[1];
313
    float z = numLayers[2];
314
    float a = SIZE_CORRECTION*(x+y+z)/1.5f;
315

    
316
    return new float[] {(x+2)/a,x/a,y/a,(y+2)/a,z/a,(z+2)/a};
317
    }
318

    
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320

    
321
  public Static4D getCubitQuats(int cubit, int[] numLayers)
322
    {
323
    return mObjectQuats[0];
324
    }
325

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327

    
328
  public ObjectShape getObjectShape(int variant)
329
    {
330
    int[][] indices =
331
        {
332
          {2,3,1,0},
333
          {7,6,4,5},
334
          {4,0,1,5},
335
          {7,3,2,6},
336
          {6,2,0,4},
337
          {3,7,5,1},
338
        };
339

    
340
    return new ObjectShape( getVertices(variant), indices);
341
    }
342

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344

    
345
  public ObjectFaceShape getObjectFaceShape(int variant)
346
    {
347
    int index = getDimsIndex(variant);
348

    
349
    int X = DIMS[index][0];
350
    int Y = DIMS[index][1];
351
    int Z = DIMS[index][2];
352

    
353
    float height     = isInIconMode() ? 0.001f : 0.03f;
354
    int[] bandIndices= { 0,0,1,1,2,2 };
355

    
356
    int maxXY = Math.max(X,Y);
357
    int maxXZ = Math.max(X,Z);
358
    int maxYZ = Math.max(Y,Z);
359

    
360
    int angle = 45;
361
    float R = 0.10f;
362
    float S = 0.25f;
363
    float N = 4;
364

    
365
    float[][] bands =
366
        {
367
          {height/maxYZ,angle,R,S,N,0,0},
368
          {height/maxXZ,angle,R,S,N,0,0},
369
          {height/maxXY,angle,R,S,N,0,0}
370
        };
371

    
372
    return new ObjectFaceShape(bands,bandIndices,null);
373
    }
374

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376

    
377
  public ObjectVertexEffects getVertexEffects(int variant)
378
    {
379
    boolean round = false;
380
    float[][] vertices = getVertices(variant);
381
    float A = -0.03f;
382

    
383
    float[][] variables =
384
        {
385
          { 0, A, A, A, 1  },
386
          { 0, A, A,-A, 1  },
387
          { 0, A,-A, A, 1  },
388
          { 0, A,-A,-A, 1  },
389
          { 0,-A, A, A, 1  },
390
          { 0,-A, A,-A, 1  },
391
          { 0,-A,-A, A, 1  },
392
          { 0,-A,-A,-A, 1  },
393
        };
394

    
395
    String name = EffectName.DEFORM.name();
396
    float[] reg = {0,0,0,0.10f};
397

    
398
    String[] names = {name,name,name,name,name,name,name,name};
399
    float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg};
400
    boolean[] uses = {round,round,round,round,round,round,round,round};
401

    
402
    return new ObjectVertexEffects(names,variables,vertices,regions,uses);
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

    
407
  public int getCubitVariant(int cubit, int[] numLayers)
408
    {
409
    if( mPosition==null ) mPosition = getInitData().getPos();
410

    
411
    if( mPosition==CAM_333 )
412
      {
413
      return cubit;
414
      }
415

    
416
    return 0;
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

    
421
  public int getNumCubitVariants(int[] numLayers)
422
    {
423
    if( mPosition==null ) mPosition = getInitData().getPos();
424

    
425
    if( mPosition==CAM_333 ) return 26;
426

    
427
    return 0;
428
    }
429

    
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431

    
432
  public float getStickerRadius()
433
    {
434
    return 0.18f;
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

    
439
  public float getStickerStroke()
440
    {
441
    return isInIconMode() ? 0.30f : 0.18f;
442
    }
443

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445

    
446
  public String getShortName()
447
    {
448
    if( mPosition==null ) mPosition = getInitData().getPos();
449

    
450
    if( mPosition==CAM_333 ) return ObjectType.CA_333.name();
451

    
452
    return null;
453
    }
454

    
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456

    
457
  public ObjectSignature getSignature()
458
    {
459
    if( mSignature==null )
460
      {
461
      if( mPosition==null ) mPosition = getInitData().getPos();
462
      if( mPosition==CAM_333 ) mSignature = new ObjectSignature(ObjectSignatures.CA_333);
463
      }
464
    return mSignature;
465
    }
466

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

    
469
  public String getObjectName()
470
    {
471
    if( mPosition==null ) mPosition = getInitData().getPos();
472

    
473
    if( mPosition==CAM_333 ) return "Camouflage 3x3x3";
474

    
475
    return "Camouflage";
476
    }
477

    
478
///////////////////////////////////////////////////////////////////////////////////////////////////
479

    
480
  public String getInventor()
481
    {
482
    return "Guan Yang";
483
    }
484

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486

    
487
  public int getYearOfInvention()
488
    {
489
    return 2013;
490
    }
491

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493

    
494
  public int getComplexity()
495
    {
496
    if( mPosition==null ) mPosition = getInitData().getPos();
497

    
498
    if( mPosition==CAM_333 ) return 4;
499

    
500
    return 0;
501
    }
502

    
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

    
505
  public String[][] getTutorials()
506
    {
507
    if( mPosition==null ) mPosition = getInitData().getPos();
508

    
509
    if( mPosition==CAM_333 )
510
      {
511
      return new String[][]{
512
                            {"gb","f9zmpCfg25k","3x3x3 Camouflage Part 1","Superantoniovivaldi"},
513
                            {"gb","O8pGyi5Juxk","3x3x3 Camouflage Part 2","Superantoniovivaldi"},
514
                            {"es","V1RPBIzEwp4","Tutorial 3x3 Camouflage","Manu rubiks"},
515
                            {"ru","DRGNOSw5pPc","Как собрать 3х3х3 camouflage","Илья Топор-Гилка"},
516
                            {"fr","9BfI1Fcbcl8","Résolution du Camouflage Cube","Skieur Cubb"},
517
                            {"pl","uEVvR2jDdI0","Camouflage 3x3x3 Tutorial","MrUK"},
518
                           };
519
      }
520

    
521
    return null;
522
    }
523
}
(4-4/41)