Panda3D
physxScene.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 physxScene.cxx
10  * @author enn0x
11  * @date 2009-09-14
12  */
13 
14 #include "physxScene.h"
15 #include "physxManager.h"
16 #include "physxActorDesc.h"
17 #include "physxForceFieldDesc.h"
19 #include "physxControllerDesc.h"
20 #include "physxSceneStats2.h"
22 #include "physxVehicle.h"
23 #include "physxVehicleDesc.h"
24 #include "physxCloth.h"
25 #include "physxClothDesc.h"
26 #include "physxSoftBody.h"
27 #include "physxSoftBodyDesc.h"
28 
29 TypeHandle PhysxScene::_type_handle;
30 
31 PStatCollector PhysxScene::_pcollector_fetch_results("App:PhysX:Fetch Results");
32 PStatCollector PhysxScene::_pcollector_update_transforms("App:PhysX:Update Transforms");
33 PStatCollector PhysxScene::_pcollector_debug_renderer("App:PhysX:Debug Renderer");
34 PStatCollector PhysxScene::_pcollector_simulate("App:PhysX:Simulate");
35 PStatCollector PhysxScene::_pcollector_cloth("App:PhysX:Cloth");
36 PStatCollector PhysxScene::_pcollector_softbody("App:PhysX:Softbody");
37 
38 /**
39  *
40  */
41 void PhysxScene::
42 link(NxScene *scenePtr) {
43 
44  // Link self
45  _ptr = scenePtr;
46  _ptr->userData = this;
47  _error_type = ET_ok;
48  PhysxManager::get_global_ptr()->_scenes.add(this);
49 
50  _cm = NxCreateControllerManager(NxGetPhysicsSDKAllocator());
51  nassertv_always(_cm);
52 
53  // Link materials
54  NxMaterial *materials[5];
55  NxU32 iterator = 0;
56 
57  while (NxU32 i=_ptr->getMaterialArray(materials, 5, iterator)) {
58  while(i--) {
59  PhysxMaterial *material = new PhysxMaterial();
60  material->link(materials[i]);
61  }
62  }
63 }
64 
65 /**
66  *
67  */
68 void PhysxScene::
69 unlink() {
70 
71  // Unlink vehicles
72  for (unsigned int i=0; i < _vehicles.size(); i++) {
73  _vehicles[i]->release();
74  }
75 
76  // Unlink controllers
77  NxU32 nControllers = _cm->getNbControllers();
78 
79  for (NxU32 i=0; i < nControllers; i++) {
80  NxController *controllerPtr = _cm->getController(i);
81  PhysxController *controller = (PhysxController *)controllerPtr->getUserData();
82  controller->unlink();
83  }
84 
85  // Unlink actors
86  NxActor **actors = _ptr->getActors();
87  NxU32 nActors = _ptr->getNbActors();
88 
89  for (NxU32 i=0; i < nActors; i++) {
90  PhysxActor *actor = (PhysxActor *)actors[i]->userData;
91 
92  // Actor could have already been unlinked by controller
93  if (actor) {
94  actor->unlink();
95  }
96  }
97 
98  // Unlink joints
99  NxU32 nJoints = _ptr->getNbJoints();
100 
101  _ptr->resetJointIterator();
102  for (NxU32 i=0; i < nJoints; i++) {
103  NxJoint *jointPtr = _ptr->getNextJoint();
104  PhysxJoint *joint = (PhysxJoint *)jointPtr->userData;
105  joint->unlink();
106  }
107 
108  // Unlink force fields
109  NxForceField **fields = _ptr->getForceFields();
110  NxU32 nFields = _ptr->getNbForceFields();
111 
112  for (NxU32 i=0; i < nFields; i++) {
113  PhysxForceField *field = (PhysxForceField *)fields[i]->userData;
114  field->unlink();
115  }
116 
117  // Unlink force field shape groups
118  NxU32 nGroups = _ptr->getNbForceFieldShapeGroups();
119 
120  _ptr->resetForceFieldShapeGroupsIterator();
121  for (NxU32 i=0; i < nGroups; i++) {
122  NxForceFieldShapeGroup *groupPtr = _ptr->getNextForceFieldShapeGroup();
123  PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)groupPtr->userData;
124  group->unlink();
125  }
126 
127  // Unlink cloths
128  NxCloth **cloths = _ptr->getCloths();
129  NxU32 nCloths = _ptr->getNbCloths();
130 
131  for (NxU32 i=0; i < nCloths; i++) {
132  PhysxCloth *cloth = (PhysxCloth *)cloths[i]->userData;
133  cloth->unlink();
134  }
135 
136  // Unlink softbodies
137  NxSoftBody **softbodies = _ptr->getSoftBodies();
138  NxU32 nSoftbodies = _ptr->getNbSoftBodies();
139 
140  for (NxU32 i=0; i < nSoftbodies; i++) {
141  PhysxSoftBody *softbody = (PhysxSoftBody *)softbodies[i]->userData;
142  softbody->unlink();
143  }
144 
145  // Unlink materials
146  NxMaterial *materials[5];
147  NxU32 iterator = 0;
148 
149  while (NxU32 i=_ptr->getMaterialArray(materials, 5, iterator)) {
150  while(i--) {
151  PhysxMaterial *material = (PhysxMaterial *)materials[i]->userData;
152  material->unlink();
153  }
154  }
155 
156  // Unlink self
157  _cm->purgeControllers();
158  NxReleaseControllerManager(_cm);
159 
160  _ptr->userData = nullptr;
161  _error_type = ET_released;
162 
163  PhysxManager::get_global_ptr()->_scenes.remove(this);
164 }
165 
166 /**
167  *
168  */
169 void PhysxScene::
170 release() {
171 
172  nassertv(_error_type == ET_ok);
173 
174  unlink();
175  NxPhysicsSDK *sdk = NxGetPhysicsSDK();
176  sdk->releaseScene(*_ptr);
177  _ptr = nullptr;
178 }
179 
180 /**
181  * Advances the simulation by an elapsedTime time. The elapsed time has to be
182  * in the range (0, inf).
183  *
184  * It is not allowed to modify the physics scene in between the simulate(dt)
185  * and the fetch_results calls! But it is allowed to read from the scene and
186  * do additional computations, e. g. AI, in between these calls.
187  */
189 simulate(float dt) {
190 
191  nassertv(_error_type == ET_ok);
192 
193  _pcollector_simulate.start();
194 
195  // Update all vehicles
196  for (unsigned int i=0; i < _vehicles.size(); i++) {
197  PhysxVehicle *vehicle = _vehicles[i];
198  vehicle->update_vehicle(dt);
199  }
200 
201  // Update all controllers
202  for (NxU32 i=0; i < _cm->getNbControllers(); i++) {
203  NxController *controllerPtr = _cm->getController(i);
204  PhysxController *controller = (PhysxController *)controllerPtr->getUserData();
205  controller->update_controller(dt);
206  }
207 
208  _cm->updateControllers();
209 
210  // Simulate and flush streams
211  _ptr->simulate(dt);
212  _ptr->flushStream();
213 
214  _pcollector_simulate.stop();
215 }
216 
217 /**
218  * Waits until the simulation has finished, and then updates the scene graph
219  * with with simulation results.
220  *
221  * It is not allowed to modify the physics scene in between the simulate(dt)
222  * and the fetch_results calls! But it is allowed to read from the scene and
223  * do additional computations, e. g. AI, in between these calls.
224  */
226 fetch_results() {
227 
228  nassertv(_error_type == ET_ok);
229  nassertv(_ptr != nullptr);
230 
231  _pcollector_fetch_results.start();
232  _ptr->fetchResults(NX_RIGID_BODY_FINISHED, true);
233  _pcollector_fetch_results.stop();
234 
235  // Update node transforms
236  _pcollector_update_transforms.start();
237 
238  NxU32 nbTransforms = 0;
239  NxActiveTransform *activeTransforms = _ptr->getActiveTransforms(nbTransforms);
240 
241  if (nbTransforms && activeTransforms) {
242  for (NxU32 i=0; i<nbTransforms; ++i) {
243 
244  // Objects created by the Visual Remote Debugger might not have user
245  // data. So check if user data ist set.
246  void *userData = activeTransforms[i].userData;
247  if (userData) {
248  LMatrix4f m = PhysxManager::nxMat34_to_mat4(activeTransforms[i].actor2World);
249  PhysxActor *actor = (PhysxActor *)userData;
250  actor->update_transform(m);
251  }
252  }
253  }
254  _pcollector_update_transforms.stop();
255 
256  // Update debug node
257  _pcollector_debug_renderer.start();
258  _debugNode->update(_ptr);
259  _pcollector_debug_renderer.stop();
260 
261  nassertv(_ptr->isWritable());
262 
263  // Update cloth nodes
264  _pcollector_cloth.start();
265 
266  NxCloth **cloths = _ptr->getCloths();
267  for (NxU32 i=0; i < _ptr->getNbCloths(); i++) {
268  PT(PhysxCloth) cloth = (PhysxCloth *)cloths[i]->userData;
269  cloth->update();
270  }
271 
272  _pcollector_cloth.stop();
273 
274  // Update softbody nodes
275  _pcollector_softbody.start();
276 
277  NxSoftBody **softbodies = _ptr->getSoftBodies();
278  for (NxU32 i=0; i < _ptr->getNbSoftBodies(); i++) {
279  PT(PhysxSoftBody) softbody = (PhysxSoftBody *)softbodies[i]->userData;
280  softbody->update();
281  }
282 
283  _pcollector_softbody.stop();
284 }
285 
286 /**
287  * Sets simulation timing parameters used in simulate.
288  */
291 
292  nassertv(_error_type == ET_ok);
293  _ptr->setTiming(0, 0, NX_TIMESTEP_VARIABLE);
294 }
295 
296 /**
297  * Sets simulation timing parameters used in simulate. The elapsed time
298  * (parameter "dt" in simulate()) is internally subdivided into up to maxIter
299  * substeps no larger than maxTimestep. If the elapsed time is not a multiple
300  * of maxTimestep then any remaining time is accumulated to be added onto the
301  * elapsed time for the next time step. If more sub steps than maxIter are
302  * needed to advance the simulation by elapsed time, then the remaining time
303  * is also accumulated for the next call to simulate().
304  *
305  * This timing method is strongly preferred for stable, reproducible
306  * simulation.
307  */
309 set_timing_fixed(float maxTimestep, unsigned int maxIter) {
310 
311  nassertv(_error_type == ET_ok);
312  _ptr->setTiming(maxTimestep, maxIter, NX_TIMESTEP_FIXED);
313 }
314 
315 /**
316  * Sets a constant gravity for the entire scene.
317  */
319 set_gravity(const LVector3f &gravity) {
320 
321  nassertv(_error_type == ET_ok);
322  nassertv_always(!gravity.is_nan());
323 
324  _ptr->setGravity(PhysxManager::vec3_to_nxVec3(gravity));
325 }
326 
327 /**
328  * Retrieves the current gravity setting.
329  */
330 LVector3f PhysxScene::
331 get_gravity() const {
332 
333  nassertr(_error_type == ET_ok, LVector3f::zero());
334 
335  NxVec3 gravity;
336  _ptr->getGravity(gravity);
337  return PhysxManager::nxVec3_to_vec3(gravity);
338 }
339 
340 /**
341  *
342  */
343 unsigned int PhysxScene::
344 get_num_actors() const {
345 
346  nassertr(_error_type == ET_ok,-1);
347 
348  return _ptr->getNbActors();
349 }
350 
351 /**
352  *
353  */
354 PhysxActor *PhysxScene::
355 create_actor(PhysxActorDesc &desc) {
356 
357  nassertr(_error_type == ET_ok, nullptr);
358  nassertr(desc.is_valid(), nullptr);
359 
360  PhysxActor *actor = new PhysxActor();
361  nassertr(actor, nullptr);
362 
363  NxActor *actorPtr = _ptr->createActor(desc._desc);
364  nassertr(actorPtr, nullptr);
365 
366  actor->link(actorPtr);
367 
368  return actor;
369 }
370 
371 /**
372  *
373  */
374 PhysxActor *PhysxScene::
375 get_actor(unsigned int idx) const {
376 
377  nassertr(_error_type == ET_ok, nullptr);
378  nassertr_always(idx < _ptr->getNbActors(), nullptr);
379 
380  NxActor *actorPtr = _ptr->getActors()[idx];
381  PhysxActor *actor = (PhysxActor *)(actorPtr->userData);
382 
383  return actor;
384 }
385 
386 /**
387  * Retrieves the debug geom node for this scene. The debug geom node is used
388  * to visualize information about the physical scene which can be useful for
389  * debugging an application.
390  *
391  * The debug geom node geometry is generated in global coordinates. In order
392  * to see correct information it is important not to dislocate the debug node.
393  * Reparent it to render and leave position at (0,0,0).
394  */
397 
398  nassertr(_error_type == ET_ok, nullptr);
399  return _debugNode;
400 }
401 
402 /**
403  *
404  */
405 void PhysxScene::
406 enable_contact_reporting(bool enabled) {
407 
408  nassertv(_error_type == ET_ok);
409 
410  if (enabled) {
411  _ptr->setUserContactReport(&_contact_report);
412  _contact_report.enable();
413  }
414  else {
415  _ptr->setUserContactReport(nullptr);
416  _contact_report.disable();
417  }
418 }
419 
420 /**
421  *
422  */
423 bool PhysxScene::
424 is_contact_reporting_enabled() const {
425 
426  nassertr(_error_type == ET_ok, false);
427 
428  return _contact_report.is_enabled();
429 }
430 
431 /**
432  *
433  */
434 void PhysxScene::
435 enable_trigger_reporting(bool enabled) {
436 
437  nassertv(_error_type == ET_ok);
438 
439  if (enabled) {
440  _ptr->setUserTriggerReport(&_trigger_report);
441  _trigger_report.enable();
442  }
443  else {
444  _ptr->setUserTriggerReport(nullptr);
445  _trigger_report.disable();
446  }
447 }
448 
449 /**
450  *
451  */
452 bool PhysxScene::
453 is_trigger_reporting_enabled() const {
454 
455  nassertr(_error_type == ET_ok, false);
456 
457  return _trigger_report.is_enabled();
458 }
459 
460 /**
461  *
462  */
463 void PhysxScene::
464 enable_controller_reporting(bool enabled) {
465 
466  nassertv(_error_type == ET_ok);
467 
468  if (enabled) {
469  _controller_report.enable();
470  }
471  else {
472  _controller_report.disable();
473  }
474 }
475 
476 /**
477  *
478  */
479 bool PhysxScene::
480 is_controller_reporting_enabled() const {
481 
482  nassertr(_error_type == ET_ok, false);
483 
484  return _controller_report.is_enabled();
485 }
486 
487 /**
488  * Return the number of materials in the scene.
489  *
490  * Note that the returned value is not related to material indices. Those may
491  * not be allocated continuously, and its values may be higher than
492  * get_num_materials(). This will also include the default material which
493  * exists without having to be created.
494  */
495 unsigned int PhysxScene::
496 get_num_materials() const {
497 
498  nassertr(_error_type == ET_ok, -1);
499  return _ptr->getNbMaterials();
500 }
501 
502 /**
503  * Creates a new PhysxMaterial.
504  *
505  * The material library consists of an array of material objects. Each
506  * material has a well defined index that can be used to refer to it. If an
507  * object references an undefined material, the default material with index 0
508  * is used instead.
509  */
512 
513  nassertr(_error_type == ET_ok, nullptr);
514  nassertr(desc.is_valid(), nullptr);
515 
516  PhysxMaterial *material = new PhysxMaterial();
517  nassertr(material, nullptr);
518 
519  NxMaterial *materialPtr = _ptr->createMaterial(desc._desc);
520  nassertr(materialPtr, nullptr);
521 
522  material->link(materialPtr);
523 
524  return material;
525 }
526 
527 /**
528  * Creates a new PhysxMaterial using the default settings of
529  * PhysxMaterialDesc.
530  */
532 create_material() {
533 
534  nassertr(_error_type == ET_ok, nullptr);
535 
536  PhysxMaterial *material = new PhysxMaterial();
537  nassertr(material, nullptr);
538 
539  NxMaterialDesc desc;
540  desc.setToDefault();
541  NxMaterial *materialPtr = _ptr->createMaterial(desc);
542  nassertr(materialPtr, nullptr);
543 
544  material->link(materialPtr);
545 
546  return material;
547 }
548 
549 /**
550  * Returns current highest valid material index.
551  *
552  * Note that not all indices below this are valid if some of them belong to
553  * meshes that have beed freed.
554  */
555 unsigned int PhysxScene::
557 
558  nassertr(_error_type == ET_ok, -1);
559  return _ptr->getHighestMaterialIndex();
560 }
561 
562 /**
563  * Retrieves the material with the given material index.
564  *
565  * There is always at least one material in the Scene, the default material
566  * (index 0). If the specified material index is out of range (larger than
567  * get_hightest_material_index) or belongs to a material that has been
568  * released, then the default material is returned, but no error is reported.
569  */
571 get_material_from_index(unsigned int idx) const {
572 
573  nassertr(_error_type == ET_ok, nullptr);
574 
575  NxMaterial *materialPtr = _ptr->getMaterialFromIndex(idx);
576 
577  return (PhysxMaterial *)(materialPtr->userData);
578 }
579 
580 /**
581  * Retrieves the n-th material from the array of materials. See also
582  * get_material_from_index, which retrieves a material by it's material index.
583  */
585 get_material(unsigned int idx) const {
586 
587  nassertr(_error_type == ET_ok, nullptr);
588  nassertr_always(idx < _ptr->getNbMaterials(), nullptr);
589 
590  NxU32 n = _ptr->getNbMaterials();
591  NxMaterial **materials = new NxMaterial *[n];
592  NxU32 materialCount;
593  NxU32 iterator = 0;
594 
595  materialCount = _ptr->getMaterialArray(materials, n, iterator);
596  nassertr((materialCount == n), nullptr);
597 
598  NxMaterial *materialPtr = materials[idx];
599  delete[] materials;
600 
601  return (PhysxMaterial *)(materialPtr->userData);
602 }
603 
604 /**
605  * Return the number of controllers in the scene.
606  */
607 unsigned int PhysxScene::
608 get_num_controllers() const {
609 
610  nassertr(_error_type == ET_ok, -1);
611  return _cm->getNbControllers();
612 }
613 
614 
615 /**
616  * Creates a new character controller.
617  */
620 
621  nassertr(_error_type == ET_ok, nullptr);
622  nassertr(desc.is_valid(), nullptr);
623 
624  PhysxController *controller = PhysxController::factory(desc.ptr()->getType());
625  nassertr(controller, nullptr);
626 
627  desc.ptr()->callback = &_controller_report;
628  desc.ptr()->userData = controller;
629 
630  NxController *controllerPtr = _cm->createController(_ptr,*desc.ptr());
631  nassertr(controllerPtr, nullptr);
632 
633  controller->link(controllerPtr);
634  controller->get_actor()->set_name("");
635 
636  return controller;
637 }
638 
639 /**
640  * Retrieves the n-th controller within the scene.
641  */
643 get_controller(unsigned int idx) const {
644 
645  nassertr(_error_type == ET_ok, nullptr);
646  nassertr_always(idx < _cm->getNbControllers(), nullptr);
647 
648  NxController *controllerPtr = _cm->getController(idx);
649  PhysxController *controller = (PhysxController *)(controllerPtr->getUserData());
650 
651  return controller;
652 }
653 
654 /**
655  * Returns the number of joints in the scene (excluding "dead" joints). Note
656  * that this includes compartments.
657  */
658 unsigned int PhysxScene::
659 get_num_joints() const {
660 
661  nassertr(_error_type == ET_ok, -1);
662  return _ptr->getNbJoints();
663 }
664 
665 /**
666  * Creates a joint in this scene.
667  */
670 
671  nassertr(_error_type == ET_ok, nullptr);
672  nassertr(desc.is_valid(), nullptr);
673 
674  PhysxJoint *joint = PhysxJoint::factory(desc.ptr()->getType());
675  nassertr(joint, nullptr);
676 
677  NxJoint *jointPtr = _ptr->createJoint(*desc.ptr());
678  nassertr(jointPtr, nullptr);
679 
680  joint->link(jointPtr);
681 
682  return joint;
683 }
684 
685 /**
686  * Retrieve the n-th joint from the array of all the joints in the scene.
687  */
689 get_joint(unsigned int idx) const {
690 
691  nassertr(_error_type == ET_ok, nullptr);
692  nassertr_always(idx < _ptr->getNbJoints(), nullptr);
693 
694  NxJoint *jointPtr;
695  NxU32 nJoints = _ptr->getNbJoints();
696 
697  _ptr->resetJointIterator();
698  for (NxU32 i=0; i <= idx; i++) {
699  jointPtr = _ptr->getNextJoint();
700  }
701 
702  return (PhysxJoint *)(jointPtr->userData);
703 }
704 
705 /**
706  * Gets the number of force fields in the scene.
707  */
708 unsigned int PhysxScene::
709 get_num_force_fields() const {
710 
711  nassertr(_error_type == ET_ok, -1);
712  return _ptr->getNbForceFields();
713 }
714 
715 /**
716  * Creates a force field in this scene.
717  */
720 
721  nassertr(_error_type == ET_ok, nullptr);
722 
723  // Create the kernel
724  desc.create_kernel(_ptr);
725  nassertr(desc.is_valid(), nullptr);
726 
727  // Create the force field
728  PhysxForceField *field = new PhysxForceField();
729  nassertr(field, nullptr);
730 
731  NxForceField *fieldPtr = _ptr->createForceField(desc._desc);
732  nassertr(fieldPtr, nullptr);
733 
734  field->link(fieldPtr);
735 
736  return field;
737 }
738 
739 /**
740  * Returns the n-th force field from the array of all the force fields in the
741  * scene.
742  */
744 get_force_field(unsigned int idx) const {
745 
746  nassertr(_error_type == ET_ok, nullptr);
747  nassertr_always(idx < _ptr->getNbForceFields(), nullptr);
748 
749  NxForceField **fields = _ptr->getForceFields();
750  NxForceField *fieldPtr = fields[idx];
751 
752  return (PhysxForceField *)(fieldPtr->userData);
753 }
754 
755 /**
756  * Gets the number of force field shape groups in the scene.
757  */
758 unsigned int PhysxScene::
760 
761  nassertr(_error_type == ET_ok, -1);
762  return _ptr->getNbForceFieldShapeGroups();
763 }
764 
765 /**
766  * Creates a new force field shape group in this scene.
767  */
770 
771  nassertr(_error_type == ET_ok, nullptr);
772 
774  nassertr(group, nullptr);
775 
776  NxForceFieldShapeGroup *groupPtr = _ptr->createForceFieldShapeGroup(desc._desc);
777  nassertr(groupPtr, nullptr);
778 
779  group->link(groupPtr);
780 
781  return group;
782 }
783 
784 /**
785  * Returns the n-th force field shape group in this scene
786  */
788 get_force_field_shape_group(unsigned int idx) const {
789 
790  nassertr(_error_type == ET_ok, nullptr);
791  nassertr_always(idx < _ptr->getNbForceFieldShapeGroups(), nullptr);
792 
793  _ptr->resetForceFieldShapeGroupsIterator();
794  NxForceFieldShapeGroup *groupPtr = nullptr;
795  idx++;
796  while (idx-- > 0) {
797  groupPtr = _ptr->getNextForceFieldShapeGroup();
798  }
799 
800  return groupPtr ? (PhysxForceFieldShapeGroup *)groupPtr->userData : nullptr;
801 }
802 
803 /**
804  * Gets the number of cloths in the scene.
805  */
806 unsigned int PhysxScene::
807 get_num_cloths() const {
808 
809  nassertr(_error_type == ET_ok, -1);
810  return _ptr->getNbCloths();
811 }
812 
813 /**
814  * Creates a cloth in this scene.
815  */
818 
819  nassertr(_error_type == ET_ok, nullptr);
820 
821  PhysxCloth *cloth = new PhysxCloth();
822  nassertr(cloth, nullptr);
823 
824  NxCloth *clothPtr = _ptr->createCloth(desc._desc);
825  nassertr(clothPtr, nullptr);
826 
827  cloth->link(clothPtr);
828 
829  return cloth;
830 }
831 
832 /**
833  * Returns the n-th cloth from the array of all the cloths in the scene.
834  */
836 get_cloth(unsigned int idx) const {
837 
838  nassertr(_error_type == ET_ok, nullptr);
839  nassertr_always(idx < _ptr->getNbCloths(), nullptr);
840 
841  NxCloth **cloths = _ptr->getCloths();
842  NxCloth *clothPtr = cloths[idx];
843 
844  return (PhysxCloth *)(clothPtr->userData);
845 }
846 
847 /**
848  * Gets the number of soft bodies in the scene.
849  */
850 unsigned int PhysxScene::
851 get_num_soft_bodies() const {
852 
853  nassertr(_error_type == ET_ok, -1);
854  return _ptr->getNbSoftBodies();
855 }
856 
857 /**
858  * Creates a soft body in this scene.
859  */
862 
863  nassertr(_error_type == ET_ok, nullptr);
864 
865  PhysxSoftBody *softbody = new PhysxSoftBody();
866  nassertr(softbody, nullptr);
867 
868  NxSoftBody *softbodyPtr = _ptr->createSoftBody(desc._desc);
869  nassertr(softbodyPtr, nullptr);
870 
871  softbody->link(softbodyPtr);
872 
873  return softbody;
874 }
875 
876 /**
877  * Returns the n-th soft body from the array of all the soft bodies in the
878  * scene.
879  */
881 get_soft_body(unsigned int idx) const {
882 
883  nassertr(_error_type == ET_ok, nullptr);
884  nassertr_always(idx < _ptr->getNbSoftBodies(), nullptr);
885 
886  NxSoftBody **softbodies = _ptr->getSoftBodies();
887  NxSoftBody *softbodyPtr = softbodies[idx];
888 
889  return (PhysxSoftBody *)(softbodyPtr->userData);
890 }
891 
892 /**
893  * Returns the number of vehicles in the scene.
894  */
895 unsigned int PhysxScene::
896 get_num_vehicles() const {
897 
898  nassertr(_error_type == ET_ok, -1);
899  return _vehicles.size();
900 }
901 
902 /**
903  * Creates a vehicle in this scene.
904  */
907 
908  nassertr(_error_type == ET_ok, nullptr);
909  nassertr(desc.is_valid(), nullptr);
910 
911  PhysxVehicle *vehicle = new PhysxVehicle();
912  nassertr(vehicle, nullptr);
913 
914  vehicle->create(this, desc);
915 
916  return vehicle;
917 }
918 
919 /**
920  * Returns the n-th vehicle from the array of all the vehicles in the scene.
921  */
923 get_vehicle(unsigned int idx) const {
924 
925  nassertr(_error_type == ET_ok, nullptr);
926  nassertr_always(idx < _vehicles.size(), nullptr);
927 
928  return _vehicles[idx];
929 }
930 
931 /**
932  *
933  */
934 PhysxSceneStats2 PhysxScene::
935 get_stats2() const {
936 
937  nassertr(_error_type == ET_ok, nullptr);
938  return PhysxSceneStats2(_ptr->getStats2());
939 }
940 
941 /**
942  * Returns true if any shape is intersected by the ray.
943  */
945 raycast_any_shape(const PhysxRay &ray,
946  PhysxShapesType shapesType,
947  PhysxMask mask,
948  PhysxGroupsMask *groups) const {
949 
950  nassertr(_error_type == ET_ok, false);
951 
952  NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : nullptr;
953 
954  return _ptr->raycastAnyShape(ray._ray, (NxShapesType)shapesType,
955  mask.get_mask(), ray._length, groupsPtr);
956 }
957 
958 /**
959  * Returns the first shape that is hit along the ray. If not shape is hit
960  * then an empty raycast hit is returned (is_empty() == true).
961  */
964  PhysxShapesType shapesType,
965  PhysxMask mask,
966  PhysxGroupsMask *groups, bool smoothNormal) const {
967 
968  NxRaycastHit hit;
969 
970  nassertr(_error_type == ET_ok, hit);
971 
972  NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : nullptr;
973 
974  NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
975  if (smoothNormal == true) {
976  hints |= NX_RAYCAST_NORMAL;
977  }
978  else {
979  hints |= NX_RAYCAST_FACE_NORMAL;
980  }
981 
982  _ptr->raycastClosestShape(ray._ray, (NxShapesType)shapesType, hit,
983  mask.get_mask(), ray._length, hints, groupsPtr);
984 
985 
986  return PhysxRaycastHit(hit);
987 }
988 
989 /**
990  * Returns a PhysxRaycastReport object which can be used to iterate over all
991  * shapes that have been hit by the ray.
992  */
994 raycast_all_shapes(const PhysxRay &ray,
995  PhysxShapesType shapesType,
996  PhysxMask mask,
997  PhysxGroupsMask *groups, bool smoothNormal) const {
998 
999  PhysxRaycastReport report;
1000 
1001  nassertr(_error_type == ET_ok, report);
1002 
1003  NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : nullptr;
1004 
1005  NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
1006  if (smoothNormal == true) {
1007  hints |= NX_RAYCAST_NORMAL;
1008  }
1009  else {
1010  hints |= NX_RAYCAST_FACE_NORMAL;
1011  }
1012 
1013  _ptr->raycastAllShapes(ray._ray, report, (NxShapesType)shapesType,
1014  mask.get_mask(), ray._length, hints, groupsPtr);
1015 
1016  return report;
1017 }
1018 
1019 /**
1020  * Returns true if any axis aligned bounding box enclosing a shape is
1021  * intersected by the ray.
1022  */
1024 raycast_any_bounds(const PhysxRay &ray,
1025  PhysxShapesType shapesType,
1026  PhysxMask mask,
1027  PhysxGroupsMask *groups) const {
1028 
1029  nassertr(_error_type == ET_ok, false);
1030 
1031  NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : nullptr;
1032 
1033  return _ptr->raycastAnyBounds(ray._ray, (NxShapesType)shapesType,
1034  mask.get_mask(), ray._length, groupsPtr);
1035 }
1036 
1037 /**
1038  * Returns the first axis aligned bounding box enclosing a shape that is hit
1039  * along the ray. If not shape is hit then an empty raycast hit is returned
1040  * (is_empty() == true).
1041  */
1043 raycast_closest_bounds(const PhysxRay &ray, PhysxShapesType shapesType, PhysxMask mask, PhysxGroupsMask *groups, bool smoothNormal) const {
1044 
1045  NxRaycastHit hit;
1046 
1047  nassertr(_error_type == ET_ok, hit);
1048 
1049  NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : nullptr;
1050 
1051  NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
1052  if (smoothNormal == true) {
1053  hints |= NX_RAYCAST_NORMAL;
1054  }
1055  else {
1056  hints |= NX_RAYCAST_FACE_NORMAL;
1057  }
1058 
1059  _ptr->raycastClosestBounds(ray._ray, (NxShapesType)shapesType, hit,
1060  mask.get_mask(), ray._length, hints, groupsPtr);
1061 
1062 
1063  return PhysxRaycastHit(hit);
1064 }
1065 
1066 /**
1067  * Returns a PhysxRaycastReport object which can be used to iterate over all
1068  * shapes that have been enclosed by axis aligned bounding boxes hit by the
1069  * ray.
1070  */
1072 raycast_all_bounds(const PhysxRay &ray,
1073  PhysxShapesType shapesType,
1074  PhysxMask mask,
1075  PhysxGroupsMask *groups, bool smoothNormal) const {
1076 
1077  PhysxRaycastReport report;
1078 
1079  nassertr(_error_type == ET_ok, report);
1080 
1081  NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : nullptr;
1082 
1083  NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
1084  if (smoothNormal == true) {
1085  hints |= NX_RAYCAST_NORMAL;
1086  }
1087  else {
1088  hints |= NX_RAYCAST_FACE_NORMAL;
1089  }
1090 
1091  _ptr->raycastAllBounds(ray._ray, report, (NxShapesType)shapesType,
1092  mask.get_mask(), ray._length, hints, groupsPtr);
1093 
1094  return report;
1095 }
1096 
1097 /**
1098  * Returns the set of shapes overlapped by the world-space sphere. You can
1099  * test against static and/or dynamic objects by adjusting 'shapeType'.
1100  */
1102 overlap_sphere_shapes(const LPoint3f &center, float radius,
1103  PhysxShapesType shapesType,
1104  PhysxMask mask, bool accurateCollision) const {
1105 
1106  PhysxOverlapReport report;
1107 
1108  nassertr(_error_type == ET_ok, report);
1109 
1110  NxSphere worldSphere(PhysxManager::point3_to_nxVec3(center), radius);
1111 
1112  _ptr->overlapSphereShapes(worldSphere, (NxShapesType)shapesType, 0, nullptr, &report,
1113  mask.get_mask(), nullptr, accurateCollision);
1114 
1115  return report;
1116 }
1117 
1118 /**
1119  * Returns the set of shapes overlapped by the world-space capsule. You can
1120  * test against static and/or dynamic objects by adjusting 'shapeType'.
1121  */
1123 overlap_capsule_shapes(const LPoint3f &p0, const LPoint3f &p1, float radius,
1124  PhysxShapesType shapesType,
1125  PhysxMask mask, bool accurateCollision) const {
1126 
1127  PhysxOverlapReport report;
1128 
1129  nassertr(_error_type == ET_ok, report);
1130 
1131  NxSegment segment(PhysxManager::point3_to_nxVec3(p0),
1133  NxCapsule worldCapsule(segment, radius);
1134 
1135  _ptr->overlapCapsuleShapes(worldCapsule, (NxShapesType)shapesType, 0, nullptr, &report,
1136  mask.get_mask(), nullptr, accurateCollision);
1137 
1138  return report;
1139 }
1140 
1141 /**
1142  * Sets the pair flags for the given pair of actors.
1143  *
1144  * Calling this on an actor that has no shape(s) has no effect. The two actor
1145  * references must not reference the same actor.
1146  *
1147  * It is important to note that the engine stores pair flags per shape, even
1148  * for actor pair flags. This means that shapes should be created before
1149  * actor pair flags are set, otherwise the pair flags will be ignored.
1150  */
1152 set_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB,
1153  PhysxContactPairFlag flag, bool value) {
1154 
1155  nassertv(_error_type == ET_ok);
1156 
1157  NxActor *ptrA = actorA.ptr();
1158  NxActor *ptrB = actorB.ptr();
1159  NxU32 flags = _ptr->getActorPairFlags(*ptrA, *ptrB);
1160 
1161  if (value == true) {
1162  flags |= flag;
1163  }
1164  else {
1165  flags &= ~(flag);
1166  }
1167 
1168  _ptr->setActorPairFlags(*ptrA, *ptrB, flags);
1169 }
1170 
1171 /**
1172  * Retrieves a single flag for the given pair of actors.
1173  *
1174  * The two actor references must not reference the same actor.
1175  */
1177 get_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB,
1178  PhysxContactPairFlag flag) {
1179 
1180  nassertr(_error_type == ET_ok, false);
1181 
1182  NxActor *ptrA = actorA.ptr();
1183  NxActor *ptrB = actorB.ptr();
1184  NxU32 flags = _ptr->getActorPairFlags(*ptrA, *ptrB);
1185 
1186  return (flags && flag) ? true : false;
1187 }
1188 
1189 /**
1190  * Disables or enables contact generation for a pair of shapes.
1191  *
1192  * The two shape references must not reference the same shape.
1193  */
1195 set_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB, bool value) {
1196 
1197  nassertv(_error_type == ET_ok);
1198 
1199  NxShape *ptrA = shapeA.ptr();
1200  NxShape *ptrB = shapeB.ptr();
1201  NxU32 flags = _ptr->getShapePairFlags(*ptrA, *ptrB);
1202 
1203  if (value == true) {
1204  flags |= NX_IGNORE_PAIR;
1205  }
1206  else {
1207  flags &= ~(NX_IGNORE_PAIR);
1208  }
1209 
1210  _ptr->setShapePairFlags(*ptrA, *ptrB, flags);
1211 }
1212 
1213 /**
1214  * Returns /true/ if contact generation between a pair of shapes is enabled,
1215  * and /false/ if contact generation is disables.
1216  *
1217  * The two shape references must not reference the same shape.
1218  */
1220 get_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB) {
1221 
1222  nassertr(_error_type == ET_ok, false);
1223 
1224  NxShape *ptrA = shapeA.ptr();
1225  NxShape *ptrB = shapeB.ptr();
1226  NxU32 flags = _ptr->getShapePairFlags(*ptrA, *ptrB);
1227 
1228  return (flags && NX_IGNORE_PAIR) ? true : false;
1229 }
1230 
1231 /**
1232  * With this method one can set contact reporting flags between actors
1233  * belonging to a pair of groups.
1234  *
1235  * It is possible to assign each actor to a group using
1236  * PhysxActor::set_group(). This is a different set of groups from the shape
1237  * groups despite the similar name. Here up to 0xffff different groups are
1238  * permitted, With this method one can set contact reporting flags between
1239  * actors belonging to a pair of groups.
1240  *
1241  * The following flags are permitted: - CPF_start_touch - CPF_end_touch -
1242  * CPF_touch - CPF_start_touch_treshold - CPF_end_touch_treshold -
1243  * CPF_touch_treshold
1244  *
1245  * Note that finer grain control of pairwise flags is possible using the
1246  * function PhysxScene::set_actor_pair_flags().
1247  */
1249 set_actor_group_pair_flag(unsigned int g1, unsigned int g2,
1250  PhysxContactPairFlag flag, bool value) {
1251 
1252  nassertv(_error_type == ET_ok);
1253 
1254  NxU32 flags = _ptr->getActorGroupPairFlags(g1, g2);
1255  if (value == true) {
1256  flags |= flag;
1257  }
1258  else {
1259  flags &= ~(flag);
1260  }
1261  _ptr->setActorGroupPairFlags(g1, g2, flags);
1262 }
1263 
1264 /**
1265  * Retrieves a single flag set with PhysxScene::set_actor_group_pair_flag()
1266  */
1268 get_actor_group_pair_flag(unsigned int g1, unsigned int g2,
1269  PhysxContactPairFlag flag) {
1270 
1271  nassertr(_error_type == ET_ok, false);
1272  NxU32 flags = _ptr->getActorGroupPairFlags(g1, g2);
1273  return (flags && flag) ? true : false;
1274 }
1275 
1276 /**
1277  * Setups filtering operations.
1278  */
1280 set_filter_ops(PhysxFilterOp op0, PhysxFilterOp op1, PhysxFilterOp op2) {
1281 
1282  nassertv(_error_type == ET_ok);
1283  _ptr->setFilterOps((NxFilterOp)op0, (NxFilterOp)op1, (NxFilterOp)op2);
1284 }
1285 
1286 /**
1287  * Setups filtering's boolean value.
1288  */
1290 set_filter_bool(bool flag) {
1291 
1292  nassertv(_error_type == ET_ok);
1293  _ptr->setFilterBool(flag);
1294 }
1295 
1296 /**
1297  * Setups filtering's K0 value.
1298  */
1301 
1302  nassertv(_error_type == ET_ok);
1303  _ptr->setFilterConstant0(mask.get_mask());
1304 }
1305 
1306 /**
1307  * Setups filtering's K1 value.
1308  */
1311 
1312  nassertv(_error_type == ET_ok);
1313  _ptr->setFilterConstant1(mask.get_mask());
1314 }
1315 
1316 /**
1317  * Retrieves filtering's boolean value.
1318  */
1320 get_filter_bool() const {
1321 
1322  nassertr(_error_type == ET_ok, false);
1323  return _ptr->getFilterBool();
1324 }
1325 
1326 /**
1327  * Gets filtering constant K0.
1328  */
1330 get_filter_constant0() const {
1331 
1332  PhysxGroupsMask mask;
1333 
1334  nassertr(_error_type == ET_ok, mask);
1335 
1336  NxGroupsMask _mask = ptr()->getFilterConstant0();
1337  mask.set_mask(_mask);
1338 
1339  return mask;
1340 }
1341 
1342 /**
1343  * Gets filtering constant K1.
1344  */
1346 get_filter_constant1() const {
1347 
1348  PhysxGroupsMask mask;
1349 
1350  nassertr(_error_type == ET_ok, mask);
1351 
1352  NxGroupsMask _mask = ptr()->getFilterConstant1();
1353  mask.set_mask(_mask);
1354 
1355  return mask;
1356 }
1357 
1358 /**
1359  * Retrieves the op0 filtering operation.
1360  */
1361 PhysxEnums::PhysxFilterOp PhysxScene::
1362 get_filter_op0() const {
1363 
1364  nassertr(_error_type == ET_ok, FO_and);
1365 
1366  NxFilterOp op0;
1367  NxFilterOp op1;
1368  NxFilterOp op2;
1369 
1370  _ptr->getFilterOps(op0, op1, op2);
1371 
1372  return (PhysxFilterOp)op0;
1373 }
1374 
1375 /**
1376  * Retrieves the op1 filtering operation.
1377  */
1378 PhysxEnums::PhysxFilterOp PhysxScene::
1379 get_filter_op1() const {
1380 
1381  nassertr(_error_type == ET_ok, FO_and);
1382 
1383  NxFilterOp op0;
1384  NxFilterOp op1;
1385  NxFilterOp op2;
1386 
1387  _ptr->getFilterOps(op0, op1, op2);
1388 
1389  return (PhysxFilterOp)op1;
1390 }
1391 
1392 /**
1393  * Retrieves the op2 filtering operation.
1394  */
1395 PhysxEnums::PhysxFilterOp PhysxScene::
1396 get_filter_op2() const {
1397 
1398  nassertr(_error_type == ET_ok, FO_and);
1399 
1400  NxFilterOp op0;
1401  NxFilterOp op1;
1402  NxFilterOp op2;
1403 
1404  _ptr->getFilterOps(op0, op1, op2);
1405 
1406  return (PhysxFilterOp)op2;
1407 }
1408 
1409 /**
1410  * Specifies if collision should be performed by a pair of shape groups.
1411  *
1412  * It is possible to assign each shape to a collision groups using
1413  * PhysxShape::set_group(). With this method one can set whether collisions
1414  * should be detected between shapes belonging to a given pair of groups.
1415  * Initially all pairs are enabled.
1416  *
1417  * Fluids can be assigned to collision groups as well.
1418  *
1419  * Collision groups are integers between 0 and 31.
1420  */
1422 set_group_collision_flag(unsigned int g1, unsigned int g2, bool enable) {
1423 
1424  nassertv(_error_type == ET_ok);
1425  nassertv(g1 >= 0 && g1 < 32);
1426  nassertv(g2 >= 0 && g2 < 32);
1427 
1428  _ptr->setGroupCollisionFlag((NxCollisionGroup)g1, (NxCollisionGroup)g2, enable);
1429 }
1430 
1431 /**
1432  * Determines if collision detection is performed between a pair of groups.
1433  * Collision groups are integers between 0 and 31.
1434  */
1436 get_group_collision_flag(unsigned int g1, unsigned int g2) {
1437 
1438  nassertr(_error_type == ET_ok, false);
1439  nassertr(g1 >= 0 && g1 < 32, false);
1440  nassertr(g2 >= 0 && g2 < 32, false);
1441 
1442  return _ptr->getGroupCollisionFlag((NxCollisionGroup)g1, (NxCollisionGroup)g2);
1443 }
1444 
1445 /**
1446  * Return the specified scene flag flag.
1447  */
1449 get_flag(PhysxSceneFlag flag) const {
1450 
1451  nassertr(_error_type == ET_ok, false);
1452  return (_ptr->getFlags() & flag) ? true : false;
1453 }
1454 
1455 /**
1456  * Returns TRUE if the the scene is simulated in hardware. FALSE if the scene
1457  * is simulated in software.
1458  */
1460 is_hardware_scene() const {
1461 
1462  nassertr(_error_type == ET_ok, false);
1463  return (_ptr->getSimType() & NX_SIMULATION_HW) ? true : false;
1464 }
1465 
1466 /**
1467  * Specifies the dominance behavior of constraints between two actors with two
1468  * certain dominance groups.
1469  *
1470  * It is possible to assign each actor to a dominance groups using
1471  * PhysxActor::set_dominance_group().
1472  *
1473  * With dominance groups one can have all constraints (contacts and joints)
1474  * created between actors act in one direction only. This is useful if you
1475  * want to make sure that the movement of the rider of a vehicle or the pony
1476  * tail of a character doesn't influence the object it is attached to, while
1477  * keeping the motion of both inherently physical.
1478  *
1479  * Whenever a constraint (i.e. joint or contact) between two actors (a0, a1)
1480  * needs to be solved, the groups (g0, g1) of both actors are retrieved. Then
1481  * the constraint dominance setting for this group pair is retrieved.
1482  *
1483  * In the constraint, PhysxConstraintDominance::get_0() becomes the dominance
1484  * setting for a0, and PhysxConstraintDominance::get_1() becomes the dominance
1485  * setting for a1. A dominance setting of 1.0f, the default, will permit the
1486  * actor to be pushed or pulled by the other actor. A dominance setting of
1487  * 0.0f will however prevent the actor to be pushed or pulled by the other
1488  * actor. Thus, a PhysxConstraintDominance of (1.0f, 0.0f) makes the
1489  * interaction one-way.
1490  *
1491  * The dominance matrix is initialised by default such that: - if g1 == g2,
1492  * then (1.0f, 1.0f) is returned - if g1 < g2, then (0.0f, 1.0f) is returned -
1493  * if g1 > g2, then (1.0f, 0.0f) is returned
1494  *
1495  * In other words, actors in higher groups can be pushed around by actors in
1496  * lower groups by default.
1497  *
1498  * These settings should cover most applications, and in fact not overriding
1499  * these settings may likely result in higher performance.
1500  *
1501  * Dominance settings are currently specified as floats 0.0f or 1.0f because
1502  * in the future PhysX may permit arbitrary fractional settings to express
1503  * 'partly-one-way' interactions.
1504  */
1506 set_dominance_group_pair(unsigned int g1, unsigned int g2, PhysxConstraintDominance dominance ) {
1507 
1508  nassertv(_error_type == ET_ok);
1509  nassertv(g1 < 32);
1510  nassertv(g2 < 32);
1511 
1512  NxConstraintDominance d = dominance.get_dominance();
1513  _ptr->setDominanceGroupPair((NxDominanceGroup)g1, (NxDominanceGroup)g2, d);
1514 }
1515 
1516 /**
1517  * Samples the dominance matrix.
1518  */
1520 get_dominance_group_pair(unsigned int g1, unsigned int g2) {
1521 
1522  PhysxConstraintDominance result(1.0f, 1.0f);
1523 
1524  nassertr(_error_type == ET_ok, result);
1525  nassertr(g1 < 32, result);
1526  nassertr(g2 < 32, result);
1527 
1528  result.set_dominance(_ptr->getDominanceGroupPair((NxDominanceGroup)g1, (NxDominanceGroup)g2));
1529  return result;
1530 }
1531 
1532 /**
1533  * Gets the shared material for all wheel shapes.
1534  *
1535  * If this material is not already created then calling this method will
1536  * create the material.
1537  *
1538  * Normally users don't need to call this method. It is used internally by
1539  * PhysWheel::create_wheel.
1540  */
1543 
1544  nassertr(_error_type == ET_ok, nullptr);
1545 
1546  if (_wheelShapeMaterial == nullptr) {
1547  PhysxMaterialDesc materialDesc;
1548  materialDesc.set_flag(PhysxMaterialDesc::MF_disable_friction, true);
1549  _wheelShapeMaterial = create_material(materialDesc);
1550  }
1551 
1552  return _wheelShapeMaterial;
1553 }
PhysxActorDesc::is_valid
bool is_valid() const
Returns true if the descriptor is valid.
Definition: physxActorDesc.I:45
PhysxForceFieldShapeGroupDesc
Definition: physxForceFieldShapeGroupDesc.h:27
PhysxOverlapReport
Objects of this class are returned by the 'overlap shape' methods, for example overlapSphereShapes.
Definition: physxOverlapReport.h:33
physxForceFieldShapeGroupDesc.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxScene::get_hightest_material_index
unsigned int get_hightest_material_index() const
Returns current highest valid material index.
Definition: physxScene.cxx:556
PhysxActorDesc
Descriptor for PhysxActor.
Definition: physxActorDesc.h:28
PhysxScene::get_dominance_group_pair
PhysxConstraintDominance get_dominance_group_pair(unsigned int g1, unsigned int g2)
Samples the dominance matrix.
Definition: physxScene.cxx:1520
PhysxVehicleDesc
Definition: physxVehicleDesc.h:24
PhysxScene::set_timing_fixed
void set_timing_fixed(float maxTimestep=1.0f/60.0f, unsigned int maxIter=8)
Sets simulation timing parameters used in simulate.
Definition: physxScene.cxx:309
PhysxSceneStats2
Definition: physxSceneStats2.h:24
PhysxManager::get_global_ptr
static PhysxManager * get_global_ptr()
Returns a pointer to the global PhysxManager object.
Definition: physxManager.cxx:98
PhysxSoftBody
Definition: physxSoftBody.h:32
PhysxManager::point3_to_nxVec3
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Definition: physxManager.I:63
PhysxActor
Actors are the main simulation objects.
Definition: physxActor.h:44
PhysxScene::get_actor_group_pair_flag
bool get_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag)
Retrieves a single flag set with PhysxScene::set_actor_group_pair_flag()
Definition: physxScene.cxx:1268
PhysxScene::get_force_field_shape_group
get_force_field_shape_group
Returns the n-th force field shape group in this scene.
Definition: physxScene.h:136
PhysxScene::get_vehicle
get_vehicle
Returns the n-th vehicle from the array of all the vehicles in the scene.
Definition: physxScene.h:154
PhysxRaycastReport
Objects of this class are returned by the 'raycast all' methods.
Definition: physxRaycastReport.h:28
physxScene.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxVehicle
Definition: physxVehicle.h:31
PhysxScene::set_dominance_group_pair
void set_dominance_group_pair(unsigned int g1, unsigned int g2, PhysxConstraintDominance dominance)
Specifies the dominance behavior of constraints between two actors with two certain dominance groups.
Definition: physxScene.cxx:1506
physxSoftBodyDesc.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxScene::get_num_force_field_shape_groups
get_num_force_field_shape_groups
Gets the number of force field shape groups in the scene.
Definition: physxScene.h:136
PhysxScene::create_joint
PhysxJoint * create_joint(PhysxJointDesc &desc)
Creates a joint in this scene.
Definition: physxScene.cxx:669
PhysxScene::create_force_field_shape_group
PhysxForceFieldShapeGroup * create_force_field_shape_group(PhysxForceFieldShapeGroupDesc &desc)
Creates a new force field shape group in this scene.
Definition: physxScene.cxx:769
PhysxScene::set_filter_constant1
void set_filter_constant1(const PhysxGroupsMask &mask)
Setups filtering's K1 value.
Definition: physxScene.cxx:1310
PhysxScene::get_num_soft_bodies
get_num_soft_bodies
Gets the number of soft bodies in the scene.
Definition: physxScene.h:148
PhysxScene::is_hardware_scene
bool is_hardware_scene() const
Returns TRUE if the the scene is simulated in hardware.
Definition: physxScene.cxx:1460
PhysxScene::raycast_all_shapes
PhysxRaycastReport raycast_all_shapes(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const
Returns a PhysxRaycastReport object which can be used to iterate over all shapes that have been hit b...
Definition: physxScene.cxx:994
PhysxManager::vec3_to_nxVec3
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
Definition: physxManager.I:27
PhysxController
Abstract base class for character controllers.
Definition: physxController.h:30
PhysxMaterialDesc::set_flag
void set_flag(PhysxMaterialFlag flag, bool value)
Sets flags which control the behavior of a material.
Definition: physxMaterialDesc.cxx:78
PhysxScene::get_material_from_index
PhysxMaterial * get_material_from_index(unsigned int idx) const
Retrieves the material with the given material index.
Definition: physxScene.cxx:571
PhysxScene::get_filter_bool
bool get_filter_bool() const
Retrieves filtering's boolean value.
Definition: physxScene.cxx:1320
PhysxActor::set_name
void set_name(const char *name)
Sets a name string for the object that can be retrieved with get_name().
Definition: physxActor.cxx:119
PhysxScene::set_timing_variable
void set_timing_variable()
Sets simulation timing parameters used in simulate.
Definition: physxScene.cxx:290
physxActorDesc.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxScene::get_joint
get_joint
Retrieve the n-th joint from the array of all the joints in the scene.
Definition: physxScene.h:109
PhysxScene::set_group_collision_flag
void set_group_collision_flag(unsigned int g1, unsigned int g2, bool enable)
Specifies if collision should be performed by a pair of shape groups.
Definition: physxScene.cxx:1422
PhysxScene::overlap_sphere_shapes
PhysxOverlapReport overlap_sphere_shapes(const LPoint3f &center, float radius, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), bool accurateCollision=true) const
Returns the set of shapes overlapped by the world-space sphere.
Definition: physxScene.cxx:1102
PhysxScene::overlap_capsule_shapes
PhysxOverlapReport overlap_capsule_shapes(const LPoint3f &p0, const LPoint3f &p1, float radius, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), bool accurateCollision=true) const
Returns the set of shapes overlapped by the world-space capsule.
Definition: physxScene.cxx:1123
PhysxScene::set_gravity
void set_gravity(const LVector3f &gravity)
Sets a constant gravity for the entire scene.
Definition: physxScene.cxx:319
PhysxScene::get_material
get_material
Retrieves the n-th material from the array of materials.
Definition: physxScene.h:118
PhysxVehicleDesc::is_valid
bool is_valid() const
Returns true if the descriptor is valid.
Definition: physxVehicleDesc.I:44
PhysxScene::set_actor_group_pair_flag
void set_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag, bool value)
With this method one can set contact reporting flags between actors belonging to a pair of groups.
Definition: physxScene.cxx:1249
PhysxScene::create_vehicle
PhysxVehicle * create_vehicle(PhysxVehicleDesc &desc)
Creates a vehicle in this scene.
Definition: physxScene.cxx:906
PhysxScene::get_filter_op2
PhysxFilterOp get_filter_op2() const
Retrieves the op2 filtering operation.
Definition: physxScene.cxx:1396
PhysxScene::get_flag
bool get_flag(PhysxSceneFlag flag) const
Return the specified scene flag flag.
Definition: physxScene.cxx:1449
PhysxMaterialDesc::is_valid
bool is_valid() const
Returns true if the descriptor is valid.
Definition: physxMaterialDesc.I:43
PhysxScene::get_force_field
get_force_field
Returns the n-th force field from the array of all the force fields in the scene.
Definition: physxScene.h:130
PhysxManager::nxMat34_to_mat4
static LMatrix4f nxMat34_to_mat4(const NxMat34 &m)
Converts from NxMat34 to LMatrix4f.
Definition: physxManager.I:130
PhysxScene::get_filter_op0
PhysxFilterOp get_filter_op0() const
Retrieves the op0 filtering operation.
Definition: physxScene.cxx:1362
PhysxScene::create_force_field
PhysxForceField * create_force_field(PhysxForceFieldDesc &desc)
Creates a force field in this scene.
Definition: physxScene.cxx:719
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PhysxForceFieldDesc::is_valid
bool is_valid() const
Returns true if the descriptor is valid.
Definition: physxForceFieldDesc.I:44
PhysxScene::raycast_any_bounds
bool raycast_any_bounds(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr) const
Returns true if any axis aligned bounding box enclosing a shape is intersected by the ray.
Definition: physxScene.cxx:1024
PhysxScene::get_num_joints
get_num_joints
Returns the number of joints in the scene (excluding "dead" joints).
Definition: physxScene.h:109
PhysxForceFieldShapeGroup
Definition: physxForceFieldShapeGroup.h:33
PhysxScene::set_filter_ops
void set_filter_ops(PhysxFilterOp op0, PhysxFilterOp op1, PhysxFilterOp op2)
Setups filtering operations.
Definition: physxScene.cxx:1280
PhysxScene::create_material
PhysxMaterial * create_material()
Creates a new PhysxMaterial using the default settings of PhysxMaterialDesc.
Definition: physxScene.cxx:532
PhysxScene::get_num_force_fields
get_num_force_fields
Gets the number of force fields in the scene.
Definition: physxScene.h:130
PhysxControllerDesc
Descriptor class for a character controller.
Definition: physxControllerDesc.h:25
PhysxScene::get_num_controllers
get_num_controllers
Return the number of controllers in the scene.
Definition: physxScene.h:124
PhysxMaterial
A class for describing a shape's surface properties.
Definition: physxMaterial.h:44
PhysxRaycastHit
This structure captures results for a single raycast query.
Definition: physxRaycastHit.h:28
PhysxScene::get_actor_pair_flag
bool get_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag)
Retrieves a single flag for the given pair of actors.
Definition: physxScene.cxx:1177
PhysxScene::get_num_materials
get_num_materials
Return the number of materials in the scene.
Definition: physxScene.h:118
PhysxScene::create_controller
PhysxController * create_controller(PhysxControllerDesc &controllerDesc)
Creates a new character controller.
Definition: physxScene.cxx:619
PhysxRay
Represents an ray as an origin and direction.
Definition: physxRay.h:26
PhysxScene::get_cloth
get_cloth
Returns the n-th cloth from the array of all the cloths in the scene.
Definition: physxScene.h:142
physxVehicle.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatCollector
A lightweight class that represents a single element that may be timed and/or counted via stats.
Definition: pStatCollector.h:43
PhysxScene::create_soft_body
PhysxSoftBody * create_soft_body(PhysxSoftBodyDesc &desc)
Creates a soft body in this scene.
Definition: physxScene.cxx:861
PhysxScene::raycast_closest_shape
PhysxRaycastHit raycast_closest_shape(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const
Returns the first shape that is hit along the ray.
Definition: physxScene.cxx:963
PhysxScene::get_wheel_shape_material
PhysxMaterial * get_wheel_shape_material()
Gets the shared material for all wheel shapes.
Definition: physxScene.cxx:1542
physxClothDesc.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxScene::get_debug_geom_node
PhysxDebugGeomNode * get_debug_geom_node()
Retrieves the debug geom node for this scene.
Definition: physxScene.cxx:396
PhysxScene::set_filter_bool
void set_filter_bool(bool flag)
Setups filtering's boolean value.
Definition: physxScene.cxx:1290
PhysxDebugGeomNode
Renderable geometry which represents visualizations of physics objects.
Definition: physxDebugGeomNode.h:34
PhysxScene::raycast_all_bounds
PhysxRaycastReport raycast_all_bounds(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const
Returns a PhysxRaycastReport object which can be used to iterate over all shapes that have been enclo...
Definition: physxScene.cxx:1072
PhysxForceFieldDesc
Descriptor class for force fields.
Definition: physxForceFieldDesc.h:30
physxControllerDesc.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxConstraintDominance
Expresses the dominance relationship of a constraint.
Definition: physxConstraintDominance.h:32
PhysxScene::raycast_closest_bounds
PhysxRaycastHit raycast_closest_bounds(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const
Returns the first axis aligned bounding box enclosing a shape that is hit along the ray.
Definition: physxScene.cxx:1043
physxSceneStats2.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxScene::get_group_collision_flag
bool get_group_collision_flag(unsigned int g1, unsigned int g2)
Determines if collision detection is performed between a pair of groups.
Definition: physxScene.cxx:1436
PhysxScene::get_filter_constant0
PhysxGroupsMask get_filter_constant0() const
Gets filtering constant K0.
Definition: physxScene.cxx:1330
physxManager.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxMask
32-bit bitmask class.
Definition: physxMask.h:24
physxForceFieldDesc.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxScene::get_controller
get_controller
Retrieves the n-th controller within the scene.
Definition: physxScene.h:124
PhysxScene::get_shape_pair_flag
bool get_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB)
Returns /true/ if contact generation between a pair of shapes is enabled, and /false/ if contact gene...
Definition: physxScene.cxx:1220
PhysxJoint
Abstract base class for the different types of joints.
Definition: physxJoint.h:32
PhysxScene::get_filter_op1
PhysxFilterOp get_filter_op1() const
Retrieves the op1 filtering operation.
Definition: physxScene.cxx:1379
PhysxScene::set_filter_constant0
void set_filter_constant0(const PhysxGroupsMask &mask)
Setups filtering's K0 value.
Definition: physxScene.cxx:1300
physxSoftBody.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxScene::get_num_cloths
get_num_cloths
Gets the number of cloths in the scene.
Definition: physxScene.h:142
physxCloth.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxSoftBodyDesc
Descriptor for PhysxSoftBody.
Definition: physxSoftBodyDesc.h:28
PhysxScene::set_shape_pair_flag
void set_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB, bool value)
Disables or enables contact generation for a pair of shapes.
Definition: physxScene.cxx:1195
PhysxShape
Abstract base class for shapes.
Definition: physxShape.h:39
physxVehicleDesc.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxGroupsMask
128-bit bitmask class.
Definition: physxGroupsMask.h:24
PhysxJointDesc
Abstract base class for joint descriptors.
Definition: physxJointDesc.h:28
PhysxCloth
Definition: physxCloth.h:32
PhysxScene::get_filter_constant1
PhysxGroupsMask get_filter_constant1() const
Gets filtering constant K1.
Definition: physxScene.cxx:1346
PhysxScene::set_actor_pair_flag
void set_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag, bool value)
Sets the pair flags for the given pair of actors.
Definition: physxScene.cxx:1152
PhysxForceField
A force field effector.
Definition: physxForceField.h:33
PhysxActor::update_transform
void update_transform(const LMatrix4f &m)
Updates the transform of an assigned NodePath.
Definition: physxActor.cxx:143
PhysxScene::simulate
void simulate(float dt)
Advances the simulation by an elapsedTime time.
Definition: physxScene.cxx:189
PhysxScene::raycast_any_shape
bool raycast_any_shape(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr) const
Returns true if any shape is intersected by the ray.
Definition: physxScene.cxx:945
PhysxScene::fetch_results
void fetch_results()
Waits until the simulation has finished, and then updates the scene graph with with simulation result...
Definition: physxScene.cxx:226
PhysxMaterialDesc
Descriptor class for materials.
Definition: physxMaterialDesc.h:25
PhysxScene::create_cloth
PhysxCloth * create_cloth(PhysxClothDesc &desc)
Creates a cloth in this scene.
Definition: physxScene.cxx:817
PhysxScene::get_num_vehicles
get_num_vehicles
Returns the number of vehicles in the scene.
Definition: physxScene.h:154
PhysxManager::nxVec3_to_vec3
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
Definition: physxManager.I:36
PhysxClothDesc
Descriptor for PhysxCloth.
Definition: physxClothDesc.h:28
PhysxController::get_actor
PhysxActor * get_actor() const
Retrieves the actor which this controller is associated with.
Definition: physxController.cxx:66
physxConstraintDominance.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxScene::get_gravity
LVector3f get_gravity() const
Retrieves the current gravity setting.
Definition: physxScene.cxx:331
PhysxScene::get_soft_body
get_soft_body
Returns the n-th soft body from the array of all the soft bodies in the scene.
Definition: physxScene.h:148