Project

General

Profile

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

examples / src / main / java / org / distorted / examples / meshfile / FactoryCubit.java @ ef02f5e0

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.examples.meshfile;
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
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
class FactoryCubit
37
  {
38
  private static final float SQ2 = (float)Math.sqrt(2);
39
  private static final float SQ3 = (float)Math.sqrt(3);
40
  private static final float SQ5 = (float)Math.sqrt(5);
41
  private static final float SQ6 = (float)Math.sqrt(6);
42

    
43
  private static final float IVY_D = 0.003f;
44
  private static final int   IVY_N = 8;
45
  private static final float IVY_C = 0.59f;
46
  private static final float IVY_M = 0.35f;
47
  private static final float REX_D = 0.2f;
48
  private static final int   REX_N = 5;
49

    
50
  static final float SIN18    = (SQ5-1)/4;
51
  static final float COS18    = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
52
  static final float SIN54    = (SQ5+1)/4;
53
  static final float COS54    = (float)(Math.sqrt(10-2*SQ5)/4);
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
  private static final Static1D RADIUS = new Static1D(1);
61

    
62
  private static FactoryCubit mThis;
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  private FactoryCubit()
67
    {
68

    
69
    }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

    
73
  public static FactoryCubit getInstance()
74
    {
75
    if( mThis==null ) mThis = new FactoryCubit();
76

    
77
    return mThis;
78
    }
79

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

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

    
117
  private float f(float D, float B, float x)
118
    {
119
    return ((D-B)*x + B*(1-D))/(1-B);
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

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

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
  private float h(float R, float sinAlpha, float x)
133
    {
134
    return R*(sinAlpha-(float)Math.sin(x));
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  float[] computeBands(float H, int alpha, float dist, float K, int N)
140
    {
141
    float[] bands = new float[2*N];
142

    
143
    bands[0] = 1.0f;
144
    bands[1] = 0.0f;
145

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

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

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

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

    
182
    bands[2*N-2] = 0.0f;
183
    bands[2*N-1] =    H;
184

    
185
    return bands;
186
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

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

    
194
    float centX = center.get0();
195
    float centY = center.get1();
196
    float centZ = center.get2();
197

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

    
204
      VertexEffect effect = new VertexEffectDeform(new Static3D(x,y,z), RADIUS, vertex, reg);
205
      mesh.apply(effect);
206
      }
207
    }
208

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

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

    
219
    float sinA = (float)Math.sin(radians);
220
    float cosA = (float)Math.cos(radians);
221

    
222
    float rvx = vx*cosA - vy*sinA;
223
    float rvy = vx*sinA + vy*cosA;
224

    
225
    array[index  ] = rvx + cx;
226
    array[index+1] = rvy + cy;
227
    }
228

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

    
231
  MeshBase createFacesCube(int sizeIndex)
232
    {
233
    MeshBase[] meshes = new MeshPolygon[6];
234

    
235
    float E = 0.5f;
236
    int extraI, extraV, num;
237

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

    
246
    float[] vertices = { -E,-E, +E,-E, +E,+E, -E,+E };
247
    float[] bands = computeBands(0.048f,35,E,0.7f,num);
248

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

    
262
    return new MeshJoined(meshes);
263
    }
264

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

    
267
  MeshBase createFacesSkewbCorner()
268
    {
269
    MeshBase[] meshes = new MeshBase[6];
270

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

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

    
284
    float[] vertices1 = { -F/2,-2*G, F/2,-2*G, 3*F/8,-G, 1*F/8,G, 0,2*G };
285
    float[] bands1 = computeBands(0,0,1,0,3);
286

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

    
294
    return new MeshJoined(meshes);
295
    }
296

    
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298

    
299
  MeshBase createFacesSkewbFace()
300
    {
301
    MeshBase[] meshes = new MeshBase[5];
302

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

    
307
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
308
    meshes[0].setEffectAssociation(0,1,0);
309

    
310
    float[] vertices1 = { -E,-SQ3*E, -E*0.7f,-SQ3*E, +E*0.7f,-SQ3*E, +E,-SQ3*E, 0,0 };
311
    float[] bands1 = computeBands(0,0,1,0,3);
312

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

    
322
    return new MeshJoined(meshes);
323
    }
324

    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326

    
327
  MeshBase createFacesOcta()
328
    {
329
    MeshBase[] meshes = new MeshPolygon[8];
330

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

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

    
353
    return new MeshJoined(meshes);
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

    
358
  MeshBase createFacesTetra()
359
    {
360
    MeshBase[] meshes = new MeshBase[4];
361

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

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

    
376
    return new MeshJoined(meshes);
377
    }
378

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

    
381
  MeshBase createFacesDino()
382
    {
383
    MeshBase[] meshes = new MeshPolygon[4];
384

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

    
390
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 5);
391
    meshes[0].setEffectAssociation(0,1,0);
392
    meshes[1] = meshes[0].copy(true);
393
    meshes[1].setEffectAssociation(0,2,0);
394

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

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

    
403
    return new MeshJoined(meshes);
404
    }
405

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

    
408
  MeshBase createFacesHelicopterCorner()
409
    {
410
    MeshBase[] meshes = new MeshBase[6];
411

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

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

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

    
434
    return new MeshJoined(meshes);
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

    
439
  MeshBase createFacesHelicopterFace()
440
    {
441
    MeshBase[] meshes = new MeshBase[4];
442

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

    
449
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
450
    meshes[0].setEffectAssociation(0,1,0);
451

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

    
455
    meshes[1] = new MeshPolygon(vertices1, bands1, 1, 3);
456
    meshes[1].setEffectAssociation(0,2,0);
457

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

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

    
465
    return new MeshJoined(meshes);
466
    }
467

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469

    
470
  MeshBase createFacesRediEdge()
471
    {
472
    MeshBase[] meshes = new MeshPolygon[6];
473

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

    
478
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 2);
479
    meshes[0].setEffectAssociation(0,1,0);
480
    meshes[1] = meshes[0].copy(true);
481
    meshes[1].setEffectAssociation(0,2,0);
482

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

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

    
491
    float X = 0.25f*SQ2;
492
    float Y = SQ6/16;
493
    float[] vertices2 = { -X, Y, -1.5f*X, -Y, +1.5f*X, -Y, +X, Y };
494

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

    
500
    return new MeshJoined(meshes);
501
    }
502

    
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

    
505
  MeshBase createFacesRediCorner()
506
    {
507
    MeshBase[] meshes = new MeshBase[6];
508

    
509
    float E = 0.5f;
510
    float[] vertices0 = { -E,-E, +E,-E, +E,+E, -E,+E };
511
    float[] bands0 = computeBands(0.06f,35,E,0.7f,6);
512

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

    
520
    float F = 0.5f;
521
    float X = 0.5f;
522
    float G = 0.72f;
523
    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 };
524
    float[] bands1 = computeBands(0.0f,0,1.0f,0.0f,2);
525

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

    
533
    return new MeshJoined(meshes);
534
    }
535

    
536
///////////////////////////////////////////////////////////////////////////////////////////////////
537

    
538
  MeshBase createFacesIvyCorner()
539
    {
540
    MeshBase[] meshes = new MeshBase[6];
541

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

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

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

    
560
      vertices[2*i+6] = (CORR*(cos-0.5f)-IVY_M)*IVY_C;
561
      vertices[2*i+7] = (CORR*(sin-0.5f)-IVY_M)*IVY_C;
562
      }
563

    
564
    float[] bands0 = computeBands(+0.012f,20,0.2f,0.5f,7);
565
    float[] bands1 = computeBands(-0.100f,20,0.2f,0.0f,2);
566

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

    
580
    return new MeshJoined(meshes);
581
    }
582

    
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584

    
585
  MeshBase createFacesIvyFace()
586
    {
587
    MeshBase[] meshes = new MeshBase[2];
588

    
589
    final float angle = (float)Math.PI/(2*IVY_N);
590
    final float CORR  = 1.0f - IVY_D*SQ2;
591
    float[] vertices = new float[4*IVY_N];
592

    
593
    for(int i=0; i<IVY_N; i++)
594
      {
595
      float sin = (float)Math.sin(i*angle);
596
      float cos = (float)Math.cos(i*angle);
597

    
598
      vertices[2*i          ] = CORR*(0.5f-cos);
599
      vertices[2*i+1        ] = CORR*(0.5f-sin);
600
      vertices[2*i  +2*IVY_N] = CORR*(cos-0.5f);
601
      vertices[2*i+1+2*IVY_N] = CORR*(sin-0.5f);
602
      }
603

    
604
    float[] bands0 = computeBands(+0.05f,35,0.5f,0.5f,5);
605
    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
606

    
607
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
608
    meshes[0].setEffectAssociation(0,1,0);
609
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
610
    meshes[1].setEffectAssociation(0,2,0);
611

    
612
    return new MeshJoined(meshes);
613
    }
614

    
615
///////////////////////////////////////////////////////////////////////////////////////////////////
616

    
617
  MeshBase createFacesRexCorner()
618
    {
619
    MeshBase[] meshes = new MeshBase[2];
620

    
621
    final float angle = (float)Math.PI/(6*REX_N);
622
    float[] vertices = new float[6*REX_N];
623
    final float D = 0.5f - REX_D;
624
    final float F = D*SQ2*(SQ3-1);
625
    final float B = 2.5f;
626

    
627
    final float V1x = -F*0.5f;
628
    final float V1y = -F*SQ3/6;
629
    final float V2x = -V1x;
630
    final float V2y = V1y;
631
    final float V3x = 0.0f;
632
    final float V3y = -2*V1y;
633

    
634
    final float C1x = 0.0f;
635
    final float C1y = -F*(1+2*SQ3/3);
636
    final float C2x = B*V1x;
637
    final float C2y = B*V1y;
638
    final float C3x = B*V2x;
639
    final float C3y = B*V2y;
640

    
641
    for(int i=0; i<REX_N; i++)
642
      {
643
      writeVertex(C1x,C1y,V1x,V1y,-i*angle, vertices, 2*i          );
644
      writeVertex(C2x,C2y,V2x,V2y, i*angle, vertices, 2*i + 2*REX_N);
645
      writeVertex(C3x,C3y,V3x,V3y, i*angle, vertices, 2*i + 4*REX_N);
646
      }
647

    
648
    float[] bands0 = computeBands(+0.02f,10,0.5f,0.5f,5);
649
    float[] bands1 = computeBands(-0.00f,45,0.5f,0.0f,2);
650

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

    
656
    return new MeshJoined(meshes);
657
    }
658

    
659
///////////////////////////////////////////////////////////////////////////////////////////////////
660

    
661
  MeshBase createFacesRexFace()
662
    {
663
    MeshBase[] meshes = new MeshBase[2];
664

    
665
    final float angle = (float)Math.PI/(6*REX_N);
666
    float[] vertices = new float[8*REX_N];
667
    final float D = 0.5f - REX_D;
668
    final float F = D*(SQ3-1);
669

    
670
    final float V1x = 0.0f;
671
    final float V1y = +F;
672
    final float V2x = -F;
673
    final float V2y = 0.0f;
674
    final float V3x = 0.0f;
675
    final float V3y = -F;
676
    final float V4x = +F;
677
    final float V4y = 0.0f;
678

    
679
    final float C1x = +D;
680
    final float C1y = -D;
681
    final float C2x = +D;
682
    final float C2y = +D;
683
    final float C3x = -D;
684
    final float C3y = +D;
685
    final float C4x = -D;
686
    final float C4y = -D;
687

    
688
    for(int i=0; i<REX_N; i++)
689
      {
690
      writeVertex(C1x,C1y,V1x,V1y, i*angle, vertices, 2*i          );
691
      writeVertex(C2x,C2y,V2x,V2y, i*angle, vertices, 2*i + 2*REX_N);
692
      writeVertex(C3x,C3y,V3x,V3y, i*angle, vertices, 2*i + 4*REX_N);
693
      writeVertex(C4x,C4y,V4x,V4y, i*angle, vertices, 2*i + 6*REX_N);
694
      }
695

    
696
    float[] bands0 = computeBands(+0.02f,10,0.5f,0.5f,5);
697
    float[] bands1 = computeBands(-0.00f,45,0.5f,0.0f,2);
698

    
699
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
700
    meshes[0].setEffectAssociation(0,1,0);
701
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
702
    meshes[1].setEffectAssociation(0,2,0);
703

    
704
    return new MeshJoined(meshes);
705
    }
706

    
707
///////////////////////////////////////////////////////////////////////////////////////////////////
708

    
709
  MeshBase createFacesRexEdge()
710
    {
711
    MeshBase[] meshes = new MeshPolygon[6];
712

    
713
    float E = 0.5f - REX_D;
714
    float F = 0.5f;
715
    float[] vertices0 = { -F,E/3, 0,-2*E/3, +F,E/3 };
716
    float[] bands0 = computeBands(0.03f,27,F/3,0.8f,5);
717

    
718
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 3);
719
    meshes[0].setEffectAssociation(0,1,0);
720
    meshes[1] = meshes[0].copy(true);
721
    meshes[1].setEffectAssociation(0,2,0);
722

    
723
    float G = (float)Math.sqrt(E*E+F*F);
724
    float[] vertices1 = { -2*G/3, -E/3, G/3, -E/3, G/3, 2*E/3 };
725
    float[] bands1 = computeBands(0.00f,45,G/3,0.2f,3);
726

    
727
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
728
    meshes[2].setEffectAssociation(0,4,0);
729
    meshes[3] = meshes[2].copy(true);
730
    meshes[3].setEffectAssociation(0,8,0);
731
    meshes[4] = meshes[2].copy(true);
732
    meshes[4].setEffectAssociation(0,16,0);
733
    meshes[5] = meshes[2].copy(true);
734
    meshes[5].setEffectAssociation(0,32,0);
735

    
736
    return new MeshJoined(meshes);
737
    }
738

    
739
///////////////////////////////////////////////////////////////////////////////////////////////////
740

    
741
  MeshBase createFacesKilominxCorner()
742
    {
743
    MeshBase[] meshes = new MeshPolygon[6];
744

    
745
    float X1= (SQ5+1)/8;
746
    float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
747
    float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8);
748
    float H = 0.5f* SIN54 / COS54;
749
    float X2= H*SIN_HALFD;
750
    float Y3= H/(2*COS_HALFD);
751
    float Y4= H*(1/(2*COS_HALFD) - COS_HALFD);
752

    
753
    float[] vertices0 = { -X1, Y2, 0, -Y1, X1, Y2, 0, Y1 };
754
    float[] bands0 = computeBands(0.03f,39,0.3f,0.2f,5);
755
    float[] vertices1 = { -X2, Y4, 0, -Y3, X2, Y4, 0, Y3 };
756
    float[] bands1 = computeBands(0.00f,27,0.25f,0.5f,5);
757

    
758
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
759
    meshes[0].setEffectAssociation(0, 1,0);
760
    meshes[1] = meshes[0].copy(true);
761
    meshes[1].setEffectAssociation(0, 2,0);
762
    meshes[2] = meshes[0].copy(true);
763
    meshes[2].setEffectAssociation(0, 4,0);
764
    meshes[3] = new MeshPolygon(vertices1, bands1, 1, 1);
765
    meshes[3].setEffectAssociation(0, 8,0);
766
    meshes[4] = meshes[3].copy(true);
767
    meshes[4].setEffectAssociation(0,16,0);
768
    meshes[5] = meshes[3].copy(true);
769
    meshes[5].setEffectAssociation(0,32,0);
770

    
771
    return new MeshJoined(meshes);
772
    }
773

    
774
///////////////////////////////////////////////////////////////////////////////////////////////////
775

    
776
  MeshBase createFacesMegaminxCorner()
777
    {
778
    MeshBase[] meshes = new MeshPolygon[6];
779

    
780
    float Y = COS54/(2*SIN54);
781

    
782
    float[] vertices0 = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y };
783
    float[] bands0 = computeBands(0.04f,34,0.3f,0.2f,5);
784
    float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,2);
785

    
786
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
787
    meshes[0].setEffectAssociation(0, 1,0);
788
    meshes[1] = meshes[0].copy(true);
789
    meshes[1].setEffectAssociation(0, 2,0);
790
    meshes[2] = meshes[0].copy(true);
791
    meshes[2].setEffectAssociation(0, 4,0);
792
    meshes[3] = new MeshPolygon(vertices0, bands1, 1, 4);
793
    meshes[3].setEffectAssociation(0, 8,0);
794
    meshes[4] = meshes[3].copy(true);
795
    meshes[4].setEffectAssociation(0,16,0);
796
    meshes[5] = meshes[3].copy(true);
797
    meshes[5].setEffectAssociation(0,32,0);
798

    
799
    return new MeshJoined(meshes);
800
    }
801

    
802
///////////////////////////////////////////////////////////////////////////////////////////////////
803

    
804
  MeshBase createFacesMegaminxEdge(float width, float height)
805
    {
806
    MeshBase[] meshes = new MeshPolygon[6];
807

    
808
    float D = height/COS18;
809
    float W = D*SIN18;
810

    
811
    float Y1 = 0.5f*width;
812
    float Y2 = 0.5f*width + W;
813
    float Y3 = 0.5f*width + 2*W;
814
    float X2 = D*SIN54;
815
    float X1 = 0.5f*height;
816
    float Y4 = D*COS54;
817

    
818
    float[] vertices0 = { -X1, Y1, -X1, -Y1, X1, -Y2, X1, Y2 };
819
    float[] vertices1 = { -X1, Y3, -X1, -Y3, X1, -Y2, X1, Y2 };
820
    float[] vertices2 = { -X2, 0.0f, 0.0f, -Y4, X2, 0.0f, 0.0f, Y4 };
821

    
822
    float[] bands0 = computeBands(0.04f,34,  X1,0.2f,5);
823
    float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,2);
824

    
825
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
826
    meshes[0].setEffectAssociation(0, 1,0);
827
    meshes[1] = meshes[0].copy(true);
828
    meshes[1].setEffectAssociation(0, 2,0);
829
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 4);
830
    meshes[2].setEffectAssociation(0, 4,0);
831
    meshes[3] = meshes[2].copy(true);
832
    meshes[3].setEffectAssociation(0, 8,0);
833
    meshes[4] = new MeshPolygon(vertices2, bands1, 1, 4);
834
    meshes[4].setEffectAssociation(0,16,0);
835
    meshes[5] = meshes[4].copy(true);
836
    meshes[5].setEffectAssociation(0,32,0);
837

    
838
    return new MeshJoined(meshes);
839
    }
840

    
841
///////////////////////////////////////////////////////////////////////////////////////////////////
842
// EFFECTS
843
///////////////////////////////////////////////////////////////////////////////////////////////////
844

    
845
  VertexEffect[] createVertexEffectsCube()
846
    {
847
    Static3D axisY   = new Static3D(0,1,0);
848
    Static3D axisX   = new Static3D(1,0,0);
849
    Static3D center  = new Static3D(0,0,0);
850
    Static1D angle90 = new Static1D(90);
851
    Static1D angle180= new Static1D(180);
852
    Static1D angle270= new Static1D(270);
853

    
854
    VertexEffect[] effect = new VertexEffect[6];
855

    
856
    effect[0] = new VertexEffectMove(new Static3D(0,0,+0.5f));
857
    effect[1] = new VertexEffectRotate( angle180, axisX, center );
858
    effect[2] = new VertexEffectRotate( angle90 , axisX, center );
859
    effect[3] = new VertexEffectRotate( angle270, axisX, center );
860
    effect[4] = new VertexEffectRotate( angle270, axisY, center );
861
    effect[5] = new VertexEffectRotate( angle90 , axisY, center );
862

    
863
    effect[0].setMeshAssociation(63,-1);  // all 6 sides
864
    effect[1].setMeshAssociation(32,-1);  // back
865
    effect[2].setMeshAssociation( 8,-1);  // bottom
866
    effect[3].setMeshAssociation( 4,-1);  // top
867
    effect[4].setMeshAssociation( 2,-1);  // left
868
    effect[5].setMeshAssociation( 1,-1);  // right
869

    
870
    return effect;
871
    }
872

    
873
///////////////////////////////////////////////////////////////////////////////////////////////////
874

    
875
  VertexEffect[] createVertexEffectsSkewbCorner()
876
    {
877
    float E = 0.5f;
878

    
879
    Static3D axisX  = new Static3D(1,0,0);
880
    Static3D axisY  = new Static3D(0,1,0);
881
    Static3D axis0  = new Static3D(-SQ2/2,0,SQ2/2);
882
    Static3D axis1  = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3);
883
    Static1D angle1 = new Static1D(+90);
884
    Static1D angle2 = new Static1D(-90);
885
    Static1D angle3 = new Static1D(-15);
886
    Static1D angle4 = new Static1D((float)((180.0f/Math.PI)*Math.acos(SQ3/3)));
887
    Static1D angle5 = new Static1D(120);
888
    Static1D angle6 = new Static1D(240);
889
    Static3D center1= new Static3D(0,0,0);
890
    Static3D center2= new Static3D(-0.5f,-0.5f,-0.5f);
891
    Static3D move1  = new Static3D(-E/4,-E/4,0);
892
    Static3D move2  = new Static3D(-0.5f+SQ2/4,-0.5f+SQ6/8,-0.5f);
893

    
894
    VertexEffect[] effect = new VertexEffect[10];
895

    
896
    effect[0] = new VertexEffectMove(move1);
897
    effect[1] = new VertexEffectScale(new Static3D(1,1,-1));
898
    effect[2] = new VertexEffectRotate(angle1,axisX,center1);
899
    effect[3] = new VertexEffectRotate(angle2,axisY,center1);
900
    effect[4] = new VertexEffectMove(move2);
901
    effect[5] = new VertexEffectRotate(angle1,axisX,center2);
902
    effect[6] = new VertexEffectRotate(angle3,axisY,center2);
903
    effect[7] = new VertexEffectRotate(angle4,axis0,center2);
904
    effect[8] = new VertexEffectRotate(angle5,axis1,center2);
905
    effect[9] = new VertexEffectRotate(angle6,axis1,center2);
906

    
907
    effect[0].setMeshAssociation( 7,-1);  // meshes 0,1,2
908
    effect[1].setMeshAssociation( 6,-1);  // meshes 1,2
909
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
910
    effect[3].setMeshAssociation( 4,-1);  // mesh 2
911
    effect[4].setMeshAssociation(56,-1);  // meshes 3,4,5
912
    effect[5].setMeshAssociation(56,-1);  // meshes 3,4,5
913
    effect[6].setMeshAssociation(56,-1);  // meshes 3,4,5
914
    effect[7].setMeshAssociation(56,-1);  // meshes 3,4,5
915
    effect[8].setMeshAssociation(16,-1);  // mesh 4
916
    effect[9].setMeshAssociation(32,-1);  // mesh 5
917

    
918
    return effect;
919
    }
920

    
921
///////////////////////////////////////////////////////////////////////////////////////////////////
922

    
923
  VertexEffect[] createVertexEffectsSkewbFace()
924
    {
925
    Static3D center = new Static3D(0,0,0);
926
    Static3D axisX  = new Static3D(1,0,0);
927
    Static3D axisZ  = new Static3D(0,0,1);
928
    float angle = -(float)((180.0f/Math.PI)*Math.acos(SQ3/3));
929

    
930
    VertexEffect[] effect = new VertexEffect[6];
931

    
932
    effect[0] = new VertexEffectRotate( new Static1D(angle), axisX, center);
933
    effect[1] = new VertexEffectRotate( new Static1D(  135), axisZ, center);
934
    effect[2] = new VertexEffectRotate( new Static1D(   45), axisZ, center);
935
    effect[3] = new VertexEffectRotate( new Static1D(  -45), axisZ, center);
936
    effect[4] = new VertexEffectRotate( new Static1D( -135), axisZ, center);
937
    effect[5] = new VertexEffectMove( new Static3D(0,0,-0.5f) );
938

    
939
    effect[0].setMeshAssociation(30,-1);  // meshes 1,2,3,4
940
    effect[1].setMeshAssociation( 2,-1);  // mesh 1
941
    effect[2].setMeshAssociation( 5,-1);  // meshes 0,2
942
    effect[3].setMeshAssociation( 8,-1);  // mesh 3
943
    effect[4].setMeshAssociation(16,-1);  // mesh 4
944
    effect[5].setMeshAssociation(30,-1);  // meshes 1,2,3,4
945

    
946
    return effect;
947
    }
948

    
949
///////////////////////////////////////////////////////////////////////////////////////////////////
950

    
951
  VertexEffect[] createVertexEffectsOcta()
952
    {
953
    Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3)));
954
    Static1D angle1= new Static1D( 90);
955
    Static1D angle2= new Static1D(180);
956
    Static1D angle3= new Static1D(270);
957
    Static3D move1 = new Static3D(0,SQ2/2-SQ3/3,0);
958
    Static3D axisX = new Static3D(1,0,0);
959
    Static3D axisY = new Static3D(0,1,0);
960
    Static3D cent0 = new Static3D(0,0,0);
961
    Static3D cent1 = new Static3D(0,SQ2/2,0);
962
    Static3D flipY = new Static3D( 1,-1, 1);
963
    Static3D scale = new Static3D( 1, 2*SQ3/3, 1);
964

    
965
    VertexEffect[] effect = new VertexEffect[7];
966

    
967
    effect[0] = new VertexEffectScale(scale);
968
    effect[1] = new VertexEffectMove(move1);
969
    effect[2] = new VertexEffectRotate(alpha , axisX, cent1);
970
    effect[3] = new VertexEffectRotate(angle1, axisY, cent0);
971
    effect[4] = new VertexEffectRotate(angle2, axisY, cent0);
972
    effect[5] = new VertexEffectRotate(angle3, axisY, cent0);
973
    effect[6] = new VertexEffectScale(flipY);
974

    
975
    effect[3].setMeshAssociation ( 34,-1); // apply to meshes 1 & 5
976
    effect[4].setMeshAssociation ( 68,-1); // apply to meshes 2 & 6
977
    effect[5].setMeshAssociation (136,-1); // apply to meshes 3 & 7
978
    effect[6].setMeshAssociation (240,-1); // apply to meshes 4,5,6,7
979

    
980
    return effect;
981
    }
982

    
983
///////////////////////////////////////////////////////////////////////////////////////////////////
984

    
985
  VertexEffect[] createVertexEffectsTetra()
986
    {
987
    Static3D flipZ = new Static3D( 1, 1,-1);
988
    Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3)));
989
    Static1D angle1= new Static1D( 90);
990
    Static1D angle2= new Static1D(180);
991
    Static3D move1 = new Static3D(0,SQ2/4-SQ3/6,0);
992
    Static3D axisX = new Static3D(1,0,0);
993
    Static3D axisY = new Static3D(0,1,0);
994
    Static3D axisZ = new Static3D(0,0,1);
995
    Static3D cent0 = new Static3D(0,0,0);
996
    Static3D cent1 = new Static3D(0,SQ2/4,0);
997
    Static3D scale = new Static3D( 1, 2*SQ3/3, 1);
998

    
999
    VertexEffect[] effect = new VertexEffect[7];
1000

    
1001
    effect[0] = new VertexEffectScale(scale);
1002
    effect[1] = new VertexEffectRotate(angle2, axisZ, cent0);
1003
    effect[2] = new VertexEffectMove(move1);
1004
    effect[3] = new VertexEffectRotate(alpha , axisX, cent1);
1005
    effect[4] = new VertexEffectScale(flipZ);
1006
    effect[5] = new VertexEffectRotate(angle1, axisY, cent0);
1007
    effect[6] = new VertexEffectRotate(angle2, axisZ, cent0);
1008

    
1009
    effect[4].setMeshAssociation(10,-1); // meshes 1 & 3
1010
    effect[5].setMeshAssociation(12,-1); // meshes 2 & 3
1011
    effect[6].setMeshAssociation(12,-1); // meshes 2 & 3
1012

    
1013
    return effect;
1014
    }
1015

    
1016
///////////////////////////////////////////////////////////////////////////////////////////////////
1017

    
1018
  VertexEffect[] createVertexEffectsDino()
1019
    {
1020
    float E = 0.5f*SQ2;
1021
    float F = 0.5f;
1022
    final float ANGLE = (float)((180/Math.PI)*(Math.atan(SQ2)));
1023

    
1024
    Static1D angle1 = new Static1D(-ANGLE);
1025
    Static1D angle2 = new Static1D(+ANGLE);
1026
    Static3D axisX  = new Static3D(1,0,0);
1027
    Static3D axisY  = new Static3D(0,1,0);
1028
    Static3D axisZ  = new Static3D(0,-1,1);
1029
    Static3D center0= new Static3D(0,0,0);
1030
    Static3D center1= new Static3D(0,-3*F,0);
1031

    
1032
    VertexEffect[] effect = new VertexEffect[10];
1033

    
1034
    effect[0] = new VertexEffectScale ( new Static3D(3,3,3) );
1035
    effect[1] = new VertexEffectMove  ( new Static3D(0,-F,0) );
1036
    effect[2] = new VertexEffectRotate( new Static1D(90), axisX, center0 );
1037
    effect[3] = new VertexEffectScale ( new Static3D(1,-1,1) );
1038
    effect[4] = new VertexEffectMove  ( new Static3D(3*E/2,E*(SQ3/2)-3*F,0) );
1039
    effect[5] = new VertexEffectRotate( new Static1D(+90), axisY, center1 );
1040
    effect[6] = new VertexEffectScale ( new Static3D(-1,1,1) );
1041
    effect[7] = new VertexEffectRotate( new Static1D( 45), axisX, center1 );
1042
    effect[8] = new VertexEffectRotate( angle1           , axisZ, center1 );
1043
    effect[9] = new VertexEffectRotate( angle2           , axisZ, center1 );
1044

    
1045
    effect[0].setMeshAssociation(15,-1);  // apply to meshes 0,1,2,3
1046
    effect[1].setMeshAssociation( 3,-1);  // apply to meshes 0,1
1047
    effect[2].setMeshAssociation( 2,-1);  // apply to mesh 1
1048
    effect[3].setMeshAssociation( 2,-1);  // apply to mesh 0
1049
    effect[4].setMeshAssociation(12,-1);  // apply to meshes 2,3
1050
    effect[5].setMeshAssociation(12,-1);  // apply to meshes 2,3
1051
    effect[6].setMeshAssociation( 8,-1);  // apply to mesh 3
1052
    effect[7].setMeshAssociation(12,-1);  // apply to meshes 2,3
1053
    effect[8].setMeshAssociation( 4,-1);  // apply to mesh 2
1054
    effect[9].setMeshAssociation( 8,-1);  // apply to mesh 3
1055

    
1056
    return effect;
1057
    }
1058

    
1059
///////////////////////////////////////////////////////////////////////////////////////////////////
1060

    
1061
  VertexEffect[] createVertexEffectsHelicopterCorner()
1062
    {
1063
    float E = 0.5f;
1064

    
1065
    Static3D axisX  = new Static3D(1,0,0);
1066
    Static3D axisY  = new Static3D(0,1,0);
1067
    Static3D axis0  = new Static3D(-SQ2/2,0,SQ2/2);
1068
    Static3D axis1  = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3);
1069
    Static1D angle1 = new Static1D(+90);
1070
    Static1D angle2 = new Static1D(-90);
1071
    Static1D angle3 = new Static1D(-135);
1072
    Static1D angle4 = new Static1D(90);
1073
    Static1D angle5 = new Static1D(120);
1074
    Static1D angle6 = new Static1D(240);
1075
    Static3D center1= new Static3D(0,0,0);
1076
    Static3D center2= new Static3D(-0.25f,-0.25f,-0.25f);
1077
    Static3D move1  = new Static3D(-E/4,-E/4,0);
1078
    Static3D move2  = new Static3D(-0.25f,(-1.0f/6)-0.25f,-0.25f);
1079

    
1080
    VertexEffect[] effect = new VertexEffect[10];
1081

    
1082
    effect[0] = new VertexEffectMove(move1);
1083
    effect[1] = new VertexEffectScale(new Static3D(1,1,-1));
1084
    effect[2] = new VertexEffectRotate(angle1,axisX,center1);
1085
    effect[3] = new VertexEffectRotate(angle2,axisY,center1);
1086
    effect[4] = new VertexEffectMove(move2);
1087
    effect[5] = new VertexEffectRotate(angle1,axisX,center2);
1088
    effect[6] = new VertexEffectRotate(angle3,axisY,center2);
1089
    effect[7] = new VertexEffectRotate(angle4,axis0,center2);
1090
    effect[8] = new VertexEffectRotate(angle5,axis1,center2);
1091
    effect[9] = new VertexEffectRotate(angle6,axis1,center2);
1092

    
1093
    effect[0].setMeshAssociation( 7,-1);  // meshes 0,1,2
1094
    effect[1].setMeshAssociation( 6,-1);  // meshes 1,2
1095
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
1096
    effect[3].setMeshAssociation( 4,-1);  // mesh 2
1097
    effect[4].setMeshAssociation(56,-1);  // meshes 3,4,5
1098
    effect[5].setMeshAssociation(56,-1);  // meshes 3,4,5
1099
    effect[6].setMeshAssociation(56,-1);  // meshes 3,4,5
1100
    effect[7].setMeshAssociation(56,-1);  // meshes 3,4,5
1101
    effect[8].setMeshAssociation(16,-1);  // mesh 4
1102
    effect[9].setMeshAssociation(32,-1);  // mesh 5
1103

    
1104
    return effect;
1105
    }
1106

    
1107
///////////////////////////////////////////////////////////////////////////////////////////////////
1108

    
1109
  VertexEffect[] createVertexEffectsHelicopterFace()
1110
    {
1111
    float E = 0.5f;
1112
    float F = SQ2/4;
1113

    
1114
    Static3D move0  = new Static3D(-E/4, -E/4, 0);
1115
    Static3D move1  = new Static3D(-(SQ2/24)-E/2, -(SQ2/24)-E/2, 0);
1116
    Static3D move2  = new Static3D(-E/2, F/3, 0);
1117
    Static3D move3  = new Static3D(+E/2, F/3, 0);
1118
    Static3D move4  = new Static3D(+E/3,+E/3, 0);
1119
    Static1D angle1 = new Static1D(135);
1120
    Static1D angle2 = new Static1D(90);
1121
    Static1D angle3 = new Static1D(-90);
1122
    Static1D angle4 = new Static1D(-135);
1123
    Static3D axisX  = new Static3D(1,0,0);
1124
    Static3D axisY  = new Static3D(0,1,0);
1125
    Static3D axisZ  = new Static3D(0,0,1);
1126
    Static3D axis1  = new Static3D(1,-1,0);
1127
    Static3D center = new Static3D(0,0,0);
1128
    Static3D center1= new Static3D(-E/2,-E/2,0);
1129

    
1130
    VertexEffect[] effect = new VertexEffect[10];
1131

    
1132
    effect[0] = new VertexEffectMove(move0);
1133
    effect[1] = new VertexEffectRotate(angle1, axisZ, center);
1134
    effect[2] = new VertexEffectMove(move1);
1135
    effect[3] = new VertexEffectRotate(angle2, axis1, center1);
1136
    effect[4] = new VertexEffectMove(move2);
1137
    effect[5] = new VertexEffectMove(move3);
1138
    effect[6] = new VertexEffectRotate(angle3, axisZ, center);
1139
    effect[7] = new VertexEffectRotate(angle4, axisX, center);
1140
    effect[8] = new VertexEffectRotate(angle1, axisY, center);
1141
    effect[9] = new VertexEffectMove(move4);
1142

    
1143
    effect[0].setMeshAssociation( 1,-1);  // mesh 0
1144
    effect[1].setMeshAssociation( 2,-1);  // mesh 1
1145
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
1146
    effect[3].setMeshAssociation( 2,-1);  // mesh 1
1147
    effect[4].setMeshAssociation( 4,-1);  // mesh 2
1148
    effect[5].setMeshAssociation( 8,-1);  // mesh 3
1149
    effect[6].setMeshAssociation( 8,-1);  // mesh 3
1150
    effect[7].setMeshAssociation( 4,-1);  // mesh 2
1151
    effect[8].setMeshAssociation( 8,-1);  // mesh 3
1152
    effect[9].setMeshAssociation(15,-1);  // meshes 0,1,2,3
1153

    
1154
    return effect;
1155
    }
1156

    
1157
///////////////////////////////////////////////////////////////////////////////////////////////////
1158

    
1159
  VertexEffect[] createVertexEffectsRediEdge()
1160
    {
1161
    Static3D move0 = new Static3D(0.0f, -0.5f, 0.0f);
1162
    Static3D move1 = new Static3D(0.25f, -0.25f, 0.0f);
1163
    Static3D move2 = new Static3D(0.5f, 0.0f, 0.0f);
1164
    Static3D move3 = new Static3D(0.0f, (SQ3-6)/8, (SQ3-6)/8);
1165
    Static3D flipZ = new Static3D(1,1,-1);
1166
    Static3D flipX = new Static3D(-1,1,1);
1167
    Static3D scale = new Static3D(2,2,2);
1168
    Static3D cent0 = new Static3D(0,0, 0);
1169
    Static3D cent1 = new Static3D(0,0, -1.5f);
1170
    Static3D axisX = new Static3D(1,0, 0);
1171
    Static3D axisY = new Static3D(0,1, 0);
1172
    Static3D axis  = new Static3D(0,SQ2/2,-SQ2/2);
1173
    Static1D angle1= new Static1D(90);
1174
    Static1D angle2= new Static1D(45);
1175
    Static1D angle3= new Static1D( (float)(180/Math.PI*Math.acos(SQ3/3)) );
1176

    
1177
    VertexEffect[] effect = new VertexEffect[12];
1178

    
1179
    effect[0] = new VertexEffectScale(scale);
1180
    effect[1] = new VertexEffectMove(move0);
1181
    effect[2] = new VertexEffectScale(flipZ);
1182
    effect[3] = new VertexEffectRotate(angle1,axisX,cent0);
1183
    effect[4] = new VertexEffectMove(move1);
1184
    effect[5] = new VertexEffectRotate(angle1,axisY,cent0);
1185
    effect[6] = new VertexEffectMove(move2);
1186
    effect[7] = new VertexEffectScale(flipX);
1187
    effect[8] = new VertexEffectRotate(angle2,axisX,cent0);
1188
    effect[9] = new VertexEffectMove(move3);
1189
    effect[10]= new VertexEffectRotate(angle3,axis ,cent1);
1190
    effect[11]= new VertexEffectScale(flipX);
1191

    
1192
    effect[0].setMeshAssociation(63,-1);  // meshes 0,1,2,3,4,5
1193
    effect[1].setMeshAssociation( 3,-1);  // meshes 0,1
1194
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
1195
    effect[3].setMeshAssociation( 2,-1);  // mesh 1
1196
    effect[4].setMeshAssociation(12,-1);  // meshes 2,3
1197
    effect[5].setMeshAssociation(60,-1);  // meshes 2,3,4,5
1198
    effect[6].setMeshAssociation(12,-1);  // meshes 2,3
1199
    effect[7].setMeshAssociation( 8,-1);  // mesh 3
1200
    effect[8].setMeshAssociation(48,-1);  // meshes 4,5
1201
    effect[9].setMeshAssociation(48,-1);  // meshes 4,5
1202
    effect[10].setMeshAssociation(48,-1); // meshes 4,5
1203
    effect[11].setMeshAssociation(32,-1); // mesh 5
1204

    
1205
    return effect;
1206
    }
1207

    
1208
///////////////////////////////////////////////////////////////////////////////////////////////////
1209

    
1210
  VertexEffect[] createVertexEffectsRediCorner()
1211
    {
1212
    Static3D axisY   = new Static3D(0,1,0);
1213
    Static3D axisX   = new Static3D(1,0,0);
1214
    Static3D axisZ   = new Static3D(0,0,1);
1215
    Static3D center  = new Static3D(0,0,0);
1216
    Static1D angle90 = new Static1D(90);
1217
    Static1D angle270= new Static1D(270);
1218
    Static1D angle45 = new Static1D(-45);
1219
    Static3D scale   = new Static3D(1.0f, SQ2, 1.0f);
1220

    
1221
    VertexEffect[] effect = new VertexEffect[7];
1222

    
1223
    effect[0] = new VertexEffectMove(new Static3D(0,0,+0.5f));
1224
    effect[1] = new VertexEffectRotate( angle270, axisX, center );
1225
    effect[2] = new VertexEffectRotate( angle90 , axisY, center );
1226
    effect[3] = new VertexEffectScale(scale);
1227
    effect[4] = new VertexEffectRotate( angle45 , axisX, center );
1228
    effect[5] = new VertexEffectRotate( angle90 , axisY, center );
1229
    effect[6] = new VertexEffectRotate( angle270, axisZ, center );
1230

    
1231
    effect[0].setMeshAssociation( 7,-1);  // 0,1,2
1232
    effect[1].setMeshAssociation( 2,-1);  // 1
1233
    effect[2].setMeshAssociation( 4,-1);  // 2
1234
    effect[3].setMeshAssociation(56,-1);  // 3,4,5
1235
    effect[4].setMeshAssociation(56,-1);  // 3,4,5
1236
    effect[5].setMeshAssociation(16,-1);  // 4
1237
    effect[6].setMeshAssociation(32,-1);  // 5
1238

    
1239
    return effect;
1240
    }
1241

    
1242
///////////////////////////////////////////////////////////////////////////////////////////////////
1243

    
1244
  VertexEffect[] createVertexEffectsIvyCorner()
1245
    {
1246
    Static3D axisX  = new Static3D(1,0,0);
1247
    Static3D axisY  = new Static3D(0,1,0);
1248
    Static1D angle1 = new Static1D(+90);
1249
    Static1D angle2 = new Static1D(-90);
1250
    Static3D center = new Static3D(0,0,0);
1251
    Static3D move1  = new Static3D(IVY_M-0.5f,IVY_M-0.5f,0);
1252

    
1253
    VertexEffect[] effect = new VertexEffect[5];
1254

    
1255
    effect[0] = new VertexEffectScale(1/IVY_C);
1256
    effect[1] = new VertexEffectMove(move1);
1257
    effect[2] = new VertexEffectScale(new Static3D(1,1,-1));
1258
    effect[3] = new VertexEffectRotate(angle1,axisX,center);
1259
    effect[4] = new VertexEffectRotate(angle2,axisY,center);
1260

    
1261
    effect[2].setMeshAssociation(54,-1);  // meshes 1,2,4,5
1262
    effect[3].setMeshAssociation(18,-1);  // meshes 1,4
1263
    effect[4].setMeshAssociation(36,-1);  // meshes 2,5
1264

    
1265
    return effect;
1266
    }
1267

    
1268
///////////////////////////////////////////////////////////////////////////////////////////////////
1269

    
1270
  VertexEffect[] createVertexEffectsRexEdge()
1271
    {
1272
    float E = 0.5f - REX_D;
1273
    float F = 0.5f;
1274
    float G = (float)Math.sqrt(E*E+F*F);
1275
    float A = (float)((180/Math.PI)*Math.asin(E/G));
1276

    
1277
    Static3D move1 = new Static3D(    0.0f, -E/3, 0.0f);
1278
    Static3D move2 = new Static3D(2*G/3 -F, +E/3, 0.0f);
1279

    
1280
    Static3D center0= new Static3D(0.0f, 0.0f, 0.0f);
1281
    Static3D center1= new Static3D(  -F, 0.0f, 0.0f);
1282
    Static3D center2= new Static3D(  +F, 0.0f, 0.0f);
1283
    Static3D axisX  = new Static3D(1.0f, 0.0f, 0.0f);
1284
    Static3D axisY  = new Static3D(0.0f, 1.0f, 0.0f);
1285
    Static3D axisZ  = new Static3D(0.0f, 0.0f, 1.0f);
1286

    
1287
    Static1D angle180 = new Static1D(180);
1288
    Static1D angle90  = new Static1D( 90);
1289
    Static1D angle270 = new Static1D(270);
1290
    Static1D angle1   = new Static1D(+A);
1291
    Static1D angle2   = new Static1D(-A);
1292

    
1293
    VertexEffect[] effect = new VertexEffect[12];
1294

    
1295
    effect[0] = new VertexEffectMove(move1);
1296
    effect[1] = new VertexEffectMove(move2);
1297
    effect[2] = new VertexEffectRotate(  angle90, axisX, center0 );
1298
    effect[3] = new VertexEffectRotate( angle270, axisX, center0 );
1299
    effect[4] = new VertexEffectRotate( angle180, axisX, center0 );
1300
    effect[5] = new VertexEffectRotate( angle180, axisY, center0 );
1301
    effect[6] = new VertexEffectScale ( new Static3D(-1, 1, 1) );
1302
    effect[7] = new VertexEffectScale ( new Static3D( 1,-1, 1) );
1303
    effect[8] = new VertexEffectRotate(   angle1, axisY, center1);
1304
    effect[9] = new VertexEffectRotate(   angle2, axisY, center2);
1305
    effect[10]= new VertexEffectRotate(   angle2, axisZ, center1);
1306
    effect[11]= new VertexEffectRotate(   angle1, axisZ, center2);
1307

    
1308
    effect[0].setMeshAssociation( 3,-1);  // meshes 0 & 1
1309
    effect[1].setMeshAssociation(60,-1);  // meshes 2,3,4,5
1310
    effect[2].setMeshAssociation( 2,-1);  // meshes 1
1311
    effect[3].setMeshAssociation(12,-1);  // meshes 2,3
1312
    effect[4].setMeshAssociation(48,-1);  // meshes 4,5
1313
    effect[5].setMeshAssociation(32,-1);  // mesh 5
1314
    effect[6].setMeshAssociation( 8,-1);  // apply to mesh 3
1315
    effect[7].setMeshAssociation( 2,-1);  // apply to mesh 1
1316
    effect[8].setMeshAssociation(16,-1);  // apply to mesh 4
1317
    effect[9].setMeshAssociation(32,-1);  // apply to mesh 5
1318
    effect[10].setMeshAssociation(4,-1);  // apply to mesh 2
1319
    effect[11].setMeshAssociation(8,-1);  // apply to mesh 3
1320

    
1321
    return effect;
1322
    }
1323

    
1324
///////////////////////////////////////////////////////////////////////////////////////////////////
1325

    
1326
  VertexEffect[] createVertexEffectsRexCorner()
1327
    {
1328
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
1329
    Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
1330
    Static1D angle = new Static1D(45);
1331

    
1332
    VertexEffect[] effect = new VertexEffect[1];
1333
    effect[0] = new VertexEffectRotate(angle, axisZ, center);
1334

    
1335
    return effect;
1336
    }
1337

    
1338
///////////////////////////////////////////////////////////////////////////////////////////////////
1339

    
1340
  VertexEffect[] createVertexEffectsKilominxCorner()
1341
    {
1342
    VertexEffect[] effect = new VertexEffect[9];
1343

    
1344
    float H = 0.5f*(SIN54 / COS54);
1345
    float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
1346
    float Y2= H/(2*COS_HALFD);
1347
    float A = (float)(Math.acos(-SQ5/5)*180/Math.PI);  // dihedral angle of a dedecahedron in degrees
1348
    float sin18 = SIN18;
1349
    float cos18 = (float)(Math.sqrt(1- SIN18 * SIN18));
1350
    float LEN   = (float)Math.sqrt(H*H/(COS_HALFD*COS_HALFD) + 0.25f);
1351

    
1352
    Static3D axisZ = new Static3D(0.0f  , 0.0f , 1.0f);
1353
    Static3D axisY = new Static3D(0.0f  , 1.0f , 0.0f);
1354
    Static3D axisA = new Static3D(-sin18, cos18, 0.0f);
1355
    Static3D axisC = new Static3D( H/LEN, -0.5f/LEN,-H*SIN_HALFD/(COS_HALFD*LEN));
1356

    
1357
    Static3D move1 = new Static3D(0,-Y1,0);
1358
    Static3D move2 = new Static3D(0,-Y2,0);
1359
    Static3D move3 = new Static3D(0.5f*cos18,0.5f*sin18,0);
1360
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
1361

    
1362
    Static1D angle1 = new Static1D(54);
1363
    Static1D angle2 = new Static1D(A/2+18);
1364
    Static1D angle3 = new Static1D(90);
1365
    Static1D angle4 = new Static1D(120);
1366
    Static1D angle5 = new Static1D(240);
1367
    Static1D angle6 = new Static1D(90-A/2);
1368

    
1369
    effect[0] = new VertexEffectMove(move1);
1370
    effect[1] = new VertexEffectMove(move2);
1371
    effect[2] = new VertexEffectRotate(angle1, axisZ, center);
1372
    effect[3] = new VertexEffectRotate(angle2, axisZ, center);
1373
    effect[4] = new VertexEffectRotate(angle3, axisA, center);
1374
    effect[5] = new VertexEffectMove(move3);
1375
    effect[6] = new VertexEffectRotate(angle4, axisC, center);
1376
    effect[7] = new VertexEffectRotate(angle5, axisC, center);
1377
    effect[8] = new VertexEffectRotate(angle6, axisY, center);
1378

    
1379
    effect[0].setMeshAssociation( 7,-1);  // meshes 0,1,2
1380
    effect[1].setMeshAssociation(56,-1);  // meshes 3,4,5
1381
    effect[2].setMeshAssociation( 7,-1);  // meshes 0,1,2
1382
    effect[3].setMeshAssociation(56,-1);  // meshes 3,4,5
1383
    effect[4].setMeshAssociation(56,-1);  // meshes 3,4,5
1384
    effect[5].setMeshAssociation(56,-1);  // meshes 3,4,5
1385
    effect[6].setMeshAssociation(18,-1);  // meshes 1,4
1386
    effect[7].setMeshAssociation(36,-1);  // meshes 2,5
1387

    
1388
    return effect;
1389
    }
1390

    
1391
///////////////////////////////////////////////////////////////////////////////////////////////////
1392

    
1393
  VertexEffect[] createVertexEffectsMegaminxCorner()
1394
    {
1395
    VertexEffect[] effect = new VertexEffect[9];
1396

    
1397
    float Y = COS54/(2*SIN54);
1398

    
1399
    float sinA = (2*SIN54*SIN54-1)/COS54;
1400
    float cosA = (float)Math.sqrt(1-sinA*sinA);
1401
    float LEN  = 0.5f/SIN54;
1402

    
1403
    Static3D axisA = new Static3D( SIN54, COS54, 0.0f);
1404
    Static3D axisB = new Static3D(-SIN54, COS54, 0.0f);
1405
    Static3D axisX = new Static3D(  1.0f,  0.0f, 0.0f);
1406

    
1407
    Static3D centerU = new Static3D( 0.0f, Y, 0.0f);
1408
    Static3D centerD = new Static3D( 0.0f,-Y, 0.0f);
1409

    
1410
    Static3D move1= new Static3D(0.0f, -sinA*LEN, -cosA*LEN );
1411
    Static3D move2= new Static3D(0.0f, Y , 0.0f );
1412

    
1413
    Static1D angleD = new Static1D(DIHEDRAL1);
1414
    Static1D angleE = new Static1D(360-DIHEDRAL1);
1415
    Static1D angleF = new Static1D(DIHEDRAL2);
1416

    
1417
    effect[0] = new VertexEffectScale ( new Static3D( 1, 1,-1) );
1418
    effect[1] = new VertexEffectRotate(angleE, axisA, centerU);
1419
    effect[2] = new VertexEffectRotate(angleD, axisB, centerU);
1420
    effect[3] = new VertexEffectMove(move1);
1421
    effect[4] = new VertexEffectRotate(angleE, axisA, centerD);
1422
    effect[5] = new VertexEffectRotate(angleD, axisB, centerD);
1423
    effect[6] = new VertexEffectRotate(angleF, axisX, centerD);
1424
    effect[7] = new VertexEffectMove(move2);
1425
    effect[8] = new VertexEffectScale(SIN54);
1426

    
1427
    effect[0].setMeshAssociation(  3,-1);  // meshes 0,1
1428
    effect[1].setMeshAssociation( 16,-1);  // mesh 4
1429
    effect[2].setMeshAssociation( 32,-1);  // mesh 5
1430
    effect[3].setMeshAssociation( 56,-1);  // meshes 3,4,5
1431
    effect[4].setMeshAssociation(  1,-1);  // mesh 0
1432
    effect[5].setMeshAssociation(  2,-1);  // mesh 1
1433

    
1434
    return effect;
1435
    }
1436

    
1437
///////////////////////////////////////////////////////////////////////////////////////////////////
1438

    
1439
  VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height)
1440
    {
1441
    VertexEffect[] effect = new VertexEffect[11];
1442

    
1443
    float X = 0.5f*height;
1444
    float Y = height*(COS54/COS18) + width*0.5f;
1445
    float Z = 2*height*COS_HALFD;
1446

    
1447
    float alpha = 90-DIHEDRAL1/2;
1448
    float beta  = DIHEDRAL2;
1449

    
1450
    Static1D angle1 = new Static1D(alpha);
1451
    Static1D angle2 = new Static1D(180-alpha);
1452
    Static1D angle3 = new Static1D(beta);
1453

    
1454
    Static3D move1 = new Static3D(X,0,0);
1455
    Static3D move2 = new Static3D(X,0,-Z);
1456
    Static3D move3 = new Static3D(0,+Y,0);
1457
    Static3D move4 = new Static3D(0,-Y,0);
1458
    Static3D scale = new Static3D(+1,+1,-1);
1459

    
1460
    Static3D axisXplus = new Static3D(+1, 0, 0);
1461
    Static3D axisXminus= new Static3D(-1, 0, 0);
1462
    Static3D axisYplus = new Static3D( 0,+1, 0);
1463
    Static3D axisYminus= new Static3D( 0,-1, 0);
1464

    
1465
    Static3D center1= new Static3D( 0, 0, 0);
1466
    Static3D center2= new Static3D( 0, 0,-Z);
1467
    Static3D center3= new Static3D( 0,+width*0.5f, 0);
1468
    Static3D center4= new Static3D( 0,-width*0.5f, 0);
1469

    
1470
    effect[ 0] = new VertexEffectMove(move1);
1471
    effect[ 1] = new VertexEffectMove(move2);
1472
    effect[ 2] = new VertexEffectMove(move3);
1473
    effect[ 3] = new VertexEffectMove(move4);
1474
    effect[ 4] = new VertexEffectScale(scale);
1475
    effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1);
1476
    effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1);
1477
    effect[ 7] = new VertexEffectRotate(angle1, axisYminus, center2);
1478
    effect[ 8] = new VertexEffectRotate(angle2, axisYminus, center2);
1479
    effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center3);
1480
    effect[10] = new VertexEffectRotate(angle3, axisXminus, center4);
1481

    
1482
    effect[ 0].setMeshAssociation( 3,-1);  // meshes 0,1
1483
    effect[ 1].setMeshAssociation(12,-1);  // meshes 2,3
1484
    effect[ 2].setMeshAssociation(16,-1);  // mesh 4
1485
    effect[ 3].setMeshAssociation(32,-1);  // mesh 5
1486
    effect[ 4].setMeshAssociation( 2,-1);  // mesh 1
1487
    effect[ 5].setMeshAssociation( 1,-1);  // mesh 0
1488
    effect[ 6].setMeshAssociation( 2,-1);  // mesh 1
1489
    effect[ 7].setMeshAssociation( 4,-1);  // mesh 2
1490
    effect[ 8].setMeshAssociation( 8,-1);  // mesh 3
1491
    effect[ 9].setMeshAssociation(16,-1);  // mesh 4
1492
    effect[10].setMeshAssociation(32,-1);  // mesh 5
1493

    
1494
    return effect;
1495
    }
1496

    
1497
///////////////////////////////////////////////////////////////////////////////////////////////////
1498
// OBJECTS
1499
///////////////////////////////////////////////////////////////////////////////////////////////////
1500
// CUBE
1501

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

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

    
1519
    roundCorners(mesh,roundingCenter,vertices,0.06f,0.12f);
1520

    
1521
    mesh.mergeEffComponents();
1522

    
1523
    return mesh;
1524
    }
1525

    
1526
///////////////////////////////////////////////////////////////////////////////////////////////////
1527
// SKEWB
1528

    
1529
  MeshBase createSkewbCornerMesh()
1530
    {
1531
    MeshBase mesh = createFacesSkewbCorner();
1532
    VertexEffect[] effects = createVertexEffectsSkewbCorner();
1533
    for( VertexEffect effect : effects ) mesh.apply(effect);
1534

    
1535
    float E = 0.5f;
1536
    Static3D roundingCenter = new Static3D(-E/2,-E/2,-E/2);
1537

    
1538
    Static3D[] verticesType1 = new Static3D[1];
1539
    verticesType1[0] = new Static3D(0.0f,0.0f,0.0f);
1540
    roundCorners(mesh,roundingCenter,verticesType1,0.08f,0.15f);
1541

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

    
1548
    mesh.mergeEffComponents();
1549

    
1550
    return mesh;
1551
    }
1552

    
1553
///////////////////////////////////////////////////////////////////////////////////////////////////
1554

    
1555
  MeshBase createSkewbFaceMesh()
1556
    {
1557
    MeshBase mesh = createFacesSkewbFace();
1558
    VertexEffect[] effects = createVertexEffectsSkewbFace();
1559
    for( VertexEffect effect : effects ) mesh.apply(effect);
1560

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

    
1570
    mesh.mergeEffComponents();
1571
    mesh.addEmptyTexComponent();
1572

    
1573
    return mesh;
1574
    }
1575

    
1576
///////////////////////////////////////////////////////////////////////////////////////////////////
1577
// SKEWB DIAMOND / PYRAMINX
1578

    
1579
  MeshBase createOctaMesh()
1580
    {
1581
    MeshBase mesh = createFacesOcta();
1582
    VertexEffect[] effects = createVertexEffectsOcta();
1583
    for( VertexEffect effect : effects ) mesh.apply(effect);
1584

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

    
1594
    roundCorners(mesh,roundingCenter,vertices,0.06f,0.20f);
1595

    
1596
    mesh.mergeEffComponents();
1597

    
1598
    return mesh;
1599
    }
1600

    
1601
///////////////////////////////////////////////////////////////////////////////////////////////////
1602

    
1603
  MeshBase createTetraMesh()
1604
    {
1605
    MeshBase mesh = createFacesTetra();
1606
    VertexEffect[] effects = createVertexEffectsTetra();
1607
    for( VertexEffect effect : effects ) mesh.apply(effect);
1608

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

    
1617
    mesh.mergeEffComponents();
1618
    mesh.addEmptyTexComponent();
1619
    mesh.addEmptyTexComponent();
1620
    mesh.addEmptyTexComponent();
1621
    mesh.addEmptyTexComponent();
1622

    
1623
    return mesh;
1624
    }
1625

    
1626
///////////////////////////////////////////////////////////////////////////////////////////////////
1627
// DINO
1628

    
1629
  MeshBase createDinoMesh()
1630
    {
1631
    MeshBase mesh = createFacesDino();
1632
    VertexEffect[] effects = createVertexEffectsDino();
1633
    for( VertexEffect effect : effects ) mesh.apply(effect);
1634

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

    
1644
    mesh.mergeEffComponents();
1645

    
1646
    return mesh;
1647
    }
1648

    
1649
///////////////////////////////////////////////////////////////////////////////////////////////////
1650
// Helicopter
1651

    
1652
  MeshBase createHelicopterCornerMesh()
1653
    {
1654
    MeshBase mesh = createFacesHelicopterCorner();
1655
    VertexEffect[] effects = createVertexEffectsHelicopterCorner();
1656
    for( VertexEffect effect : effects ) mesh.apply(effect);
1657

    
1658
    float E = 0.5f;
1659
    Static3D roundingCenter = new Static3D(-E/2,-E/2,-E/2);
1660

    
1661
    Static3D[] verticesType1 = new Static3D[1];
1662
    verticesType1[0] = new Static3D(0.0f,0.0f,0.0f);
1663
    roundCorners(mesh,roundingCenter,verticesType1,0.08f,0.15f);
1664

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

    
1671
    mesh.mergeEffComponents();
1672

    
1673
    return mesh;
1674
    }
1675

    
1676
///////////////////////////////////////////////////////////////////////////////////////////////////
1677

    
1678
  MeshBase createHelicopterFaceMesh()
1679
    {
1680
    MeshBase mesh = createFacesHelicopterFace();
1681
    VertexEffect[] effects = createVertexEffectsHelicopterFace();
1682
    for( VertexEffect effect : effects ) mesh.apply(effect);
1683

    
1684
    float E = 0.5f;
1685
    Static3D roundingCenter = new Static3D(-E/2 + E/3,-E/2 + E/3,-E/2);
1686

    
1687
    Static3D[] verticesType1 = new Static3D[1];
1688
    verticesType1[0] = new Static3D(E/3,E/3,0.0f);
1689
    roundCorners(mesh,roundingCenter,verticesType1,0.06f,0.15f);
1690

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

    
1696
    mesh.mergeEffComponents();
1697
    mesh.addEmptyTexComponent();
1698
    mesh.addEmptyTexComponent();
1699

    
1700
    return mesh;
1701
    }
1702

    
1703
///////////////////////////////////////////////////////////////////////////////////////////////////
1704
// Redi cube
1705

    
1706
  MeshBase createRediEdgeMesh()
1707
    {
1708
    MeshBase mesh = createFacesRediEdge();
1709
    VertexEffect[] effects = createVertexEffectsRediEdge();
1710
    for( VertexEffect effect : effects ) mesh.apply(effect);
1711

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

    
1718
    mesh.mergeEffComponents();
1719

    
1720
    return mesh;
1721
    }
1722

    
1723
///////////////////////////////////////////////////////////////////////////////////////////////////
1724

    
1725
  MeshBase createRediCornerMesh()
1726
    {
1727
    MeshBase mesh = createFacesRediCorner();
1728
    VertexEffect[] effects = createVertexEffectsRediCorner();
1729
    for( VertexEffect effect : effects ) mesh.apply(effect);
1730

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

    
1742
    roundCorners(mesh,center,vertices,0.06f,0.12f);
1743

    
1744
    mesh.mergeEffComponents();
1745

    
1746
    return mesh;
1747
    }
1748

    
1749
///////////////////////////////////////////////////////////////////////////////////////////////////
1750

    
1751
  MeshBase createIvyCornerMesh()
1752
    {
1753
    MeshBase mesh = createFacesIvyCorner();
1754
    VertexEffect[] effects = createVertexEffectsIvyCorner();
1755
    for( VertexEffect effect : effects ) mesh.apply(effect);
1756

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

    
1764
    roundCorners(mesh,center,vertices,0.03f,0.10f);
1765

    
1766
    mesh.mergeEffComponents();
1767

    
1768
    return mesh;
1769
    }
1770

    
1771
///////////////////////////////////////////////////////////////////////////////////////////////////
1772

    
1773
  MeshBase createIvyFaceMesh()
1774
    {
1775
    MeshBase mesh = createFacesIvyFace();
1776

    
1777
    Static3D center = new Static3D(-0.0f,-0.0f,-0.5f);
1778
    Static3D[] vertices = new Static3D[2];
1779
    vertices[0] = new Static3D(-0.5f,+0.5f,+0.0f);
1780
    vertices[1] = new Static3D(+0.5f,-0.5f,+0.0f);
1781

    
1782
    roundCorners(mesh,center,vertices,0.03f,0.10f);
1783

    
1784
    mesh.mergeEffComponents();
1785
    mesh.addEmptyTexComponent();
1786
    mesh.addEmptyTexComponent();
1787
    mesh.addEmptyTexComponent();
1788
    mesh.addEmptyTexComponent();
1789

    
1790
    return mesh;
1791
    }
1792

    
1793
///////////////////////////////////////////////////////////////////////////////////////////////////
1794

    
1795
  MeshBase createRexCornerMesh()
1796
    {
1797
    MeshBase mesh = createFacesRexCorner();
1798
    VertexEffect[] effects = createVertexEffectsRexCorner();
1799
    for( VertexEffect effect : effects ) mesh.apply(effect);
1800

    
1801
    Static3D center = new Static3D(0.0f,0.0f,-0.25f);
1802
    Static3D[] vertices = new Static3D[1];
1803
    vertices[0] = new Static3D(+0.25f,+0.25f,+0.0f);
1804
    roundCorners(mesh,center,vertices,0.03f,0.10f);
1805

    
1806
    mesh.mergeEffComponents();
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

    
1823
    return mesh;
1824
    }
1825

    
1826
///////////////////////////////////////////////////////////////////////////////////////////////////
1827

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

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

    
1840
    mesh.mergeEffComponents();
1841

    
1842
    return mesh;
1843
    }
1844

    
1845
///////////////////////////////////////////////////////////////////////////////////////////////////
1846

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

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

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

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

    
1867
    roundCorners(mesh,center,vertices,0.03f,0.10f);
1868

    
1869
    //mesh.mergeEffComponents();
1870

    
1871
    return mesh;
1872
    }
1873

    
1874
///////////////////////////////////////////////////////////////////////////////////////////////////
1875

    
1876
  MeshBase createMegaminxCornerMesh()
1877
    {
1878
    MeshBase mesh = createFacesMegaminxCorner();
1879
    VertexEffect[] effects = createVertexEffectsMegaminxCorner();
1880
    for( VertexEffect effect : effects ) mesh.apply(effect);
1881

    
1882
    float A = (2*SQ3/3)* SIN54;
1883
    float B = 0.4f;
1884
    float X = SIN_HALFD* SIN54 * COS54;
1885
    float Y = SIN54 * SIN54 - 0.5f;
1886
    float Z = COS_HALFD* SIN54 * COS54;
1887

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

    
1890
    Static3D[] vertices = new Static3D[4];
1891
    vertices[0] = new Static3D( 0.0f, 0.0f, 0.0f);
1892
    vertices[1] = new Static3D( 0.0f,-0.5f, 0.0f);
1893
    vertices[2] = new Static3D(-X   , Y   ,-Z   );
1894
    vertices[3] = new Static3D(+X   , Y   ,-Z   );
1895

    
1896
    roundCorners(mesh,center,vertices,0.04f,0.10f);
1897

    
1898
    //mesh.mergeEffComponents();
1899

    
1900
    return mesh;
1901
    }
1902

    
1903
///////////////////////////////////////////////////////////////////////////////////////////////////
1904

    
1905
  MeshBase createMegaminxEdgeMesh(float width, float height)
1906
    {
1907
    MeshBase mesh = createFacesMegaminxEdge(width,height);
1908
    VertexEffect[] effects = createVertexEffectsMegaminxEdge(width,height);
1909
    for( VertexEffect effect : effects ) mesh.apply(effect);
1910

    
1911
    //mesh.mergeEffComponents();
1912

    
1913
    return mesh;
1914
    }
1915
  }
(1-1/5)