summaryrefslogtreecommitdiffhomepage
path: root/Opcode/OPC_VolumeCollider.h
blob: 5c39ea3c9b68a4466b72809a0a552267d673b072 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
 *	OPCODE - Optimized Collision Detection
 *	Copyright (C) 2001 Pierre Terdiman
 *	Homepage: http://www.codercorner.com/Opcode.htm
 */
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 *	Contains base volume collider class.
 *	\file		OPC_VolumeCollider.h
 *	\author		Pierre Terdiman
 *	\date		June, 2, 2001
 */
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Include Guard
#ifndef __OPC_VOLUMECOLLIDER_H__
#define __OPC_VOLUMECOLLIDER_H__

	struct OPCODE_API VolumeCache
	{
							VolumeCache() : Model(null)		{}
							~VolumeCache()					{}

		Container			TouchedPrimitives;	//!< Indices of touched primitives
		const BaseModel*	Model;				//!< Owner
	};

	class OPCODE_API VolumeCollider : public Collider
	{
		public:
		// Constructor / Destructor
											VolumeCollider();
		virtual								~VolumeCollider() = 0;

		// Collision report

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Gets the number of touched primitives after a collision query.
		 *	\see		GetContactStatus()
		 *	\see		GetTouchedPrimitives()
		 *	\return		the number of touched primitives
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_				udword			GetNbTouchedPrimitives()	const	{ return mTouchedPrimitives ? mTouchedPrimitives->GetNbEntries() : 0;	}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Gets the list of touched primitives after a collision query.
		 *	\see		GetContactStatus()
		 *	\see		GetNbTouchedPrimitives()
		 *	\return		the list of touched primitives (primitive indices)
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_		const	udword*			GetTouchedPrimitives()		const	{ return mTouchedPrimitives ? mTouchedPrimitives->GetEntries() : null;	}

		// Stats

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Stats: gets the number of Volume-BV overlap tests after a collision query.
		 *	\see		GetNbVolumePrimTests()
		 *	\return		the number of Volume-BV tests performed during last query
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_				udword			GetNbVolumeBVTests()		const	{ return mNbVolumeBVTests;												}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Stats: gets the number of Volume-Triangle overlap tests after a collision query.
		 *	\see		GetNbVolumeBVTests()
		 *	\return		the number of Volume-Triangle tests performed during last query
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_				udword			GetNbVolumePrimTests()		const	{ return mNbVolumePrimTests;											}

		// Settings

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Validates current settings. You should call this method after all the settings / callbacks have been defined for a collider.
		 *	\return		null if everything is ok, else a string describing the problem
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		override(Collider)	const char*		ValidateSettings();

		protected:
		// Touched primitives
							Container*		mTouchedPrimitives;	//!< List of touched primitives

		// Dequantization coeffs
							IcePoint			mCenterCoeff;
							IcePoint			mExtentsCoeff;
		// Stats
							udword			mNbVolumeBVTests;	//!< Number of Volume-BV tests
							udword			mNbVolumePrimTests;	//!< Number of Volume-Primitive tests
		// Internal methods
							void			_Dump(const AABBCollisionNode* node);
							void			_Dump(const AABBNoLeafNode* node);
							void			_Dump(const AABBQuantizedNode* node);
							void			_Dump(const AABBQuantizedNoLeafNode* node);

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Initializes a query
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		override(Collider) inline_	void	InitQuery()
											{
												// Reset stats & contact status
												mNbVolumeBVTests	= 0;
												mNbVolumePrimTests	= 0;
												Collider::InitQuery();
											}

		inline_				BOOL			IsCacheValid(VolumeCache& cache)
											{
												// We're going to do a volume-vs-model query.
												if(cache.Model!=mCurrentModel)
												{
													// Cached list was for another model so we can't keep it
													// Keep track of new owner and reset cache
													cache.Model = mCurrentModel;
													return FALSE;
												}
												else
												{
													// Same models, no problem
													return TRUE;
												}
											}
	};

#endif // __OPC_VOLUMECOLLIDER_H__