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
543543 qDebug() << " modelExtents:" << modelExtents;
544544
545545 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 reference
547− AABox overlayFrameBox(corner, dimensions);
546+ glm::vec3 corner = -(dimensions * _registrationPoint); // since we're going to do the ray picking in the model frame of reference
547+ AABox modelFrameBox(corner, dimensions);
548548
549− qDebug() << " overlayFrameBox:" << overlayFrameBox;
549+ qDebug() << " modelFrameBox:" << modelFrameBox;
550550
551551 glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));
552552 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
555555
556556 // we can use the AABox's ray intersection by mapping our origin and direction into the model frame
557557 // 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!!!";
559561
560562 float bestDistance = std::numeric_limits<float>::max();
561563 float bestTriangleDistance = std::numeric_limits<float>::max();
@@ -566,14 +568,21 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 4 unmodified lines
566568 int subMeshIndex = 0;
567569
568570 const FBXGeometry& geometry = _geometry->getFBXGeometry();
571+
572+ qDebug() << " Checking mesh boxes....";
569573
570574 // If we hit the models box, then consider the submeshes...
571575 foreach(const AABox& subMeshBox, _calculatedMeshBoxes) {
572576
573− qDebug() << "subMeshBox[" << subMeshIndex <<"]:" << subMeshBox;
577+ qDebug() << " subMeshBox[" << subMeshIndex <<"]:" << subMeshBox;
574578 if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {
579+ qDebug() << " subMeshBox[" << subMeshIndex <<"].findRayIntersection() HITS!";
580+ qDebug() << " subMeshBox[" << subMeshIndex <<"].distanceToSubMesh:" << distanceToSubMesh;
581+ qDebug() << " bestDistance:" << bestDistance;
575582 if (distanceToSubMesh < bestDistance) {
576583
584+ qDebug() << " distanceToSubMesh < bestDistance !! looks like a good match!";
585+
577586 if (pickAgainstTriangles) {
578587 if (!_calculatedMeshTrianglesValid) {
579588 recalcuateMeshBoxes();
@@ -599,6 +608,8 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 19 unmodified lines
599608 intersectedSomething = true;
600609 face = subMeshFace;
601610 extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
611+ } else {
612+ qDebug() << " distanceToSubMesh >= bestDistance !! TOO FAR AWAY!";
602613 }
603614 }
604615 subMeshIndex++;
@@ -607,6 +618,7 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 2 unmodified lines
607618 // if we were asked to pick against triangles, and we didn't hit one, then we
608619 // do not consider this model to be hit at all.
609620 if (pickAgainstTriangles && !someTriangleHit) {
621+ qDebug() << "pickAgainstTriangles && !someTriangleHit --- call it a NON-HIT!";
610622 intersectedSomething = false;
611623 }
612624 qDebug() << "pickAgainstTriangles:" << pickAgainstTriangles;
@@ -626,6 +638,8 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 13 unmodified lines
626638 }
627639
628640 return intersectedSomething;
641+ } else {
642+ qDebug() << "modelFrameBox.findRayIntersection()... DID NOT INTERSECT...";
629643 }
630644
631645 return intersectedSomething;
libraries/entities/src/EntityTreeElement.cpp+4−0
@@ -553,6 +553,8 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con · 552 unmodified lines
553553 face = localFace;
554554 *intersectedObject = (void*)entity;
555555 somethingIntersected = true;
556+ } else {
557+ qDebug() << " localDistance >= distance... TOO FAR AWAY";
556558 }
557559 }
558560 } else {
@@ -566,6 +568,8 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con · 7 unmodified lines
566568 face = localFace;
567569 *intersectedObject = (void*)entity;
568570 somethingIntersected = true;
571+ } else {
572+ qDebug() << " localDistance >= distance... TOO FAR AWAY";
569573 }
570574 }
571575 }
libraries/octree/src/OctreeElement.cpp+4−0
@@ -1391,6 +1391,10 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3 · 1390 unmodified lines
13911391 qDebug() << " distance:" << distance << " -- THIS ONE IS GOOD -------";
13921392
13931393 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 -------";
13941398 }
13951399 }
13961400 }