mirror of
https://github.com/lubosz/overte.git
synced 2025-04-15 21:06:23 +02:00
add rayHitsSphere() util method
This commit is contained in:
parent
81de668c1e
commit
79b9fec900
2 changed files with 11 additions and 0 deletions
|
@ -40,6 +40,14 @@ glm::vec3 computeVectorFromPointToSegment(const glm::vec3& point, const glm::vec
|
|||
}
|
||||
}
|
||||
|
||||
bool rayHitsSphere(const glm::vec3& rayStart, const glm::vec3& rayDirection,
|
||||
const glm::vec3& sphereCenter, float sphereRadiusSquared) {
|
||||
glm::vec3 center = sphereCenter - rayStart;
|
||||
float distance = glm::dot(center, rayDirection);
|
||||
return (glm::length2(center) < sphereRadiusSquared
|
||||
|| (glm::abs(distance) > 0.0f && glm::distance2(distance * rayDirection, center) < sphereRadiusSquared));
|
||||
}
|
||||
|
||||
// Computes the penetration between a point and a sphere (centered at the origin)
|
||||
// if point is inside sphere: returns true and stores the result in 'penetration'
|
||||
// (the vector that would move the point outside the sphere)
|
||||
|
|
|
@ -19,6 +19,9 @@ class Plane;
|
|||
|
||||
glm::vec3 computeVectorFromPointToSegment(const glm::vec3& point, const glm::vec3& start, const glm::vec3& end);
|
||||
|
||||
bool rayHitsSphere(const glm::vec3& rayStart, const glm::vec3& rayDirection,
|
||||
const glm::vec3& sphereCenter, float sphereRadiusSquared);
|
||||
|
||||
/// Computes the penetration between a point and a sphere (centered at the origin)
|
||||
/// \param point the point location relative to sphere center (origin)
|
||||
/// \param defaultDirection the direction of the pentration when the point is near the origin
|
||||
|
|
Loading…
Reference in a new issue