summaryrefslogtreecommitdiffhomepage
path: root/third-party/Opcode/Ice/IceLSS.h
blob: e4c9ef8a109e5328c9c23c4eaf359d398e4c19c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 *	Contains code for line-swept spheres.
 *	\file		IceLSS.h
 *	\author		Pierre Terdiman
 *	\date		April, 4, 2000
 */
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Include Guard
#ifndef __ICELSS_H__
#define __ICELSS_H__

	class ICEMATHS_API LSS : public IceSegment
	{
		public:
		//! Constructor
		inline_			LSS()																	{}
		//! Constructor
		inline_			LSS(const IceSegment& seg, float radius) : IceSegment(seg), mRadius(radius)	{}
		//! Destructor
		inline_			~LSS()																	{}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Computes an OBB surrounding the LSS.
		 *	\param		box		[out] the OBB
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				void	ComputeOBB(OBB& box);

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Tests if a IcePoint is contained within the LSS.
		 *	\param		pt	[in] the IcePoint to test
		 *	\return		true if inside the LSS
		 *	\warning	IcePoint and LSS must be in same space
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_	bool	Contains(const IcePoint& pt)	const	{ return SquareDistance(pt) <= mRadius*mRadius;	}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Tests if a sphere is contained within the LSS.
		 *	\param		sphere	[in] the sphere to test
		 *	\return		true if inside the LSS
		 *	\warning	sphere and LSS must be in same space
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_	bool	Contains(const Sphere& sphere)
						{
							float d = mRadius - sphere.mRadius;
							if(d>=0.0f)	return SquareDistance(sphere.mCenter) <= d*d;
							else		return false;
						}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Tests if an LSS is contained within the LSS.
		 *	\param		lss		[in] the LSS to test
		 *	\return		true if inside the LSS
		 *	\warning	both LSS must be in same space
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_	bool	Contains(const LSS& lss)
						{
							// We check the LSS contains the two spheres at the start and end of the sweep
							return Contains(Sphere(lss.mP0, lss.mRadius)) && Contains(Sphere(lss.mP0, lss.mRadius));
						}

				float	mRadius;	//!< Sphere radius
	};

#endif // __ICELSS_H__