Panda3D
 All Classes Functions Variables Enumerations
physxBounds3.cxx
1 // Filename: physxBounds3.cxx
2 // Created by: enn0x (31Oct09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "physxBounds3.h"
16 #include "physxManager.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: PhysxBounds3::get_max
20 // Access: Published
21 // Description: Returns the minimum corner of the bounding box.
22 ////////////////////////////////////////////////////////////////////
24 get_max() const {
25 
26  return PhysxManager::nxVec3_to_point3(_bounds.max);
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: PhysxBounds3::get_min
31 // Access: Published
32 // Description: Returns the maximum corner of the bounding box.
33 ////////////////////////////////////////////////////////////////////
35 get_min() const {
36 
37  return PhysxManager::nxVec3_to_point3(_bounds.min);
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: PhysxBounds3::get_center
42 // Access: Published
43 // Description: Returns the center of the bounding box.
44 ////////////////////////////////////////////////////////////////////
46 get_center() const {
47 
48  NxVec3 center;
49  _bounds.getCenter(center);
50  return PhysxManager::nxVec3_to_point3(center);
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: PhysxBounds3::get_dimensions
55 // Access: Published
56 // Description: Returns the extents of the bounding box.
57 ////////////////////////////////////////////////////////////////////
59 get_dimensions() const {
60 
61  NxVec3 dims;
62  _bounds.getDimensions(dims);
63  return PhysxManager::nxVec3_to_vec3(dims);
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: PhysxBounds3::set_max
68 // Access: Published
69 // Description: Sets the maximum corner of the bounding box.
70 ////////////////////////////////////////////////////////////////////
71 void PhysxBounds3::
72 set_max(LPoint3f value) {
73 
74  nassertv(!value.is_nan());
75 
76  _bounds.max = PhysxManager::point3_to_nxVec3(value);
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: PhysxBounds3::set_min
81 // Access: Published
82 // Description: Sets the minimum corner of the bounding box.
83 ////////////////////////////////////////////////////////////////////
84 void PhysxBounds3::
85 set_min(LPoint3f value) {
86 
87  nassertv(!value.is_nan());
88 
89  _bounds.min = PhysxManager::point3_to_nxVec3(value);
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: PhysxBounds3::bounds_of_obb
94 // Access: Published
95 // Description: Sets this to the AABB (axis ligned bounding box)
96 // of the OBB (oriented bounding box). The OBB is
97 // described by orientation, translation and half
98 // dimensions.
99 ////////////////////////////////////////////////////////////////////
100 void PhysxBounds3::
101 bounds_of_obb(const LMatrix3f &orientation, const LPoint3f &translation, const LVector3f &half_dims) {
102 
103  nassertv(!orientation.is_nan());
104  nassertv(!translation.is_nan());
105  nassertv(!half_dims.is_nan());
106 
107  _bounds.boundsOfOBB(PhysxManager::mat3_to_nxMat33(orientation),
108  PhysxManager::point3_to_nxVec3(translation),
109  PhysxManager::vec3_to_nxVec3(half_dims));
110 }
111 
112 ////////////////////////////////////////////////////////////////////
113 // Function: PhysxBounds3::combine
114 // Access: Published
115 // Description: Sets this to the union of this and b2.
116 ////////////////////////////////////////////////////////////////////
117 void PhysxBounds3::
118 combine(const PhysxBounds3 &b2) {
119 
120  _bounds.combine(b2._bounds);
121 }
122 
123 ////////////////////////////////////////////////////////////////////
124 // Function: PhysxBounds3::contain
125 // Access: Published
126 // Description: Returns TRUE if these bounds contain the point v.
127 ////////////////////////////////////////////////////////////////////
128 bool PhysxBounds3::
129 contain(const LPoint3f &p) const {
130 
131  nassertr(!p.is_nan(), false);
132 
133  return _bounds.contain(PhysxManager::point3_to_nxVec3(p));
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function: PhysxBounds3::fatten
138 // Access: Published
139 // Description: Fattens the AABB in all three dimensions by the
140 // given distance.
141 ////////////////////////////////////////////////////////////////////
142 void PhysxBounds3::
143 fatten(float distance) {
144 
145  _bounds.fatten(distance);
146 }
147 
148 ////////////////////////////////////////////////////////////////////
149 // Function: PhysxBounds3::include
150 // Access: Published
151 // Description: Expands the volume to include the point v.
152 ////////////////////////////////////////////////////////////////////
153 void PhysxBounds3::
154 include(const LPoint3f &p) {
155 
156  nassertv(!p.is_nan());
157  _bounds.include(PhysxManager::point3_to_nxVec3(p));
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: PhysxBounds3::intersects
162 // Access: Published
163 // Description: Returns TRUE if the intersection of this and b is
164 // is not empty.
165 ////////////////////////////////////////////////////////////////////
166 bool PhysxBounds3::
167 intersects(const PhysxBounds3 &b) const {
168 
169  return _bounds.intersects(b._bounds);
170 }
171 
172 ////////////////////////////////////////////////////////////////////
173 // Function: PhysxBounds3::intersects2d
174 // Access: Published
175 // Description: Indicates whether the intersection of this and b
176 // is empty or not in the plane orthogonal to the
177 // axis passed (X = 0, Y = 1 or Z = 2).
178 ////////////////////////////////////////////////////////////////////
179 bool PhysxBounds3::
180 intersects2d(const PhysxBounds3 &b, unsigned axis_to_ignore) const {
181 
182  return _bounds.intersects2D(b._bounds, axis_to_ignore);
183 }
184 
185 ////////////////////////////////////////////////////////////////////
186 // Function: PhysxBounds3::is_empty
187 // Access: Published
188 // Description: Returns TRUE if the bounding box is empty.
189 ////////////////////////////////////////////////////////////////////
190 bool PhysxBounds3::
191 is_empty() const {
192 
193  return _bounds.isEmpty();
194 }
195 
196 ////////////////////////////////////////////////////////////////////
197 // Function: PhysxBounds3::scale
198 // Access: Published
199 // Description: Scales the AABB by the given factor.
200 ////////////////////////////////////////////////////////////////////
201 void PhysxBounds3::
202 scale(float scale) {
203 
204  _bounds.scale(scale);
205 }
206 
207 ////////////////////////////////////////////////////////////////////
208 // Function: PhysxBounds3::set
209 // Access: Published
210 // Description: Setup this AABB from minimum corner and maximum
211 // corner.
212 ////////////////////////////////////////////////////////////////////
213 void PhysxBounds3::
214 set(const LPoint3f &min, const LPoint3f &max) {
215 
216  nassertv(!min.is_nan());
217  nassertv(!max.is_nan());
218 
219  _bounds.set(PhysxManager::point3_to_nxVec3(min),
221 }
222 
223 ////////////////////////////////////////////////////////////////////
224 // Function: PhysxBounds3::set_center_extents
225 // Access: Published
226 // Description: Setup this AABB from center point and extents
227 // vector.
228 ////////////////////////////////////////////////////////////////////
229 void PhysxBounds3::
230 set_center_extents(const LPoint3f &center, const LVector3f &extents) {
231 
232  nassertv(!center.is_nan());
233  nassertv(!extents.is_nan());
234 
235  _bounds.setCenterExtents(PhysxManager::point3_to_nxVec3(center),
237 }
238 
239 ////////////////////////////////////////////////////////////////////
240 // Function: PhysxBounds3::set_empty
241 // Access: Published
242 // Description: Sets empty to TRUE.
243 ////////////////////////////////////////////////////////////////////
244 void PhysxBounds3::
246 
247  _bounds.setEmpty();
248 }
249 
250 ////////////////////////////////////////////////////////////////////
251 // Function: PhysxBounds3::set_infinite
252 // Access: Published
253 // Description: Sets infinite bounds.
254 ////////////////////////////////////////////////////////////////////
255 void PhysxBounds3::
257 
258  _bounds.setInfinite();
259 }
260 
261 ////////////////////////////////////////////////////////////////////
262 // Function: PhysxBounds3::transform
263 // Access: Published
264 // Description: Transforms this volume as if it was an axis aligned
265 // bounding box, and then assigns the results' bounds
266 // to this. The orientation is applied first, then the
267 // translation.
268 ////////////////////////////////////////////////////////////////////
269 void PhysxBounds3::
270 transform(const LMatrix3f &orientation, const LPoint3f &translation) {
271 
272  nassertv(!orientation.is_nan());
273  nassertv(!translation.is_nan());
274 
275  _bounds.transform(PhysxManager::mat3_to_nxMat33(orientation),
276  PhysxManager::point3_to_nxVec3(translation));
277 }
278 
void bounds_of_obb(const LMatrix3f &orientation, const LPoint3f &translation, const LVector3f &half_dims)
Sets this to the AABB (axis ligned bounding box) of the OBB (oriented bounding box).
LVector3f get_dimensions() const
Returns the extents of the bounding box.
bool is_empty() const
Returns TRUE if the bounding box is empty.
void set_center_extents(const LPoint3f &center, const LVector3f &extents)
Setup this AABB from center point and extents vector.
void set_max(LPoint3f value)
Sets the maximum corner of the bounding box.
void include(const LPoint3f &v)
Expands the volume to include the point v.
void set(const LPoint3f &min, const LPoint3f &max)
Setup this AABB from minimum corner and maximum corner.
bool contain(const LPoint3f &p) const
Returns TRUE if these bounds contain the point v.
bool intersects2d(const PhysxBounds3 &b, unsigned axis_to_ignore) const
Indicates whether the intersection of this and b is empty or not in the plane orthogonal to the axis ...
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Definition: physxManager.I:77
Represention of a axis aligned bounding box.
Definition: physxBounds3.h:32
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
void set_empty()
Sets empty to TRUE.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
Definition: lvecBase3.h:463
LPoint3f get_center() const
Returns the center of the bounding box.
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
Definition: lmatrix.h:3147
void set_infinite()
Sets infinite bounds.
LPoint3f get_min() const
Returns the maximum corner of the bounding box.
void scale(float scale)
Scales the AABB by the given factor.
void combine(const PhysxBounds3 &b2)
Sets this to the union of this and b2.
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
Definition: physxManager.I:33
void fatten(float distance)
Fattens the AABB in all three dimensions by the given distance.
static NxMat33 mat3_to_nxMat33(const LMatrix3f &m)
Converts from LMatrix3f to NxMat33.
Definition: physxManager.I:169
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
Definition: physxManager.I:44
bool intersects(const PhysxBounds3 &b) const
Returns TRUE if the intersection of this and b is is not empty.
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
Definition: physxManager.I:88
LPoint3f get_max() const
Returns the minimum corner of the bounding box.
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110
void set_min(LPoint3f value)
Sets the minimum corner of the bounding box.
void transform(const LMatrix3f &orientation, const LPoint3f &translation)
Transforms this volume as if it was an axis aligned bounding box, and then assigns the results' bound...