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.objectlib.helpers;
|
21
|
|
22
|
import java.util.ArrayList;
|
23
|
|
24
|
import org.distorted.library.mesh.MeshBase;
|
25
|
import org.distorted.library.type.Static3D;
|
26
|
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
|
27
|
|
28
|
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
|
29
|
|
30
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31
|
|
32
|
public class FactoryBandaged3x3Cubit
|
33
|
{
|
34
|
private static final int WALL_MARKED=0;
|
35
|
private static final int WALL_EMPTY =-1;
|
36
|
|
37
|
private static final int AXIS_XP = 0;
|
38
|
private static final int AXIS_XM = 1;
|
39
|
private static final int AXIS_YP = 2;
|
40
|
private static final int AXIS_YM = 3;
|
41
|
private static final int AXIS_ZP = 4;
|
42
|
private static final int AXIS_ZM = 5;
|
43
|
|
44
|
private static final float[][] VECTOR =
|
45
|
{
|
46
|
{-1.0f,-1.0f,-1.0f},
|
47
|
{-1.0f,-1.0f,+1.0f},
|
48
|
{-1.0f,+1.0f,-1.0f},
|
49
|
{-1.0f,+1.0f,+1.0f},
|
50
|
{+1.0f,-1.0f,-1.0f},
|
51
|
{+1.0f,-1.0f,+1.0f},
|
52
|
{+1.0f,+1.0f,-1.0f},
|
53
|
{+1.0f,+1.0f,+1.0f}
|
54
|
};
|
55
|
|
56
|
private static FactoryBandaged3x3Cubit mThis;
|
57
|
private ArrayList<float[]> mVertexArray;
|
58
|
private ArrayList<float[]> mTmpArray;
|
59
|
private float[][][] mVertices;
|
60
|
private int[][][] mIndices;
|
61
|
private float[][] mMove;
|
62
|
private final int[] mWall;
|
63
|
private final int[][] mPoints;
|
64
|
private final boolean[][][] mTmp;
|
65
|
|
66
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67
|
|
68
|
private FactoryBandaged3x3Cubit()
|
69
|
{
|
70
|
mWall= new int[9];
|
71
|
mPoints = new int[4][4];
|
72
|
mTmp = new boolean[3][3][3];
|
73
|
}
|
74
|
|
75
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76
|
|
77
|
private float[][] getVertices(ArrayList<float[]> list, float[] move, int variant)
|
78
|
{
|
79
|
int numMoves = move.length/3;
|
80
|
mMove[variant][0]=0.0f;
|
81
|
mMove[variant][1]=0.0f;
|
82
|
mMove[variant][2]=0.0f;
|
83
|
|
84
|
for(int m=0; m<numMoves; m++)
|
85
|
{
|
86
|
mMove[variant][0] += move[3*m ];
|
87
|
mMove[variant][1] += move[3*m+1];
|
88
|
mMove[variant][2] += move[3*m+2];
|
89
|
}
|
90
|
|
91
|
mMove[variant][0]/=numMoves;
|
92
|
mMove[variant][1]/=numMoves;
|
93
|
mMove[variant][2]/=numMoves;
|
94
|
|
95
|
int total = 0;
|
96
|
int length = list.size();
|
97
|
float[][] vertices = new float[length][];
|
98
|
|
99
|
for( int i=0; i<length; i++ )
|
100
|
{
|
101
|
vertices[i] = list.get(i);
|
102
|
total += vertices[i].length/3;
|
103
|
}
|
104
|
|
105
|
float[][] verts = new float[total][3];
|
106
|
int pointer = 0;
|
107
|
|
108
|
for(int i=0; i<length; i++)
|
109
|
{
|
110
|
int len = vertices[i].length/3;
|
111
|
|
112
|
for(int j=0; j<len; j++)
|
113
|
{
|
114
|
verts[pointer][0] = vertices[i][3*j ] - mMove[variant][0];
|
115
|
verts[pointer][1] = vertices[i][3*j+1] - mMove[variant][1];
|
116
|
verts[pointer][2] = vertices[i][3*j+2] - mMove[variant][2];
|
117
|
pointer++;
|
118
|
}
|
119
|
}
|
120
|
|
121
|
return verts;
|
122
|
}
|
123
|
|
124
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
125
|
|
126
|
private int[][] getIndices(ArrayList<float[]> list)
|
127
|
{
|
128
|
int indicesSoFar=0;
|
129
|
int length = list.size();
|
130
|
int[][] indices = new int[length][];
|
131
|
|
132
|
for( int i=0; i<length; i++ )
|
133
|
{
|
134
|
float[] f = list.get(i);
|
135
|
int len = f.length/3;
|
136
|
int[] ind = new int[len];
|
137
|
for(int j=0; j<len; j++) ind[j] = (indicesSoFar++);
|
138
|
indices[i] = ind;
|
139
|
}
|
140
|
|
141
|
return indices;
|
142
|
}
|
143
|
|
144
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
145
|
|
146
|
private void markAllVertices(float[] vertex, float[][] vertices, int[][] indices, int pointer, int variant)
|
147
|
{
|
148
|
int lenI = indices.length;
|
149
|
|
150
|
for(int index=0; index<lenI; index++)
|
151
|
{
|
152
|
int len = indices[index].length;
|
153
|
|
154
|
for(int i=0; i<len; i++)
|
155
|
{
|
156
|
if( mIndices[variant][index][i] == -1 )
|
157
|
{
|
158
|
int ind = indices[index][i];
|
159
|
float[] ver = vertices[ind];
|
160
|
|
161
|
if( vertex[0]==ver[0] && vertex[1]==ver[1] && vertex[2]==ver[2] )
|
162
|
{
|
163
|
mIndices[variant][index][i] = pointer;
|
164
|
}
|
165
|
}
|
166
|
}
|
167
|
}
|
168
|
}
|
169
|
|
170
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171
|
// So far the 'vertices/indices' are stored inefficiently, with each vertex stored three times
|
172
|
// (each one normally is a corner of three faces) or even six times. Compress!
|
173
|
// Example of six times: the central vertex here:
|
174
|
//
|
175
|
// { 1.0f, 0.0f, -1.0f,
|
176
|
// 1.0f, -1.0f, -1.0f,
|
177
|
// 1.0f, -1.0f, +0.0f,
|
178
|
// 0.0f, -1.0f, -1.0f },
|
179
|
|
180
|
private void compressVerticesAndIndices(int variant, float[][] vertices, int[][] indices)
|
181
|
{
|
182
|
if( mTmpArray==null ) mTmpArray = new ArrayList<>();
|
183
|
|
184
|
int lenI = indices.length;
|
185
|
int pointer=0;
|
186
|
|
187
|
mIndices[variant] = new int[lenI][];
|
188
|
|
189
|
for(int index=0; index<lenI; index++)
|
190
|
{
|
191
|
int len = indices[index].length;
|
192
|
mIndices[variant][index] = new int[len];
|
193
|
for(int i=0; i<len; i++) mIndices[variant][index][i] = -1;
|
194
|
}
|
195
|
|
196
|
for(int index=0; index<lenI; index++)
|
197
|
{
|
198
|
int len = indices[index].length;
|
199
|
|
200
|
for(int i=0; i<len; i++)
|
201
|
{
|
202
|
if( mIndices[variant][index][i] == -1 )
|
203
|
{
|
204
|
int ind = indices[index][i];
|
205
|
float[] ver = vertices[ind];
|
206
|
mTmpArray.add(ver);
|
207
|
markAllVertices(ver,vertices,indices,pointer,variant);
|
208
|
pointer++;
|
209
|
}
|
210
|
}
|
211
|
}
|
212
|
|
213
|
int len = mTmpArray.size();
|
214
|
mVertices[variant] = new float[len][];
|
215
|
|
216
|
for(int i=0; i<len; i++)
|
217
|
{
|
218
|
mVertices[variant][i] = mTmpArray.remove(0);
|
219
|
}
|
220
|
}
|
221
|
|
222
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
223
|
|
224
|
private boolean cubitExists(float[] pos, float x, float y, float z)
|
225
|
{
|
226
|
int len = pos.length/3;
|
227
|
|
228
|
for(int i=0; i<len; i++)
|
229
|
if( pos[3*i]==x && pos[3*i+1]==y && pos[3*i+2]==z ) return true;
|
230
|
|
231
|
return false;
|
232
|
}
|
233
|
|
234
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
235
|
|
236
|
private void createRight0(ArrayList<float[]> list)
|
237
|
{
|
238
|
mWall[0] = (mTmp[0][2][2] && !mTmp[1][2][2]) ? WALL_MARKED:WALL_EMPTY;
|
239
|
mWall[1] = (mTmp[0][2][1] && !mTmp[1][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
240
|
mWall[2] = (mTmp[0][2][0] && !mTmp[1][2][0]) ? WALL_MARKED:WALL_EMPTY;
|
241
|
mWall[3] = (mTmp[0][1][2] && !mTmp[1][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
242
|
mWall[4] = (mTmp[0][1][1] && !mTmp[1][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
243
|
mWall[5] = (mTmp[0][1][0] && !mTmp[1][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
244
|
mWall[6] = (mTmp[0][0][2] && !mTmp[1][0][2]) ? WALL_MARKED:WALL_EMPTY;
|
245
|
mWall[7] = (mTmp[0][0][1] && !mTmp[1][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
246
|
mWall[8] = (mTmp[0][0][0] && !mTmp[1][0][0]) ? WALL_MARKED:WALL_EMPTY;
|
247
|
|
248
|
createVertices(list,mWall,AXIS_XP,0);
|
249
|
}
|
250
|
|
251
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
252
|
|
253
|
private void createRight1(ArrayList<float[]> list)
|
254
|
{
|
255
|
mWall[0] = (mTmp[1][2][2] && !mTmp[2][2][2]) ? WALL_MARKED:WALL_EMPTY;
|
256
|
mWall[1] = (mTmp[1][2][1] && !mTmp[2][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
257
|
mWall[2] = (mTmp[1][2][0] && !mTmp[2][2][0]) ? WALL_MARKED:WALL_EMPTY;
|
258
|
mWall[3] = (mTmp[1][1][2] && !mTmp[2][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
259
|
mWall[4] = (mTmp[1][1][1] && !mTmp[2][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
260
|
mWall[5] = (mTmp[1][1][0] && !mTmp[2][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
261
|
mWall[6] = (mTmp[1][0][2] && !mTmp[2][0][2]) ? WALL_MARKED:WALL_EMPTY;
|
262
|
mWall[7] = (mTmp[1][0][1] && !mTmp[2][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
263
|
mWall[8] = (mTmp[1][0][0] && !mTmp[2][0][0]) ? WALL_MARKED:WALL_EMPTY;
|
264
|
|
265
|
createVertices(list,mWall,AXIS_XP,1);
|
266
|
}
|
267
|
|
268
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
269
|
|
270
|
private void createRight2(ArrayList<float[]> list)
|
271
|
{
|
272
|
mWall[0] = mTmp[2][2][2] ? WALL_MARKED:WALL_EMPTY;
|
273
|
mWall[1] = mTmp[2][2][1] ? WALL_MARKED:WALL_EMPTY;
|
274
|
mWall[2] = mTmp[2][2][0] ? WALL_MARKED:WALL_EMPTY;
|
275
|
mWall[3] = mTmp[2][1][2] ? WALL_MARKED:WALL_EMPTY;
|
276
|
mWall[4] = mTmp[2][1][1] ? WALL_MARKED:WALL_EMPTY;
|
277
|
mWall[5] = mTmp[2][1][0] ? WALL_MARKED:WALL_EMPTY;
|
278
|
mWall[6] = mTmp[2][0][2] ? WALL_MARKED:WALL_EMPTY;
|
279
|
mWall[7] = mTmp[2][0][1] ? WALL_MARKED:WALL_EMPTY;
|
280
|
mWall[8] = mTmp[2][0][0] ? WALL_MARKED:WALL_EMPTY;
|
281
|
|
282
|
createVertices(list,mWall,AXIS_XP,2);
|
283
|
}
|
284
|
|
285
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
286
|
|
287
|
private void createLeft0(ArrayList<float[]> list)
|
288
|
{
|
289
|
mWall[0] = mTmp[0][2][0] ? WALL_MARKED:WALL_EMPTY;
|
290
|
mWall[1] = mTmp[0][2][1] ? WALL_MARKED:WALL_EMPTY;
|
291
|
mWall[2] = mTmp[0][2][2] ? WALL_MARKED:WALL_EMPTY;
|
292
|
mWall[3] = mTmp[0][1][0] ? WALL_MARKED:WALL_EMPTY;
|
293
|
mWall[4] = mTmp[0][1][1] ? WALL_MARKED:WALL_EMPTY;
|
294
|
mWall[5] = mTmp[0][1][2] ? WALL_MARKED:WALL_EMPTY;
|
295
|
mWall[6] = mTmp[0][0][0] ? WALL_MARKED:WALL_EMPTY;
|
296
|
mWall[7] = mTmp[0][0][1] ? WALL_MARKED:WALL_EMPTY;
|
297
|
mWall[8] = mTmp[0][0][2] ? WALL_MARKED:WALL_EMPTY;
|
298
|
|
299
|
createVertices(list,mWall,AXIS_XM,0);
|
300
|
}
|
301
|
|
302
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
303
|
|
304
|
private void createLeft1(ArrayList<float[]> list)
|
305
|
{
|
306
|
mWall[0] = (!mTmp[0][2][0] && mTmp[1][2][0]) ? WALL_MARKED:WALL_EMPTY;
|
307
|
mWall[1] = (!mTmp[0][2][1] && mTmp[1][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
308
|
mWall[2] = (!mTmp[0][2][2] && mTmp[1][2][2]) ? WALL_MARKED:WALL_EMPTY;
|
309
|
mWall[3] = (!mTmp[0][1][0] && mTmp[1][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
310
|
mWall[4] = (!mTmp[0][1][1] && mTmp[1][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
311
|
mWall[5] = (!mTmp[0][1][2] && mTmp[1][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
312
|
mWall[6] = (!mTmp[0][0][0] && mTmp[1][0][0]) ? WALL_MARKED:WALL_EMPTY;
|
313
|
mWall[7] = (!mTmp[0][0][1] && mTmp[1][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
314
|
mWall[8] = (!mTmp[0][0][2] && mTmp[1][0][2]) ? WALL_MARKED:WALL_EMPTY;
|
315
|
|
316
|
createVertices(list,mWall,AXIS_XM,1);
|
317
|
}
|
318
|
|
319
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
320
|
|
321
|
private void createLeft2(ArrayList<float[]> list)
|
322
|
{
|
323
|
mWall[0] = (!mTmp[1][2][0] && mTmp[2][2][0]) ? WALL_MARKED:WALL_EMPTY;
|
324
|
mWall[1] = (!mTmp[1][2][1] && mTmp[2][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
325
|
mWall[2] = (!mTmp[1][2][2] && mTmp[2][2][2]) ? WALL_MARKED:WALL_EMPTY;
|
326
|
mWall[3] = (!mTmp[1][1][0] && mTmp[2][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
327
|
mWall[4] = (!mTmp[1][1][1] && mTmp[2][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
328
|
mWall[5] = (!mTmp[1][1][2] && mTmp[2][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
329
|
mWall[6] = (!mTmp[1][0][0] && mTmp[2][0][0]) ? WALL_MARKED:WALL_EMPTY;
|
330
|
mWall[7] = (!mTmp[1][0][1] && mTmp[2][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
331
|
mWall[8] = (!mTmp[1][0][2] && mTmp[2][0][2]) ? WALL_MARKED:WALL_EMPTY;
|
332
|
|
333
|
createVertices(list,mWall,AXIS_XM,2);
|
334
|
}
|
335
|
|
336
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
337
|
|
338
|
private void createTop0(ArrayList<float[]> list)
|
339
|
{
|
340
|
mWall[0] = (mTmp[0][0][0] && !mTmp[0][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
341
|
mWall[1] = (mTmp[1][0][0] && !mTmp[1][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
342
|
mWall[2] = (mTmp[2][0][0] && !mTmp[2][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
343
|
mWall[3] = (mTmp[0][0][1] && !mTmp[0][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
344
|
mWall[4] = (mTmp[1][0][1] && !mTmp[1][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
345
|
mWall[5] = (mTmp[2][0][1] && !mTmp[2][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
346
|
mWall[6] = (mTmp[0][0][2] && !mTmp[0][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
347
|
mWall[7] = (mTmp[1][0][2] && !mTmp[1][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
348
|
mWall[8] = (mTmp[2][0][2] && !mTmp[2][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
349
|
|
350
|
createVertices(list,mWall,AXIS_YP,0);
|
351
|
}
|
352
|
|
353
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
354
|
|
355
|
private void createTop1(ArrayList<float[]> list)
|
356
|
{
|
357
|
mWall[0] = (mTmp[0][1][0] && !mTmp[0][2][0]) ? WALL_MARKED:WALL_EMPTY;
|
358
|
mWall[1] = (mTmp[1][1][0] && !mTmp[1][2][0]) ? WALL_MARKED:WALL_EMPTY;
|
359
|
mWall[2] = (mTmp[2][1][0] && !mTmp[2][2][0]) ? WALL_MARKED:WALL_EMPTY;
|
360
|
mWall[3] = (mTmp[0][1][1] && !mTmp[0][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
361
|
mWall[4] = (mTmp[1][1][1] && !mTmp[1][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
362
|
mWall[5] = (mTmp[2][1][1] && !mTmp[2][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
363
|
mWall[6] = (mTmp[0][1][2] && !mTmp[0][2][2]) ? WALL_MARKED:WALL_EMPTY;
|
364
|
mWall[7] = (mTmp[1][1][2] && !mTmp[1][2][2]) ? WALL_MARKED:WALL_EMPTY;
|
365
|
mWall[8] = (mTmp[2][1][2] && !mTmp[2][2][2]) ? WALL_MARKED:WALL_EMPTY;
|
366
|
|
367
|
createVertices(list,mWall,AXIS_YP,1);
|
368
|
}
|
369
|
|
370
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
371
|
|
372
|
private void createTop2(ArrayList<float[]> list)
|
373
|
{
|
374
|
mWall[0] = mTmp[0][2][0] ? WALL_MARKED:WALL_EMPTY;
|
375
|
mWall[1] = mTmp[1][2][0] ? WALL_MARKED:WALL_EMPTY;
|
376
|
mWall[2] = mTmp[2][2][0] ? WALL_MARKED:WALL_EMPTY;
|
377
|
mWall[3] = mTmp[0][2][1] ? WALL_MARKED:WALL_EMPTY;
|
378
|
mWall[4] = mTmp[1][2][1] ? WALL_MARKED:WALL_EMPTY;
|
379
|
mWall[5] = mTmp[2][2][1] ? WALL_MARKED:WALL_EMPTY;
|
380
|
mWall[6] = mTmp[0][2][2] ? WALL_MARKED:WALL_EMPTY;
|
381
|
mWall[7] = mTmp[1][2][2] ? WALL_MARKED:WALL_EMPTY;
|
382
|
mWall[8] = mTmp[2][2][2] ? WALL_MARKED:WALL_EMPTY;
|
383
|
|
384
|
createVertices(list,mWall,AXIS_YP,2);
|
385
|
}
|
386
|
|
387
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
388
|
|
389
|
private void createBottom0(ArrayList<float[]> list)
|
390
|
{
|
391
|
mWall[0] = mTmp[0][0][2] ? WALL_MARKED:WALL_EMPTY;
|
392
|
mWall[1] = mTmp[1][0][2] ? WALL_MARKED:WALL_EMPTY;
|
393
|
mWall[2] = mTmp[2][0][2] ? WALL_MARKED:WALL_EMPTY;
|
394
|
mWall[3] = mTmp[0][0][1] ? WALL_MARKED:WALL_EMPTY;
|
395
|
mWall[4] = mTmp[1][0][1] ? WALL_MARKED:WALL_EMPTY;
|
396
|
mWall[5] = mTmp[2][0][1] ? WALL_MARKED:WALL_EMPTY;
|
397
|
mWall[6] = mTmp[0][0][0] ? WALL_MARKED:WALL_EMPTY;
|
398
|
mWall[7] = mTmp[1][0][0] ? WALL_MARKED:WALL_EMPTY;
|
399
|
mWall[8] = mTmp[2][0][0] ? WALL_MARKED:WALL_EMPTY;
|
400
|
|
401
|
createVertices(list,mWall,AXIS_YM,0);
|
402
|
}
|
403
|
|
404
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
405
|
|
406
|
private void createBottom1(ArrayList<float[]> list)
|
407
|
{
|
408
|
mWall[0] = (mTmp[0][1][2] && !mTmp[0][0][2]) ? WALL_MARKED:WALL_EMPTY;
|
409
|
mWall[1] = (mTmp[1][1][2] && !mTmp[1][0][2]) ? WALL_MARKED:WALL_EMPTY;
|
410
|
mWall[2] = (mTmp[2][1][2] && !mTmp[2][0][2]) ? WALL_MARKED:WALL_EMPTY;
|
411
|
mWall[3] = (mTmp[0][1][1] && !mTmp[0][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
412
|
mWall[4] = (mTmp[1][1][1] && !mTmp[1][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
413
|
mWall[5] = (mTmp[2][1][1] && !mTmp[2][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
414
|
mWall[6] = (mTmp[0][1][0] && !mTmp[0][0][0]) ? WALL_MARKED:WALL_EMPTY;
|
415
|
mWall[7] = (mTmp[1][1][0] && !mTmp[1][0][0]) ? WALL_MARKED:WALL_EMPTY;
|
416
|
mWall[8] = (mTmp[2][1][0] && !mTmp[2][0][0]) ? WALL_MARKED:WALL_EMPTY;
|
417
|
|
418
|
createVertices(list,mWall,AXIS_YM,1);
|
419
|
}
|
420
|
|
421
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
422
|
|
423
|
private void createBottom2(ArrayList<float[]> list)
|
424
|
{
|
425
|
mWall[0] = (mTmp[0][2][2] && !mTmp[0][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
426
|
mWall[1] = (mTmp[1][2][2] && !mTmp[1][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
427
|
mWall[2] = (mTmp[2][2][2] && !mTmp[2][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
428
|
mWall[3] = (mTmp[0][2][1] && !mTmp[0][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
429
|
mWall[4] = (mTmp[1][2][1] && !mTmp[1][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
430
|
mWall[5] = (mTmp[2][2][1] && !mTmp[2][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
431
|
mWall[6] = (mTmp[0][2][0] && !mTmp[0][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
432
|
mWall[7] = (mTmp[1][2][0] && !mTmp[1][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
433
|
mWall[8] = (mTmp[2][2][0] && !mTmp[2][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
434
|
|
435
|
createVertices(list,mWall,AXIS_YM,2);
|
436
|
}
|
437
|
|
438
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
439
|
|
440
|
private void createFront0(ArrayList<float[]> list)
|
441
|
{
|
442
|
mWall[0] = (mTmp[0][2][0] && !mTmp[0][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
443
|
mWall[1] = (mTmp[1][2][0] && !mTmp[1][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
444
|
mWall[2] = (mTmp[2][2][0] && !mTmp[2][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
445
|
mWall[3] = (mTmp[0][1][0] && !mTmp[0][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
446
|
mWall[4] = (mTmp[1][1][0] && !mTmp[1][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
447
|
mWall[5] = (mTmp[2][1][0] && !mTmp[2][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
448
|
mWall[6] = (mTmp[0][0][0] && !mTmp[0][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
449
|
mWall[7] = (mTmp[1][0][0] && !mTmp[1][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
450
|
mWall[8] = (mTmp[2][0][0] && !mTmp[2][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
451
|
|
452
|
createVertices(list,mWall,AXIS_ZP,0);
|
453
|
}
|
454
|
|
455
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
456
|
|
457
|
private void createFront1(ArrayList<float[]> list)
|
458
|
{
|
459
|
mWall[0] = (mTmp[0][2][1] && !mTmp[0][2][2]) ? WALL_MARKED:WALL_EMPTY;
|
460
|
mWall[1] = (mTmp[1][2][1] && !mTmp[1][2][2]) ? WALL_MARKED:WALL_EMPTY;
|
461
|
mWall[2] = (mTmp[2][2][1] && !mTmp[2][2][2]) ? WALL_MARKED:WALL_EMPTY;
|
462
|
mWall[3] = (mTmp[0][1][1] && !mTmp[0][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
463
|
mWall[4] = (mTmp[1][1][1] && !mTmp[1][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
464
|
mWall[5] = (mTmp[2][1][1] && !mTmp[2][1][2]) ? WALL_MARKED:WALL_EMPTY;
|
465
|
mWall[6] = (mTmp[0][0][1] && !mTmp[0][0][2]) ? WALL_MARKED:WALL_EMPTY;
|
466
|
mWall[7] = (mTmp[1][0][1] && !mTmp[1][0][2]) ? WALL_MARKED:WALL_EMPTY;
|
467
|
mWall[8] = (mTmp[2][0][1] && !mTmp[2][0][2]) ? WALL_MARKED:WALL_EMPTY;
|
468
|
|
469
|
createVertices(list,mWall,AXIS_ZP,1);
|
470
|
}
|
471
|
|
472
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
473
|
|
474
|
private void createFront2(ArrayList<float[]> list)
|
475
|
{
|
476
|
mWall[0] = mTmp[0][2][2] ? WALL_MARKED:WALL_EMPTY;
|
477
|
mWall[1] = mTmp[1][2][2] ? WALL_MARKED:WALL_EMPTY;
|
478
|
mWall[2] = mTmp[2][2][2] ? WALL_MARKED:WALL_EMPTY;
|
479
|
mWall[3] = mTmp[0][1][2] ? WALL_MARKED:WALL_EMPTY;
|
480
|
mWall[4] = mTmp[1][1][2] ? WALL_MARKED:WALL_EMPTY;
|
481
|
mWall[5] = mTmp[2][1][2] ? WALL_MARKED:WALL_EMPTY;
|
482
|
mWall[6] = mTmp[0][0][2] ? WALL_MARKED:WALL_EMPTY;
|
483
|
mWall[7] = mTmp[1][0][2] ? WALL_MARKED:WALL_EMPTY;
|
484
|
mWall[8] = mTmp[2][0][2] ? WALL_MARKED:WALL_EMPTY;
|
485
|
|
486
|
createVertices(list,mWall,AXIS_ZP,2);
|
487
|
}
|
488
|
|
489
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
490
|
|
491
|
private void createBack0(ArrayList<float[]> list)
|
492
|
{
|
493
|
mWall[0] = mTmp[2][2][0] ? WALL_MARKED:WALL_EMPTY;
|
494
|
mWall[1] = mTmp[1][2][0] ? WALL_MARKED:WALL_EMPTY;
|
495
|
mWall[2] = mTmp[0][2][0] ? WALL_MARKED:WALL_EMPTY;
|
496
|
mWall[3] = mTmp[2][1][0] ? WALL_MARKED:WALL_EMPTY;
|
497
|
mWall[4] = mTmp[1][1][0] ? WALL_MARKED:WALL_EMPTY;
|
498
|
mWall[5] = mTmp[0][1][0] ? WALL_MARKED:WALL_EMPTY;
|
499
|
mWall[6] = mTmp[2][0][0] ? WALL_MARKED:WALL_EMPTY;
|
500
|
mWall[7] = mTmp[1][0][0] ? WALL_MARKED:WALL_EMPTY;
|
501
|
mWall[8] = mTmp[0][0][0] ? WALL_MARKED:WALL_EMPTY;
|
502
|
|
503
|
createVertices(list,mWall,AXIS_ZM,0);
|
504
|
}
|
505
|
|
506
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
507
|
|
508
|
private void createBack1(ArrayList<float[]> list)
|
509
|
{
|
510
|
mWall[0] = (mTmp[2][2][1] && !mTmp[2][2][0]) ? WALL_MARKED:WALL_EMPTY;
|
511
|
mWall[1] = (mTmp[1][2][1] && !mTmp[1][2][0]) ? WALL_MARKED:WALL_EMPTY;
|
512
|
mWall[2] = (mTmp[0][2][1] && !mTmp[0][2][0]) ? WALL_MARKED:WALL_EMPTY;
|
513
|
mWall[3] = (mTmp[2][1][1] && !mTmp[2][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
514
|
mWall[4] = (mTmp[1][1][1] && !mTmp[1][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
515
|
mWall[5] = (mTmp[0][1][1] && !mTmp[0][1][0]) ? WALL_MARKED:WALL_EMPTY;
|
516
|
mWall[6] = (mTmp[2][0][1] && !mTmp[2][0][0]) ? WALL_MARKED:WALL_EMPTY;
|
517
|
mWall[7] = (mTmp[1][0][1] && !mTmp[1][0][0]) ? WALL_MARKED:WALL_EMPTY;
|
518
|
mWall[8] = (mTmp[0][0][1] && !mTmp[0][0][0]) ? WALL_MARKED:WALL_EMPTY;
|
519
|
|
520
|
createVertices(list,mWall,AXIS_ZM,1);
|
521
|
}
|
522
|
|
523
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
524
|
|
525
|
private void createBack2(ArrayList<float[]> list)
|
526
|
{
|
527
|
mWall[0] = (mTmp[2][2][2] && !mTmp[2][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
528
|
mWall[1] = (mTmp[1][2][2] && !mTmp[1][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
529
|
mWall[2] = (mTmp[0][2][2] && !mTmp[0][2][1]) ? WALL_MARKED:WALL_EMPTY;
|
530
|
mWall[3] = (mTmp[2][1][2] && !mTmp[2][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
531
|
mWall[4] = (mTmp[1][1][2] && !mTmp[1][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
532
|
mWall[5] = (mTmp[0][1][2] && !mTmp[0][1][1]) ? WALL_MARKED:WALL_EMPTY;
|
533
|
mWall[6] = (mTmp[2][0][2] && !mTmp[2][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
534
|
mWall[7] = (mTmp[1][0][2] && !mTmp[1][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
535
|
mWall[8] = (mTmp[0][0][2] && !mTmp[0][0][1]) ? WALL_MARKED:WALL_EMPTY;
|
536
|
|
537
|
createVertices(list,mWall,AXIS_ZM,2);
|
538
|
}
|
539
|
|
540
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
541
|
|
542
|
private void markNeighbours(int[] wall, int index, int section)
|
543
|
{
|
544
|
wall[index] = section;
|
545
|
|
546
|
switch(index)
|
547
|
{
|
548
|
case 0: if( wall[1]==WALL_MARKED ) markNeighbours(wall,1,section);
|
549
|
if( wall[3]==WALL_MARKED ) markNeighbours(wall,3,section);
|
550
|
break;
|
551
|
case 1: if( wall[0]==WALL_MARKED ) markNeighbours(wall,0,section);
|
552
|
if( wall[2]==WALL_MARKED ) markNeighbours(wall,2,section);
|
553
|
if( wall[4]==WALL_MARKED ) markNeighbours(wall,4,section);
|
554
|
break;
|
555
|
case 2: if( wall[1]==WALL_MARKED ) markNeighbours(wall,1,section);
|
556
|
if( wall[5]==WALL_MARKED ) markNeighbours(wall,5,section);
|
557
|
break;
|
558
|
case 3: if( wall[0]==WALL_MARKED ) markNeighbours(wall,0,section);
|
559
|
if( wall[4]==WALL_MARKED ) markNeighbours(wall,4,section);
|
560
|
if( wall[6]==WALL_MARKED ) markNeighbours(wall,6,section);
|
561
|
break;
|
562
|
case 4: if( wall[1]==WALL_MARKED ) markNeighbours(wall,1,section);
|
563
|
if( wall[3]==WALL_MARKED ) markNeighbours(wall,3,section);
|
564
|
if( wall[5]==WALL_MARKED ) markNeighbours(wall,5,section);
|
565
|
if( wall[7]==WALL_MARKED ) markNeighbours(wall,7,section);
|
566
|
break;
|
567
|
case 5: if( wall[2]==WALL_MARKED ) markNeighbours(wall,2,section);
|
568
|
if( wall[4]==WALL_MARKED ) markNeighbours(wall,4,section);
|
569
|
if( wall[8]==WALL_MARKED ) markNeighbours(wall,8,section);
|
570
|
break;
|
571
|
case 6: if( wall[3]==WALL_MARKED ) markNeighbours(wall,3,section);
|
572
|
if( wall[7]==WALL_MARKED ) markNeighbours(wall,7,section);
|
573
|
break;
|
574
|
case 7: if( wall[4]==WALL_MARKED ) markNeighbours(wall,4,section);
|
575
|
if( wall[6]==WALL_MARKED ) markNeighbours(wall,6,section);
|
576
|
if( wall[8]==WALL_MARKED ) markNeighbours(wall,8,section);
|
577
|
break;
|
578
|
case 8: if( wall[5]==WALL_MARKED ) markNeighbours(wall,5,section);
|
579
|
if( wall[7]==WALL_MARKED ) markNeighbours(wall,7,section);
|
580
|
break;
|
581
|
}
|
582
|
}
|
583
|
|
584
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
585
|
|
586
|
private int markSections(int[] wall)
|
587
|
{
|
588
|
int sections = 0;
|
589
|
|
590
|
for(int i=0; i<9; i++)
|
591
|
if( wall[i]==WALL_MARKED )
|
592
|
{
|
593
|
sections++;
|
594
|
markNeighbours(wall,i,sections);
|
595
|
}
|
596
|
|
597
|
return sections;
|
598
|
}
|
599
|
|
600
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
601
|
// return true iff exactly three or exactly one of the four values (x1,x2,x3,x4) are equal to 'value'.
|
602
|
|
603
|
private boolean threeOrOne(int x1, int x2, int x3, int x4, int value)
|
604
|
{
|
605
|
if( x1==value ) return x2==value ? (x3==value)^(x4==value) : (x3==value)^(x4!=value);
|
606
|
else return x2==value ? (x3==value)^(x4!=value) : (x3==value)^(x4==value);
|
607
|
}
|
608
|
|
609
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
610
|
|
611
|
private int buildPoints(int[] wall, int section)
|
612
|
{
|
613
|
mPoints[0][0] = (wall[0]==section ) ? 0 : -1;
|
614
|
mPoints[1][0] = (wall[0]==section)^(wall[1]==section) ? 0 : -1;
|
615
|
mPoints[2][0] = (wall[1]==section)^(wall[2]==section) ? 0 : -1;
|
616
|
mPoints[3][0] = (wall[2]==section ) ? 0 : -1;
|
617
|
mPoints[0][1] = (wall[0]==section)^(wall[3]==section) ? 0 : -1;
|
618
|
mPoints[1][1] = threeOrOne(wall[0],wall[1],wall[3],wall[4],section) ? 0 : -1;
|
619
|
mPoints[2][1] = threeOrOne(wall[1],wall[2],wall[4],wall[5],section) ? 0 : -1;
|
620
|
mPoints[3][1] = (wall[2]==section)^(wall[5]==section) ? 0 : -1;
|
621
|
mPoints[0][2] = (wall[3]==section)^(wall[6]==section) ? 0 : -1;
|
622
|
mPoints[1][2] = threeOrOne(wall[3],wall[4],wall[6],wall[7],section) ? 0 : -1;
|
623
|
mPoints[2][2] = threeOrOne(wall[4],wall[5],wall[7],wall[8],section) ? 0 : -1;
|
624
|
mPoints[3][2] = (wall[5]==section)^(wall[8]==section) ? 0 : -1;
|
625
|
mPoints[0][3] = (wall[6]==section ) ? 0 : -1;
|
626
|
mPoints[1][3] = (wall[6]==section)^(wall[7]==section) ? 0 : -1;
|
627
|
mPoints[2][3] = (wall[7]==section)^(wall[8]==section) ? 0 : -1;
|
628
|
mPoints[3][3] = (wall[8]==section ) ? 0 : -1;
|
629
|
|
630
|
int numPoints=0;
|
631
|
|
632
|
for(int i=0; i<4; i++)
|
633
|
for(int j=0; j<4; j++)
|
634
|
{
|
635
|
if( mPoints[i][j]==0 ) numPoints++;
|
636
|
}
|
637
|
|
638
|
return numPoints;
|
639
|
}
|
640
|
|
641
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
642
|
|
643
|
private boolean isOddVertical(int x, int y)
|
644
|
{
|
645
|
int number = 0;
|
646
|
|
647
|
for(int i=0; i<y; i++)
|
648
|
if( mPoints[x][i]==0 ) number++;
|
649
|
|
650
|
return (number%2)==0;
|
651
|
}
|
652
|
|
653
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
654
|
|
655
|
private boolean isOddHorizontal(int x, int y)
|
656
|
{
|
657
|
int number = 0;
|
658
|
|
659
|
for(int i=0; i<x; i++)
|
660
|
if( mPoints[i][y]==0 ) number++;
|
661
|
|
662
|
return (number%2)==0;
|
663
|
}
|
664
|
|
665
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
666
|
|
667
|
private int moveUp(int x, int y)
|
668
|
{
|
669
|
for(int i=y-1; i>=0; i--)
|
670
|
if( mPoints[x][i]==0 ) return i;
|
671
|
|
672
|
android.util.Log.e("D", "moveUp error!");
|
673
|
return 0;
|
674
|
}
|
675
|
|
676
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
677
|
|
678
|
private int moveDown(int x, int y)
|
679
|
{
|
680
|
for(int i=y+1; i<4; i++)
|
681
|
if( mPoints[x][i]==0 ) return i;
|
682
|
|
683
|
android.util.Log.e("D", "moveDown error!");
|
684
|
return 0;
|
685
|
}
|
686
|
|
687
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
688
|
|
689
|
private int moveLeft(int x, int y)
|
690
|
{
|
691
|
for(int i=x-1; i>=0; i--)
|
692
|
if( mPoints[i][y]==0 ) return i;
|
693
|
|
694
|
android.util.Log.e("D", "moveLeft error!");
|
695
|
return 0;
|
696
|
}
|
697
|
|
698
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
699
|
|
700
|
private int moveRight(int x, int y)
|
701
|
{
|
702
|
for(int i=x+1; i<4; i++)
|
703
|
if( mPoints[i][y]==0 ) return i;
|
704
|
|
705
|
android.util.Log.e("D", "moveRight error!");
|
706
|
return 0;
|
707
|
}
|
708
|
|
709
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
710
|
|
711
|
private float[] buildVertices(int[] wall, int section)
|
712
|
{
|
713
|
int numPoints = buildPoints(wall,section);
|
714
|
int numSections = numPoints/2;
|
715
|
float[] vertices = new float[3*numPoints];
|
716
|
int x=0,y=0,pointer=0;
|
717
|
|
718
|
for(int i=0; i<4; i++)
|
719
|
for(int j=0; j<4; j++)
|
720
|
if( mPoints[i][j]==0 )
|
721
|
{
|
722
|
x = i;
|
723
|
y = j;
|
724
|
i = j = 4;
|
725
|
}
|
726
|
|
727
|
for(int s=0; s<numSections; s++)
|
728
|
{
|
729
|
vertices[6*pointer ] = x-1.5f;
|
730
|
vertices[6*pointer+1] = 1.5f-y;
|
731
|
vertices[6*pointer+2] = 0.0f;
|
732
|
|
733
|
y = isOddVertical(x,y) ? moveDown(x,y) : moveUp(x,y);
|
734
|
|
735
|
vertices[6*pointer+3] = x-1.5f;
|
736
|
vertices[6*pointer+4] = 1.5f-y;
|
737
|
vertices[6*pointer+5] = 0.0f;
|
738
|
|
739
|
x = isOddHorizontal(x,y) ? moveRight(x,y) : moveLeft(x,y);
|
740
|
|
741
|
pointer++;
|
742
|
}
|
743
|
|
744
|
return vertices;
|
745
|
}
|
746
|
|
747
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
748
|
|
749
|
private void rotateAndMoveVertices(float[] vertices, int axis, int layer)
|
750
|
{
|
751
|
int i,len = vertices.length/3;
|
752
|
|
753
|
switch(axis)
|
754
|
{
|
755
|
case AXIS_XP: for(i=0; i<len; i++)
|
756
|
{
|
757
|
vertices[3*i+2] = -vertices[3*i];
|
758
|
vertices[3*i ] = layer-0.5f;
|
759
|
}
|
760
|
break;
|
761
|
case AXIS_XM: for(i=0; i<len; i++)
|
762
|
{
|
763
|
vertices[3*i+2] = vertices[3*i];
|
764
|
vertices[3*i ] = layer-1.5f;
|
765
|
}
|
766
|
break;
|
767
|
case AXIS_YP: for(i=0; i<len; i++)
|
768
|
{
|
769
|
vertices[3*i+2] = -vertices[3*i+1];
|
770
|
vertices[3*i+1] = layer-0.5f;
|
771
|
}
|
772
|
break;
|
773
|
case AXIS_YM: for(i=0; i<len; i++)
|
774
|
{
|
775
|
vertices[3*i+2] = vertices[3*i+1];
|
776
|
vertices[3*i+1] = layer-1.5f;
|
777
|
}
|
778
|
break;
|
779
|
case AXIS_ZP: for(i=0; i<len; i++)
|
780
|
{
|
781
|
vertices[3*i+2] = layer-0.5f;
|
782
|
}
|
783
|
break;
|
784
|
case AXIS_ZM: for(i=0; i<len; i++)
|
785
|
{
|
786
|
vertices[3*i ] = -vertices[3*i];
|
787
|
vertices[3*i+2] = layer-1.5f;
|
788
|
}
|
789
|
break;
|
790
|
}
|
791
|
}
|
792
|
|
793
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
794
|
// 1. assume the 'wall' is in the XY plane
|
795
|
// 2. split the wall into individual connected regions and for each such region:
|
796
|
// a. build the list of vertices (Z=0)
|
797
|
// b. take the axis into consideration and rotate the vertices.
|
798
|
// c. take layer into consideration and move the vertices.
|
799
|
// d. add the resulting vertices to the list.
|
800
|
|
801
|
private void createVertices(ArrayList<float[]> list, int[] wall, int axis, int layer)
|
802
|
{
|
803
|
int sections = markSections(wall);
|
804
|
|
805
|
for(int i=0; i<sections; i++)
|
806
|
{
|
807
|
float[] vertices = buildVertices(wall,i+1);
|
808
|
|
809
|
rotateAndMoveVertices(vertices,axis,layer);
|
810
|
list.add(vertices);
|
811
|
/*
|
812
|
int len = vertices.length/3;
|
813
|
String w="";
|
814
|
|
815
|
for(int j=0; j<len; j++)
|
816
|
{
|
817
|
w += ( "["+vertices[3*j]+" "+vertices[3*j+1]+" "+vertices[3*j+2]+"] ");
|
818
|
}
|
819
|
android.util.Log.e("D", i+" vertices after: "+w);
|
820
|
*/
|
821
|
}
|
822
|
}
|
823
|
|
824
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
825
|
|
826
|
private static boolean vertInFace(float[] vertex, float[] move, Static3D faceAxis, float dist)
|
827
|
{
|
828
|
final float MAX_ERROR = 0.01f;
|
829
|
|
830
|
float x= faceAxis.get0();
|
831
|
float y= faceAxis.get1();
|
832
|
float z= faceAxis.get2();
|
833
|
|
834
|
float a = (vertex[0]+move[0])*x + (vertex[1]+move[1])*y + (vertex[2]+move[2])*z;
|
835
|
float diff = a - dist;
|
836
|
|
837
|
return diff>-MAX_ERROR && diff<MAX_ERROR;
|
838
|
}
|
839
|
|
840
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
841
|
// (vertices,indices) define a cubit face, i.e. a connected subset of the 3x3 grid.
|
842
|
// Return its 'diameter', i.e. max(width,height)
|
843
|
|
844
|
private int faceDiameter(float[][] vertices, int[] indices)
|
845
|
{
|
846
|
float maxX = -1.5f;
|
847
|
float minX = +1.5f;
|
848
|
float maxY = -1.5f;
|
849
|
float minY = +1.5f;
|
850
|
float maxZ = -1.5f;
|
851
|
float minZ = +1.5f;
|
852
|
|
853
|
for (int index : indices)
|
854
|
{
|
855
|
float[] v = vertices[index];
|
856
|
|
857
|
if (v[0] > maxX) maxX = v[0];
|
858
|
if (v[0] < minX) minX = v[0];
|
859
|
if (v[1] > maxY) maxY = v[1];
|
860
|
if (v[1] < minY) minY = v[1];
|
861
|
if (v[2] > maxZ) maxZ = v[2];
|
862
|
if (v[2] < minZ) minZ = v[2];
|
863
|
}
|
864
|
|
865
|
float diffX = maxX-minX;
|
866
|
float diffY = maxY-minY;
|
867
|
float diffZ = maxZ-minZ;
|
868
|
|
869
|
float max = diffX>diffY ? Math.max(diffX,diffZ) : Math.max(diffY,diffZ);
|
870
|
|
871
|
return (int)max;
|
872
|
}
|
873
|
|
874
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
875
|
// return array of:
|
876
|
// 0 if this is an inner face, 1 if its diameter is 1, 2 if diameter is 2, 3 if 3.
|
877
|
|
878
|
private int[] generateBandIndices(float[][] vertices, int[][] indices, float[] move)
|
879
|
{
|
880
|
int numCubitFaces = indices.length;
|
881
|
int[] bandIndices = new int[numCubitFaces];
|
882
|
|
883
|
for(int cubitFace=0; cubitFace<numCubitFaces; cubitFace++)
|
884
|
{
|
885
|
bandIndices[cubitFace] = 0xffffffff;
|
886
|
int numVertices = indices[cubitFace].length;
|
887
|
|
888
|
for(int vertex=0; vertex<numVertices; vertex++)
|
889
|
{
|
890
|
int vertBelongsBitmap = 0x00000000;
|
891
|
|
892
|
for(int face=0; face<6; face++)
|
893
|
{
|
894
|
float[] vert = vertices[ indices[cubitFace][vertex] ];
|
895
|
if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[face],1.5f) )
|
896
|
{
|
897
|
vertBelongsBitmap |= (1<<face);
|
898
|
}
|
899
|
}
|
900
|
|
901
|
bandIndices[cubitFace] &= vertBelongsBitmap;
|
902
|
}
|
903
|
|
904
|
if( bandIndices[cubitFace]!=0 ) // outer face
|
905
|
{
|
906
|
bandIndices[cubitFace] = faceDiameter(vertices, indices[cubitFace]);
|
907
|
}
|
908
|
|
909
|
//android.util.Log.e("D", "cubit face "+cubitFace+" : "+bandIndices[cubitFace]);
|
910
|
}
|
911
|
|
912
|
return bandIndices;
|
913
|
}
|
914
|
|
915
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
916
|
|
917
|
private int[] generateCornerIndices(float[][] vertices, int[][] indices)
|
918
|
{
|
919
|
int len = vertices.length;
|
920
|
int[] cornerIndices = new int[len];
|
921
|
for(int i=0; i<len; i++) cornerIndices[i] = 0;
|
922
|
return cornerIndices;
|
923
|
}
|
924
|
|
925
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
926
|
|
927
|
private int computeVectorFace(float[] prev, float[] curr, float[] next)
|
928
|
{
|
929
|
float ax = prev[0]-curr[0];
|
930
|
float ay = prev[1]-curr[1];
|
931
|
float az = prev[2]-curr[2];
|
932
|
|
933
|
float bx = next[0]-curr[0];
|
934
|
float by = next[1]-curr[1];
|
935
|
float bz = next[2]-curr[2];
|
936
|
|
937
|
float lena = (float)Math.sqrt(ax*ax + ay*ay + az*az);
|
938
|
float lenb = (float)Math.sqrt(bx*bx + by*by + bz*bz);
|
939
|
|
940
|
ax /= lena;
|
941
|
ay /= lena;
|
942
|
az /= lena;
|
943
|
|
944
|
bx /= lenb;
|
945
|
by /= lenb;
|
946
|
bz /= lenb;
|
947
|
|
948
|
float cx = ax + bx + ay*bz-az*by;
|
949
|
float cy = ay + by + az*bx-ax*bz;
|
950
|
float cz = az + bz + ax*by-ay*bx;
|
951
|
|
952
|
return (cx<0 ? 0:4) + (cy<0 ? 0:2) + (cz<0 ? 0:1);
|
953
|
}
|
954
|
|
955
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
956
|
|
957
|
private float[] computeVector(int index, float[][] vertices, int[][] indices, int[] bandIndices)
|
958
|
{
|
959
|
int band=0;
|
960
|
int len = indices.length;
|
961
|
int vector=-1;
|
962
|
|
963
|
for(int i=0; i<len; i++)
|
964
|
{
|
965
|
int len2 = indices[i].length;
|
966
|
|
967
|
for(int j=0; j<len2; j++)
|
968
|
{
|
969
|
if( indices[i][j]==index )
|
970
|
{
|
971
|
int prev = j>0 ? j-1 : len2-1;
|
972
|
int next = j<len2-1 ? j+1 : 0;
|
973
|
|
974
|
int prevIndex = indices[i][prev];
|
975
|
int currIndex = indices[i][j];
|
976
|
int nextIndex = indices[i][next];
|
977
|
|
978
|
int newVector = computeVectorFace(vertices[prevIndex],vertices[currIndex],vertices[nextIndex]);
|
979
|
if( vector!=-1 && vector!=newVector ) return null;
|
980
|
|
981
|
vector = newVector;
|
982
|
band |= bandIndices[i];
|
983
|
}
|
984
|
}
|
985
|
}
|
986
|
|
987
|
return band==0 ? null : VECTOR[vector];
|
988
|
}
|
989
|
|
990
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
991
|
|
992
|
private float[][] generateVectors(float[][] vertices, int[][] indices, int[] bandIndices)
|
993
|
{
|
994
|
int len = vertices.length;
|
995
|
float[][] vectors = new float[len][];
|
996
|
|
997
|
for(int i=0; i<len; i++)
|
998
|
{
|
999
|
vectors[i] = computeVector(i,vertices,indices,bandIndices);
|
1000
|
}
|
1001
|
|
1002
|
return vectors;
|
1003
|
}
|
1004
|
|
1005
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1006
|
|
1007
|
private float[][] generateCenters(float[][] vertices, float[][] vectors)
|
1008
|
{
|
1009
|
int pointer=0,total=0;
|
1010
|
int len = vertices.length;
|
1011
|
|
1012
|
for( float[] vector : vectors )
|
1013
|
{
|
1014
|
if( vector!=null ) total++;
|
1015
|
}
|
1016
|
|
1017
|
float[][] centers = new float[total][3];
|
1018
|
|
1019
|
for( int i=0; i<len; i++ )
|
1020
|
{
|
1021
|
if( vectors[i]!=null )
|
1022
|
{
|
1023
|
centers[pointer][0] = vertices[i][0]+vectors[i][0];
|
1024
|
centers[pointer][1] = vertices[i][1]+vectors[i][1];
|
1025
|
centers[pointer][2] = vertices[i][2]+vectors[i][2];
|
1026
|
pointer++;
|
1027
|
}
|
1028
|
}
|
1029
|
|
1030
|
return centers;
|
1031
|
}
|
1032
|
|
1033
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1034
|
|
1035
|
private int[] generateCenterIndices(float[][] vectors)
|
1036
|
{
|
1037
|
int pointer=0;
|
1038
|
int len = vectors.length;
|
1039
|
int[] centerIndices = new int[len];
|
1040
|
|
1041
|
for(int i=0; i<len; i++)
|
1042
|
{
|
1043
|
if( vectors[i]==null )
|
1044
|
{
|
1045
|
centerIndices[i] = -1;
|
1046
|
}
|
1047
|
else
|
1048
|
{
|
1049
|
centerIndices[i] = pointer;
|
1050
|
pointer++;
|
1051
|
}
|
1052
|
}
|
1053
|
|
1054
|
return centerIndices;
|
1055
|
}
|
1056
|
|
1057
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1058
|
// PUBLIC API
|
1059
|
|
1060
|
public static FactoryBandaged3x3Cubit getInstance()
|
1061
|
{
|
1062
|
if( mThis==null ) mThis = new FactoryBandaged3x3Cubit();
|
1063
|
return mThis;
|
1064
|
}
|
1065
|
|
1066
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1067
|
|
1068
|
public void prepare(int numVariants)
|
1069
|
{
|
1070
|
if( mVertexArray==null ) mVertexArray = new ArrayList<>();
|
1071
|
mVertices= new float[numVariants][][];
|
1072
|
mIndices = new int[numVariants][][];
|
1073
|
mMove = new float[numVariants][3];
|
1074
|
}
|
1075
|
|
1076
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1077
|
|
1078
|
public ObjectShape createIrregularShape(int variant, float[] pos)
|
1079
|
{
|
1080
|
mVertexArray.clear();
|
1081
|
|
1082
|
for(int x=0; x<3; x++)
|
1083
|
for(int y=0; y<3; y++)
|
1084
|
for(int z=0; z<3; z++)
|
1085
|
{
|
1086
|
mTmp[x][y][z] = cubitExists(pos,x-1.0f,y-1.0f,z-1.0f);
|
1087
|
}
|
1088
|
|
1089
|
createRight0(mVertexArray);
|
1090
|
createRight1(mVertexArray);
|
1091
|
createRight2(mVertexArray);
|
1092
|
|
1093
|
createLeft0(mVertexArray);
|
1094
|
createLeft1(mVertexArray);
|
1095
|
createLeft2(mVertexArray);
|
1096
|
|
1097
|
createTop0(mVertexArray);
|
1098
|
createTop1(mVertexArray);
|
1099
|
createTop2(mVertexArray);
|
1100
|
|
1101
|
createBottom0(mVertexArray);
|
1102
|
createBottom1(mVertexArray);
|
1103
|
createBottom2(mVertexArray);
|
1104
|
|
1105
|
createFront0(mVertexArray);
|
1106
|
createFront1(mVertexArray);
|
1107
|
createFront2(mVertexArray);
|
1108
|
|
1109
|
createBack0(mVertexArray);
|
1110
|
createBack1(mVertexArray);
|
1111
|
createBack2(mVertexArray);
|
1112
|
|
1113
|
float[][] verts = getVertices(mVertexArray,pos,variant);
|
1114
|
int[][] inds = getIndices(mVertexArray);
|
1115
|
|
1116
|
compressVerticesAndIndices(variant,verts,inds);
|
1117
|
|
1118
|
return new ObjectShape(mVertices[variant], mIndices[variant]);
|
1119
|
}
|
1120
|
|
1121
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1122
|
|
1123
|
private void debug(float[][] vert, int[][] ind)
|
1124
|
{
|
1125
|
String vv="VERTICES: ";
|
1126
|
for (float[] floats : vert)
|
1127
|
{
|
1128
|
vv += "\n";
|
1129
|
int lenV2 = floats.length / 3;
|
1130
|
|
1131
|
for (int v2 = 0; v2 < lenV2; v2++)
|
1132
|
{
|
1133
|
vv += " {";
|
1134
|
vv += (floats[3 * v2] + " ");
|
1135
|
vv += (floats[3 * v2 + 1] + " ");
|
1136
|
vv += (floats[3 * v2 + 2] + " ");
|
1137
|
vv += "}";
|
1138
|
}
|
1139
|
}
|
1140
|
android.util.Log.e("D", vv);
|
1141
|
|
1142
|
String ii="INDICES: ";
|
1143
|
for (int[] ints : ind)
|
1144
|
{
|
1145
|
ii += "\n";
|
1146
|
int lenI2 = ints.length;
|
1147
|
|
1148
|
for (int i2 = 0; i2 < lenI2; i2++)
|
1149
|
{
|
1150
|
ii += (ints[i2] + " ");
|
1151
|
}
|
1152
|
}
|
1153
|
android.util.Log.e("D", ii);
|
1154
|
}
|
1155
|
|
1156
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1157
|
|
1158
|
public ObjectFaceShape createIrregularFaceShape(int variant)
|
1159
|
{
|
1160
|
float defHeight = 0.048f;
|
1161
|
int angle = 60;
|
1162
|
float R = 0.25f;
|
1163
|
float S = 0.5f;
|
1164
|
int numVertices = 5;
|
1165
|
int extraI = 1;
|
1166
|
int extraV = 1;
|
1167
|
|
1168
|
float[][] corners = { {0.02f,0.12f} };
|
1169
|
float[][] bands = { { 0.001f,angle,R,S,numVertices,extraV,extraI},
|
1170
|
{defHeight/1,angle,R,S,numVertices,extraV,extraI},
|
1171
|
{defHeight/2,angle,R,S,numVertices,extraV,extraI},
|
1172
|
{defHeight/3,angle,R,S,numVertices,extraV,extraI} };
|
1173
|
|
1174
|
int[] bandIndices = generateBandIndices(mVertices[variant], mIndices[variant], mMove[variant]);
|
1175
|
int[] cornerIndices = generateCornerIndices(mVertices[variant], mIndices[variant]);
|
1176
|
float[][] vertexVec = generateVectors(mVertices[variant], mIndices[variant], bandIndices);
|
1177
|
float[][] centers = generateCenters(mVertices[variant], vertexVec);
|
1178
|
int[] centerIndices = generateCenterIndices(vertexVec);
|
1179
|
|
1180
|
return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
|
1181
|
}
|
1182
|
|
1183
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1184
|
|
1185
|
public MeshBase createMesh(float[] pos)
|
1186
|
{
|
1187
|
prepare(1);
|
1188
|
ObjectShape shape = createIrregularShape(0,pos);
|
1189
|
ObjectFaceShape face = createIrregularFaceShape(0);
|
1190
|
int[][] indices = shape.getVertIndices();
|
1191
|
int numComponents = indices.length;
|
1192
|
|
1193
|
FactoryCubit factory = FactoryCubit.getInstance();
|
1194
|
factory.clear();
|
1195
|
factory.createNewFaceTransform(shape,null);
|
1196
|
return factory.createRoundedSolid(shape,face,MESH_NICE,numComponents);
|
1197
|
}
|
1198
|
}
|