Project

General

Profile

« Previous | Next » 

Revision be56193c

Added by Leszek Koltunski over 3 years ago

Move all the special cubit-creating code out of FactoryCubit and to the Object classes, and thus hopefully finish implementing the new cubit creating engine.

View differences:

src/main/java/org/distorted/helpers/FactoryCubit.java
24 24
import org.distorted.library.effect.MatrixEffectScale;
25 25
import org.distorted.library.effect.VertexEffect;
26 26
import org.distorted.library.effect.VertexEffectDeform;
27
import org.distorted.library.effect.VertexEffectMove;
28
import org.distorted.library.effect.VertexEffectRotate;
29
import org.distorted.library.effect.VertexEffectScale;
30 27
import org.distorted.library.mesh.MeshBase;
31 28
import org.distorted.library.mesh.MeshJoined;
32 29
import org.distorted.library.mesh.MeshPolygon;
......
40 37

  
41 38
public class FactoryCubit
42 39
  {
43
  private static final float SQ2 = (float)Math.sqrt(2);
44 40
  private static final Static1D RADIUS = new Static1D(1);
45 41
  private static FactoryCubit mThis;
46 42

  
47
  // IVY
48
  static final float IVY_D = 0.003f;
49
  static final float IVY_C = 0.59f;
50
  static final float IVY_M = 0.35f;
51
  private static final int IVY_N = 8;
52

  
53
  // REX
54
  public static final float REX_D = 0.2f;
55

  
56 43
  private static final double[] mBuffer = new double[3];
57 44
  private static final double[] mQuat1  = new double[4];
58 45
  private static final double[] mQuat2  = new double[4];
......
150 137
    return R*(sinAlpha-(float)Math.sin(x));
151 138
    }
152 139

  
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

  
155
  private float[] computeBands(float H, int alpha, float dist, float K, int N)
156
    {
157
    float[] bands = new float[2*N];
158

  
159
    bands[0] = 1.0f;
160
    bands[1] = 0.0f;
161

  
162
    float beta = (float)Math.atan(dist*Math.tan(Math.PI*alpha/180));
163
    float sinBeta = (float)Math.sin(beta);
164
    float cosBeta = (float)Math.cos(beta);
165
    float R = cosBeta<1.0f ? H/(1.0f-cosBeta) : 0.0f;
166
    float D = R*sinBeta;
167
    float B = h(R,sinBeta,K*beta);
168

  
169
    if( D>1.0f )
170
      {
171
      for(int i=1; i<N; i++)
172
        {
173
        bands[2*i  ] = (float)(N-1-i)/(N-1);
174
        bands[2*i+1] = H*(1-bands[2*i]);
175
        }
176
      }
177
    else
178
      {
179
      int K2 = (int)((N-3)*K);
180
      int K1 = (N-3)-K2;
181

  
182
      for(int i=0; i<=K1; i++)
183
        {
184
        float angle = K*beta + (1-K)*beta*(K1-i)/(K1+1);
185
        float x = h(R,sinBeta,angle);
186
        bands[2*i+2] = 1.0f - x;
187
        bands[2*i+3] = g(R,D,x,cosBeta);
188
        }
189

  
190
      for(int i=0; i<=K2; i++)
191
        {
192
        float x = (1-B)*(i+1)/(K2+1) + B;
193
        bands[2*K1+2 + 2*i+2] = 1.0f - x;
194
        bands[2*K1+2 + 2*i+3] = g(R,D,f(D,B,x),cosBeta);
195
        }
196
      }
197

  
198
    bands[2*N-2] = 0.0f;
199
    bands[2*N-1] =    H;
200

  
201
    return bands;
202
    }
203

  
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

  
206
  private void roundCorners(MeshBase mesh, Static3D center, Static3D[] vertices, float strength, float regionRadius)
207
    {
208
    Static4D reg= new Static4D(0,0,0,regionRadius);
209

  
210
    float centX = center.get0();
211
    float centY = center.get1();
212
    float centZ = center.get2();
213

  
214
    for (Static3D vertex : vertices)
215
      {
216
      float x = strength*(centX - vertex.get0());
217
      float y = strength*(centY - vertex.get1());
218
      float z = strength*(centZ - vertex.get2());
219

  
220
      VertexEffect effect = new VertexEffectDeform(new Static3D(x,y,z), RADIUS, vertex, reg);
221
      mesh.apply(effect);
222
      }
223
    }
224

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

  
227
  MeshBase createFacesIvyCorner()
228
    {
229
    MeshBase[] meshes = new MeshBase[6];
230

  
231
    final float angle = (float)Math.PI/(2*IVY_N);
232
    final float CORR  = 1.0f - 2*IVY_D;
233
    final float DIST  = -0.5f*CORR + IVY_D;
234
    float[] vertices  = new float[2*(IVY_N+1)+6];
235

  
236
    vertices[0] = (0.5f-IVY_M) * IVY_C;
237
    vertices[1] = (DIST-IVY_M) * IVY_C;
238
    vertices[2] = (0.5f-IVY_M) * IVY_C;
239
    vertices[3] = (0.5f-IVY_M) * IVY_C;
240
    vertices[4] = (DIST-IVY_M) * IVY_C;
241
    vertices[5] = (0.5f-IVY_M) * IVY_C;
242

  
243
    for(int i=0; i<=IVY_N; i++)
244
      {
245
      float ang = (IVY_N-i)*angle;
246
      float sin = (float)Math.sin(ang);
247
      float cos = (float)Math.cos(ang);
248

  
249
      vertices[2*i+6] = (CORR*(cos-0.5f)-IVY_M)*IVY_C;
250
      vertices[2*i+7] = (CORR*(sin-0.5f)-IVY_M)*IVY_C;
251
      }
252

  
253
    float[] bands0 = computeBands(+0.012f,20,0.2f,0.5f,7);
254
    float[] bands1 = computeBands(-0.100f,20,0.2f,0.0f,2);
255

  
256
    meshes[0] = new MeshPolygon(vertices,bands0,1,2);
257
    meshes[0].setEffectAssociation(0,1,0);
258
    meshes[1] = meshes[0].copy(true);
259
    meshes[1].setEffectAssociation(0,2,0);
260
    meshes[2] = meshes[0].copy(true);
261
    meshes[2].setEffectAssociation(0,4,0);
262
    meshes[3] = new MeshPolygon(vertices,bands1,1,2);
263
    meshes[3].setEffectAssociation(0,8,0);
264
    meshes[4] = meshes[3].copy(true);
265
    meshes[4].setEffectAssociation(0,16,0);
266
    meshes[5] = meshes[3].copy(true);
267
    meshes[5].setEffectAssociation(0,32,0);
268

  
269
    return new MeshJoined(meshes);
270
    }
271

  
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

  
274
  MeshBase createFacesIvyFace()
275
    {
276
    MeshBase[] meshes = new MeshBase[2];
277

  
278
    final float angle = (float)Math.PI/(2*IVY_N);
279
    final float CORR  = 1.0f - 2*IVY_D;
280
    float[] vertices = new float[4*IVY_N];
281

  
282
    for(int i=0; i<IVY_N; i++)
283
      {
284
      float sin = (float)Math.sin(i*angle);
285
      float cos = (float)Math.cos(i*angle);
286

  
287
      vertices[2*i          ] = CORR*(0.5f-cos);
288
      vertices[2*i+1        ] = CORR*(0.5f-sin);
289
      vertices[2*i  +2*IVY_N] = CORR*(cos-0.5f);
290
      vertices[2*i+1+2*IVY_N] = CORR*(sin-0.5f);
291
      }
292

  
293
    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
294
    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
295

  
296
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
297
    meshes[0].setEffectAssociation(0,1,0);
298
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
299
    meshes[1].setEffectAssociation(0,2,0);
300

  
301
    return new MeshJoined(meshes);
302
    }
303

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

  
306
  MeshBase createFacesRexCorner()
307
    {
308
    MeshBase[] meshes = new MeshBase[2];
309

  
310
    float F = REX_D*SQ2;
311
    float G = (1-REX_D)*SQ2/2;
312
    float H = 0.1f;
313
    float J = +2*G/3 - H*G;
314

  
315
    float[] vertices = { -F/2, -G/3, +F/2, -G/3, H*F/2, J, -H*F/2, J};
316

  
317
    float[] bands0 = computeBands(+0.016f,10,G/3,0.5f,5);
318
    float[] bands1 = computeBands(-0.230f,45,G/3,0.0f,2);
319

  
320
    meshes[0] = new MeshPolygon(vertices,bands0,1,1);
321
    meshes[0].setEffectAssociation(0,1,0);
322
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
323
    meshes[1].setEffectAssociation(0,2,0);
324

  
325
    return new MeshJoined(meshes);
326
    }
327

  
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329

  
330
  MeshBase createFacesRexFace()
331
    {
332
    MeshBase[] meshes = new MeshBase[2];
333

  
334
    float[] vertices = { -REX_D,0.0f, 0.0f, -REX_D, +REX_D, 0.0f, 0.0f, +REX_D};
335

  
336
    float[] bands0 = computeBands(0.016f,10,REX_D/2,0.5f,5);
337
    float[] bands1 = computeBands(0.000f,45,REX_D/2,0.0f,2);
338

  
339
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
340
    meshes[0].setEffectAssociation(0,1,0);
341
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
342
    meshes[1].setEffectAssociation(0,2,0);
343

  
344
    return new MeshJoined(meshes);
345
    }
346

  
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

  
349
  MeshBase createFacesRexEdge()
350
    {
351
    MeshBase[] meshes = new MeshPolygon[6];
352

  
353
    float E = 0.5f - REX_D;
354
    float F = 0.5f;
355
    float[] vertices0 = { -F,E/3, 0,-2*E/3, +F,E/3 };
356
    float[] bands0 = computeBands(0.03f,27,F/3,0.8f,5);
357

  
358
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 3);
359
    meshes[0].setEffectAssociation(0,1,0);
360
    meshes[1] = meshes[0].copy(true);
361
    meshes[1].setEffectAssociation(0,2,0);
362

  
363
    float G = (float)Math.sqrt(E*E+F*F);
364
    float[] vertices1 = { -2*G/3, -E/3, G/3, -E/3, G/3, 2*E/3 };
365
    float[] bands1 = computeBands(0.00f,45,G/3,0.2f,3);
366

  
367
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
368
    meshes[2].setEffectAssociation(0,4,0);
369
    meshes[3] = meshes[2].copy(true);
370
    meshes[3].setEffectAssociation(0,8,0);
371
    meshes[4] = meshes[2].copy(true);
372
    meshes[4].setEffectAssociation(0,16,0);
373
    meshes[5] = meshes[2].copy(true);
374
    meshes[5].setEffectAssociation(0,32,0);
375

  
376
    return new MeshJoined(meshes);
377
    }
378

  
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

  
381
  private float[] createVertices(int A, int B)
382
    {
383
    float E = 0.5f / Math.max(A,B);
384
    return new float[] { -A*E,-B*E, +A*E,-B*E, +A*E,+B*E, -A*E,+B*E };
385
    }
386

  
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388

  
389
  MeshBase createCuboid(int[] dimensions)
390
    {
391
    int X = dimensions[0];
392
    int Y = dimensions[1];
393
    int Z = dimensions[2];
394

  
395
    float[] verticesXY = createVertices(X,Y);
396
    float[] verticesXZ = createVertices(X,Z);
397
    float[] verticesYZ = createVertices(Z,Y);
398

  
399
    float defHeight = 0.048f;
400

  
401
    float[] bandsX = computeBands( defHeight/X,65,0.25f,0.5f,5);
402
    float[] bandsY = computeBands( defHeight/Y,65,0.25f,0.5f,5);
403
    float[] bandsZ = computeBands( defHeight/Z,65,0.25f,0.5f,5);
404

  
405
    MeshBase[] meshes = new MeshPolygon[6];
406

  
407
    meshes[0] = new MeshPolygon(verticesYZ,bandsX,1,2);
408
    meshes[0].setEffectAssociation(0,1,0);
409
    meshes[1] = meshes[0].copy(true);
410
    meshes[1].setEffectAssociation(0,2,0);
411
    meshes[2] = new MeshPolygon(verticesXZ,bandsY,1,2);
412
    meshes[2].setEffectAssociation(0,4,0);
413
    meshes[3] = meshes[2].copy(true);
414
    meshes[3].setEffectAssociation(0,8,0);
415
    meshes[4] = new MeshPolygon(verticesXY,bandsZ,1,2);
416
    meshes[4].setEffectAssociation(0,16,0);
417
    meshes[5] = meshes[4].copy(true);
418
    meshes[5].setEffectAssociation(0,32,0);
419

  
420
    return new MeshJoined(meshes);
421
    }
422

  
423
///////////////////////////////////////////////////////////////////////////////////////////////////
424
// EFFECTS
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

  
427
  VertexEffect[] createVertexEffectsIvyCorner()
428
    {
429
    Static3D axisX  = new Static3D(1,0,0);
430
    Static3D axisY  = new Static3D(0,1,0);
431
    Static1D angle1 = new Static1D(+90);
432
    Static1D angle2 = new Static1D(-90);
433
    Static3D center = new Static3D(0,0,0);
434
    Static3D move1  = new Static3D(IVY_M-0.5f,IVY_M-0.5f,0);
435

  
436
    VertexEffect[] effect = new VertexEffect[5];
437

  
438
    effect[0] = new VertexEffectScale(1/IVY_C);
439
    effect[1] = new VertexEffectMove(move1);
440
    effect[2] = new VertexEffectScale(new Static3D(1,1,-1));
441
    effect[3] = new VertexEffectRotate(angle1,axisX,center);
442
    effect[4] = new VertexEffectRotate(angle2,axisY,center);
443

  
444
    effect[2].setMeshAssociation(54,-1);  // meshes 1,2,4,5
445
    effect[3].setMeshAssociation(18,-1);  // meshes 1,4
446
    effect[4].setMeshAssociation(36,-1);  // meshes 2,5
447

  
448
    return effect;
449
    }
450

  
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452

  
453
  VertexEffect[] createVertexEffectsRexEdge()
454
    {
455
    float E = 0.5f - REX_D;
456
    float F = 0.5f;
457
    float G = (float)Math.sqrt(E*E+F*F);
458
    float A = (float)((180/Math.PI)*Math.asin(E/G));
459

  
460
    Static3D move1 = new Static3D(    0.0f, -E/3, 0.0f);
461
    Static3D move2 = new Static3D(2*G/3 -F, +E/3, 0.0f);
462

  
463
    Static3D center0= new Static3D(0.0f, 0.0f, 0.0f);
464
    Static3D center1= new Static3D(  -F, 0.0f, 0.0f);
465
    Static3D center2= new Static3D(  +F, 0.0f, 0.0f);
466
    Static3D axisX  = new Static3D(1.0f, 0.0f, 0.0f);
467
    Static3D axisY  = new Static3D(0.0f, 1.0f, 0.0f);
468
    Static3D axisZ  = new Static3D(0.0f, 0.0f, 1.0f);
469

  
470
    Static1D angle180 = new Static1D(180);
471
    Static1D angle90  = new Static1D( 90);
472
    Static1D angle270 = new Static1D(270);
473
    Static1D angle1   = new Static1D(+A);
474
    Static1D angle2   = new Static1D(-A);
475

  
476
    VertexEffect[] effect = new VertexEffect[12];
477

  
478
    effect[0] = new VertexEffectMove(move1);
479
    effect[1] = new VertexEffectMove(move2);
480
    effect[2] = new VertexEffectRotate(  angle90, axisX, center0 );
481
    effect[3] = new VertexEffectRotate( angle270, axisX, center0 );
482
    effect[4] = new VertexEffectRotate( angle180, axisX, center0 );
483
    effect[5] = new VertexEffectRotate( angle180, axisY, center0 );
484
    effect[6] = new VertexEffectScale ( new Static3D(-1, 1, 1) );
485
    effect[7] = new VertexEffectScale ( new Static3D( 1,-1, 1) );
486
    effect[8] = new VertexEffectRotate(   angle1, axisY, center1);
487
    effect[9] = new VertexEffectRotate(   angle2, axisY, center2);
488
    effect[10]= new VertexEffectRotate(   angle2, axisZ, center1);
489
    effect[11]= new VertexEffectRotate(   angle1, axisZ, center2);
490

  
491
    effect[0].setMeshAssociation( 3,-1);  // meshes 0 & 1
492
    effect[1].setMeshAssociation(60,-1);  // meshes 2,3,4,5
493
    effect[2].setMeshAssociation( 2,-1);  // meshes 1
494
    effect[3].setMeshAssociation(12,-1);  // meshes 2,3
495
    effect[4].setMeshAssociation(48,-1);  // meshes 4,5
496
    effect[5].setMeshAssociation(32,-1);  // mesh 5
497
    effect[6].setMeshAssociation( 8,-1);  // apply to mesh 3
498
    effect[7].setMeshAssociation( 2,-1);  // apply to mesh 1
499
    effect[8].setMeshAssociation(16,-1);  // apply to mesh 4
500
    effect[9].setMeshAssociation(32,-1);  // apply to mesh 5
501
    effect[10].setMeshAssociation(4,-1);  // apply to mesh 2
502
    effect[11].setMeshAssociation(8,-1);  // apply to mesh 3
503

  
504
    return effect;
505
    }
506

  
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508

  
509
  VertexEffect[] createVertexEffectsRexCorner()
510
    {
511
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
512
    Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
513
    Static1D angle = new Static1D(225);
514

  
515
    VertexEffect[] effect = new VertexEffect[1];
516
    effect[0] = new VertexEffectRotate(angle, axisZ, center);
517

  
518
    return effect;
519
    }
520

  
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522

  
523
  VertexEffect[] createCuboidEffects(int[] dimensions)
524
    {
525
    float X = dimensions[0];
526
    float Y = dimensions[1];
527
    float Z = dimensions[2];
528

  
529
    float MAX_XY = Math.max(X,Y);
530
    float MAX_XZ = Math.max(X,Z);
531
    float MAX_YZ = Math.max(Z,Y);
532

  
533
    Static1D angle = new Static1D(90);
534
    Static3D move  = new Static3D( 0.0f, 0.0f, 0.5f);
535
    Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f);
536
    Static3D axisY = new Static3D( 0.0f, 1.0f, 0.0f);
537
    Static3D center= new Static3D( 0.0f, 0.0f, 0.0f);
538

  
539
    Static3D scale3 = new Static3D(MAX_XY,MAX_XY,+Z);
540
    Static3D scale4 = new Static3D(MAX_XY,MAX_XY,-Z);
541
    Static3D scale5 = new Static3D(MAX_XZ,+Y,MAX_XZ);
542
    Static3D scale6 = new Static3D(MAX_XZ,-Y,MAX_XZ);
543
    Static3D scale7 = new Static3D(+X,MAX_YZ,MAX_YZ);
544
    Static3D scale8 = new Static3D(-X,MAX_YZ,MAX_YZ);
545

  
546
    VertexEffect[] effect = new VertexEffect[9];
547

  
548
    effect[0] = new VertexEffectMove(move);
549
    effect[1] = new VertexEffectRotate(angle, axisX, center);
550
    effect[2] = new VertexEffectRotate(angle, axisY, center);
551
    effect[3] = new VertexEffectScale(scale3);
552
    effect[4] = new VertexEffectScale(scale4);
553
    effect[5] = new VertexEffectScale(scale5);
554
    effect[6] = new VertexEffectScale(scale6);
555
    effect[7] = new VertexEffectScale(scale7);
556
    effect[8] = new VertexEffectScale(scale8);
557

  
558
    effect[1].setMeshAssociation(12,-1);  // meshes 2,3
559
    effect[2].setMeshAssociation( 3,-1);  // meshes 0,1
560
    effect[3].setMeshAssociation(16,-1);  // mesh 4
561
    effect[4].setMeshAssociation(32,-1);  // mesh 5
562
    effect[5].setMeshAssociation( 8,-1);  // mesh 3
563
    effect[6].setMeshAssociation( 4,-1);  // mesh 2
564
    effect[7].setMeshAssociation( 1,-1);  // mesh 0
565
    effect[8].setMeshAssociation( 2,-1);  // mesh 1
566

  
567
    return effect;
568
    }
569

  
570
///////////////////////////////////////////////////////////////////////////////////////////////////
571
// OBJECTS
572
///////////////////////////////////////////////////////////////////////////////////////////////////
573

  
574
  public MeshBase createIvyCornerMesh()
575
    {
576
    MeshBase mesh = createFacesIvyCorner();
577
    VertexEffect[] effects = createVertexEffectsIvyCorner();
578
    for( VertexEffect effect : effects ) mesh.apply(effect);
579

  
580
    Static3D center = new Static3D(-0.5f,-0.5f,-0.5f);
581
    Static3D[] vertices = new Static3D[4];
582
    vertices[0] = new Static3D(+0.0f,+0.0f,+0.0f);
583
    vertices[1] = new Static3D(-1.0f,+0.0f,+0.0f);
584
    vertices[2] = new Static3D(+0.0f,-1.0f,+0.0f);
585
    vertices[3] = new Static3D(+0.0f,+0.0f,-1.0f);
586

  
587
    roundCorners(mesh,center,vertices,0.03f,0.10f);
588

  
589
    mesh.mergeEffComponents();
590

  
591
    return mesh;
592
    }
593

  
594
///////////////////////////////////////////////////////////////////////////////////////////////////
595

  
596
  public MeshBase createIvyFaceMesh()
597
    {
598
    MeshBase mesh = createFacesIvyFace();
599

  
600
    Static3D center = new Static3D(-0.0f,-0.0f,-0.5f);
601
    Static3D[] vertices = new Static3D[2];
602
    vertices[0] = new Static3D(-0.5f,+0.5f,+0.0f);
603
    vertices[1] = new Static3D(+0.5f,-0.5f,+0.0f);
604

  
605
    roundCorners(mesh,center,vertices,0.03f,0.10f);
606

  
607
    mesh.mergeEffComponents();
608
    mesh.addEmptyTexComponent();
609
    mesh.addEmptyTexComponent();
610
    mesh.addEmptyTexComponent();
611
    mesh.addEmptyTexComponent();
612

  
613
    return mesh;
614
    }
615

  
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617

  
618
  public MeshBase createRexCornerMesh()
619
    {
620
    MeshBase mesh = createFacesRexCorner();
621
    VertexEffect[] effects = createVertexEffectsRexCorner();
622
    for( VertexEffect effect : effects ) mesh.apply(effect);
623

  
624
    final float G = (1-REX_D)/3;
625
    Static3D center = new Static3D(0.0f,0.0f,-G*SQ2/2);
626
    Static3D[] vertices = new Static3D[1];
627
    vertices[0] = new Static3D(+G,-G,+0.0f);
628
    roundCorners(mesh,center,vertices,0.10f,0.10f);
629

  
630
    mesh.mergeEffComponents();
631
    mesh.addEmptyTexComponent();
632
    mesh.addEmptyTexComponent();
633
    mesh.addEmptyTexComponent();
634
    mesh.addEmptyTexComponent();
635

  
636
    return mesh;
637
    }
638

  
639
///////////////////////////////////////////////////////////////////////////////////////////////////
640

  
641
  public MeshBase createRexFaceMesh()
642
    {
643
    MeshBase mesh = createFacesRexFace();
644

  
645
    mesh.mergeEffComponents();
646
    mesh.addEmptyTexComponent();
647
    mesh.addEmptyTexComponent();
648
    mesh.addEmptyTexComponent();
649
    mesh.addEmptyTexComponent();
650

  
651
    return mesh;
652
    }
653

  
654
///////////////////////////////////////////////////////////////////////////////////////////////////
655

  
656
  public MeshBase createRexEdgeMesh()
657
    {
658
    MeshBase mesh = createFacesRexEdge();
659
    VertexEffect[] effects = createVertexEffectsRexEdge();
660
    for( VertexEffect effect : effects ) mesh.apply(effect);
661

  
662
    Static3D center = new Static3D(0.0f,-0.5f,-0.5f);
663
    Static3D[] vertices = new Static3D[2];
664
    vertices[0] = new Static3D(+0.5f,+0.0f,+0.0f);
665
    vertices[1] = new Static3D(-0.5f,+0.0f,+0.0f);
666
    roundCorners(mesh,center,vertices,0.06f,0.10f);
667

  
668
    mesh.mergeEffComponents();
669

  
670
    return mesh;
671
    }
672

  
673
///////////////////////////////////////////////////////////////////////////////////////////////////
674

  
675
  public MeshBase createCuboidMesh(int[] dimensions)
676
    {
677
    MeshBase mesh = createCuboid(dimensions);
678
    VertexEffect[] effects = createCuboidEffects(dimensions);
679
    for( VertexEffect effect : effects ) mesh.apply(effect);
680

  
681
    int X = dimensions[0];
682
    int Y = dimensions[1];
683
    int Z = dimensions[2];
684

  
685
    float strength = 0.04f;
686
    float radius   = 0.15f;
687

  
688
    Static3D[] vertices = new Static3D[1];
689
    Static3D center;
690

  
691
    vertices[0] = new Static3D(+0.5f*X,+0.5f*Y,+0.5f*Z);
692
    center = new Static3D(+0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1));
693
    roundCorners(mesh, center, vertices, strength, radius);
694

  
695
    vertices[0] = new Static3D(+0.5f*X,+0.5f*Y,-0.5f*Z);
696
    center = new Static3D(+0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1));
697
    roundCorners(mesh, center, vertices, strength, radius);
698

  
699
    vertices[0] = new Static3D(+0.5f*X,-0.5f*Y,+0.5f*Z);
700
    center = new Static3D(+0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1));
701
    roundCorners(mesh, center, vertices, strength, radius);
702

  
703
    vertices[0] = new Static3D(+0.5f*X,-0.5f*Y,-0.5f*Z);
704
    center = new Static3D(+0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1));
705
    roundCorners(mesh, center, vertices, strength, radius);
706

  
707
    vertices[0] = new Static3D(-0.5f*X,+0.5f*Y,+0.5f*Z);
708
    center = new Static3D(-0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1));
709
    roundCorners(mesh, center, vertices, strength, radius);
710

  
711
    vertices[0] = new Static3D(-0.5f*X,+0.5f*Y,-0.5f*Z);
712
    center = new Static3D(-0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1));
713
    roundCorners(mesh, center, vertices, strength, radius);
714

  
715
    vertices[0] = new Static3D(-0.5f*X,-0.5f*Y,+0.5f*Z);
716
    center = new Static3D(-0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1));
717
    roundCorners(mesh, center, vertices, strength, radius);
718

  
719
    vertices[0] = new Static3D(-0.5f*X,-0.5f*Y,-0.5f*Z);
720
    center = new Static3D(-0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1));
721
    roundCorners(mesh, center, vertices, strength, radius);
722

  
723
    mesh.mergeEffComponents();
724

  
725
    return mesh;
726
    }
727

  
728 140
///////////////////////////////////////////////////////////////////////////////////////////////////
729 141

  
730 142
  private boolean areColinear(double[][] vertices, int index1, int index2, int index3)
......
1249 661
///////////////////////////////////////////////////////////////////////////////////////////////////
1250 662
// PUBLIC
1251 663

  
664
  public float[] computeBands(float H, int alpha, float dist, float K, int N)
665
    {
666
    float[] bands = new float[2*N];
667

  
668
    bands[0] = 1.0f;
669
    bands[1] = 0.0f;
670

  
671
    float beta = (float)Math.atan(dist*Math.tan(Math.PI*alpha/180));
672
    float sinBeta = (float)Math.sin(beta);
673
    float cosBeta = (float)Math.cos(beta);
674
    float R = cosBeta<1.0f ? H/(1.0f-cosBeta) : 0.0f;
675
    float D = R*sinBeta;
676
    float B = h(R,sinBeta,K*beta);
677

  
678
    if( D>1.0f )
679
      {
680
      for(int i=1; i<N; i++)
681
        {
682
        bands[2*i  ] = (float)(N-1-i)/(N-1);
683
        bands[2*i+1] = H*(1-bands[2*i]);
684
        }
685
      }
686
    else
687
      {
688
      int K2 = (int)((N-3)*K);
689
      int K1 = (N-3)-K2;
690

  
691
      for(int i=0; i<=K1; i++)
692
        {
693
        float angle = K*beta + (1-K)*beta*(K1-i)/(K1+1);
694
        float x = h(R,sinBeta,angle);
695
        bands[2*i+2] = 1.0f - x;
696
        bands[2*i+3] = g(R,D,x,cosBeta);
697
        }
698

  
699
      for(int i=0; i<=K2; i++)
700
        {
701
        float x = (1-B)*(i+1)/(K2+1) + B;
702
        bands[2*K1+2 + 2*i+2] = 1.0f - x;
703
        bands[2*K1+2 + 2*i+3] = g(R,D,f(D,B,x),cosBeta);
704
        }
705
      }
706

  
707
    bands[2*N-2] = 0.0f;
708
    bands[2*N-1] =    H;
709

  
710
    return bands;
711
    }
712

  
713
///////////////////////////////////////////////////////////////////////////////////////////////////
714

  
715
  public void roundCorners(MeshBase mesh, Static3D center, Static3D[] vertices, float strength, float regionRadius)
716
    {
717
    Static4D reg= new Static4D(0,0,0,regionRadius);
718

  
719
    float centX = center.get0();
720
    float centY = center.get1();
721
    float centZ = center.get2();
722

  
723
    for (Static3D vertex : vertices)
724
      {
725
      float x = strength*(centX - vertex.get0());
726
      float y = strength*(centY - vertex.get1());
727
      float z = strength*(centZ - vertex.get2());
728

  
729
      VertexEffect effect = new VertexEffectDeform(new Static3D(x,y,z), RADIUS, vertex, reg);
730
      mesh.apply(effect);
731
      }
732
    }
733

  
734
///////////////////////////////////////////////////////////////////////////////////////////////////
735

  
1252 736
  public void printStickerCoords()
1253 737
    {
1254 738
    int stickers = mStickerCoords.size();
src/main/java/org/distorted/helpers/FactorySticker.java
24 24

  
25 25
import static org.distorted.objects.TwistyObject.TEXTURE_HEIGHT;
26 26
import static org.distorted.objects.TwistyObject.COLOR_BLACK;
27
import static org.distorted.helpers.FactoryCubit.IVY_D;
28
import static org.distorted.helpers.FactoryCubit.IVY_C;
29
import static org.distorted.helpers.FactoryCubit.IVY_M;
30
import static org.distorted.helpers.FactoryCubit.REX_D;
27
import static org.distorted.objects.TwistyIvy.IVY_D;
28
import static org.distorted.objects.TwistyIvy.IVY_C;
29
import static org.distorted.objects.TwistyIvy.IVY_M;
30
import static org.distorted.objects.TwistyRex.REX_D;
31 31

  
32 32
///////////////////////////////////////////////////////////////////////////////////////////////////
33 33

  
src/main/java/org/distorted/objects/TwistyBandagedAbstract.java
26 26
import org.distorted.helpers.FactoryCubit;
27 27
import org.distorted.helpers.FactorySticker;
28 28
import org.distorted.library.effect.MatrixEffectQuaternion;
29
import org.distorted.library.effect.VertexEffect;
30
import org.distorted.library.effect.VertexEffectMove;
31
import org.distorted.library.effect.VertexEffectRotate;
32
import org.distorted.library.effect.VertexEffectScale;
29 33
import org.distorted.library.main.DistortedEffects;
30 34
import org.distorted.library.main.DistortedTexture;
31 35
import org.distorted.library.mesh.MeshBase;
36
import org.distorted.library.mesh.MeshJoined;
37
import org.distorted.library.mesh.MeshPolygon;
32 38
import org.distorted.library.mesh.MeshSquare;
39
import org.distorted.library.type.Static1D;
33 40
import org.distorted.library.type.Static3D;
34 41
import org.distorted.library.type.Static4D;
35 42

  
......
183 190
    return ( cubit>=0 && cubit< indices.length ) ? indices[cubit] : 0;
184 191
    }
185 192

  
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

  
195
  private float[] createVertices(int A, int B)
196
    {
197
    float E = 0.5f / Math.max(A,B);
198
    return new float[] { -A*E,-B*E, +A*E,-B*E, +A*E,+B*E, -A*E,+B*E };
199
    }
200

  
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

  
203
  private MeshBase createCuboid(int[] dimensions)
204
    {
205
    FactoryCubit factory = FactoryCubit.getInstance();
206

  
207
    int X = dimensions[0];
208
    int Y = dimensions[1];
209
    int Z = dimensions[2];
210

  
211
    float[] verticesXY = createVertices(X,Y);
212
    float[] verticesXZ = createVertices(X,Z);
213
    float[] verticesYZ = createVertices(Z,Y);
214

  
215
    float defHeight = 0.048f;
216

  
217
    float[] bandsX = factory.computeBands( defHeight/X,65,0.25f,0.5f,5);
218
    float[] bandsY = factory.computeBands( defHeight/Y,65,0.25f,0.5f,5);
219
    float[] bandsZ = factory.computeBands( defHeight/Z,65,0.25f,0.5f,5);
220

  
221
    MeshBase[] meshes = new MeshPolygon[6];
222

  
223
    meshes[0] = new MeshPolygon(verticesYZ,bandsX,1,2);
224
    meshes[0].setEffectAssociation(0,1,0);
225
    meshes[1] = meshes[0].copy(true);
226
    meshes[1].setEffectAssociation(0,2,0);
227
    meshes[2] = new MeshPolygon(verticesXZ,bandsY,1,2);
228
    meshes[2].setEffectAssociation(0,4,0);
229
    meshes[3] = meshes[2].copy(true);
230
    meshes[3].setEffectAssociation(0,8,0);
231
    meshes[4] = new MeshPolygon(verticesXY,bandsZ,1,2);
232
    meshes[4].setEffectAssociation(0,16,0);
233
    meshes[5] = meshes[4].copy(true);
234
    meshes[5].setEffectAssociation(0,32,0);
235

  
236
    return new MeshJoined(meshes);
237
    }
238

  
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

  
241
  private VertexEffect[] createCuboidEffects(int[] dimensions)
242
    {
243
    float X = dimensions[0];
244
    float Y = dimensions[1];
245
    float Z = dimensions[2];
246

  
247
    float MAX_XY = Math.max(X,Y);
248
    float MAX_XZ = Math.max(X,Z);
249
    float MAX_YZ = Math.max(Z,Y);
250

  
251
    Static1D angle = new Static1D(90);
252
    Static3D move  = new Static3D( 0.0f, 0.0f, 0.5f);
253
    Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f);
254
    Static3D axisY = new Static3D( 0.0f, 1.0f, 0.0f);
255
    Static3D center= new Static3D( 0.0f, 0.0f, 0.0f);
256

  
257
    Static3D scale3 = new Static3D(MAX_XY,MAX_XY,+Z);
258
    Static3D scale4 = new Static3D(MAX_XY,MAX_XY,-Z);
259
    Static3D scale5 = new Static3D(MAX_XZ,+Y,MAX_XZ);
260
    Static3D scale6 = new Static3D(MAX_XZ,-Y,MAX_XZ);
261
    Static3D scale7 = new Static3D(+X,MAX_YZ,MAX_YZ);
262
    Static3D scale8 = new Static3D(-X,MAX_YZ,MAX_YZ);
263

  
264
    VertexEffect[] effect = new VertexEffect[9];
265

  
266
    effect[0] = new VertexEffectMove(move);
267
    effect[1] = new VertexEffectRotate(angle, axisX, center);
268
    effect[2] = new VertexEffectRotate(angle, axisY, center);
269
    effect[3] = new VertexEffectScale(scale3);
270
    effect[4] = new VertexEffectScale(scale4);
271
    effect[5] = new VertexEffectScale(scale5);
272
    effect[6] = new VertexEffectScale(scale6);
273
    effect[7] = new VertexEffectScale(scale7);
274
    effect[8] = new VertexEffectScale(scale8);
275

  
276
    effect[1].setMeshAssociation(12,-1);  // meshes 2,3
277
    effect[2].setMeshAssociation( 3,-1);  // meshes 0,1
278
    effect[3].setMeshAssociation(16,-1);  // mesh 4
279
    effect[4].setMeshAssociation(32,-1);  // mesh 5
280
    effect[5].setMeshAssociation( 8,-1);  // mesh 3
281
    effect[6].setMeshAssociation( 4,-1);  // mesh 2
282
    effect[7].setMeshAssociation( 1,-1);  // mesh 0
283
    effect[8].setMeshAssociation( 2,-1);  // mesh 1
284

  
285
    return effect;
286
    }
287

  
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

  
290
  private MeshBase createCuboidMesh(int[] dimensions)
291
    {
292
    MeshBase mesh = createCuboid(dimensions);
293
    VertexEffect[] effects = createCuboidEffects(dimensions);
294
    for( VertexEffect effect : effects ) mesh.apply(effect);
295

  
296
    int X = dimensions[0];
297
    int Y = dimensions[1];
298
    int Z = dimensions[2];
299

  
300
    float strength = 0.04f;
301
    float radius   = 0.15f;
302

  
303
    Static3D[] vertices = new Static3D[1];
304
    Static3D center;
305
    FactoryCubit factory = FactoryCubit.getInstance();
306

  
307
    vertices[0] = new Static3D(+0.5f*X,+0.5f*Y,+0.5f*Z);
308
    center = new Static3D(+0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1));
309
    factory.roundCorners(mesh, center, vertices, strength, radius);
310

  
311
    vertices[0] = new Static3D(+0.5f*X,+0.5f*Y,-0.5f*Z);
312
    center = new Static3D(+0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1));
313
    factory.roundCorners(mesh, center, vertices, strength, radius);
314

  
315
    vertices[0] = new Static3D(+0.5f*X,-0.5f*Y,+0.5f*Z);
316
    center = new Static3D(+0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1));
317
    factory.roundCorners(mesh, center, vertices, strength, radius);
318

  
319
    vertices[0] = new Static3D(+0.5f*X,-0.5f*Y,-0.5f*Z);
320
    center = new Static3D(+0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1));
321
    factory.roundCorners(mesh, center, vertices, strength, radius);
322

  
323
    vertices[0] = new Static3D(-0.5f*X,+0.5f*Y,+0.5f*Z);
324
    center = new Static3D(-0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1));
325
    factory.roundCorners(mesh, center, vertices, strength, radius);
326

  
327
    vertices[0] = new Static3D(-0.5f*X,+0.5f*Y,-0.5f*Z);
328
    center = new Static3D(-0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1));
329
    factory.roundCorners(mesh, center, vertices, strength, radius);
330

  
331
    vertices[0] = new Static3D(-0.5f*X,-0.5f*Y,+0.5f*Z);
332
    center = new Static3D(-0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1));
333
    factory.roundCorners(mesh, center, vertices, strength, radius);
334

  
335
    vertices[0] = new Static3D(-0.5f*X,-0.5f*Y,-0.5f*Z);
336
    center = new Static3D(-0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1));
337
    factory.roundCorners(mesh, center, vertices, strength, radius);
338

  
339
    mesh.mergeEffComponents();
340

  
341
    return mesh;
342
    }
343

  
186 344
///////////////////////////////////////////////////////////////////////////////////////////////////
187 345

  
188 346
  MeshBase createCubitMesh(int cubit, int numLayers)
......
194 352

  
195 353
      for(int i=0; i<LEN; i++)
196 354
        {
197
        mMeshes[i] = FactoryCubit.getInstance().createCuboidMesh(mDimensions[i]);
355
        mMeshes[i] = createCuboidMesh(mDimensions[i]);
198 356
        }
199 357
      }
200 358

  
src/main/java/org/distorted/objects/TwistyIvy.java
26 26
import org.distorted.helpers.FactoryCubit;
27 27
import org.distorted.helpers.FactorySticker;
28 28
import org.distorted.library.effect.MatrixEffectQuaternion;
29
import org.distorted.library.effect.VertexEffect;
30
import org.distorted.library.effect.VertexEffectMove;
31
import org.distorted.library.effect.VertexEffectRotate;
32
import org.distorted.library.effect.VertexEffectScale;
29 33
import org.distorted.library.main.DistortedEffects;
30 34
import org.distorted.library.main.DistortedTexture;
31 35
import org.distorted.library.mesh.MeshBase;
36
import org.distorted.library.mesh.MeshJoined;
37
import org.distorted.library.mesh.MeshPolygon;
32 38
import org.distorted.library.mesh.MeshSquare;
39
import org.distorted.library.type.Static1D;
33 40
import org.distorted.library.type.Static3D;
34 41
import org.distorted.library.type.Static4D;
35 42
import org.distorted.main.R;
......
40 47

  
41 48
public class TwistyIvy extends TwistyObject
42 49
{
50
  public static final float IVY_D = 0.003f;
51
  public static final float IVY_C = 0.59f;
52
  public static final float IVY_M = 0.35f;
53
  private static final int IVY_N = 8;
54

  
43 55
  private static final int FACES_PER_CUBIT =6;
44 56

  
45 57
  // the four rotation axis of a RubikIvy. Must be normalized.
......
198 210
    return 0;
199 211
    }
200 212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

  
215
  MeshBase createFacesIvyCorner()
216
    {
217
    MeshBase[] meshes = new MeshBase[6];
218

  
219
    final float angle = (float)Math.PI/(2*IVY_N);
220
    final float CORR  = 1.0f - 2*IVY_D;
221
    final float DIST  = -0.5f*CORR + IVY_D;
222
    float[] vertices  = new float[2*(IVY_N+1)+6];
223

  
224
    vertices[0] = (0.5f-IVY_M) * IVY_C;
225
    vertices[1] = (DIST-IVY_M) * IVY_C;
226
    vertices[2] = (0.5f-IVY_M) * IVY_C;
227
    vertices[3] = (0.5f-IVY_M) * IVY_C;
228
    vertices[4] = (DIST-IVY_M) * IVY_C;
229
    vertices[5] = (0.5f-IVY_M) * IVY_C;
230

  
231
    for(int i=0; i<=IVY_N; i++)
232
      {
233
      float ang = (IVY_N-i)*angle;
234
      float sin = (float)Math.sin(ang);
235
      float cos = (float)Math.cos(ang);
236

  
237
      vertices[2*i+6] = (CORR*(cos-0.5f)-IVY_M)*IVY_C;
238
      vertices[2*i+7] = (CORR*(sin-0.5f)-IVY_M)*IVY_C;
239
      }
240

  
241
    FactoryCubit factory = FactoryCubit.getInstance();
242
    float[] bands0 = factory.computeBands(+0.012f,20,0.2f,0.5f,7);
243
    float[] bands1 = factory.computeBands(-0.100f,20,0.2f,0.0f,2);
244

  
245
    meshes[0] = new MeshPolygon(vertices,bands0,1,2);
246
    meshes[0].setEffectAssociation(0,1,0);
247
    meshes[1] = meshes[0].copy(true);
248
    meshes[1].setEffectAssociation(0,2,0);
249
    meshes[2] = meshes[0].copy(true);
250
    meshes[2].setEffectAssociation(0,4,0);
251
    meshes[3] = new MeshPolygon(vertices,bands1,1,2);
252
    meshes[3].setEffectAssociation(0,8,0);
253
    meshes[4] = meshes[3].copy(true);
254
    meshes[4].setEffectAssociation(0,16,0);
255
    meshes[5] = meshes[3].copy(true);
256
    meshes[5].setEffectAssociation(0,32,0);
257

  
258
    return new MeshJoined(meshes);
259
    }
260

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

  
263
  private VertexEffect[] createVertexEffectsIvyCorner()
264
    {
265
    Static3D axisX  = new Static3D(1,0,0);
266
    Static3D axisY  = new Static3D(0,1,0);
267
    Static1D angle1 = new Static1D(+90);
268
    Static1D angle2 = new Static1D(-90);
269
    Static3D center = new Static3D(0,0,0);
270
    Static3D move1  = new Static3D(IVY_M-0.5f,IVY_M-0.5f,0);
271

  
272
    VertexEffect[] effect = new VertexEffect[5];
273

  
274
    effect[0] = new VertexEffectScale(1/IVY_C);
275
    effect[1] = new VertexEffectMove(move1);
276
    effect[2] = new VertexEffectScale(new Static3D(1,1,-1));
277
    effect[3] = new VertexEffectRotate(angle1,axisX,center);
278
    effect[4] = new VertexEffectRotate(angle2,axisY,center);
279

  
280
    effect[2].setMeshAssociation(54,-1);  // meshes 1,2,4,5
281
    effect[3].setMeshAssociation(18,-1);  // meshes 1,4
282
    effect[4].setMeshAssociation(36,-1);  // meshes 2,5
283

  
284
    return effect;
285
    }
286

  
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288

  
289
  private MeshBase createFacesIvyFace()
290
    {
291
    MeshBase[] meshes = new MeshBase[2];
292

  
293
    final float angle = (float)Math.PI/(2*IVY_N);
294
    final float CORR  = 1.0f - 2*IVY_D;
295
    float[] vertices = new float[4*IVY_N];
296

  
297
    for(int i=0; i<IVY_N; i++)
298
      {
299
      float sin = (float)Math.sin(i*angle);
300
      float cos = (float)Math.cos(i*angle);
301

  
302
      vertices[2*i          ] = CORR*(0.5f-cos);
303
      vertices[2*i+1        ] = CORR*(0.5f-sin);
304
      vertices[2*i  +2*IVY_N] = CORR*(cos-0.5f);
305
      vertices[2*i+1+2*IVY_N] = CORR*(sin-0.5f);
306
      }
307

  
308
    FactoryCubit factory = FactoryCubit.getInstance();
309
    float[] bands0 = factory.computeBands(+0.03f,35,0.5f,0.5f,5);
310
    float[] bands1 = factory.computeBands(-0.10f,45,0.5f,0.0f,2);
311

  
312
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
313
    meshes[0].setEffectAssociation(0,1,0);
314
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
315
    meshes[1].setEffectAssociation(0,2,0);
316

  
317
    return new MeshJoined(meshes);
318
    }
319

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

  
322
  private MeshBase createIvyFaceMesh()
323
    {
324
    MeshBase mesh = createFacesIvyFace();
325

  
326
    Static3D center = new Static3D(-0.0f,-0.0f,-0.5f);
327
    Static3D[] vertices = new Static3D[2];
328
    vertices[0] = new Static3D(-0.5f,+0.5f,+0.0f);
329
    vertices[1] = new Static3D(+0.5f,-0.5f,+0.0f);
330

  
331
    FactoryCubit.getInstance().roundCorners(mesh,center,vertices,0.03f,0.10f);
332

  
333
    mesh.mergeEffComponents();
334
    mesh.addEmptyTexComponent();
335
    mesh.addEmptyTexComponent();
336
    mesh.addEmptyTexComponent();
337
    mesh.addEmptyTexComponent();
338

  
339
    return mesh;
340
    }
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

  
343
  private MeshBase createIvyCornerMesh()
344
    {
345
    MeshBase mesh = createFacesIvyCorner();
346
    VertexEffect[] effects = createVertexEffectsIvyCorner();
347
    for( VertexEffect effect : effects ) mesh.apply(effect);
348

  
349
    Static3D center = new Static3D(-0.5f,-0.5f,-0.5f);
350
    Static3D[] vertices = new Static3D[4];
351
    vertices[0] = new Static3D(+0.0f,+0.0f,+0.0f);
352
    vertices[1] = new Static3D(-1.0f,+0.0f,+0.0f);
353
    vertices[2] = new Static3D(+0.0f,-1.0f,+0.0f);
354
    vertices[3] = new Static3D(+0.0f,+0.0f,-1.0f);
355

  
356
    FactoryCubit.getInstance().roundCorners(mesh,center,vertices,0.03f,0.10f);
357

  
358
    mesh.mergeEffComponents();
359

  
360
    return mesh;
361
    }
362

  
201 363
///////////////////////////////////////////////////////////////////////////////////////////////////
202 364

  
203 365
  MeshBase createCubitMesh(int cubit, int numLayers)
......
206 368

  
207 369
    if( cubit<4 )
208 370
      {
209
      if( mCornerMesh==null ) mCornerMesh = FactoryCubit.getInstance().createIvyCornerMesh();
371
      if( mCornerMesh==null ) mCornerMesh = createIvyCornerMesh();
210 372
      mesh = mCornerMesh.copy(true);
211 373
      }
212 374
    else
213 375
      {
214
      if( mFaceMesh==null ) mFaceMesh = FactoryCubit.getInstance().createIvyFaceMesh();
376
      if( mFaceMesh==null ) mFaceMesh = createIvyFaceMesh();
215 377
      mesh = mFaceMesh.copy(true);
216 378
      }
217 379

  
src/main/java/org/distorted/objects/TwistyRex.java
26 26
import org.distorted.helpers.FactoryCubit;
27 27
import org.distorted.helpers.FactorySticker;
28 28
import org.distorted.library.effect.MatrixEffectQuaternion;
29
import org.distorted.library.effect.VertexEffect;
30
import org.distorted.library.effect.VertexEffectMove;
31
import org.distorted.library.effect.VertexEffectRotate;
32
import org.distorted.library.effect.VertexEffectScale;
29 33
import org.distorted.library.main.DistortedEffects;
30 34
import org.distorted.library.main.DistortedTexture;
31 35
import org.distorted.library.mesh.MeshBase;
36
import org.distorted.library.mesh.MeshJoined;
37
import org.distorted.library.mesh.MeshPolygon;
32 38
import org.distorted.library.mesh.MeshSquare;
39
import org.distorted.library.type.Static1D;
33 40
import org.distorted.library.type.Static3D;
34 41
import org.distorted.library.type.Static4D;
35 42
import org.distorted.main.R;
36 43

  
37 44
import java.util.Random;
38 45

  
39
import static org.distorted.helpers.FactoryCubit.REX_D;
40

  
41 46
///////////////////////////////////////////////////////////////////////////////////////////////////
42 47

  
43 48
public class TwistyRex extends TwistyObject
44 49
{
45 50
  private static final int FACES_PER_CUBIT =6;
46 51

  
52
  public static final float REX_D = 0.2f;
53

  
47 54
  // the four rotation axis of a RubikRex. Must be normalized.
48 55
  static final Static3D[] ROT_AXIS = new Static3D[]
49 56
         {
......
299 306
    return QUATS[0];
300 307
    }
301 308

  
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

  
311
  MeshBase createFacesRexCorner()
312
    {
313
    MeshBase[] meshes = new MeshBase[2];
314

  
315
    float F = REX_D*SQ2;
316
    float G = (1-REX_D)*SQ2/2;
317
    float H = 0.1f;
318
    float J = +2*G/3 - H*G;
319

  
320
    float[] vertices = { -F/2, -G/3, +F/2, -G/3, H*F/2, J, -H*F/2, J};
321

  
322
    FactoryCubit factory = FactoryCubit.getInstance();
323
    float[] bands0 = factory.computeBands(+0.016f,10,G/3,0.5f,5);
324
    float[] bands1 = factory.computeBands(-0.230f,45,G/3,0.0f,2);
325

  
326
    meshes[0] = new MeshPolygon(vertices,bands0,1,1);
327
    meshes[0].setEffectAssociation(0,1,0);
328
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
329
    meshes[1].setEffectAssociation(0,2,0);
330

  
331
    return new MeshJoined(meshes);
332
    }
333

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

  
336
  MeshBase createFacesRexFace()
337
    {
338
    MeshBase[] meshes = new MeshBase[2];
339

  
340
    float[] vertices = { -REX_D,0.0f, 0.0f, -REX_D, +REX_D, 0.0f, 0.0f, +REX_D};
341

  
342
    FactoryCubit factory = FactoryCubit.getInstance();
343
    float[] bands0 = factory.computeBands(0.016f,10,REX_D/2,0.5f,5);
344
    float[] bands1 = factory.computeBands(0.000f,45,REX_D/2,0.0f,2);
345

  
346
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
347
    meshes[0].setEffectAssociation(0,1,0);
348
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
349
    meshes[1].setEffectAssociation(0,2,0);
350

  
351
    return new MeshJoined(meshes);
352
    }
353

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

  
356
  MeshBase createFacesRexEdge()
357
    {
358
    MeshBase[] meshes = new MeshPolygon[6];
359
    FactoryCubit factory = FactoryCubit.getInstance();
360

  
361
    float E = 0.5f - REX_D;
362
    float F = 0.5f;
363
    float[] vertices0 = { -F,E/3, 0,-2*E/3, +F,E/3 };
364
    float[] bands0 = factory.computeBands(0.03f,27,F/3,0.8f,5);
365

  
366
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 3);
367
    meshes[0].setEffectAssociation(0,1,0);
368
    meshes[1] = meshes[0].copy(true);
369
    meshes[1].setEffectAssociation(0,2,0);
370

  
371
    float G = (float)Math.sqrt(E*E+F*F);
372
    float[] vertices1 = { -2*G/3, -E/3, G/3, -E/3, G/3, 2*E/3 };
373
    float[] bands1 = factory.computeBands(0.00f,45,G/3,0.2f,3);
374

  
375
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
376
    meshes[2].setEffectAssociation(0,4,0);
377
    meshes[3] = meshes[2].copy(true);
378
    meshes[3].setEffectAssociation(0,8,0);
379
    meshes[4] = meshes[2].copy(true);
380
    meshes[4].setEffectAssociation(0,16,0);
381
    meshes[5] = meshes[2].copy(true);
382
    meshes[5].setEffectAssociation(0,32,0);
383

  
384
    return new MeshJoined(meshes);
385
    }
386

  
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388

  
389
  private VertexEffect[] createVertexEffectsRexEdge()
390
    {
391
    float E = 0.5f - REX_D;
392
    float F = 0.5f;
393
    float G = (float)Math.sqrt(E*E+F*F);
394
    float A = (float)((180/Math.PI)*Math.asin(E/G));
395

  
396
    Static3D move1 = new Static3D(    0.0f, -E/3, 0.0f);
397
    Static3D move2 = new Static3D(2*G/3 -F, +E/3, 0.0f);
398

  
399
    Static3D center0= new Static3D(0.0f, 0.0f, 0.0f);
400
    Static3D center1= new Static3D(  -F, 0.0f, 0.0f);
401
    Static3D center2= new Static3D(  +F, 0.0f, 0.0f);
402
    Static3D axisX  = new Static3D(1.0f, 0.0f, 0.0f);
403
    Static3D axisY  = new Static3D(0.0f, 1.0f, 0.0f);
404
    Static3D axisZ  = new Static3D(0.0f, 0.0f, 1.0f);
405

  
406
    Static1D angle180 = new Static1D(180);
407
    Static1D angle90  = new Static1D( 90);
408
    Static1D angle270 = new Static1D(270);
409
    Static1D angle1   = new Static1D(+A);
410
    Static1D angle2   = new Static1D(-A);
411

  
412
    VertexEffect[] effect = new VertexEffect[12];
413

  
414
    effect[0] = new VertexEffectMove(move1);
415
    effect[1] = new VertexEffectMove(move2);
416
    effect[2] = new VertexEffectRotate(  angle90, axisX, center0 );
417
    effect[3] = new VertexEffectRotate( angle270, axisX, center0 );
418
    effect[4] = new VertexEffectRotate( angle180, axisX, center0 );
419
    effect[5] = new VertexEffectRotate( angle180, axisY, center0 );
420
    effect[6] = new VertexEffectScale( new Static3D(-1, 1, 1) );
421
    effect[7] = new VertexEffectScale ( new Static3D( 1,-1, 1) );
422
    effect[8] = new VertexEffectRotate(   angle1, axisY, center1);
423
    effect[9] = new VertexEffectRotate(   angle2, axisY, center2);
424
    effect[10]= new VertexEffectRotate(   angle2, axisZ, center1);
425
    effect[11]= new VertexEffectRotate(   angle1, axisZ, center2);
426

  
427
    effect[0].setMeshAssociation( 3,-1);  // meshes 0 & 1
428
    effect[1].setMeshAssociation(60,-1);  // meshes 2,3,4,5
429
    effect[2].setMeshAssociation( 2,-1);  // meshes 1
430
    effect[3].setMeshAssociation(12,-1);  // meshes 2,3
431
    effect[4].setMeshAssociation(48,-1);  // meshes 4,5
432
    effect[5].setMeshAssociation(32,-1);  // mesh 5
433
    effect[6].setMeshAssociation( 8,-1);  // apply to mesh 3
434
    effect[7].setMeshAssociation( 2,-1);  // apply to mesh 1
435
    effect[8].setMeshAssociation(16,-1);  // apply to mesh 4
436
    effect[9].setMeshAssociation(32,-1);  // apply to mesh 5
437
    effect[10].setMeshAssociation(4,-1);  // apply to mesh 2
438
    effect[11].setMeshAssociation(8,-1);  // apply to mesh 3
439

  
440
    return effect;
441
    }
442

  
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444

  
445
  private VertexEffect[] createVertexEffectsRexCorner()
446
    {
447
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
448
    Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
449
    Static1D angle = new Static1D(225);
450

  
451
    VertexEffect[] effect = new VertexEffect[1];
452
    effect[0] = new VertexEffectRotate(angle, axisZ, center);
453

  
454
    return effect;
455
    }
456

  
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458

  
459
  private MeshBase createRexCornerMesh()
460
    {
461
    MeshBase mesh = createFacesRexCorner();
462
    VertexEffect[] effects = createVertexEffectsRexCorner();
463
    for( VertexEffect effect : effects ) mesh.apply(effect);
464

  
465
    final float G = (1-REX_D)/3;
466
    Static3D center = new Static3D(0.0f,0.0f,-G*SQ2/2);
467
    Static3D[] vertices = new Static3D[1];
468
    vertices[0] = new Static3D(+G,-G,+0.0f);
469
    FactoryCubit.getInstance().roundCorners(mesh,center,vertices,0.10f,0.10f);
470

  
471
    mesh.mergeEffComponents();
472
    mesh.addEmptyTexComponent();
473
    mesh.addEmptyTexComponent();
474
    mesh.addEmptyTexComponent();
475
    mesh.addEmptyTexComponent();
476

  
477
    return mesh;
478
    }
479

  
480
///////////////////////////////////////////////////////////////////////////////////////////////////
481

  
482
  private MeshBase createRexFaceMesh()
483
    {
484
    MeshBase mesh = createFacesRexFace();
485

  
486
    mesh.mergeEffComponents();
487
    mesh.addEmptyTexComponent();
488
    mesh.addEmptyTexComponent();
489
    mesh.addEmptyTexComponent();
490
    mesh.addEmptyTexComponent();
491

  
492
    return mesh;
493
    }
494

  
495
///////////////////////////////////////////////////////////////////////////////////////////////////
496

  
497
  private MeshBase createRexEdgeMesh()
498
    {
499
    MeshBase mesh = createFacesRexEdge();
500
    VertexEffect[] effects = createVertexEffectsRexEdge();
501
    for( VertexEffect effect : effects ) mesh.apply(effect);
502

  
503
    Static3D center = new Static3D(0.0f,-0.5f,-0.5f);
504
    Static3D[] vertices = new Static3D[2];
505
    vertices[0] = new Static3D(+0.5f,+0.0f,+0.0f);
506
    vertices[1] = new Static3D(-0.5f,+0.0f,+0.0f);
507
    FactoryCubit.getInstance().roundCorners(mesh,center,vertices,0.06f,0.10f);
508

  
509
    mesh.mergeEffComponents();
510

  
511
    return mesh;
512
    }
513

  
302 514
///////////////////////////////////////////////////////////////////////////////////////////////////
303 515

  
304 516
  MeshBase createCubitMesh(int cubit, int numLayers)
......
307 519

  
308 520
    if( cubit<24 )
309 521
      {
310
      if( mCornerMesh==null ) mCornerMesh = FactoryCubit.getInstance().createRexCornerMesh();
522
      if( mCornerMesh==null ) mCornerMesh = createRexCornerMesh();
311 523
      mesh = mCornerMesh.copy(true);
312 524
      }
313 525
    else if( cubit<30 )
314 526
      {
315
      if( mFaceMesh==null ) mFaceMesh = FactoryCubit.getInstance().createRexFaceMesh();
527
      if( mFaceMesh==null ) mFaceMesh = createRexFaceMesh();
316 528
      mesh = mFaceMesh.copy(true);
317 529
      }
318 530
    else
319 531
      {
320
      if( mEdgeMesh==null ) mEdgeMesh = FactoryCubit.getInstance().createRexEdgeMesh();
532
      if( mEdgeMesh==null ) mEdgeMesh = createRexEdgeMesh();
321 533
      mesh = mEdgeMesh.copy(true);
322 534
      }
323 535

  
src/main/java/org/distorted/objects/TwistySkewb.java
167 167
             {4,0,3}
168 168
          };
169 169

  
170

  
171 170
  private static final float[][] STICKERS = new float[][]
172 171
          {
173
             { -0.5f,   0.25f, 0.25f,  -0.5f, 0.25f, 0.25f  },
174
             {  0.0f, -1.0f/3, 0.50f, 1.0f/6, -0.5f, 1.0f/6 },
175
             { -0.5f,    0.0f, 0.00f,  -0.5f, 0.50f, 0.0f, 0.0f, 0.5f }
172
             { -0.5f, 0.25f, 0.25f,  -0.5f, 0.25f, 0.25f  },
173
             { -0.5f, 0.00f, 0.00f,  -0.5f, 0.50f, 0.0f, 0.0f, 0.5f }
176 174
          };
177 175

  
178 176
  private static MeshBase[] mMeshes;
......
583 581
    {
584 582
    int COLORS = FACE_COLORS.length;
585 583
    float R=0.0f,S=0.0f;
586
    int cubitType = face/COLORS;
584
    int index=0, cubitType = face/COLORS;
587 585

  
588 586
    switch(cubitType)
589 587
      {
590
      case 0: R = 0.025f; S = 0.045f; break;
591
      case 1: R = 0.025f; S = 0.035f; break;
592
      case 2: R = 0.055f; S = 0.035f; break;
588
      case 0: R = 0.025f; S = 0.045f; index= 0; break;
589
      case 1: R = 0.025f; S = 0.035f; index= 0; break;
590
      case 2: R = 0.055f; S = 0.035f; index= 1; break;
593 591
      }
594 592

  
595 593
    FactorySticker factory = FactorySticker.getInstance();
596
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[cubitType], S, FACE_COLORS[face%COLORS], R);
594
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[index], S, FACE_COLORS[face%COLORS], R);
597 595
    }
598 596

  
599 597
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff