Revision 57ef6378
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objectlib/helpers/FactoryCubit.java | ||
---|---|---|
41 | 41 |
private static final Static1D RADIUS = new Static1D(1); |
42 | 42 |
private static FactoryCubit mThis; |
43 | 43 |
|
44 |
private static final double[] mBuffer = new double[3];
|
|
45 |
private static final double[] mQuat1 = new double[4];
|
|
46 |
private static final double[] mQuat2 = new double[4];
|
|
47 |
private static final double[] mQuat3 = new double[4];
|
|
48 |
private static final double[] mQuat4 = new double[4];
|
|
44 |
private static final float[] mBuffer = new float[3];
|
|
45 |
private static final float[] mQuat1 = new float[4];
|
|
46 |
private static final float[] mQuat2 = new float[4];
|
|
47 |
private static final float[] mQuat3 = new float[4];
|
|
48 |
private static final float[] mQuat4 = new float[4];
|
|
49 | 49 |
|
50 | 50 |
private static class StickerCoords |
51 | 51 |
{ |
52 |
double[] vertices;
|
|
52 |
float[] vertices;
|
|
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
private static class FaceTransform |
56 | 56 |
{ |
57 | 57 |
int sticker; |
58 |
double vx,vy,vz;
|
|
59 |
double scale;
|
|
60 |
double qx,qy,qz,qw;
|
|
58 |
float vx,vy,vz;
|
|
59 |
float scale;
|
|
60 |
float qx,qy,qz,qw;
|
|
61 | 61 |
boolean flip; |
62 | 62 |
} |
63 | 63 |
|
... | ... | |
140 | 140 |
|
141 | 141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
142 | 142 |
|
143 |
private boolean areColinear(double[][] vertices, int index1, int index2, int index3)
|
|
143 |
private boolean areColinear(float[][] vertices, int index1, int index2, int index3)
|
|
144 | 144 |
{ |
145 |
double x1 = vertices[index1][0];
|
|
146 |
double y1 = vertices[index1][1];
|
|
147 |
double z1 = vertices[index1][2];
|
|
148 |
double x2 = vertices[index2][0];
|
|
149 |
double y2 = vertices[index2][1];
|
|
150 |
double z2 = vertices[index2][2];
|
|
151 |
double x3 = vertices[index3][0];
|
|
152 |
double y3 = vertices[index3][1];
|
|
153 |
double z3 = vertices[index3][2];
|
|
145 |
float x1 = vertices[index1][0];
|
|
146 |
float y1 = vertices[index1][1];
|
|
147 |
float z1 = vertices[index1][2];
|
|
148 |
float x2 = vertices[index2][0];
|
|
149 |
float y2 = vertices[index2][1];
|
|
150 |
float z2 = vertices[index2][2];
|
|
151 |
float x3 = vertices[index3][0];
|
|
152 |
float y3 = vertices[index3][1];
|
|
153 |
float z3 = vertices[index3][2];
|
|
154 | 154 |
|
155 |
double v1x = x2-x1;
|
|
156 |
double v1y = y2-y1;
|
|
157 |
double v1z = z2-z1;
|
|
158 |
double v2x = x3-x1;
|
|
159 |
double v2y = y3-y1;
|
|
160 |
double v2z = z3-z1;
|
|
155 |
float v1x = x2-x1;
|
|
156 |
float v1y = y2-y1;
|
|
157 |
float v1z = z2-z1;
|
|
158 |
float v2x = x3-x1;
|
|
159 |
float v2y = y3-y1;
|
|
160 |
float v2z = z3-z1;
|
|
161 | 161 |
|
162 | 162 |
double A = Math.sqrt( (v1x*v1x+v1y*v1y+v1z*v1z) / (v2x*v2x+v2y*v2y+v2z*v2z) ); |
163 | 163 |
|
... | ... | |
166 | 166 |
|
167 | 167 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
168 | 168 |
|
169 |
private void computeNormalVector(double[][] vertices, int index1, int index2, int index3)
|
|
169 |
private void computeNormalVector(float[][] vertices, int index1, int index2, int index3)
|
|
170 | 170 |
{ |
171 |
double x1 = vertices[index1][0];
|
|
172 |
double y1 = vertices[index1][1];
|
|
173 |
double z1 = vertices[index1][2];
|
|
174 |
double x2 = vertices[index2][0];
|
|
175 |
double y2 = vertices[index2][1];
|
|
176 |
double z2 = vertices[index2][2];
|
|
177 |
double x3 = vertices[index3][0];
|
|
178 |
double y3 = vertices[index3][1];
|
|
179 |
double z3 = vertices[index3][2];
|
|
171 |
float x1 = vertices[index1][0];
|
|
172 |
float y1 = vertices[index1][1];
|
|
173 |
float z1 = vertices[index1][2];
|
|
174 |
float x2 = vertices[index2][0];
|
|
175 |
float y2 = vertices[index2][1];
|
|
176 |
float z2 = vertices[index2][2];
|
|
177 |
float x3 = vertices[index3][0];
|
|
178 |
float y3 = vertices[index3][1];
|
|
179 |
float z3 = vertices[index3][2];
|
|
180 | 180 |
|
181 |
double v1x = x2-x1;
|
|
182 |
double v1y = y2-y1;
|
|
183 |
double v1z = z2-z1;
|
|
184 |
double v2x = x3-x1;
|
|
185 |
double v2y = y3-y1;
|
|
186 |
double v2z = z3-z1;
|
|
181 |
float v1x = x2-x1;
|
|
182 |
float v1y = y2-y1;
|
|
183 |
float v1z = z2-z1;
|
|
184 |
float v2x = x3-x1;
|
|
185 |
float v2y = y3-y1;
|
|
186 |
float v2z = z3-z1;
|
|
187 | 187 |
|
188 | 188 |
mBuffer[0] = v1y*v2z - v2y*v1z; |
189 | 189 |
mBuffer[1] = v1z*v2x - v2z*v1x; |
... | ... | |
199 | 199 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
200 | 200 |
// return quat1*quat2 |
201 | 201 |
|
202 |
private static void quatMultiply( double[] quat1, double[] quat2, double[] result )
|
|
202 |
private static void quatMultiply( float[] quat1, float[] quat2, float[] result )
|
|
203 | 203 |
{ |
204 |
double qx = quat1[0];
|
|
205 |
double qy = quat1[1];
|
|
206 |
double qz = quat1[2];
|
|
207 |
double qw = quat1[3];
|
|
204 |
float qx = quat1[0];
|
|
205 |
float qy = quat1[1];
|
|
206 |
float qz = quat1[2];
|
|
207 |
float qw = quat1[3];
|
|
208 | 208 |
|
209 |
double rx = quat2[0];
|
|
210 |
double ry = quat2[1];
|
|
211 |
double rz = quat2[2];
|
|
212 |
double rw = quat2[3];
|
|
209 |
float rx = quat2[0];
|
|
210 |
float ry = quat2[1];
|
|
211 |
float rz = quat2[2];
|
|
212 |
float rw = quat2[3];
|
|
213 | 213 |
|
214 | 214 |
result[0] = rw*qx - rz*qy + ry*qz + rx*qw; |
215 | 215 |
result[1] = rw*qy + rz*qx + ry*qw - rx*qz; |
... | ... | |
219 | 219 |
|
220 | 220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
221 | 221 |
|
222 |
private void fitInSquare(FaceTransform info, double[][] vert3D)
|
|
222 |
private void fitInSquare(FaceTransform info, float[][] vert3D)
|
|
223 | 223 |
{ |
224 |
double minX = Double.MAX_VALUE;
|
|
225 |
double maxX =-Double.MAX_VALUE;
|
|
226 |
double minY = Double.MAX_VALUE;
|
|
227 |
double maxY =-Double.MAX_VALUE;
|
|
224 |
float minX = Float.MAX_VALUE;
|
|
225 |
float maxX =-Float.MAX_VALUE;
|
|
226 |
float minY = Float.MAX_VALUE;
|
|
227 |
float maxY =-Float.MAX_VALUE;
|
|
228 | 228 |
|
229 |
for (double[] vert : vert3D)
|
|
229 |
for (float[] vert : vert3D)
|
|
230 | 230 |
{ |
231 |
double x = vert[0];
|
|
232 |
double y = vert[1];
|
|
231 |
float x = vert[0];
|
|
232 |
float y = vert[1];
|
|
233 | 233 |
|
234 | 234 |
if (x > maxX) maxX = x; |
235 | 235 |
if (x < minX) minX = x; |
... | ... | |
242 | 242 |
minY = minY<0 ? -minY:minY; |
243 | 243 |
maxY = maxY<0 ? -maxY:maxY; |
244 | 244 |
|
245 |
double max1 = Math.max(minX,minY);
|
|
246 |
double max2 = Math.max(maxX,maxY);
|
|
247 |
double max3 = Math.max(max1,max2);
|
|
245 |
float max1 = Math.max(minX,minY);
|
|
246 |
float max2 = Math.max(maxX,maxY);
|
|
247 |
float max3 = Math.max(max1,max2);
|
|
248 | 248 |
|
249 |
info.scale = max3/0.5; |
|
249 |
info.scale = max3/0.5f;
|
|
250 | 250 |
|
251 | 251 |
int len = vert3D.length; |
252 | 252 |
StickerCoords sInfo = new StickerCoords(); |
253 |
sInfo.vertices = new double[2*len];
|
|
253 |
sInfo.vertices = new float[2*len];
|
|
254 | 254 |
|
255 | 255 |
for( int vertex=0; vertex<len; vertex++ ) |
256 | 256 |
{ |
... | ... | |
266 | 266 |
|
267 | 267 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
268 | 268 |
|
269 |
private FaceTransform constructNewTransform(final double[][] vert3D)
|
|
269 |
private FaceTransform constructNewTransform(final float[][] vert3D)
|
|
270 | 270 |
{ |
271 | 271 |
FaceTransform ft = new FaceTransform(); |
272 | 272 |
|
... | ... | |
276 | 276 |
ft.vz = 0.0f; |
277 | 277 |
int len = vert3D.length; |
278 | 278 |
|
279 |
for (double[] vert : vert3D)
|
|
279 |
for (float[] vert : vert3D)
|
|
280 | 280 |
{ |
281 | 281 |
ft.vx += vert[0]; |
282 | 282 |
ft.vy += vert[1]; |
... | ... | |
316 | 316 |
computeNormalVector(vert3D,0,1,foundIndex); |
317 | 317 |
|
318 | 318 |
// rotate so that the normal vector becomes (0,0,1) |
319 |
double axisX, axisY, axisZ;
|
|
319 |
float axisX, axisY, axisZ;
|
|
320 | 320 |
|
321 | 321 |
if( mBuffer[0]!=0.0f || mBuffer[1]!=0.0f ) |
322 | 322 |
{ |
... | ... | |
324 | 324 |
axisY = mBuffer[0]; |
325 | 325 |
axisZ = 0.0f; |
326 | 326 |
|
327 |
double axiLen = axisX*axisX + axisY*axisY;
|
|
328 |
axiLen = Math.sqrt(axiLen); |
|
327 |
float axiLen = axisX*axisX + axisY*axisY;
|
|
328 |
axiLen = (float)Math.sqrt(axiLen);
|
|
329 | 329 |
axisX /= axiLen; |
330 | 330 |
axisY /= axiLen; |
331 | 331 |
axisZ /= axiLen; |
... | ... | |
337 | 337 |
axisZ = 0.0f; |
338 | 338 |
} |
339 | 339 |
|
340 |
double cosTheta = mBuffer[2];
|
|
341 |
double sinTheta = Math.sqrt(1-cosTheta*cosTheta);
|
|
342 |
double sinHalfTheta = computeSinHalf(cosTheta);
|
|
343 |
double cosHalfTheta = computeCosHalf(sinTheta,cosTheta);
|
|
340 |
float cosTheta = mBuffer[2];
|
|
341 |
float sinTheta = (float)Math.sqrt(1-cosTheta*cosTheta);
|
|
342 |
float sinHalfTheta = computeSinHalf(cosTheta);
|
|
343 |
float cosHalfTheta = computeCosHalf(sinTheta,cosTheta);
|
|
344 | 344 |
|
345 | 345 |
mQuat1[0] = axisX*sinHalfTheta; |
346 | 346 |
mQuat1[1] = axisY*sinHalfTheta; |
... | ... | |
351 | 351 |
mQuat2[2] =-axisZ*sinHalfTheta; |
352 | 352 |
mQuat2[3] = cosHalfTheta; |
353 | 353 |
|
354 |
for (double[] vert : vert3D)
|
|
354 |
for (float[] vert : vert3D)
|
|
355 | 355 |
{ |
356 | 356 |
quatMultiply(mQuat1, vert , mQuat3); |
357 | 357 |
quatMultiply(mQuat3, mQuat2, vert ); |
... | ... | |
371 | 371 |
|
372 | 372 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
373 | 373 |
|
374 |
private void rotateAllVertices(double[] result, int len, double[] vertices, double sin, double cos)
|
|
374 |
private void rotateAllVertices(float[] result, int len, float[] vertices, float sin, float cos)
|
|
375 | 375 |
{ |
376 | 376 |
for(int i=0; i<len; i++) |
377 | 377 |
{ |
... | ... | |
382 | 382 |
|
383 | 383 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
384 | 384 |
|
385 |
private double computeScale(double[] v1, double[] v2, int v1i, int v2i)
|
|
385 |
private float computeScale(float[] v1, float[] v2, int v1i, int v2i)
|
|
386 | 386 |
{ |
387 |
double v1x = v1[2*v1i];
|
|
388 |
double v1y = v1[2*v1i+1];
|
|
389 |
double v2x = v2[2*v2i];
|
|
390 |
double v2y = v2[2*v2i+1];
|
|
387 |
float v1x = v1[2*v1i];
|
|
388 |
float v1y = v1[2*v1i+1];
|
|
389 |
float v2x = v2[2*v2i];
|
|
390 |
float v2y = v2[2*v2i+1];
|
|
391 | 391 |
|
392 |
double lenSq1 = v1x*v1x + v1y*v1y;
|
|
393 |
double lenSq2 = v2x*v2x + v2y*v2y;
|
|
392 |
float lenSq1 = v1x*v1x + v1y*v1y;
|
|
393 |
float lenSq2 = v2x*v2x + v2y*v2y;
|
|
394 | 394 |
|
395 |
return Math.sqrt(lenSq2/lenSq1); |
|
395 |
return (float)Math.sqrt(lenSq2/lenSq1);
|
|
396 | 396 |
} |
397 | 397 |
|
398 | 398 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
399 | 399 |
// valid for 0<angle<2*PI |
400 | 400 |
|
401 |
private double computeSinHalf(double cos)
|
|
401 |
private float computeSinHalf(float cos)
|
|
402 | 402 |
{ |
403 |
return Math.sqrt((1-cos)/2); |
|
403 |
return (float)Math.sqrt((1-cos)/2);
|
|
404 | 404 |
} |
405 | 405 |
|
406 | 406 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
407 | 407 |
// valid for 0<angle<2*PI |
408 | 408 |
|
409 |
private double computeCosHalf(double sin, double cos)
|
|
409 |
private float computeCosHalf(float sin, float cos)
|
|
410 | 410 |
{ |
411 |
double cosHalf = Math.sqrt((1+cos)/2);
|
|
411 |
float cosHalf = (float)Math.sqrt((1+cos)/2);
|
|
412 | 412 |
return sin<0 ? -cosHalf : cosHalf; |
413 | 413 |
} |
414 | 414 |
|
... | ... | |
425 | 425 |
|
426 | 426 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
427 | 427 |
|
428 |
private boolean isScaledVersionOf(double[] newVert, double[] oldVert, int len, int vertex, boolean inverted)
|
|
428 |
private boolean isScaledVersionOf(float[] newVert, float[] oldVert, int len, int vertex, boolean inverted)
|
|
429 | 429 |
{ |
430 | 430 |
int newZeroIndex = computeRotatedIndex(0,len,vertex,inverted); |
431 |
double EPSILON = 0.001;
|
|
432 |
double scale = computeScale(newVert,oldVert,newZeroIndex,0);
|
|
431 |
float EPSILON = 0.001f;
|
|
432 |
float scale = computeScale(newVert,oldVert,newZeroIndex,0);
|
|
433 | 433 |
|
434 | 434 |
for(int i=1; i<len; i++) |
435 | 435 |
{ |
436 | 436 |
int index = computeRotatedIndex(i,len,vertex,inverted); |
437 | 437 |
|
438 |
double horz = oldVert[2*i ] - scale*newVert[2*index ];
|
|
439 |
double vert = oldVert[2*i+1] - scale*newVert[2*index+1];
|
|
438 |
float horz = oldVert[2*i ] - scale*newVert[2*index ];
|
|
439 |
float vert = oldVert[2*i+1] - scale*newVert[2*index+1];
|
|
440 | 440 |
|
441 | 441 |
if( horz>EPSILON || horz<-EPSILON || vert>EPSILON || vert<-EPSILON ) return false; |
442 | 442 |
} |
... | ... | |
446 | 446 |
|
447 | 447 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
448 | 448 |
|
449 |
private void mirrorAllVertices(double[] output, int len, double[] input)
|
|
449 |
private void mirrorAllVertices(float[] output, int len, float[] input)
|
|
450 | 450 |
{ |
451 | 451 |
for(int vertex=0; vertex<len; vertex++) |
452 | 452 |
{ |
... | ... | |
457 | 457 |
|
458 | 458 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
459 | 459 |
|
460 |
private void correctInfo(FaceTransform info, double scale, double sin, double cos, int oldSticker, boolean flip)
|
|
460 |
private void correctInfo(FaceTransform info, float scale, float sin, float cos, int oldSticker, boolean flip)
|
|
461 | 461 |
{ |
462 | 462 |
mStickerCoords.remove(info.sticker); |
463 | 463 |
|
... | ... | |
470 | 470 |
mQuat1[2] = info.qz; |
471 | 471 |
mQuat1[3] = info.qw; |
472 | 472 |
|
473 |
double sinHalf = computeSinHalf(cos);
|
|
474 |
double cosHalf = computeCosHalf(sin,cos);
|
|
473 |
float sinHalf = computeSinHalf(cos);
|
|
474 |
float cosHalf = computeCosHalf(sin,cos);
|
|
475 | 475 |
|
476 | 476 |
if( flip ) |
477 | 477 |
{ |
... | ... | |
480 | 480 |
mQuat3[2] = sinHalf; |
481 | 481 |
mQuat3[3] = cosHalf; |
482 | 482 |
|
483 |
mQuat4[0] = 1.0; |
|
484 |
mQuat4[1] = 0.0; |
|
485 |
mQuat4[2] = 0.0; |
|
486 |
mQuat4[3] = 0.0; |
|
483 |
mQuat4[0] = 1.0f;
|
|
484 |
mQuat4[1] = 0.0f;
|
|
485 |
mQuat4[2] = 0.0f;
|
|
486 |
mQuat4[3] = 0.0f;
|
|
487 | 487 |
|
488 | 488 |
quatMultiply( mQuat3, mQuat4, mQuat2 ); |
489 | 489 |
} |
... | ... | |
520 | 520 |
|
521 | 521 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
522 | 522 |
|
523 |
private boolean foundVertex(FaceTransform info, double[] buffer, int len, double[] newVert,
|
|
524 |
double[] oldVert, double lenFirstOld, int oldSticker, boolean inverted)
|
|
523 |
private boolean foundVertex(FaceTransform info, float[] buffer, int len, float[] newVert,
|
|
524 |
float[] oldVert, float lenFirstOld, int oldSticker, boolean inverted)
|
|
525 | 525 |
{ |
526 | 526 |
for(int vertex=0; vertex<len; vertex++) |
527 | 527 |
{ |
528 |
double newX = newVert[2*vertex ];
|
|
529 |
double newY = newVert[2*vertex+1];
|
|
530 |
double lenIthNew = Math.sqrt(newX*newX + newY*newY);
|
|
531 |
double cos = QuatHelper.computeCos( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
|
|
532 |
double sin = QuatHelper.computeSin( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
|
|
528 |
float newX = newVert[2*vertex ];
|
|
529 |
float newY = newVert[2*vertex+1];
|
|
530 |
float lenIthNew = (float)Math.sqrt(newX*newX + newY*newY);
|
|
531 |
float cos = (float)QuatHelper.computeCos( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
|
|
532 |
float sin = (float)QuatHelper.computeSin( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
|
|
533 | 533 |
|
534 | 534 |
rotateAllVertices(buffer,len,newVert,sin,cos); |
535 | 535 |
|
536 | 536 |
if( isScaledVersionOf(buffer,oldVert,len,vertex,inverted) ) |
537 | 537 |
{ |
538 | 538 |
int newZeroIndex = computeRotatedIndex(0,len,vertex,inverted); |
539 |
double scale = computeScale(oldVert,newVert,0,newZeroIndex);
|
|
539 |
float scale = computeScale(oldVert,newVert,0,newZeroIndex);
|
|
540 | 540 |
correctInfo(info,scale,sin,cos,oldSticker,inverted); |
541 | 541 |
return true; |
542 | 542 |
} |
... | ... | |
551 | 551 |
{ |
552 | 552 |
StickerCoords sNewInfo = mStickerCoords.get(newInfo.sticker); |
553 | 553 |
StickerCoords sOldInfo = mStickerCoords.get(oldInfo.sticker); |
554 |
double[] newVert = sNewInfo.vertices;
|
|
555 |
double[] oldVert = sOldInfo.vertices;
|
|
554 |
float[] newVert = sNewInfo.vertices;
|
|
555 |
float[] oldVert = sOldInfo.vertices;
|
|
556 | 556 |
int oldLen = oldVert.length; |
557 | 557 |
int newLen = newVert.length; |
558 | 558 |
|
559 | 559 |
if( oldLen == newLen ) |
560 | 560 |
{ |
561 | 561 |
int oldSticker = oldInfo.sticker; |
562 |
double[] buffer1 = new double[oldLen];
|
|
563 |
double lenFirstOld = Math.sqrt(oldVert[0]*oldVert[0] + oldVert[1]*oldVert[1]);
|
|
562 |
float[] buffer1 = new float[oldLen];
|
|
563 |
float lenFirstOld = (float)Math.sqrt(oldVert[0]*oldVert[0] + oldVert[1]*oldVert[1]);
|
|
564 | 564 |
if( foundVertex(newInfo, buffer1, oldLen/2, newVert, oldVert, lenFirstOld, oldSticker, false) ) return true; |
565 |
double[] buffer2 = new double[oldLen];
|
|
565 |
float[] buffer2 = new float[oldLen];
|
|
566 | 566 |
mirrorAllVertices(buffer2, newLen/2, newVert); |
567 | 567 |
if( foundVertex(newInfo, buffer1, oldLen/2, buffer2, oldVert, lenFirstOld, oldSticker, true ) ) return true; |
568 | 568 |
} |
... | ... | |
572 | 572 |
|
573 | 573 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
574 | 574 |
|
575 |
private double[][] constructVert(double[][] vertices, int[] index)
|
|
575 |
private float[][] constructVert(float[][] vertices, int[] index)
|
|
576 | 576 |
{ |
577 | 577 |
int len = index.length; |
578 |
double[][] ret = new double[len][4];
|
|
578 |
float[][] ret = new float[len][4];
|
|
579 | 579 |
|
580 | 580 |
for(int i=0; i<len; i++) |
581 | 581 |
{ |
... | ... | |
590 | 590 |
|
591 | 591 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
592 | 592 |
|
593 |
private void prepareAndRoundCorners(MeshBase mesh, double[][] vertices,
|
|
593 |
private void prepareAndRoundCorners(MeshBase mesh, float[][] vertices,
|
|
594 | 594 |
float[][] corners, int[] cornerIndexes, |
595 | 595 |
float[][] centers, int[] centerIndexes ) |
596 | 596 |
{ |
... | ... | |
773 | 773 |
|
774 | 774 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
775 | 775 |
|
776 |
public void createNewFaceTransform( final double[][] vertices, final int[][] indexes)
|
|
776 |
public void createNewFaceTransform( final float[][] vertices, final int[][] indexes)
|
|
777 | 777 |
{ |
778 | 778 |
FaceTransform ft; |
779 | 779 |
int numNew = mNewFaceTransf.size(); |
... | ... | |
791 | 791 |
{ |
792 | 792 |
boolean collapsed = false; |
793 | 793 |
|
794 |
double[][] vert = constructVert(vertices, indexes[face]);
|
|
794 |
float[][] vert = constructVert(vertices, indexes[face]);
|
|
795 | 795 |
FaceTransform newT = constructNewTransform(vert); |
796 | 796 |
|
797 | 797 |
for (int old=0; !collapsed && old<numOld; old++) |
... | ... | |
815 | 815 |
|
816 | 816 |
public void createNewFaceTransform(final ObjectShape shape) |
817 | 817 |
{ |
818 |
double[][] vertices = shape.getVertices();
|
|
818 |
float[][] vertices = shape.getVertices();
|
|
819 | 819 |
int[][] indices = shape.getVertIndices(); |
820 | 820 |
createNewFaceTransform(vertices,indices); |
821 | 821 |
} |
822 | 822 |
|
823 | 823 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
824 | 824 |
|
825 |
private void computeConvexityCenter(double[] out, float[] in, FaceTransform ft)
|
|
825 |
private void computeConvexityCenter(float[] out, float[] in, FaceTransform ft)
|
|
826 | 826 |
{ |
827 | 827 |
if( in==null ) |
828 | 828 |
{ |
... | ... | |
858 | 858 |
|
859 | 859 |
public MeshBase createRoundedSolid(final ObjectShape shape) |
860 | 860 |
{ |
861 |
double[][] vertices = shape.getVertices();
|
|
861 |
float[][] vertices = shape.getVertices();
|
|
862 | 862 |
int[][] vertIndexes = shape.getVertIndices(); |
863 | 863 |
float[][] bands = shape.getBands(); |
864 | 864 |
int[] bandIndexes = shape.getBandIndices(); |
... | ... | |
875 | 875 |
|
876 | 876 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
877 | 877 |
|
878 |
public MeshBase createRoundedSolid(final double[][] vertices, final int[][] vertIndexes,
|
|
879 |
final float[][] bands , final int[] bandIndexes,
|
|
880 |
final float[][] corners , final int[] cornerIndexes,
|
|
881 |
final float[][] centers , final int[] centerIndexes,
|
|
882 |
final int numComponents , final float[] convexityCenter )
|
|
878 |
public MeshBase createRoundedSolid(final float[][] vertices, final int[][] vertIndexes,
|
|
879 |
final float[][] bands , final int[] bandIndexes, |
|
880 |
final float[][] corners , final int[] cornerIndexes, |
|
881 |
final float[][] centers , final int[] centerIndexes, |
|
882 |
final int numComponents , final float[] convexityCenter ) |
|
883 | 883 |
{ |
884 | 884 |
int numFaces = vertIndexes.length; |
885 | 885 |
float[] band, bandsComputed; |
886 | 886 |
MeshBase[] meshes = new MeshBase[numFaces]; |
887 | 887 |
FaceTransform fInfo; |
888 | 888 |
StickerCoords sInfo; |
889 |
double[] convexXY = new double[4];
|
|
889 |
float[] convexXY = new float[4];
|
|
890 | 890 |
|
891 | 891 |
for(int face=0; face<numFaces; face++) |
892 | 892 |
{ |
893 | 893 |
fInfo = mNewFaceTransf.get(face); |
894 | 894 |
sInfo = mStickerCoords.get(fInfo.sticker); |
895 | 895 |
|
896 |
double[] verts = sInfo.vertices; |
|
897 |
int lenVerts = verts.length; |
|
898 |
float[] vertsFloat = new float[lenVerts]; |
|
899 |
for(int i=0; i<lenVerts; i++) vertsFloat[i] = (float)verts[i]; |
|
896 |
float[] verts = sInfo.vertices; |
|
900 | 897 |
|
901 | 898 |
computeConvexityCenter(convexXY,convexityCenter,fInfo); |
902 | 899 |
|
900 |
android.util.Log.e("D", "convexX="+convexXY[0]+" converY="+convexXY[1]); |
|
901 |
|
|
903 | 902 |
band = bands[bandIndexes[face]]; |
904 | 903 |
bandsComputed = computeBands( band[0], (int)band[1], band[2], band[3], (int)band[4]); |
905 |
meshes[face] = new MeshPolygon(vertsFloat,bandsComputed,(int)band[5],(int)band[6], (float)convexXY[0], (float)convexXY[1]);
|
|
904 |
meshes[face] = new MeshPolygon(verts,bandsComputed,(int)band[5],(int)band[6], convexXY[0], convexXY[1]);
|
|
906 | 905 |
meshes[face].setEffectAssociation(0,(1<<face),0); |
907 | 906 |
} |
908 | 907 |
|
... | ... | |
914 | 913 |
int assoc = (1<<face); |
915 | 914 |
fInfo = mNewFaceTransf.get(face); |
916 | 915 |
|
917 |
float vx = (float)fInfo.vx;
|
|
918 |
float vy = (float)fInfo.vy;
|
|
919 |
float vz = (float)fInfo.vz;
|
|
920 |
float sc = (float)fInfo.scale;
|
|
921 |
float qx = (float)fInfo.qx;
|
|
922 |
float qy = (float)fInfo.qy;
|
|
923 |
float qz = (float)fInfo.qz;
|
|
924 |
float qw = (float)fInfo.qw;
|
|
916 |
float vx = fInfo.vx; |
|
917 |
float vy = fInfo.vy; |
|
918 |
float vz = fInfo.vz; |
|
919 |
float sc = fInfo.scale; |
|
920 |
float qx = fInfo.qx; |
|
921 |
float qy = fInfo.qy; |
|
922 |
float qz = fInfo.qz; |
|
923 |
float qw = fInfo.qw; |
|
925 | 924 |
|
926 | 925 |
Static3D scale = new Static3D(sc,sc, fInfo.flip ? -sc : sc); |
927 | 926 |
Static3D move3D= new Static3D(vx,vy,vz); |
Also available in: Unified diff
Float vertices - scratchbook