History

more work on improved model picking

ZappoMan committed 11 years ago

Commit 37ffa481 parent 5ec9a9b3 files · +18 −377Browse files

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

Unified · Split

interface/src/renderer/Model.cpp+7−0
@@ -536,6 +536,8 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 535 unmodified lines
536 return intersectedSomething;536 return intersectedSomething;
537 }537 }
538 538
539 qDebug() << "Model::findRayIntersectionAgainstSubMeshes()...";
540
539 // extents is the entity relative, scaled, centered extents of the entity541 // extents is the entity relative, scaled, centered extents of the entity
540 glm::vec3 position = _translation;542 glm::vec3 position = _translation;
541 glm::mat4 rotation = glm::mat4_cast(_rotation);543 glm::mat4 rotation = glm::mat4_cast(_rotation);
@@ -544,11 +546,14 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 2 unmodified lines
544 glm::mat4 worldToModelMatrix = glm::inverse(modelToWorldMatrix);546 glm::mat4 worldToModelMatrix = glm::inverse(modelToWorldMatrix);
545 547
546 Extents modelExtents = getMeshExtents(); // NOTE: unrotated548 Extents modelExtents = getMeshExtents(); // NOTE: unrotated
549 qDebug() << " modelExtents:" << modelExtents;
547 550
548 glm::vec3 dimensions = modelExtents.maximum - modelExtents.minimum;551 glm::vec3 dimensions = modelExtents.maximum - modelExtents.minimum;
549 glm::vec3 corner = dimensions * -0.5f; // since we're going to do the ray picking in the model frame of reference552 glm::vec3 corner = dimensions * -0.5f; // since we're going to do the ray picking in the model frame of reference
550 AABox overlayFrameBox(corner, dimensions);553 AABox overlayFrameBox(corner, dimensions);
551 554
555 qDebug() << " overlayFrameBox:" << overlayFrameBox;
556
552 glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));557 glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));
553 glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f));558 glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f));
554 559
@@ -560,11 +565,13 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 5 unmodified lines
560 float distanceToSubMesh;565 float distanceToSubMesh;
561 BoxFace subMeshFace;566 BoxFace subMeshFace;
562 int subMeshIndex = 0;567 int subMeshIndex = 0;
568
563 569
564 // If we hit the models box, then consider the submeshes...570 // If we hit the models box, then consider the submeshes...
565 foreach(const AABox& subMeshBox, _calculatedMeshBoxes) {571 foreach(const AABox& subMeshBox, _calculatedMeshBoxes) {
566 const FBXGeometry& geometry = _geometry->getFBXGeometry();572 const FBXGeometry& geometry = _geometry->getFBXGeometry();
567 573
574 qDebug() << "subMeshBox[" << subMeshIndex <<"]:" << subMeshBox;
568 if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {575 if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {
569 if (distanceToSubMesh < bestDistance) {576 if (distanceToSubMesh < bestDistance) {
570 bestDistance = distanceToSubMesh;577 bestDistance = distanceToSubMesh;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t