Panda3D
physxSoftBody.cxx
1 // Filename: physxSoftBody.cxx
2 // Created by: enn0x (13Sep10)
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 "physxSoftBody.h"
16 #include "physxSoftBodyDesc.h"
17 #include "physxSoftBodyNode.h"
18 #include "physxScene.h"
19 #include "physxGroupsMask.h"
20 
21 #include "boundingBox.h"
22 
23 TypeHandle PhysxSoftBody::_type_handle;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: PhysxSoftBody::link
27 // Access: Public
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 void PhysxSoftBody::
31 link(NxSoftBody *softbodyPtr) {
32 
33  // Link self
34  _ptr = softbodyPtr;
35  _error_type = ET_ok;
36  _ptr->userData = this;
37 
38  set_name(softbodyPtr->getName());
39 
40  PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
41  scene->_softbodies.add(this);
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: PhysxSoftBody::unlink
46 // Access: Public
47 // Description:
48 ////////////////////////////////////////////////////////////////////
49 void PhysxSoftBody::
50 unlink() {
51 
52  // Unlink self
53  _ptr->userData = NULL;
54  _error_type = ET_released;
55 
56  PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
57  scene->_softbodies.remove(this);
58 
59  _node = NULL;
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: PhysxSoftBody::release
64 // Access: Published
65 // Description:
66 ////////////////////////////////////////////////////////////////////
67 void PhysxSoftBody::
68 release() {
69 
70  nassertv(_error_type == ET_ok);
71 
72  unlink();
73  _ptr->getScene().releaseSoftBody(*_ptr);
74  _ptr = NULL;
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: PhysxSoftBody::update
79 // Access: Public
80 // Description:
81 ////////////////////////////////////////////////////////////////////
82 void PhysxSoftBody::
83 update() {
84 
85  if (_node) {
86 
87  // Update node mesh data
88  _node->update();
89 
90  // Update node bounding volume
91  NxBounds3 bounds;
92  _ptr->getWorldBounds(bounds);
93 
95  PhysxManager::nxVec3_to_point3(bounds.max));
96  _node->set_bounds(&bb);
97  }
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function: PhysxSoftBody::get_scene
102 // Access: Published
103 // Description: Returns the scene which this soft body belongs to.
104 ////////////////////////////////////////////////////////////////////
106 get_scene() const {
107 
108  nassertr(_error_type == ET_ok, NULL);
109  return (PhysxScene *)_ptr->getScene().userData;
110 }
111 
112 ////////////////////////////////////////////////////////////////////
113 // Function: PhysxSoftBody::get_soft_body_node
114 // Access: Published
115 // Description:
116 ////////////////////////////////////////////////////////////////////
117 PhysxSoftBodyNode *PhysxSoftBody::
118 get_soft_body_node() const {
119 
120  nassertr(_error_type == ET_ok, NULL);
121  return _node;
122 }
123 
124 ////////////////////////////////////////////////////////////////////
125 // Function: PhysxSoftBody::create_soft_body_node
126 // Access: Published
127 // Description:
128 ////////////////////////////////////////////////////////////////////
129 PhysxSoftBodyNode *PhysxSoftBody::
130 create_soft_body_node(const char *name) {
131 
132  nassertr(_error_type == ET_ok, NULL);
133 
134  _node = new PhysxSoftBodyNode(name);
135  _node->allocate(this);
136 
137  return _node;
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: PhysxSoftBody::set_name
142 // Access: Published
143 // Description: Sets a name string for the object that can be
144 // retrieved with get_name().
145 // This is for debugging and is not used by the
146 // engine.
147 ////////////////////////////////////////////////////////////////////
148 void PhysxSoftBody::
149 set_name(const char *name) {
150 
151  nassertv(_error_type == ET_ok);
152 
153  _name = name ? name : "";
154  _ptr->setName(_name.c_str());
155 }
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: PhysxSoftBody::get_name
159 // Access: Published
160 // Description: Retrieves the name string.
161 ////////////////////////////////////////////////////////////////////
162 const char *PhysxSoftBody::
163 get_name() const {
164 
165  nassertr(_error_type == ET_ok, "");
166  return _ptr->getName();
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: PhysxSoftBody::set_group
171 // Access: Published
172 // Description: Sets which collision group this soft body is part
173 // of. Collision group must be between 0 and 31.
174 ////////////////////////////////////////////////////////////////////
175 void PhysxSoftBody::
176 set_group(unsigned int group) {
177 
178  nassertv(_error_type == ET_ok);
179  nassertv(group >= 0 && group < 32);
180  _ptr->setGroup(group);
181 }
182 
183 ////////////////////////////////////////////////////////////////////
184 // Function: PhysxSoftBody::get_group
185 // Access: Published
186 // Description: Retrieves the collision group this soft body is
187 // part of.
188 ////////////////////////////////////////////////////////////////////
189 unsigned int PhysxSoftBody::
190 get_group() const {
191 
192  nassertr(_error_type == ET_ok, 0);
193  return _ptr->getGroup();
194 }
195 
196 ////////////////////////////////////////////////////////////////////
197 // Function: PhysxSoftBody::set_groups_mask
198 // Access: Published
199 // Description: Sets 128-bit mask used for collision filtering.
200 ////////////////////////////////////////////////////////////////////
201 void PhysxSoftBody::
203 
204  nassertv(_error_type == ET_ok);
205 
206  NxGroupsMask _mask = mask.get_mask();
207  _ptr->setGroupsMask(_mask);
208 }
209 
210 ////////////////////////////////////////////////////////////////////
211 // Function: PhysxSoftBody::get_groups_mask
212 // Access: Published
213 // Description: Gets the 128-bit groups mask used for collision
214 // filtering.
215 ////////////////////////////////////////////////////////////////////
218 
219  PhysxGroupsMask mask;
220 
221  nassertr(_error_type == ET_ok, mask);
222 
223  NxGroupsMask _mask = _ptr->getGroupsMask();
224  mask.set_mask(_mask);
225 
226  return mask;
227 }
228 
229 ////////////////////////////////////////////////////////////////////
230 // Function: PhysxSoftBody::get_num_particles
231 // Access: Published
232 // Description: Gets the number of cloth particles.
233 ////////////////////////////////////////////////////////////////////
234 unsigned int PhysxSoftBody::
236 
237  nassertr(_error_type == ET_ok, 0);
238  return _ptr->getNumberOfParticles();
239 }
240 
241 ////////////////////////////////////////////////////////////////////
242 // Function: PhysxSoftBody::set_particle_radius
243 // Access: Published
244 // Description: Sets the soft body particle radius (must be
245 // positive).
246 ////////////////////////////////////////////////////////////////////
247 void PhysxSoftBody::
248 set_particle_radius(float radius) {
249 
250  nassertv(_error_type == ET_ok);
251  _ptr->setParticleRadius(radius);
252 }
253 
254 ////////////////////////////////////////////////////////////////////
255 // Function: PhysxSoftBody::get_particle_radius
256 // Access: Published
257 // Description: Gets the soft body particle radius.
258 ////////////////////////////////////////////////////////////////////
259 float PhysxSoftBody::
261 
262  nassertr(_error_type == ET_ok, 0.0f);
263  return _ptr->getParticleRadius();
264 }
265 
266 ////////////////////////////////////////////////////////////////////
267 // Function: PhysxSoftBody::set_flag
268 // Access: Published
269 // Description: Sets the value of a single flag.
270 ////////////////////////////////////////////////////////////////////
271 void PhysxSoftBody::
272 set_flag(PhysxSoftBodyFlag flag, bool value) {
273 
274  nassertv(_error_type == ET_ok);
275 
276  NxU32 flags = _ptr->getFlags();
277 
278  if (value == true) {
279  flags |= flag;
280  }
281  else {
282  flags &= ~(flag);
283  }
284 
285  _ptr->setFlags(flags);
286 }
287 
288 ////////////////////////////////////////////////////////////////////
289 // Function: PhysxSoftBody::get_flag
290 // Access: Published
291 // Description: Retrieves the value of a single flag.
292 ////////////////////////////////////////////////////////////////////
293 bool PhysxSoftBody::
294 get_flag(PhysxSoftBodyFlag flag) const {
295 
296  nassertr(_error_type == ET_ok, false);
297 
298  return (_ptr->getFlags() & flag) ? true : false;
299 }
300 
301 ////////////////////////////////////////////////////////////////////
302 // Function: PhysxSoftBody::get_density
303 // Access: Published
304 // Description: Gets the soft body density.
305 ////////////////////////////////////////////////////////////////////
306 float PhysxSoftBody::
307 get_density() const {
308 
309  nassertr(_error_type == ET_ok, 0.0f);
310  return _ptr->getDensity();
311 }
312 
313 ////////////////////////////////////////////////////////////////////
314 // Function: PhysxSoftBody::get_relative_grid_spacing
315 // Access: Published
316 // Description: Gets the relative grid spacing for the broad
317 // phase. The cloth is represented by a set of
318 // world aligned cubical cells in broad phase. The
319 // size of these cells is determined by multiplying
320 // the length of the diagonal of the AABB of the
321 // initial soft body size with this constant.
322 ////////////////////////////////////////////////////////////////////
323 float PhysxSoftBody::
325 
326  nassertr(_error_type == ET_ok, 0.0f);
327  return _ptr->getRelativeGridSpacing();
328 }
329 
330 ////////////////////////////////////////////////////////////////////
331 // Function: PhysxSoftBody::set_volume_stiffness
332 // Access: Published
333 // Description: Sets the soft body volume stiffness in the range
334 // from 0 to 1.
335 ////////////////////////////////////////////////////////////////////
336 void PhysxSoftBody::
337 set_volume_stiffness(float stiffness) {
338 
339  nassertv(_error_type == ET_ok);
340  ptr()->setVolumeStiffness(stiffness);
341 }
342 
343 ////////////////////////////////////////////////////////////////////
344 // Function: PhysxSoftBody::get_volume_stiffness
345 // Access: Published
346 // Description: Retrieves the soft body volume stiffness.
347 ////////////////////////////////////////////////////////////////////
348 float PhysxSoftBody::
350 
351  nassertr(_error_type == ET_ok, 0.0f);
352  return ptr()->getVolumeStiffness();
353 }
354 
355 ////////////////////////////////////////////////////////////////////
356 // Function: PhysxSoftBody::set_stretching_stiffness
357 // Access: Published
358 // Description: Sets the soft body stretching stiffness in the
359 // range from 0 to 1.
360 ////////////////////////////////////////////////////////////////////
361 void PhysxSoftBody::
362 set_stretching_stiffness(float stiffness) {
363 
364  nassertv(_error_type == ET_ok);
365  ptr()->setStretchingStiffness(stiffness);
366 }
367 
368 ////////////////////////////////////////////////////////////////////
369 // Function: PhysxSoftBody::get_stretching_stiffness
370 // Access: Published
371 // Description: Retrieves the soft body stretching stiffness.
372 ////////////////////////////////////////////////////////////////////
373 float PhysxSoftBody::
375 
376  nassertr(_error_type == ET_ok, 0.0f);
377  return ptr()->getStretchingStiffness();
378 }
379 
380 ////////////////////////////////////////////////////////////////////
381 // Function: PhysxSoftBody::set_damping_coefficient
382 // Access: Published
383 // Description: Sets the damping coefficient in the range from 0
384 // to 1.
385 ////////////////////////////////////////////////////////////////////
386 void PhysxSoftBody::
388 
389  nassertv(_error_type == ET_ok);
390  ptr()->setDampingCoefficient(coef);
391 }
392 
393 ////////////////////////////////////////////////////////////////////
394 // Function: PhysxSoftBody::get_damping_coefficient
395 // Access: Published
396 // Description: Retrieves the damping coefficient.
397 ////////////////////////////////////////////////////////////////////
398 float PhysxSoftBody::
400 
401  nassertr(_error_type == ET_ok, 0.0f);
402  return ptr()->getDampingCoefficient();
403 }
404 
405 ////////////////////////////////////////////////////////////////////
406 // Function: PhysxSoftBody::set_friction
407 // Access: Published
408 // Description: Sets the soft body friction coefficient in the
409 // range from 0 to 1.
410 ////////////////////////////////////////////////////////////////////
411 void PhysxSoftBody::
412 set_friction(float friction) {
413 
414  nassertv(_error_type == ET_ok);
415  ptr()->setFriction(friction);
416 }
417 
418 ////////////////////////////////////////////////////////////////////
419 // Function: PhysxSoftBody::get_friction
420 // Access: Published
421 // Description: Retrieves the soft body friction coefficient.
422 ////////////////////////////////////////////////////////////////////
423 float PhysxSoftBody::
424 get_friction() const {
425 
426  nassertr(_error_type == ET_ok, 0.0f);
427  return ptr()->getFriction();
428 }
429 
430 ////////////////////////////////////////////////////////////////////
431 // Function: PhysxSoftBody::set_tear_factor
432 // Access: Published
433 // Description: Sets the soft body tear factor (must be larger
434 // than one).
435 ////////////////////////////////////////////////////////////////////
436 void PhysxSoftBody::
437 set_tear_factor(float factor) {
438 
439  nassertv(_error_type == ET_ok);
440  nassertv(factor > 1.0f);
441  ptr()->setTearFactor(factor);
442 }
443 
444 ////////////////////////////////////////////////////////////////////
445 // Function: PhysxSoftBody::get_tear_factor
446 // Access: Published
447 // Description: Retrieves the soft body tear factor.
448 ////////////////////////////////////////////////////////////////////
449 float PhysxSoftBody::
451 
452  nassertr(_error_type == ET_ok, 0.0f);
453  return ptr()->getTearFactor();
454 }
455 
456 ////////////////////////////////////////////////////////////////////
457 // Function: PhysxSoftBody::set_attachment_tear_factor
458 // Access: Published
459 // Description: Sets the soft body attachment tear factor (must be
460 // larger than one).
461 ////////////////////////////////////////////////////////////////////
462 void PhysxSoftBody::
464 
465  nassertv(_error_type == ET_ok);
466  nassertv(factor > 1.0f);
467  ptr()->setAttachmentTearFactor(factor);
468 }
469 
470 ////////////////////////////////////////////////////////////////////
471 // Function: PhysxSoftBody::get_attachment_tear_factor
472 // Access: Published
473 // Description: Retrieves the attachment soft body tear factor.
474 ////////////////////////////////////////////////////////////////////
475 float PhysxSoftBody::
477 
478  nassertr(_error_type == ET_ok, 0.0f);
479  return ptr()->getAttachmentTearFactor();
480 }
481 
482 ////////////////////////////////////////////////////////////////////
483 // Function: PhysxSoftBody::set_solver_iterations
484 // Access: Published
485 // Description: Sets the soft body solver iterations.
486 ////////////////////////////////////////////////////////////////////
487 void PhysxSoftBody::
488 set_solver_iterations(unsigned int iterations) {
489 
490  nassertv(_error_type == ET_ok);
491  ptr()->setSolverIterations(iterations);
492 }
493 
494 ////////////////////////////////////////////////////////////////////
495 // Function: PhysxSoftBody::get_solver_iterations
496 // Access: Published
497 // Description: Retrieves the soft body solver iterations.
498 ////////////////////////////////////////////////////////////////////
499 unsigned int PhysxSoftBody::
501 
502  nassertr(_error_type == ET_ok, 0);
503  return ptr()->getSolverIterations();
504 }
505 
506 ////////////////////////////////////////////////////////////////////
507 // Function: PhysxSoftBody::is_sleeping
508 // Access: Published
509 // Description: Returns true if this soft body is sleeping.
510 //
511 // When a soft body does not move for a period of
512 // time, it is no longer simulated in order to save
513 // time. This state is called sleeping. However,
514 // because the object automatically wakes up when it
515 // is either touched by an awake object, or one of its
516 // properties is changed by the user, the entire sleep
517 // mechanism should be transparent to the user.
518 ////////////////////////////////////////////////////////////////////
519 bool PhysxSoftBody::
520 is_sleeping() const {
521 
522  nassertr(_error_type == ET_ok, false);
523  return _ptr->isSleeping();
524 }
525 
526 ////////////////////////////////////////////////////////////////////
527 // Function: PhysxSoftBody::wake_up
528 // Access: Published
529 // Description: Wakes up the soft body if it is sleeping.
530 //
531 // The wakeCounterValue determines how long until the
532 // body is put to sleep, a value of zero means that
533 // the body is sleeping. wake_up(0) is equivalent to
534 // PhysxSoftBody::put_to_sleep().
535 ////////////////////////////////////////////////////////////////////
536 void PhysxSoftBody::
537 wake_up(float wakeCounterValue) {
538 
539  nassertv(_error_type == ET_ok);
540  _ptr->wakeUp(wakeCounterValue);
541 }
542 
543 ////////////////////////////////////////////////////////////////////
544 // Function: PhysxSoftBody::put_to_sleep
545 // Access: Published
546 // Description: Forces the soft body to sleep.
547 //
548 // The soft body will stay asleep until the next
549 // call to simulate, and will not wake up until then
550 // even when otherwise it would (for example a force
551 // is applied to it). It can however wake up during
552 // the next do_physics call.
553 ////////////////////////////////////////////////////////////////////
554 void PhysxSoftBody::
556 
557  nassertv(_error_type == ET_ok);
558  _ptr->putToSleep();
559 }
560 
561 ////////////////////////////////////////////////////////////////////
562 // Function: PhysxSoftBody::set_sleep_linear_velocity
563 // Access: Published
564 // Description: Sets the linear velocity below which an soft body
565 // may go to sleep. SoftBodys whose linear velocity is
566 // above this threshold will not be put to sleep.
567 //
568 // Setting the sleep angular/linear velocity only
569 // makes sense when the BF_energy_sleep_test is not
570 // set.
571 ////////////////////////////////////////////////////////////////////
572 void PhysxSoftBody::
573 set_sleep_linear_velocity(float threshold) {
574 
575  nassertv(_error_type == ET_ok);
576  _ptr->setSleepLinearVelocity(threshold);
577 }
578 
579 ////////////////////////////////////////////////////////////////////
580 // Function: PhysxSoftBody::get_sleep_linear_velocity
581 // Access: Published
582 // Description: Returns the linear velocity below which an soft
583 // body may go to sleep. Soft bodies whose linear
584 // velocity is above this threshold will not be put
585 // to sleep.
586 ////////////////////////////////////////////////////////////////////
587 float PhysxSoftBody::
589 
590  nassertr(_error_type == ET_ok, 0.0f);
591  return _ptr->getSleepLinearVelocity();
592 }
593 
594 #if NX_SDK_VERSION_NUMBER > 281
595 ////////////////////////////////////////////////////////////////////
596 // Function: PhysxSoftBody::set_self_collision_thickness
597 // Access: Published
598 // Description: Sets the soft body self collision thickness (must
599 // be positive).
600 ////////////////////////////////////////////////////////////////////
601 void PhysxSoftBody::
602 set_self_collision_thickness(float thickness) {
603 
604  nassertv(_error_type == ET_ok);
605  _ptr->setSelfCollisionThickness(thickness);
606 }
607 
608 ////////////////////////////////////////////////////////////////////
609 // Function: PhysxSoftBody::get_self_collision_thickness
610 // Access: Published
611 // Description: Gets the soft body self collision thickness.
612 ////////////////////////////////////////////////////////////////////
613 float PhysxSoftBody::
614 get_self_collision_thickness() const {
615 
616  nassertr(_error_type == ET_ok, 0.0f);
617  return _ptr->getSelfCollisionThickness();
618 }
619 
620 ////////////////////////////////////////////////////////////////////
621 // Function: PhysxSoftBody::set_hard_stretch_limitation_factor
622 // Access: Published
623 // Description: Sets the soft body hard stretch elongation limit.
624 ////////////////////////////////////////////////////////////////////
625 void PhysxSoftBody::
626 set_hard_stretch_limitation_factor(float factor) {
627 
628  nassertv(_error_type == ET_ok);
629  ptr()->setHardStretchLimitationFactor(factor);
630 }
631 
632 ////////////////////////////////////////////////////////////////////
633 // Function: PhysxSoftBody::get_hard_stretch_limitation_factor
634 // Access: Published
635 // Description: Retrieves the soft body hard stretch elongation
636 // limit.
637 ////////////////////////////////////////////////////////////////////
638 float PhysxSoftBody::
639 get_hard_stretch_limitation_factor() const {
640 
641  nassertr(_error_type == ET_ok, 0.0f);
642  return ptr()->getHardStretchLimitationFactor();
643 }
644 #endif // NX_SDK_VERSION_NUMBER > 281
645 
646 
647 
648 
649 
650 
651 
652 
653 /*
654 ////////////////////////////////////////////////////////////////////
655 // Function: PhysxSoftBody::attach_vertex_to_global_pos
656 // Access: Published
657 // Description: Attaches a cloth vertex to a position in world
658 // space.
659 ////////////////////////////////////////////////////////////////////
660 void PhysxSoftBody::
661 attach_vertex_to_global_pos(unsigned int vertexId, LPoint3f const &pos) {
662 
663  nassertv(_error_type == ET_ok);
664  nassertv(!pos.is_nan());
665 
666  _ptr->attachVertexToGlobalPosition(vertexId, PhysxManager::point3_to_nxVec3(pos));
667 }
668 
669 ////////////////////////////////////////////////////////////////////
670 // Function: PhysxSoftBody::attach_to_shape
671 // Access: Published
672 // Description: Attaches the cloth to a shape. All cloth points
673 // currently inside the shape are attached.
674 //
675 // This method only works with primitive and convex
676 // shapes. Since the inside of a general triangle mesh
677 // is not clearly defined.
678 ////////////////////////////////////////////////////////////////////
679 void PhysxSoftBody::
680 attach_to_shape(PhysxShape *shape) {
681 
682  nassertv(_error_type == ET_ok);
683  nassertv(shape);
684 
685  NxU32 attachmentFlags = 0; // --TODO--
686  _ptr->attachToShape(shape->ptr(), attachmentFlags);
687 }
688 
689 ////////////////////////////////////////////////////////////////////
690 // Function: PhysxSoftBody::attach_to_colliding_shapes
691 // Access: Published
692 // Description: Attaches the cloth to all shapes, currently
693 // colliding.
694 //
695 // This method only works with primitive and convex
696 // shapes. Since the inside of a general triangle mesh
697 // is not clearly defined.
698 ////////////////////////////////////////////////////////////////////
699 void PhysxSoftBody::
700 attach_to_colliding_shapes() {
701 
702  nassertv(_error_type == ET_ok);
703 
704  NxU32 attachmentFlags = 0; // --TODO--
705  _ptr->attachToCollidingShapes(attachmentFlags);
706 }
707 
708 ////////////////////////////////////////////////////////////////////
709 // Function: PhysxSoftBody::detach_from_shape
710 // Access: Published
711 // Description: Detaches the cloth from a shape it has been
712 // attached to before.
713 //
714 // If the cloth has not been attached to the shape
715 // before, the call has no effect.
716 ////////////////////////////////////////////////////////////////////
717 void PhysxSoftBody::
718 detach_from_shape(PhysxShape *shape) {
719 
720  nassertv(_error_type == ET_ok);
721  nassertv(shape);
722 
723  _ptr->detachFromShape(shape->ptr());
724 }
725 
726 ////////////////////////////////////////////////////////////////////
727 // Function: PhysxSoftBody::free_vertex
728 // Access: Published
729 // Description: Frees a previously attached cloth point.
730 ////////////////////////////////////////////////////////////////////
731 void PhysxSoftBody::
732 free_vertex(unsigned int vertexId) {
733 
734  nassertv(_error_type == ET_ok);
735  _ptr->freeVertex(vertexId);
736 }
737 
738 ////////////////////////////////////////////////////////////////////
739 // Function: PhysxSoftBody::attach_vertex_to_shape
740 // Access: Published
741 // Description: Attaches a cloth vertex to a local position within
742 // a shape.
743 ////////////////////////////////////////////////////////////////////
744 void PhysxSoftBody::
745 attach_vertex_to_shape(unsigned int vertexId, PhysxShape *shape, LPoint3f const &localPos) {
746 
747  nassertv(_error_type == ET_ok);
748  nassertv(!localPos.is_nan());
749  nassertv(shape);
750 
751  NxU32 attachmentFlags = 0; // --TODO--
752  _ptr->attachVertexToShape(vertexId, shape->ptr(),
753  PhysxManager::point3_to_nxVec3(localPos),
754  attachmentFlags);
755 }
756 
757 ////////////////////////////////////////////////////////////////////
758 // Function: PhysxSoftBody::get_vertex_attachment_status
759 // Access: Published
760 // Description: Return the attachment status of the given vertex.
761 ////////////////////////////////////////////////////////////////////
762 PhysxEnums::PhysxVertexAttachmentStatus PhysxSoftBody::
763 get_vertex_attachment_status(unsigned int vertexId) const {
764 
765  nassertr(_error_type == ET_ok, VAS_none);
766  // --TODO-- nassertr(vertexId < _ptr->getNumberOfParticles(), VAS_none);
767 
768  return (PhysxVertexAttachmentStatus) _ptr->getVertexAttachmentStatus(vertexId);
769 }
770 
771 ////////////////////////////////////////////////////////////////////
772 // Function: PhysxSoftBody::get_vertex_attachment_shape
773 // Access: Published
774 // Description: Returns the pointer to an attached shape pointer
775 // of the given vertex. If the vertex is not attached
776 // or attached to a global position, NULL is returned.
777 ////////////////////////////////////////////////////////////////////
778 PhysxShape *PhysxSoftBody::
779 get_vertex_attachment_shape(unsigned int vertexId) const {
780 
781  nassertr(_error_type == ET_ok, NULL);
782  // --TODO-- nassertr(vertexId < _ptr->getNumberOfParticles(), NULL);
783 
784  NxShape *shapePtr = _ptr->getVertexAttachmentShape(vertexId);
785  PhysxShape *shape = shapePtr ? (PhysxShape *)(shapePtr->userData) : NULL;
786 
787  return shape;
788 }
789 
790 ////////////////////////////////////////////////////////////////////
791 // Function: PhysxSoftBody::get_vertex_attachment_pos
792 // Access: Published
793 // Description: Returns the attachment position of the given
794 // vertex. If the vertex is attached to shape, the
795 // position local to the shape's pose is returned. If
796 // the vertex is not attached, the return value is
797 // undefined.
798 ////////////////////////////////////////////////////////////////////
799 LPoint3f PhysxSoftBody::
800 get_vertex_attachment_pos(unsigned int vertexId) const {
801 
802  nassertr(_error_type == ET_ok, LPoint3f::zero());
803  // --TODO-- nassertr(vertexId < _ptr->getNumberOfParticles(), LPoint3f::zero());
804 
805  return PhysxManager::nxVec3_to_point3(_ptr->getVertexAttachmentPosition(vertexId));
806 }
807 
808 ////////////////////////////////////////////////////////////////////
809 // Function: PhysxSoftBody::set_external_acceleration
810 // Access: Published
811 // Description: Sets an external acceleration which affects all non
812 // attached particles of the cloth.
813 ////////////////////////////////////////////////////////////////////
814 void PhysxSoftBody::
815 set_external_acceleration(LVector3f const &acceleration) {
816 
817  nassertv(_error_type == ET_ok);
818  nassertv_always(!acceleration.is_nan());
819 
820  _ptr->setExternalAcceleration(PhysxManager::vec3_to_nxVec3(acceleration));
821 }
822 
823 ////////////////////////////////////////////////////////////////////
824 // Function: PhysxSoftBody::set_wind_acceleration
825 // Access: Published
826 // Description: Sets an acceleration acting normal to the cloth
827 // surface at each vertex.
828 ////////////////////////////////////////////////////////////////////
829 void PhysxSoftBody::
830 set_wind_acceleration(LVector3f const &acceleration) {
831 
832  nassertv(_error_type == ET_ok);
833  nassertv_always(!acceleration.is_nan());
834 
835  _ptr->setWindAcceleration(PhysxManager::vec3_to_nxVec3(acceleration));
836 }
837 
838 ////////////////////////////////////////////////////////////////////
839 // Function: PhysxSoftBody::get_external_acceleration
840 // Access: Published
841 // Description: Retrieves the external acceleration which affects
842 // all non attached particles of the cloth.
843 ////////////////////////////////////////////////////////////////////
844 LVector3f PhysxSoftBody::
845 get_external_acceleration() const {
846 
847  nassertr(_error_type == ET_ok, LVector3f::zero());
848  return PhysxManager::nxVec3_to_vec3(_ptr->getExternalAcceleration());
849 }
850 
851 ////////////////////////////////////////////////////////////////////
852 // Function: PhysxSoftBody::get_wind_acceleration
853 // Access: Published
854 // Description: Retrieves the acceleration acting normal to the
855 // cloth surface at each vertex
856 ////////////////////////////////////////////////////////////////////
857 LVector3f PhysxSoftBody::
858 get_wind_acceleration() const {
859 
860  nassertr(_error_type == ET_ok, LVector3f::zero());
861  return PhysxManager::nxVec3_to_vec3(_ptr->getWindAcceleration());
862 }
863 
864 ////////////////////////////////////////////////////////////////////
865 // Function: PhysxSoftBody::add_force_at_vertex
866 // Access: Published
867 // Description: Applies a force (or impulse) defined in the
868 // global coordinate frame, to a particular vertex
869 // of the cloth.
870 ////////////////////////////////////////////////////////////////////
871 void PhysxSoftBody::
872 add_force_at_vertex(LVector3f const &force, int vertexId, PhysxForceMode mode) {
873 
874  nassertv(_error_type == ET_ok);
875  _ptr->addForceAtVertex(PhysxManager::vec3_to_nxVec3(force),
876  vertexId,
877  (NxForceMode) mode);
878 }
879 
880 ////////////////////////////////////////////////////////////////////
881 // Function: PhysxSoftBody::add_force_at_pos
882 // Access: Published
883 // Description: Applies a radial force (or impulse) at a
884 // particular position. All vertices within radius
885 // will be affected with a quadratic drop-off.
886 ////////////////////////////////////////////////////////////////////
887 void PhysxSoftBody::
888 add_force_at_pos(LPoint3f const &pos, float magnitude, float radius, PhysxForceMode mode) {
889 
890  nassertv(_error_type == ET_ok);
891  _ptr->addForceAtPos(PhysxManager::point3_to_nxVec3(pos),
892  magnitude,
893  radius,
894  (NxForceMode) mode);
895 }
896 
897 ////////////////////////////////////////////////////////////////////
898 // Function: PhysxSoftBody::add_directed_force_at_pos
899 // Access: Published
900 // Description: Applies a directed force (or impulse) at a
901 // particular position. All vertices within radius
902 // will be affected with a quadratic drop-off.
903 ////////////////////////////////////////////////////////////////////
904 void PhysxSoftBody::
905 add_directed_force_at_pos(LPoint3f const &pos, LVector3f const &force, float radius, PhysxForceMode mode) {
906 
907  nassertv(_error_type == ET_ok);
908  _ptr->addDirectedForceAtPos(PhysxManager::point3_to_nxVec3(pos),
909  PhysxManager::vec3_to_nxVec3(force),
910  radius,
911  (NxForceMode) mode);
912 }
913 */
914 
PhysxScene * get_scene() const
Returns the scene which this soft body belongs to.
void set_attachment_tear_factor(float factor)
Sets the soft body attachment tear factor (must be larger than one).
bool is_sleeping() const
Returns true if this soft body is sleeping.
An axis-aligned bounding box; that is, a minimum and maximum coordinate triple.
Definition: boundingBox.h:31
float get_damping_coefficient() const
Retrieves the damping coefficient.
float get_tear_factor() const
Retrieves the soft body tear factor.
unsigned int get_solver_iterations() const
Retrieves the soft body solver iterations.
float get_sleep_linear_velocity() const
Returns the linear velocity below which an soft body may go to sleep.
void wake_up(float wakeCounterValue=NX_SLEEP_INTERVAL)
Wakes up the soft body if it is sleeping.
float get_density() const
Gets the soft body density.
A scene is a collection of bodies, constraints, and effectors which can interact. ...
Definition: physxScene.h:73
void set_volume_stiffness(float stiffness)
Sets the soft body volume stiffness in the range from 0 to 1.
void set_damping_coefficient(float coef)
Sets the damping coefficient in the range from 0 to 1.
void set_particle_radius(float radius)
Sets the soft body particle radius (must be positive).
unsigned int get_group() const
Retrieves the collision group this soft body is part of.
bool get_flag(PhysxSoftBodyFlag flag) const
Retrieves the value of a single flag.
void set_group(unsigned int group)
Sets which collision group this soft body is part of.
void set_friction(float friction)
Sets the soft body friction coefficient in the range from 0 to 1.
void set_stretching_stiffness(float stiffness)
Sets the soft body stretching stiffness in the range from 0 to 1.
PhysxGroupsMask get_groups_mask() const
Gets the 128-bit groups mask used for collision filtering.
void set_name(const char *name)
Sets a name string for the object that can be retrieved with get_name().
float get_relative_grid_spacing() const
Gets the relative grid spacing for the broad phase.
void set_flag(PhysxSoftBodyFlag flag, bool value)
Sets the value of a single flag.
Renderable geometry which represents a soft body mesh.
void set_tear_factor(float factor)
Sets the soft body tear factor (must be larger than one).
void set_groups_mask(const PhysxGroupsMask &mask)
Sets 128-bit mask used for collision filtering.
float get_particle_radius() const
Gets the soft body particle radius.
float get_friction() const
Retrieves the soft body friction coefficient.
void set_solver_iterations(unsigned int iterations)
Sets the soft body solver iterations.
const char * get_name() const
Retrieves the name string.
void set_sleep_linear_velocity(float threshold)
Sets the linear velocity below which an soft body may go to sleep.
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
Definition: physxManager.I:88
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
float get_attachment_tear_factor() const
Retrieves the attachment soft body tear factor.
float get_volume_stiffness() const
Retrieves the soft body volume stiffness.
void put_to_sleep()
Forces the soft body to sleep.
float get_stretching_stiffness() const
Retrieves the soft body stretching stiffness.
unsigned int get_num_particles()
Gets the number of cloth particles.
128-bit bitmask class.