mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 14:03:55 +02:00
the real fix for ray-vs-plane intersection
This commit is contained in:
parent
ff0872a5f0
commit
a9957ac7df
1 changed files with 14 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue