313 |
313 |
int len = vert3D.length;
|
314 |
314 |
StickerInfo sInfo = new StickerInfo();
|
315 |
315 |
sInfo.vertices = new float[2*len];
|
316 |
|
mStickerInfo.add(sInfo);
|
317 |
316 |
|
318 |
317 |
for( int vertex=0; vertex<len; vertex++ )
|
319 |
318 |
{
|
... | ... | |
321 |
320 |
sInfo.vertices[2*vertex+1] = vert3D[vertex][1] / info.scale;
|
322 |
321 |
}
|
323 |
322 |
|
|
323 |
mStickerInfo.add(sInfo);
|
|
324 |
|
|
325 |
info.sticker = mStickerInfo.size() -1;
|
324 |
326 |
info.flip = false;
|
325 |
327 |
}
|
326 |
328 |
|
... | ... | |
382 |
384 |
axisY = mBuffer[0];
|
383 |
385 |
axisZ = 0.0f;
|
384 |
386 |
|
385 |
|
float axiLen = axisX*axisX + axisY*axisY + axisZ*axisZ;
|
|
387 |
float axiLen = axisX*axisX + axisY*axisY;
|
386 |
388 |
axiLen = (float)Math.sqrt(axiLen);
|
387 |
389 |
axisX /= axiLen;
|
388 |
390 |
axisY /= axiLen;
|
... | ... | |
403 |
405 |
mQuat1[1] = axisY*sinHalfTheta;
|
404 |
406 |
mQuat1[2] = axisZ*sinHalfTheta;
|
405 |
407 |
mQuat1[3] = cosHalfTheta;
|
406 |
|
mQuat2[0] = axisX*sinHalfTheta;
|
407 |
|
mQuat2[1] = axisY*sinHalfTheta;
|
408 |
|
mQuat2[2] = axisZ*sinHalfTheta;
|
409 |
|
mQuat2[3] = -cosHalfTheta;
|
|
408 |
mQuat2[0] =-axisX*sinHalfTheta;
|
|
409 |
mQuat2[1] =-axisY*sinHalfTheta;
|
|
410 |
mQuat2[2] =-axisZ*sinHalfTheta;
|
|
411 |
mQuat2[3] = cosHalfTheta;
|
410 |
412 |
|
411 |
413 |
for (float[] vert : vert3D)
|
412 |
414 |
{
|
413 |
|
quatMultiply(mQuat1, vert, mQuat3);
|
414 |
|
quatMultiply(mQuat3, mQuat2, vert);
|
|
415 |
quatMultiply(mQuat1, vert , mQuat3);
|
|
416 |
quatMultiply(mQuat3, mQuat2, vert );
|
415 |
417 |
}
|
416 |
418 |
|
417 |
419 |
// fit the whole thing in a square and remember the scale & 2D vertices
|
418 |
420 |
fitInSquare(info, vert3D);
|
419 |
421 |
|
420 |
422 |
// remember the rotation
|
421 |
|
info.qx = mQuat1[0];
|
422 |
|
info.qy = mQuat1[1];
|
423 |
|
info.qz = mQuat1[2];
|
424 |
|
info.qw =-mQuat1[3];
|
|
423 |
info.qx =-mQuat1[0];
|
|
424 |
info.qy =-mQuat1[1];
|
|
425 |
info.qz =-mQuat1[2];
|
|
426 |
info.qw = mQuat1[3];
|
425 |
427 |
}
|
426 |
428 |
|
427 |
429 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
428 |
430 |
|
429 |
431 |
private float computeCos(float x1, float y1, float x2, float y2, float len1, float len2)
|
430 |
432 |
{
|
431 |
|
return (x1*x2+y1*y2) / (len1*len2);
|
|
433 |
float ret = (x1*x2+y1*y2) / (len1*len2);
|
|
434 |
|
|
435 |
if( ret> 1.0f ) return 1.0f;
|
|
436 |
if( ret<-1.0f ) return -1.0f;
|
|
437 |
|
|
438 |
return ret;
|
432 |
439 |
}
|
433 |
440 |
|
434 |
441 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
436 |
443 |
|
437 |
444 |
private float computeSin(float x1, float y1, float x2, float y2, float len1, float len2)
|
438 |
445 |
{
|
439 |
|
return (x2*y1-x1*y2) / (len1*len2);
|
|
446 |
float ret = (x2*y1-x1*y2) / (len1*len2);
|
|
447 |
|
|
448 |
if( ret> 1.0f ) return 1.0f;
|
|
449 |
if( ret<-1.0f ) return -1.0f;
|
|
450 |
|
|
451 |
return ret;
|
440 |
452 |
}
|
441 |
453 |
|
442 |
454 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
481 |
493 |
|
482 |
494 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
483 |
495 |
|
484 |
|
private void correctInfo(FaceInfo info, float scale, float sin, float cos, int oldSticker, boolean flip)
|
|
496 |
private void correctInfo(FaceInfo info, float scale, float cos, int oldSticker, boolean flip)
|
485 |
497 |
{
|
486 |
498 |
mStickerInfo.remove(info.sticker);
|
487 |
499 |
|
488 |
|
info.flip = flip;
|
|
500 |
info.flip = flip;
|
489 |
501 |
info.sticker = oldSticker;
|
490 |
|
info.scale *= scale;
|
|
502 |
info.scale *= scale;
|
|
503 |
|
|
504 |
mQuat1[0] = info.qx;
|
|
505 |
mQuat1[1] = info.qy;
|
|
506 |
mQuat1[2] = info.qz;
|
|
507 |
mQuat1[3] = info.qw;
|
491 |
508 |
|
492 |
|
mQuat1[0] = 0.0f;
|
493 |
|
mQuat1[1] = 0.0f;
|
494 |
|
mQuat1[2] = sin;
|
495 |
|
mQuat1[3] = cos;
|
|
509 |
float sinHalf = (float)Math.sqrt(0.5f*(1-cos));
|
|
510 |
float cosHalf = (float)Math.sqrt(0.5f*(1+cos));
|
496 |
511 |
|
497 |
|
mQuat2[0] = info.qx;
|
498 |
|
mQuat2[1] = info.qy;
|
499 |
|
mQuat2[2] = info.qz;
|
500 |
|
mQuat2[3] = info.qw;
|
|
512 |
mQuat2[0] = 0.0f;
|
|
513 |
mQuat2[1] = 0.0f;
|
|
514 |
mQuat2[2] = sinHalf;
|
|
515 |
mQuat2[3] = cosHalf;
|
501 |
516 |
|
502 |
517 |
quatMultiply( mQuat1, mQuat2, mQuat3 );
|
503 |
518 |
|
... | ... | |
514 |
529 |
{
|
515 |
530 |
for(int vertex=0; vertex<len; vertex++)
|
516 |
531 |
{
|
517 |
|
float xR = newVert[2*vertex ];
|
518 |
|
float yR = newVert[2*vertex+1];
|
|
532 |
float xR = preVert[2*vertex ];
|
|
533 |
float yR = preVert[2*vertex+1];
|
519 |
534 |
float lenRotV = (float)Math.sqrt(xR*xR+yR*yR);
|
520 |
|
float cos = computeCos(xR,yR,preVert[0],preVert[1], lenRotV, lenVert);
|
521 |
|
float sin = computeSin(xR,yR,preVert[0],preVert[1], lenRotV, lenVert);
|
|
535 |
float cos = computeCos(xR,yR,newVert[0],newVert[1], lenRotV, lenVert);
|
|
536 |
float sin = computeSin(xR,yR,newVert[0],newVert[1], lenRotV, lenVert);
|
522 |
537 |
|
523 |
538 |
rotateAllVertices(buffer,len,newVert,sin,cos);
|
524 |
539 |
|
525 |
540 |
if( isScaledVersionOf(buffer,preVert,len) )
|
526 |
541 |
{
|
527 |
542 |
float scale = preVert[0]!=0.0f ? buffer[0]/preVert[0] : buffer[1]/preVert[1];
|
528 |
|
correctInfo(info,scale,sin,cos,oldSticker,inverted);
|
|
543 |
correctInfo(info,scale,cos,oldSticker,inverted);
|
529 |
544 |
return true;
|
530 |
545 |
}
|
531 |
546 |
}
|
... | ... | |
660 |
675 |
|
661 |
676 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
662 |
677 |
|
663 |
|
private void printStickerInfo()
|
|
678 |
private void printInfo()
|
664 |
679 |
{
|
665 |
|
String ver="";
|
666 |
680 |
int stickers = mStickerInfo.size();
|
667 |
681 |
|
|
682 |
android.util.Log.d("D", "-------------------------");
|
|
683 |
|
668 |
684 |
for(int s=0; s<stickers; s++)
|
669 |
685 |
{
|
670 |
|
ver = "";
|
|
686 |
String ver = "";
|
671 |
687 |
StickerInfo info = mStickerInfo.get(s);
|
672 |
688 |
int len = info.vertices.length/2;
|
673 |
689 |
|
... | ... | |
675 |
691 |
{
|
676 |
692 |
ver += ("("+info.vertices[2*i]+","+info.vertices[2*i+1]+") ");
|
677 |
693 |
}
|
|
694 |
|
|
695 |
android.util.Log.e("D", "sticker "+s+" "+ver);
|
678 |
696 |
}
|
679 |
697 |
|
680 |
|
android.util.Log.e("D", "vertices= "+ver);
|
681 |
|
}
|
|
698 |
android.util.Log.d("D", "-------------------------");
|
682 |
699 |
|
683 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
700 |
int faces = mFaceInfo.size();
|
684 |
701 |
|
685 |
|
private void printFaceInfo(FaceInfo info)
|
686 |
|
{
|
687 |
|
android.util.Log.e("D", "q=("+info.qx+", "+info.qy+", "+info.qz+", "+info.qw+") v=("
|
|
702 |
for(int f=0; f<faces; f++)
|
|
703 |
{
|
|
704 |
FaceInfo info = mFaceInfo.get(f);
|
|
705 |
|
|
706 |
android.util.Log.e("D", "q=("+info.qx+", "+info.qy+", "+info.qz+", "+info.qw+") v=("
|
688 |
707 |
+info.vx+", "+info.vy+", "+info.vz+") scale="+info.scale+" sticker="+info.sticker);
|
|
708 |
}
|
|
709 |
|
|
710 |
android.util.Log.d("D", "-------------------------");
|
689 |
711 |
}
|
690 |
712 |
|
691 |
713 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
704 |
726 |
FaceInfo fInfo;
|
705 |
727 |
StickerInfo sInfo;
|
706 |
728 |
|
707 |
|
//printStickerInfo();
|
|
729 |
printInfo();
|
708 |
730 |
|
709 |
731 |
for(int face=0; face<numFaces; face++)
|
710 |
732 |
{
|
711 |
733 |
fInfo = mFaceInfo.get(face);
|
712 |
734 |
sInfo = mStickerInfo.get(fInfo.sticker);
|
713 |
735 |
|
714 |
|
//printFaceInfo(fInfo);
|
715 |
|
|
716 |
736 |
band = bands[bandIndexes[face]];
|
717 |
737 |
bandsComputed = computeBands( band[0], (int)band[1], band[2], band[3], (int)band[4]);
|
718 |
738 |
meshes[face] = new MeshPolygon(sInfo.vertices,bandsComputed,(int)band[5],(int)band[6]);
|
Face cubit creation: progress: cube & tetrahedron work; dino cubit does not.
Also, the texture is not yet moved inside the (0,1)x(0,1) square.