fix models with registrations other than 0,0,0

This commit is contained in:
ZappoMan 2014-12-05 16:14:18 -08:00
parent 0ccbb98bde
commit ae647d39d0
3 changed files with 27 additions and 5 deletions

View file

@ -543,10 +543,10 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
qDebug() << " modelExtents:" << modelExtents; qDebug() << " modelExtents:" << modelExtents;
glm::vec3 dimensions = modelExtents.maximum - modelExtents.minimum; glm::vec3 dimensions = modelExtents.maximum - modelExtents.minimum;
glm::vec3 corner = dimensions * _registrationPoint; // since we're going to do the ray picking in the model frame of reference glm::vec3 corner = -(dimensions * _registrationPoint); // since we're going to do the ray picking in the model frame of reference
AABox overlayFrameBox(corner, dimensions); AABox modelFrameBox(corner, dimensions);
qDebug() << " overlayFrameBox:" << overlayFrameBox; qDebug() << " modelFrameBox:" << modelFrameBox;
glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f)); glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));
glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f)); glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f));
@ -555,7 +555,9 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
// we can use the AABox's ray intersection by mapping our origin and direction into the model frame // we can use the AABox's ray intersection by mapping our origin and direction into the model frame
// and testing intersection there. // and testing intersection there.
if (overlayFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) { if (modelFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) {
qDebug() << " modelFrameBox.findRayIntersection() HITS!!!";
float bestDistance = std::numeric_limits<float>::max(); float bestDistance = std::numeric_limits<float>::max();
float bestTriangleDistance = std::numeric_limits<float>::max(); float bestTriangleDistance = std::numeric_limits<float>::max();
@ -567,13 +569,20 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
const FBXGeometry& geometry = _geometry->getFBXGeometry(); const FBXGeometry& geometry = _geometry->getFBXGeometry();
qDebug() << " Checking mesh boxes....";
// If we hit the models box, then consider the submeshes... // If we hit the models box, then consider the submeshes...
foreach(const AABox& subMeshBox, _calculatedMeshBoxes) { foreach(const AABox& subMeshBox, _calculatedMeshBoxes) {
qDebug() << "subMeshBox[" << subMeshIndex <<"]:" << subMeshBox; qDebug() << " subMeshBox[" << subMeshIndex <<"]:" << subMeshBox;
if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) { if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {
qDebug() << " subMeshBox[" << subMeshIndex <<"].findRayIntersection() HITS!";
qDebug() << " subMeshBox[" << subMeshIndex <<"].distanceToSubMesh:" << distanceToSubMesh;
qDebug() << " bestDistance:" << bestDistance;
if (distanceToSubMesh < bestDistance) { if (distanceToSubMesh < bestDistance) {
qDebug() << " distanceToSubMesh < bestDistance !! looks like a good match!";
if (pickAgainstTriangles) { if (pickAgainstTriangles) {
if (!_calculatedMeshTrianglesValid) { if (!_calculatedMeshTrianglesValid) {
recalcuateMeshBoxes(); recalcuateMeshBoxes();
@ -599,6 +608,8 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
intersectedSomething = true; intersectedSomething = true;
face = subMeshFace; face = subMeshFace;
extraInfo = geometry.getModelNameOfMesh(subMeshIndex); extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
} else {
qDebug() << " distanceToSubMesh >= bestDistance !! TOO FAR AWAY!";
} }
} }
subMeshIndex++; subMeshIndex++;
@ -607,6 +618,7 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
// if we were asked to pick against triangles, and we didn't hit one, then we // if we were asked to pick against triangles, and we didn't hit one, then we
// do not consider this model to be hit at all. // do not consider this model to be hit at all.
if (pickAgainstTriangles && !someTriangleHit) { if (pickAgainstTriangles && !someTriangleHit) {
qDebug() << "pickAgainstTriangles && !someTriangleHit --- call it a NON-HIT!";
intersectedSomething = false; intersectedSomething = false;
} }
qDebug() << "pickAgainstTriangles:" << pickAgainstTriangles; qDebug() << "pickAgainstTriangles:" << pickAgainstTriangles;
@ -626,6 +638,8 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
} }
return intersectedSomething; return intersectedSomething;
} else {
qDebug() << "modelFrameBox.findRayIntersection()... DID NOT INTERSECT...";
} }
return intersectedSomething; return intersectedSomething;

View file

@ -553,6 +553,8 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
face = localFace; face = localFace;
*intersectedObject = (void*)entity; *intersectedObject = (void*)entity;
somethingIntersected = true; somethingIntersected = true;
} else {
qDebug() << " localDistance >= distance... TOO FAR AWAY";
} }
} }
} else { } else {
@ -566,6 +568,8 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
face = localFace; face = localFace;
*intersectedObject = (void*)entity; *intersectedObject = (void*)entity;
somethingIntersected = true; somethingIntersected = true;
} else {
qDebug() << " localDistance >= distance... TOO FAR AWAY";
} }
} }
} }

View file

@ -1391,6 +1391,10 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3
qDebug() << " distance:" << distance << " -- THIS ONE IS GOOD -------"; qDebug() << " distance:" << distance << " -- THIS ONE IS GOOD -------";
return true; return true;
} else {
qDebug() << " distanceToElementDetails:" << distanceToElementDetails;
qDebug() << " distance:" << distance;
qDebug() << " distanceToElementDetails >= distance -- THIS ONE IS NOT SELECTED even though it INTERSECTED -------";
} }
} }
} }