source: GTP/trunk/App/Games/Jungle_Rumble/src/physic/foundation/include/NxBox.h @ 1378

Revision 1378, 6.1 KB checked in by giegl, 18 years ago (diff)

GTPD - Jungle Rumble - integrate into GTP SVN structure

Line 
1#ifndef NX_FOUNDATION_NXBOX
2#define NX_FOUNDATION_NXBOX
3/*----------------------------------------------------------------------------*\
4|
5|                                               Public Interface to NovodeX Technology
6|
7|                                                            www.novodex.com
8|
9\*----------------------------------------------------------------------------*/
10/** \addtogroup foundation
11  @{
12*/
13
14#include "Nx.h"
15#include "NxVec3.h"
16#include "NxMat33.h"
17#include "NxMat34.h"
18
19class NxCapsule;
20class NxPlane;
21class NxBox;
22class NxBounds3;
23
24
25/**
26\brief Represents an oriented bounding box.
27
28As a centre point, extents(radii) and a rotation. ie the centre of the box is at the centre point,
29the box is rotated around this point with the rotation and it is 2*extents in width, height and depth.
30*/
31class NxBox
32        {
33        public:
34        /**
35        \brief Constructor
36        */
37        NX_INLINE NxBox()
38                {
39                }
40
41        /**
42        \brief Constructor
43
44        \param _center Centre of the OBB
45        \param _extents Extents/radii of the obb.
46        \param _rot rotation to apply to the obb.
47        */
48        NX_INLINE NxBox(const NxVec3& _center, const NxVec3& _extents, const NxMat33& _rot) : center(_center), extents(_extents), rot(_rot)
49                {
50                }
51
52        /**
53        \brief Destructor
54        */
55        NX_INLINE ~NxBox()
56                {
57                }
58
59        /**
60         \brief Setups an empty box.
61         */
62        NX_INLINE void setEmpty()
63                {
64                center.zero();
65                extents.set(NX_MIN_REAL, NX_MIN_REAL, NX_MIN_REAL);
66                rot.id();
67                }
68#ifdef FOUNDATION_EXPORTS
69
70        /**
71         \brief Tests if a point is contained within the box
72
73         See #NxBoxContainsPoint().
74
75         \param         p       [in] the world point to test
76         \return        true if inside the box
77         */
78        NX_INLINE bool containsPoint(const NxVec3& p) const
79                {
80                return NxBoxContainsPoint(*this, p);
81                }
82
83        /**
84         \brief Builds a box from AABB and a world transform.
85
86         See #NxCreateBox().
87
88         \param         aabb    [in] the aabb
89         \param         mat             [in] the world transform
90         */
91        NX_INLINE void create(const NxBounds3& aabb, const NxMat34& mat)
92                {
93                NxCreateBox(*this, aabb, mat);
94                }
95#endif
96        /**
97         \brief Recomputes the box after an arbitrary transform by a 4x4 matrix.
98
99         \param         mtx             [in] the transform matrix
100         \param         obb             [out] the transformed OBB
101         */
102        NX_INLINE void rotate(const NxMat34& mtx, NxBox& obb) const
103                {               
104                obb.extents = extents;// The extents remain constant
105                obb.center = mtx.M * center + mtx.t;
106                obb.rot.multiply(mtx.M, rot);
107                }
108
109        /**
110         \brief Checks the box is valid.
111
112         \return        true if the box is valid
113         */
114        NX_INLINE bool isValid() const
115                {
116                // Consistency condition for (Center, Extents) boxes: Extents >= 0.0f
117                if(extents.x < 0.0f)    return false;
118                if(extents.y < 0.0f)    return false;
119                if(extents.z < 0.0f)    return false;
120                return true;
121                }
122#ifdef FOUNDATION_EXPORTS
123
124        /**
125         \brief Computes the obb planes.
126
127         See #NxComputeBoxPlanes().
128
129         \param         planes  [out] 6 box planes
130         \return        true if success
131         */
132        NX_INLINE bool computePlanes(NxPlane* planes) const
133                {
134                return NxComputeBoxPlanes(*this, planes);
135                }
136
137        /**
138         \brief Computes the obb points.
139
140         See #NxComputeBoxPoints().
141
142         \param         pts     [out] 8 box points
143         \return        true if success
144         */
145        NX_INLINE bool computePoints(NxVec3* pts) const
146                {
147                return NxComputeBoxPoints(*this, pts);
148                }
149
150        /**
151         \brief Computes vertex normals.
152
153         See #NxComputeBoxVertexNormals().
154
155         \param         pts     [out] 8 box points
156         \return        true if success
157         */
158        NX_INLINE bool computeVertexNormals(NxVec3* pts) const
159                {
160                return NxComputeBoxVertexNormals(*this, pts);
161                }
162
163        /**
164         \brief Returns edges.
165
166         See #NxGetBoxEdges().
167
168         \return        24 indices (12 edges) indexing the list returned by ComputePoints()
169         */
170        NX_INLINE const NxU32* getEdges() const
171                {
172                return NxGetBoxEdges();
173                }
174
175                /**
176                \brief Return edge axes indices.
177
178                 See #NxgetBoxEdgeAxes().
179
180                 \return Array of edge axes indices.
181                */
182
183        NX_INLINE const NxI32* getEdgesAxes() const
184                {
185                return NxGetBoxEdgesAxes();
186                }
187
188        /**
189         \brief Returns triangles.
190
191         See #NxGetBoxTriangles().
192
193
194         \return 36 indices (12 triangles) indexing the list returned by ComputePoints()
195         */
196        NX_INLINE const NxU32* getTriangles() const
197                {
198                return NxGetBoxTriangles();
199                }
200
201        /**
202         \brief Returns local edge normals.
203
204         See #NxGetBoxLocalEdgeNormals().
205
206         \return edge normals in local space
207         */
208        NX_INLINE const NxVec3* getLocalEdgeNormals() const
209                {
210                return NxGetBoxLocalEdgeNormals();
211                }
212
213        /**
214         \brief Returns world edge normal
215
216         See #NxComputeBoxWorldEdgeNormal().
217
218         \param         edge_index              [in] 0 <= edge index < 12
219         \param         world_normal    [out] edge normal in world space
220         */
221        NX_INLINE void computeWorldEdgeNormal(NxU32 edge_index, NxVec3& world_normal) const
222                {
223                NxComputeBoxWorldEdgeNormal(*this, edge_index, world_normal);
224                }
225
226        /**
227         \brief Computes a capsule surrounding the box.
228
229         See #NxComputeCapsuleAroundBox().
230
231         \param         capsule [out] the capsule
232         */
233        NX_INLINE void computeCapsule(NxCapsule& capsule) const
234                {
235                NxComputeCapsuleAroundBox(*this, capsule);
236                }
237
238        /**
239         \brief Checks the box is inside another box
240
241         See #NxIsBoxAInsideBoxB().
242
243         \param         box             [in] the other box
244         \return        TRUE if we're inside the other box
245         */
246        NX_INLINE bool isInside(const NxBox& box) const
247                {
248                return NxIsBoxAInsideBoxB(*this, box);
249                }
250#endif
251        // Accessors
252
253                /**
254                \brief Return center of box.
255
256                \return Center of box.
257                */
258        NX_INLINE const NxVec3& GetCenter() const
259                {
260                return center;
261                }
262
263                /**
264                \brief Return extents(radii) of box.
265
266                \return Extents of box.
267                */
268
269        NX_INLINE const NxVec3& GetExtents() const
270                {
271                return extents;
272                }
273
274                /**
275                \brief return box rotation.
276
277                \return Box Rotation.
278                */
279
280        NX_INLINE const NxMat33& GetRot() const
281                {
282                return rot;
283                }
284
285/*      NX_INLINE       void GetRotatedExtents(NxMat33& extents) const
286                {
287                extents = mRot;
288                extents.Scale(mExtents);
289                }*/
290
291        NxVec3  center;
292        NxVec3  extents;
293        NxMat33 rot;
294        };
295
296 /** @} */
297#endif
298
299
300//AGCOPYRIGHTBEGIN
301///////////////////////////////////////////////////////////////////////////
302// Copyright © 2005 AGEIA Technologies.
303// All rights reserved. www.ageia.com
304///////////////////////////////////////////////////////////////////////////
305//AGCOPYRIGHTEND
306
Note: See TracBrowser for help on using the repository browser.