Revision 86308421
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java | ||
---|---|---|
97 | 97 |
mScreen = new DistortedScreen(); |
98 | 98 |
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
99 | 99 |
mScale = new Static3D(1,1,1); |
100 |
mObject = new BandagedObject(mScreen); |
|
100 |
mObject = new BandagedObjectCuboid(mScreen);
|
|
101 | 101 |
} |
102 | 102 |
|
103 | 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/bandaged/BandagedObject.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.bandaged; |
11 | 11 |
|
12 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_BLUE; |
|
13 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_GREEN; |
|
14 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_ORANGE; |
|
15 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_RED; |
|
16 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_WHITE; |
|
17 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_YELLOW; |
|
18 |
|
|
19 | 12 |
import org.distorted.library.main.DistortedNode; |
20 | 13 |
import org.distorted.library.main.DistortedScreen; |
21 | 14 |
import org.distorted.library.mesh.MeshBase; |
22 | 15 |
import org.distorted.library.type.Static3D; |
23 | 16 |
import org.distorted.library.type.Static4D; |
24 |
import org.distorted.objectlib.helpers.FactoryBandagedCubit; |
|
25 |
import org.distorted.objectlib.main.InitData; |
|
26 | 17 |
import org.distorted.objectlib.main.TwistyObject; |
27 |
import org.distorted.objectlib.objects.TwistyBandagedCuboid; |
|
28 |
import org.distorted.objectlib.shape.ShapeHexahedron; |
|
29 |
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron; |
|
30 | 18 |
|
31 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
32 | 20 |
|
33 |
public class BandagedObject |
|
21 |
public abstract class BandagedObject
|
|
34 | 22 |
{ |
35 | 23 |
private final DistortedScreen mScreen; |
36 |
private final float[] mPos;
|
|
37 |
private final int[] mSize;
|
|
38 |
private final float mDist2D;
|
|
24 |
private final float[][] mFaceAxis;
|
|
25 |
final int[] mSize; |
|
26 |
final float mDist2D; |
|
39 | 27 |
|
40 |
private BandagedCubit[] mCubits;
|
|
41 |
private int mMax;
|
|
42 |
private int mNumCubits;
|
|
28 |
BandagedCubit[] mCubits; |
|
29 |
int mMax; |
|
30 |
int mNumCubits; |
|
43 | 31 |
|
44 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
45 | 33 |
|
46 | 34 |
BandagedObject(DistortedScreen screen) |
47 | 35 |
{ |
48 | 36 |
mScreen = screen; |
49 |
mPos = new float[3]; |
|
50 | 37 |
mSize = new int[3]; |
51 | 38 |
mDist2D = getDist2D(); |
39 |
|
|
40 |
Static3D[] axis = getFaceAxis(); |
|
41 |
int numAxis = axis.length; |
|
42 |
mFaceAxis = new float[numAxis][]; |
|
43 |
for(int i=0; i<numAxis; i++) mFaceAxis[i] = new float[] { axis[i].get0(), axis[i].get1(), axis[1].get2() }; |
|
52 | 44 |
} |
53 | 45 |
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
abstract float getDist2D(); |
|
49 |
abstract float[] getDist3D(); |
|
50 |
abstract int[] getColors(); |
|
51 |
abstract Static3D[] getFaceAxis(); |
|
52 |
abstract void createCubits(Static4D quatT, Static4D quatA, Static3D scale); |
|
53 |
abstract boolean isAdjacent(float[] pos1, float[] pos2); |
|
54 |
abstract int computeProjectionAngle(); |
|
55 |
abstract boolean tryChangeObject(int x, int y, int z); |
|
56 |
abstract void stretchPoint(int face, float[] output); |
|
57 |
abstract int whichCubitTouched(int face, float pointX, float pointY); |
|
58 |
abstract boolean isInsideFace(int face, float[] p); |
|
59 |
abstract TwistyObject createObject(int mode, float scale ); |
|
60 |
abstract MeshBase createMesh(float[] pos, boolean round); |
|
61 |
|
|
54 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 63 |
|
56 | 64 |
int[] getSize() |
... | ... | |
58 | 66 |
return mSize; |
59 | 67 |
} |
60 | 68 |
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
70 |
|
|
71 |
int computeMapsIndex(float[] faceAx) |
|
72 |
{ |
|
73 |
int min=-1, numAxis = mFaceAxis.length; |
|
74 |
float error = Float.MAX_VALUE; |
|
75 |
float x = faceAx[0]; |
|
76 |
float y = faceAx[1]; |
|
77 |
float z = faceAx[2]; |
|
78 |
|
|
79 |
for(int i=0; i<numAxis; i++) |
|
80 |
{ |
|
81 |
float[] ax = mFaceAxis[i]; |
|
82 |
float dx = x-ax[0]; |
|
83 |
float dy = y-ax[1]; |
|
84 |
float dz = z-ax[2]; |
|
85 |
|
|
86 |
float diff = dx*dx + dy*dy + dz*dz; |
|
87 |
|
|
88 |
if( error>diff ) |
|
89 |
{ |
|
90 |
error = diff; |
|
91 |
min = i; |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
return min; |
|
96 |
} |
|
97 |
|
|
61 | 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | 99 |
|
63 | 100 |
void resetObject(float scale) |
... | ... | |
77 | 114 |
} |
78 | 115 |
} |
79 | 116 |
|
80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
81 |
|
|
82 |
private boolean isAdjacent(float[] pos1, float[] pos2) |
|
83 |
{ |
|
84 |
int len1 = pos1.length/3; |
|
85 |
int len2 = pos2.length/3; |
|
86 |
|
|
87 |
for(int i=0; i<len1; i++) |
|
88 |
for(int j=0; j<len2; j++) |
|
89 |
{ |
|
90 |
float d0 = pos1[3*i ] - pos2[3*j ]; |
|
91 |
float d1 = pos1[3*i+1] - pos2[3*j+1]; |
|
92 |
float d2 = pos1[3*i+2] - pos2[3*j+2]; |
|
93 |
|
|
94 |
if( d0*d0 + d1*d1 + d2*d2 == 1 ) return true; |
|
95 |
} |
|
96 |
|
|
97 |
return false; |
|
98 |
} |
|
99 |
|
|
100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
101 |
|
|
102 |
private int computeNumCubits(int x, int y, int z) |
|
103 |
{ |
|
104 |
return ( x<=1 || y<=1 || z<=1 ) ? x*y*z : x*y*z-(x-2)*(y-2)*(z-2); |
|
105 |
} |
|
106 |
|
|
107 | 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
108 | 118 |
|
109 | 119 |
float getMaxSize() |
... | ... | |
132 | 142 |
return pos; |
133 | 143 |
} |
134 | 144 |
|
135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
136 |
|
|
137 |
TwistyObject createObject(int mode, float size) |
|
138 |
{ |
|
139 |
float[][] pos = getCubitPositions(); |
|
140 |
InitData data = new InitData( mSize,pos); |
|
141 |
return new TwistyBandagedCuboid( TwistyObject.MESH_NICE, mode, ShapeHexahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null ); |
|
142 |
} |
|
143 |
|
|
144 | 145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
145 | 146 |
|
146 | 147 |
void tryConnectingCubits(int index1, int index2, float scale) |
... | ... | |
188 | 189 |
} |
189 | 190 |
} |
190 | 191 |
|
191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
192 |
|
|
193 |
boolean tryChangeObject(int x, int y, int z) |
|
194 |
{ |
|
195 |
if( mSize[0]!=x || mSize[1]!=y || mSize[2]!=z ) |
|
196 |
{ |
|
197 |
mSize[0] = x; |
|
198 |
mSize[1] = y; |
|
199 |
mSize[2] = z; |
|
200 |
mMax = x>y ? Math.max(x,z) : Math.max(y,z); |
|
201 |
mNumCubits = computeNumCubits(x,y,z); |
|
202 |
return true; |
|
203 |
} |
|
204 |
|
|
205 |
return false; |
|
206 |
} |
|
207 |
|
|
208 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
209 |
|
|
210 |
int computeProjectionAngle() |
|
211 |
{ |
|
212 |
float quot1 = mSize[2]/ (float)mSize[0]; |
|
213 |
float quot2 = mSize[2]/ (float)mSize[1]; |
|
214 |
float quot3 = mSize[0]/ (float)mSize[2]; |
|
215 |
float quot4 = mSize[0]/ (float)mSize[1]; |
|
216 |
|
|
217 |
float quot5 = Math.max(quot1,quot2); |
|
218 |
float quot6 = Math.max(quot3,quot4); |
|
219 |
float quot7 = Math.max(quot5,quot6); |
|
220 |
|
|
221 |
if( quot7<=1.0f ) return 120; |
|
222 |
else if( quot7<=1.5f ) return 90; |
|
223 |
else if( quot7<=2.0f ) return 60; |
|
224 |
else return 30; |
|
225 |
} |
|
226 |
|
|
227 | 192 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
228 | 193 |
|
229 | 194 |
void scaleCubits(float scale) |
... | ... | |
245 | 210 |
} |
246 | 211 |
} |
247 | 212 |
|
248 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
249 |
|
|
250 |
float[] getDist3D() |
|
251 |
{ |
|
252 |
float max = getMaxSize(); |
|
253 |
|
|
254 |
float x = 0.5f*(mSize[0]/max); |
|
255 |
float y = 0.5f*(mSize[1]/max); |
|
256 |
float z = 0.5f*(mSize[2]/max); |
|
257 |
|
|
258 |
return new float[] {x,x,y,y,z,z}; |
|
259 |
} |
|
260 |
|
|
261 |
|
|
262 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
263 |
|
|
264 |
float getDist2D() |
|
265 |
{ |
|
266 |
return 0.5f; |
|
267 |
} |
|
268 |
|
|
269 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
270 |
// (x,y,z) == |
|
271 |
// |
|
272 |
// ( 1,0,0) --> 0 |
|
273 |
// (-1,0,0) --> 1 |
|
274 |
// (0, 1,0) --> 2 |
|
275 |
// (0,-1,0) --> 3 |
|
276 |
// (0,0, 1) --> 4 |
|
277 |
// (0,0,-1) --> 5 |
|
278 |
|
|
279 |
int computeMapsIndex(float[] faceAxis) |
|
280 |
{ |
|
281 |
float x = faceAxis[0]; |
|
282 |
float y = faceAxis[1]; |
|
283 |
float z = faceAxis[2]; |
|
284 |
|
|
285 |
int ix = x>0 ? (int)(x+0.5f) : (int)(x-0.5f); |
|
286 |
int iy = y>0 ? (int)(y+0.5f) : (int)(y-0.5f); |
|
287 |
int iz = z>0 ? (int)(z+0.5f) : (int)(z-0.5f); |
|
288 |
|
|
289 |
if( ix== 1 ) return 0; |
|
290 |
if( ix==-1 ) return 1; |
|
291 |
if( iy== 1 ) return 2; |
|
292 |
if( iy==-1 ) return 3; |
|
293 |
if( iz== 1 ) return 4; |
|
294 |
if( iz==-1 ) return 5; |
|
295 |
|
|
296 |
return 0; |
|
297 |
} |
|
298 |
|
|
299 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
300 |
|
|
301 |
MeshBase createMesh(float[] pos, boolean round) |
|
302 |
{ |
|
303 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
304 |
int[] size = getSize(); |
|
305 |
return factory.createMesh(pos,size[0],size[1],size[2],false,round); |
|
306 |
} |
|
307 |
|
|
308 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
309 |
|
|
310 |
int[] getColors() |
|
311 |
{ |
|
312 |
return new int[] |
|
313 |
{ |
|
314 |
COLOR_YELLOW, COLOR_WHITE, |
|
315 |
COLOR_BLUE , COLOR_GREEN, |
|
316 |
COLOR_RED , COLOR_ORANGE |
|
317 |
}; |
|
318 |
} |
|
319 |
|
|
320 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
321 |
|
|
322 |
void createCubits(Static4D quatT, Static4D quatA, Static3D scale) |
|
323 |
{ |
|
324 |
mCubits = new BandagedCubit[mNumCubits]; |
|
325 |
int c=0; |
|
326 |
int sx = mSize[0]; |
|
327 |
int sy = mSize[1]; |
|
328 |
int sz = mSize[2]; |
|
329 |
|
|
330 |
float begX = 0.5f*(1-sx); |
|
331 |
float begY = 0.5f*(1-sy); |
|
332 |
float begZ = 0.5f*(1-sz); |
|
333 |
|
|
334 |
for(int x=0; x<sx; x++) |
|
335 |
for(int y=0; y<sy; y++) |
|
336 |
for(int z=0; z<sz; z++) |
|
337 |
if( x==0 || x==sx-1 || y==0 || y==sy-1 || z==0 || z==sz-1 ) |
|
338 |
{ |
|
339 |
float[] pos = new float[] { begX+x,begY+y,begZ+z }; |
|
340 |
mCubits[c] = new BandagedCubit(this,pos,quatT,quatA,scale,false); |
|
341 |
c++; |
|
342 |
} |
|
343 |
} |
|
344 |
|
|
345 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
346 |
|
|
347 |
Static3D[] getFaceAxis() |
|
348 |
{ |
|
349 |
return TouchControlHexahedron.FACE_AXIS; |
|
350 |
} |
|
351 |
|
|
352 | 213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
353 | 214 |
|
354 | 215 |
void touchCubit(int index) |
... | ... | |
362 | 223 |
{ |
363 | 224 |
if( index>=0 && index<mNumCubits && mCubits[index]!=null ) mCubits[index].setUnmarked(); |
364 | 225 |
} |
365 |
|
|
366 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
367 |
|
|
368 |
void stretchPoint(int face, float[] output) |
|
369 |
{ |
|
370 |
float max = getMaxSize(); |
|
371 |
|
|
372 |
switch(face/2) |
|
373 |
{ |
|
374 |
case 0: output[0] *= (max/mSize[2]); output[1] *= (max/mSize[1]); break; |
|
375 |
case 1: output[0] *= (max/mSize[0]); output[1] *= (max/mSize[2]); break; |
|
376 |
case 2: output[0] *= (max/mSize[0]); output[1] *= (max/mSize[1]); break; |
|
377 |
} |
|
378 |
} |
|
379 |
|
|
380 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
381 |
|
|
382 |
int whichCubitTouched(int face, float pointX, float pointY) |
|
383 |
{ |
|
384 |
float x = mSize[0]; |
|
385 |
float y = mSize[1]; |
|
386 |
float z = mSize[2]; |
|
387 |
|
|
388 |
switch(face) |
|
389 |
{ |
|
390 |
case 0: mPos[0] = (x-1)/2; |
|
391 |
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2; |
|
392 |
mPos[2] = (int)(-z*pointX-z/2)+(z-1)/2; |
|
393 |
break; |
|
394 |
case 1: mPos[0] =-(x-1)/2; |
|
395 |
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2; |
|
396 |
mPos[2] = (int)( z*pointX+z/2)-(z-1)/2; |
|
397 |
break; |
|
398 |
case 2: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2; |
|
399 |
mPos[1] = (y-1)/2; |
|
400 |
mPos[2] = (int)(-z*pointY-z/2)+(z-1)/2; |
|
401 |
break; |
|
402 |
case 3: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2; |
|
403 |
mPos[1] =-(y-1)/2; |
|
404 |
mPos[2] = (int)( z*pointY+z/2)-(z-1)/2; |
|
405 |
break; |
|
406 |
case 4: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2; |
|
407 |
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2; |
|
408 |
mPos[2] = (z-1)/2; |
|
409 |
break; |
|
410 |
case 5: mPos[0] = (int)(-x*pointX-x/2)+(x-1)/2; |
|
411 |
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2; |
|
412 |
mPos[2] =-(z-1)/2; |
|
413 |
break; |
|
414 |
} |
|
415 |
|
|
416 |
for(int c=0; c<mNumCubits; c++) |
|
417 |
if( mCubits[c].isAttached() ) |
|
418 |
{ |
|
419 |
float[] pos = mCubits[c].getPosition(); |
|
420 |
int len = pos.length/3; |
|
421 |
|
|
422 |
for(int p=0; p<len; p++) |
|
423 |
if( pos[3*p]==mPos[0] && pos[3*p+1]==mPos[1] && pos[3*p+2]==mPos[2] ) return c; |
|
424 |
} |
|
425 |
|
|
426 |
android.util.Log.e("D", "whichCubitTouched: IMPOSSIBLE!!"); |
|
427 |
return -1; |
|
428 |
} |
|
429 |
|
|
430 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
431 |
|
|
432 |
boolean isInsideFace(int face, float[] p) |
|
433 |
{ |
|
434 |
return ( p[0]<=mDist2D && p[0]>=-mDist2D && p[1]<=mDist2D && p[1]>=-mDist2D ); |
|
435 |
} |
|
436 | 226 |
} |
src/main/java/org/distorted/bandaged/BandagedObjectCuboid.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.bandaged; |
|
11 |
|
|
12 |
import org.distorted.library.main.DistortedScreen; |
|
13 |
import org.distorted.library.mesh.MeshBase; |
|
14 |
import org.distorted.library.type.Static3D; |
|
15 |
import org.distorted.library.type.Static4D; |
|
16 |
import org.distorted.objectlib.helpers.FactoryBandagedCubit; |
|
17 |
import org.distorted.objectlib.main.InitData; |
|
18 |
import org.distorted.objectlib.main.TwistyObject; |
|
19 |
import org.distorted.objectlib.objects.TwistyBandagedCuboid; |
|
20 |
import org.distorted.objectlib.shape.ShapeHexahedron; |
|
21 |
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron; |
|
22 |
|
|
23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
24 |
|
|
25 |
public class BandagedObjectCuboid extends BandagedObject |
|
26 |
{ |
|
27 |
private final float[] mPos; |
|
28 |
|
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
|
31 |
BandagedObjectCuboid(DistortedScreen screen) |
|
32 |
{ |
|
33 |
super(screen); |
|
34 |
mPos = new float[3]; |
|
35 |
} |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
boolean isAdjacent(float[] pos1, float[] pos2) |
|
40 |
{ |
|
41 |
int len1 = pos1.length/3; |
|
42 |
int len2 = pos2.length/3; |
|
43 |
|
|
44 |
for(int i=0; i<len1; i++) |
|
45 |
for(int j=0; j<len2; j++) |
|
46 |
{ |
|
47 |
float d0 = pos1[3*i ] - pos2[3*j ]; |
|
48 |
float d1 = pos1[3*i+1] - pos2[3*j+1]; |
|
49 |
float d2 = pos1[3*i+2] - pos2[3*j+2]; |
|
50 |
|
|
51 |
if( d0*d0 + d1*d1 + d2*d2 == 1 ) return true; |
|
52 |
} |
|
53 |
|
|
54 |
return false; |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
TwistyObject createObject(int mode, float size) |
|
60 |
{ |
|
61 |
float[][] pos = getCubitPositions(); |
|
62 |
InitData data = new InitData( mSize,pos); |
|
63 |
return new TwistyBandagedCuboid( TwistyObject.MESH_NICE, mode, ShapeHexahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null ); |
|
64 |
} |
|
65 |
|
|
66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
67 |
|
|
68 |
boolean tryChangeObject(int x, int y, int z) |
|
69 |
{ |
|
70 |
if( mSize[0]!=x || mSize[1]!=y || mSize[2]!=z ) |
|
71 |
{ |
|
72 |
mSize[0] = x; |
|
73 |
mSize[1] = y; |
|
74 |
mSize[2] = z; |
|
75 |
mMax = x>y ? Math.max(x,z) : Math.max(y,z); |
|
76 |
mNumCubits = ( x<=1 || y<=1 || z<=1 ) ? x*y*z : x*y*z-(x-2)*(y-2)*(z-2); |
|
77 |
return true; |
|
78 |
} |
|
79 |
|
|
80 |
return false; |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
int computeProjectionAngle() |
|
86 |
{ |
|
87 |
float quot1 = mSize[2]/ (float)mSize[0]; |
|
88 |
float quot2 = mSize[2]/ (float)mSize[1]; |
|
89 |
float quot3 = mSize[0]/ (float)mSize[2]; |
|
90 |
float quot4 = mSize[0]/ (float)mSize[1]; |
|
91 |
|
|
92 |
float quot5 = Math.max(quot1,quot2); |
|
93 |
float quot6 = Math.max(quot3,quot4); |
|
94 |
float quot7 = Math.max(quot5,quot6); |
|
95 |
|
|
96 |
if( quot7<=1.0f ) return 120; |
|
97 |
else if( quot7<=1.5f ) return 90; |
|
98 |
else if( quot7<=2.0f ) return 60; |
|
99 |
else return 30; |
|
100 |
} |
|
101 |
|
|
102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
103 |
|
|
104 |
float[] getDist3D() |
|
105 |
{ |
|
106 |
float max = mMax; |
|
107 |
|
|
108 |
float x = 0.5f*(mSize[0]/max); |
|
109 |
float y = 0.5f*(mSize[1]/max); |
|
110 |
float z = 0.5f*(mSize[2]/max); |
|
111 |
|
|
112 |
return new float[] {x,x,y,y,z,z}; |
|
113 |
} |
|
114 |
|
|
115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
116 |
|
|
117 |
float getDist2D() |
|
118 |
{ |
|
119 |
return 0.5f; |
|
120 |
} |
|
121 |
|
|
122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
|
|
124 |
MeshBase createMesh(float[] pos, boolean round) |
|
125 |
{ |
|
126 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
127 |
int[] size = getSize(); |
|
128 |
return factory.createMesh(pos,size[0],size[1],size[2],false,round); |
|
129 |
} |
|
130 |
|
|
131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
132 |
|
|
133 |
int[] getColors() |
|
134 |
{ |
|
135 |
return ShapeHexahedron.FACE_COLORS; |
|
136 |
} |
|
137 |
|
|
138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
139 |
|
|
140 |
void createCubits(Static4D quatT, Static4D quatA, Static3D scale) |
|
141 |
{ |
|
142 |
mCubits = new BandagedCubit[mNumCubits]; |
|
143 |
int c=0; |
|
144 |
int sx = mSize[0]; |
|
145 |
int sy = mSize[1]; |
|
146 |
int sz = mSize[2]; |
|
147 |
|
|
148 |
float begX = 0.5f*(1-sx); |
|
149 |
float begY = 0.5f*(1-sy); |
|
150 |
float begZ = 0.5f*(1-sz); |
|
151 |
|
|
152 |
for(int x=0; x<sx; x++) |
|
153 |
for(int y=0; y<sy; y++) |
|
154 |
for(int z=0; z<sz; z++) |
|
155 |
if( x==0 || x==sx-1 || y==0 || y==sy-1 || z==0 || z==sz-1 ) |
|
156 |
{ |
|
157 |
float[] pos = new float[] { begX+x,begY+y,begZ+z }; |
|
158 |
mCubits[c] = new BandagedCubit(this,pos,quatT,quatA,scale,false); |
|
159 |
c++; |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
164 |
|
|
165 |
Static3D[] getFaceAxis() |
|
166 |
{ |
|
167 |
return TouchControlHexahedron.FACE_AXIS; |
|
168 |
} |
|
169 |
|
|
170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
171 |
|
|
172 |
void stretchPoint(int face, float[] output) |
|
173 |
{ |
|
174 |
float max = getMaxSize(); |
|
175 |
|
|
176 |
switch(face/2) |
|
177 |
{ |
|
178 |
case 0: output[0] *= (max/mSize[2]); output[1] *= (max/mSize[1]); break; |
|
179 |
case 1: output[0] *= (max/mSize[0]); output[1] *= (max/mSize[2]); break; |
|
180 |
case 2: output[0] *= (max/mSize[0]); output[1] *= (max/mSize[1]); break; |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
185 |
|
|
186 |
int whichCubitTouched(int face, float pointX, float pointY) |
|
187 |
{ |
|
188 |
float x = mSize[0]; |
|
189 |
float y = mSize[1]; |
|
190 |
float z = mSize[2]; |
|
191 |
|
|
192 |
switch(face) |
|
193 |
{ |
|
194 |
case 0: mPos[0] = (x-1)/2; |
|
195 |
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2; |
|
196 |
mPos[2] = (int)(-z*pointX-z/2)+(z-1)/2; |
|
197 |
break; |
|
198 |
case 1: mPos[0] =-(x-1)/2; |
|
199 |
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2; |
|
200 |
mPos[2] = (int)( z*pointX+z/2)-(z-1)/2; |
|
201 |
break; |
|
202 |
case 2: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2; |
|
203 |
mPos[1] = (y-1)/2; |
|
204 |
mPos[2] = (int)(-z*pointY-z/2)+(z-1)/2; |
|
205 |
break; |
|
206 |
case 3: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2; |
|
207 |
mPos[1] =-(y-1)/2; |
|
208 |
mPos[2] = (int)( z*pointY+z/2)-(z-1)/2; |
|
209 |
break; |
|
210 |
case 4: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2; |
|
211 |
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2; |
|
212 |
mPos[2] = (z-1)/2; |
|
213 |
break; |
|
214 |
case 5: mPos[0] = (int)(-x*pointX-x/2)+(x-1)/2; |
|
215 |
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2; |
|
216 |
mPos[2] =-(z-1)/2; |
|
217 |
break; |
|
218 |
} |
|
219 |
|
|
220 |
for(int c=0; c<mNumCubits; c++) |
|
221 |
if( mCubits[c].isAttached() ) |
|
222 |
{ |
|
223 |
float[] pos = mCubits[c].getPosition(); |
|
224 |
int len = pos.length/3; |
|
225 |
|
|
226 |
for(int p=0; p<len; p++) |
|
227 |
if( pos[3*p]==mPos[0] && pos[3*p+1]==mPos[1] && pos[3*p+2]==mPos[2] ) return c; |
|
228 |
} |
|
229 |
|
|
230 |
android.util.Log.e("D", "whichCubitTouched: IMPOSSIBLE!!"); |
|
231 |
return -1; |
|
232 |
} |
|
233 |
|
|
234 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
235 |
|
|
236 |
boolean isInsideFace(int face, float[] p) |
|
237 |
{ |
|
238 |
return ( p[0]<=mDist2D && p[0]>=-mDist2D && p[1]<=mDist2D && p[1]>=-mDist2D ); |
|
239 |
} |
|
240 |
} |
Also available in: Unified diff
Split bandagedObject into abstract part and BandagedCuboid.