Project

General

Profile

« Previous | Next » 

Revision c7c72305

Added by Leszek Koltunski 12 months ago

move almost all methods to the generic 'FactoryBandaged'

View differences:

src/main/java/org/distorted/objectlib/helpers/BandagedElement.java
13 13

  
14 14
public class BandagedElement
15 15
  {
16
  private final float mX, mY, mZ;
17 16
  private final float[][] mCuts;
18 17
  private final int[] mNumCuts;
19 18
  private final float[][] mRotAxis;
20 19
  private final int[] mRotationRow;
20
  private final float[] mPos;
21 21

  
22 22
///////////////////////////////////////////////////////////////////////////////////////////////////
23 23

  
24 24
  BandagedElement(float[] pos, int index, float[][] rotAxis, float[][] cuts)
25 25
    {
26
    mX = pos[index  ];
27
    mY = pos[index+1];
28
    mZ = pos[index+2];
26
    mPos = new float[] { pos[index], pos[index+1], pos[index+2] };
29 27

  
30 28
    int numAxis = rotAxis.length;
31 29
    mRotAxis = rotAxis;
......
45 43
  private int computeRow(int rotAx)
46 44
    {
47 45
    float[] ax = mRotAxis[rotAx];
48
    float casted = mX*ax[0] + mY*ax[1] + mZ*ax[2];
46
    float casted = mPos[0]*ax[0] + mPos[1]*ax[1] + mPos[2]*ax[2];
49 47
    int num = mNumCuts[rotAx];
50 48
    float[] cuts = mCuts[rotAx];
51 49

  
......
61 59
    {
62 60
    return mRotationRow;
63 61
    }
62

  
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

  
65
  float[] getPos()
66
    {
67
    return mPos;
68
    }
64 69
  }
src/main/java/org/distorted/objectlib/helpers/FactoryBandaged.java
38 38
  float[][] mMove;
39 39
  int mNumElements;
40 40
  int mNumFaces;
41
  int mNumAxis;
41 42
  Static3D[] mNormals;
42 43

  
43 44
  int[] mNumLayers;
......
51 52

  
52 53
///////////////////////////////////////////////////////////////////////////////////////////////////
53 54

  
54
  abstract void prepareSubclass(int numVariants, int[] numLayers);
55 55
  abstract float faceDiameter(float[][] vertices, int[][] indices);
56 56
  abstract Static3D[] getNormals();
57 57
  abstract float[] getDist3D();
58 58
  abstract float[][] getBands(boolean iconMode);
59
  abstract void fillUpVertexArray();
60 59
  abstract float[][] getCuts(int[] numLayers);
61 60
  abstract float[][] getRotAxis();
61
  abstract float[] elementVertices(int ax, boolean left, int element);
62 62

  
63 63
///////////////////////////////////////////////////////////////////////////////////////////////////
64 64

  
......
291 291

  
292 292
///////////////////////////////////////////////////////////////////////////////////////////////////
293 293

  
294
  boolean elementExists(int x, int y, int z)
294
  boolean elementDoesntExist(int[] p)
295 295
    {
296
    boolean res;
297

  
296 298
    for(int i=0; i<mNumElements; i++)
297 299
      {
298 300
      int[] row = mElements[i].getRotRow();
299
      if( row[0]==x && row[1]==y && row[2]==z ) return true;
301
      res = true;
302

  
303
      for(int j=0; j<mNumAxis; j++)
304
        if( row[j]!=p[j] )
305
          {
306
          res = false;
307
          break;
308
          }
309

  
310
      if( res ) return false;
300 311
      }
301 312

  
302
    return false;
313
    return true;
303 314
    }
304 315

  
305 316
///////////////////////////////////////////////////////////////////////////////////////////////////
......
407 418
    return vectors;
408 419
    }
409 420

  
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422

  
423
  private boolean elementsFormSection(int e1, int e2, int ax)
424
    {
425
    int[] r1 = mElements[e1].getRotRow();
426
    int[] r2 = mElements[e2].getRotRow();
427

  
428
    if( r1[ax]==r2[ax] )
429
      {
430
      int dist=0;
431

  
432
      for(int i=0; i<mNumAxis; i++)
433
        {
434
        int d=r1[i]-r2[i];
435
        dist+=d*d;
436
        }
437

  
438
      return dist==1;
439
      }
440
    return false;
441
    }
442

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

  
445
  private int computeConnectedSection(int element, int ax, boolean[] walls, int[] output, int index)
446
    {
447
    int found = index;
448

  
449
    for(int e=0; e<mNumElements; e++)
450
      if( walls[e] && elementsFormSection(element,e,ax) )
451
        {
452
        walls[e] = false;
453
        output[found++] = e;
454
        found = computeConnectedSection(e,ax,walls,output,found);
455
        }
456

  
457
    return found;
458
    }
459

  
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

  
462
  private void buildSection(int ax, boolean left, boolean[] walls, ArrayList<float[][]> list, boolean debug)
463
    {
464
    int numElements = 0;
465
    for(int i=0; i<mNumElements; i++)
466
      if( walls[i] ) numElements++;
467

  
468
    boolean showDebug = ( ax==2 && !left && debug );
469

  
470
    if( showDebug )
471
      {
472
      for(int i=0; i<mNumElements; i++)
473
        android.util.Log.e("D",  "element "+i+" walls: "+walls[i]);
474
      }
475

  
476
    int[] tmp = new int[numElements];
477

  
478
    while( numElements>0 )
479
      {
480
      int element  = 0;
481

  
482
      for( ; element<mNumElements; element++)
483
        if( walls[element] )
484
          {
485
          walls[element] = false;
486
          tmp[0] = element;
487
          break;
488
          }
489

  
490
      int found = computeConnectedSection(element,ax,walls,tmp,1);
491

  
492
      float[][] newSection = new float[found][];
493

  
494
      for(int i=0; i<found; i++)
495
        newSection[i] = elementVertices(ax,left,tmp[i]);
496

  
497
      if( showDebug )
498
        {
499
        android.util.Log.e("D",  "numFound="+found);
500

  
501
        for(int i=0; i<found; i++)
502
          {
503
          float[] s = newSection[i];
504
          android.util.Log.e("D", "found: "+i+" first vertex: "+s[0]+" "+s[1]+" "+s[2]);
505
          }
506
        }
507

  
508
      list.add(newSection);
509

  
510
      numElements -= found;
511
      }
512
    }
513

  
514
///////////////////////////////////////////////////////////////////////////////////////////////////
515

  
516
  private void fillUpVertexArray(int length)
517
    {
518
    boolean[][][] walls = new boolean[mNumAxis][2][mNumElements];
519

  
520
    int[] tmp = new int[mNumAxis];
521

  
522
    if( length>3 )
523
      for(int e=0; e<mNumElements; e++)
524
        {
525
        float[] p = mElements[e].getPos();
526
        android.util.Log.e("D", "element "+e+" : "+p[0]+" "+p[1]+" "+p[2]);
527
        }
528

  
529
    for(int e=0; e<mNumElements; e++)
530
      {
531
      int[] row = mElements[e].getRotRow();
532
      for(int t=0; t<mNumAxis; t++) tmp[t]=row[t];
533

  
534
      for(int a=0; a<mNumAxis; a++)
535
        {
536
        if( a>0 ) tmp[a-1]=row[a-1];
537
        tmp[a] = row[a]-1;
538
        walls[a][0][e] = elementDoesntExist(tmp);
539
        tmp[a] = row[a]+1;
540
        walls[a][1][e] = elementDoesntExist(tmp);
541
        }
542
      }
543

  
544
    for(int a=0; a<mNumAxis; a++)
545
      {
546
      buildSection(a, true,  walls[a][0], mVertexArray, length>3 );
547
      buildSection(a, false, walls[a][1], mVertexArray, length>3 );
548
      }
549
    }
550

  
410 551
///////////////////////////////////////////////////////////////////////////////////////////////////
411 552

  
412 553
  private void debug(float[][] vert, int[][] ind)
......
485 626
    mFaceBelongsBitmap= new int[numVariants][];
486 627

  
487 628
    mNumLayers = numLayers;
488
    mNormals = getNormals();
489
    mNumFaces =mNormals.length;
490
    mDist3D = getDist3D();
491
    mCuts = getCuts(numLayers);
492
    mRotAxis = getRotAxis();
493

  
494
    prepareSubclass(numVariants,numLayers);
629
    mNormals   = getNormals();
630
    mNumFaces  = mNormals.length;
631
    mDist3D    = getDist3D();
632
    mCuts      = getCuts(numLayers);
633
    mRotAxis   = getRotAxis();
634
    mNumAxis   = mRotAxis.length;
495 635
    }
496 636

  
497 637
///////////////////////////////////////////////////////////////////////////////////////////////////
......
504 644
    mElements = new BandagedElement[mNumElements];
505 645
    for(int i=0; i<mNumElements; i++) mElements[i] = new BandagedElement(pos, 3*i, mRotAxis, mCuts);
506 646

  
507
    fillUpVertexArray();
647
    fillUpVertexArray(pos.length);
508 648

  
509 649
    computeMove(pos,variant);
510 650
    float[][] verts = getVertices(mVertexArray,variant);
src/main/java/org/distorted/objectlib/helpers/FactoryBandagedCuboid.java
9 9

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

  
12
import java.util.ArrayList;
13

  
14 12
import org.distorted.library.type.Static3D;
15 13
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
16 14

  
......
18 16

  
19 17
public class FactoryBandagedCuboid extends FactoryBandaged
20 18
  {
21
  private static final int WALL_MARKED=0;
22
  private static final int WALL_EMPTY =-1;
23

  
24
  private static final int AXIS_XP = 0;
25
  private static final int AXIS_XM = 1;
26
  private static final int AXIS_YP = 2;
27
  private static final int AXIS_YM = 3;
28
  private static final int AXIS_ZP = 4;
29
  private static final int AXIS_ZM = 5;
30

  
31 19
  private static FactoryBandagedCuboid mThis;
32 20

  
33
  private int mMax;
34
  private int[][] mWall;
35

  
36 21
///////////////////////////////////////////////////////////////////////////////////////////////////
37 22

  
38 23
  private FactoryBandagedCuboid()
......
42 27

  
43 28
///////////////////////////////////////////////////////////////////////////////////////////////////
44 29

  
45
  private void displayWall(String tmp)
46
    {
47
    StringBuilder sb = new StringBuilder();
48

  
49
    for(int i=0; i<mMax; i++)
50
      {
51
      for(int j=0; j<mMax; j++)
52
        {
53
        sb.append(mWall[i][j]);
54
        sb.append(' ');
55
        }
56
      sb.append("  -  ");
57
      }
58

  
59
    android.util.Log.e("D", tmp+" : "+sb);
60
    }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
64
  private void createRight(int x, ArrayList<float[][]> list)
30
  public float[] elementVertices(int ax, boolean left, int element)
65 31
    {
66
    for(int i=0; i<mMax; i++)
67
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
32
    float[] pos = mElements[element].getPos();
33
    float[] ret = new float[12];
68 34

  
69
    for(int i=0; i<mNumElements; i++)
35
    switch(ax)
70 36
      {
71
      int[] row = mElements[i].getRotRow();
72

  
73
      if( row[0]==x )
74
        {
75
        int y = mNumLayers[1]-1-row[1];
76
        int z = mNumLayers[2]-1-row[2];
77
        mWall[z][y] = elementExists(x+1,row[1],row[2]) ? WALL_EMPTY : WALL_MARKED;
78
        }
37
      case 0: if( left )
38
                {
39
                ret[ 0] = pos[0]-0.5f;
40
                ret[ 1] = pos[1]+0.5f;
41
                ret[ 2] = pos[2]-0.5f;
42
                ret[ 3] = pos[0]-0.5f;
43
                ret[ 4] = pos[1]-0.5f;
44
                ret[ 5] = pos[2]-0.5f;
45
                ret[ 6] = pos[0]-0.5f;
46
                ret[ 7] = pos[1]-0.5f;
47
                ret[ 8] = pos[2]+0.5f;
48
                ret[ 9] = pos[0]-0.5f;
49
                ret[10] = pos[1]+0.5f;
50
                ret[11] = pos[2]+0.5f;
51
                }
52
              else
53
                {
54
                ret[ 0] = pos[0]+0.5f;
55
                ret[ 1] = pos[1]+0.5f;
56
                ret[ 2] = pos[2]+0.5f;
57
                ret[ 3] = pos[0]+0.5f;
58
                ret[ 4] = pos[1]-0.5f;
59
                ret[ 5] = pos[2]+0.5f;
60
                ret[ 6] = pos[0]+0.5f;
61
                ret[ 7] = pos[1]-0.5f;
62
                ret[ 8] = pos[2]-0.5f;
63
                ret[ 9] = pos[0]+0.5f;
64
                ret[10] = pos[1]+0.5f;
65
                ret[11] = pos[2]-0.5f;
66
                }
67
              break;
68
      case 1: if( left )
69
                {
70
                ret[ 0] = pos[0]-0.5f;
71
                ret[ 1] = pos[1]-0.5f;
72
                ret[ 2] = pos[2]+0.5f;
73
                ret[ 3] = pos[0]-0.5f;
74
                ret[ 4] = pos[1]-0.5f;
75
                ret[ 5] = pos[2]-0.5f;
76
                ret[ 6] = pos[0]+0.5f;
77
                ret[ 7] = pos[1]-0.5f;
78
                ret[ 8] = pos[2]-0.5f;
79
                ret[ 9] = pos[0]+0.5f;
80
                ret[10] = pos[1]-0.5f;
81
                ret[11] = pos[2]+0.5f;
82
                }
83
              else
84
                {
85
                ret[ 0] = pos[0]-0.5f;
86
                ret[ 1] = pos[1]+0.5f;
87
                ret[ 2] = pos[2]-0.5f;
88
                ret[ 3] = pos[0]-0.5f;
89
                ret[ 4] = pos[1]+0.5f;
90
                ret[ 5] = pos[2]+0.5f;
91
                ret[ 6] = pos[0]+0.5f;
92
                ret[ 7] = pos[1]+0.5f;
93
                ret[ 8] = pos[2]+0.5f;
94
                ret[ 9] = pos[0]+0.5f;
95
                ret[10] = pos[1]+0.5f;
96
                ret[11] = pos[2]-0.5f;
97
                }
98
              break;
99
      case 2: if( left )
100
                {
101
                ret[ 0] = pos[0]+0.5f;
102
                ret[ 1] = pos[1]+0.5f;
103
                ret[ 2] = pos[2]-0.5f;
104
                ret[ 3] = pos[0]+0.5f;
105
                ret[ 4] = pos[1]-0.5f;
106
                ret[ 5] = pos[2]-0.5f;
107
                ret[ 6] = pos[0]-0.5f;
108
                ret[ 7] = pos[1]-0.5f;
109
                ret[ 8] = pos[2]-0.5f;
110
                ret[ 9] = pos[0]-0.5f;
111
                ret[10] = pos[1]+0.5f;
112
                ret[11] = pos[2]-0.5f;
113
                }
114
              else
115
                {
116
                ret[ 0] = pos[0]-0.5f;
117
                ret[ 1] = pos[1]+0.5f;
118
                ret[ 2] = pos[2]+0.5f;
119
                ret[ 3] = pos[0]-0.5f;
120
                ret[ 4] = pos[1]-0.5f;
121
                ret[ 5] = pos[2]+0.5f;
122
                ret[ 6] = pos[0]+0.5f;
123
                ret[ 7] = pos[1]-0.5f;
124
                ret[ 8] = pos[2]+0.5f;
125
                ret[ 9] = pos[0]+0.5f;
126
                ret[10] = pos[1]+0.5f;
127
                ret[11] = pos[2]+0.5f;
128
                }
129
              break;
79 130
      }
80 131

  
81
    createVertices(list,mWall,AXIS_XP,x);
82
    }
83

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

  
86
  private void createLeft(int x, ArrayList<float[][]> list)
87
    {
88
    for(int i=0; i<mMax; i++)
89
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
90

  
91
    for(int i=0; i<mNumElements; i++)
92
      {
93
      int[] row = mElements[i].getRotRow();
94

  
95
      if( row[0]==x )
96
        {
97
        int y = mNumLayers[1]-1-row[1];
98
        int z = row[2];
99
        mWall[z][y] = elementExists(x-1,row[1],row[2]) ? WALL_EMPTY : WALL_MARKED;
100
        }
101
      }
102

  
103
    createVertices(list,mWall,AXIS_XM,x);
104
    }
105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

  
108
  private void createTop(int y, ArrayList<float[][]> list)
109
    {
110
    for(int i=0; i<mMax; i++)
111
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
112

  
113
    for(int i=0; i< mNumElements; i++)
114
      {
115
      int[] row = mElements[i].getRotRow();
116

  
117
      if( row[1]==y )
118
        {
119
        int x = row[0];
120
        int z = row[2];
121
        mWall[x][z] = elementExists(row[0],y+1,row[2]) ? WALL_EMPTY : WALL_MARKED;
122
        }
123
      }
124

  
125
    createVertices(list,mWall,AXIS_YP,y);
126
    }
127

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

  
130
  private void createBottom(int y, ArrayList<float[][]> list)
131
    {
132
    for(int i=0; i<mMax; i++)
133
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
134

  
135
    for(int i=0; i<mNumElements; i++)
136
      {
137
      int[] row = mElements[i].getRotRow();
138

  
139
      if( row[1]==y )
140
        {
141
        int x = row[0];
142
        int z = mNumLayers[2]-1-row[2];
143
        mWall[x][z] = elementExists(row[0],y-1,row[2]) ? WALL_EMPTY : WALL_MARKED;
144
        }
145
      }
146

  
147
    createVertices(list,mWall,AXIS_YM,y);
148
    }
149

  
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

  
152
  private void createFront(int z, ArrayList<float[][]> list)
153
    {
154
    for(int i=0; i<mMax; i++)
155
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
156

  
157
    for(int i=0; i<mNumElements; i++)
158
      {
159
      int[] row = mElements[i].getRotRow();
160

  
161
      if( row[2]==z )
162
        {
163
        int x = row[0];
164
        int y = mNumLayers[1]-1-row[1];
165
        mWall[x][y] = elementExists(row[0],row[1],z+1) ? WALL_EMPTY : WALL_MARKED;
166
        }
167
      }
168

  
169
    createVertices(list,mWall,AXIS_ZP,z);
170
    }
171

  
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

  
174
  private void createBack(int z, ArrayList<float[][]> list)
175
    {
176
    for(int i=0; i<mMax; i++)
177
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
178

  
179
    for(int i=0; i<mNumElements; i++)
180
      {
181
      int[] row = mElements[i].getRotRow();
182

  
183
      if( row[2]==z )
184
        {
185
        int x = mNumLayers[0]-1-row[0];
186
        int y = mNumLayers[1]-1-row[1];
187
        mWall[x][y] = elementExists(row[0],row[1],z-1) ? WALL_EMPTY : WALL_MARKED;
188
        }
189
      }
190

  
191
    createVertices(list,mWall,AXIS_ZM,z);
192
    }
193

  
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

  
196
  private void markNeighbours(int[][] wall, int x, int y, int section)
197
    {
198
    wall[x][y] = section;
199

  
200
    if( x  >   0 && wall[x-1][y]==WALL_MARKED ) markNeighbours(wall,x-1,y,section);
201
    if( x+1<mMax && wall[x+1][y]==WALL_MARKED ) markNeighbours(wall,x+1,y,section);
202
    if( y  >   0 && wall[x][y-1]==WALL_MARKED ) markNeighbours(wall,x,y-1,section);
203
    if( y+1<mMax && wall[x][y+1]==WALL_MARKED ) markNeighbours(wall,x,y+1,section);
204
    }
205

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

  
208
  private int markSections(int[][] wall)
209
    {
210
    int sections = 0;
211

  
212
    for(int x=0; x<mMax; x++)
213
      for(int y=0; y<mMax; y++)
214
        if( wall[x][y]==WALL_MARKED )
215
          {
216
          sections++;
217
          markNeighbours(wall,x,y,sections);
218
          }
219

  
220
    return sections;
221
    }
222

  
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

  
225
  private float[][] buildVertices(int[][] wall, int section, float dx, float dy)
226
    {
227
    int numMarked = howManyMarked(wall,section);
228
    float[][] vertices = new float[numMarked][];
229
    int curr=0;
230

  
231
    for(int x=0; x<mMax; x++)
232
      for(int y=0; y<mMax; y++)
233
        if( wall[x][y]==section )
234
          {
235
          vertices[curr] = new float[12];
236

  
237
          vertices[curr][ 0] = x-dx;
238
          vertices[curr][ 1] = dy-y;
239
          vertices[curr][ 2] = 0.0f;
240

  
241
          vertices[curr][ 3] = x-dx;
242
          vertices[curr][ 4] = dy-y-1;
243
          vertices[curr][ 5] = 0.0f;
244

  
245
          vertices[curr][ 6] = x-dx+1;
246
          vertices[curr][ 7] = dy-y-1;
247
          vertices[curr][ 8] = 0.0f;
248

  
249
          vertices[curr][ 9] = x-dx+1;
250
          vertices[curr][10] = dy-y;
251
          vertices[curr][11] = 0.0f;
252

  
253
          curr++;
254
          }
255

  
256
    return vertices;
257
    }
258

  
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

  
261
  private int howManyMarked(int[][] wall, int section)
262
    {
263
    int numMarked=0;
264

  
265
    for(int x=0; x<mMax; x++)
266
      for(int y=0; y<mMax; y++)
267
        if( wall[x][y]==section ) numMarked++;
268

  
269
    return numMarked;
270
    }
271

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

  
274
  private void rotateAndMoveVertices(float[][] vertices, int axis, int layer)
275
    {
276
    int i,len = vertices.length;
277

  
278
    switch(axis)
279
      {
280
      case AXIS_XP: for(i=0; i<len; i++)
281
                      {
282
                      int l = vertices[i].length/3;
283
                      float x = layer - mNumLayers[0]/2.0f + 1.0f;
284

  
285
                      for(int j=0; j<l; j++)
286
                        {
287
                        vertices[i][3*j+2] = -vertices[i][3*j];
288
                        vertices[i][3*j]   = x;
289
                        }
290
                      }
291
                    break;
292
      case AXIS_XM: for(i=0; i<len; i++)
293
                      {
294
                      int l = vertices[i].length/3;
295
                      float x = layer - mNumLayers[0]/2.0f;
296

  
297
                      for(int j=0; j<l; j++)
298
                        {
299
                        vertices[i][3*j+2] = vertices[i][3*j];
300
                        vertices[i][3*j]   = x;
301
                        }
302
                      }
303
                    break;
304
      case AXIS_YP: for(i=0; i<len; i++)
305
                      {
306
                      int l = vertices[i].length/3;
307
                      float y = layer - mNumLayers[1]/2.0f + 1.0f;
308

  
309
                      for(int j=0; j<l; j++)
310
                        {
311
                        vertices[i][3*j+2] = -vertices[i][3*j+1];
312
                        vertices[i][3*j+1] = y;
313
                        }
314
                      }
315
                    break;
316
      case AXIS_YM: for(i=0; i<len; i++)
317
                      {
318
                      int l = vertices[i].length/3;
319
                      float y = layer - mNumLayers[1]/2.0f;
320

  
321
                      for(int j=0; j<l; j++)
322
                        {
323
                        vertices[i][3*j+2] = vertices[i][3*j+1];
324
                        vertices[i][3*j+1] = y;
325
                        }
326
                      }
327
                    break;
328
      case AXIS_ZP: for(i=0; i<len; i++)
329
                      {
330
                      int l = vertices[i].length/3;
331
                      float z = layer - mNumLayers[2]/2.0f + 1.0f;
332

  
333
                      for(int j=0; j<l; j++)
334
                        {
335
                        vertices[i][3*j+2] = z;
336
                        }
337
                      }
338
                    break;
339
      case AXIS_ZM: for(i=0; i<len; i++)
340
                      {
341
                      int l = vertices[i].length/3;
342
                      float z = layer - mNumLayers[2]/2.0f;
343

  
344
                      for(int j=0; j<l; j++)
345
                        {
346
                        vertices[i][3*j+2] = z;
347
                        vertices[i][3*j]   = -vertices[i][3*j];
348
                        }
349
                      }
350
                    break;
351
      }
352
    }
353

  
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355
// 1. assume the 'wall' is in the XY plane
356
// 2. split the wall into individual connected regions and for each such region:
357
//   a. build the list of vertices (Z=0)
358
//   b. take the axis into consideration and rotate the vertices.
359
//   c. take layer into consideration and move the vertices.
360
//   d. add the resulting vertices to the list.
361

  
362
  private void createVertices(ArrayList<float[][]> list, int[][] wall, int axis, int layer)
363
    {
364
    int sections = markSections(wall);
365

  
366
    float dx = (axis==AXIS_XP || axis==AXIS_XM) ? mNumLayers[2]/2.0f : mNumLayers[0]/2.0f;
367
    float dy = (axis==AXIS_YP || axis==AXIS_YM) ? mNumLayers[2]/2.0f : mNumLayers[1]/2.0f;
368

  
369
    for(int i=0; i<sections; i++)
370
      {
371
      float[][] vertices = buildVertices(wall,i+1,dx,dy);
372
      rotateAndMoveVertices(vertices,axis,layer);
373
      list.add(vertices);
374
      }
132
    return ret;
375 133
    }
376 134

  
377 135
///////////////////////////////////////////////////////////////////////////////////////////////////
......
463 221
    return new float[] {dx,dx,dy,dy,dz,dz};
464 222
    }
465 223

  
466
///////////////////////////////////////////////////////////////////////////////////////////////////
467

  
468
  public void prepareSubclass(int numVariants, int[] numLayers)
469
    {
470
    int x = numLayers[0];
471
    int y = numLayers[1];
472
    int z = numLayers[2];
473

  
474
    mMax = x>y ? Math.max(x,z) : Math.max(y,z);
475
    mWall = new int[mMax][mMax];
476
    }
477

  
478 224
///////////////////////////////////////////////////////////////////////////////////////////////////
479 225

  
480 226
  public float[][] getBands(boolean iconMode)
......
497 243
                           {height/4,angle[4],R,S,numVertA,extraV,extraI},
498 244
                           {height/5,angle[5],R,S,numVertA,extraV,extraI} };
499 245
    }
500

  
501
///////////////////////////////////////////////////////////////////////////////////////////////////
502

  
503
  public void fillUpVertexArray()
504
    {
505
    int numX = mNumLayers[0];
506
    int numY = mNumLayers[1];
507
    int numZ = mNumLayers[2];
508

  
509
    for(int x=0; x<numX; x++) createRight (x,mVertexArray);
510
    for(int x=0; x<numX; x++) createLeft  (x,mVertexArray);
511
    for(int y=0; y<numY; y++) createTop   (y,mVertexArray);
512
    for(int y=0; y<numY; y++) createBottom(y,mVertexArray);
513
    for(int z=0; z<numZ; z++) createFront (z,mVertexArray);
514
    for(int z=0; z<numZ; z++) createBack  (z,mVertexArray);
515
    }
516 246
  }
src/main/java/org/distorted/objectlib/helpers/FactoryBandagedPyraminx.java
28 28

  
29 29
    }
30 30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
// TODO
33

  
34
  public float[] elementVertices(int ax, boolean left, int element)
35
    {
36
    return null;
37
    }
38

  
31 39
///////////////////////////////////////////////////////////////////////////////////////////////////
32 40
// (vertices,indices) define a cubit face. Return its 'diameter', i.e. max distance between vertices.
33 41

  
......
119 127
    return TouchControlTetrahedron.D3D;
120 128
    }
121 129

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

  
124
  public void prepareSubclass(int numVariants, int[] numLayers)
125
    {
126

  
127
    }
128

  
129 130
///////////////////////////////////////////////////////////////////////////////////////////////////
130 131

  
131 132
  public float[][] getBands(boolean iconMode)
......
147 148
            {height/4,angle[4],R,S,numVertA,extraV,extraI},
148 149
            {height/5,angle[5],R,S,numVertA,extraV,extraI} };
149 150
    }
150

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

  
153
  public void fillUpVertexArray()
154
    {
155

  
156
    }
157 151
  }

Also available in: Unified diff