normalize the surface normal from the triangle, coding standard fix, update example

This commit is contained in:
Brad Hefta-Gaub 2015-09-28 08:30:49 -07:00
parent 430cbcca7e
commit ce3da099f6
3 changed files with 8 additions and 6 deletions

View file

@ -18,20 +18,22 @@ function mouseMoveEvent(event) {
print("computePickRay origin=" + pickRay.origin.x + ", " + pickRay.origin.y + ", " + pickRay.origin.z);
print("computePickRay direction=" + pickRay.direction.x + ", " + pickRay.direction.y + ", " + pickRay.direction.z);
var pickRay = Camera.computePickRay(event.x, event.y);
intersection = Entities.findRayIntersection(pickRay);
intersection = Entities.findRayIntersection(pickRay, true); // to get precise picking
if (!intersection.accurate) {
print(">>> NOTE: intersection not accurate. will try calling Entities.findRayIntersectionBlocking()");
intersection = Entities.findRayIntersectionBlocking(pickRay);
intersection = Entities.findRayIntersectionBlocking(pickRay, true); // to get precise picking
print(">>> AFTER BLOCKING CALL intersection.accurate=" + intersection.accurate);
}
if (intersection.intersects) {
print("intersection entityID.id=" + intersection.entityID.id);
print("intersection entityID=" + intersection.entityID);
print("intersection properties.modelURL=" + intersection.properties.modelURL);
print("intersection face=" + intersection.face);
print("intersection distance=" + intersection.distance);
print("intersection intersection.x/y/z=" + intersection.intersection.x + ", "
print("intersection intersection.x/y/z=" + intersection.intersection.x + ", "
+ intersection.intersection.y + ", " + intersection.intersection.z);
print("intersection surfaceNormal.x/y/z=" + intersection.surfaceNormal.x + ", "
+ intersection.surfaceNormal.y + ", " + intersection.surfaceNormal.z);
}
}

View file

@ -502,7 +502,7 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
recalculateMeshBoxes(pickAgainstTriangles);
}
foreach(const AABox& subMeshBox, _calculatedMeshBoxes) {
foreach (const AABox& subMeshBox, _calculatedMeshBoxes) {
if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace, subMeshSurfaceNormal)) {
if (distanceToSubMesh < bestDistance) {

View file

@ -265,7 +265,7 @@ glm::vec3 Triangle::getNormal() const {
result.x = (u.z * v.x) - (u.x * v.z);
result.x = (u.x * v.y) - (u.y * v.x);
return result;
return glm::normalize(result);
}
bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,