PageRenderTime 14ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmath/raytrace.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 232 lines | 65 code | 49 blank | 118 comment | 0 complexity | b70d30a98f9b1f9485d658261a4b73c3 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file raytrace.h
  3. * @brief Ray intersection tests for primitives.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_RAYTRACE_H
  27. #define LL_RAYTRACE_H
  28. class LLVector3;
  29. class LLQuaternion;
  30. // All functions produce results in the same reference frame as the arguments.
  31. //
  32. // Any arguments of the form "foo_direction" or "foo_normal" are assumed to
  33. // be normalized, or normalized vectors are stored in them.
  34. //
  35. // Vector arguments of the form "shape_scale" represent the scale of the
  36. // object along the three axes.
  37. //
  38. // All functions return the expected TRUE or FALSE, unless otherwise noted.
  39. // When FALSE is returned, any resulting values that might have been stored
  40. // are undefined.
  41. //
  42. // Rays are defined by a "ray_point" and a "ray_direction" (unit).
  43. //
  44. // Lines are defined by a "line_point" and a "line_direction" (unit).
  45. //
  46. // Line segements are defined by "point_a" and "point_b", and for intersection
  47. // purposes are assumed to point from "point_a" to "point_b".
  48. //
  49. // A ray is different from a line in that it starts at a point and extends
  50. // in only one direction.
  51. //
  52. // Intersection normals always point outside the object, normal to the object's
  53. // surface at the point of intersection.
  54. //
  55. // Object rotations passed as quaternions are expected to rotate from the
  56. // object's local frame to the absolute frame. So, if "foo" is a vector in
  57. // the object's local frame, then "foo * object_rotation" is in the absolute
  58. // frame.
  59. // returns TRUE iff line is not parallel to plane.
  60. BOOL line_plane(const LLVector3 &line_point, const LLVector3 &line_direction,
  61. const LLVector3 &plane_point, const LLVector3 plane_normal,
  62. LLVector3 &intersection);
  63. // returns TRUE iff line is not parallel to plane.
  64. BOOL ray_plane(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  65. const LLVector3 &plane_point, const LLVector3 plane_normal,
  66. LLVector3 &intersection);
  67. BOOL ray_circle(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  68. const LLVector3 &circle_center, const LLVector3 plane_normal, F32 circle_radius,
  69. LLVector3 &intersection);
  70. // point_0 through point_2 define the plane_normal via the right-hand rule:
  71. // circle from point_0 to point_2 with fingers ==> thumb points in direction of normal
  72. BOOL ray_triangle(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  73. const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2,
  74. LLVector3 &intersection, LLVector3 &intersection_normal);
  75. // point_0 is the lower-left corner, point_1 is the lower-right, point_2 is the upper-right
  76. // right-hand-rule... curl fingers from lower-left toward lower-right then toward upper-right
  77. // ==> thumb points in direction of normal
  78. // assumes a parallelogram, so point_3 is determined by the other points
  79. BOOL ray_quadrangle(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  80. const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2,
  81. LLVector3 &intersection, LLVector3 &intersection_normal);
  82. BOOL ray_sphere(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  83. const LLVector3 &sphere_center, F32 sphere_radius,
  84. LLVector3 &intersection, LLVector3 &intersection_normal);
  85. // finite right cylinder is defined by end centers: "cyl_top", "cyl_bottom",
  86. // and by the cylinder radius "cyl_radius"
  87. BOOL ray_cylinder(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  88. const LLVector3 &cyl_center, const LLVector3 &cyl_scale, const LLQuaternion &cyl_rotation,
  89. LLVector3 &intersection, LLVector3 &intersection_normal);
  90. // this function doesn't just return a BOOL because the return is currently
  91. // used to decide how to break up boxes that have been hit by shots...
  92. // a hack that will probably be changed later
  93. //
  94. // returns a number representing the side of the box that was hit by the ray,
  95. // or NO_SIDE if intersection test failed.
  96. U32 ray_box(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  97. const LLVector3 &box_center, const LLVector3 &box_scale, const LLQuaternion &box_rotation,
  98. LLVector3 &intersection, LLVector3 &intersection_normal);
  99. /* TODO
  100. BOOL ray_ellipsoid(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  101. const LLVector3 &e_center, const LLVector3 &e_scale, const LLQuaternion &e_rotation,
  102. LLVector3 &intersection, LLVector3 &intersection_normal);
  103. BOOL ray_cone(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  104. const LLVector3 &cone_tip, const LLVector3 &cone_bottom,
  105. const LLVector3 &cone_scale, const LLQuaternion &cone_rotation,
  106. LLVector3 &intersection, LLVector3 &intersection_normal);
  107. */
  108. BOOL ray_prism(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  109. const LLVector3 &prism_center, const LLVector3 &prism_scale, const LLQuaternion &prism_rotation,
  110. LLVector3 &intersection, LLVector3 &intersection_normal);
  111. BOOL ray_tetrahedron(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  112. const LLVector3 &t_center, const LLVector3 &t_scale, const LLQuaternion &t_rotation,
  113. LLVector3 &intersection, LLVector3 &intersection_normal);
  114. BOOL ray_pyramid(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  115. const LLVector3 &p_center, const LLVector3 &p_scale, const LLQuaternion &p_rotation,
  116. LLVector3 &intersection, LLVector3 &intersection_normal);
  117. /* TODO
  118. BOOL ray_hemiellipsoid(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  119. const LLVector3 &e_center, const LLVector3 &e_scale, const LLQuaternion &e_rotation,
  120. const LLVector3 &e_cut_normal,
  121. LLVector3 &intersection, LLVector3 &intersection_normal);
  122. BOOL ray_hemisphere(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  123. const LLVector3 &sphere_center, F32 sphere_radius, const LLVector3 &sphere_cut_normal,
  124. LLVector3 &intersection, LLVector3 &intersection_normal);
  125. BOOL ray_hemicylinder(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  126. const LLVector3 &cyl_top, const LLVector3 &cyl_bottom, F32 cyl_radius,
  127. const LLVector3 &cyl_cut_normal,
  128. LLVector3 &intersection, LLVector3 &intersection_normal);
  129. BOOL ray_hemicone(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  130. const LLVector3 &cone_tip, const LLVector3 &cone_bottom,
  131. const LLVector3 &cone_scale, const LLVector3 &cyl_cut_normal,
  132. LLVector3 &intersection, LLVector3 &intersection_normal);
  133. */
  134. BOOL linesegment_circle(const LLVector3 &point_a, const LLVector3 &point_b,
  135. const LLVector3 &circle_center, const LLVector3 plane_normal, F32 circle_radius,
  136. LLVector3 &intersection);
  137. // point_0 through point_2 define the plane_normal via the right-hand rule:
  138. // circle from point_0 to point_2 with fingers ==> thumb points in direction of normal
  139. BOOL linesegment_triangle(const LLVector3 &point_a, const LLVector3 &point_b,
  140. const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2,
  141. LLVector3 &intersection, LLVector3 &intersection_normal);
  142. // point_0 is the lower-left corner, point_1 is the lower-right, point_2 is the upper-right
  143. // right-hand-rule... curl fingers from lower-left toward lower-right then toward upper-right
  144. // ==> thumb points in direction of normal
  145. // assumes a parallelogram, so point_3 is determined by the other points
  146. BOOL linesegment_quadrangle(const LLVector3 &point_a, const LLVector3 &point_b,
  147. const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2,
  148. LLVector3 &intersection, LLVector3 &intersection_normal);
  149. BOOL linesegment_sphere(const LLVector3 &point_a, const LLVector3 &point_b,
  150. const LLVector3 &sphere_center, F32 sphere_radius,
  151. LLVector3 &intersection, LLVector3 &intersection_normal);
  152. // finite right cylinder is defined by end centers: "cyl_top", "cyl_bottom",
  153. // and by the cylinder radius "cyl_radius"
  154. BOOL linesegment_cylinder(const LLVector3 &point_a, const LLVector3 &point_b,
  155. const LLVector3 &cyl_center, const LLVector3 &cyl_scale, const LLQuaternion &cyl_rotation,
  156. LLVector3 &intersection, LLVector3 &intersection_normal);
  157. // this function doesn't just return a BOOL because the return is currently
  158. // used to decide how to break up boxes that have been hit by shots...
  159. // a hack that will probably be changed later
  160. //
  161. // returns a number representing the side of the box that was hit by the ray,
  162. // or NO_SIDE if intersection test failed.
  163. U32 linesegment_box(const LLVector3 &point_a, const LLVector3 &point_b,
  164. const LLVector3 &box_center, const LLVector3 &box_scale, const LLQuaternion &box_rotation,
  165. LLVector3 &intersection, LLVector3 &intersection_normal);
  166. BOOL linesegment_prism(const LLVector3 &point_a, const LLVector3 &point_b,
  167. const LLVector3 &prism_center, const LLVector3 &prism_scale, const LLQuaternion &prism_rotation,
  168. LLVector3 &intersection, LLVector3 &intersection_normal);
  169. BOOL linesegment_tetrahedron(const LLVector3 &point_a, const LLVector3 &point_b,
  170. const LLVector3 &t_center, const LLVector3 &t_scale, const LLQuaternion &t_rotation,
  171. LLVector3 &intersection, LLVector3 &intersection_normal);
  172. BOOL linesegment_pyramid(const LLVector3 &point_a, const LLVector3 &point_b,
  173. const LLVector3 &p_center, const LLVector3 &p_scale, const LLQuaternion &p_rotation,
  174. LLVector3 &intersection, LLVector3 &intersection_normal);
  175. #endif