Project

General

Profile

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

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

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.1f;
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
  private int getDimsIndex(int variant)
136
    {
137
    if( mPosition==null ) mPosition = getInitData().getPos();
138

    
139
    if( mPosition==CAM_333 )
140
      {
141
      if( mDimsIndices==null ) mDimsIndices = new int[]
142
                                   { 0,
143
                                     1,0,2,0,3,0,
144
                                     3,0,4,2,1,0,5,3,6,2,1,0,
145
                                     6,2,1,0,5,4,3 };
146
      }
147

    
148
    return mDimsIndices[variant];
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  private int getOffsetsIndex(int variant)
154
    {
155
    if( mPosition==null ) mPosition = getInitData().getPos();
156

    
157
    if( mPosition==CAM_333 )
158
      {
159
      if( mOffsIndices==null ) mOffsIndices = new int[]
160
                                   { 0,
161
                                     0,1,0,4,0,6,
162
                                     4,7,0,6,6,8,0,1,0,1,4,9,
163
                                     6,8,7,10,4,1,9 };
164
      }
165

    
166
    return mOffsIndices[variant];
167
    }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

    
171
  private float[][] getVertices(int variant)
172
    {
173
    int indexD = getDimsIndex(variant);
174

    
175
    int X=DIMS[indexD][0];
176
    int Y=DIMS[indexD][1];
177
    int Z=DIMS[indexD][2];
178

    
179
    int indexO = getOffsetsIndex(variant);
180

    
181
    float XF = OFFSETS[indexO][0];
182
    float YF = OFFSETS[indexO][1];
183
    float ZF = OFFSETS[indexO][2];
184

    
185
    return new float[][]
186
      {
187
        { 0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF},
188
        { 0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF},
189
        { 0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF},
190
        { 0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF},
191
        {-0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF},
192
        {-0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF},
193
        {-0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF},
194
        {-0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF}
195
      };
196
    }
197

    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199
// PUBLIC API
200

    
201
  public int getTouchControlType()
202
    {
203
    return TC_CHANGING_MIRROR;
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  public float[] getDist3D(int[] numLayers)
209
    {
210
    float x = numLayers[0];
211
    float y = numLayers[1];
212
    float z = numLayers[2];
213
    float a = SIZE_CORRECTION*(x+y+z)/1.5f;
214

    
215
    return new float[] {(x+2)/a,x/a,y/a,(y+2)/a,z/a,(z+2)/a};
216
    }
217

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

    
220
  public Static4D getCubitQuats(int cubit, int[] numLayers)
221
    {
222
    return mObjectQuats[0];
223
    }
224

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

    
227
  public ObjectShape getObjectShape(int variant)
228
    {
229
    int[][] indices =
230
        {
231
          {2,3,1,0},
232
          {7,6,4,5},
233
          {4,0,1,5},
234
          {7,3,2,6},
235
          {6,2,0,4},
236
          {3,7,5,1},
237
        };
238

    
239
    return new ObjectShape( getVertices(variant), indices);
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
  public ObjectFaceShape getObjectFaceShape(int variant)
245
    {
246
    int index = getDimsIndex(variant);
247

    
248
    int X = DIMS[index][0];
249
    int Y = DIMS[index][1];
250
    int Z = DIMS[index][2];
251

    
252
    float height     = isInIconMode() ? 0.001f : 0.03f;
253
    int[] bandIndices= { 0,0,1,1,2,2 };
254

    
255
    int maxXY = Math.max(X,Y);
256
    int maxXZ = Math.max(X,Z);
257
    int maxYZ = Math.max(Y,Z);
258

    
259
    int angle = 45;
260
    float R = 0.10f;
261
    float S = 0.25f;
262
    float N = 4;
263

    
264
    float[][] bands =
265
        {
266
          {height/maxYZ,angle,R,S,N,0,0},
267
          {height/maxXZ,angle,R,S,N,0,0},
268
          {height/maxXY,angle,R,S,N,0,0}
269
        };
270

    
271
    return new ObjectFaceShape(bands,bandIndices,null);
272
    }
273

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

    
276
  public ObjectVertexEffects getVertexEffects(int variant)
277
    {
278
    boolean round = false;
279
    float[][] vertices = getVertices(variant);
280
    float A = -0.03f;
281

    
282
    float[][] variables =
283
        {
284
          { 0, A, A, A, 1  },
285
          { 0, A, A,-A, 1  },
286
          { 0, A,-A, A, 1  },
287
          { 0, A,-A,-A, 1  },
288
          { 0,-A, A, A, 1  },
289
          { 0,-A, A,-A, 1  },
290
          { 0,-A,-A, A, 1  },
291
          { 0,-A,-A,-A, 1  },
292
        };
293

    
294
    String name = EffectName.DEFORM.name();
295
    float[] reg = {0,0,0,0.10f};
296

    
297
    String[] names = {name,name,name,name,name,name,name,name};
298
    float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg};
299
    boolean[] uses = {round,round,round,round,round,round,round,round};
300

    
301
    return new ObjectVertexEffects(names,variables,vertices,regions,uses);
302
    }
303

    
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305

    
306
  public int getCubitVariant(int cubit, int[] numLayers)
307
    {
308
    if( mPosition==null ) mPosition = getInitData().getPos();
309

    
310
    if( mPosition==CAM_333 )
311
      {
312
      return cubit;
313
      }
314

    
315
    return 0;
316
    }
317

    
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

    
320
  public int getNumCubitVariants(int[] numLayers)
321
    {
322
    if( mPosition==null ) mPosition = getInitData().getPos();
323

    
324
    if( mPosition==CAM_333 ) return 26;
325

    
326
    return 0;
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

    
331
  public float getStickerRadius()
332
    {
333
    return 0.18f;
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  public float getStickerStroke()
339
    {
340
    return isInIconMode() ? 0.25f : 0.15f;
341
    }
342

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

    
345
  public String getShortName()
346
    {
347
    if( mPosition==null ) mPosition = getInitData().getPos();
348

    
349
    if( mPosition==CAM_333 ) return ObjectType.CA_333.name();
350

    
351
    return null;
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

    
356
  public ObjectSignature getSignature()
357
    {
358
    if( mSignature==null )
359
      {
360
      if( mPosition==null ) mPosition = getInitData().getPos();
361
      if( mPosition==CAM_333 ) mSignature = new ObjectSignature(ObjectType.CA_333);
362
      }
363
    return mSignature;
364
    }
365

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

    
368
  public String getObjectName()
369
    {
370
    int[] nL = getNumLayers();
371
    return "Camouflage "+nL[0]+"x"+nL[1]+"x"+nL[2];
372
    }
373

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

    
376
  public String getInventor()
377
    {
378
    return "Guan Yang";
379
    }
380

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

    
383
  public int getYearOfInvention()
384
    {
385
    return 2013;
386
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

    
390
  public int getComplexity()
391
    {
392
    if( mPosition==null ) mPosition = getInitData().getPos();
393

    
394
    if( mPosition==CAM_333 ) return 3;
395

    
396
    return 0;
397
    }
398

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

    
401
  public String[][] getTutorials()
402
    {
403
    if( mPosition==null ) mPosition = getInitData().getPos();
404

    
405
    if( mPosition==CAM_333 )
406
      {
407
      return new String[][]{
408
                            {"gb","f9zmpCfg25k","3x3x3 Camouflage Part 1","Superantoniovivaldi"},
409
                            {"gb","O8pGyi5Juxk","3x3x3 Camouflage Part 2","Superantoniovivaldi"},
410
                            {"es","V1RPBIzEwp4","Tutorial 3x3 Camouflage","Manu rubiks"},
411
                            {"ru","DRGNOSw5pPc","Как собрать 3х3х3 camouflage","Илья Топор-Гилка"},
412
                            {"fr","9BfI1Fcbcl8","Résolution du Camouflage Cube","Skieur Cubb"},
413
                            {"pl","uEVvR2jDdI0","Camouflage 3x3x3 Tutorial","MrUK"},
414
                           };
415
      }
416

    
417
    return null;
418
    }
419
}
(4-4/41)