History

fix models with registrations other than 0,0,0

ZappoMan committed 11 years ago

Commit ae647d31 parent 0ccbb983 files · +27 −5Browse files

Unified · Split

3 files
  1. interface/src/renderer/Model.cpp +19 −5
  2. libraries/entities/src/EntityTreeElement.cpp +4 −0
  3. libraries/octree/src/OctreeElement.cpp +4 −0
interface/src/renderer/Model.cpp+19−5
@@ -543,10 +543,10 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 542 unmodified lines
543 qDebug() << " modelExtents:" << modelExtents;543 qDebug() << " modelExtents:" << modelExtents;
544 544
545 glm::vec3 dimensions = modelExtents.maximum - modelExtents.minimum;545 glm::vec3 dimensions = modelExtents.maximum - modelExtents.minimum;
546 glm::vec3 corner = dimensions * _registrationPoint; // since we're going to do the ray picking in the model frame of reference546 glm::vec3 corner = -(dimensions * _registrationPoint); // since we're going to do the ray picking in the model frame of reference
547 AABox overlayFrameBox(corner, dimensions);547 AABox modelFrameBox(corner, dimensions);
548 548
549 qDebug() << " overlayFrameBox:" << overlayFrameBox;549 qDebug() << " modelFrameBox:" << modelFrameBox;
550 550
551 glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));551 glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));
552 glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f));552 glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f));
@@ -555,7 +555,9 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 2 unmodified lines
555 555
556 // we can use the AABox's ray intersection by mapping our origin and direction into the model frame556 // we can use the AABox's ray intersection by mapping our origin and direction into the model frame
557 // and testing intersection there.557 // and testing intersection there.
558 if (overlayFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) {558 if (modelFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) {
559
560 qDebug() << " modelFrameBox.findRayIntersection() HITS!!!";
559 561
560 float bestDistance = std::numeric_limits<float>::max();562 float bestDistance = std::numeric_limits<float>::max();
561 float bestTriangleDistance = std::numeric_limits<float>::max();563 float bestTriangleDistance = std::numeric_limits<float>::max();
@@ -566,14 +568,21 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 4 unmodified lines
566 int subMeshIndex = 0;568 int subMeshIndex = 0;
567 569
568 const FBXGeometry& geometry = _geometry->getFBXGeometry();570 const FBXGeometry& geometry = _geometry->getFBXGeometry();
571
572 qDebug() << " Checking mesh boxes....";
569 573
570 // If we hit the models box, then consider the submeshes...574 // If we hit the models box, then consider the submeshes...
571 foreach(const AABox& subMeshBox, _calculatedMeshBoxes) {575 foreach(const AABox& subMeshBox, _calculatedMeshBoxes) {
572 576
573 qDebug() << "subMeshBox[" << subMeshIndex <<"]:" << subMeshBox;577 qDebug() << " subMeshBox[" << subMeshIndex <<"]:" << subMeshBox;
574 if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {578 if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {
579 qDebug() << " subMeshBox[" << subMeshIndex <<"].findRayIntersection() HITS!";
580 qDebug() << " subMeshBox[" << subMeshIndex <<"].distanceToSubMesh:" << distanceToSubMesh;
581 qDebug() << " bestDistance:" << bestDistance;
575 if (distanceToSubMesh < bestDistance) {582 if (distanceToSubMesh < bestDistance) {
576 583
584 qDebug() << " distanceToSubMesh < bestDistance !! looks like a good match!";
585
577 if (pickAgainstTriangles) {586 if (pickAgainstTriangles) {
578 if (!_calculatedMeshTrianglesValid) {587 if (!_calculatedMeshTrianglesValid) {
579 recalcuateMeshBoxes();588 recalcuateMeshBoxes();
@@ -599,6 +608,8 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 19 unmodified lines
599 intersectedSomething = true;608 intersectedSomething = true;
600 face = subMeshFace;609 face = subMeshFace;
601 extraInfo = geometry.getModelNameOfMesh(subMeshIndex);610 extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
611 } else {
612 qDebug() << " distanceToSubMesh >= bestDistance !! TOO FAR AWAY!";
602 }613 }
603 }614 }
604 subMeshIndex++;615 subMeshIndex++;
@@ -607,6 +618,7 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 2 unmodified lines
607 // if we were asked to pick against triangles, and we didn't hit one, then we618 // if we were asked to pick against triangles, and we didn't hit one, then we
608 // do not consider this model to be hit at all.619 // do not consider this model to be hit at all.
609 if (pickAgainstTriangles && !someTriangleHit) {620 if (pickAgainstTriangles && !someTriangleHit) {
621 qDebug() << "pickAgainstTriangles && !someTriangleHit --- call it a NON-HIT!";
610 intersectedSomething = false;622 intersectedSomething = false;
611 }623 }
612 qDebug() << "pickAgainstTriangles:" << pickAgainstTriangles;624 qDebug() << "pickAgainstTriangles:" << pickAgainstTriangles;
@@ -626,6 +638,8 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 13 unmodified lines
626 }638 }
627 639
628 return intersectedSomething;640 return intersectedSomething;
641 } else {
642 qDebug() << "modelFrameBox.findRayIntersection()... DID NOT INTERSECT...";
629 }643 }
630 644
631 return intersectedSomething;645 return intersectedSomething;
libraries/entities/src/EntityTreeElement.cpp+4−0
@@ -553,6 +553,8 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con · 552 unmodified lines
553 face = localFace;553 face = localFace;
554 *intersectedObject = (void*)entity;554 *intersectedObject = (void*)entity;
555 somethingIntersected = true;555 somethingIntersected = true;
556 } else {
557 qDebug() << " localDistance >= distance... TOO FAR AWAY";
556 }558 }
557 }559 }
558 } else {560 } else {
@@ -566,6 +568,8 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con · 7 unmodified lines
566 face = localFace;568 face = localFace;
567 *intersectedObject = (void*)entity;569 *intersectedObject = (void*)entity;
568 somethingIntersected = true;570 somethingIntersected = true;
571 } else {
572 qDebug() << " localDistance >= distance... TOO FAR AWAY";
569 }573 }
570 }574 }
571 }575 }
libraries/octree/src/OctreeElement.cpp+4−0
@@ -1391,6 +1391,10 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3 · 1390 unmodified lines
1391 qDebug() << " distance:" << distance << " -- THIS ONE IS GOOD -------";1391 qDebug() << " distance:" << distance << " -- THIS ONE IS GOOD -------";
1392 1392
1393 return true;1393 return true;
1394 } else {
1395 qDebug() << " distanceToElementDetails:" << distanceToElementDetails;
1396 qDebug() << " distance:" << distance;
1397 qDebug() << " distanceToElementDetails >= distance -- THIS ONE IS NOT SELECTED even though it INTERSECTED -------";
1394 }1398 }
1395 }1399 }
1396 }1400 }