PageRenderTime 117ms CodeModel.GetById 3ms app.highlight 106ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llmath/raytrace.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 1274 lines | 937 code | 134 blank | 203 comment | 152 complexity | 0a93002cc68a49502bd465c1102d0e49 MD5 | raw file
   1/** 
   2 * @file raytrace.cpp
   3 * @brief Functions called by box object scripts.
   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#include "linden_common.h"
  28
  29#include "math.h"
  30//#include "vmath.h"
  31#include "v3math.h"
  32#include "llquaternion.h"
  33#include "m3math.h"
  34#include "raytrace.h"
  35
  36
  37BOOL line_plane(const LLVector3 &line_point, const LLVector3 &line_direction,
  38				const LLVector3 &plane_point, const LLVector3 plane_normal, 
  39				LLVector3 &intersection)
  40{
  41	F32 N = line_direction * plane_normal;
  42	if (0.0f == N)
  43	{
  44		// line is perpendicular to plane normal
  45		// so it is either entirely on plane, or not on plane at all
  46		return FALSE;
  47	}
  48	// Ax + By, + Cz + D = 0
  49	// D = - (plane_point * plane_normal)
  50	// N = line_direction * plane_normal
  51	// intersection = line_point - ((D + plane_normal * line_point) / N) * line_direction
  52	intersection = line_point - ((plane_normal * line_point - plane_point * plane_normal) / N) * line_direction;
  53	return TRUE;
  54}
  55
  56
  57BOOL ray_plane(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  58			   const LLVector3 &plane_point, const LLVector3 plane_normal, 
  59			   LLVector3 &intersection)
  60{
  61	F32 N = ray_direction * plane_normal;
  62	if (0.0f == N)
  63	{
  64		// ray is perpendicular to plane normal
  65		// so it is either entirely on plane, or not on plane at all
  66		return FALSE;
  67	}
  68	// Ax + By, + Cz + D = 0
  69	// D = - (plane_point * plane_normal)
  70	// N = ray_direction * plane_normal
  71	// intersection = ray_point - ((D + plane_normal * ray_point) / N) * ray_direction
  72	F32 alpha = -(plane_normal * ray_point - plane_point * plane_normal) / N;
  73	if (alpha < 0.0f)
  74	{
  75		// ray points away from plane
  76		return FALSE;
  77	}
  78	intersection = ray_point + alpha * ray_direction;
  79	return TRUE;
  80}
  81
  82
  83BOOL ray_circle(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  84				const LLVector3 &circle_center, const LLVector3 plane_normal, F32 circle_radius,
  85				LLVector3 &intersection)
  86{
  87	if (ray_plane(ray_point, ray_direction, circle_center, plane_normal, intersection))
  88	{
  89		if (circle_radius >= (intersection - circle_center).magVec())
  90		{
  91			return TRUE;
  92		}
  93	}
  94	return FALSE;
  95}
  96
  97
  98BOOL ray_triangle(const LLVector3 &ray_point, const LLVector3 &ray_direction,
  99				  const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2, 
 100				  LLVector3 &intersection, LLVector3 &intersection_normal)
 101{
 102	LLVector3 side_01 = point_1 - point_0;
 103	LLVector3 side_12 = point_2 - point_1;
 104
 105	intersection_normal = side_01 % side_12;
 106	intersection_normal.normVec();
 107
 108	if (ray_plane(ray_point, ray_direction, point_0, intersection_normal, intersection))
 109	{
 110		LLVector3 side_20 = point_0 - point_2;
 111		if (intersection_normal * (side_01 % (intersection - point_0)) >= 0.0f  &&
 112			intersection_normal * (side_12 % (intersection - point_1)) >= 0.0f  &&
 113			intersection_normal * (side_20 % (intersection - point_2)) >= 0.0f)
 114		{
 115			return TRUE;
 116		}
 117	}
 118	return FALSE;
 119}
 120
 121
 122// assumes a parallelogram
 123BOOL ray_quadrangle(const LLVector3 &ray_point, const LLVector3 &ray_direction,
 124					const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2,
 125					LLVector3 &intersection, LLVector3 &intersection_normal)
 126{
 127	LLVector3 side_01 = point_1 - point_0;
 128	LLVector3 side_12 = point_2 - point_1;
 129
 130	intersection_normal = side_01 % side_12;
 131	intersection_normal.normVec();
 132
 133	if (ray_plane(ray_point, ray_direction, point_0, intersection_normal, intersection))
 134	{
 135		LLVector3 point_3 = point_0 + (side_12);
 136		LLVector3 side_23 = point_3 - point_2;
 137		LLVector3 side_30 = point_0 - point_3;
 138		if (intersection_normal * (side_01 % (intersection - point_0)) >= 0.0f  &&
 139			intersection_normal * (side_12 % (intersection - point_1)) >= 0.0f  &&
 140			intersection_normal * (side_23 % (intersection - point_2)) >= 0.0f  &&
 141			intersection_normal * (side_30 % (intersection - point_3)) >= 0.0f)
 142		{
 143			return TRUE;
 144		}
 145	}
 146	return FALSE;
 147}
 148
 149
 150BOOL ray_sphere(const LLVector3 &ray_point, const LLVector3 &ray_direction,
 151				const LLVector3 &sphere_center, F32 sphere_radius,
 152				LLVector3 &intersection, LLVector3 &intersection_normal)
 153{
 154	LLVector3 ray_to_sphere = sphere_center - ray_point;
 155	F32 dot = ray_to_sphere * ray_direction;
 156
 157	LLVector3 closest_approach = dot * ray_direction - ray_to_sphere;
 158
 159	F32 shortest_distance = closest_approach.magVecSquared();
 160	F32 radius_squared = sphere_radius * sphere_radius;
 161	if (shortest_distance > radius_squared)
 162	{
 163		return FALSE;
 164	}
 165
 166	F32 half_chord = (F32) sqrt(radius_squared - shortest_distance);
 167	closest_approach = sphere_center + closest_approach;			// closest_approach now in absolute coordinates
 168	intersection = closest_approach + half_chord * ray_direction;
 169	dot = ray_direction * (intersection - ray_point);
 170	if (dot < 0.0f)
 171	{
 172		// ray shoots away from sphere and is not inside it
 173		return FALSE;
 174	}
 175
 176	shortest_distance = ray_direction * ((closest_approach - half_chord * ray_direction) - ray_point);
 177	if (shortest_distance > 0.0f)
 178	{
 179		// ray enters sphere 
 180		intersection = intersection - (2.0f * half_chord) * ray_direction;
 181	}
 182	else
 183	{
 184		// do nothing
 185		// ray starts inside sphere and intersects as it leaves the sphere
 186	}
 187
 188	intersection_normal = intersection - sphere_center;
 189	if (sphere_radius > 0.0f)
 190	{
 191		intersection_normal *= 1.0f / sphere_radius;
 192	}
 193	else
 194	{
 195		intersection_normal.setVec(0.0f, 0.0f, 0.0f);
 196	}
 197	
 198	return TRUE;
 199}
 200
 201
 202BOOL ray_cylinder(const LLVector3 &ray_point, const LLVector3 &ray_direction,
 203				  const LLVector3 &cyl_center, const LLVector3 &cyl_scale, const LLQuaternion &cyl_rotation,
 204				  LLVector3 &intersection, LLVector3 &intersection_normal)
 205{
 206	// calculate the centers of the cylinder caps in the absolute frame
 207	LLVector3 cyl_top(0.0f, 0.0f, 0.5f * cyl_scale.mV[VZ]);
 208	LLVector3 cyl_bottom(0.0f, 0.0f, -cyl_top.mV[VZ]);
 209	cyl_top = (cyl_top * cyl_rotation) + cyl_center;
 210	cyl_bottom = (cyl_bottom * cyl_rotation) + cyl_center;
 211
 212	// we only handle cylinders with circular cross-sections at the moment
 213	F32 cyl_radius = 0.5f * llmax(cyl_scale.mV[VX], cyl_scale.mV[VY]);	// HACK until scaled cylinders are supported
 214
 215	// This implementation is based on the intcyl() function from Graphics_Gems_IV, page 361
 216	LLVector3   cyl_axis;								// axis direction (bottom toward top)
 217	LLVector3 	ray_to_cyl;								// ray_point to cyl_top
 218	F32 		shortest_distance;						// shortest distance from ray to axis
 219	F32 		cyl_length;
 220	LLVector3	shortest_direction;
 221	LLVector3	temp_vector;
 222
 223	cyl_axis = cyl_bottom - cyl_top;
 224	cyl_length = cyl_axis.normVec();
 225	ray_to_cyl = ray_point - cyl_bottom;
 226	shortest_direction = ray_direction % cyl_axis;
 227	shortest_distance = shortest_direction.normVec();	// recycle shortest_distance
 228
 229	// check for ray parallel to cylinder axis
 230	if (0.0f == shortest_distance)
 231	{
 232		// ray is parallel to cylinder axis
 233		temp_vector = ray_to_cyl - (ray_to_cyl * cyl_axis) * cyl_axis;
 234		shortest_distance = temp_vector.magVec();
 235		if (shortest_distance <= cyl_radius)
 236		{
 237			shortest_distance = ray_to_cyl * cyl_axis;
 238			F32 dot = ray_direction * cyl_axis;
 239
 240			if (shortest_distance > 0.0)
 241			{
 242			   	if (dot > 0.0f)
 243				{
 244					// ray points away from cylinder bottom
 245					return FALSE;
 246				}
 247				// ray hit bottom of cylinder from outside 
 248				intersection = ray_point - shortest_distance * cyl_axis;
 249				intersection_normal = cyl_axis;
 250
 251			}
 252			else if (shortest_distance > -cyl_length)
 253			{
 254				// ray starts inside cylinder
 255				if (dot < 0.0f)
 256				{
 257					// ray hit top from inside
 258					intersection = ray_point - (cyl_length + shortest_distance) * cyl_axis;
 259					intersection_normal = -cyl_axis;
 260				}
 261				else
 262				{
 263					// ray hit bottom from inside
 264					intersection = ray_point - shortest_distance * cyl_axis;
 265					intersection_normal = cyl_axis;
 266				}
 267			}
 268			else
 269			{
 270				if (dot < 0.0f)
 271				{
 272					// ray points away from cylinder bottom
 273					return FALSE;
 274				}
 275				// ray hit top from outside
 276				intersection = ray_point - (shortest_distance + cyl_length) * cyl_axis;
 277				intersection_normal = -cyl_axis;
 278			}
 279			return TRUE;
 280		}
 281		return FALSE;
 282	}
 283
 284	// check for intersection with infinite cylinder
 285	shortest_distance = (F32) fabs(ray_to_cyl * shortest_direction);
 286	if (shortest_distance <= cyl_radius)
 287	{
 288		F32 		dist_to_closest_point;				// dist from ray_point to closest_point
 289		F32 		half_chord_length;					// half length of intersection chord
 290		F32 		in, out;							// distances to entering/exiting points
 291		temp_vector = ray_to_cyl % cyl_axis;
 292		dist_to_closest_point = - (temp_vector * shortest_direction);
 293		temp_vector = shortest_direction % cyl_axis;
 294		temp_vector.normVec();
 295		half_chord_length = (F32) fabs( sqrt(cyl_radius*cyl_radius - shortest_distance * shortest_distance) /
 296							(ray_direction * temp_vector) );
 297
 298		out = dist_to_closest_point + half_chord_length;	// dist to exiting point
 299		if (out < 0.0f)
 300		{
 301			// cylinder is behind the ray, so we return FALSE
 302			return FALSE;
 303		}
 304
 305		in = dist_to_closest_point - half_chord_length;		// dist to entering point
 306		if (in < 0.0f)
 307		{
 308			// ray_point is inside the cylinder
 309			// so we store the exiting intersection
 310			intersection = ray_point + out * ray_direction;
 311			shortest_distance = out;
 312		}
 313		else
 314		{
 315			// ray hit cylinder from outside
 316			// so we store the entering intersection
 317			intersection = ray_point + in * ray_direction;
 318			shortest_distance = in;
 319		}
 320
 321		// calculate the normal at intersection
 322		if (0.0f == cyl_radius)
 323		{
 324			intersection_normal.setVec(0.0f, 0.0f, 0.0f);
 325		}
 326		else
 327		{
 328			temp_vector = intersection - cyl_bottom;	
 329			intersection_normal = temp_vector - (temp_vector * cyl_axis) * cyl_axis;
 330			intersection_normal.normVec();
 331		}
 332
 333		// check for intersection with end caps
 334		// calculate intersection of ray and top plane
 335		if (line_plane(ray_point, ray_direction, cyl_top, -cyl_axis, temp_vector))	// NOTE side-effect: changing temp_vector
 336		{
 337			shortest_distance = (temp_vector - ray_point).magVec();
 338			if ( (ray_direction * cyl_axis) > 0.0f)
 339			{
 340				// ray potentially enters the cylinder at top
 341				if (shortest_distance > out)
 342				{
 343					// ray missed the finite cylinder
 344					return FALSE;
 345				}
 346				if (shortest_distance > in)
 347				{
 348					// ray intersects cylinder at top plane
 349					intersection = temp_vector;
 350					intersection_normal = -cyl_axis;
 351					return TRUE;
 352				}
 353			}
 354			else
 355			{
 356				// ray potentially exits the cylinder at top
 357				if (shortest_distance < in)
 358				{
 359					// missed the finite cylinder
 360					return FALSE;
 361				}
 362			}
 363
 364			// calculate intersection of ray and bottom plane
 365			line_plane(ray_point, ray_direction, cyl_bottom, cyl_axis, temp_vector); // NOTE side-effect: changing temp_vector
 366			shortest_distance = (temp_vector - ray_point).magVec();
 367			if ( (ray_direction * cyl_axis) < 0.0)
 368			{
 369				// ray potentially enters the cylinder at bottom
 370				if (shortest_distance > out)
 371				{
 372					// ray missed the finite cylinder
 373					return FALSE;
 374				}
 375				if (shortest_distance > in)
 376				{
 377					// ray intersects cylinder at bottom plane
 378					intersection = temp_vector;
 379					intersection_normal = cyl_axis;
 380					return TRUE;
 381				}
 382			}
 383			else
 384			{
 385				// ray potentially exits the cylinder at bottom
 386				if (shortest_distance < in)
 387				{
 388					// ray missed the finite cylinder
 389					return FALSE;
 390				}
 391			}
 392
 393		}
 394		else
 395		{
 396			// ray is parallel to end cap planes
 397			temp_vector = cyl_bottom - ray_point;
 398			shortest_distance = temp_vector * cyl_axis;
 399			if (shortest_distance < 0.0f  ||  shortest_distance > cyl_length)
 400			{
 401				// ray missed finite cylinder
 402				return FALSE;
 403			}
 404		}
 405
 406		return TRUE;
 407	}
 408
 409	return FALSE;
 410}
 411
 412
 413U32 ray_box(const LLVector3 &ray_point, const LLVector3 &ray_direction, 
 414			const LLVector3 &box_center, const LLVector3 &box_scale, const LLQuaternion &box_rotation,
 415			LLVector3 &intersection, LLVector3 &intersection_normal)
 416{
 417
 418	// Need to rotate into box frame
 419	LLQuaternion into_box_frame(box_rotation);		// rotates things from box frame to absolute
 420	into_box_frame.conjQuat();						// now rotates things into box frame
 421	LLVector3 line_point = (ray_point - box_center) * into_box_frame;
 422	LLVector3 line_direction = ray_direction * into_box_frame;
 423
 424	// Suppose we have a plane:  Ax + By + Cz + D = 0
 425	// then, assuming [A, B, C] is a unit vector:
 426	//
 427	//    plane_normal = [A, B, C] 
 428	//    D = - (plane_normal * plane_point)
 429	// 
 430	// Suppose we have a line:  X = line_point + alpha * line_direction
 431	//
 432	// the intersection of the plane and line determines alpha
 433	//
 434	//    alpha = - (D + plane_normal * line_point) / (plane_normal * line_direction)
 435
 436	LLVector3 line_plane_intersection;
 437
 438	F32 pointX = line_point.mV[VX];
 439	F32 pointY = line_point.mV[VY];
 440	F32 pointZ = line_point.mV[VZ];
 441
 442	F32 dirX = line_direction.mV[VX];
 443	F32 dirY = line_direction.mV[VY];
 444	F32 dirZ = line_direction.mV[VZ];
 445
 446	// we'll be using the half-scales of the box
 447	F32 boxX = 0.5f * box_scale.mV[VX];
 448	F32 boxY = 0.5f * box_scale.mV[VY];
 449	F32 boxZ = 0.5f * box_scale.mV[VZ];
 450
 451	// check to see if line_point is OUTSIDE the box
 452	if (pointX < -boxX ||
 453		pointX >  boxX ||
 454		pointY < -boxY ||
 455		pointY >  boxY ||
 456		pointZ < -boxZ ||
 457		pointZ >  boxZ) 
 458	{
 459		// -------------- point is OUTSIDE the box ----------------
 460
 461		// front
 462		if (pointX > 0.0f  &&  dirX < 0.0f)
 463		{
 464			// plane_normal                = [ 1, 0, 0]
 465			// plane_normal*line_point     = pointX
 466			// plane_normal*line_direction = dirX
 467			// D                           = -boxX
 468			// alpha                       = - (-boxX + pointX) / dirX
 469			line_plane_intersection = line_point - ((pointX - boxX) / dirX) * line_direction;
 470			if (line_plane_intersection.mV[VY] <  boxY &&
 471				line_plane_intersection.mV[VY] > -boxY &&
 472				line_plane_intersection.mV[VZ] <  boxZ &&
 473				line_plane_intersection.mV[VZ] > -boxZ )
 474			{
 475				intersection = (line_plane_intersection * box_rotation) + box_center;
 476				intersection_normal = LLVector3(1.0f, 0.0f, 0.0f) * box_rotation;
 477				return FRONT_SIDE;
 478			}
 479		}
 480	
 481		// back
 482		if (pointX < 0.0f  &&  dirX > 0.0f)
 483		{
 484			// plane_normal                = [ -1, 0, 0]
 485			// plane_normal*line_point     = -pX 
 486			// plane_normal*line_direction = -direction.mV[VX]
 487			// D                           = -bX
 488			// alpha                       = - (-bX - pX) / (-dirX)
 489			line_plane_intersection = line_point - ((boxX + pointX)/ dirX) * line_direction;
 490			if (line_plane_intersection.mV[VY] <  boxY &&
 491				line_plane_intersection.mV[VY] > -boxY &&
 492				line_plane_intersection.mV[VZ] <  boxZ &&
 493				line_plane_intersection.mV[VZ] > -boxZ )
 494			{
 495				intersection = (line_plane_intersection * box_rotation) + box_center;
 496				intersection_normal = LLVector3(-1.0f, 0.0f, 0.0f) * box_rotation;
 497				return BACK_SIDE;
 498			}
 499		}
 500	
 501		// left
 502		if (pointY > 0.0f  &&  dirY < 0.0f)
 503		{
 504			// plane_normal                = [0, 1, 0]
 505			// plane_normal*line_point     = pointY 
 506			// plane_normal*line_direction = dirY
 507			// D                           = -boxY
 508			// alpha                       = - (-boxY + pointY) / dirY
 509			line_plane_intersection = line_point + ((boxY - pointY)/dirY) * line_direction;
 510
 511			if (line_plane_intersection.mV[VX] <  boxX &&
 512				line_plane_intersection.mV[VX] > -boxX &&
 513				line_plane_intersection.mV[VZ] <  boxZ &&
 514				line_plane_intersection.mV[VZ] > -boxZ )
 515			{
 516				intersection = (line_plane_intersection * box_rotation) + box_center;
 517				intersection_normal = LLVector3(0.0f, 1.0f, 0.0f) * box_rotation;
 518				return LEFT_SIDE;
 519			}
 520		}
 521	
 522		// right
 523		if (pointY < 0.0f  &&  dirY > 0.0f)
 524		{
 525			// plane_normal                = [0, -1, 0]
 526			// plane_normal*line_point     = -pointY 
 527			// plane_normal*line_direction = -dirY
 528			// D                           = -boxY
 529			// alpha                       = - (-boxY - pointY) / (-dirY)
 530			line_plane_intersection = line_point - ((boxY + pointY)/dirY) * line_direction;
 531			if (line_plane_intersection.mV[VX] <  boxX &&
 532				line_plane_intersection.mV[VX] > -boxX &&
 533				line_plane_intersection.mV[VZ] <  boxZ &&
 534				line_plane_intersection.mV[VZ] > -boxZ )
 535			{
 536				intersection = (line_plane_intersection * box_rotation) + box_center;
 537				intersection_normal = LLVector3(0.0f, -1.0f, 0.0f) * box_rotation;
 538				return RIGHT_SIDE;
 539			}
 540		}
 541	
 542		// top
 543		if (pointZ > 0.0f  &&  dirZ < 0.0f)
 544		{
 545			// plane_normal                = [0, 0, 1]
 546			// plane_normal*line_point     = pointZ 
 547			// plane_normal*line_direction = dirZ
 548			// D                           = -boxZ
 549			// alpha                       = - (-boxZ + pointZ) / dirZ
 550			line_plane_intersection = line_point - ((pointZ - boxZ)/dirZ) * line_direction;
 551			if (line_plane_intersection.mV[VX] <  boxX &&
 552				line_plane_intersection.mV[VX] > -boxX &&
 553				line_plane_intersection.mV[VY] <  boxY &&
 554				line_plane_intersection.mV[VY] > -boxY )
 555			{
 556				intersection = (line_plane_intersection * box_rotation) + box_center;
 557				intersection_normal = LLVector3(0.0f, 0.0f, 1.0f) * box_rotation;
 558				return TOP_SIDE;
 559			}
 560		}
 561	
 562		// bottom
 563		if (pointZ < 0.0f  &&  dirZ > 0.0f)
 564		{
 565			// plane_normal                = [0, 0, -1]
 566			// plane_normal*line_point     = -pointZ 
 567			// plane_normal*line_direction = -dirZ
 568			// D                           = -boxZ
 569			// alpha                       = - (-boxZ - pointZ) / (-dirZ)
 570			line_plane_intersection = line_point - ((boxZ + pointZ)/dirZ) * line_direction;
 571			if (line_plane_intersection.mV[VX] <  boxX &&
 572				line_plane_intersection.mV[VX] > -boxX &&
 573				line_plane_intersection.mV[VY] <  boxY &&
 574				line_plane_intersection.mV[VY] > -boxY )
 575			{
 576				intersection = (line_plane_intersection * box_rotation) + box_center;
 577				intersection_normal = LLVector3(0.0f, 0.0f, -1.0f) * box_rotation;
 578				return BOTTOM_SIDE;
 579			}
 580		}
 581		return NO_SIDE;
 582	}
 583
 584	// -------------- point is INSIDE the box ----------------
 585
 586	// front
 587	if (dirX > 0.0f)
 588	{
 589		// plane_normal                = [ 1, 0, 0]
 590		// plane_normal*line_point     = pointX
 591		// plane_normal*line_direction = dirX
 592		// D                           = -boxX
 593		// alpha                       = - (-boxX + pointX) / dirX
 594		line_plane_intersection = line_point - ((pointX - boxX) / dirX) * line_direction;
 595		if (line_plane_intersection.mV[VY] <  boxY &&
 596			line_plane_intersection.mV[VY] > -boxY &&
 597			line_plane_intersection.mV[VZ] <  boxZ &&
 598			line_plane_intersection.mV[VZ] > -boxZ )
 599		{
 600			intersection = (line_plane_intersection * box_rotation) + box_center;
 601			intersection_normal = LLVector3(1.0f, 0.0f, 0.0f) * box_rotation;
 602			return FRONT_SIDE;
 603		}
 604	}
 605
 606	// back
 607	if (dirX < 0.0f)
 608	{
 609		// plane_normal                = [ -1, 0, 0]
 610		// plane_normal*line_point     = -pX 
 611		// plane_normal*line_direction = -direction.mV[VX]
 612		// D                           = -bX
 613		// alpha                       = - (-bX - pX) / (-dirX)
 614		line_plane_intersection = line_point - ((boxX + pointX)/ dirX) * line_direction;
 615		if (line_plane_intersection.mV[VY] <  boxY &&
 616			line_plane_intersection.mV[VY] > -boxY &&
 617			line_plane_intersection.mV[VZ] <  boxZ &&
 618			line_plane_intersection.mV[VZ] > -boxZ )
 619		{
 620			intersection = (line_plane_intersection * box_rotation) + box_center;
 621			intersection_normal = LLVector3(-1.0f, 0.0f, 0.0f) * box_rotation;
 622			return BACK_SIDE;
 623		}
 624	}
 625
 626	// left
 627	if (dirY > 0.0f)
 628	{
 629		// plane_normal                = [0, 1, 0]
 630		// plane_normal*line_point     = pointY 
 631		// plane_normal*line_direction = dirY
 632		// D                           = -boxY
 633		// alpha                       = - (-boxY + pointY) / dirY
 634		line_plane_intersection = line_point + ((boxY - pointY)/dirY) * line_direction;
 635
 636		if (line_plane_intersection.mV[VX] <  boxX &&
 637			line_plane_intersection.mV[VX] > -boxX &&
 638			line_plane_intersection.mV[VZ] <  boxZ &&
 639			line_plane_intersection.mV[VZ] > -boxZ )
 640		{
 641			intersection = (line_plane_intersection * box_rotation) + box_center;
 642			intersection_normal = LLVector3(0.0f, 1.0f, 0.0f) * box_rotation;
 643			return LEFT_SIDE;
 644		}
 645	}
 646
 647	// right
 648	if (dirY < 0.0f)
 649	{
 650		// plane_normal                = [0, -1, 0]
 651		// plane_normal*line_point     = -pointY 
 652		// plane_normal*line_direction = -dirY
 653		// D                           = -boxY
 654		// alpha                       = - (-boxY - pointY) / (-dirY)
 655		line_plane_intersection = line_point - ((boxY + pointY)/dirY) * line_direction;
 656		if (line_plane_intersection.mV[VX] <  boxX &&
 657			line_plane_intersection.mV[VX] > -boxX &&
 658			line_plane_intersection.mV[VZ] <  boxZ &&
 659			line_plane_intersection.mV[VZ] > -boxZ )
 660		{
 661			intersection = (line_plane_intersection * box_rotation) + box_center;
 662			intersection_normal = LLVector3(0.0f, -1.0f, 0.0f) * box_rotation;
 663			return RIGHT_SIDE;
 664		}
 665	}
 666
 667	// top
 668	if (dirZ > 0.0f)
 669	{
 670		// plane_normal                = [0, 0, 1]
 671		// plane_normal*line_point     = pointZ 
 672		// plane_normal*line_direction = dirZ
 673		// D                           = -boxZ
 674		// alpha                       = - (-boxZ + pointZ) / dirZ
 675		line_plane_intersection = line_point - ((pointZ - boxZ)/dirZ) * line_direction;
 676		if (line_plane_intersection.mV[VX] <  boxX &&
 677			line_plane_intersection.mV[VX] > -boxX &&
 678			line_plane_intersection.mV[VY] <  boxY &&
 679			line_plane_intersection.mV[VY] > -boxY )
 680		{
 681			intersection = (line_plane_intersection * box_rotation) + box_center;
 682			intersection_normal = LLVector3(0.0f, 0.0f, 1.0f) * box_rotation;
 683			return TOP_SIDE;
 684		}
 685	}
 686
 687	// bottom
 688	if (dirZ < 0.0f)
 689	{
 690		// plane_normal                = [0, 0, -1]
 691		// plane_normal*line_point     = -pointZ 
 692		// plane_normal*line_direction = -dirZ
 693		// D                           = -boxZ
 694		// alpha                       = - (-boxZ - pointZ) / (-dirZ)
 695		line_plane_intersection = line_point - ((boxZ + pointZ)/dirZ) * line_direction;
 696		if (line_plane_intersection.mV[VX] <  boxX &&
 697			line_plane_intersection.mV[VX] > -boxX &&
 698			line_plane_intersection.mV[VY] <  boxY &&
 699			line_plane_intersection.mV[VY] > -boxY )
 700		{
 701			intersection = (line_plane_intersection * box_rotation) + box_center;
 702			intersection_normal = LLVector3(0.0f, 0.0f, -1.0f) * box_rotation;
 703			return BOTTOM_SIDE;
 704		}
 705	}
 706
 707	// should never get here unless line instersects at tangent point on edge or corner
 708	// however such cases will be EXTREMELY rare
 709	return NO_SIDE;
 710}
 711
 712
 713BOOL ray_prism(const LLVector3 &ray_point, const LLVector3 &ray_direction,
 714			   const LLVector3 &prism_center, const LLVector3 &prism_scale, const LLQuaternion &prism_rotation,
 715			   LLVector3 &intersection, LLVector3 &intersection_normal)
 716{
 717	//      (0)              Z  
 718	//      /| \             .  
 719	//    (1)|  \           /|\  _.Y
 720	//     | \   \           |   /|
 721	//     | |\   \          |  /
 722	//     | | \(0)\         | / 
 723	//     | |  \   \        |/
 724	//     | |   \   \      (*)----> X  
 725	//     |(3)---\---(2)      
 726	//     |/      \  /        
 727	//    (4)-------(5)        
 728
 729	// need to calculate the points of the prism so we can run ray tests with each face
 730	F32 x = prism_scale.mV[VX];
 731	F32 y = prism_scale.mV[VY];
 732	F32 z = prism_scale.mV[VZ];
 733
 734	F32 tx = x * 2.0f / 3.0f;
 735	F32 ty = y * 0.5f;
 736	F32 tz = z * 2.0f / 3.0f;
 737
 738	LLVector3 point0(tx-x,  ty, tz);
 739	LLVector3 point1(tx-x, -ty, tz);
 740	LLVector3 point2(tx,    ty, tz-z);
 741	LLVector3 point3(tx-x,  ty, tz-z);
 742	LLVector3 point4(tx-x, -ty, tz-z);
 743	LLVector3 point5(tx,   -ty, tz-z);
 744
 745	// transform these points into absolute frame
 746	point0 = (point0 * prism_rotation) + prism_center;
 747	point1 = (point1 * prism_rotation) + prism_center;
 748	point2 = (point2 * prism_rotation) + prism_center;
 749	point3 = (point3 * prism_rotation) + prism_center;
 750	point4 = (point4 * prism_rotation) + prism_center;
 751	point5 = (point5 * prism_rotation) + prism_center;
 752
 753	// test ray intersection for each face
 754	BOOL b_hit = FALSE;
 755	LLVector3 face_intersection, face_normal;
 756	F32 distance_squared = 0.0f;
 757	F32 temp;
 758
 759	// face 0
 760	if (ray_direction * ( (point0 - point2) % (point5 - point2)) < 0.0f  && 
 761		ray_quadrangle(ray_point, ray_direction, point5, point2, point0, intersection, intersection_normal))
 762	{
 763		distance_squared = (ray_point - intersection).magVecSquared();
 764		b_hit = TRUE;
 765	}
 766
 767	// face 1
 768	if (ray_direction * ( (point0 - point3) % (point2 - point3)) < 0.0f  &&
 769		ray_triangle(ray_point, ray_direction, point2, point3, point0, face_intersection, face_normal))
 770	{
 771		if (TRUE == b_hit)
 772		{
 773			temp = (ray_point - face_intersection).magVecSquared();
 774			if (temp < distance_squared)
 775			{
 776				distance_squared = temp;
 777				intersection = face_intersection;
 778				intersection_normal = face_normal;
 779			}
 780		}
 781		else 
 782		{
 783			distance_squared = (ray_point - face_intersection).magVecSquared();
 784			intersection = face_intersection;
 785			intersection_normal = face_normal;
 786			b_hit = TRUE;
 787		}
 788	}
 789	
 790	// face 2
 791	if (ray_direction * ( (point1 - point4) % (point3 - point4)) < 0.0f  &&
 792		ray_quadrangle(ray_point, ray_direction, point3, point4, point1, face_intersection, face_normal))
 793	{
 794		if (TRUE == b_hit)
 795		{
 796			temp = (ray_point - face_intersection).magVecSquared();
 797			if (temp < distance_squared)
 798			{
 799				distance_squared = temp;
 800				intersection = face_intersection;
 801				intersection_normal = face_normal;
 802			}
 803		}
 804		else 
 805		{
 806			distance_squared = (ray_point - face_intersection).magVecSquared();
 807			intersection = face_intersection;
 808			intersection_normal = face_normal;
 809			b_hit = TRUE;
 810		}
 811	}
 812	
 813	// face 3
 814	if (ray_direction * ( (point5 - point4) % (point1 - point4)) < 0.0f  &&
 815		ray_triangle(ray_point, ray_direction, point1, point4, point5, face_intersection, face_normal))
 816	{
 817		if (TRUE == b_hit)
 818		{
 819			temp = (ray_point - face_intersection).magVecSquared();
 820			if (temp < distance_squared)
 821			{
 822				distance_squared = temp;
 823				intersection = face_intersection;
 824				intersection_normal = face_normal;
 825			}
 826		}
 827		else 
 828		{
 829			distance_squared = (ray_point - face_intersection).magVecSquared();
 830			intersection = face_intersection;
 831			intersection_normal = face_normal;
 832			b_hit = TRUE;
 833		}
 834	}
 835
 836	// face 4
 837	if (ray_direction * ( (point4 - point5) % (point2 - point5)) < 0.0f  &&
 838		ray_quadrangle(ray_point, ray_direction, point2, point5, point4, face_intersection, face_normal))
 839	{
 840		if (TRUE == b_hit)
 841		{
 842			temp = (ray_point - face_intersection).magVecSquared();
 843			if (temp < distance_squared)
 844			{
 845				distance_squared = temp;
 846				intersection = face_intersection;
 847				intersection_normal = face_normal;
 848			}
 849		}
 850		else 
 851		{
 852			distance_squared = (ray_point - face_intersection).magVecSquared();
 853			intersection = face_intersection;
 854			intersection_normal = face_normal;
 855			b_hit = TRUE;
 856		}
 857	}
 858
 859	return b_hit;
 860}
 861
 862
 863BOOL ray_tetrahedron(const LLVector3 &ray_point, const LLVector3 &ray_direction,
 864					 const LLVector3 &t_center, const LLVector3 &t_scale, const LLQuaternion &t_rotation,
 865					 LLVector3 &intersection, LLVector3 &intersection_normal)
 866{
 867	F32 a = 0.5f * F_SQRT3;				// height of unit triangle
 868	F32 b = 1.0f / F_SQRT3;				// distance of center of unit triangle to each point
 869	F32 c = F_SQRT2 / F_SQRT3;			// height of unit tetrahedron
 870	F32 d = 0.5f * F_SQRT3 / F_SQRT2;	// distance of center of tetrahedron to each point
 871
 872	// if we want the tetrahedron to have unit height (c = 1.0) then we need to divide
 873	// each constant by hieght of a unit tetrahedron
 874	F32 oo_c = 1.0f / c;
 875	a = a * oo_c;
 876	b = b * oo_c;
 877	c = 1.0f;
 878	d = d * oo_c;
 879	F32 e = 0.5f * oo_c;
 880
 881	LLVector3 point0(			   0.0f,					0.0f,  t_scale.mV[VZ] * d);
 882	LLVector3 point1(t_scale.mV[VX] * b,					0.0f,  t_scale.mV[VZ] * (d-c));
 883	LLVector3 point2(t_scale.mV[VX] * (b-a),  e * t_scale.mV[VY],  t_scale.mV[VZ] * (d-c));
 884	LLVector3 point3(t_scale.mV[VX] * (b-a), -e * t_scale.mV[VY],  t_scale.mV[VZ] * (d-c));
 885
 886	// transform these points into absolute frame
 887	point0 = (point0 * t_rotation) + t_center;
 888	point1 = (point1 * t_rotation) + t_center;
 889	point2 = (point2 * t_rotation) + t_center;
 890	point3 = (point3 * t_rotation) + t_center;
 891
 892	// test ray intersection for each face
 893	BOOL b_hit = FALSE;
 894	LLVector3 face_intersection, face_normal;
 895	F32 distance_squared = 1.0e12f;
 896	F32 temp;
 897
 898	// face 0
 899	if (ray_direction * ( (point2 - point1) % (point0 - point1)) < 0.0f  && 
 900		ray_triangle(ray_point, ray_direction, point1, point2, point0, intersection, intersection_normal))
 901	{
 902		distance_squared = (ray_point - intersection).magVecSquared();
 903		b_hit = TRUE;
 904	}
 905
 906	// face 1
 907	if (ray_direction * ( (point3 - point2) % (point0 - point2)) < 0.0f  &&
 908		ray_triangle(ray_point, ray_direction, point2, point3, point0, face_intersection, face_normal))
 909	{
 910		if (TRUE == b_hit)
 911		{
 912			temp = (ray_point - face_intersection).magVecSquared();
 913			if (temp < distance_squared)
 914			{
 915				distance_squared = temp;
 916				intersection = face_intersection;
 917				intersection_normal = face_normal;
 918			}
 919		}
 920		else 
 921		{
 922			distance_squared = (ray_point - face_intersection).magVecSquared();
 923			intersection = face_intersection;
 924			intersection_normal = face_normal;
 925			b_hit = TRUE;
 926		}
 927	}
 928	
 929	// face 2
 930	if (ray_direction * ( (point1 - point3) % (point0 - point3)) < 0.0f  &&
 931		ray_triangle(ray_point, ray_direction, point3, point1, point0, face_intersection, face_normal))
 932	{
 933		if (TRUE == b_hit)
 934		{
 935			temp = (ray_point - face_intersection).magVecSquared();
 936			if (temp < distance_squared)
 937			{
 938				distance_squared = temp;
 939				intersection = face_intersection;
 940				intersection_normal = face_normal;
 941			}
 942		}
 943		else 
 944		{
 945			distance_squared = (ray_point - face_intersection).magVecSquared();
 946			intersection = face_intersection;
 947			intersection_normal = face_normal;
 948			b_hit = TRUE;
 949		}
 950	}
 951	
 952	// face 3
 953	if (ray_direction * ( (point2 - point3) % (point1 - point3)) < 0.0f  &&
 954		ray_triangle(ray_point, ray_direction, point3, point2, point1, face_intersection, face_normal))
 955	{
 956		if (TRUE == b_hit)
 957		{
 958			temp = (ray_point - face_intersection).magVecSquared();
 959			if (temp < distance_squared)
 960			{
 961				intersection = face_intersection;
 962				intersection_normal = face_normal;
 963			}
 964		}
 965		else 
 966		{
 967			intersection = face_intersection;
 968			intersection_normal = face_normal;
 969			b_hit = TRUE;
 970		}
 971	}
 972
 973	return b_hit;
 974}
 975
 976
 977BOOL ray_pyramid(const LLVector3 &ray_point, const LLVector3 &ray_direction,
 978				 const LLVector3 &p_center, const LLVector3 &p_scale, const LLQuaternion &p_rotation,
 979				 LLVector3 &intersection, LLVector3 &intersection_normal)
 980{
 981	// center of mass of pyramid is located 1/4 its height from the base
 982	F32 x = 0.5f * p_scale.mV[VX];
 983	F32 y = 0.5f * p_scale.mV[VY];
 984	F32 z = 0.25f * p_scale.mV[VZ];
 985
 986	LLVector3 point0(0.0f, 0.0f,  p_scale.mV[VZ] - z);
 987	LLVector3 point1( x,  y, -z);
 988	LLVector3 point2(-x,  y, -z);
 989	LLVector3 point3(-x, -y, -z);
 990	LLVector3 point4( x, -y, -z);
 991
 992	// transform these points into absolute frame
 993	point0 = (point0 * p_rotation) + p_center;
 994	point1 = (point1 * p_rotation) + p_center;
 995	point2 = (point2 * p_rotation) + p_center;
 996	point3 = (point3 * p_rotation) + p_center;
 997	point4 = (point4 * p_rotation) + p_center;
 998
 999	// test ray intersection for each face
1000	BOOL b_hit = FALSE;
1001	LLVector3 face_intersection, face_normal;
1002	F32 distance_squared = 1.0e12f;
1003	F32 temp;
1004
1005	// face 0
1006	if (ray_direction * ( (point1 - point4) % (point0 - point4)) < 0.0f  && 
1007		ray_triangle(ray_point, ray_direction, point4, point1, point0, intersection, intersection_normal))
1008	{
1009		distance_squared = (ray_point - intersection).magVecSquared();
1010		b_hit = TRUE;
1011	}
1012
1013	// face 1
1014	if (ray_direction * ( (point2 - point1) % (point0 - point1)) < 0.0f  &&
1015		ray_triangle(ray_point, ray_direction, point1, point2, point0, face_intersection, face_normal))
1016	{
1017		if (TRUE == b_hit)
1018		{
1019			temp = (ray_point - face_intersection).magVecSquared();
1020			if (temp < distance_squared)
1021			{
1022				distance_squared = temp;
1023				intersection = face_intersection;
1024				intersection_normal = face_normal;
1025			}
1026		}
1027		else 
1028		{
1029			distance_squared = (ray_point - face_intersection).magVecSquared();
1030			intersection = face_intersection;
1031			intersection_normal = face_normal;
1032			b_hit = TRUE;
1033		}
1034	}
1035	
1036	// face 2
1037	if (ray_direction * ( (point3 - point2) % (point0 - point2)) < 0.0f  &&
1038		ray_triangle(ray_point, ray_direction, point2, point3, point0, face_intersection, face_normal))
1039	{
1040		if (TRUE == b_hit)
1041		{
1042			temp = (ray_point - face_intersection).magVecSquared();
1043			if (temp < distance_squared)
1044			{
1045				distance_squared = temp;
1046				intersection = face_intersection;
1047				intersection_normal = face_normal;
1048			}
1049		}
1050		else 
1051		{
1052			distance_squared = (ray_point - face_intersection).magVecSquared();
1053			intersection = face_intersection;
1054			intersection_normal = face_normal;
1055			b_hit = TRUE;
1056		}
1057	}
1058
1059	// face 3
1060	if (ray_direction * ( (point4 - point3) % (point0 - point3)) < 0.0f  &&
1061		ray_triangle(ray_point, ray_direction, point3, point4, point0, face_intersection, face_normal))
1062	{
1063		if (TRUE == b_hit)
1064		{
1065			temp = (ray_point - face_intersection).magVecSquared();
1066			if (temp < distance_squared)
1067			{
1068				distance_squared = temp;
1069				intersection = face_intersection;
1070				intersection_normal = face_normal;
1071			}
1072		}
1073		else 
1074		{
1075			distance_squared = (ray_point - face_intersection).magVecSquared();
1076			intersection = face_intersection;
1077			intersection_normal = face_normal;
1078			b_hit = TRUE;
1079		}
1080	}
1081	
1082	// face 4
1083	if (ray_direction * ( (point3 - point4) % (point2 - point4)) < 0.0f  &&
1084		ray_quadrangle(ray_point, ray_direction, point4, point3, point2, face_intersection, face_normal))
1085	{
1086		if (TRUE == b_hit)
1087		{
1088			temp = (ray_point - face_intersection).magVecSquared();
1089			if (temp < distance_squared)
1090			{
1091				intersection = face_intersection;
1092				intersection_normal = face_normal;
1093			}
1094		}
1095		else 
1096		{
1097			intersection = face_intersection;
1098			intersection_normal = face_normal;
1099			b_hit = TRUE;
1100		}
1101	}
1102
1103	return b_hit;
1104}
1105
1106
1107BOOL linesegment_circle(const LLVector3 &point_a, const LLVector3 &point_b,
1108						const LLVector3 &circle_center, const LLVector3 plane_normal, F32 circle_radius,
1109						LLVector3 &intersection)
1110{
1111	LLVector3 ray_direction = point_b - point_a;
1112	F32 segment_length = ray_direction.normVec();
1113
1114	if (ray_circle(point_a, ray_direction, circle_center, plane_normal, circle_radius, intersection))
1115	{
1116		if (segment_length >= (point_a - intersection).magVec())
1117		{
1118			return TRUE;
1119		}
1120	}
1121	return FALSE;
1122}
1123
1124
1125BOOL linesegment_triangle(const LLVector3 &point_a, const LLVector3 &point_b,
1126						  const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2,
1127						  LLVector3 &intersection, LLVector3 &intersection_normal)
1128{
1129	LLVector3 ray_direction = point_b - point_a;
1130	F32 segment_length = ray_direction.normVec();
1131
1132	if (ray_triangle(point_a, ray_direction, point_0, point_1, point_2, intersection, intersection_normal))
1133	{
1134		if (segment_length >= (point_a - intersection).magVec())
1135		{
1136			return TRUE;
1137		}
1138	}
1139	return FALSE;
1140}
1141
1142
1143BOOL linesegment_quadrangle(const LLVector3 &point_a, const LLVector3 &point_b,
1144							const LLVector3 &point_0, const LLVector3 &point_1, const LLVector3 &point_2,
1145							LLVector3 &intersection, LLVector3 &intersection_normal)
1146{
1147	LLVector3 ray_direction = point_b - point_a;
1148	F32 segment_length = ray_direction.normVec();
1149
1150	if (ray_quadrangle(point_a, ray_direction, point_0, point_1, point_2, intersection, intersection_normal))
1151	{
1152		if (segment_length >= (point_a - intersection).magVec())
1153		{
1154			return TRUE;
1155		}
1156	}
1157	return FALSE;
1158}
1159
1160
1161BOOL linesegment_sphere(const LLVector3 &point_a, const LLVector3 &point_b,
1162				const LLVector3 &sphere_center, F32 sphere_radius,
1163				LLVector3 &intersection, LLVector3 &intersection_normal)
1164{
1165	LLVector3 ray_direction = point_b - point_a;
1166	F32 segment_length = ray_direction.normVec();
1167
1168	if (ray_sphere(point_a, ray_direction, sphere_center, sphere_radius, intersection, intersection_normal))
1169	{
1170		if (segment_length >= (point_a - intersection).magVec())
1171		{
1172			return TRUE;
1173		}
1174	}
1175	return FALSE;
1176}
1177
1178
1179BOOL linesegment_cylinder(const LLVector3 &point_a, const LLVector3 &point_b,
1180				  const LLVector3 &cyl_center, const LLVector3 &cyl_scale, const LLQuaternion &cyl_rotation,
1181				  LLVector3 &intersection, LLVector3 &intersection_normal)
1182{
1183	LLVector3 ray_direction = point_b - point_a;
1184	F32 segment_length = ray_direction.normVec();
1185
1186	if (ray_cylinder(point_a, ray_direction, cyl_center, cyl_scale, cyl_rotation, intersection, intersection_normal))
1187	{
1188		if (segment_length >= (point_a - intersection).magVec())
1189		{
1190			return TRUE;
1191		}
1192	}
1193	return FALSE;
1194}
1195
1196
1197U32 linesegment_box(const LLVector3 &point_a, const LLVector3 &point_b, 
1198					const LLVector3 &box_center, const LLVector3 &box_scale, const LLQuaternion &box_rotation,
1199					LLVector3 &intersection, LLVector3 &intersection_normal)
1200{
1201	LLVector3 direction = point_b - point_a;
1202	if (direction.isNull())
1203	{
1204		return NO_SIDE;
1205	}
1206
1207	F32 segment_length = direction.normVec();
1208	U32 box_side = ray_box(point_a, direction, box_center, box_scale, box_rotation, intersection, intersection_normal);
1209	if (NO_SIDE == box_side  ||  segment_length < (intersection - point_a).magVec())
1210	{
1211		return NO_SIDE;
1212	}
1213
1214	return box_side;
1215}
1216
1217
1218BOOL linesegment_prism(const LLVector3 &point_a, const LLVector3 &point_b,
1219					   const LLVector3 &prism_center, const LLVector3 &prism_scale, const LLQuaternion &prism_rotation,
1220					   LLVector3 &intersection, LLVector3 &intersection_normal)
1221{
1222	LLVector3 ray_direction = point_b - point_a;
1223	F32 segment_length = ray_direction.normVec();
1224
1225	if (ray_prism(point_a, ray_direction, prism_center, prism_scale, prism_rotation, intersection, intersection_normal))
1226	{
1227		if (segment_length >= (point_a - intersection).magVec())
1228		{
1229			return TRUE;
1230		}
1231	}
1232	return FALSE;
1233}
1234
1235
1236BOOL linesegment_tetrahedron(const LLVector3 &point_a, const LLVector3 &point_b,
1237							 const LLVector3 &t_center, const LLVector3 &t_scale, const LLQuaternion &t_rotation,
1238							 LLVector3 &intersection, LLVector3 &intersection_normal)
1239{
1240	LLVector3 ray_direction = point_b - point_a;
1241	F32 segment_length = ray_direction.normVec();
1242
1243	if (ray_tetrahedron(point_a, ray_direction, t_center, t_scale, t_rotation, intersection, intersection_normal))
1244	{
1245		if (segment_length >= (point_a - intersection).magVec())
1246		{
1247			return TRUE;
1248		}
1249	}
1250	return FALSE;
1251}
1252
1253
1254BOOL linesegment_pyramid(const LLVector3 &point_a, const LLVector3 &point_b,
1255						 const LLVector3 &p_center, const LLVector3 &p_scale, const LLQuaternion &p_rotation,
1256						 LLVector3 &intersection, LLVector3 &intersection_normal)
1257{
1258	LLVector3 ray_direction = point_b - point_a;
1259	F32 segment_length = ray_direction.normVec();
1260
1261	if (ray_pyramid(point_a, ray_direction, p_center, p_scale, p_rotation, intersection, intersection_normal))
1262	{
1263		if (segment_length >= (point_a - intersection).magVec())
1264		{
1265			return TRUE;
1266		}
1267	}
1268	return FALSE;
1269}
1270
1271
1272
1273
1274