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