From a9957ac7df97b15bc6b6fb5e714431dd403f3018 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 12 Sep 2014 08:40:03 -0700 Subject: [PATCH] the real fix for ray-vs-plane intersection --- libraries/shared/src/PlaneShape.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/shared/src/PlaneShape.cpp b/libraries/shared/src/PlaneShape.cpp index b844bac299..845b58728a 100644 --- a/libraries/shared/src/PlaneShape.cpp +++ b/libraries/shared/src/PlaneShape.cpp @@ -11,6 +11,7 @@ #include "PlaneShape.h" #include "SharedUtil.h" +#include "GLMHelpers.h" const glm::vec3 UNROTATED_NORMAL(0.0f, 1.0f, 0.0f); @@ -34,6 +35,18 @@ glm::vec3 PlaneShape::getNormal() const { return _rotation * UNROTATED_NORMAL; } +void PlaneShape::setNormal(const glm::vec3& direction) { + glm::vec3 oldTranslation = _translation; + _rotation = rotationBetween(UNROTATED_NORMAL, direction); + glm::vec3 normal = getNormal(); + _translation = glm::dot(oldTranslation, normal) * normal; +} + +void PlaneShape::setPoint(const glm::vec3& point) { + glm::vec3 normal = getNormal(); + _translation = glm::dot(point, normal) * normal; +} + glm::vec4 PlaneShape::getCoefficients() const { glm::vec3 normal = _rotation * UNROTATED_NORMAL; return glm::vec4(normal.x, normal.y, normal.z, -glm::dot(normal, _translation)); @@ -53,7 +66,7 @@ bool PlaneShape::findRayIntersection(RayIntersectionInfo& intersection) const { } } else { float d = glm::dot(_translation - intersection._rayStart, n) / denominator; - if (d > 0.0f && d < intersection._rayLength && intersection._hitDistance) { + if (d > 0.0f && d < intersection._rayLength && d < intersection._hitDistance) { // ray points toward plane intersection._hitDistance = d; intersection._hitNormal = n;