Panda3D
physxShapeDesc.cxx
1 // Filename: physxShapeDesc.cxx
2 // Created by: enn0x (08Sep09)
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 "physxShapeDesc.h"
16 #include "physxManager.h"
17 #include "physxMaterial.h"
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: PhysxShapeDesc::set_name
21 // Access: Published
22 // Description: Sets a possible debug name.
23 ////////////////////////////////////////////////////////////////////
25 set_name(const char *name) {
26 
27  _name = name ? name : "";
28  ptr()->name = _name.c_str();
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: PhysxShapeDesc::set_trigger
33 // Access: Published
34 // Description: This shape will become a trigger shape if this
35 // parameter is set to TRUE. It won't take part in
36 // collisions, but trigger events if some other
37 // shape passes through it.
38 ////////////////////////////////////////////////////////////////////
40 set_trigger(bool value) {
41 
42  if (value == true) {
43  ptr()->shapeFlags |= NX_TRIGGER_ENABLE;
44  }
45  else {
46  ptr()->shapeFlags &= ~(NX_TRIGGER_ENABLE);
47  }
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: PhysxShapeDesc::set_local_pos
52 // Access: Published
53 // Description:
54 ////////////////////////////////////////////////////////////////////
55 void PhysxShapeDesc::
56 set_local_pos(const LPoint3f &pos) {
57 
58  nassertv(!pos.is_nan());
59  ptr()->localPose.t = PhysxManager::point3_to_nxVec3(pos);
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: PhysxShapeDesc::set_local_mat
64 // Access: Published
65 // Description:
66 ////////////////////////////////////////////////////////////////////
67 void PhysxShapeDesc::
68 set_local_mat(const LMatrix4f &mat) {
69 
70  nassertv(!mat.is_nan());
71  ptr()->localPose = PhysxManager::mat4_to_nxMat34(mat);
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: PhysxShapeDesc::set_local_hpr
76 // Access: Published
77 // Description:
78 ////////////////////////////////////////////////////////////////////
79 void PhysxShapeDesc::
80 set_local_hpr(float h, float p, float r) {
81 
82  LQuaternionf q;
83  LMatrix3f rot;
84  NxMat34 m;
85 
86  q.set_hpr(LVector3f(h, p, r));
87  q.extract_to_matrix(rot);
88 
89  ptr()->localPose.M = PhysxManager::mat3_to_nxMat33(rot);
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: PhysxShapeDesc::set_skin_width
94 // Access: Published
95 // Description: Specifies by how much shapes can interpenetrate.
96 //
97 // Two shapes will interpenetrate by the sum of their
98 // skin widths. This means that their graphical
99 // representations should be adjusted so that they
100 // just touch when the shapes are interpenetrating.
101 //
102 // The default skin width is the 'physx-skin-width'
103 // parameter.
104 //
105 // A skin width sum of zero for two bodies is not
106 // permitted because it will lead to an unstable
107 // simulation.
108 //
109 // If your simulation jitters because resting bodies
110 // occasionally lose contact, increasing the size of
111 // your collision volumes and the skin width may
112 // improve things.
113 ////////////////////////////////////////////////////////////////////
114 void PhysxShapeDesc::
115 set_skin_width(float skinWidth) {
116 
117  nassertv(skinWidth >= 0.0f);
118  ptr()->skinWidth = skinWidth;
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: PhysxShapeDesc::set_shape_flag
123 // Access: Published
124 // Description:
125 ////////////////////////////////////////////////////////////////////
126 void PhysxShapeDesc::
127 set_shape_flag(const PhysxShapeFlag flag, bool value) {
128 
129  if (value == true) {
130  ptr()->shapeFlags |= flag;
131  }
132  else {
133  ptr()->shapeFlags &= ~(flag);
134  }
135 }
136 
137 ////////////////////////////////////////////////////////////////////
138 // Function: PhysxShapeDesc::set_mass
139 // Access: Published
140 // Description: Sets the mass of this individual shape when
141 // computing mass inertial properties for a rigidbody.
142 // When mass<=0.0 then density and volume determine
143 // the mass. Note that this will only be used if the
144 // body has a zero inertia tensor, or if you call
145 // PhysxActor::update_mass_from_shapes explicitly.
146 ////////////////////////////////////////////////////////////////////
147 void PhysxShapeDesc::
148 set_mass(float mass) {
149 
150  ptr()->mass = mass;
151 }
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: PhysxShapeDesc::set_density
155 // Access: Published
156 // Description: Sets the density of this individual shape when
157 // computing mass inertial properties for a rigidbody
158 // (unless a valid mass >0.0 is provided). Note that
159 // this will only be used if the body has a zero
160 // inertia tensor, or if you call
161 // PhysxActor::update_mass_from_shapes explicitly.
162 ////////////////////////////////////////////////////////////////////
163 void PhysxShapeDesc::
164 set_density(float density) {
165 
166  nassertv(density > 0.0f);
167  ptr()->density = density;
168 }
169 
170 ////////////////////////////////////////////////////////////////////
171 // Function: PhysxShapeDesc::set_group
172 // Access: Published
173 // Description:
174 ////////////////////////////////////////////////////////////////////
175 void PhysxShapeDesc::
176 set_group(unsigned short group) {
177 
178  ptr()->group = group;
179 }
180 
181 ////////////////////////////////////////////////////////////////////
182 // Function: PhysxShapeDesc::get_name
183 // Access: Published
184 // Description:
185 ////////////////////////////////////////////////////////////////////
186 const char *PhysxShapeDesc::
187 get_name() const {
188 
189  return ptr()->name;
190 }
191 
192 ////////////////////////////////////////////////////////////////////
193 // Function: PhysxShapeDesc::get_local_pos
194 // Access: Published
195 // Description:
196 ////////////////////////////////////////////////////////////////////
197 LPoint3f PhysxShapeDesc::
198 get_local_pos() const {
199 
200  return PhysxManager::nxVec3_to_point3(ptr()->localPose.t);
201 }
202 
203 ////////////////////////////////////////////////////////////////////
204 // Function: PhysxShapeDesc::get_local_mat
205 // Access: Published
206 // Description:
207 ////////////////////////////////////////////////////////////////////
208 LMatrix4f PhysxShapeDesc::
209 get_local_mat() const {
210 
211  return PhysxManager::nxMat34_to_mat4(ptr()->localPose);
212 }
213 
214 ////////////////////////////////////////////////////////////////////
215 // Function: PhysxShapeDesc::get_skin_width
216 // Access: Published
217 // Description:
218 ////////////////////////////////////////////////////////////////////
219 float PhysxShapeDesc::
220 get_skin_width() const {
221 
222  return ptr()->skinWidth;
223 }
224 
225 ////////////////////////////////////////////////////////////////////
226 // Function: PhysxShapeDesc::get_shape_flag
227 // Access: Published
228 // Description:
229 ////////////////////////////////////////////////////////////////////
230 bool PhysxShapeDesc::
231 get_shape_flag(const PhysxShapeFlag flag) const {
232 
233  return (ptr()->shapeFlags & flag) ? true : false;
234 }
235 
236 ////////////////////////////////////////////////////////////////////
237 // Function: PhysxShapeDesc::get_mass
238 // Access: Published
239 // Description:
240 ////////////////////////////////////////////////////////////////////
241 float PhysxShapeDesc::
242 get_mass() const {
243 
244  return ptr()->mass;
245 }
246 
247 ////////////////////////////////////////////////////////////////////
248 // Function: PhysxShapeDesc::get_density
249 // Access: Published
250 // Description:
251 ////////////////////////////////////////////////////////////////////
252 float PhysxShapeDesc::
253 get_density() const {
254 
255  return ptr()->density;
256 }
257 
258 ////////////////////////////////////////////////////////////////////
259 // Function: PhysxShapeDesc::get_group
260 // Access: Published
261 // Description:
262 ////////////////////////////////////////////////////////////////////
263 unsigned short PhysxShapeDesc::
264 get_group() const {
265 
266  return ptr()->group;
267 }
268 
269 ////////////////////////////////////////////////////////////////////
270 // Function: PhysxShapeDesc::set_material
271 // Access: Published
272 // Description:
273 ////////////////////////////////////////////////////////////////////
274 void PhysxShapeDesc::
275 set_material(const PhysxMaterial &material) {
276 
277  ptr()->materialIndex = material.ptr()->getMaterialIndex();
278 }
279 
280 ////////////////////////////////////////////////////////////////////
281 // Function: PhysxShapeDesc::set_material_index
282 // Access: Published
283 // Description:
284 ////////////////////////////////////////////////////////////////////
285 void PhysxShapeDesc::
286 set_material_index(unsigned short index) {
287 
288  ptr()->materialIndex = index;
289 }
290 
291 ////////////////////////////////////////////////////////////////////
292 // Function: PhysxShapeDesc::get_material_index
293 // Access: Published
294 // Description:
295 ////////////////////////////////////////////////////////////////////
296 unsigned short PhysxShapeDesc::
297 get_material_index() const {
298 
299  return ptr()->materialIndex;
300 }
301 
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 extract_to_matrix(LMatrix3f &m) const
Based on the quat lib from VRPN.
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:464
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
Definition: lmatrix.h:1417
A class for describing a shape&#39;s surface properties.
Definition: physxMaterial.h:51
static NxMat34 mat4_to_nxMat34(const LMatrix4f &m)
Converts from LMatrix4f to NxMat34.
Definition: physxManager.I:145
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
void set_density(float density)
Sets the density of this individual shape when computing mass inertial properties for a rigidbody (un...
static NxMat33 mat3_to_nxMat33(const LMatrix3f &m)
Converts from LMatrix3f to NxMat33.
Definition: physxManager.I:169
void set_hpr(const LVecBase3f &hpr, CoordinateSystem cs=CS_default)
Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.
void set_trigger(bool value)
This shape will become a trigger shape if this parameter is set to TRUE.
This is the base quaternion class.
Definition: lquaternion.h:96
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
Definition: physxManager.I:88
void set_mass(float mass)
Sets the mass of this individual shape when computing mass inertial properties for a rigidbody...
void set_name(const char *name)
Sets a possible debug name.
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110
static LMatrix4f nxMat34_to_mat4(const NxMat34 &m)
Converts from NxMat34 to LMatrix4f.
Definition: physxManager.I:158
void set_skin_width(float skinWidth)
Specifies by how much shapes can interpenetrate.