Project

General

Profile

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

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

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.InitData;
22
import org.distorted.objectlib.main.ObjectType;
23

    
24
import java.io.InputStream;
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.0f,-0.5f,-0.5f, 2, 1, 1),
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.0f,-0.5f, 1, 2, 1),
50
      getCenters(  1.5f, 1.0f,-0.5f, 1, 2, 1),
51
      getCenters(  0.5f,-0.5f, 1.0f, 1, 1, 2),
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

    
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95

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

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

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

    
115
    return result;
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

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

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

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

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
  @Override
136
  public int getScrambleType()
137
    {
138
    return 2;
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
  public int[][] getScrambleEdges()
144
    {
145
    return null;
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  private int getDimsIndex(int variant)
151
    {
152
    if( mPosition==null ) mPosition = getInitData().getPos();
153

    
154
    if( mPosition==CAM_333 )
155
      {
156
      if( mDimsIndices==null ) mDimsIndices = new int[]
157
                                   { 0,
158
                                     1,0,2,0,3,0,
159
                                     3,0,4,2,1,0,5,3,6,2,1,0,
160
                                     6,2,1,0,5,4,3 };
161
      }
162

    
163
    return mDimsIndices[variant];
164
    }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
  private int getOffsetsIndex(int variant)
169
    {
170
    if( mPosition==null ) mPosition = getInitData().getPos();
171

    
172
    if( mPosition==CAM_333 )
173
      {
174
      if( mOffsIndices==null ) mOffsIndices = new int[]
175
                                   { 0,
176
                                     0,1,0,4,0,6,
177
                                     4,7,0,6,6,8,0,1,0,1,4,9,
178
                                     6,8,7,10,4,1,9 };
179
      }
180

    
181
    return mOffsIndices[variant];
182
    }
183

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

    
186
  private float[][] getVertices(int variant)
187
    {
188
    int indexD = getDimsIndex(variant);
189

    
190
    int X=DIMS[indexD][0];
191
    int Y=DIMS[indexD][1];
192
    int Z=DIMS[indexD][2];
193

    
194
    int indexO = getOffsetsIndex(variant);
195

    
196
    float XF = OFFSETS[indexO][0];
197
    float YF = OFFSETS[indexO][1];
198
    float ZF = OFFSETS[indexO][2];
199

    
200
    return new float[][]
201
      {
202
        { 0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF},
203
        { 0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF},
204
        { 0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF},
205
        { 0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF},
206
        {-0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF},
207
        {-0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF},
208
        {-0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF},
209
        {-0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF}
210
      };
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
// PUBLIC API
215

    
216
  public int getTouchControlType()
217
    {
218
    return TC_CHANGING_MIRROR;
219
    }
220

    
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

    
223
  public float[] getDist3D(int[] numLayers)
224
    {
225
    float x = numLayers[0];
226
    float y = numLayers[1];
227
    float z = numLayers[2];
228
    float a = SIZE_CORRECTION*(x+y+z)/1.5f;
229

    
230
    return new float[] {(x+2)/a,x/a,y/a,(y+2)/a,z/a,(z+2)/a};
231
    }
232

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

    
235
  public Static4D getCubitQuats(int cubit, int[] numLayers)
236
    {
237
    return mObjectQuats[0];
238
    }
239

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

    
242
  public ObjectShape getObjectShape(int variant)
243
    {
244
    int[][] indices =
245
        {
246
          {2,3,1,0},
247
          {7,6,4,5},
248
          {4,0,1,5},
249
          {7,3,2,6},
250
          {6,2,0,4},
251
          {3,7,5,1},
252
        };
253

    
254
    return new ObjectShape( getVertices(variant), indices);
255
    }
256

    
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

    
259
  public ObjectFaceShape getObjectFaceShape(int variant)
260
    {
261
    int index = getDimsIndex(variant);
262

    
263
    int X = DIMS[index][0];
264
    int Y = DIMS[index][1];
265
    int Z = DIMS[index][2];
266

    
267
    float height     = isInIconMode() ? 0.001f : 0.03f;
268
    int[] bandIndices= { 0,0,1,1,2,2 };
269

    
270
    int maxXY = Math.max(X,Y);
271
    int maxXZ = Math.max(X,Z);
272
    int maxYZ = Math.max(Y,Z);
273

    
274
    int angle = 45;
275
    float R = 0.10f;
276
    float S = 0.25f;
277
    float N = 4;
278

    
279
    float[][] bands =
280
        {
281
          {height/maxYZ,angle,R,S,N,0,0},
282
          {height/maxXZ,angle,R,S,N,0,0},
283
          {height/maxXY,angle,R,S,N,0,0}
284
        };
285

    
286
    return new ObjectFaceShape(bands,bandIndices,null);
287
    }
288

    
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

    
291
  public ObjectVertexEffects getVertexEffects(int variant)
292
    {
293
    boolean round = false;
294
    float[][] vertices = getVertices(variant);
295
    float A = -0.03f;
296

    
297
    float[][] variables =
298
        {
299
          { 0, A, A, A, 1  },
300
          { 0, A, A,-A, 1  },
301
          { 0, A,-A, A, 1  },
302
          { 0, A,-A,-A, 1  },
303
          { 0,-A, A, A, 1  },
304
          { 0,-A, A,-A, 1  },
305
          { 0,-A,-A, A, 1  },
306
          { 0,-A,-A,-A, 1  },
307
        };
308

    
309
    String name = EffectName.DEFORM.name();
310
    float[] reg = {0,0,0,0.10f};
311

    
312
    String[] names = {name,name,name,name,name,name,name,name};
313
    float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg};
314
    boolean[] uses = {round,round,round,round,round,round,round,round};
315

    
316
    return new ObjectVertexEffects(names,variables,vertices,regions,uses);
317
    }
318

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

    
321
  public int getCubitVariant(int cubit, int[] numLayers)
322
    {
323
    if( mPosition==null ) mPosition = getInitData().getPos();
324

    
325
    if( mPosition==CAM_333 )
326
      {
327
      return cubit;
328
      }
329

    
330
    return 0;
331
    }
332

    
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334

    
335
  public int getNumCubitVariants(int[] numLayers)
336
    {
337
    if( mPosition==null ) mPosition = getInitData().getPos();
338

    
339
    if( mPosition==CAM_333 ) return 26;
340

    
341
    return 0;
342
    }
343

    
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345

    
346
  public float getStickerRadius()
347
    {
348
    return 0.18f;
349
    }
350

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

    
353
  public float getStickerStroke()
354
    {
355
    return isInIconMode() ? 0.30f : 0.18f;
356
    }
357

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

    
360
  public String getShortName()
361
    {
362
    if( mPosition==null ) mPosition = getInitData().getPos();
363

    
364
    if( mPosition==CAM_333 ) return ObjectType.CA_333.name();
365

    
366
    return null;
367
    }
368

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

    
371
  public ObjectSignature getSignature()
372
    {
373
    if( mSignature==null )
374
      {
375
      if( mPosition==null ) mPosition = getInitData().getPos();
376
      if( mPosition==CAM_333 ) mSignature = new ObjectSignature(ObjectType.CA_333);
377
      }
378
    return mSignature;
379
    }
380

    
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382

    
383
  public String getObjectName()
384
    {
385
    if( mPosition==null ) mPosition = getInitData().getPos();
386

    
387
    if( mPosition==CAM_333 ) return "Camouflage 3x3x3";
388

    
389
    return "Camouflage";
390
    }
391

    
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393

    
394
  public String getInventor()
395
    {
396
    return "Guan Yang";
397
    }
398

    
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400

    
401
  public int getYearOfInvention()
402
    {
403
    return 2013;
404
    }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
  public int getComplexity()
409
    {
410
    if( mPosition==null ) mPosition = getInitData().getPos();
411

    
412
    if( mPosition==CAM_333 ) return 3;
413

    
414
    return 0;
415
    }
416

    
417
///////////////////////////////////////////////////////////////////////////////////////////////////
418

    
419
  public String[][] getTutorials()
420
    {
421
    if( mPosition==null ) mPosition = getInitData().getPos();
422

    
423
    if( mPosition==CAM_333 )
424
      {
425
      return new String[][]{
426
                            {"gb","f9zmpCfg25k","3x3x3 Camouflage Part 1","Superantoniovivaldi"},
427
                            {"gb","O8pGyi5Juxk","3x3x3 Camouflage Part 2","Superantoniovivaldi"},
428
                            {"es","V1RPBIzEwp4","Tutorial 3x3 Camouflage","Manu rubiks"},
429
                            {"ru","DRGNOSw5pPc","Как собрать 3х3х3 camouflage","Илья Топор-Гилка"},
430
                            {"fr","9BfI1Fcbcl8","Résolution du Camouflage Cube","Skieur Cubb"},
431
                            {"pl","uEVvR2jDdI0","Camouflage 3x3x3 Tutorial","MrUK"},
432
                           };
433
      }
434

    
435
    return null;
436
    }
437
}
(4-4/41)