Panda3D

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