Project

General

Profile

« Previous | Next » 

Revision f925d455

Added by Leszek Koltunski over 1 year ago

Progress with the Camouflage 3x3x3.

View differences:

src/main/java/org/distorted/objectlib/objects/TwistyBandagedCuboid.java
9 9

  
10 10
package org.distorted.objectlib.objects;
11 11

  
12
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CUBOID;
13

  
12 14
import java.io.InputStream;
13 15

  
16
import org.distorted.library.effect.EffectName;
17
import org.distorted.library.main.DistortedLibrary;
14 18
import org.distorted.library.type.Static3D;
15 19
import org.distorted.library.type.Static4D;
16 20

  
21
import org.distorted.objectlib.helpers.FactoryBandagedCubit;
22
import org.distorted.objectlib.helpers.ObjectFaceShape;
17 23
import org.distorted.objectlib.helpers.ObjectSignature;
24
import org.distorted.objectlib.helpers.ObjectVertexEffects;
18 25
import org.distorted.objectlib.main.InitData;
19 26
import org.distorted.objectlib.helpers.ObjectShape;
20 27
import org.distorted.objectlib.main.ObjectType;
......
25 32
{
26 33
  private static final String OBJECT_NAME = "LOCAL_BANDAGED";
27 34

  
35
  private static final int CUBIT_111 = 0;
36
  private static final int CUBIT_211 = 1;
37
  private static final int CUBIT_311 = 2;
38
  private static final int CUBIT_221 = 3;
39
  private static final int CUBIT_222 = 4;
40
  private static final int CUBIT_OTH = 5;
41

  
42
  private static final int[][] mDims = new int[][]
43
        {
44
         {1,1,1},  // has to be X>=Z>=Y so that all
45
         {2,1,1},  // the faces are horizontal
46
         {3,1,1},
47
         {2,1,2},
48
         {2,2,2},
49
        };
50

  
28 51
  public static final float[][] POS_1 = new float[][]
29 52
        {
30 53
          {-1.0f, -1.0f, +0.0f,
......
120 143
          { 1.0f, -1.0f, -1.0f,  1.0f,  0.0f, -1.0f}
121 144
        };
122 145

  
146
  private int[] mCubitVariantMap;
147
  private int[] mTypeVariantMap;
148
  private Static4D[] mInitQuats;
149

  
123 150
///////////////////////////////////////////////////////////////////////////////////////////////////
124 151

  
125 152
  public static int getType(String shortName, String longName)
......
143 170

  
144 171
///////////////////////////////////////////////////////////////////////////////////////////////////
145 172

  
146
  float[][] getVertices(int variant)
173
  private int getType(float[] pos)
174
    {
175
    switch(pos.length)
176
      {
177
      case  3: return CUBIT_111;
178
      case  6: return CUBIT_211;
179
      case  9: boolean x1 = (pos[0]==pos[3] && pos[0]==pos[6]);
180
               boolean y1 = (pos[1]==pos[4] && pos[1]==pos[7]);
181
               boolean z1 = (pos[2]==pos[5] && pos[2]==pos[8]);
182
               return ( (x1&&y1) || (x1&&z1) || (y1&&z1) ) ? CUBIT_311 : CUBIT_OTH;
183
      case 12: float x = (pos[0]+pos[3]+pos[6]+pos[ 9])/4;
184
               float y = (pos[1]+pos[4]+pos[7]+pos[10])/4;
185
               float z = (pos[2]+pos[5]+pos[8]+pos[11])/4;
186
               float d1 = (pos[0]-x)*(pos[0]-x) + (pos[ 1]-y)*(pos[ 1]-y) + (pos[ 2]-z)*(pos[ 2]-z);
187
               float d2 = (pos[3]-x)*(pos[3]-x) + (pos[ 4]-y)*(pos[ 4]-y) + (pos[ 5]-z)*(pos[ 5]-z);
188
               float d3 = (pos[6]-x)*(pos[6]-x) + (pos[ 7]-y)*(pos[ 7]-y) + (pos[ 8]-z)*(pos[ 8]-z);
189
               float d4 = (pos[9]-x)*(pos[9]-x) + (pos[10]-y)*(pos[10]-y) + (pos[11]-z)*(pos[11]-z);
190
               return ( d1==0.5f && d2==0.5f && d3==0.5f && d4==0.5f ) ? CUBIT_221 : CUBIT_OTH;
191
      case 24: float x3 = pos[0];
192
               float y3 = pos[1];
193
               float z3 = pos[2];
194
               float x4=-10,y4=-10,z4=-10;
195
               int i;
196

  
197
               for(i=0; i<8; i++)
198
                 {
199
                 if( pos[3*i]!=x3 && pos[3*i+1]!=y3 && pos[3*i+2]!=z3 )
200
                   {
201
                   x4 = pos[3*i  ];
202
                   y4 = pos[3*i+1];
203
                   z4 = pos[3*i+2];
204
                   break;
205
                   }
206
                 }
207
               if( i==9 ) return CUBIT_OTH;
208

  
209
               float dX = x4-x3;
210
               float dY = y4-y3;
211
               float dZ = z4-z3;
212

  
213
               if( (dX==1.0f || dX==-1.0f) && (dY==1.0f || dY==-1.0f) && (dZ==1.0f || dZ==-1.0f) )
214
                 {
215
                 for(i=0; i<8; i++)
216
                   {
217
                   if( (pos[3*i  ]!=x3 && pos[3*i  ]!=x4) ||
218
                       (pos[3*i+1]!=y3 && pos[3*i+1]!=y4) ||
219
                       (pos[3*i+2]!=z3 && pos[3*i+2]!=z4)  ) return CUBIT_OTH;
220
                   }
221

  
222
                 return CUBIT_222;
223
                 }
224

  
225
      default: return CUBIT_OTH;
226
      }
227
    }
228

  
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

  
231
  private int getQuatIndex(int cubit)
232
    {
233
    float[][] positions = getPositions();
234
    int len = positions.length;
235

  
236
    if( cubit>=0 && cubit<len )
237
      {
238
      float[] pos = positions[cubit];
239
      int type = getType(pos);
240

  
241
      switch(type)
242
        {
243
        case CUBIT_222:
244
        case CUBIT_111: return 0;
245
        case CUBIT_211:
246
        case CUBIT_311: return (pos[1]==pos[4]) ? (pos[0]==pos[3] ? 2 : 0) : 3;
247
        case CUBIT_221: if( pos[0]==pos[3] && pos[0]==pos[6] ) return 3;
248
                        if( pos[1]==pos[4] && pos[1]==pos[7] ) return 0;
249
                        if( pos[2]==pos[5] && pos[2]==pos[8] ) return 1;
250
        }
251
      }
252

  
253
    return 0;
254
    }
255

  
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

  
258
  private int[] getDim(int variant)
259
    {
260
    int type,numTypes = mDims.length;
261
    for(type=0; type<numTypes; type++) if( mTypeVariantMap[type]==variant ) break;
262
    return type<numTypes ? mDims[type] : null;
263
    }
264

  
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

  
267
  private void produceTmpShape(int variant)
268
    {
269
    float[][] positions = getPositions();
270
    int cubit,numCubits = positions.length;
271

  
272
    for(cubit=0; cubit<numCubits; cubit++)
273
      {
274
      if( mCubitVariantMap[cubit]==variant ) break;
275
      }
276

  
277
    if( cubit>=numCubits )
278
      {
279
      android.util.Log.e("D", "unknown variant: "+variant);
280
      }
281
    else
282
      {
283
      FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
284
      mTmpShapes[variant] = factory.createIrregularShape(variant,positions[cubit]);
285
      }
286
    }
287

  
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289
// PUBLIC API
290

  
291
  public int getTouchControlType()
292
    {
293
    return TC_CUBOID;
294
    }
295

  
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

  
298
  public ObjectShape getObjectShape(int variant)
299
    {
300
    if( getDim(variant)!=null )
301
      {
302
      int[][] indices =
303
        {
304
          {2,3,1,0},
305
          {7,6,4,5},
306
          {4,0,1,5},
307
          {7,3,2,6},
308
          {6,2,0,4},
309
          {3,7,5,1},
310
        };
311

  
312
      return new ObjectShape( getVertices(variant), indices);
313
      }
314

  
315
    if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
316
    if( mTmpShapes[variant]==null ) produceTmpShape(variant);
317
    return mTmpShapes[variant];
318
    }
319

  
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321

  
322
  public ObjectFaceShape getObjectFaceShape(int variant)
323
    {
324
    int[] numLayers = getNumLayers();
325
    int size = (numLayers[0]+numLayers[1]+numLayers[2])/3;
326
    int[] dim = getDim(variant);
327

  
328
    if( dim!=null )
329
      {
330
      int X = dim[0];
331
      int Y = dim[1];
332
      int Z = dim[2];
333

  
334
      float height     = isInIconMode() ? 0.001f : size<=5 ? 0.048f : 0.020f;
335
      int[] bandIndices= { 0,0,1,1,2,2 };
336

  
337
      int maxXY = Math.max(X,Y);
338
      int maxXZ = Math.max(X,Z);
339
      int maxYZ = Math.max(Y,Z);
340

  
341
      int angle = 45;
342
      float R = 0.25f;
343
      float S = 0.50f;
344
      float N = size<=4 ? 5 : size<=5 ? 4 : 3;
345

  
346
      float[][] bands =
347
        {
348
          {height/maxYZ,angle,R,S,N,0,0},
349
          {height/maxXZ,angle,R,S,N,0,0},
350
          {height/maxXY,angle,R,S,N,0,0}
351
        };
352

  
353
      return new ObjectFaceShape(bands,bandIndices,null);
354
      }
355

  
356
    FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
357
    return factory.createIrregularFaceShape(variant, isInIconMode() );
358
    }
359

  
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

  
362
  public ObjectVertexEffects getVertexEffects(int variant)
363
    {
364
    int[] numLayers = getNumLayers();
365
    int size = (numLayers[0]+numLayers[1]+numLayers[2])/3;
366
    boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode());
367

  
368
    if( getDim(variant)!=null )
369
      {
370
      float[][] vertices = getVertices(variant);
371
      float strength = -0.04f;
372

  
373
      float[][] variables =
374
        {
375
          { 0, strength*vertices[0][0], strength*vertices[0][1], strength*vertices[0][2], 1  },
376
          { 0, strength*vertices[1][0], strength*vertices[1][1], strength*vertices[1][2], 1  },
377
          { 0, strength*vertices[2][0], strength*vertices[2][1], strength*vertices[2][2], 1  },
378
          { 0, strength*vertices[3][0], strength*vertices[3][1], strength*vertices[3][2], 1  },
379
          { 0, strength*vertices[4][0], strength*vertices[4][1], strength*vertices[4][2], 1  },
380
          { 0, strength*vertices[5][0], strength*vertices[5][1], strength*vertices[5][2], 1  },
381
          { 0, strength*vertices[6][0], strength*vertices[6][1], strength*vertices[6][2], 1  },
382
          { 0, strength*vertices[7][0], strength*vertices[7][1], strength*vertices[7][2], 1  },
383
        };
384

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

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

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

  
395
    FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
396
    return factory.createVertexEffects(variant,round);
397
    }
398

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

  
401
  public Static4D getCubitQuats(int cubit, int[] numLayers)
402
    {
403
    if( mInitQuats ==null )
404
      {
405
      mInitQuats = new Static4D[]
406
        {
407
        new Static4D(  0.0f,   0.0f,   0.0f,   1.0f),  // NULL
408
        new Static4D( SQ2/2,   0.0f,   0.0f, -SQ2/2),  // X
409
        new Static4D(  0.0f,  SQ2/2,   0.0f, -SQ2/2),  // Y
410
        new Static4D(  0.0f,   0.0f,  SQ2/2, -SQ2/2),  // Z
411
        new Static4D( -0.5f,  +0.5f,  -0.5f,  +0.5f),  // ZX
412
        new Static4D( +0.5f,  +0.5f,  +0.5f,  -0.5f),  // YX
413
        };
414
      }
415

  
416
    return mInitQuats[getQuatIndex(cubit)];
417
    }
418

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

  
421
  public int getNumCubitVariants(int[] numLayers)
422
    {
423
    if( mNumVariants==0 )
424
      {
425
      float[][] positions = getPositions();
426
      boolean C111=false;
427
      boolean C211=false;
428
      boolean C311=false;
429
      boolean C221=false;
430
      boolean C222=false;
431

  
432
      int numCubits = positions.length;
433
      mCubitVariantMap = new int[numCubits];
434

  
435
      int numTypes = mDims.length;
436
      mTypeVariantMap = new int[numTypes];
437
      for(int i=0; i<numTypes; i++) mTypeVariantMap[i] = -1;
438

  
439
      for (int cubit=0; cubit<numCubits; cubit++)
440
        {
441
        int type = getType(positions[cubit]);
442

  
443
        switch (type)
444
          {
445
          case CUBIT_111: if (!C111) { C111 = true; mTypeVariantMap[CUBIT_111]=mNumVariants++; }
446
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_111];
447
                          break;
448
          case CUBIT_211: if (!C211) { C211 = true; mTypeVariantMap[CUBIT_211]=mNumVariants++; }
449
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_211];
450
                          break;
451
          case CUBIT_311: if (!C311) { C311 = true; mTypeVariantMap[CUBIT_311]=mNumVariants++; }
452
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_311];
453
                          break;
454
          case CUBIT_221: if (!C221) { C221 = true; mTypeVariantMap[CUBIT_221]=mNumVariants++; }
455
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_221];
456
                          break;
457
          case CUBIT_222: if (!C222) { C222 = true; mTypeVariantMap[CUBIT_222]=mNumVariants++; }
458
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_222];
459
                          break;
460
          default       : mCubitVariantMap[cubit] = mNumVariants++;
461
          }
462
        }
463

  
464
      FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
465
      factory.prepare(mNumVariants,numLayers[0],numLayers[1],numLayers[2]);
466
      }
467

  
468
    return mNumVariants;
469
    }
470

  
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472

  
473
  public int getCubitVariant(int cubit, int[] numLayers)
474
    {
475
    return mCubitVariantMap[cubit];
476
    }
477

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

  
480
  private float[][] getVertices(int variant)
147 481
    {
148 482
    int[] dim = getDim(variant);
149 483

  
......
174 508
///////////////////////////////////////////////////////////////////////////////////////////////////
175 509
// PUBLIC API
176 510

  
511
  public float getStickerRadius()
512
    {
513
    return 0.10f;
514
    }
515

  
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517

  
518
  public float getStickerStroke()
519
    {
520
    return isInIconMode() ? 0.16f : 0.08f;
521
    }
522

  
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524

  
177 525
  public String getShortName()
178 526
    {
179 527
    if( mPosition==null ) mPosition = getInitData().getPos();

Also available in: Unified diff