PageRenderTime 16ms CodeModel.GetById 2ms app.highlight 11ms 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
  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
 27#ifndef LL_RAYTRACE_H
 28#define LL_RAYTRACE_H
 29
 30class LLVector3;
 31class LLQuaternion;
 32
 33// All functions produce results in the same reference frame as the arguments.
 34//
 35// Any arguments of the form "foo_direction" or "foo_normal" are assumed to
 36// be normalized, or normalized vectors are stored in them.
 37//
 38// Vector arguments of the form "shape_scale" represent the scale of the
 39// object along the three axes.
 40//
 41// All functions return the expected TRUE or FALSE, unless otherwise noted.
 42// When FALSE is returned, any resulting values that might have been stored 
 43// are undefined.
 44//
 45// Rays are defined by a "ray_point" and a "ray_direction" (unit).
 46//
 47// Lines are defined by a "line_point" and a "line_direction" (unit).
 48//
 49// Line segements are defined by "point_a" and "point_b", and for intersection
 50// purposes are assumed to point from "point_a" to "point_b".
 51//
 52// A ray is different from a line in that it starts at a point and extends
 53// in only one direction.
 54//
 55// Intersection normals always point outside the object, normal to the object's
 56// surface at the point of intersection.
 57//
 58// Object rotations passed as quaternions are expected to rotate from the 
 59// object's local frame to the absolute frame.  So, if "foo" is a vector in
 60// the object's local frame, then "foo * object_rotation" is in the absolute
 61// frame.
 62
 63
 64// returns TRUE iff line is not parallel to plane.
 65BOOL line_plane(const LLVector3 &line_point, const LLVector3 &line_direction, 
 66				const LLVector3 &plane_point, const LLVector3 plane_normal, 
 67				LLVector3 &intersection);
 68
 69
 70// returns TRUE iff line is not parallel to plane.
 71BOOL ray_plane(const LLVector3 &ray_point, const LLVector3 &ray_direction, 
 72			   const LLVector3 &plane_point, const LLVector3 plane_normal, 
 73			   LLVector3 &intersection);
 74
 75
 76BOOL ray_circle(const LLVector3 &ray_point, const LLVector3 &ray_direction, 
 77				const LLVector3 &circle_center, const LLVector3 plane_normal, F32 circle_radius,
 78				LLVector3 &intersection);
 79
 80// point_0 through point_2 define the plane_normal via the right-hand rule:
 81// circle from point_0 to point_2 with fingers ==> thumb points in direction of normal
 82BOOL ray_triangle(const LLVector3 &ray_point, const LLVector3 &ray_direction, 
 83				  const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2, 
 84				  LLVector3 &intersection, LLVector3 &intersection_normal);
 85
 86
 87// point_0 is the lower-left corner, point_1 is the lower-right, point_2 is the upper-right
 88// right-hand-rule... curl fingers from lower-left toward lower-right then toward upper-right
 89// ==> thumb points in direction of normal
 90// assumes a parallelogram, so point_3 is determined by the other points
 91BOOL ray_quadrangle(const LLVector3 &ray_point, const LLVector3 &ray_direction, 
 92					const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2, 
 93					LLVector3 &intersection, LLVector3 &intersection_normal);
 94
 95
 96BOOL ray_sphere(const LLVector3 &ray_point, const LLVector3 &ray_direction,
 97				const LLVector3 &sphere_center, F32 sphere_radius,
 98				LLVector3 &intersection, LLVector3 &intersection_normal);
 99
100
101// finite right cylinder is defined by end centers: "cyl_top", "cyl_bottom", 
102// and by the cylinder radius "cyl_radius"
103BOOL ray_cylinder(const LLVector3 &ray_point, const LLVector3 &ray_direction,
104		          const LLVector3 &cyl_center, const LLVector3 &cyl_scale, const LLQuaternion &cyl_rotation,
105				  LLVector3 &intersection, LLVector3 &intersection_normal);
106
107
108// this function doesn't just return a BOOL because the return is currently
109// used to decide how to break up boxes that have been hit by shots... 
110// a hack that will probably be changed later
111//
112// returns a number representing the side of the box that was hit by the ray,
113// or NO_SIDE if intersection test failed.
114U32 ray_box(const LLVector3 &ray_point, const LLVector3 &ray_direction,
115		    const LLVector3 &box_center, const LLVector3 &box_scale, const LLQuaternion &box_rotation,
116			LLVector3 &intersection, LLVector3 &intersection_normal);
117
118
119/* TODO
120BOOL ray_ellipsoid(const LLVector3 &ray_point, const LLVector3 &ray_direction,
121				   const LLVector3 &e_center, const LLVector3 &e_scale, const LLQuaternion &e_rotation,
122				   LLVector3 &intersection, LLVector3 &intersection_normal);
123
124
125BOOL ray_cone(const LLVector3 &ray_point, const LLVector3 &ray_direction,
126			  const LLVector3 &cone_tip, const LLVector3 &cone_bottom, 
127			  const LLVector3 &cone_scale, const LLQuaternion &cone_rotation,
128			  LLVector3 &intersection, LLVector3 &intersection_normal);
129*/
130
131
132BOOL ray_prism(const LLVector3 &ray_point, const LLVector3 &ray_direction,
133			   const LLVector3 &prism_center, const LLVector3 &prism_scale, const LLQuaternion &prism_rotation,
134			   LLVector3 &intersection, LLVector3 &intersection_normal);
135
136
137BOOL ray_tetrahedron(const LLVector3 &ray_point, const LLVector3 &ray_direction,
138					 const LLVector3 &t_center, const LLVector3 &t_scale, const LLQuaternion &t_rotation,
139					 LLVector3 &intersection, LLVector3 &intersection_normal);
140
141
142BOOL ray_pyramid(const LLVector3 &ray_point, const LLVector3 &ray_direction,
143				 const LLVector3 &p_center, const LLVector3 &p_scale, const LLQuaternion &p_rotation,
144				 LLVector3 &intersection, LLVector3 &intersection_normal);
145
146
147
148/* TODO
149BOOL ray_hemiellipsoid(const LLVector3 &ray_point, const LLVector3 &ray_direction,
150					   const LLVector3 &e_center, const LLVector3 &e_scale, const LLQuaternion &e_rotation,
151					   const LLVector3 &e_cut_normal,
152					   LLVector3 &intersection, LLVector3 &intersection_normal);
153
154
155BOOL ray_hemisphere(const LLVector3 &ray_point, const LLVector3 &ray_direction,
156					const LLVector3 &sphere_center, F32 sphere_radius, const LLVector3 &sphere_cut_normal, 
157					LLVector3 &intersection, LLVector3 &intersection_normal);
158
159
160BOOL ray_hemicylinder(const LLVector3 &ray_point, const LLVector3 &ray_direction,
161					  const LLVector3 &cyl_top, const LLVector3 &cyl_bottom, F32 cyl_radius, 
162					  const LLVector3 &cyl_cut_normal,
163					  LLVector3 &intersection, LLVector3 &intersection_normal);
164
165
166BOOL ray_hemicone(const LLVector3 &ray_point, const LLVector3 &ray_direction,
167				  const LLVector3 &cone_tip, const LLVector3 &cone_bottom, 
168				  const LLVector3 &cone_scale, const LLVector3 &cyl_cut_normal,
169				  LLVector3 &intersection, LLVector3 &intersection_normal);
170*/
171
172
173BOOL linesegment_circle(const LLVector3 &point_a, const LLVector3 &point_b, 
174						const LLVector3 &circle_center, const LLVector3 plane_normal, F32 circle_radius,
175						LLVector3 &intersection);
176
177// point_0 through point_2 define the plane_normal via the right-hand rule:
178// circle from point_0 to point_2 with fingers ==> thumb points in direction of normal
179BOOL linesegment_triangle(const LLVector3 &point_a, const LLVector3 &point_b, 
180						  const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2, 
181						  LLVector3 &intersection, LLVector3 &intersection_normal);
182
183
184// point_0 is the lower-left corner, point_1 is the lower-right, point_2 is the upper-right
185// right-hand-rule... curl fingers from lower-left toward lower-right then toward upper-right
186// ==> thumb points in direction of normal
187// assumes a parallelogram, so point_3 is determined by the other points
188BOOL linesegment_quadrangle(const LLVector3 &point_a, const LLVector3 &point_b, 
189							const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2, 
190							LLVector3 &intersection, LLVector3 &intersection_normal);
191
192
193BOOL linesegment_sphere(const LLVector3 &point_a, const LLVector3 &point_b,
194				const LLVector3 &sphere_center, F32 sphere_radius,
195				LLVector3 &intersection, LLVector3 &intersection_normal);
196
197
198// finite right cylinder is defined by end centers: "cyl_top", "cyl_bottom", 
199// and by the cylinder radius "cyl_radius"
200BOOL linesegment_cylinder(const LLVector3 &point_a, const LLVector3 &point_b,
201						  const LLVector3 &cyl_center, const LLVector3 &cyl_scale, const LLQuaternion &cyl_rotation,
202						  LLVector3 &intersection, LLVector3 &intersection_normal);
203
204
205// this function doesn't just return a BOOL because the return is currently
206// used to decide how to break up boxes that have been hit by shots... 
207// a hack that will probably be changed later
208//
209// returns a number representing the side of the box that was hit by the ray,
210// or NO_SIDE if intersection test failed.
211U32 linesegment_box(const LLVector3 &point_a, const LLVector3 &point_b, 
212					const LLVector3 &box_center, const LLVector3 &box_scale, const LLQuaternion &box_rotation,
213					LLVector3 &intersection, LLVector3 &intersection_normal);
214
215
216BOOL linesegment_prism(const LLVector3 &point_a, const LLVector3 &point_b,
217					   const LLVector3 &prism_center, const LLVector3 &prism_scale, const LLQuaternion &prism_rotation,
218					   LLVector3 &intersection, LLVector3 &intersection_normal);
219
220
221BOOL linesegment_tetrahedron(const LLVector3 &point_a, const LLVector3 &point_b,
222							 const LLVector3 &t_center, const LLVector3 &t_scale, const LLQuaternion &t_rotation,
223							 LLVector3 &intersection, LLVector3 &intersection_normal);
224
225
226BOOL linesegment_pyramid(const LLVector3 &point_a, const LLVector3 &point_b,
227						 const LLVector3 &p_center, const LLVector3 &p_scale, const LLQuaternion &p_rotation,
228						 LLVector3 &intersection, LLVector3 &intersection_normal);
229
230
231#endif
232