Panda3D
Loading...
Searching...
No Matches
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 */
21get_max() const {
22
23 return PhysxManager::nxVec3_to_point3(_bounds.max);
24}
25
26/**
27 * Returns the maximum corner of the bounding box.
28 */
30get_min() const {
31
32 return PhysxManager::nxVec3_to_point3(_bounds.min);
33}
34
35/**
36 * Returns the center of the bounding box.
37 */
39get_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 */
50get_dimensions() const {
51
52 NxVec3 dims;
53 _bounds.getDimensions(dims);
55}
56
57/**
58 * Sets the maximum corner of the bounding box.
59 */
61set_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 */
72set_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 */
85bounds_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),
94}
95
96/**
97 * Sets this to the union of this and b2.
98 */
100combine(const PhysxBounds3 &b2) {
101
102 _bounds.combine(b2._bounds);
103}
104
105/**
106 * Returns TRUE if these bounds contain the point v.
107 */
109contain(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 */
120fatten(float distance) {
121
122 _bounds.fatten(distance);
123}
124
125/**
126 * Expands the volume to include the point v.
127 */
129include(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 */
139intersects(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 */
149intersects2d(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 */
158is_empty() const {
159
160 return _bounds.isEmpty();
161}
162
163/**
164 * Scales the AABB by the given factor.
165 */
167scale(float scale) {
168
169 _bounds.scale(scale);
170}
171
172/**
173 * Setup this AABB from minimum corner and maximum corner.
174 */
176set(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 */
189set_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 */
202set_empty() {
203
204 _bounds.setEmpty();
205}
206
207/**
208 * Sets infinite bounds.
209 */
211set_infinite() {
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 */
222transform(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}
Represention of a axis aligned bounding box.
void set_min(LPoint3f value)
Sets the minimum corner of the bounding box.
LPoint3f get_min() const
Returns the maximum corner of the bounding box.
void set_max(LPoint3f value)
Sets the maximum 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...
void scale(float scale)
Scales the AABB by the given factor.
bool is_empty() const
Returns TRUE if the bounding box is empty.
void set_empty()
Sets empty to TRUE.
void include(const LPoint3f &v)
Expands the volume to include the point v.
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.
LVector3f get_dimensions() const
Returns the extents of the bounding box.
void fatten(float distance)
Fattens the AABB in all three dimensions by the given distance.
void combine(const PhysxBounds3 &b2)
Sets this to the union of this and b2.
void set(const LPoint3f &min, const LPoint3f &max)
Setup this AABB from minimum corner and maximum corner.
LPoint3f get_max() const
Returns the minimum corner of the bounding box.
LPoint3f get_center() const
Returns the center of the bounding box.
void set_infinite()
Sets infinite bounds.
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 ...
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.
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
static NxMat33 mat3_to_nxMat33(const LMatrix3f &m)
Converts from LMatrix3f to NxMat33.
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.