~jtaylor/ubuntu/oneiric/soya/fix-780305

« back to all changes in this revision

Viewing changes to ode-0.5/OPCODE/OPC_Common.h

  • Committer: Bazaar Package Importer
  • Author(s): Marc Dequènes (Duck)
  • Date: 2005-01-30 09:55:06 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050130095506-f21p6v6cgaobhn5j
Tags: 0.9.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
2
/*
 
3
 *      OPCODE - Optimized Collision Detection
 
4
 *      Copyright (C) 2001 Pierre Terdiman
 
5
 *      Homepage: http://www.codercorner.com/Opcode.htm
 
6
 */
 
7
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
8
 
 
9
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
10
/**
 
11
 *      Contains common classes & defs used in OPCODE.
 
12
 *      \file           OPC_Common.h
 
13
 *      \author         Pierre Terdiman
 
14
 *      \date           March, 20, 2001
 
15
 */
 
16
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
17
 
 
18
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
19
// Include Guard
 
20
#ifndef __OPC_COMMON_H__
 
21
#define __OPC_COMMON_H__
 
22
 
 
23
// [GOTTFRIED]: Just a small change for readability.
 
24
#ifdef OPC_CPU_COMPARE
 
25
        #define GREATER(x, y)   AIR(x) > IR(y)
 
26
#else
 
27
        #define GREATER(x, y)   fabsf(x) > (y)
 
28
#endif
 
29
 
 
30
        class OPCODE_API CollisionAABB
 
31
        {
 
32
                public:
 
33
                //! Constructor
 
34
                inline_                         CollisionAABB()                                         {}
 
35
                //! Constructor
 
36
                inline_                         CollisionAABB(const AABB& b)            { b.GetCenter(mCenter); b.GetExtents(mExtents); }
 
37
                //! Destructor
 
38
                inline_                         ~CollisionAABB()                                        {}
 
39
 
 
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;                                     }
 
44
 
 
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];        }
 
49
 
 
50
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
51
                /**
 
52
                 *      Setups an AABB from min & max vectors.
 
53
                 *      \param          min                     [in] the min point
 
54
                 *      \param          max                     [in] the max point
 
55
                 */
 
56
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
57
                inline_ void            SetMinMax(const Point& min, const Point& max)           { mCenter = (max + min)*0.5f; mExtents = (max - min)*0.5f;              }
 
58
 
 
59
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
60
                /**
 
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
 
64
                 */
 
65
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
66
                inline_ BOOL            IsInside(const CollisionAABB& box) const
 
67
                                                        {
 
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;
 
74
                                                                return TRUE;
 
75
                                                        }
 
76
 
 
77
                                Point           mCenter;                                //!< Box center
 
78
                                Point           mExtents;                               //!< Box extents
 
79
        };
 
80
 
 
81
        class OPCODE_API QuantizedAABB
 
82
        {
 
83
                public:
 
84
                //! Constructor
 
85
                inline_                         QuantizedAABB()                 {}
 
86
                //! Destructor
 
87
                inline_                         ~QuantizedAABB()                {}
 
88
 
 
89
                                sword           mCenter[3];                             //!< Quantized center
 
90
                                uword           mExtents[3];                    //!< Quantized extents
 
91
        };
 
92
 
 
93
        //! Quickly rotates & translates a vector
 
94
        inline_ void TransformPoint(Point& dest, const Point& source, const Matrix3x3& rot, const Point& trans)
 
95
        {
 
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];
 
99
        }
 
100
 
 
101
#endif //__OPC_COMMON_H__