00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "physxScene.h"
00016 #include "physxManager.h"
00017 #include "physxActorDesc.h"
00018 #include "physxForceFieldDesc.h"
00019 #include "physxForceFieldShapeGroupDesc.h"
00020 #include "physxControllerDesc.h"
00021 #include "physxSceneStats2.h"
00022 #include "physxConstraintDominance.h"
00023 #include "physxVehicle.h"
00024 #include "physxVehicleDesc.h"
00025 #include "physxCloth.h"
00026 #include "physxClothDesc.h"
00027 #include "physxSoftBody.h"
00028 #include "physxSoftBodyDesc.h"
00029
00030 TypeHandle PhysxScene::_type_handle;
00031
00032 PStatCollector PhysxScene::_pcollector_fetch_results("App:PhysX:Fetch Results");
00033 PStatCollector PhysxScene::_pcollector_update_transforms("App:PhysX:Update Transforms");
00034 PStatCollector PhysxScene::_pcollector_debug_renderer("App:PhysX:Debug Renderer");
00035 PStatCollector PhysxScene::_pcollector_simulate("App:PhysX:Simulate");
00036 PStatCollector PhysxScene::_pcollector_cloth("App:PhysX:Cloth");
00037 PStatCollector PhysxScene::_pcollector_softbody("App:PhysX:Softbody");
00038
00039
00040
00041
00042
00043
00044 void PhysxScene::
00045 link(NxScene *scenePtr) {
00046
00047
00048 _ptr = scenePtr;
00049 _ptr->userData = this;
00050 _error_type = ET_ok;
00051 PhysxManager::get_global_ptr()->_scenes.add(this);
00052
00053 _cm = NxCreateControllerManager(NxGetPhysicsSDKAllocator());
00054 nassertv_always(_cm);
00055
00056
00057 NxMaterial *materials[5];
00058 NxU32 iterator = 0;
00059
00060 while (NxU32 i=_ptr->getMaterialArray(materials, 5, iterator)) {
00061 while(i--) {
00062 PhysxMaterial *material = new PhysxMaterial();
00063 material->link(materials[i]);
00064 }
00065 }
00066 }
00067
00068
00069
00070
00071
00072
00073 void PhysxScene::
00074 unlink() {
00075
00076
00077 for (unsigned int i=0; i < _vehicles.size(); i++) {
00078 _vehicles[i]->release();
00079 }
00080
00081
00082 NxU32 nControllers = _cm->getNbControllers();
00083
00084 for (NxU32 i=0; i < nControllers; i++) {
00085 NxController *controllerPtr = _cm->getController(i);
00086 PhysxController *controller = (PhysxController *)controllerPtr->getUserData();
00087 controller->unlink();
00088 }
00089
00090
00091 NxActor **actors = _ptr->getActors();
00092 NxU32 nActors = _ptr->getNbActors();
00093
00094 for (NxU32 i=0; i < nActors; i++) {
00095 PhysxActor *actor = (PhysxActor *)actors[i]->userData;
00096
00097
00098 if (actor) {
00099 actor->unlink();
00100 }
00101 }
00102
00103
00104 NxU32 nJoints = _ptr->getNbJoints();
00105
00106 _ptr->resetJointIterator();
00107 for (NxU32 i=0; i < nJoints; i++) {
00108 NxJoint *jointPtr = _ptr->getNextJoint();
00109 PhysxJoint *joint = (PhysxJoint *)jointPtr->userData;
00110 joint->unlink();
00111 }
00112
00113
00114 NxForceField **fields = _ptr->getForceFields();
00115 NxU32 nFields = _ptr->getNbForceFields();
00116
00117 for (NxU32 i=0; i < nFields; i++) {
00118 PhysxForceField *field = (PhysxForceField *)fields[i]->userData;
00119 field->unlink();
00120 }
00121
00122
00123 NxU32 nGroups = _ptr->getNbForceFieldShapeGroups();
00124
00125 _ptr->resetForceFieldShapeGroupsIterator();
00126 for (NxU32 i=0; i < nGroups; i++) {
00127 NxForceFieldShapeGroup *groupPtr = _ptr->getNextForceFieldShapeGroup();
00128 PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)groupPtr->userData;
00129 group->unlink();
00130 }
00131
00132
00133 NxCloth **cloths = _ptr->getCloths();
00134 NxU32 nCloths = _ptr->getNbCloths();
00135
00136 for (NxU32 i=0; i < nCloths; i++) {
00137 PhysxCloth *cloth = (PhysxCloth *)cloths[i]->userData;
00138 cloth->unlink();
00139 }
00140
00141
00142 NxSoftBody **softbodies = _ptr->getSoftBodies();
00143 NxU32 nSoftbodies = _ptr->getNbSoftBodies();
00144
00145 for (NxU32 i=0; i < nSoftbodies; i++) {
00146 PhysxSoftBody *softbody = (PhysxSoftBody *)softbodies[i]->userData;
00147 softbody->unlink();
00148 }
00149
00150
00151 NxMaterial *materials[5];
00152 NxU32 iterator = 0;
00153
00154 while (NxU32 i=_ptr->getMaterialArray(materials, 5, iterator)) {
00155 while(i--) {
00156 PhysxMaterial *material = (PhysxMaterial *)materials[i]->userData;
00157 material->unlink();
00158 }
00159 }
00160
00161
00162 _cm->purgeControllers();
00163 NxReleaseControllerManager(_cm);
00164
00165 _ptr->userData = NULL;
00166 _error_type = ET_released;
00167
00168 PhysxManager::get_global_ptr()->_scenes.remove(this);
00169 }
00170
00171
00172
00173
00174
00175
00176 void PhysxScene::
00177 release() {
00178
00179 nassertv(_error_type == ET_ok);
00180
00181 unlink();
00182 NxPhysicsSDK *sdk = NxGetPhysicsSDK();
00183 sdk->releaseScene(*_ptr);
00184 _ptr = NULL;
00185 }
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 void PhysxScene::
00200 simulate(float dt) {
00201
00202 nassertv(_error_type == ET_ok);
00203
00204 _pcollector_simulate.start();
00205
00206
00207 for (unsigned int i=0; i < _vehicles.size(); i++) {
00208 PhysxVehicle *vehicle = _vehicles[i];
00209 vehicle->update_vehicle(dt);
00210 }
00211
00212
00213 for (NxU32 i=0; i < _cm->getNbControllers(); i++) {
00214 NxController *controllerPtr = _cm->getController(i);
00215 PhysxController *controller = (PhysxController *)controllerPtr->getUserData();
00216 controller->update_controller(dt);
00217 }
00218
00219 _cm->updateControllers();
00220
00221
00222 _ptr->simulate(dt);
00223 _ptr->flushStream();
00224
00225 _pcollector_simulate.stop();
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 void PhysxScene::
00242 fetch_results() {
00243
00244 nassertv(_error_type == ET_ok);
00245 nassertv(_ptr != NULL);
00246
00247 _pcollector_fetch_results.start();
00248 _ptr->fetchResults(NX_RIGID_BODY_FINISHED, true);
00249 _pcollector_fetch_results.stop();
00250
00251
00252 _pcollector_update_transforms.start();
00253
00254 NxU32 nbTransforms = 0;
00255 NxActiveTransform *activeTransforms = _ptr->getActiveTransforms(nbTransforms);
00256
00257 if (nbTransforms && activeTransforms) {
00258 for (NxU32 i=0; i<nbTransforms; ++i) {
00259
00260
00261
00262 void *userData = activeTransforms[i].userData;
00263 if (userData) {
00264 LMatrix4f m = PhysxManager::nxMat34_to_mat4(activeTransforms[i].actor2World);
00265 PhysxActor *actor = (PhysxActor *)userData;
00266 actor->update_transform(m);
00267 }
00268 }
00269 }
00270 _pcollector_update_transforms.stop();
00271
00272
00273 _pcollector_debug_renderer.start();
00274 _debugNode->update(_ptr);
00275 _pcollector_debug_renderer.stop();
00276
00277 nassertv(_ptr->isWritable());
00278
00279
00280 _pcollector_cloth.start();
00281
00282 NxCloth **cloths = _ptr->getCloths();
00283 for (NxU32 i=0; i < _ptr->getNbCloths(); i++) {
00284 PT(PhysxCloth) cloth = (PhysxCloth *)cloths[i]->userData;
00285 cloth->update();
00286 }
00287
00288 _pcollector_cloth.stop();
00289
00290
00291 _pcollector_softbody.start();
00292
00293 NxSoftBody **softbodies = _ptr->getSoftBodies();
00294 for (NxU32 i=0; i < _ptr->getNbSoftBodies(); i++) {
00295 PT(PhysxSoftBody) softbody = (PhysxSoftBody *)softbodies[i]->userData;
00296 softbody->update();
00297 }
00298
00299 _pcollector_softbody.stop();
00300 }
00301
00302
00303
00304
00305
00306
00307
00308 void PhysxScene::
00309 set_timing_variable() {
00310
00311 nassertv(_error_type == ET_ok);
00312 _ptr->setTiming(NULL, NULL, NX_TIMESTEP_VARIABLE);
00313 }
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 void PhysxScene::
00333 set_timing_fixed(float maxTimestep, unsigned int maxIter) {
00334
00335 nassertv(_error_type == ET_ok);
00336 _ptr->setTiming(maxTimestep, maxIter, NX_TIMESTEP_FIXED);
00337 }
00338
00339
00340
00341
00342
00343
00344 void PhysxScene::
00345 set_gravity(const LVector3f &gravity) {
00346
00347 nassertv(_error_type == ET_ok);
00348 nassertv_always(!gravity.is_nan());
00349
00350 _ptr->setGravity(PhysxManager::vec3_to_nxVec3(gravity));
00351 }
00352
00353
00354
00355
00356
00357
00358 LVector3f PhysxScene::
00359 get_gravity() const {
00360
00361 nassertr(_error_type == ET_ok, LVector3f::zero());
00362
00363 NxVec3 gravity;
00364 _ptr->getGravity(gravity);
00365 return PhysxManager::nxVec3_to_vec3(gravity);
00366 }
00367
00368
00369
00370
00371
00372
00373 unsigned int PhysxScene::
00374 get_num_actors() const {
00375
00376 nassertr(_error_type == ET_ok,-1);
00377
00378 return _ptr->getNbActors();
00379 }
00380
00381
00382
00383
00384
00385
00386 PhysxActor *PhysxScene::
00387 create_actor(PhysxActorDesc &desc) {
00388
00389 nassertr(_error_type == ET_ok, NULL);
00390 nassertr(desc.is_valid(), NULL);
00391
00392 PhysxActor *actor = new PhysxActor();
00393 nassertr(actor, NULL);
00394
00395 NxActor *actorPtr = _ptr->createActor(desc._desc);
00396 nassertr(actorPtr, NULL);
00397
00398 actor->link(actorPtr);
00399
00400 return actor;
00401 }
00402
00403
00404
00405
00406
00407
00408 PhysxActor *PhysxScene::
00409 get_actor(unsigned int idx) const {
00410
00411 nassertr(_error_type == ET_ok, NULL);
00412 nassertr_always(idx < _ptr->getNbActors(), NULL);
00413
00414 NxActor *actorPtr = _ptr->getActors()[idx];
00415 PhysxActor *actor = (PhysxActor *)(actorPtr->userData);
00416
00417 return actor;
00418 }
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434 PhysxDebugGeomNode *PhysxScene::
00435 get_debug_geom_node() {
00436
00437 nassertr(_error_type == ET_ok, NULL);
00438 return _debugNode;
00439 }
00440
00441
00442
00443
00444
00445
00446 void PhysxScene::
00447 enable_contact_reporting(bool enabled) {
00448
00449 nassertv(_error_type == ET_ok);
00450
00451 if (enabled) {
00452 _ptr->setUserContactReport(&_contact_report);
00453 _contact_report.enable();
00454 }
00455 else {
00456 _ptr->setUserContactReport(NULL);
00457 _contact_report.disable();
00458 }
00459 }
00460
00461
00462
00463
00464
00465
00466 bool PhysxScene::
00467 is_contact_reporting_enabled() const {
00468
00469 nassertr(_error_type == ET_ok, false);
00470
00471 return _contact_report.is_enabled();
00472 }
00473
00474
00475
00476
00477
00478
00479 void PhysxScene::
00480 enable_trigger_reporting(bool enabled) {
00481
00482 nassertv(_error_type == ET_ok);
00483
00484 if (enabled) {
00485 _ptr->setUserTriggerReport(&_trigger_report);
00486 _trigger_report.enable();
00487 }
00488 else {
00489 _ptr->setUserTriggerReport(NULL);
00490 _trigger_report.disable();
00491 }
00492 }
00493
00494
00495
00496
00497
00498
00499 bool PhysxScene::
00500 is_trigger_reporting_enabled() const {
00501
00502 nassertr(_error_type == ET_ok, false);
00503
00504 return _trigger_report.is_enabled();
00505 }
00506
00507
00508
00509
00510
00511
00512 void PhysxScene::
00513 enable_controller_reporting(bool enabled) {
00514
00515 nassertv(_error_type == ET_ok);
00516
00517 if (enabled) {
00518 _controller_report.enable();
00519 }
00520 else {
00521 _controller_report.disable();
00522 }
00523 }
00524
00525
00526
00527
00528
00529
00530 bool PhysxScene::
00531 is_controller_reporting_enabled() const {
00532
00533 nassertr(_error_type == ET_ok, false);
00534
00535 return _controller_report.is_enabled();
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550 unsigned int PhysxScene::
00551 get_num_materials() const {
00552
00553 nassertr(_error_type == ET_ok, -1);
00554 return _ptr->getNbMaterials();
00555 }
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568 PhysxMaterial *PhysxScene::
00569 create_material(PhysxMaterialDesc &desc) {
00570
00571 nassertr(_error_type == ET_ok, NULL);
00572 nassertr(desc.is_valid(), NULL);
00573
00574 PhysxMaterial *material = new PhysxMaterial();
00575 nassertr(material, NULL);
00576
00577 NxMaterial *materialPtr = _ptr->createMaterial(desc._desc);
00578 nassertr(materialPtr, NULL);
00579
00580 material->link(materialPtr);
00581
00582 return material;
00583 }
00584
00585
00586
00587
00588
00589
00590
00591 PhysxMaterial *PhysxScene::
00592 create_material() {
00593
00594 nassertr(_error_type == ET_ok, NULL);
00595
00596 PhysxMaterial *material = new PhysxMaterial();
00597 nassertr(material, NULL);
00598
00599 NxMaterialDesc desc;
00600 desc.setToDefault();
00601 NxMaterial *materialPtr = _ptr->createMaterial(desc);
00602 nassertr(materialPtr, NULL);
00603
00604 material->link(materialPtr);
00605
00606 return material;
00607 }
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618 unsigned int PhysxScene::
00619 get_hightest_material_index() const {
00620
00621 nassertr(_error_type == ET_ok, -1);
00622 return _ptr->getHighestMaterialIndex();
00623 }
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638 PhysxMaterial *PhysxScene::
00639 get_material_from_index(unsigned int idx) const {
00640
00641 nassertr(_error_type == ET_ok, NULL);
00642
00643 NxMaterial *materialPtr = _ptr->getMaterialFromIndex(idx);
00644
00645 return (PhysxMaterial *)(materialPtr->userData);
00646 }
00647
00648
00649
00650
00651
00652
00653
00654
00655 PhysxMaterial *PhysxScene::
00656 get_material(unsigned int idx) const {
00657
00658 nassertr(_error_type == ET_ok, NULL);
00659 nassertr_always(idx < _ptr->getNbMaterials(), NULL);
00660
00661 NxU32 n = _ptr->getNbMaterials();
00662 NxMaterial **materials = new NxMaterial *[n];
00663 NxU32 materialCount;
00664 NxU32 iterator = 0;
00665
00666 materialCount = _ptr->getMaterialArray(materials, n, iterator);
00667 nassertr((materialCount == n), NULL);
00668
00669 NxMaterial *materialPtr = materials[idx];
00670 delete[] materials;
00671
00672 return (PhysxMaterial *)(materialPtr->userData);
00673 }
00674
00675
00676
00677
00678
00679
00680 unsigned int PhysxScene::
00681 get_num_controllers() const {
00682
00683 nassertr(_error_type == ET_ok, -1);
00684 return _cm->getNbControllers();
00685 }
00686
00687
00688
00689
00690
00691
00692
00693 PhysxController *PhysxScene::
00694 create_controller(PhysxControllerDesc &desc) {
00695
00696 nassertr(_error_type == ET_ok, NULL);
00697 nassertr(desc.is_valid(), NULL);
00698
00699 PhysxController *controller = PhysxController::factory(desc.ptr()->getType());
00700 nassertr(controller, NULL);
00701
00702 desc.ptr()->callback = &_controller_report;
00703 desc.ptr()->userData = controller;
00704
00705 NxController *controllerPtr = _cm->createController(_ptr,*desc.ptr());
00706 nassertr(controllerPtr, NULL);
00707
00708 controller->link(controllerPtr);
00709 controller->get_actor()->set_name("");
00710
00711 return controller;
00712 }
00713
00714
00715
00716
00717
00718
00719 PhysxController *PhysxScene::
00720 get_controller(unsigned int idx) const {
00721
00722 nassertr(_error_type == ET_ok, NULL);
00723 nassertr_always(idx < _cm->getNbControllers(), NULL);
00724
00725 NxController *controllerPtr = _cm->getController(idx);
00726 PhysxController *controller = (PhysxController *)(controllerPtr->getUserData());
00727
00728 return controller;
00729 }
00730
00731
00732
00733
00734
00735
00736
00737
00738 unsigned int PhysxScene::
00739 get_num_joints() const {
00740
00741 nassertr(_error_type == ET_ok, -1);
00742 return _ptr->getNbJoints();
00743 }
00744
00745
00746
00747
00748
00749
00750 PhysxJoint *PhysxScene::
00751 create_joint(PhysxJointDesc &desc) {
00752
00753 nassertr(_error_type == ET_ok, NULL);
00754 nassertr(desc.is_valid(), NULL);
00755
00756 PhysxJoint *joint = PhysxJoint::factory(desc.ptr()->getType());
00757 nassertr(joint, NULL);
00758
00759 NxJoint *jointPtr = _ptr->createJoint(*desc.ptr());
00760 nassertr(jointPtr, NULL);
00761
00762 joint->link(jointPtr);
00763
00764 return joint;
00765 }
00766
00767
00768
00769
00770
00771
00772
00773 PhysxJoint *PhysxScene::
00774 get_joint(unsigned int idx) const {
00775
00776 nassertr(_error_type == ET_ok, NULL);
00777 nassertr_always(idx < _ptr->getNbJoints(), NULL);
00778
00779 NxJoint *jointPtr;
00780 NxU32 nJoints = _ptr->getNbJoints();
00781
00782 _ptr->resetJointIterator();
00783 for (NxU32 i=0; i <= idx; i++) {
00784 jointPtr = _ptr->getNextJoint();
00785 }
00786
00787 return (PhysxJoint *)(jointPtr->userData);
00788 }
00789
00790
00791
00792
00793
00794
00795 unsigned int PhysxScene::
00796 get_num_force_fields() const {
00797
00798 nassertr(_error_type == ET_ok, -1);
00799 return _ptr->getNbForceFields();
00800 }
00801
00802
00803
00804
00805
00806
00807 PhysxForceField *PhysxScene::
00808 create_force_field(PhysxForceFieldDesc &desc) {
00809
00810 nassertr(_error_type == ET_ok, NULL);
00811
00812
00813 desc.create_kernel(_ptr);
00814 nassertr(desc.is_valid(), NULL);
00815
00816
00817 PhysxForceField *field = new PhysxForceField();
00818 nassertr(field, NULL);
00819
00820 NxForceField *fieldPtr = _ptr->createForceField(desc._desc);
00821 nassertr(fieldPtr, NULL);
00822
00823 field->link(fieldPtr);
00824
00825 return field;
00826 }
00827
00828
00829
00830
00831
00832
00833
00834 PhysxForceField *PhysxScene::
00835 get_force_field(unsigned int idx) const {
00836
00837 nassertr(_error_type == ET_ok, NULL);
00838 nassertr_always(idx < _ptr->getNbForceFields(), NULL);
00839
00840 NxForceField **fields = _ptr->getForceFields();
00841 NxForceField *fieldPtr = fields[idx];
00842
00843 return (PhysxForceField *)(fieldPtr->userData);
00844 }
00845
00846
00847
00848
00849
00850
00851
00852 unsigned int PhysxScene::
00853 get_num_force_field_shape_groups() const {
00854
00855 nassertr(_error_type == ET_ok, -1);
00856 return _ptr->getNbForceFieldShapeGroups();
00857 }
00858
00859
00860
00861
00862
00863
00864
00865 PhysxForceFieldShapeGroup *PhysxScene::
00866 create_force_field_shape_group(PhysxForceFieldShapeGroupDesc &desc) {
00867
00868 nassertr(_error_type == ET_ok, NULL);
00869
00870 PhysxForceFieldShapeGroup *group = new PhysxForceFieldShapeGroup();
00871 nassertr(group, NULL);
00872
00873 NxForceFieldShapeGroup *groupPtr = _ptr->createForceFieldShapeGroup(desc._desc);
00874 nassertr(groupPtr, NULL);
00875
00876 group->link(groupPtr);
00877
00878 return group;
00879 }
00880
00881
00882
00883
00884
00885
00886
00887 PhysxForceFieldShapeGroup *PhysxScene::
00888 get_force_field_shape_group(unsigned int idx) const {
00889
00890 nassertr(_error_type == ET_ok, NULL);
00891 nassertr_always(idx < _ptr->getNbForceFieldShapeGroups(), NULL);
00892
00893 _ptr->resetForceFieldShapeGroupsIterator();
00894 NxForceFieldShapeGroup *groupPtr = NULL;
00895 idx++;
00896 while (idx-- > 0) {
00897 groupPtr = _ptr->getNextForceFieldShapeGroup();
00898 }
00899
00900 return groupPtr ? (PhysxForceFieldShapeGroup *)groupPtr->userData : NULL;
00901 }
00902
00903
00904
00905
00906
00907
00908 unsigned int PhysxScene::
00909 get_num_cloths() const {
00910
00911 nassertr(_error_type == ET_ok, -1);
00912 return _ptr->getNbCloths();
00913 }
00914
00915
00916
00917
00918
00919
00920 PhysxCloth *PhysxScene::
00921 create_cloth(PhysxClothDesc &desc) {
00922
00923 nassertr(_error_type == ET_ok, NULL);
00924
00925 PhysxCloth *cloth = new PhysxCloth();
00926 nassertr(cloth, NULL);
00927
00928 NxCloth *clothPtr = _ptr->createCloth(desc._desc);
00929 nassertr(clothPtr, NULL);
00930
00931 cloth->link(clothPtr);
00932
00933 return cloth;
00934 }
00935
00936
00937
00938
00939
00940
00941
00942 PhysxCloth *PhysxScene::
00943 get_cloth(unsigned int idx) const {
00944
00945 nassertr(_error_type == ET_ok, NULL);
00946 nassertr_always(idx < _ptr->getNbCloths(), NULL);
00947
00948 NxCloth **cloths = _ptr->getCloths();
00949 NxCloth *clothPtr = cloths[idx];
00950
00951 return (PhysxCloth *)(clothPtr->userData);
00952 }
00953
00954
00955
00956
00957
00958
00959 unsigned int PhysxScene::
00960 get_num_soft_bodies() const {
00961
00962 nassertr(_error_type == ET_ok, -1);
00963 return _ptr->getNbSoftBodies();
00964 }
00965
00966
00967
00968
00969
00970
00971 PhysxSoftBody *PhysxScene::
00972 create_soft_body(PhysxSoftBodyDesc &desc) {
00973
00974 nassertr(_error_type == ET_ok, NULL);
00975
00976 PhysxSoftBody *softbody = new PhysxSoftBody();
00977 nassertr(softbody, NULL);
00978
00979 NxSoftBody *softbodyPtr = _ptr->createSoftBody(desc._desc);
00980 nassertr(softbodyPtr, NULL);
00981
00982 softbody->link(softbodyPtr);
00983
00984 return softbody;
00985 }
00986
00987
00988
00989
00990
00991
00992
00993 PhysxSoftBody *PhysxScene::
00994 get_soft_body(unsigned int idx) const {
00995
00996 nassertr(_error_type == ET_ok, NULL);
00997 nassertr_always(idx < _ptr->getNbSoftBodies(), NULL);
00998
00999 NxSoftBody **softbodies = _ptr->getSoftBodies();
01000 NxSoftBody *softbodyPtr = softbodies[idx];
01001
01002 return (PhysxSoftBody *)(softbodyPtr->userData);
01003 }
01004
01005
01006
01007
01008
01009
01010 unsigned int PhysxScene::
01011 get_num_vehicles() const {
01012
01013 nassertr(_error_type == ET_ok, -1);
01014 return _vehicles.size();
01015 }
01016
01017
01018
01019
01020
01021
01022 PhysxVehicle *PhysxScene::
01023 create_vehicle(PhysxVehicleDesc &desc) {
01024
01025 nassertr(_error_type == ET_ok, NULL);
01026 nassertr(desc.is_valid(), NULL);
01027
01028 PhysxVehicle *vehicle = new PhysxVehicle();
01029 nassertr(vehicle, NULL);
01030
01031 vehicle->create(this, desc);
01032
01033 return vehicle;
01034 }
01035
01036
01037
01038
01039
01040
01041
01042 PhysxVehicle *PhysxScene::
01043 get_vehicle(unsigned int idx) const {
01044
01045 nassertr(_error_type == ET_ok, NULL);
01046 nassertr_always(idx < _vehicles.size(), NULL);
01047
01048 return _vehicles[idx];
01049 }
01050
01051
01052
01053
01054
01055
01056 PhysxSceneStats2 PhysxScene::
01057 get_stats2() const {
01058
01059 nassertr(_error_type == ET_ok, NULL);
01060 return PhysxSceneStats2(_ptr->getStats2());
01061 }
01062
01063
01064
01065
01066
01067
01068
01069 bool PhysxScene::
01070 raycast_any_shape(const PhysxRay &ray,
01071 PhysxShapesType shapesType,
01072 PhysxMask mask,
01073 PhysxGroupsMask *groups) const {
01074
01075 nassertr(_error_type == ET_ok, false);
01076
01077 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL;
01078
01079 return _ptr->raycastAnyShape(ray._ray, (NxShapesType)shapesType,
01080 mask.get_mask(), ray._length, groupsPtr);
01081 }
01082
01083
01084
01085
01086
01087
01088
01089
01090 PhysxRaycastHit PhysxScene::
01091 raycast_closest_shape(const PhysxRay &ray,
01092 PhysxShapesType shapesType,
01093 PhysxMask mask,
01094 PhysxGroupsMask *groups, bool smoothNormal) const {
01095
01096 NxRaycastHit hit;
01097
01098 nassertr(_error_type == ET_ok, hit);
01099
01100 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL;
01101
01102 NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
01103 if (smoothNormal == true) {
01104 hints |= NX_RAYCAST_NORMAL;
01105 }
01106 else {
01107 hints |= NX_RAYCAST_FACE_NORMAL;
01108 }
01109
01110 _ptr->raycastClosestShape(ray._ray, (NxShapesType)shapesType, hit,
01111 mask.get_mask(), ray._length, hints, groupsPtr);
01112
01113
01114 return PhysxRaycastHit(hit);
01115 }
01116
01117
01118
01119
01120
01121
01122
01123
01124 PhysxRaycastReport PhysxScene::
01125 raycast_all_shapes(const PhysxRay &ray,
01126 PhysxShapesType shapesType,
01127 PhysxMask mask,
01128 PhysxGroupsMask *groups, bool smoothNormal) const {
01129
01130 PhysxRaycastReport report;
01131
01132 nassertr(_error_type == ET_ok, report);
01133
01134 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL;
01135
01136 NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
01137 if (smoothNormal == true) {
01138 hints |= NX_RAYCAST_NORMAL;
01139 }
01140 else {
01141 hints |= NX_RAYCAST_FACE_NORMAL;
01142 }
01143
01144 _ptr->raycastAllShapes(ray._ray, report, (NxShapesType)shapesType,
01145 mask.get_mask(), ray._length, hints, groupsPtr);
01146
01147 return report;
01148 }
01149
01150
01151
01152
01153
01154
01155
01156 bool PhysxScene::
01157 raycast_any_bounds(const PhysxRay &ray,
01158 PhysxShapesType shapesType,
01159 PhysxMask mask,
01160 PhysxGroupsMask *groups) const {
01161
01162 nassertr(_error_type == ET_ok, false);
01163
01164 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL;
01165
01166 return _ptr->raycastAnyBounds(ray._ray, (NxShapesType)shapesType,
01167 mask.get_mask(), ray._length, groupsPtr);
01168 }
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178 PhysxRaycastHit PhysxScene::
01179 raycast_closest_bounds(const PhysxRay &ray, PhysxShapesType shapesType, PhysxMask mask, PhysxGroupsMask *groups, bool smoothNormal) const {
01180
01181 NxRaycastHit hit;
01182
01183 nassertr(_error_type == ET_ok, hit);
01184
01185 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL;
01186
01187 NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
01188 if (smoothNormal == true) {
01189 hints |= NX_RAYCAST_NORMAL;
01190 }
01191 else {
01192 hints |= NX_RAYCAST_FACE_NORMAL;
01193 }
01194
01195 _ptr->raycastClosestBounds(ray._ray, (NxShapesType)shapesType, hit,
01196 mask.get_mask(), ray._length, hints, groupsPtr);
01197
01198
01199 return PhysxRaycastHit(hit);
01200 }
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210 PhysxRaycastReport PhysxScene::
01211 raycast_all_bounds(const PhysxRay &ray,
01212 PhysxShapesType shapesType,
01213 PhysxMask mask,
01214 PhysxGroupsMask *groups, bool smoothNormal) const {
01215
01216 PhysxRaycastReport report;
01217
01218 nassertr(_error_type == ET_ok, report);
01219
01220 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL;
01221
01222 NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
01223 if (smoothNormal == true) {
01224 hints |= NX_RAYCAST_NORMAL;
01225 }
01226 else {
01227 hints |= NX_RAYCAST_FACE_NORMAL;
01228 }
01229
01230 _ptr->raycastAllBounds(ray._ray, report, (NxShapesType)shapesType,
01231 mask.get_mask(), ray._length, hints, groupsPtr);
01232
01233 return report;
01234 }
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244 PhysxOverlapReport PhysxScene::
01245 overlap_sphere_shapes(const LPoint3f ¢er, float radius,
01246 PhysxShapesType shapesType,
01247 PhysxMask mask, bool accurateCollision) const {
01248
01249 PhysxOverlapReport report;
01250
01251 nassertr(_error_type == ET_ok, report);
01252
01253 NxSphere worldSphere(PhysxManager::point3_to_nxVec3(center), radius);
01254
01255 _ptr->overlapSphereShapes(worldSphere, (NxShapesType)shapesType, 0, NULL, &report,
01256 mask.get_mask(), NULL, accurateCollision);
01257
01258 return report;
01259 }
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269 PhysxOverlapReport PhysxScene::
01270 overlap_capsule_shapes(const LPoint3f &p0, const LPoint3f &p1, float radius,
01271 PhysxShapesType shapesType,
01272 PhysxMask mask, bool accurateCollision) const {
01273
01274 PhysxOverlapReport report;
01275
01276 nassertr(_error_type == ET_ok, report);
01277
01278 NxSegment segment(PhysxManager::point3_to_nxVec3(p0),
01279 PhysxManager::point3_to_nxVec3(p1));
01280 NxCapsule worldCapsule(segment, radius);
01281
01282 _ptr->overlapCapsuleShapes(worldCapsule, (NxShapesType)shapesType, 0, NULL, &report,
01283 mask.get_mask(), NULL, accurateCollision);
01284
01285 return report;
01286 }
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303 void PhysxScene::
01304 set_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB,
01305 PhysxContactPairFlag flag, bool value) {
01306
01307 nassertv(_error_type == ET_ok);
01308
01309 NxActor *ptrA = actorA.ptr();
01310 NxActor *ptrB = actorB.ptr();
01311 NxU32 flags = _ptr->getActorPairFlags(*ptrA, *ptrB);
01312
01313 if (value == true) {
01314 flags |= flag;
01315 }
01316 else {
01317 flags &= ~(flag);
01318 }
01319
01320 _ptr->setActorPairFlags(*ptrA, *ptrB, flags);
01321 }
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332 bool PhysxScene::
01333 get_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB,
01334 PhysxContactPairFlag flag) {
01335
01336 nassertr(_error_type == ET_ok, false);
01337
01338 NxActor *ptrA = actorA.ptr();
01339 NxActor *ptrB = actorB.ptr();
01340 NxU32 flags = _ptr->getActorPairFlags(*ptrA, *ptrB);
01341
01342 return (flags && flag) ? true : false;
01343 }
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354 void PhysxScene::
01355 set_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB, bool value) {
01356
01357 nassertv(_error_type == ET_ok);
01358
01359 NxShape *ptrA = shapeA.ptr();
01360 NxShape *ptrB = shapeB.ptr();
01361 NxU32 flags = _ptr->getShapePairFlags(*ptrA, *ptrB);
01362
01363 if (value == true) {
01364 flags |= NX_IGNORE_PAIR;
01365 }
01366 else {
01367 flags &= ~(NX_IGNORE_PAIR);
01368 }
01369
01370 _ptr->setShapePairFlags(*ptrA, *ptrB, flags);
01371 }
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383 bool PhysxScene::
01384 get_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB) {
01385
01386 nassertr(_error_type == ET_ok, false);
01387
01388 NxShape *ptrA = shapeA.ptr();
01389 NxShape *ptrB = shapeB.ptr();
01390 NxU32 flags = _ptr->getShapePairFlags(*ptrA, *ptrB);
01391
01392 return (flags && NX_IGNORE_PAIR) ? true : false;
01393 }
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421 void PhysxScene::
01422 set_actor_group_pair_flag(unsigned int g1, unsigned int g2,
01423 PhysxContactPairFlag flag, bool value) {
01424
01425 nassertv(_error_type == ET_ok);
01426
01427 NxU32 flags = _ptr->getActorGroupPairFlags(g1, g2);
01428 if (value == true) {
01429 flags |= flag;
01430 }
01431 else {
01432 flags &= ~(flag);
01433 }
01434 _ptr->setActorGroupPairFlags(g1, g2, flags);
01435 }
01436
01437
01438
01439
01440
01441
01442
01443 bool PhysxScene::
01444 get_actor_group_pair_flag(unsigned int g1, unsigned int g2,
01445 PhysxContactPairFlag flag) {
01446
01447 nassertr(_error_type == ET_ok, false);
01448 NxU32 flags = _ptr->getActorGroupPairFlags(g1, g2);
01449 return (flags && flag) ? true : false;
01450 }
01451
01452
01453
01454
01455
01456
01457 void PhysxScene::
01458 set_filter_ops(PhysxFilterOp op0, PhysxFilterOp op1, PhysxFilterOp op2) {
01459
01460 nassertv(_error_type == ET_ok);
01461 _ptr->setFilterOps((NxFilterOp)op0, (NxFilterOp)op1, (NxFilterOp)op2);
01462 }
01463
01464
01465
01466
01467
01468
01469 void PhysxScene::
01470 set_filter_bool(bool flag) {
01471
01472 nassertv(_error_type == ET_ok);
01473 _ptr->setFilterBool(flag);
01474 }
01475
01476
01477
01478
01479
01480
01481 void PhysxScene::
01482 set_filter_constant0(const PhysxGroupsMask &mask) {
01483
01484 nassertv(_error_type == ET_ok);
01485 _ptr->setFilterConstant0(mask.get_mask());
01486 }
01487
01488
01489
01490
01491
01492
01493 void PhysxScene::
01494 set_filter_constant1(const PhysxGroupsMask &mask) {
01495
01496 nassertv(_error_type == ET_ok);
01497 _ptr->setFilterConstant1(mask.get_mask());
01498 }
01499
01500
01501
01502
01503
01504
01505 bool PhysxScene::
01506 get_filter_bool() const {
01507
01508 nassertr(_error_type == ET_ok, false);
01509 return _ptr->getFilterBool();
01510 }
01511
01512
01513
01514
01515
01516
01517 PhysxGroupsMask PhysxScene::
01518 get_filter_constant0() const {
01519
01520 PhysxGroupsMask mask;
01521
01522 nassertr(_error_type == ET_ok, mask);
01523
01524 NxGroupsMask _mask = ptr()->getFilterConstant0();
01525 mask.set_mask(_mask);
01526
01527 return mask;
01528 }
01529
01530
01531
01532
01533
01534
01535 PhysxGroupsMask PhysxScene::
01536 get_filter_constant1() const {
01537
01538 PhysxGroupsMask mask;
01539
01540 nassertr(_error_type == ET_ok, mask);
01541
01542 NxGroupsMask _mask = ptr()->getFilterConstant1();
01543 mask.set_mask(_mask);
01544
01545 return mask;
01546 }
01547
01548
01549
01550
01551
01552
01553 PhysxEnums::PhysxFilterOp PhysxScene::
01554 get_filter_op0() const {
01555
01556 nassertr(_error_type == ET_ok, FO_and);
01557
01558 NxFilterOp op0;
01559 NxFilterOp op1;
01560 NxFilterOp op2;
01561
01562 _ptr->getFilterOps(op0, op1, op2);
01563
01564 return (PhysxFilterOp)op0;
01565 }
01566
01567
01568
01569
01570
01571
01572 PhysxEnums::PhysxFilterOp PhysxScene::
01573 get_filter_op1() const {
01574
01575 nassertr(_error_type == ET_ok, FO_and);
01576
01577 NxFilterOp op0;
01578 NxFilterOp op1;
01579 NxFilterOp op2;
01580
01581 _ptr->getFilterOps(op0, op1, op2);
01582
01583 return (PhysxFilterOp)op1;
01584 }
01585
01586
01587
01588
01589
01590
01591 PhysxEnums::PhysxFilterOp PhysxScene::
01592 get_filter_op2() const {
01593
01594 nassertr(_error_type == ET_ok, FO_and);
01595
01596 NxFilterOp op0;
01597 NxFilterOp op1;
01598 NxFilterOp op2;
01599
01600 _ptr->getFilterOps(op0, op1, op2);
01601
01602 return (PhysxFilterOp)op2;
01603 }
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621 void PhysxScene::
01622 set_group_collision_flag(unsigned int g1, unsigned int g2, bool enable) {
01623
01624 nassertv(_error_type == ET_ok);
01625 nassertv(g1 >= 0 && g1 < 32);
01626 nassertv(g2 >= 0 && g2 < 32);
01627
01628 _ptr->setGroupCollisionFlag((NxCollisionGroup)g1, (NxCollisionGroup)g2, enable);
01629 }
01630
01631
01632
01633
01634
01635
01636
01637
01638 bool PhysxScene::
01639 get_group_collision_flag(unsigned int g1, unsigned int g2) {
01640
01641 nassertr(_error_type == ET_ok, false);
01642 nassertr(g1 >= 0 && g1 < 32, false);
01643 nassertr(g2 >= 0 && g2 < 32, false);
01644
01645 return _ptr->getGroupCollisionFlag((NxCollisionGroup)g1, (NxCollisionGroup)g2);
01646 }
01647
01648
01649
01650
01651
01652
01653 bool PhysxScene::
01654 get_flag(PhysxSceneFlag flag) const {
01655
01656 nassertr(_error_type == ET_ok, false);
01657 return (_ptr->getFlags() & flag) ? true : false;
01658 }
01659
01660
01661
01662
01663
01664
01665
01666
01667 bool PhysxScene::
01668 is_hardware_scene() const {
01669
01670 nassertr(_error_type == ET_ok, false);
01671 return (_ptr->getSimType() & NX_SIMULATION_HW) ? true : false;
01672 }
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727 void PhysxScene::
01728 set_dominance_group_pair(unsigned int g1, unsigned int g2, PhysxConstraintDominance dominance ) {
01729
01730 nassertv(_error_type == ET_ok);
01731 nassertv(g1 < 32);
01732 nassertv(g2 < 32);
01733
01734 NxConstraintDominance d = dominance.get_dominance();
01735 _ptr->setDominanceGroupPair((NxDominanceGroup)g1, (NxDominanceGroup)g2, d);
01736 }
01737
01738
01739
01740
01741
01742
01743 PhysxConstraintDominance PhysxScene::
01744 get_dominance_group_pair(unsigned int g1, unsigned int g2) {
01745
01746 PhysxConstraintDominance result(1.0f, 1.0f);
01747
01748 nassertr(_error_type == ET_ok, result);
01749 nassertr(g1 < 32, result);
01750 nassertr(g2 < 32, result);
01751
01752 result.set_dominance(_ptr->getDominanceGroupPair((NxDominanceGroup)g1, (NxDominanceGroup)g2));
01753 return result;
01754 }
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767 PhysxMaterial *PhysxScene::
01768 get_wheel_shape_material() {
01769
01770 nassertr(_error_type == ET_ok, NULL);
01771
01772 if (_wheelShapeMaterial == NULL) {
01773 PhysxMaterialDesc materialDesc;
01774 materialDesc.set_flag(PhysxMaterialDesc::MF_disable_friction, true);
01775 _wheelShapeMaterial = create_material(materialDesc);
01776 }
01777
01778 return _wheelShapeMaterial;
01779 }
01780