Panda3D
 All Classes Functions Variables Enumerations
physxBox.cxx
1 // Filename: physxBox.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 "physxBox.h"
16 #include "physxManager.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: PhysxBox::Constructor
20 // Access: Published
21 // Description:
22 ////////////////////////////////////////////////////////////////////
23 PhysxBox::
24 PhysxBox(const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot) {
25 
26  _box = NxBox(PhysxManager::point3_to_nxVec3(center),
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: PhysxBox::is_valid
33 // Access: Published
34 // Description: Returns TRUE if the box is valid.
35 ////////////////////////////////////////////////////////////////////
36 bool PhysxBox::
37 is_valid() const {
38 
39  return _box.isValid();
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: PhysxBox::rotate
44 // Access: Published
45 // Description: Recomputes the box after an arbitrary transform by
46 // a 4x4 matrix.
47 ////////////////////////////////////////////////////////////////////
48 void PhysxBox::
49 rotate(const LMatrix4f &m, PhysxBox &obb) const {
50 
51  nassertv(!m.is_nan());
52 
53  _box.rotate(PhysxManager::mat4_to_nxMat34(m), obb._box);
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: PhysxBox::set_empty
58 // Access: Published
59 // Description: Setups an empty box.
60 ////////////////////////////////////////////////////////////////////
61 void PhysxBox::
63 
64  _box.setEmpty();
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: PhysxBox::get_center
69 // Access: Published
70 // Description: Return center of the box.
71 ////////////////////////////////////////////////////////////////////
73 get_center() const {
74 
75  return PhysxManager::nxVec3_to_point3(_box.GetCenter());
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: PhysxBox::get_extents
80 // Access: Published
81 // Description: Returns the extents (radii) of the box.
82 ////////////////////////////////////////////////////////////////////
84 get_extents() const {
85 
86  return PhysxManager::nxVec3_to_vec3(_box.GetExtents());
87 }
88 
89 ////////////////////////////////////////////////////////////////////
90 // Function: PhysxBox::get_rot
91 // Access: Published
92 // Description: Return the rotation of the box.
93 ////////////////////////////////////////////////////////////////////
95 get_rot() const {
96 
97  return PhysxManager::nxMat33_to_mat3(_box.GetRot());
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function: PhysxBox::set_center
102 // Access: Published
103 // Description: Sets the center of the box.
104 ////////////////////////////////////////////////////////////////////
105 void PhysxBox::
107 
108  nassertv(!center.is_nan());
109 
110  _box.center = PhysxManager::vec3_to_nxVec3(center);
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: PhysxBox::set_extents
115 // Access: Published
116 // Description: Sets the extents of the box.
117 ////////////////////////////////////////////////////////////////////
118 void PhysxBox::
120 
121  nassertv(!extents.is_nan());
122 
123  _box.extents = PhysxManager::vec3_to_nxVec3(extents);
124 }
125 
126 ////////////////////////////////////////////////////////////////////
127 // Function: PhysxBox::set_rot
128 // Access: Published
129 // Description: Sets the rotation of the box.
130 ////////////////////////////////////////////////////////////////////
131 void PhysxBox::
133 
134  nassertv(!rot.is_nan());
135 
136  _box.rot = PhysxManager::mat3_to_nxMat33(rot);
137 }
138 
LPoint3f get_center() const
Return center of the box.
Definition: physxBox.cxx:73
void set_center(LPoint3f center)
Sets the center of the box.
Definition: physxBox.cxx:106
void set_extents(LVector3f extents)
Sets the extents of the box.
Definition: physxBox.cxx:119
Represents an oriented bounding box, as a center point, extents(radii) and a rotation.
Definition: physxBox.h:32
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Definition: physxManager.I:77
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
void set_rot(LMatrix3f rot)
Sets the rotation of the box.
Definition: physxBox.cxx:132
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
void rotate(const LMatrix4f &m, PhysxBox &obb) const
Recomputes the box after an arbitrary transform by a 4x4 matrix.
Definition: physxBox.cxx:49
static NxMat34 mat4_to_nxMat34(const LMatrix4f &m)
Converts from LMatrix4f to NxMat34.
Definition: physxManager.I:145
LMatrix3f get_rot() const
Return the rotation of the box.
Definition: physxBox.cxx:95
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
Definition: lmatrix.h:3147
bool is_valid() const
Returns TRUE if the box is valid.
Definition: physxBox.cxx:37
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
Definition: physxManager.I:33
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
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
Definition: physxManager.I:88
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110
static LMatrix3f nxMat33_to_mat3(const NxMat33 &m)
Converts from NxMat33 to LMatrix3f.
Definition: physxManager.I:182
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
Definition: lmatrix.h:1417
LVector3f get_extents() const
Returns the extents (radii) of the box.
Definition: physxBox.cxx:84
void set_empty()
Setups an empty box.
Definition: physxBox.cxx:62