Project

General

Profile

Download (69 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / FactoryCubit.java @ e4bf4d02

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objects;
21

    
22
import org.distorted.library.effect.VertexEffect;
23
import org.distorted.library.effect.VertexEffectDeform;
24
import org.distorted.library.effect.VertexEffectMove;
25
import org.distorted.library.effect.VertexEffectRotate;
26
import org.distorted.library.effect.VertexEffectScale;
27
import org.distorted.library.mesh.MeshBase;
28
import org.distorted.library.mesh.MeshJoined;
29
import org.distorted.library.mesh.MeshPolygon;
30
import org.distorted.library.type.Static1D;
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33

    
34
import static org.distorted.objects.TwistyMegaminx.MEGA_D;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
class FactoryCubit
39
  {
40
  static final float IVY_D = 0.003f;
41
  static final float IVY_C = 0.59f;
42
  static final float IVY_M = 0.35f;
43
  static final float REX_D = 0.2f;
44

    
45
  private static final float SQ2 = (float)Math.sqrt(2);
46
  private static final float SQ3 = (float)Math.sqrt(3);
47
  private static final float SQ5 = (float)Math.sqrt(5);
48
  private static final float SQ6 = (float)Math.sqrt(6);
49

    
50
  static final float SIN54    = (SQ5+1)/4;
51
  static final float COS54    = (float)(Math.sqrt(10-2*SQ5)/4);
52
  static final float SIN18    = (SQ5-1)/4;
53
  static final float COS18    = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
54
  static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
55
  static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
56

    
57
  static final float DIHEDRAL1= (float)(Math.acos(-SQ5/5)*180/Math.PI);
58
  static final float DIHEDRAL2= (float)((180/Math.PI)*Math.asin((2*SIN54*SIN54-1)/COS54) - 90);
59

    
60
  static final float MINX_SC  = 0.5f;
61

    
62
  private static final int IVY_N = 8;
63

    
64
  private static final Static1D RADIUS = new Static1D(1);
65
  private static FactoryCubit mThis;
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  private FactoryCubit()
70
    {
71

    
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  public static FactoryCubit getInstance()
77
    {
78
    if( mThis==null ) mThis = new FactoryCubit();
79

    
80
    return mThis;
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84
// H - height of the band in the middle
85
// alpha - angle of the edge  [0,90]
86
// dist - often in a polygon the distance from edge to center is not 1, but something else.
87
// This is the distance.
88
// K - where to begin the second, much more flat part of the band. [0,1]
89
// N - number of bands. N>=3
90
//
91
// theory: two distinct parts to the band:
92
// 1) (0,B) - steep
93
// 2) (B,1) - flat
94
//
95
// In first part, we have y = g(x) ; in second - y = g(f(x)) where
96
//
97
// g(x) = sqrt( R^2 - (x-D)^2 ) - R*cos(alpha)
98
// f(x) = ((D-B)/(1-B)*x + B*(1-D)/(1-B)
99
// h(x) = R*(sin(alpha) - sin(x))
100
// R = H/(1-cos(alpha))
101
// D = H*sin(alpha)
102
// B = h(K*alpha)
103
//
104
// The N points are taken at:
105
//
106
// 1) in the second part, there are K2 = (N-3)/3 such points
107
// 2) in the first - K1 = (N-3) - K2
108
// 3) also, the 3 points 0,B,1
109
//
110
// so we have the sequence A[i] of N points
111
//
112
// 0
113
// h((i+1)*(1-K)*alpha/(K1+1)) (i=0,1,...,K1-1)
114
// B
115
// (1-B)*(i+1)/(K2+1) + B   (i=0,i,...,K2-1)
116
// 1
117

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

    
120
  private float f(float D, float B, float x)
121
    {
122
    return ((D-B)*x + B*(1-D))/(1-B);
123
    }
124

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

    
127
  private float g(float R, float D, float x, float cosAlpha)
128
    {
129
    float d = x-D;
130
    return (float)(Math.sqrt(R*R-d*d)-R*cosAlpha);
131
    }
132

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

    
135
  private float h(float R, float sinAlpha, float x)
136
    {
137
    return R*(sinAlpha-(float)Math.sin(x));
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
  private float[] computeBands(float H, int alpha, float dist, float K, int N)
143
    {
144
    float[] bands = new float[2*N];
145

    
146
    bands[0] = 1.0f;
147
    bands[1] = 0.0f;
148

    
149
    float beta = (float)Math.atan(dist*Math.tan(Math.PI*alpha/180));
150
    float sinBeta = (float)Math.sin(beta);
151
    float cosBeta = (float)Math.cos(beta);
152
    float R = cosBeta<1.0f ? H/(1.0f-cosBeta) : 0.0f;
153
    float D = R*sinBeta;
154
    float B = h(R,sinBeta,K*beta);
155

    
156
    if( D>1.0f )
157
      {
158
      for(int i=1; i<N; i++)
159
        {
160
        bands[2*i  ] = (float)(N-1-i)/(N-1);
161
        bands[2*i+1] = H*(1-bands[2*i]);
162
        }
163
      }
164
    else
165
      {
166
      int K2 = (int)((N-3)*K);
167
      int K1 = (N-3)-K2;
168

    
169
      for(int i=0; i<=K1; i++)
170
        {
171
        float angle = K*beta + (1-K)*beta*(K1-i)/(K1+1);
172
        float x = h(R,sinBeta,angle);
173
        bands[2*i+2] = 1.0f - x;
174
        bands[2*i+3] = g(R,D,x,cosBeta);
175
        }
176

    
177
      for(int i=0; i<=K2; i++)
178
        {
179
        float x = (1-B)*(i+1)/(K2+1) + B;
180
        bands[2*K1+2 + 2*i+2] = 1.0f - x;
181
        bands[2*K1+2 + 2*i+3] = g(R,D,f(D,B,x),cosBeta);
182
        }
183
      }
184

    
185
    bands[2*N-2] = 0.0f;
186
    bands[2*N-1] =    H;
187

    
188
    return bands;
189
    }
190

    
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

    
193
  private void roundCorners(MeshBase mesh, Static3D center, Static3D[] vertices, float strength, float regionRadius)
194
    {
195
    Static4D reg= new Static4D(0,0,0,regionRadius);
196

    
197
    float centX = center.get0();
198
    float centY = center.get1();
199
    float centZ = center.get2();
200

    
201
    for (Static3D vertex : vertices)
202
      {
203
      float x = strength*(centX - vertex.get0());
204
      float y = strength*(centY - vertex.get1());
205
      float z = strength*(centZ - vertex.get2());
206

    
207
      VertexEffect effect = new VertexEffectDeform(new Static3D(x,y,z), RADIUS, vertex, reg);
208
      mesh.apply(effect);
209
      }
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213
// Compute (rx,ry) - coords of a point which is the result of rotation by angle 'radians' of the
214
// point (px,py) along axis Z. Center of rotation: (cx,cy). Rotation is counterclockwise!
215
// Write (rx,ry) to array[index] and array[index+1].
216

    
217
  private void writeVertex( float cx, float cy, float px, float py, float radians, float[] array, int index)
218
    {
219
    float vx = px-cx;
220
    float vy = py-cy;
221

    
222
    float sinA = (float)Math.sin(radians);
223
    float cosA = (float)Math.cos(radians);
224

    
225
    float rvx = vx*cosA - vy*sinA;
226
    float rvy = vx*sinA + vy*cosA;
227

    
228
    array[index  ] = rvx + cx;
229
    array[index+1] = rvy + cy;
230
    }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
  MeshBase createFacesCube(int sizeIndex)
235
    {
236
    MeshBase[] meshes = new MeshPolygon[6];
237

    
238
    float E = 0.5f;
239
    int extraI, extraV, num;
240

    
241
    switch(sizeIndex)
242
      {
243
      case 0 : num = 6; extraI = 2; extraV = 2; break;
244
      case 1 : num = 5; extraI = 2; extraV = 2; break;
245
      case 2 : num = 5; extraI = 1; extraV = 2; break;
246
      default: num = 4; extraI = 1; extraV = 1; break;
247
      }
248

    
249
    float[] vertices = { -E,-E, +E,-E, +E,+E, -E,+E };
250
    float[] bands = computeBands(0.048f,35,E,0.7f,num);
251

    
252
    meshes[0] = new MeshPolygon(vertices,bands,extraI,extraV);
253
    meshes[0].setEffectAssociation(0,1,0);
254
    meshes[1] = meshes[0].copy(true);
255
    meshes[1].setEffectAssociation(0,2,0);
256
    meshes[2] = meshes[0].copy(true);
257
    meshes[2].setEffectAssociation(0,4,0);
258
    meshes[3] = meshes[0].copy(true);
259
    meshes[3].setEffectAssociation(0,8,0);
260
    meshes[4] = meshes[0].copy(true);
261
    meshes[4].setEffectAssociation(0,16,0);
262
    meshes[5] = meshes[0].copy(true);
263
    meshes[5].setEffectAssociation(0,32,0);
264

    
265
    return new MeshJoined(meshes);
266
    }
267

    
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269

    
270
  MeshBase createFacesSkewbCorner()
271
    {
272
    MeshBase[] meshes = new MeshBase[6];
273

    
274
    float E = 0.5f;
275
    float F = SQ2/2;
276
    float G = SQ6/16;
277
    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
278
    float[] bands0 = computeBands(0.028f,35,E/3,0.7f,7);
279

    
280
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
281
    meshes[0].setEffectAssociation(0,1,0);
282
    meshes[1] = meshes[0].copy(true);
283
    meshes[1].setEffectAssociation(0,2,0);
284
    meshes[2] = meshes[0].copy(true);
285
    meshes[2].setEffectAssociation(0,4,0);
286

    
287
    float[] vertices1 = { -F/2,-2*G, F/2,-2*G, 3*F/8,-G, 1*F/8,G, 0,2*G };
288
    float[] bands1 = computeBands(0,0,1,0,3);
289

    
290
    meshes[3] = new MeshPolygon(vertices1,bands1,1,5);
291
    meshes[3].setEffectAssociation(0,8,0);
292
    meshes[4] = meshes[3].copy(true);
293
    meshes[4].setEffectAssociation(0,16,0);
294
    meshes[5] = meshes[3].copy(true);
295
    meshes[5].setEffectAssociation(0,32,0);
296

    
297
    return new MeshJoined(meshes);
298
    }
299

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

    
302
  MeshBase createFacesSkewbFace()
303
    {
304
    MeshBase[] meshes = new MeshBase[5];
305

    
306
    float E = SQ2/4;
307
    float[] vertices0 = { -E,-E, +E,-E, +E,+E, -E,+E };
308
    float[] bands0 = computeBands(0.051f,35,E/2,0.9f,7);
309

    
310
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
311
    meshes[0].setEffectAssociation(0,1,0);
312

    
313
    float[] vertices1 = { -E,-SQ3*E, -E*0.7f,-SQ3*E, +E*0.7f,-SQ3*E, +E,-SQ3*E, 0,0 };
314
    float[] bands1 = computeBands(0,0,1,0,3);
315

    
316
    meshes[1] = new MeshPolygon(vertices1,bands1,0,0);
317
    meshes[1].setEffectAssociation(0,2,0);
318
    meshes[2] = meshes[1].copy(true);
319
    meshes[2].setEffectAssociation(0,4,0);
320
    meshes[3] = meshes[1].copy(true);
321
    meshes[3].setEffectAssociation(0,8,0);
322
    meshes[4] = meshes[1].copy(true);
323
    meshes[4].setEffectAssociation(0,16,0);
324

    
325
    return new MeshJoined(meshes);
326
    }
327

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

    
330
  MeshBase createFacesOcta()
331
    {
332
    MeshBase[] meshes = new MeshPolygon[8];
333

    
334
    float E = 0.75f;
335
    float F = 0.5f;
336
    float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
337
    float[] bands = computeBands(0.05f,35,F,0.8f,6);
338

    
339
    meshes[0] = new MeshPolygon(vertices, bands, 2,2);
340
    meshes[0].setEffectAssociation(0,1,0);
341
    meshes[1] = meshes[0].copy(true);
342
    meshes[1].setEffectAssociation(0,2,0);
343
    meshes[2] = meshes[0].copy(true);
344
    meshes[2].setEffectAssociation(0,4,0);
345
    meshes[3] = meshes[0].copy(true);
346
    meshes[3].setEffectAssociation(0,8,0);
347
    meshes[4] = meshes[0].copy(true);
348
    meshes[4].setEffectAssociation(0,16,0);
349
    meshes[5] = meshes[0].copy(true);
350
    meshes[5].setEffectAssociation(0,32,0);
351
    meshes[6] = meshes[0].copy(true);
352
    meshes[6].setEffectAssociation(0,64,0);
353
    meshes[7] = meshes[0].copy(true);
354
    meshes[7].setEffectAssociation(0,128,0);
355

    
356
    return new MeshJoined(meshes);
357
    }
358

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360

    
361
  MeshBase createFacesTetra()
362
    {
363
    MeshBase[] meshes = new MeshBase[4];
364

    
365
    float E = 0.75f;
366
    float F = 0.5f;
367
    float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
368
    float[] bands = computeBands(0.05f,35,F,0.8f,6);
369

    
370
    meshes[0] = new MeshPolygon(vertices, bands, 2,2);
371
    meshes[0].setEffectAssociation(0,1,0);
372
    meshes[1] = meshes[0].copy(true);
373
    meshes[1].setEffectAssociation(0,2,0);
374
    meshes[2] = meshes[0].copy(true);
375
    meshes[2].setEffectAssociation(0,4,0);
376
    meshes[3] = meshes[0].copy(true);
377
    meshes[3].setEffectAssociation(0,8,0);
378

    
379
    return new MeshJoined(meshes);
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

    
384
  MeshBase createFacesDino()
385
    {
386
    MeshBase[] meshes = new MeshPolygon[4];
387

    
388
    float E = 0.5f*SQ2;
389
    float F = 0.5f;
390
    float[] vertices0 = { -F,F/3, 0,-2*F/3, +F,F/3 };
391
    float[] bands0 = computeBands(0.028f,30,F/3,0.8f,7);
392

    
393
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 5);
394
    meshes[0].setEffectAssociation(0,1,0);
395
    meshes[1] = meshes[0].copy(true);
396
    meshes[1].setEffectAssociation(0,2,0);
397

    
398
    float[] vertices1 = { -E/2,-E*(SQ3/6), E/2,-E*(SQ3/6), 0,E*(SQ3/3) };
399
    float[] bands1 = computeBands(0.02f,45,F/3,0.2f,3);
400

    
401
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
402
    meshes[2].setEffectAssociation(0,4,0);
403
    meshes[3] = meshes[2].copy(true);
404
    meshes[3].setEffectAssociation(0,8,0);
405

    
406
    return new MeshJoined(meshes);
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410

    
411
  MeshBase createFacesHelicopterCorner()
412
    {
413
    MeshBase[] meshes = new MeshBase[6];
414

    
415
    float E = 0.5f;
416
    float F = SQ2/4;
417
    float G = 1.0f/12;
418
    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
419
    float[] bands0 = computeBands(0.028f,35,E/4,0.7f,7);
420

    
421
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
422
    meshes[0].setEffectAssociation(0,1,0);
423
    meshes[1] = meshes[0].copy(true);
424
    meshes[1].setEffectAssociation(0,2,0);
425
    meshes[2] = meshes[0].copy(true);
426
    meshes[2].setEffectAssociation(0,4,0);
427

    
428
    float[] vertices1 = { -F,-G, 0,-G, +F,-G, 0,2*G };
429
    float[] bands1 = computeBands(0.00f,0,0,0.0f,3);
430
    meshes[3] = new MeshPolygon(vertices1,bands1,1,5);
431
    meshes[3].setEffectAssociation(0,8,0);
432
    meshes[4] = meshes[3].copy(true);
433
    meshes[4].setEffectAssociation(0,16,0);
434
    meshes[5] = meshes[3].copy(true);
435
    meshes[5].setEffectAssociation(0,32,0);
436

    
437
    return new MeshJoined(meshes);
438
    }
439

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

    
442
  MeshBase createFacesHelicopterFace()
443
    {
444
    MeshBase[] meshes = new MeshBase[4];
445

    
446
    float E = 0.5f;
447
    float F = SQ2/4;
448
    float G = 1.0f/12;
449
    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
450
    float[] bands0 = computeBands(0.028f,35,E/4,0.7f,7);
451

    
452
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
453
    meshes[0].setEffectAssociation(0,1,0);
454

    
455
    float[] vertices1 = { -F,-G, +F,-G, 0,2*G};
456
    float[] bands1 = computeBands(0.01f,45,F,0.0f,3);
457

    
458
    meshes[1] = new MeshPolygon(vertices1, bands1, 1, 3);
459
    meshes[1].setEffectAssociation(0,2,0);
460

    
461
    float[] vertices2 = { -E/2,-F/3, +E/2,-F/3, 0,2*F/3};
462

    
463
    meshes[2] = new MeshPolygon(vertices2, bands1, 1, 3);
464
    meshes[2].setEffectAssociation(0,4,0);
465
    meshes[3] = meshes[2].copy(true);
466
    meshes[3].setEffectAssociation(0,8,0);
467

    
468
    return new MeshJoined(meshes);
469
    }
470

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

    
473
  MeshBase createFacesRediEdge()
474
    {
475
    MeshBase[] meshes = new MeshPolygon[6];
476

    
477
    float F = 0.25f;
478
    float[] vertices0 = { -F,+F, -F,-F, 0, -2*F, +F,-F, +F,+F };
479
    float[] bands0 = computeBands(0.038f,35,F,0.7f,7);
480

    
481
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 2);
482
    meshes[0].setEffectAssociation(0,1,0);
483
    meshes[1] = meshes[0].copy(true);
484
    meshes[1].setEffectAssociation(0,2,0);
485

    
486
    float[] bands1 = computeBands(0.02f,35,F/2,0.2f,3);
487
    float[] vertices1 = { -F/2, +F/2, -F/2, -1.5f*F, 1.5f*F, +F/2 };
488

    
489
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
490
    meshes[2].setEffectAssociation(0,4,0);
491
    meshes[3] = meshes[2].copy(true);
492
    meshes[3].setEffectAssociation(0,8,0);
493

    
494
    float X = 0.25f*SQ2;
495
    float Y = SQ6/16;
496
    float[] vertices2 = { -X, Y, -1.5f*X, -Y, +1.5f*X, -Y, +X, Y };
497

    
498
    meshes[4] = new MeshPolygon(vertices2, bands1, 1, 1);
499
    meshes[4].setEffectAssociation(0,16,0);
500
    meshes[5] = meshes[4].copy(true);
501
    meshes[5].setEffectAssociation(0,32,0);
502

    
503
    return new MeshJoined(meshes);
504
    }
505

    
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507

    
508
  MeshBase createFacesRediCorner()
509
    {
510
    MeshBase[] meshes = new MeshBase[6];
511

    
512
    float E = 0.5f;
513
    float[] vertices0 = { -E,-E, +E,-E, +E,+E, -E,+E };
514
    float[] bands0 = computeBands(0.06f,35,E,0.7f,6);
515

    
516
    meshes[0] = new MeshPolygon(vertices0,bands0,2,2);
517
    meshes[0].setEffectAssociation(0,1,0);
518
    meshes[1] = meshes[0].copy(true);
519
    meshes[1].setEffectAssociation(0,2,0);
520
    meshes[2] = meshes[0].copy(true);
521
    meshes[2].setEffectAssociation(0,4,0);
522

    
523
    float F = 0.5f;
524
    float X = 0.5f;
525
    float G = 0.72f;
526
    float[] vertices1 = { -E,+F, -E+X,0, -E,-F, -E*G,-F, +E*G,-F, +E,-F, +E-X,0, +E,+F, +E*G,+F, -E*G,+F };
527
    float[] bands1 = computeBands(0.0f,0,1.0f,0.0f,2);
528

    
529
    meshes[3] = new MeshPolygon(vertices1,bands1,0,0);
530
    meshes[3].setEffectAssociation(0,8,0);
531
    meshes[4] = meshes[3].copy(true);
532
    meshes[4].setEffectAssociation(0,16,0);
533
    meshes[5] = meshes[3].copy(true);
534
    meshes[5].setEffectAssociation(0,32,0);
535

    
536
    return new MeshJoined(meshes);
537
    }
538

    
539
///////////////////////////////////////////////////////////////////////////////////////////////////
540

    
541
  MeshBase createFacesIvyCorner()
542
    {
543
    MeshBase[] meshes = new MeshBase[6];
544

    
545
    final float angle = (float)Math.PI/(2*IVY_N);
546
    final float CORR  = 1.0f - 2*IVY_D;
547
    final float DIST  = -0.5f*CORR + IVY_D;
548
    float[] vertices  = new float[2*(IVY_N+1)+6];
549

    
550
    vertices[0] = (0.5f-IVY_M) * IVY_C;
551
    vertices[1] = (DIST-IVY_M) * IVY_C;
552
    vertices[2] = (0.5f-IVY_M) * IVY_C;
553
    vertices[3] = (0.5f-IVY_M) * IVY_C;
554
    vertices[4] = (DIST-IVY_M) * IVY_C;
555
    vertices[5] = (0.5f-IVY_M) * IVY_C;
556

    
557
    for(int i=0; i<=IVY_N; i++)
558
      {
559
      float ang = (IVY_N-i)*angle;
560
      float sin = (float)Math.sin(ang);
561
      float cos = (float)Math.cos(ang);
562

    
563
      vertices[2*i+6] = (CORR*(cos-0.5f)-IVY_M)*IVY_C;
564
      vertices[2*i+7] = (CORR*(sin-0.5f)-IVY_M)*IVY_C;
565
      }
566

    
567
    float[] bands0 = computeBands(+0.012f,20,0.2f,0.5f,7);
568
    float[] bands1 = computeBands(-0.100f,20,0.2f,0.0f,2);
569

    
570
    meshes[0] = new MeshPolygon(vertices,bands0,1,2);
571
    meshes[0].setEffectAssociation(0,1,0);
572
    meshes[1] = meshes[0].copy(true);
573
    meshes[1].setEffectAssociation(0,2,0);
574
    meshes[2] = meshes[0].copy(true);
575
    meshes[2].setEffectAssociation(0,4,0);
576
    meshes[3] = new MeshPolygon(vertices,bands1,1,2);
577
    meshes[3].setEffectAssociation(0,8,0);
578
    meshes[4] = meshes[3].copy(true);
579
    meshes[4].setEffectAssociation(0,16,0);
580
    meshes[5] = meshes[3].copy(true);
581
    meshes[5].setEffectAssociation(0,32,0);
582

    
583
    return new MeshJoined(meshes);
584
    }
585

    
586
///////////////////////////////////////////////////////////////////////////////////////////////////
587

    
588
  MeshBase createFacesIvyFace()
589
    {
590
    MeshBase[] meshes = new MeshBase[2];
591

    
592
    final float angle = (float)Math.PI/(2*IVY_N);
593
    final float CORR  = 1.0f - 2*IVY_D;
594
    float[] vertices = new float[4*IVY_N];
595

    
596
    for(int i=0; i<IVY_N; i++)
597
      {
598
      float sin = (float)Math.sin(i*angle);
599
      float cos = (float)Math.cos(i*angle);
600

    
601
      vertices[2*i          ] = CORR*(0.5f-cos);
602
      vertices[2*i+1        ] = CORR*(0.5f-sin);
603
      vertices[2*i  +2*IVY_N] = CORR*(cos-0.5f);
604
      vertices[2*i+1+2*IVY_N] = CORR*(sin-0.5f);
605
      }
606

    
607
    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
608
    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
609

    
610
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
611
    meshes[0].setEffectAssociation(0,1,0);
612
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
613
    meshes[1].setEffectAssociation(0,2,0);
614

    
615
    return new MeshJoined(meshes);
616
    }
617

    
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619

    
620
  MeshBase createFacesRexCorner()
621
    {
622
    MeshBase[] meshes = new MeshBase[2];
623

    
624
    float F = REX_D*SQ2;
625
    float G = (1-REX_D)*SQ2/2;
626
    float H = 0.1f;
627
    float J = +2*G/3 - H*G;
628

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

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

    
634
    meshes[0] = new MeshPolygon(vertices,bands0,1,1);
635
    meshes[0].setEffectAssociation(0,1,0);
636
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
637
    meshes[1].setEffectAssociation(0,2,0);
638

    
639
    return new MeshJoined(meshes);
640
    }
641

    
642
///////////////////////////////////////////////////////////////////////////////////////////////////
643

    
644
  MeshBase createFacesRexFace()
645
    {
646
    MeshBase[] meshes = new MeshBase[2];
647

    
648
    float[] vertices = { -REX_D,0.0f, 0.0f, -REX_D, +REX_D, 0.0f, 0.0f, +REX_D};
649

    
650
    float[] bands0 = computeBands(0.016f,10,REX_D/2,0.5f,5);
651
    float[] bands1 = computeBands(0.000f,45,REX_D/2,0.0f,2);
652

    
653
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
654
    meshes[0].setEffectAssociation(0,1,0);
655
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
656
    meshes[1].setEffectAssociation(0,2,0);
657

    
658
    return new MeshJoined(meshes);
659
    }
660

    
661
///////////////////////////////////////////////////////////////////////////////////////////////////
662

    
663
  MeshBase createFacesRexEdge()
664
    {
665
    MeshBase[] meshes = new MeshPolygon[6];
666

    
667
    float E = 0.5f - REX_D;
668
    float F = 0.5f;
669
    float[] vertices0 = { -F,E/3, 0,-2*E/3, +F,E/3 };
670
    float[] bands0 = computeBands(0.03f,27,F/3,0.8f,5);
671

    
672
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 3);
673
    meshes[0].setEffectAssociation(0,1,0);
674
    meshes[1] = meshes[0].copy(true);
675
    meshes[1].setEffectAssociation(0,2,0);
676

    
677
    float G = (float)Math.sqrt(E*E+F*F);
678
    float[] vertices1 = { -2*G/3, -E/3, G/3, -E/3, G/3, 2*E/3 };
679
    float[] bands1 = computeBands(0.00f,45,G/3,0.2f,3);
680

    
681
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
682
    meshes[2].setEffectAssociation(0,4,0);
683
    meshes[3] = meshes[2].copy(true);
684
    meshes[3].setEffectAssociation(0,8,0);
685
    meshes[4] = meshes[2].copy(true);
686
    meshes[4].setEffectAssociation(0,16,0);
687
    meshes[5] = meshes[2].copy(true);
688
    meshes[5].setEffectAssociation(0,32,0);
689

    
690
    return new MeshJoined(meshes);
691
    }
692

    
693
///////////////////////////////////////////////////////////////////////////////////////////////////
694

    
695
  MeshBase createFacesKilominxCorner()
696
    {
697
    MeshBase[] meshes = new MeshPolygon[6];
698

    
699
    float X1= (SQ5+1)/8;
700
    float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
701
    float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8);
702
    float H = 0.5f* SIN54 /COS54  ;
703
    float X2= MINX_SC*H* SIN_HALFD;
704
    float Y3= MINX_SC*H/(2*COS_HALFD);
705
    float Y4= MINX_SC*H*(1/(2*COS_HALFD) - COS_HALFD);
706

    
707
    float[] vertices0 = { -X1, Y2, 0, -Y1, X1, Y2, 0, Y1 };
708
    float[] bands0 = computeBands(0.04f,17,0.3f,0.2f,5);
709
    float[] vertices1 = { -X2, Y4, 0, -Y3, X2, Y4, 0, Y3 };
710
    float[] bands1 = computeBands(0.00f, 0,0.25f,0.5f,5);
711

    
712
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
713
    meshes[0].setEffectAssociation(0, 1,0);
714
    meshes[1] = meshes[0].copy(true);
715
    meshes[1].setEffectAssociation(0, 2,0);
716
    meshes[2] = meshes[0].copy(true);
717
    meshes[2].setEffectAssociation(0, 4,0);
718
    meshes[3] = new MeshPolygon(vertices1, bands1, 1, 1);
719
    meshes[3].setEffectAssociation(0, 8,0);
720
    meshes[4] = meshes[3].copy(true);
721
    meshes[4].setEffectAssociation(0,16,0);
722
    meshes[5] = meshes[3].copy(true);
723
    meshes[5].setEffectAssociation(0,32,0);
724

    
725
    return new MeshJoined(meshes);
726
    }
727

    
728
///////////////////////////////////////////////////////////////////////////////////////////////////
729

    
730
  MeshBase createFacesMegaminxCorner()
731
    {
732
    MeshBase[] meshes = new MeshPolygon[6];
733

    
734
    float Y = COS54/(2*SIN54);
735

    
736
    float[] vertices0 = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y };
737
    float[] bands0 = computeBands(0.04f,34,0.3f,0.2f,5);
738
    float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,2);
739

    
740
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
741
    meshes[0].setEffectAssociation(0, 1,0);
742
    meshes[1] = meshes[0].copy(true);
743
    meshes[1].setEffectAssociation(0, 2,0);
744
    meshes[2] = meshes[0].copy(true);
745
    meshes[2].setEffectAssociation(0, 4,0);
746
    meshes[3] = new MeshPolygon(vertices0, bands1, 1, 4);
747
    meshes[3].setEffectAssociation(0, 8,0);
748
    meshes[4] = meshes[3].copy(true);
749
    meshes[4].setEffectAssociation(0,16,0);
750
    meshes[5] = meshes[3].copy(true);
751
    meshes[5].setEffectAssociation(0,32,0);
752

    
753
    return new MeshJoined(meshes);
754
    }
755

    
756
///////////////////////////////////////////////////////////////////////////////////////////////////
757

    
758
  MeshBase createFacesMegaminxEdge(float width, float height)
759
    {
760
    MeshBase[] meshes = new MeshPolygon[6];
761

    
762
    float D = height/COS18;
763
    float W = D*SIN18;
764

    
765
    float Y1 = 0.5f*width;
766
    float Y2 = 0.5f*width + W;
767
    float Y3 = 0.5f*width + 2*W;
768
    float X2 = D*SIN54;
769
    float X1 = 0.5f*height;
770
    float Y4 = D*COS54;
771

    
772
    float[] vertices0 = { -X1, Y1, -X1, -Y1, X1, -Y2, X1, Y2 };
773
    float[] vertices1 = { -X1, Y3, -X1, -Y3, X1, -Y2, X1, Y2 };
774
    float[] vertices2 = { -X2, 0.0f, 0.0f, -Y4, X2, 0.0f, 0.0f, Y4 };
775

    
776
    float[] bands0 = computeBands(0.04f,34,  X1,0.2f,5);
777
    float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,2);
778

    
779
    meshes[0] = new MeshPolygon(vertices0, bands0, 0, 0);
780
    meshes[0].setEffectAssociation(0, 1,0);
781
    meshes[1] = meshes[0].copy(true);
782
    meshes[1].setEffectAssociation(0, 2,0);
783
    meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0);
784
    meshes[2].setEffectAssociation(0, 4,0);
785
    meshes[3] = meshes[2].copy(true);
786
    meshes[3].setEffectAssociation(0, 8,0);
787
    meshes[4] = new MeshPolygon(vertices2, bands1, 0, 0);
788
    meshes[4].setEffectAssociation(0,16,0);
789
    meshes[5] = meshes[4].copy(true);
790
    meshes[5].setEffectAssociation(0,32,0);
791

    
792
    return new MeshJoined(meshes);
793
    }
794

    
795
///////////////////////////////////////////////////////////////////////////////////////////////////
796

    
797
  MeshBase createFacesMegaminxCenter(float width)
798
    {
799
    MeshBase[] meshes = new MeshPolygon[2];
800

    
801
    float R  = width/(2*COS54);
802

    
803
    float X1 = width/2;
804
    float Y1 = R*SIN54;
805
    float X2 = R*COS18;
806
    float Y2 = R*SIN18;
807

    
808
    float[] vertices0 = { -X1,+Y1, -X2,-Y2, 0.0f,-R, +X2,-Y2, +X1,+Y1 };
809
    float[] bands0 = computeBands(+0.04f,45, R/3,0.2f,4);
810
    float[] bands1 = computeBands( 0.00f,34, R/3,0.2f,2);
811

    
812
    meshes[0] = new MeshPolygon(vertices0, bands0, 0, 0);
813
    meshes[0].setEffectAssociation(0,1,0);
814
    meshes[1] = new MeshPolygon(vertices0, bands1, 0, 0);
815
    meshes[1].setEffectAssociation(0,2,0);
816

    
817
    return new MeshJoined(meshes);
818
    }
819

    
820
///////////////////////////////////////////////////////////////////////////////////////////////////
821
// EFFECTS
822
///////////////////////////////////////////////////////////////////////////////////////////////////
823

    
824
  VertexEffect[] createVertexEffectsCube()
825
    {
826
    Static3D axisY   = new Static3D(0,1,0);
827
    Static3D axisX   = new Static3D(1,0,0);
828
    Static3D center  = new Static3D(0,0,0);
829
    Static1D angle90 = new Static1D(90);
830
    Static1D angle180= new Static1D(180);
831
    Static1D angle270= new Static1D(270);
832

    
833
    VertexEffect[] effect = new VertexEffect[6];
834

    
835
    effect[0] = new VertexEffectMove(new Static3D(0,0,+0.5f));
836
    effect[1] = new VertexEffectRotate( angle180, axisX, center );
837
    effect[2] = new VertexEffectRotate( angle90 , axisX, center );
838
    effect[3] = new VertexEffectRotate( angle270, axisX, center );
839
    effect[4] = new VertexEffectRotate( angle270, axisY, center );
840
    effect[5] = new VertexEffectRotate( angle90 , axisY, center );
841

    
842
    effect[0].setMeshAssociation(63,-1);  // all 6 sides
843
    effect[1].setMeshAssociation(32,-1);  // back
844
    effect[2].setMeshAssociation( 8,-1);  // bottom
845
    effect[3].setMeshAssociation( 4,-1);  // top
846
    effect[4].setMeshAssociation( 2,-1);  // left
847
    effect[5].setMeshAssociation( 1,-1);  // right
848

    
849
    return effect;
850
    }
851

    
852
///////////////////////////////////////////////////////////////////////////////////////////////////
853

    
854
  VertexEffect[] createVertexEffectsSkewbCorner()
855
    {
856
    float E = 0.5f;
857

    
858
    Static3D axisX  = new Static3D(1,0,0);
859
    Static3D axisY  = new Static3D(0,1,0);
860
    Static3D axis0  = new Static3D(-SQ2/2,0,SQ2/2);
861
    Static3D axis1  = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3);
862
    Static1D angle1 = new Static1D(+90);
863
    Static1D angle2 = new Static1D(-90);
864
    Static1D angle3 = new Static1D(-15);
865
    Static1D angle4 = new Static1D((float)((180.0f/Math.PI)*Math.acos(SQ3/3)));
866
    Static1D angle5 = new Static1D(120);
867
    Static1D angle6 = new Static1D(240);
868
    Static3D center1= new Static3D(0,0,0);
869
    Static3D center2= new Static3D(-0.5f,-0.5f,-0.5f);
870
    Static3D move1  = new Static3D(-E/4,-E/4,0);
871
    Static3D move2  = new Static3D(-0.5f+SQ2/4,-0.5f+SQ6/8,-0.5f);
872

    
873
    VertexEffect[] effect = new VertexEffect[10];
874

    
875
    effect[0] = new VertexEffectMove(move1);
876
    effect[1] = new VertexEffectScale(new Static3D(1,1,-1));
877
    effect[2] = new VertexEffectRotate(angle1,axisX,center1);
878
    effect[3] = new VertexEffectRotate(angle2,axisY,center1);
879
    effect[4] = new VertexEffectMove(move2);
880
    effect[5] = new VertexEffectRotate(angle1,axisX,center2);
881
    effect[6] = new VertexEffectRotate(angle3,axisY,center2);
882
    effect[7] = new VertexEffectRotate(angle4,axis0,center2);
883
    effect[8] = new VertexEffectRotate(angle5,axis1,center2);
884
    effect[9] = new VertexEffectRotate(angle6,axis1,center2);
885

    
886
    effect[0].setMeshAssociation( 7,-1);  // meshes 0,1,2
887
    effect[1].setMeshAssociation( 6,-1);  // meshes 1,2
888
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
889
    effect[3].setMeshAssociation( 4,-1);  // mesh 2
890
    effect[4].setMeshAssociation(56,-1);  // meshes 3,4,5
891
    effect[5].setMeshAssociation(56,-1);  // meshes 3,4,5
892
    effect[6].setMeshAssociation(56,-1);  // meshes 3,4,5
893
    effect[7].setMeshAssociation(56,-1);  // meshes 3,4,5
894
    effect[8].setMeshAssociation(16,-1);  // mesh 4
895
    effect[9].setMeshAssociation(32,-1);  // mesh 5
896

    
897
    return effect;
898
    }
899

    
900
///////////////////////////////////////////////////////////////////////////////////////////////////
901

    
902
  VertexEffect[] createVertexEffectsSkewbFace()
903
    {
904
    Static3D center = new Static3D(0,0,0);
905
    Static3D axisX  = new Static3D(1,0,0);
906
    Static3D axisZ  = new Static3D(0,0,1);
907
    float angle = -(float)((180.0f/Math.PI)*Math.acos(SQ3/3));
908

    
909
    VertexEffect[] effect = new VertexEffect[6];
910

    
911
    effect[0] = new VertexEffectRotate( new Static1D(angle), axisX, center);
912
    effect[1] = new VertexEffectRotate( new Static1D(  135), axisZ, center);
913
    effect[2] = new VertexEffectRotate( new Static1D(   45), axisZ, center);
914
    effect[3] = new VertexEffectRotate( new Static1D(  -45), axisZ, center);
915
    effect[4] = new VertexEffectRotate( new Static1D( -135), axisZ, center);
916
    effect[5] = new VertexEffectMove( new Static3D(0,0,-0.5f) );
917

    
918
    effect[0].setMeshAssociation(30,-1);  // meshes 1,2,3,4
919
    effect[1].setMeshAssociation( 2,-1);  // mesh 1
920
    effect[2].setMeshAssociation( 5,-1);  // meshes 0,2
921
    effect[3].setMeshAssociation( 8,-1);  // mesh 3
922
    effect[4].setMeshAssociation(16,-1);  // mesh 4
923
    effect[5].setMeshAssociation(30,-1);  // meshes 1,2,3,4
924

    
925
    return effect;
926
    }
927

    
928
///////////////////////////////////////////////////////////////////////////////////////////////////
929

    
930
  VertexEffect[] createVertexEffectsOcta()
931
    {
932
    Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3)));
933
    Static1D angle1= new Static1D( 90);
934
    Static1D angle2= new Static1D(180);
935
    Static1D angle3= new Static1D(270);
936
    Static3D move1 = new Static3D(0,SQ2/2-SQ3/3,0);
937
    Static3D axisX = new Static3D(1,0,0);
938
    Static3D axisY = new Static3D(0,1,0);
939
    Static3D cent0 = new Static3D(0,0,0);
940
    Static3D cent1 = new Static3D(0,SQ2/2,0);
941
    Static3D flipY = new Static3D( 1,-1, 1);
942
    Static3D scale = new Static3D( 1, 2*SQ3/3, 1);
943

    
944
    VertexEffect[] effect = new VertexEffect[7];
945

    
946
    effect[0] = new VertexEffectScale(scale);
947
    effect[1] = new VertexEffectMove(move1);
948
    effect[2] = new VertexEffectRotate(alpha , axisX, cent1);
949
    effect[3] = new VertexEffectRotate(angle1, axisY, cent0);
950
    effect[4] = new VertexEffectRotate(angle2, axisY, cent0);
951
    effect[5] = new VertexEffectRotate(angle3, axisY, cent0);
952
    effect[6] = new VertexEffectScale(flipY);
953

    
954
    effect[3].setMeshAssociation ( 34,-1); // apply to meshes 1 & 5
955
    effect[4].setMeshAssociation ( 68,-1); // apply to meshes 2 & 6
956
    effect[5].setMeshAssociation (136,-1); // apply to meshes 3 & 7
957
    effect[6].setMeshAssociation (240,-1); // apply to meshes 4,5,6,7
958

    
959
    return effect;
960
    }
961

    
962
///////////////////////////////////////////////////////////////////////////////////////////////////
963

    
964
  VertexEffect[] createVertexEffectsTetra()
965
    {
966
    Static3D flipZ = new Static3D( 1, 1,-1);
967
    Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3)));
968
    Static1D angle1= new Static1D( 90);
969
    Static1D angle2= new Static1D(180);
970
    Static3D move1 = new Static3D(0,SQ2/4-SQ3/6,0);
971
    Static3D axisX = new Static3D(1,0,0);
972
    Static3D axisY = new Static3D(0,1,0);
973
    Static3D axisZ = new Static3D(0,0,1);
974
    Static3D cent0 = new Static3D(0,0,0);
975
    Static3D cent1 = new Static3D(0,SQ2/4,0);
976
    Static3D scale = new Static3D( 1, 2*SQ3/3, 1);
977

    
978
    VertexEffect[] effect = new VertexEffect[7];
979

    
980
    effect[0] = new VertexEffectScale(scale);
981
    effect[1] = new VertexEffectRotate(angle2, axisZ, cent0);
982
    effect[2] = new VertexEffectMove(move1);
983
    effect[3] = new VertexEffectRotate(alpha , axisX, cent1);
984
    effect[4] = new VertexEffectScale(flipZ);
985
    effect[5] = new VertexEffectRotate(angle1, axisY, cent0);
986
    effect[6] = new VertexEffectRotate(angle2, axisZ, cent0);
987

    
988
    effect[4].setMeshAssociation(10,-1); // meshes 1 & 3
989
    effect[5].setMeshAssociation(12,-1); // meshes 2 & 3
990
    effect[6].setMeshAssociation(12,-1); // meshes 2 & 3
991

    
992
    return effect;
993
    }
994

    
995
///////////////////////////////////////////////////////////////////////////////////////////////////
996

    
997
  VertexEffect[] createVertexEffectsDino()
998
    {
999
    float E = 0.5f*SQ2;
1000
    float F = 0.5f;
1001
    final float ANGLE = (float)((180/Math.PI)*(Math.atan(SQ2)));
1002

    
1003
    Static1D angle1 = new Static1D(-ANGLE);
1004
    Static1D angle2 = new Static1D(+ANGLE);
1005
    Static3D axisX  = new Static3D(1,0,0);
1006
    Static3D axisY  = new Static3D(0,1,0);
1007
    Static3D axisZ  = new Static3D(0,-1,1);
1008
    Static3D center0= new Static3D(0,0,0);
1009
    Static3D center1= new Static3D(0,-3*F,0);
1010

    
1011
    VertexEffect[] effect = new VertexEffect[10];
1012

    
1013
    effect[0] = new VertexEffectScale ( new Static3D(3,3,3) );
1014
    effect[1] = new VertexEffectMove  ( new Static3D(0,-F,0) );
1015
    effect[2] = new VertexEffectRotate( new Static1D(90), axisX, center0 );
1016
    effect[3] = new VertexEffectScale ( new Static3D(1,-1,1) );
1017
    effect[4] = new VertexEffectMove  ( new Static3D(3*E/2,E*(SQ3/2)-3*F,0) );
1018
    effect[5] = new VertexEffectRotate( new Static1D(+90), axisY, center1 );
1019
    effect[6] = new VertexEffectScale ( new Static3D(-1,1,1) );
1020
    effect[7] = new VertexEffectRotate( new Static1D( 45), axisX, center1 );
1021
    effect[8] = new VertexEffectRotate( angle1           , axisZ, center1 );
1022
    effect[9] = new VertexEffectRotate( angle2           , axisZ, center1 );
1023

    
1024
    effect[0].setMeshAssociation(15,-1);  // apply to meshes 0,1,2,3
1025
    effect[1].setMeshAssociation( 3,-1);  // apply to meshes 0,1
1026
    effect[2].setMeshAssociation( 2,-1);  // apply to mesh 1
1027
    effect[3].setMeshAssociation( 2,-1);  // apply to mesh 1
1028
    effect[4].setMeshAssociation(12,-1);  // apply to meshes 2,3
1029
    effect[5].setMeshAssociation(12,-1);  // apply to meshes 2,3
1030
    effect[6].setMeshAssociation( 8,-1);  // apply to mesh 3
1031
    effect[7].setMeshAssociation(12,-1);  // apply to meshes 2,3
1032
    effect[8].setMeshAssociation( 4,-1);  // apply to mesh 2
1033
    effect[9].setMeshAssociation( 8,-1);  // apply to mesh 3
1034

    
1035
    return effect;
1036
    }
1037

    
1038
///////////////////////////////////////////////////////////////////////////////////////////////////
1039

    
1040
  VertexEffect[] createVertexEffectsHelicopterCorner()
1041
    {
1042
    float E = 0.5f;
1043

    
1044
    Static3D axisX  = new Static3D(1,0,0);
1045
    Static3D axisY  = new Static3D(0,1,0);
1046
    Static3D axis0  = new Static3D(-SQ2/2,0,SQ2/2);
1047
    Static3D axis1  = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3);
1048
    Static1D angle1 = new Static1D(+90);
1049
    Static1D angle2 = new Static1D(-90);
1050
    Static1D angle3 = new Static1D(-135);
1051
    Static1D angle4 = new Static1D(90);
1052
    Static1D angle5 = new Static1D(120);
1053
    Static1D angle6 = new Static1D(240);
1054
    Static3D center1= new Static3D(0,0,0);
1055
    Static3D center2= new Static3D(-0.25f,-0.25f,-0.25f);
1056
    Static3D move1  = new Static3D(-E/4,-E/4,0);
1057
    Static3D move2  = new Static3D(-0.25f,(-1.0f/6)-0.25f,-0.25f);
1058

    
1059
    VertexEffect[] effect = new VertexEffect[10];
1060

    
1061
    effect[0] = new VertexEffectMove(move1);
1062
    effect[1] = new VertexEffectScale(new Static3D(1,1,-1));
1063
    effect[2] = new VertexEffectRotate(angle1,axisX,center1);
1064
    effect[3] = new VertexEffectRotate(angle2,axisY,center1);
1065
    effect[4] = new VertexEffectMove(move2);
1066
    effect[5] = new VertexEffectRotate(angle1,axisX,center2);
1067
    effect[6] = new VertexEffectRotate(angle3,axisY,center2);
1068
    effect[7] = new VertexEffectRotate(angle4,axis0,center2);
1069
    effect[8] = new VertexEffectRotate(angle5,axis1,center2);
1070
    effect[9] = new VertexEffectRotate(angle6,axis1,center2);
1071

    
1072
    effect[0].setMeshAssociation( 7,-1);  // meshes 0,1,2
1073
    effect[1].setMeshAssociation( 6,-1);  // meshes 1,2
1074
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
1075
    effect[3].setMeshAssociation( 4,-1);  // mesh 2
1076
    effect[4].setMeshAssociation(56,-1);  // meshes 3,4,5
1077
    effect[5].setMeshAssociation(56,-1);  // meshes 3,4,5
1078
    effect[6].setMeshAssociation(56,-1);  // meshes 3,4,5
1079
    effect[7].setMeshAssociation(56,-1);  // meshes 3,4,5
1080
    effect[8].setMeshAssociation(16,-1);  // mesh 4
1081
    effect[9].setMeshAssociation(32,-1);  // mesh 5
1082

    
1083
    return effect;
1084
    }
1085

    
1086
///////////////////////////////////////////////////////////////////////////////////////////////////
1087

    
1088
  VertexEffect[] createVertexEffectsHelicopterFace()
1089
    {
1090
    float E = 0.5f;
1091
    float F = SQ2/4;
1092

    
1093
    Static3D move0  = new Static3D(-E/4, -E/4, 0);
1094
    Static3D move1  = new Static3D(-(SQ2/24)-E/2, -(SQ2/24)-E/2, 0);
1095
    Static3D move2  = new Static3D(-E/2, F/3, 0);
1096
    Static3D move3  = new Static3D(+E/2, F/3, 0);
1097
    Static3D move4  = new Static3D(+E/3,+E/3, 0);
1098
    Static1D angle1 = new Static1D(135);
1099
    Static1D angle2 = new Static1D(90);
1100
    Static1D angle3 = new Static1D(-90);
1101
    Static1D angle4 = new Static1D(-135);
1102
    Static3D axisX  = new Static3D(1,0,0);
1103
    Static3D axisY  = new Static3D(0,1,0);
1104
    Static3D axisZ  = new Static3D(0,0,1);
1105
    Static3D axis1  = new Static3D(1,-1,0);
1106
    Static3D center = new Static3D(0,0,0);
1107
    Static3D center1= new Static3D(-E/2,-E/2,0);
1108

    
1109
    VertexEffect[] effect = new VertexEffect[10];
1110

    
1111
    effect[0] = new VertexEffectMove(move0);
1112
    effect[1] = new VertexEffectRotate(angle1, axisZ, center);
1113
    effect[2] = new VertexEffectMove(move1);
1114
    effect[3] = new VertexEffectRotate(angle2, axis1, center1);
1115
    effect[4] = new VertexEffectMove(move2);
1116
    effect[5] = new VertexEffectMove(move3);
1117
    effect[6] = new VertexEffectRotate(angle3, axisZ, center);
1118
    effect[7] = new VertexEffectRotate(angle4, axisX, center);
1119
    effect[8] = new VertexEffectRotate(angle1, axisY, center);
1120
    effect[9] = new VertexEffectMove(move4);
1121

    
1122
    effect[0].setMeshAssociation( 1,-1);  // mesh 0
1123
    effect[1].setMeshAssociation( 2,-1);  // mesh 1
1124
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
1125
    effect[3].setMeshAssociation( 2,-1);  // mesh 1
1126
    effect[4].setMeshAssociation( 4,-1);  // mesh 2
1127
    effect[5].setMeshAssociation( 8,-1);  // mesh 3
1128
    effect[6].setMeshAssociation( 8,-1);  // mesh 3
1129
    effect[7].setMeshAssociation( 4,-1);  // mesh 2
1130
    effect[8].setMeshAssociation( 8,-1);  // mesh 3
1131
    effect[9].setMeshAssociation(15,-1);  // meshes 0,1,2,3
1132

    
1133
    return effect;
1134
    }
1135

    
1136
///////////////////////////////////////////////////////////////////////////////////////////////////
1137

    
1138
  VertexEffect[] createVertexEffectsRediEdge()
1139
    {
1140
    Static3D move0 = new Static3D(0.0f, -0.5f, 0.0f);
1141
    Static3D move1 = new Static3D(0.25f, -0.25f, 0.0f);
1142
    Static3D move2 = new Static3D(0.5f, 0.0f, 0.0f);
1143
    Static3D move3 = new Static3D(0.0f, (SQ3-6)/8, (SQ3-6)/8);
1144
    Static3D flipZ = new Static3D(1,1,-1);
1145
    Static3D flipX = new Static3D(-1,1,1);
1146
    Static3D scale = new Static3D(2,2,2);
1147
    Static3D cent0 = new Static3D(0,0, 0);
1148
    Static3D cent1 = new Static3D(0,0, -1.5f);
1149
    Static3D axisX = new Static3D(1,0, 0);
1150
    Static3D axisY = new Static3D(0,1, 0);
1151
    Static3D axis  = new Static3D(0,SQ2/2,-SQ2/2);
1152
    Static1D angle1= new Static1D(90);
1153
    Static1D angle2= new Static1D(45);
1154
    Static1D angle3= new Static1D( (float)(180/Math.PI*Math.acos(SQ3/3)) );
1155

    
1156
    VertexEffect[] effect = new VertexEffect[12];
1157

    
1158
    effect[0] = new VertexEffectScale(scale);
1159
    effect[1] = new VertexEffectMove(move0);
1160
    effect[2] = new VertexEffectScale(flipZ);
1161
    effect[3] = new VertexEffectRotate(angle1,axisX,cent0);
1162
    effect[4] = new VertexEffectMove(move1);
1163
    effect[5] = new VertexEffectRotate(angle1,axisY,cent0);
1164
    effect[6] = new VertexEffectMove(move2);
1165
    effect[7] = new VertexEffectScale(flipX);
1166
    effect[8] = new VertexEffectRotate(angle2,axisX,cent0);
1167
    effect[9] = new VertexEffectMove(move3);
1168
    effect[10]= new VertexEffectRotate(angle3,axis ,cent1);
1169
    effect[11]= new VertexEffectScale(flipX);
1170

    
1171
    effect[0].setMeshAssociation(63,-1);  // meshes 0,1,2,3,4,5
1172
    effect[1].setMeshAssociation( 3,-1);  // meshes 0,1
1173
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
1174
    effect[3].setMeshAssociation( 2,-1);  // mesh 1
1175
    effect[4].setMeshAssociation(12,-1);  // meshes 2,3
1176
    effect[5].setMeshAssociation(60,-1);  // meshes 2,3,4,5
1177
    effect[6].setMeshAssociation(12,-1);  // meshes 2,3
1178
    effect[7].setMeshAssociation( 8,-1);  // mesh 3
1179
    effect[8].setMeshAssociation(48,-1);  // meshes 4,5
1180
    effect[9].setMeshAssociation(48,-1);  // meshes 4,5
1181
    effect[10].setMeshAssociation(48,-1); // meshes 4,5
1182
    effect[11].setMeshAssociation(32,-1); // mesh 5
1183

    
1184
    return effect;
1185
    }
1186

    
1187
///////////////////////////////////////////////////////////////////////////////////////////////////
1188

    
1189
  VertexEffect[] createVertexEffectsRediCorner()
1190
    {
1191
    Static3D axisY   = new Static3D(0,1,0);
1192
    Static3D axisX   = new Static3D(1,0,0);
1193
    Static3D axisZ   = new Static3D(0,0,1);
1194
    Static3D center  = new Static3D(0,0,0);
1195
    Static1D angle90 = new Static1D(90);
1196
    Static1D angle270= new Static1D(270);
1197
    Static1D angle45 = new Static1D(-45);
1198
    Static3D scale   = new Static3D(1.0f, SQ2, 1.0f);
1199

    
1200
    VertexEffect[] effect = new VertexEffect[7];
1201

    
1202
    effect[0] = new VertexEffectMove(new Static3D(0,0,+0.5f));
1203
    effect[1] = new VertexEffectRotate( angle270, axisX, center );
1204
    effect[2] = new VertexEffectRotate( angle90 , axisY, center );
1205
    effect[3] = new VertexEffectScale(scale);
1206
    effect[4] = new VertexEffectRotate( angle45 , axisX, center );
1207
    effect[5] = new VertexEffectRotate( angle90 , axisY, center );
1208
    effect[6] = new VertexEffectRotate( angle270, axisZ, center );
1209

    
1210
    effect[0].setMeshAssociation( 7,-1);  // 0,1,2
1211
    effect[1].setMeshAssociation( 2,-1);  // 1
1212
    effect[2].setMeshAssociation( 4,-1);  // 2
1213
    effect[3].setMeshAssociation(56,-1);  // 3,4,5
1214
    effect[4].setMeshAssociation(56,-1);  // 3,4,5
1215
    effect[5].setMeshAssociation(16,-1);  // 4
1216
    effect[6].setMeshAssociation(32,-1);  // 5
1217

    
1218
    return effect;
1219
    }
1220

    
1221
///////////////////////////////////////////////////////////////////////////////////////////////////
1222

    
1223
  VertexEffect[] createVertexEffectsIvyCorner()
1224
    {
1225
    Static3D axisX  = new Static3D(1,0,0);
1226
    Static3D axisY  = new Static3D(0,1,0);
1227
    Static1D angle1 = new Static1D(+90);
1228
    Static1D angle2 = new Static1D(-90);
1229
    Static3D center = new Static3D(0,0,0);
1230
    Static3D move1  = new Static3D(IVY_M-0.5f,IVY_M-0.5f,0);
1231

    
1232
    VertexEffect[] effect = new VertexEffect[5];
1233

    
1234
    effect[0] = new VertexEffectScale(1/IVY_C);
1235
    effect[1] = new VertexEffectMove(move1);
1236
    effect[2] = new VertexEffectScale(new Static3D(1,1,-1));
1237
    effect[3] = new VertexEffectRotate(angle1,axisX,center);
1238
    effect[4] = new VertexEffectRotate(angle2,axisY,center);
1239

    
1240
    effect[2].setMeshAssociation(54,-1);  // meshes 1,2,4,5
1241
    effect[3].setMeshAssociation(18,-1);  // meshes 1,4
1242
    effect[4].setMeshAssociation(36,-1);  // meshes 2,5
1243

    
1244
    return effect;
1245
    }
1246

    
1247
///////////////////////////////////////////////////////////////////////////////////////////////////
1248

    
1249
  VertexEffect[] createVertexEffectsRexEdge()
1250
    {
1251
    float E = 0.5f - REX_D;
1252
    float F = 0.5f;
1253
    float G = (float)Math.sqrt(E*E+F*F);
1254
    float A = (float)((180/Math.PI)*Math.asin(E/G));
1255

    
1256
    Static3D move1 = new Static3D(    0.0f, -E/3, 0.0f);
1257
    Static3D move2 = new Static3D(2*G/3 -F, +E/3, 0.0f);
1258

    
1259
    Static3D center0= new Static3D(0.0f, 0.0f, 0.0f);
1260
    Static3D center1= new Static3D(  -F, 0.0f, 0.0f);
1261
    Static3D center2= new Static3D(  +F, 0.0f, 0.0f);
1262
    Static3D axisX  = new Static3D(1.0f, 0.0f, 0.0f);
1263
    Static3D axisY  = new Static3D(0.0f, 1.0f, 0.0f);
1264
    Static3D axisZ  = new Static3D(0.0f, 0.0f, 1.0f);
1265

    
1266
    Static1D angle180 = new Static1D(180);
1267
    Static1D angle90  = new Static1D( 90);
1268
    Static1D angle270 = new Static1D(270);
1269
    Static1D angle1   = new Static1D(+A);
1270
    Static1D angle2   = new Static1D(-A);
1271

    
1272
    VertexEffect[] effect = new VertexEffect[12];
1273

    
1274
    effect[0] = new VertexEffectMove(move1);
1275
    effect[1] = new VertexEffectMove(move2);
1276
    effect[2] = new VertexEffectRotate(  angle90, axisX, center0 );
1277
    effect[3] = new VertexEffectRotate( angle270, axisX, center0 );
1278
    effect[4] = new VertexEffectRotate( angle180, axisX, center0 );
1279
    effect[5] = new VertexEffectRotate( angle180, axisY, center0 );
1280
    effect[6] = new VertexEffectScale ( new Static3D(-1, 1, 1) );
1281
    effect[7] = new VertexEffectScale ( new Static3D( 1,-1, 1) );
1282
    effect[8] = new VertexEffectRotate(   angle1, axisY, center1);
1283
    effect[9] = new VertexEffectRotate(   angle2, axisY, center2);
1284
    effect[10]= new VertexEffectRotate(   angle2, axisZ, center1);
1285
    effect[11]= new VertexEffectRotate(   angle1, axisZ, center2);
1286

    
1287
    effect[0].setMeshAssociation( 3,-1);  // meshes 0 & 1
1288
    effect[1].setMeshAssociation(60,-1);  // meshes 2,3,4,5
1289
    effect[2].setMeshAssociation( 2,-1);  // meshes 1
1290
    effect[3].setMeshAssociation(12,-1);  // meshes 2,3
1291
    effect[4].setMeshAssociation(48,-1);  // meshes 4,5
1292
    effect[5].setMeshAssociation(32,-1);  // mesh 5
1293
    effect[6].setMeshAssociation( 8,-1);  // apply to mesh 3
1294
    effect[7].setMeshAssociation( 2,-1);  // apply to mesh 1
1295
    effect[8].setMeshAssociation(16,-1);  // apply to mesh 4
1296
    effect[9].setMeshAssociation(32,-1);  // apply to mesh 5
1297
    effect[10].setMeshAssociation(4,-1);  // apply to mesh 2
1298
    effect[11].setMeshAssociation(8,-1);  // apply to mesh 3
1299

    
1300
    return effect;
1301
    }
1302

    
1303
///////////////////////////////////////////////////////////////////////////////////////////////////
1304

    
1305
  VertexEffect[] createVertexEffectsRexCorner()
1306
    {
1307
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
1308
    Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
1309
    Static1D angle = new Static1D(225);
1310

    
1311
    VertexEffect[] effect = new VertexEffect[1];
1312
    effect[0] = new VertexEffectRotate(angle, axisZ, center);
1313

    
1314
    return effect;
1315
    }
1316

    
1317
///////////////////////////////////////////////////////////////////////////////////////////////////
1318

    
1319
  VertexEffect[] createVertexEffectsKilominxCorner()
1320
    {
1321
    VertexEffect[] effect = new VertexEffect[10];
1322

    
1323
    float H = 0.5f*(SIN54 /COS54  );
1324
    float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
1325
    float Y2= H/(2*COS_HALFD);
1326
    float A = (float)(Math.acos(-SQ5/5)*180/Math.PI);  // dihedral angle of a dedecahedron in degrees
1327
    float sin18 = SIN18;
1328
    float cos18 = (float)(Math.sqrt(1- SIN18 * SIN18));
1329
    float LEN   = (float)Math.sqrt(H*H/(COS_HALFD*COS_HALFD) + 0.25f);
1330

    
1331
    Static3D axisZ = new Static3D(0.0f  , 0.0f , 1.0f);
1332
    Static3D axisY = new Static3D(0.0f  , 1.0f , 0.0f);
1333
    Static3D axisA = new Static3D(-sin18, cos18, 0.0f);
1334
    Static3D axisC = new Static3D( H/LEN, -0.5f/LEN,-H* SIN_HALFD /(COS_HALFD*LEN));
1335

    
1336
    Static3D move1 = new Static3D(0,-Y1,0);
1337
    Static3D move2 = new Static3D(0,-Y2,0);
1338
    Static3D move3 = new Static3D(0.5f*cos18,0.5f*sin18,0);
1339
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
1340

    
1341
    Static1D angle1 = new Static1D(54);
1342
    Static1D angle2 = new Static1D(A/2+18);
1343
    Static1D angle3 = new Static1D(90);
1344
    Static1D angle4 = new Static1D(120);
1345
    Static1D angle5 = new Static1D(240);
1346
    Static1D angle6 = new Static1D(90-A/2);
1347

    
1348
    effect[0] = new VertexEffectMove(move1);
1349
    effect[1] = new VertexEffectScale(1/MINX_SC);
1350
    effect[2] = new VertexEffectMove(move2);
1351
    effect[3] = new VertexEffectRotate(angle1, axisZ, center);
1352
    effect[4] = new VertexEffectRotate(angle2, axisZ, center);
1353
    effect[5] = new VertexEffectRotate(angle3, axisA, center);
1354
    effect[6] = new VertexEffectMove(move3);
1355
    effect[7] = new VertexEffectRotate(angle4, axisC, center);
1356
    effect[8] = new VertexEffectRotate(angle5, axisC, center);
1357
    effect[9] = new VertexEffectRotate(angle6, axisY, center);
1358

    
1359
    effect[0].setMeshAssociation( 7,-1);  // meshes 0,1,2
1360
    effect[1].setMeshAssociation(56,-1);  // meshes 3,4,5
1361
    effect[2].setMeshAssociation(56,-1);  // meshes 3,4,5
1362
    effect[3].setMeshAssociation( 7,-1);  // meshes 0,1,2
1363
    effect[4].setMeshAssociation(56,-1);  // meshes 3,4,5
1364
    effect[5].setMeshAssociation(56,-1);  // meshes 3,4,5
1365
    effect[6].setMeshAssociation(56,-1);  // meshes 3,4,5
1366
    effect[7].setMeshAssociation(18,-1);  // meshes 1,4
1367
    effect[8].setMeshAssociation(36,-1);  // meshes 2,5
1368

    
1369
    return effect;
1370
    }
1371

    
1372
///////////////////////////////////////////////////////////////////////////////////////////////////
1373

    
1374
  VertexEffect[] createVertexEffectsMegaminxCorner(int numLayers)
1375
    {
1376
    VertexEffect[] effect = new VertexEffect[9];
1377

    
1378
    float Y = COS54/(2*SIN54);
1379

    
1380
    float sinA = (2*SIN54*SIN54-1)/COS54;
1381
    float cosA = (float)Math.sqrt(1-sinA*sinA);
1382
    float LEN  = 0.5f/SIN54;
1383
    float scale= (numLayers/3.0f)*(0.5f-MEGA_D)/(LEN*0.5f*(numLayers-1));
1384

    
1385
    Static3D axisA = new Static3D( SIN54, COS54, 0.0f);
1386
    Static3D axisB = new Static3D(-SIN54, COS54, 0.0f);
1387
    Static3D axisX = new Static3D(  1.0f,  0.0f, 0.0f);
1388

    
1389
    Static3D centerU = new Static3D( 0.0f, Y, 0.0f);
1390
    Static3D centerD = new Static3D( 0.0f,-Y, 0.0f);
1391

    
1392
    Static3D move1= new Static3D(0.0f, -sinA*LEN, -cosA*LEN );
1393
    Static3D move2= new Static3D(0.0f, Y , 0.0f );
1394

    
1395
    Static1D angleD = new Static1D(DIHEDRAL1);
1396
    Static1D angleE = new Static1D(360-DIHEDRAL1);
1397
    Static1D angleF = new Static1D(DIHEDRAL2);
1398

    
1399
    effect[0] = new VertexEffectScale ( new Static3D( 1, 1,-1) );
1400
    effect[1] = new VertexEffectRotate(angleE, axisA, centerU);
1401
    effect[2] = new VertexEffectRotate(angleD, axisB, centerU);
1402
    effect[3] = new VertexEffectMove(move1);
1403
    effect[4] = new VertexEffectRotate(angleE, axisA, centerD);
1404
    effect[5] = new VertexEffectRotate(angleD, axisB, centerD);
1405
    effect[6] = new VertexEffectRotate(angleF, axisX, centerD);
1406
    effect[7] = new VertexEffectMove(move2);
1407
    effect[8] = new VertexEffectScale(scale);
1408

    
1409
    effect[0].setMeshAssociation(  3,-1);  // meshes 0,1
1410
    effect[1].setMeshAssociation( 16,-1);  // mesh 4
1411
    effect[2].setMeshAssociation( 32,-1);  // mesh 5
1412
    effect[3].setMeshAssociation( 56,-1);  // meshes 3,4,5
1413
    effect[4].setMeshAssociation(  1,-1);  // mesh 0
1414
    effect[5].setMeshAssociation(  2,-1);  // mesh 1
1415

    
1416
    return effect;
1417
    }
1418

    
1419
///////////////////////////////////////////////////////////////////////////////////////////////////
1420

    
1421
  VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height)
1422
    {
1423
    VertexEffect[] effect = new VertexEffect[11];
1424

    
1425
    float X = 0.5f*height;
1426
    float Y = height*(COS54/COS18) + width*0.5f;
1427
    float Z = 2*height*COS_HALFD;
1428

    
1429
    float alpha = 90-DIHEDRAL1/2;
1430
    float beta  = DIHEDRAL2;
1431

    
1432
    Static1D angle1 = new Static1D(alpha);
1433
    Static1D angle2 = new Static1D(180-alpha);
1434
    Static1D angle3 = new Static1D(beta);
1435

    
1436
    Static3D move1 = new Static3D(X,0,0);
1437
    Static3D move2 = new Static3D(X,0,-Z);
1438
    Static3D move3 = new Static3D(0,+Y,0);
1439
    Static3D move4 = new Static3D(0,-Y,0);
1440
    Static3D scale = new Static3D(+1,+1,-1);
1441

    
1442
    Static3D axisXplus = new Static3D(+1, 0, 0);
1443
    Static3D axisXminus= new Static3D(-1, 0, 0);
1444
    Static3D axisYplus = new Static3D( 0,+1, 0);
1445
    Static3D axisYminus= new Static3D( 0,-1, 0);
1446

    
1447
    Static3D center1= new Static3D( 0, 0, 0);
1448
    Static3D center2= new Static3D( 0, 0,-Z);
1449
    Static3D center3= new Static3D( 0,+width*0.5f, 0);
1450
    Static3D center4= new Static3D( 0,-width*0.5f, 0);
1451

    
1452
    effect[ 0] = new VertexEffectMove(move1);
1453
    effect[ 1] = new VertexEffectMove(move2);
1454
    effect[ 2] = new VertexEffectMove(move3);
1455
    effect[ 3] = new VertexEffectMove(move4);
1456
    effect[ 4] = new VertexEffectScale(scale);
1457
    effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1);
1458
    effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1);
1459
    effect[ 7] = new VertexEffectRotate(angle1, axisYminus, center2);
1460
    effect[ 8] = new VertexEffectRotate(angle2, axisYminus, center2);
1461
    effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center3);
1462
    effect[10] = new VertexEffectRotate(angle3, axisXminus, center4);
1463

    
1464
    effect[ 0].setMeshAssociation( 3,-1);  // meshes 0,1
1465
    effect[ 1].setMeshAssociation(12,-1);  // meshes 2,3
1466
    effect[ 2].setMeshAssociation(16,-1);  // mesh 4
1467
    effect[ 3].setMeshAssociation(32,-1);  // mesh 5
1468
    effect[ 4].setMeshAssociation( 2,-1);  // mesh 1
1469
    effect[ 5].setMeshAssociation( 1,-1);  // mesh 0
1470
    effect[ 6].setMeshAssociation( 2,-1);  // mesh 1
1471
    effect[ 7].setMeshAssociation( 4,-1);  // mesh 2
1472
    effect[ 8].setMeshAssociation( 8,-1);  // mesh 3
1473
    effect[ 9].setMeshAssociation(16,-1);  // mesh 4
1474
    effect[10].setMeshAssociation(32,-1);  // mesh 5
1475

    
1476
    return effect;
1477
    }
1478

    
1479
///////////////////////////////////////////////////////////////////////////////////////////////////
1480

    
1481
  VertexEffect[] createVertexEffectsMegaminxCenter()
1482
    {
1483
    VertexEffect[] effect = new VertexEffect[1];
1484

    
1485
    Static1D angle = new Static1D(DIHEDRAL2);
1486
    Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f);
1487
    Static3D center= new Static3D( 0, 0, 0);
1488

    
1489
    effect[0] = new VertexEffectRotate(angle, axisX, center);
1490

    
1491
    return effect;
1492
    }
1493

    
1494
///////////////////////////////////////////////////////////////////////////////////////////////////
1495
// OBJECTS
1496
///////////////////////////////////////////////////////////////////////////////////////////////////
1497
// CUBE
1498

    
1499
  MeshBase createCubeMesh(int index)
1500
    {
1501
    MeshBase mesh = createFacesCube(index);
1502
    VertexEffect[] effects = createVertexEffectsCube();
1503
    for( VertexEffect effect : effects ) mesh.apply(effect);
1504

    
1505
    Static3D roundingCenter  = new Static3D(0,0,0);
1506
    Static3D[] vertices = new Static3D[8];
1507
    vertices[0] = new Static3D(+0.5f,+0.5f,+0.5f);
1508
    vertices[1] = new Static3D(+0.5f,+0.5f,-0.5f);
1509
    vertices[2] = new Static3D(+0.5f,-0.5f,+0.5f);
1510
    vertices[3] = new Static3D(+0.5f,-0.5f,-0.5f);
1511
    vertices[4] = new Static3D(-0.5f,+0.5f,+0.5f);
1512
    vertices[5] = new Static3D(-0.5f,+0.5f,-0.5f);
1513
    vertices[6] = new Static3D(-0.5f,-0.5f,+0.5f);
1514
    vertices[7] = new Static3D(-0.5f,-0.5f,-0.5f);
1515

    
1516
    roundCorners(mesh,roundingCenter,vertices,0.06f,0.12f);
1517

    
1518
    mesh.mergeEffComponents();
1519

    
1520
    return mesh;
1521
    }
1522

    
1523
///////////////////////////////////////////////////////////////////////////////////////////////////
1524
// SKEWB
1525

    
1526
  MeshBase createSkewbCornerMesh()
1527
    {
1528
    MeshBase mesh = createFacesSkewbCorner();
1529
    VertexEffect[] effects = createVertexEffectsSkewbCorner();
1530
    for( VertexEffect effect : effects ) mesh.apply(effect);
1531

    
1532
    float E = 0.5f;
1533
    Static3D roundingCenter = new Static3D(-E/2,-E/2,-E/2);
1534

    
1535
    Static3D[] verticesType1 = new Static3D[1];
1536
    verticesType1[0] = new Static3D(0.0f,0.0f,0.0f);
1537
    roundCorners(mesh,roundingCenter,verticesType1,0.08f,0.15f);
1538

    
1539
    Static3D[] verticesType2 = new Static3D[3];
1540
    verticesType2[0] = new Static3D(-E, 0, 0);
1541
    verticesType2[1] = new Static3D( 0,-E, 0);
1542
    verticesType2[2] = new Static3D( 0, 0,-E);
1543
    roundCorners(mesh,roundingCenter,verticesType2,0.08f,0.20f);
1544

    
1545
    mesh.mergeEffComponents();
1546

    
1547
    return mesh;
1548
    }
1549

    
1550
///////////////////////////////////////////////////////////////////////////////////////////////////
1551

    
1552
  MeshBase createSkewbFaceMesh()
1553
    {
1554
    MeshBase mesh = createFacesSkewbFace();
1555
    VertexEffect[] effects = createVertexEffectsSkewbFace();
1556
    for( VertexEffect effect : effects ) mesh.apply(effect);
1557

    
1558
    Static3D roundingCenter = new Static3D(0,0,-0.2f);
1559
    float E = SQ2/4;
1560
    Static3D[] vertices = new Static3D[4];
1561
    vertices[0] = new Static3D(-E*SQ2,      0, 0);
1562
    vertices[1] = new Static3D(+E*SQ2,      0, 0);
1563
    vertices[2] = new Static3D(     0, -E*SQ2, 0);
1564
    vertices[3] = new Static3D(     0, +E*SQ2, 0);
1565
    roundCorners(mesh,roundingCenter,vertices,0.06f,0.10f);
1566

    
1567
    mesh.mergeEffComponents();
1568
    mesh.addEmptyTexComponent();
1569

    
1570
    return mesh;
1571
    }
1572

    
1573
///////////////////////////////////////////////////////////////////////////////////////////////////
1574
// SKEWB DIAMOND / PYRAMINX
1575

    
1576
  MeshBase createOctaMesh()
1577
    {
1578
    MeshBase mesh = createFacesOcta();
1579
    VertexEffect[] effects = createVertexEffectsOcta();
1580
    for( VertexEffect effect : effects ) mesh.apply(effect);
1581

    
1582
    Static3D roundingCenter = new Static3D(0,0,0);
1583
    Static3D[] vertices = new Static3D[6];
1584
    vertices[0] = new Static3D(    0, SQ2/2,    0 );
1585
    vertices[1] = new Static3D( 0.5f,     0, 0.5f );
1586
    vertices[2] = new Static3D(-0.5f,     0, 0.5f );
1587
    vertices[3] = new Static3D(    0,-SQ2/2,    0 );
1588
    vertices[4] = new Static3D(-0.5f,     0,-0.5f );
1589
    vertices[5] = new Static3D( 0.5f,     0,-0.5f );
1590

    
1591
    roundCorners(mesh,roundingCenter,vertices,0.06f,0.20f);
1592

    
1593
    mesh.mergeEffComponents();
1594

    
1595
    return mesh;
1596
    }
1597

    
1598
///////////////////////////////////////////////////////////////////////////////////////////////////
1599

    
1600
  MeshBase createTetraMesh()
1601
    {
1602
    MeshBase mesh = createFacesTetra();
1603
    VertexEffect[] effects = createVertexEffectsTetra();
1604
    for( VertexEffect effect : effects ) mesh.apply(effect);
1605

    
1606
    Static3D roundingCenter = new Static3D(0,0,0);
1607
    Static3D[] verticesRound = new Static3D[4];
1608
    verticesRound[0] = new Static3D(-0.5f,+SQ2/4,   0 );
1609
    verticesRound[1] = new Static3D(+0.5f,+SQ2/4,   0 );
1610
    verticesRound[2] = new Static3D(    0,-SQ2/4,+0.5f);
1611
    verticesRound[3] = new Static3D(    0,-SQ2/4,-0.5f);
1612
    roundCorners(mesh,roundingCenter,verticesRound,0.08f,0.15f);
1613

    
1614
    mesh.mergeEffComponents();
1615
    mesh.addEmptyTexComponent();
1616
    mesh.addEmptyTexComponent();
1617
    mesh.addEmptyTexComponent();
1618
    mesh.addEmptyTexComponent();
1619

    
1620
    return mesh;
1621
    }
1622

    
1623
///////////////////////////////////////////////////////////////////////////////////////////////////
1624
// DINO
1625

    
1626
  MeshBase createDinoMesh()
1627
    {
1628
    MeshBase mesh = createFacesDino();
1629
    VertexEffect[] effects = createVertexEffectsDino();
1630
    for( VertexEffect effect : effects ) mesh.apply(effect);
1631

    
1632
    float F = 0.5f;
1633
    Static3D roundingCenter = new Static3D(0.0f, -1.5f*F, -1.5f*F);
1634
    Static3D[] verticesRound = new Static3D[4];
1635
    verticesRound[0] = new Static3D(     0,-3*F,    0 );
1636
    verticesRound[1] = new Static3D(     0,   0, -3*F );
1637
    verticesRound[2] = new Static3D(  -3*F,   0,    0 );
1638
    verticesRound[3] = new Static3D(  +3*F,   0,    0 );
1639
    roundCorners(mesh,roundingCenter,verticesRound,0.10f,0.40f);
1640

    
1641
    mesh.mergeEffComponents();
1642

    
1643
    return mesh;
1644
    }
1645

    
1646
///////////////////////////////////////////////////////////////////////////////////////////////////
1647
// Helicopter
1648

    
1649
  MeshBase createHelicopterCornerMesh()
1650
    {
1651
    MeshBase mesh = createFacesHelicopterCorner();
1652
    VertexEffect[] effects = createVertexEffectsHelicopterCorner();
1653
    for( VertexEffect effect : effects ) mesh.apply(effect);
1654

    
1655
    float E = 0.5f;
1656
    Static3D roundingCenter = new Static3D(-E/2,-E/2,-E/2);
1657

    
1658
    Static3D[] verticesType1 = new Static3D[1];
1659
    verticesType1[0] = new Static3D(0.0f,0.0f,0.0f);
1660
    roundCorners(mesh,roundingCenter,verticesType1,0.08f,0.15f);
1661

    
1662
    Static3D[] verticesType2 = new Static3D[3];
1663
    verticesType2[0] = new Static3D(-E, 0, 0);
1664
    verticesType2[1] = new Static3D( 0,-E, 0);
1665
    verticesType2[2] = new Static3D( 0, 0,-E);
1666
    roundCorners(mesh,roundingCenter,verticesType2,0.08f,0.20f);
1667

    
1668
    mesh.mergeEffComponents();
1669

    
1670
    return mesh;
1671
    }
1672

    
1673
///////////////////////////////////////////////////////////////////////////////////////////////////
1674

    
1675
  MeshBase createHelicopterFaceMesh()
1676
    {
1677
    MeshBase mesh = createFacesHelicopterFace();
1678
    VertexEffect[] effects = createVertexEffectsHelicopterFace();
1679
    for( VertexEffect effect : effects ) mesh.apply(effect);
1680

    
1681
    float E = 0.5f;
1682
    Static3D roundingCenter = new Static3D(-E/2 + E/3,-E/2 + E/3,-E/2);
1683

    
1684
    Static3D[] verticesType1 = new Static3D[1];
1685
    verticesType1[0] = new Static3D(E/3,E/3,0.0f);
1686
    roundCorners(mesh,roundingCenter,verticesType1,0.06f,0.15f);
1687

    
1688
    Static3D[] verticesType2 = new Static3D[2];
1689
    verticesType2[0] = new Static3D(-E+E/3, E/3  , 0);
1690
    verticesType2[1] = new Static3D( E/3  ,-E+E/3, 0);
1691
    roundCorners(mesh,roundingCenter,verticesType2,0.08f,0.20f);
1692

    
1693
    mesh.mergeEffComponents();
1694
    mesh.addEmptyTexComponent();
1695
    mesh.addEmptyTexComponent();
1696

    
1697
    return mesh;
1698
    }
1699

    
1700
///////////////////////////////////////////////////////////////////////////////////////////////////
1701
// Redi cube
1702

    
1703
  MeshBase createRediEdgeMesh()
1704
    {
1705
    MeshBase mesh = createFacesRediEdge();
1706
    VertexEffect[] effects = createVertexEffectsRediEdge();
1707
    for( VertexEffect effect : effects ) mesh.apply(effect);
1708

    
1709
    Static3D center = new Static3D(0.0f,-0.75f,-0.75f);
1710
    Static3D[] vertices = new Static3D[2];
1711
    vertices[0] = new Static3D( 0.5f, 0.0f, 0.0f);
1712
    vertices[1] = new Static3D(-0.5f, 0.0f, 0.0f);
1713
    roundCorners(mesh,center,vertices,0.06f,0.20f);
1714

    
1715
    mesh.mergeEffComponents();
1716

    
1717
    return mesh;
1718
    }
1719

    
1720
///////////////////////////////////////////////////////////////////////////////////////////////////
1721

    
1722
  MeshBase createRediCornerMesh()
1723
    {
1724
    MeshBase mesh = createFacesRediCorner();
1725
    VertexEffect[] effects = createVertexEffectsRediCorner();
1726
    for( VertexEffect effect : effects ) mesh.apply(effect);
1727

    
1728
    Static3D center = new Static3D(0,0,0);
1729
    Static3D[] vertices = new Static3D[8];
1730
    vertices[0] = new Static3D(+0.5f,+0.5f,+0.5f);
1731
    vertices[1] = new Static3D(+0.5f,+0.5f,-0.5f);
1732
    vertices[2] = new Static3D(+0.5f,-0.5f,+0.5f);
1733
    vertices[3] = new Static3D(+0.5f,-0.5f,-0.5f);
1734
    vertices[4] = new Static3D(-0.5f,+0.5f,+0.5f);
1735
    vertices[5] = new Static3D(-0.5f,+0.5f,-0.5f);
1736
    vertices[6] = new Static3D(-0.5f,-0.5f,+0.5f);
1737
    vertices[7] = new Static3D(-0.5f,-0.5f,-0.5f);
1738

    
1739
    roundCorners(mesh,center,vertices,0.06f,0.12f);
1740

    
1741
    mesh.mergeEffComponents();
1742

    
1743
    return mesh;
1744
    }
1745

    
1746
///////////////////////////////////////////////////////////////////////////////////////////////////
1747

    
1748
  MeshBase createIvyCornerMesh()
1749
    {
1750
    MeshBase mesh = createFacesIvyCorner();
1751
    VertexEffect[] effects = createVertexEffectsIvyCorner();
1752
    for( VertexEffect effect : effects ) mesh.apply(effect);
1753

    
1754
    Static3D center = new Static3D(-0.5f,-0.5f,-0.5f);
1755
    Static3D[] vertices = new Static3D[4];
1756
    vertices[0] = new Static3D(+0.0f,+0.0f,+0.0f);
1757
    vertices[1] = new Static3D(-1.0f,+0.0f,+0.0f);
1758
    vertices[2] = new Static3D(+0.0f,-1.0f,+0.0f);
1759
    vertices[3] = new Static3D(+0.0f,+0.0f,-1.0f);
1760

    
1761
    roundCorners(mesh,center,vertices,0.03f,0.10f);
1762

    
1763
    mesh.mergeEffComponents();
1764

    
1765
    return mesh;
1766
    }
1767

    
1768
///////////////////////////////////////////////////////////////////////////////////////////////////
1769

    
1770
  MeshBase createIvyFaceMesh()
1771
    {
1772
    MeshBase mesh = createFacesIvyFace();
1773

    
1774
    Static3D center = new Static3D(-0.0f,-0.0f,-0.5f);
1775
    Static3D[] vertices = new Static3D[2];
1776
    vertices[0] = new Static3D(-0.5f,+0.5f,+0.0f);
1777
    vertices[1] = new Static3D(+0.5f,-0.5f,+0.0f);
1778

    
1779
    roundCorners(mesh,center,vertices,0.03f,0.10f);
1780

    
1781
    mesh.mergeEffComponents();
1782
    mesh.addEmptyTexComponent();
1783
    mesh.addEmptyTexComponent();
1784
    mesh.addEmptyTexComponent();
1785
    mesh.addEmptyTexComponent();
1786

    
1787
    return mesh;
1788
    }
1789

    
1790
///////////////////////////////////////////////////////////////////////////////////////////////////
1791

    
1792
  MeshBase createRexCornerMesh()
1793
    {
1794
    MeshBase mesh = createFacesRexCorner();
1795
    VertexEffect[] effects = createVertexEffectsRexCorner();
1796
    for( VertexEffect effect : effects ) mesh.apply(effect);
1797

    
1798
    final float G = (1-REX_D)/3;
1799
    Static3D center = new Static3D(0.0f,0.0f,-G*SQ2/2);
1800
    Static3D[] vertices = new Static3D[1];
1801
    vertices[0] = new Static3D(+G,-G,+0.0f);
1802
    roundCorners(mesh,center,vertices,0.10f,0.10f);
1803

    
1804
    mesh.mergeEffComponents();
1805
    mesh.addEmptyTexComponent();
1806
    mesh.addEmptyTexComponent();
1807
    mesh.addEmptyTexComponent();
1808
    mesh.addEmptyTexComponent();
1809

    
1810
    return mesh;
1811
    }
1812

    
1813
///////////////////////////////////////////////////////////////////////////////////////////////////
1814

    
1815
  MeshBase createRexFaceMesh()
1816
    {
1817
    MeshBase mesh = createFacesRexFace();
1818

    
1819
    mesh.mergeEffComponents();
1820
    mesh.addEmptyTexComponent();
1821
    mesh.addEmptyTexComponent();
1822
    mesh.addEmptyTexComponent();
1823
    mesh.addEmptyTexComponent();
1824

    
1825
    return mesh;
1826
    }
1827

    
1828
///////////////////////////////////////////////////////////////////////////////////////////////////
1829

    
1830
  MeshBase createRexEdgeMesh()
1831
    {
1832
    MeshBase mesh = createFacesRexEdge();
1833
    VertexEffect[] effects = createVertexEffectsRexEdge();
1834
    for( VertexEffect effect : effects ) mesh.apply(effect);
1835

    
1836
    Static3D center = new Static3D(0.0f,-0.5f,-0.5f);
1837
    Static3D[] vertices = new Static3D[2];
1838
    vertices[0] = new Static3D(+0.5f,+0.0f,+0.0f);
1839
    vertices[1] = new Static3D(-0.5f,+0.0f,+0.0f);
1840
    roundCorners(mesh,center,vertices,0.06f,0.10f);
1841

    
1842
    mesh.mergeEffComponents();
1843

    
1844
    return mesh;
1845
    }
1846

    
1847
///////////////////////////////////////////////////////////////////////////////////////////////////
1848

    
1849
  MeshBase createKilominxCornerMesh()
1850
    {
1851
    MeshBase mesh = createFacesKilominxCorner();
1852
    VertexEffect[] effects = createVertexEffectsKilominxCorner();
1853
    for( VertexEffect effect : effects ) mesh.apply(effect);
1854

    
1855
    float A = (2*SQ3/3)* SIN54;
1856
    float B = 0.4f;
1857
    float X = SIN_HALFD * SIN54 *COS54  ;
1858
    float Y = SIN54 * SIN54 - 0.5f;
1859
    float Z = COS_HALFD* SIN54 *COS54  ;
1860

    
1861
    Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
1862

    
1863
    Static3D[] vertices = new Static3D[4];
1864
    vertices[0] = new Static3D( 0.0f, 0.0f, 0.0f);
1865
    vertices[1] = new Static3D( 0.0f,-0.5f, 0.0f);
1866
    vertices[2] = new Static3D(-X   , Y   ,-Z   );
1867
    vertices[3] = new Static3D(+X   , Y   ,-Z   );
1868

    
1869
    roundCorners(mesh,center,vertices,0.03f,0.10f);
1870

    
1871
    mesh.mergeEffComponents();
1872

    
1873
    return mesh;
1874
    }
1875

    
1876
///////////////////////////////////////////////////////////////////////////////////////////////////
1877

    
1878
  MeshBase createMegaminxCornerMesh(int numLayers)
1879
    {
1880
    MeshBase mesh = createFacesMegaminxCorner();
1881
    VertexEffect[] effects = createVertexEffectsMegaminxCorner(numLayers);
1882
    for( VertexEffect effect : effects ) mesh.apply(effect);
1883

    
1884
    float A = (2*SQ3/3)* SIN54;
1885
    float B = 0.4f;
1886
    float X = SIN_HALFD* SIN54 * COS54;
1887
    float Y = SIN54 * SIN54 - 0.5f;
1888
    float Z = COS_HALFD* SIN54 * COS54;
1889
    float S = 2*SIN54*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
1890

    
1891
    Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
1892

    
1893
    Static3D[] vertices = new Static3D[4];
1894
    vertices[0] = new Static3D( 0.0f, 0.0f  , 0.0f);
1895
    vertices[1] = new Static3D( 0.0f,-0.5f*S, 0.0f);
1896
    vertices[2] = new Static3D(-X*S , Y*S   ,-Z*S );
1897
    vertices[3] = new Static3D(+X*S , Y*S   ,-Z*S );
1898

    
1899
    roundCorners(mesh,center,vertices,0.04f,0.10f);
1900

    
1901
    mesh.mergeEffComponents();
1902

    
1903
    return mesh;
1904
    }
1905

    
1906
///////////////////////////////////////////////////////////////////////////////////////////////////
1907
// numLayers==3 --> index=0; numLayers=5 --> index=1 ...
1908
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc
1909

    
1910
  MeshBase createMegaminxEdgeMesh(float width, float height)
1911
    {
1912
    MeshBase mesh = createFacesMegaminxEdge(width,height);
1913
    VertexEffect[] effects = createVertexEffectsMegaminxEdge(width,height);
1914
    for( VertexEffect effect : effects ) mesh.apply(effect);
1915

    
1916
    mesh.mergeEffComponents();
1917

    
1918
    return mesh;
1919
    }
1920

    
1921
///////////////////////////////////////////////////////////////////////////////////////////////////
1922

    
1923
  MeshBase createMegaminxCenterMesh(float width)
1924
    {
1925
    MeshBase mesh = createFacesMegaminxCenter(width);
1926
    VertexEffect[] effects = createVertexEffectsMegaminxCenter();
1927
    for( VertexEffect effect : effects ) mesh.apply(effect);
1928

    
1929
    mesh.mergeEffComponents();
1930
    mesh.addEmptyTexComponent();
1931
    mesh.addEmptyTexComponent();
1932
    mesh.addEmptyTexComponent();
1933
    mesh.addEmptyTexComponent();
1934

    
1935
    return mesh;
1936
    }
1937
  }
(2-2/30)