\brief This file contains some routines to do intersection tests with low-level geometric primitives.
Focus lies on points, lines, line segments, rays, triangles, spheres and axis-aligned bounding boxes (AABB).
All functions are named \c prim1IntersectsPrim2 and return a \c bool indicating whether the primitives do intersect or not.
Functions where the possible intersection is a point (or two points) have two versions: The first one only checks whether there is an intersection and returns \c true or \c false. The second one also calculates the first point of intersection and the distance to it; this requires two more arguments, \c distance and \c hitpoint. Of course these functions are a little slower (in general).
\b IMPORTANT: For line segments \c distance is NOT the 'true distance' but the fraction by that the segment is divided! A 'distance' of 0.0f means the \c hitpoint is identical with the startPoint (\c pos1), one of 1.0f means \c hitPoint=endPoint (\c pos2) and 0.5f means the \c hitPoint lies exactly in the middle of the segment.
Here is a list of primitives and how they are represented:
- \b Points are represented as three dimensional vectors (#vec3_t)
- <b>Straight Lines</b> are represented through a starting point and a direction vector (x=pos+t*dir)
- \b Rays are treated as lines, but the area 'behind' pos (negative t) is ignored
- <b>Line segments</b> are described through two points (startpoint and endpoint)
- \b Planes are described through a unit normal vector and a distance to the origin (Hesse-Normalenform) stored in a four dimensional vector (elements 0-2: normal; element 3: distance)
- \b Triangles are represented through three points
- \b Spheres are represented through a center point and a radius
- \b AABBs are represented through their maximal and minimal coordinates on each axis (stored in the 3d-vectors min and max)
The function and argument names should be pretty self-explanatory, so I won't waste much comments here.
\see collision.h
*/
#include "vectormath.h"
bool pointIntersectsPlane(vec3_t point, vec4_t plane);
bool pointIntersectsTriangle(vec3_t point, vec3_t p1, vec3_t p2, vec3_t p3);
bool pointIntersectsSphere(vec3_t point, vec3_t center, float radius);
bool pointIntersectsCube(vec3_t point, vec3_t center, float edgelength);
bool pointIntersectsBox(vec3_t point, vec3_t center, vec3_t edgelengths);
bool pointIntersectsAABB(vec3_t point, vec3_t min, vec3_t max);