1
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3
* OPCODE - Optimized Collision Detection
4
* Copyright (C) 2001 Pierre Terdiman
5
* Homepage: http://www.codercorner.com/Opcode.htm
7
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11
* Contains common classes & defs used in OPCODE.
13
* \author Pierre Terdiman
14
* \date March, 20, 2001
16
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20
#ifndef __OPC_COMMON_H__
21
#define __OPC_COMMON_H__
23
// [GOTTFRIED]: Just a small change for readability.
24
#ifdef OPC_CPU_COMPARE
25
#define GREATER(x, y) AIR(x) > IR(y)
27
#define GREATER(x, y) fabsf(x) > (y)
30
class OPCODE_API CollisionAABB
34
inline_ CollisionAABB() {}
36
inline_ CollisionAABB(const AABB& b) { b.GetCenter(mCenter); b.GetExtents(mExtents); }
38
inline_ ~CollisionAABB() {}
40
//! Get min point of the box
41
inline_ void GetMin(Point& min) const { min = mCenter - mExtents; }
42
//! Get max point of the box
43
inline_ void GetMax(Point& max) const { max = mCenter + mExtents; }
45
//! Get component of the box's min point along a given axis
46
inline_ float GetMin(udword axis) const { return mCenter[axis] - mExtents[axis]; }
47
//! Get component of the box's max point along a given axis
48
inline_ float GetMax(udword axis) const { return mCenter[axis] + mExtents[axis]; }
50
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52
* Setups an AABB from min & max vectors.
53
* \param min [in] the min point
54
* \param max [in] the max point
56
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
57
inline_ void SetMinMax(const Point& min, const Point& max) { mCenter = (max + min)*0.5f; mExtents = (max - min)*0.5f; }
59
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61
* Checks a box is inside another box.
62
* \param box [in] the other box
63
* \return true if current box is inside input box
65
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66
inline_ BOOL IsInside(const CollisionAABB& box) const
68
if(box.GetMin(0)>GetMin(0)) return FALSE;
69
if(box.GetMin(1)>GetMin(1)) return FALSE;
70
if(box.GetMin(2)>GetMin(2)) return FALSE;
71
if(box.GetMax(0)<GetMax(0)) return FALSE;
72
if(box.GetMax(1)<GetMax(1)) return FALSE;
73
if(box.GetMax(2)<GetMax(2)) return FALSE;
77
Point mCenter; //!< Box center
78
Point mExtents; //!< Box extents
81
class OPCODE_API QuantizedAABB
85
inline_ QuantizedAABB() {}
87
inline_ ~QuantizedAABB() {}
89
sword mCenter[3]; //!< Quantized center
90
uword mExtents[3]; //!< Quantized extents
93
//! Quickly rotates & translates a vector
94
inline_ void TransformPoint(Point& dest, const Point& source, const Matrix3x3& rot, const Point& trans)
96
dest.x = trans.x + source.x * rot.m[0][0] + source.y * rot.m[1][0] + source.z * rot.m[2][0];
97
dest.y = trans.y + source.x * rot.m[0][1] + source.y * rot.m[1][1] + source.z * rot.m[2][1];
98
dest.z = trans.z + source.x * rot.m[0][2] + source.y * rot.m[1][2] + source.z * rot.m[2][2];
101
#endif //__OPC_COMMON_H__