File: FCDPhysicsAnalyticalGeometry.h

package info (click to toggle)
0ad 0.0.23.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,292 kB
  • sloc: cpp: 245,166; ansic: 200,249; python: 13,754; sh: 6,104; perl: 4,620; makefile: 977; xml: 810; java: 533; ruby: 229; erlang: 46; pascal: 30; sql: 21; tcl: 4
file content (392 lines) | stat: -rw-r--r-- 12,560 bytes parent folder | download | duplicates (4)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
/*
	Copyright (C) 2005-2007 Feeling Software Inc.
	Portions of the code are:
	Copyright (C) 2005-2007 Sony Computer Entertainment America
	
	MIT License: http://www.opensource.org/licenses/mit-license.php
*/

/**
	@file FCDPhysicsAnalyticalGeometry.h
	This file contains all the analytical geometry classes including Box, 
	Plane, Sphere, Cylinder, Capsule, Tapered Cylinder, and Tapered Capsule.
*/

#ifndef _FCD_PHYSICS_ANALYTICAL_GEOM_H_
#define _FCD_PHYSICS_ANALYTICAL_GEOM_H_

#ifndef _FCD_ENTITY_H_
#include "FCDocument/FCDEntity.h"
#endif // _FCD_ENTITY_H_

class FCDocument;
class FCDPhysicsShape;

/**
	A COLLADA physics analytical geometry.

	@ingroup FCDocument
*/
class FCOLLADA_EXPORT FCDPhysicsAnalyticalGeometry : public FCDEntity
{
private:
	DeclareObjectType(FCDEntity);

public:
	/** The geometry type of the analytical geometry class.
		Used this information to up-cast an entity instance. */
	enum GeomType { 
		BOX, /**< A box. */
		PLANE, /**< An infinate plane. */
		SPHERE, /**< A sphere. */
		CYLINDER, /**< A cylinder. */
		CAPSULE, /**< A cylinder with spheres at the end. */
		TAPERED_CYLINDER, /**< A cylinder with different sized flat faces. */
		TAPERED_CAPSULE /**< A capsule with different sized spheres. */
	};

	/** Constructor: do not use directly. Create new analytical geometries by 
		using FCDPhysicsShape::CreateAnalyticalGeometry function.
		@param document The COLLADA document that contains this physics scene.
	*/
	FCDPhysicsAnalyticalGeometry(FCDocument* document);

	/** Destructor. */
	virtual ~FCDPhysicsAnalyticalGeometry();

	/** Retrieves the entity type for this class. This function is part of the 
		FCDEntity interface.
		@return The entity type: PHYSICS_ANALYTICAL_GEOMETRY. */
	virtual Type GetType() const {return PHYSICS_ANALYTICAL_GEOMETRY;}

	/** Retrieves the analytical geometry type for this class. 
		@return The analytical geometry type. */
	virtual GeomType GetGeomType() const = 0;

	/** Calculates the volume of this analytical geometry.
		@return The volume. */
	virtual float CalculateVolume() const = 0;

	/** Copies the analytical geometry into a clone.
		@param clone The empty clone. If this pointer is NULL, a analytical
			geometry will be created and you will need to release the returned 
			pointer manually.
		@param cloneChildren Whether to recursively clone this entity's 
			children.
		@return The clone. */
	virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const;
};

/**
	A COLLADA physics box.

	@ingroup FCDocument
*/
class FCOLLADA_EXPORT FCDPASBox : public FCDPhysicsAnalyticalGeometry
{
private:
	DeclareObjectType(FCDPhysicsAnalyticalGeometry);

public:
	/** Constructor: do not use directly. Create new analytical geometries by 
		using FCDPhysicsShape::CreateAnalyticalGeometry function.
		@param document The COLLADA document that contains this physics box. */
	FCDPASBox(FCDocument* document);

	/** Destructor. */
	virtual ~FCDPASBox() {}

	/** Retrieves the analytical geometry type for this class. 
		@return The analytical geometry type: BOX. */
	virtual GeomType GetGeomType() const {return BOX;}

	/** Calculates the volume of this analytical geometry.
		@return The volume. */
	virtual float CalculateVolume() const;

	/** Copies the physics box into a clone.
		@param clone The empty clone. If this pointer is NULL, a analytical
			geometry will be created and you will need to release the returned 
			pointer manually.
		@param cloneChildren Whether to recursively clone this entity's 
			children.
		@return The clone. */
	virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const;

public:
	FMVector3 halfExtents; /**< Half extents of the box in 3 dimensions. */
};

/**
	A COLLADA physics plane.

	@ingroup FCDocument
*/
class FCOLLADA_EXPORT FCDPASPlane : public FCDPhysicsAnalyticalGeometry
{
private:
	DeclareObjectType(FCDPhysicsAnalyticalGeometry);

public:
	/** Constructor: do not use directly. Create new analytical geometries by 
		using FCDPhysicsShape::CreateAnalyticalGeometry function.
		@param document The COLLADA document that contains this physics plane.
	*/
	FCDPASPlane(FCDocument* document);

	/** Destructor. */
	virtual ~FCDPASPlane() {}

	/** Retrieves the analytical geometry type for this class. 
		@return The analytical geometry type: PLANE. */
	virtual GeomType GetGeomType() const {return PLANE;}

	/** Calculates the volume of this analytical geometry.
		@return The volume. */
	virtual float CalculateVolume() const;

	/** Copies the physics plane into a clone.
		@param clone The empty clone. If this pointer is NULL, a analytical
			geometry will be created and you will need to release the returned 
			pointer manually.
		@param cloneChildren Whether to recursively clone this entity's 
			children.
		@return The clone. */
	virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const;

public:
	FMVector3 normal; /**< The normal for the plane. */
	float d; /**< The value that positions the plane. If the normal of the plane is at (A, B, C), the equation of the plane is Ax + By + Cz + d = 0. */
};

/**
	A COLLADA physics sphere.

	@ingroup FCDocument
*/
class FCOLLADA_EXPORT FCDPASSphere : public FCDPhysicsAnalyticalGeometry
{
private:
	DeclareObjectType(FCDPhysicsAnalyticalGeometry);

public:
	/** Constructor: do not use directly. Create new analytical geometries by 
		using FCDPhysicsShape::CreateAnalyticalGeometry function.
		@param document The COLLADA document that contains this physics sphere.
	*/
	FCDPASSphere(FCDocument* document);

	/** Destructor. */
	virtual ~FCDPASSphere() {}

	/** Retrieves the analytical geometry type for this class. 
		@return The analytical geometry type: SPHERE. */
	virtual GeomType GetGeomType() const {return SPHERE;}

	/** Calculates the volume of this analytical geometry.
		@return The volume. */
	virtual float CalculateVolume() const;

	/** Copies the physics sphere into a clone.
		@param clone The empty clone. If this pointer is NULL, a analytical
			geometry will be created and you will need to release the returned 
			pointer manually.
		@param cloneChildren Whether to recursively clone this entity's 
			children.
		@return The clone. */
	virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const;

public:
	float radius; /**< The radius of the sphere. */
};

/**
	A COLLADA physics cylinder.

	@ingroup FCDocument
*/
class FCOLLADA_EXPORT FCDPASCylinder : public FCDPhysicsAnalyticalGeometry
{
private:
	DeclareObjectType(FCDPhysicsAnalyticalGeometry);

public:
	/** Constructor: do not use directly. Create new analytical geometries by 
		using FCDPhysicsShape::CreateAnalyticalGeometry function.
		@param document The COLLADA document that contains this physics 
			cylinder. */
	FCDPASCylinder(FCDocument* document);

	/** Destructor. */
	virtual ~FCDPASCylinder() {}

	/** Retrieves the analytical geometry type for this class. 
		@return The analytical geometry type: CYLINDER. */
	virtual GeomType GetGeomType() const {return CYLINDER;}

	/** Calculates the volume of this analytical geometry.
		@return The volume. */
	virtual float CalculateVolume() const;

	/** Copies the physics cylinder into a clone.
		@param clone The empty clone. If this pointer is NULL, a analytical
			geometry will be created and you will need to release the returned 
			pointer manually.
		@param cloneChildren Whether to recursively clone this entity's 
			children.
		@return The clone. */
	virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const;

public:
	float height; /**< The height of the cylinder. */
	FMVector2 radius; /**< The radius in the X direction and Z direction of the cylinder. */
};

/**
	A COLLADA physics capsule.

	@ingroup FCDocument
*/
class FCOLLADA_EXPORT FCDPASCapsule : public FCDPhysicsAnalyticalGeometry
{
private:
	DeclareObjectType(FCDPhysicsAnalyticalGeometry);

public:
	/** Constructor: do not use directly. Create new analytical geometries by 
		using FCDPhysicsShape::CreateAnalyticalGeometry function.
		@param document The COLLADA document that contains this physics 
			capsule. */
	FCDPASCapsule(FCDocument* document);

	/** Desctructor. */
	virtual ~FCDPASCapsule() {}

	/** Retrieves the analytical geometry type for this class. 
		@return The analytical geometry type: CAPSULE. */
	virtual GeomType GetGeomType() const {return CAPSULE;}

	/** Calculates the volume of this analytical geometry.
		@return The volume. */
	virtual float CalculateVolume() const;

	/** Copies the physics capsule into a clone.
		@param clone The empty clone. If this pointer is NULL, a analytical
			geometry will be created and you will need to release the returned 
			pointer manually.
		@param cloneChildren Whether to recursively clone this entity's 
			children.
		@return The clone. */
	virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const;

public:
	float height; /**< The height of the capsule. */
	FMVector2 radius; /**< The radius in the X direction and Z direction of the capsule. */
};

/**
	A COLLADA physics tapered capsule.

	@ingroup FCDocument
*/
class FCOLLADA_EXPORT FCDPASTaperedCapsule : public FCDPASCapsule
{
private:
	DeclareObjectType(FCDPASCapsule);

public:
	/** Constructor: do not use directly. Create new analytical geometries by 
		using FCDPhysicsShape::CreateAnalyticalGeometry function.
		@param document The COLLADA document that contains this physics tapered
			capsule. */
	FCDPASTaperedCapsule(FCDocument* document);
	
	/** Destructor. */
	virtual ~FCDPASTaperedCapsule() {}

	/** Retrieves the analytical geometry type for this class. 
		@return The analytical geometry type: TAPERED_CAPSULE. */
	virtual GeomType GetGeomType() const {return TAPERED_CAPSULE;}

	/** Calculates the volume of this analytical geometry.
		@return The volume. */
	virtual float CalculateVolume() const;

	/** Copies the physics tapered capsule into a clone.
		@param clone The empty clone. If this pointer is NULL, a analytical
			geometry will be created and you will need to release the returned 
			pointer manually.
		@param cloneChildren Whether to recursively clone this entity's 
			children.
		@return The clone. */
	virtual FCDPhysicsAnalyticalGeometry* Clone(FCDPhysicsAnalyticalGeometry* clone = NULL, bool cloneChildren = false) const;

public:
	//inherits all other attributes from Capsule
	FMVector2 radius2; /**< The second radius in the X direction and Z direction of the capsule. */
};

/**
	A COLLADA physics tapered cylinder.

	@ingroup FCDocument
*/
class FCOLLADA_EXPORT FCDPASTaperedCylinder : public FCDPASCylinder
{
private:
	DeclareObjectType(FCDPASCylinder);

public:
	/** Constructor: do not use directly. Create new analytical geometries by 
		using FCDPhysicsShape::CreateAnalyticalGeometry function.
		@param document The COLLADA document that contains this physics tapered
			cylinder. */
	FCDPASTaperedCylinder(FCDocument* document);

	/** Destructor. */
	virtual ~FCDPASTaperedCylinder() {}

	/** Retrieves the analytical geometry type for this class. 
		@return The analytical geometry type: TAPERED_CYLINDER. */
	virtual GeomType GetGeomType() const {return TAPERED_CYLINDER;}

	/** Calculates the volume of this analytical geometry.
		@return The volume. */
	virtual float CalculateVolume() const;

	/** Copies the physics tapered cylinder into a clone.
		@param clone The empty clone. If this pointer is NULL, a analytical
			geometry will be created and you will need to release the returned 
			pointer manually.
		@param cloneChildren Whether to recursively clone this entity's 
			children.
		@return The clone. */
	virtual FCDEntity* Clone(FCDEntity* clone = NULL, bool cloneChildren = false) const;

public:
	//inherits all other attributes from Cylinder
	FMVector2 radius2; /**< The second radius in the X direction and Z direction of the cylinder. */
};

/**
	[INTERNAL] The factory for COLLADA physics analytical shapes.

	Takes the type of analytical shape and returns a newly created one.

	@ingroup FCDEffect
*/
class FCOLLADA_EXPORT FCDPASFactory
{
private:
	FCDPASFactory() {}

public:
	/** Creates the physics analytical shape.
		@param document The COLLADA document that contains the physics 
			analytical shape to create.
		@param type The analytical geometry type of shape to dreate.
		@return The newly created analytical shape. */
	static FCDPhysicsAnalyticalGeometry* CreatePAS(FCDocument* document, FCDPhysicsAnalyticalGeometry::GeomType type);
};

#endif // _FCD_PHYSICS_ANALYTICAL_GEOMETRY_H_