home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / intersection.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-18  |  6.9 KB  |  93 lines

  1. #ifndef __intersection_h__
  2. #define __intersection_h__
  3.  
  4. /*!
  5. \file intersection.h
  6. \author Karsten Schwenk
  7.  
  8. \brief This file contains some routines to do intersection tests with low-level geometric primitives.
  9.  
  10. Focus lies on points, lines, line segments, rays, triangles, spheres and axis-aligned bounding boxes (AABB).
  11. All functions are named \c prim1IntersectsPrim2 and return a \c bool indicating whether the primitives do intersect or not.
  12.  
  13. 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).
  14. \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.
  15.  
  16. Here is a list of primitives and how they are represented:
  17. - \b Points are represented as three dimensional vectors (#vec3_t)
  18. - <b>Straight Lines</b> are represented through a starting point and a direction vector (x=pos+t*dir)
  19. - \b Rays are treated as lines, but the area 'behind' pos (negative t) is ignored
  20. - <b>Line segments</b> are described through two points (startpoint and endpoint)
  21. - \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)
  22. - \b Triangles are represented through three points
  23. - \b Spheres are represented through a center point and a radius
  24. - \b AABBs are represented through their maximal and minimal coordinates on each axis (stored in the 3d-vectors min and max)
  25.  
  26. The function and argument names should be pretty self-explanatory, so I won't waste much comments here.
  27.  
  28. \see collision.h
  29. */
  30.  
  31. #include "vectormath.h"
  32.  
  33. bool pointIntersectsPlane(vec3_t point, vec4_t plane);
  34. bool pointIntersectsTriangle(vec3_t point, vec3_t p1, vec3_t p2, vec3_t p3);
  35. bool pointIntersectsSphere(vec3_t point, vec3_t center, float radius);
  36. bool pointIntersectsCube(vec3_t point, vec3_t center, float edgelength);
  37. bool pointIntersectsBox(vec3_t point, vec3_t center, vec3_t edgelengths);
  38. bool pointIntersectsAABB(vec3_t point, vec3_t min, vec3_t max);
  39.  
  40. bool lineIntersectsPlane(vec3_t pos, vec3_t dir, vec4_t plane);
  41. bool lineIntersectsPlane(vec3_t pos, vec3_t dir, vec4_t plane, float* distance, vec3_t hitpoint);
  42. bool lineIntersectsTriangle(vec3_t pos, vec3_t dir, vec3_t p1, vec3_t p2, vec3_t p3);
  43. bool lineIntersectsTriangle(vec3_t pos, vec3_t dir, vec3_t p1, vec3_t p2, vec3_t p3, float* distance, vec3_t hitpoint);
  44. bool lineIntersectsSphere(vec3_t pos, vec3_t dir, vec3_t center, float radius);
  45. bool lineIntersectsSphere(vec3_t pos, vec3_t dir, vec3_t center, float radius, float* distance, vec3_t hitpoint);
  46. bool lineIntersectsCube(vec3_t pos, vec3_t dir, vec3_t center, float edgelength);
  47. bool lineIntersectsCube(vec3_t pos, vec3_t dir, vec3_t center, float edgelength, float* distance, vec3_t hitpoint);
  48. bool lineIntersectsBox(vec3_t pos, vec3_t dir, vec3_t center, vec3_t edgelengths);
  49. bool lineIntersectsBox(vec3_t pos, vec3_t dir, vec3_t center, vec3_t edgelengths, float* distance, vec3_t hitpoint);
  50. bool lineIntersectsAABB(vec3_t pos, vec3_t dir, vec3_t min, vec3_t max);
  51. bool lineIntersectsAABB(vec3_t pos, vec3_t dir, vec3_t min, vec3_t max, float* distance, vec3_t hitpoint);
  52.  
  53. bool linesegmentIntersectsPlane(vec3_t pos1, vec3_t pos2, vec4_t plane);
  54. bool linesegmentIntersectsPlane(vec3_t pos1, vec3_t pos2, vec4_t plane, float* distance, vec3_t hitpoint);
  55. bool linesegmentIntersectsTriangle(vec3_t pos1, vec3_t pos2, vec3_t p1, vec3_t p2, vec3_t p3);
  56. bool linesegmentIntersectsTriangle(vec3_t pos1, vec3_t pos2, vec3_t p1, vec3_t p2, vec3_t p3, float* distance, vec3_t hitpoint);
  57. bool linesegmentIntersectsSphere(vec3_t pos1, vec3_t pos2, vec3_t center, float radius);
  58. bool linesegmentIntersectsSphere(vec3_t pos1, vec3_t pos2, vec3_t center, float radius, float* distance, vec3_t hitpoint);
  59. bool linesegmentIntersectsCube(vec3_t pos1, vec3_t pos2, vec3_t center, float edgelength);
  60. bool linesegmentIntersectsCube(vec3_t pos1, vec3_t pos2, vec3_t center, float edgelength, float* distance, vec3_t hitpoint);
  61. bool linesegmentIntersectsBox(vec3_t pos1, vec3_t pos2, vec3_t center, vec3_t edgelengths);
  62. bool linesegmentIntersectsBox(vec3_t pos1, vec3_t pos2, vec3_t center, vec3_t edgelengths, float* distance, vec3_t hitpoint);
  63. bool linesegmentIntersectsAABB(vec3_t pos1, vec3_t pos2, vec3_t min, vec3_t max);
  64. bool linesegmentIntersectsAABB(vec3_t pos1, vec3_t pos2, vec3_t min, vec3_t max, float* distance, vec3_t hitpoint);
  65.  
  66. bool rayIntersectsPlane(vec3_t pos, vec3_t dir, vec4_t plane);
  67. bool rayIntersectsPlane(vec3_t pos, vec3_t dir, vec4_t plane, float* distance, vec3_t hitpoint);
  68. bool rayIntersectsTriangle(vec3_t pos, vec3_t dir, vec3_t p1, vec3_t p2, vec3_t p3);
  69. bool rayIntersectsTriangle(vec3_t pos, vec3_t dir, vec3_t p1, vec3_t p2, vec3_t p3, float* distance, vec3_t hitpoint);
  70. bool rayIntersectsSphere(vec3_t pos, vec3_t dir, vec3_t center, float radius);
  71. bool rayIntersectsSphere(vec3_t pos, vec3_t dir, vec3_t center, float radius, float* distance, vec3_t hitpoint);
  72. bool rayIntersectsCube(vec3_t pos, vec3_t dir, vec3_t center, float edgelength);
  73. bool rayIntersectsCube(vec3_t pos, vec3_t dir, vec3_t center, float edgelength, float* distance, vec3_t hitpoint);
  74. bool rayIntersectsBox(vec3_t pos, vec3_t dir, vec3_t center, vec3_t edgelengths);
  75. bool rayIntersectsBox(vec3_t pos, vec3_t dir, vec3_t center, vec3_t edgelengths, float* distance, vec3_t hitpoint);
  76. bool rayIntersectsAABB(vec3_t pos, vec3_t dir, vec3_t min, vec3_t max);
  77. bool rayIntersectsAABB(vec3_t pos, vec3_t dir, vec3_t min, vec3_t max, float* distance, vec3_t hitpoint);
  78.  
  79. bool triangleIntersectsTriangle(vec3_t p1_1, vec3_t p1_2, vec3_t p1_3, vec3_t p2_1, vec3_t p2_2, vec3_t p2_3);
  80. bool triangleIntersectsSphere(vec3_t p1, vec3_t p2, vec3_t p3, vec3_t center, float radius);
  81. bool triangleIntersectsCube(vec3_t p1, vec3_t p2, vec3_t p3, vec3_t center, float edgelength);
  82. bool triangleIntersectsBox(vec3_t p1, vec3_t p2, vec3_t p3, vec3_t center, vec3_t edgelengths);
  83. bool triangleIntersectsAABB(vec3_t p1, vec3_t p2, vec3_t p3, vec3_t min, vec3_t max);
  84. bool triangleIntersectsCylinder(vec3_t p1, vec3_t p2, vec3_t p3, vec3_t center, float radius, float height);
  85.  
  86. bool sphereIntersectsSphere(vec3_t center1, float radius1, vec3_t center2, float radius2);
  87.  
  88. bool cylinderIntersectsCylinder(vec3_t center1, float radius1, float height1, vec3_t center2, float radius2, float height2);
  89.  
  90. bool AABBIntersectsAABB(vec3_t min1, vec3_t max1, vec3_t min2, vec3_t max2);
  91.  
  92. #endif    /* __intersection_h__ */
  93.