Panda3D
 All Classes Functions Variables Enumerations
physxSoftBodyDesc.cxx
1 // Filename: physxSoftBodyDesc.cxx
2 // Created by: enn0x (12Sep10)
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 "physxSoftBodyDesc.h"
16 #include "physxSoftBodyMesh.h"
17 #include "physxManager.h"
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: PhysxSoftBodyDesc::set_name
21 // Access: Published
22 // Description:
23 ////////////////////////////////////////////////////////////////////
24 void PhysxSoftBodyDesc::
25 set_name(const char *name) {
26 
27  _name = name ? name : "";
28  _desc.name = _name.c_str();
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: PhysxSoftBodyDesc::set_global_pos
33 // Access: Published
34 // Description:
35 ////////////////////////////////////////////////////////////////////
36 void PhysxSoftBodyDesc::
37 set_global_pos(const LPoint3f &pos) {
38 
39  _desc.globalPose.t = PhysxManager::point3_to_nxVec3(pos);
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: PhysxSoftBodyDesc::set_global_mat
44 // Access: Published
45 // Description:
46 ////////////////////////////////////////////////////////////////////
47 void PhysxSoftBodyDesc::
48 set_global_mat(const LMatrix4f &mat) {
49 
50  _desc.globalPose = PhysxManager::mat4_to_nxMat34(mat);
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: PhysxSoftBodyDesc::set_global_hpr
55 // Access: Published
56 // Description:
57 ////////////////////////////////////////////////////////////////////
58 void PhysxSoftBodyDesc::
59 set_global_hpr(float h, float p, float r) {
60 
61  LQuaternionf q;
62  LMatrix3f rot;
63  NxMat34 m;
64 
65  q.set_hpr(LVector3f(h, p, r));
66  q.extract_to_matrix(rot);
67 
68  _desc.globalPose.M = PhysxManager::mat3_to_nxMat33(rot);
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: PhysxSoftBodyDesc::set_particle_radius
73 // Access: Published
74 // Description:
75 ////////////////////////////////////////////////////////////////////
76 void PhysxSoftBodyDesc::
77 set_particle_radius(float radius) {
78 
79  _desc.particleRadius = radius;
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: PhysxSoftBodyDesc::set_relative_grid_spacing
84 // Access: Published
85 // Description:
86 ////////////////////////////////////////////////////////////////////
87 void PhysxSoftBodyDesc::
88 set_relative_grid_spacing(float spacing) {
89 
90  _desc.relativeGridSpacing = spacing;
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: PhysxSoftBodyDesc::set_collision_response_coefficient
95 // Access: Published
96 // Description:
97 ////////////////////////////////////////////////////////////////////
98 void PhysxSoftBodyDesc::
99 set_collision_response_coefficient(float coef) {
100 
101  _desc.collisionResponseCoefficient = coef;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: PhysxSoftBodyDesc::set_attachment_response_coefficient
106 // Access: Published
107 // Description:
108 ////////////////////////////////////////////////////////////////////
109 void PhysxSoftBodyDesc::
110 set_attachment_response_coefficient(float coef) {
111 
112  _desc.attachmentResponseCoefficient = coef;
113 }
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: PhysxSoftBodyDesc::set_density
117 // Access: Published
118 // Description:
119 ////////////////////////////////////////////////////////////////////
120 void PhysxSoftBodyDesc::
121 set_density(float density) {
122 
123  _desc.density = density;
124 }
125 
126 ////////////////////////////////////////////////////////////////////
127 // Function: PhysxSoftBodyDesc::set_volume_stiffness
128 // Access: Published
129 // Description:
130 ////////////////////////////////////////////////////////////////////
131 void PhysxSoftBodyDesc::
132 set_volume_stiffness(float stiffness) {
133 
134  _desc.volumeStiffness = stiffness;
135 }
136 
137 ////////////////////////////////////////////////////////////////////
138 // Function: PhysxSoftBodyDesc::set_stretching_stiffness
139 // Access: Published
140 // Description:
141 ////////////////////////////////////////////////////////////////////
142 void PhysxSoftBodyDesc::
143 set_stretching_stiffness(float stiffness) {
144 
145  _desc.stretchingStiffness = stiffness;
146 }
147 
148 ////////////////////////////////////////////////////////////////////
149 // Function: PhysxSoftBodyDesc::set_damping_coefficient
150 // Access: Published
151 // Description:
152 ////////////////////////////////////////////////////////////////////
153 void PhysxSoftBodyDesc::
154 set_damping_coefficient(float damping) {
155 
156  _desc.dampingCoefficient = damping;
157 }
158 
159 ////////////////////////////////////////////////////////////////////
160 // Function: PhysxSoftBodyDesc::set_friction
161 // Access: Published
162 // Description:
163 ////////////////////////////////////////////////////////////////////
164 void PhysxSoftBodyDesc::
165 set_friction(float friction) {
166 
167  _desc.friction = friction;
168 }
169 
170 ////////////////////////////////////////////////////////////////////
171 // Function: PhysxSoftBodyDesc::set_tear_factor
172 // Access: Published
173 // Description:
174 ////////////////////////////////////////////////////////////////////
175 void PhysxSoftBodyDesc::
176 set_tear_factor(float tearFactor) {
177 
178  _desc.tearFactor = tearFactor;
179 }
180 
181 ////////////////////////////////////////////////////////////////////
182 // Function: PhysxSoftBodyDesc::set_flag
183 // Access: Published
184 // Description: Raise or lower individual SoftBodyFlag flags.
185 ////////////////////////////////////////////////////////////////////
187 set_flag(PhysxSoftBodyFlag flag, bool value) {
188 
189  if (value == true) {
190  _desc.flags |= flag;
191  }
192  else {
193  _desc.flags &= ~(flag);
194  }
195 }
196 
197 ////////////////////////////////////////////////////////////////////
198 // Function: PhysxSoftBodyDesc::set_solver_iterations
199 // Access: Published
200 // Description: Number of solver iterations.
201 // Small numbers make the simulation faster while
202 // the soft body gets less stiff.
203 ////////////////////////////////////////////////////////////////////
205 set_solver_iterations(unsigned int iterations) {
206 
207  _desc.solverIterations = iterations;
208 }
209 
210 ////////////////////////////////////////////////////////////////////
211 // Function: PhysxSoftBodyDesc::set_soft_body_mesh
212 // Access: Published
213 // Description:
214 ////////////////////////////////////////////////////////////////////
215 void PhysxSoftBodyDesc::
216 set_soft_body_mesh(PhysxSoftBodyMesh *mesh) {
217 
218  _desc.softBodyMesh = mesh->ptr();
219 }
220 
221 ////////////////////////////////////////////////////////////////////
222 // Function: PhysxSoftBodyDesc::get_name
223 // Access: Published
224 // Description:
225 ////////////////////////////////////////////////////////////////////
226 const char *PhysxSoftBodyDesc::
227 get_name() const {
228 
229  return _desc.name;
230 }
231 
232 ////////////////////////////////////////////////////////////////////
233 // Function: PhysxSoftBodyDesc::get_global_pos
234 // Access: Published
235 // Description:
236 ////////////////////////////////////////////////////////////////////
237 LPoint3f PhysxSoftBodyDesc::
238 get_global_pos() const {
239 
240  return PhysxManager::nxVec3_to_point3(_desc.globalPose.t);
241 }
242 
243 ////////////////////////////////////////////////////////////////////
244 // Function: PhysxSoftBodyDesc::get_global_mat
245 // Access: Published
246 // Description:
247 ////////////////////////////////////////////////////////////////////
248 LMatrix4f PhysxSoftBodyDesc::
249 get_global_mat() const {
250 
251  return PhysxManager::nxMat34_to_mat4(_desc.globalPose);
252 }
253 
254 ////////////////////////////////////////////////////////////////////
255 // Function: PhysxSoftBodyDesc::get_particle_radius
256 // Access: Published
257 // Description:
258 ////////////////////////////////////////////////////////////////////
259 float PhysxSoftBodyDesc::
260 get_particle_radius() const {
261 
262  return _desc.particleRadius;
263 }
264 
265 ////////////////////////////////////////////////////////////////////
266 // Function: PhysxSoftBodyDesc::get_relative_grid_spacing
267 // Access: Published
268 // Description:
269 ////////////////////////////////////////////////////////////////////
270 float PhysxSoftBodyDesc::
271 get_relative_grid_spacing() const {
272 
273  return _desc.relativeGridSpacing;
274 }
275 
276 ////////////////////////////////////////////////////////////////////
277 // Function: PhysxSoftBodyDesc::get_collision_response_coefficient
278 // Access: Published
279 // Description:
280 ////////////////////////////////////////////////////////////////////
281 float PhysxSoftBodyDesc::
282 get_collision_response_coefficient() const {
283 
284  return _desc.collisionResponseCoefficient;
285 }
286 
287 ////////////////////////////////////////////////////////////////////
288 // Function: PhysxSoftBodyDesc::get_attachment_response_coefficient
289 // Access: Published
290 // Description:
291 ////////////////////////////////////////////////////////////////////
292 float PhysxSoftBodyDesc::
293 get_attachment_response_coefficient() const {
294 
295  return _desc.attachmentResponseCoefficient;
296 }
297 
298 ////////////////////////////////////////////////////////////////////
299 // Function: PhysxSoftBodyDesc::get_density
300 // Access: Published
301 // Description:
302 ////////////////////////////////////////////////////////////////////
303 float PhysxSoftBodyDesc::
304 get_density() const {
305 
306  return _desc.density;
307 }
308 
309 ////////////////////////////////////////////////////////////////////
310 // Function: PhysxSoftBodyDesc::get_volume_stiffness
311 // Access: Published
312 // Description:
313 ////////////////////////////////////////////////////////////////////
314 float PhysxSoftBodyDesc::
315 get_volume_stiffness() const {
316 
317  return _desc.volumeStiffness;
318 }
319 
320 ////////////////////////////////////////////////////////////////////
321 // Function: PhysxSoftBodyDesc::get_stretching_stiffness
322 // Access: Published
323 // Description:
324 ////////////////////////////////////////////////////////////////////
325 float PhysxSoftBodyDesc::
326 get_stretching_stiffness() const {
327 
328  return _desc.stretchingStiffness;
329 }
330 
331 ////////////////////////////////////////////////////////////////////
332 // Function: PhysxSoftBodyDesc::get_damping_coefficient
333 // Access: Published
334 // Description:
335 ////////////////////////////////////////////////////////////////////
336 float PhysxSoftBodyDesc::
337 get_damping_coefficient() const {
338 
339  return _desc.dampingCoefficient;
340 }
341 
342 ////////////////////////////////////////////////////////////////////
343 // Function: PhysxSoftBodyDesc::get_friction
344 // Access: Published
345 // Description:
346 ////////////////////////////////////////////////////////////////////
347 float PhysxSoftBodyDesc::
348 get_friction() const {
349 
350  return _desc.friction;
351 }
352 
353 ////////////////////////////////////////////////////////////////////
354 // Function: PhysxSoftBodyDesc::get_tear_factor
355 // Access: Published
356 // Description:
357 ////////////////////////////////////////////////////////////////////
358 float PhysxSoftBodyDesc::
359 get_tear_factor() const {
360 
361  return _desc.tearFactor;
362 }
363 
364 ////////////////////////////////////////////////////////////////////
365 // Function: PhysxSoftBodyDesc::get_flag
366 // Access: Published
367 // Description:
368 ////////////////////////////////////////////////////////////////////
369 bool PhysxSoftBodyDesc::
370 get_flag(PhysxSoftBodyFlag flag) const {
371 
372  return (_desc.flags & flag) ? true : false;
373 }
374 
375 ////////////////////////////////////////////////////////////////////
376 // Function: PhysxSoftBodyDesc::get_solver_iterations
377 // Access: Published
378 // Description:
379 ////////////////////////////////////////////////////////////////////
380 unsigned int PhysxSoftBodyDesc::
381 get_solver_iterations() const {
382 
383  return _desc.solverIterations;
384 }
385 
386 /*
387 ////////////////////////////////////////////////////////////////////
388 // Function: PhysxSoftBodyDesc::get_mesh_numbers
389 // Access: Public
390 // Description: Used by PhysScene to query the sizes of arrays
391 // to allocate for the user buffers in PhysxSoftBodyNode.
392 ////////////////////////////////////////////////////////////////////
393 void PhysxSoftBodyDesc::
394 get_mesh_numbers(NxU32 &numVertices, NxU32 &numTriangles) {
395 
396  NxSoftBodyMeshDesc meshDesc;
397  _desc.clothMesh->saveToDesc(meshDesc);
398 
399  numVertices = meshDesc.numVertices;
400  numTriangles = meshDesc.numTriangles;
401 }
402 */
403 
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Definition: physxManager.I:77
void extract_to_matrix(LMatrix3f &m) const
Based on the quat lib from VRPN.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
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
static NxMat33 mat3_to_nxMat33(const LMatrix3f &m)
Converts from LMatrix3f to NxMat33.
Definition: physxManager.I:169
void set_flag(PhysxSoftBodyFlag flag, bool value)
Raise or lower individual SoftBodyFlag flags.
void set_hpr(const LVecBase3f &hpr, CoordinateSystem cs=CS_default)
Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.
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_solver_iterations(unsigned int interations)
Number of solver iterations.
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