Showing the changes to interface/src/renderer (1 of 3 files). Show all
Unified · Split
| @@ -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 reference | 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); | 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 frame | 556 | // 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 we | 618 | // 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; |