History

fix models with registrations other than 0,0,0

ZappoMan committed 11 years ago

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

Showing the changes to interface/src/renderer (1 of 3 files). Show all

Unified · Split

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;