From 1a7942b40c94c4da94ffecd8a1f7b98bea378dfc Mon Sep 17 00:00:00 2001 From: enn0x Date: Mon, 28 Dec 2009 11:33:36 +0000 Subject: [PATCH] Merging dev_physx_2009 to HEAD. --- dtool/src/parser-inc/NxBoxController.h | 28 + dtool/src/parser-inc/NxCapsuleController.h | 28 + dtool/src/parser-inc/NxCloth.h | 2 - dtool/src/parser-inc/NxController.h | 30 + dtool/src/parser-inc/NxControllerManager.h | 25 + dtool/src/parser-inc/NxCooking.h | 25 + dtool/src/parser-inc/NxExtended.h | 25 + dtool/src/parser-inc/NxFluid.h | 2 - dtool/src/parser-inc/NxPhysics.h | 262 +- dtool/src/parser-inc/NxStream.h | 25 + dtool/src/parser-inc/Sources.pp | 4 +- makepanda/makepanda.py | 69 +- makepanda/makepandacore.py | 40 + panda/metalibs/pandaphysx/Sources.pp | 34 +- panda/metalibs/pandaphysx/pandaphysx.cxx | 7 +- panda/metalibs/pandaphysx/pandaphysx.h | 2 +- panda/src/physx/NoMinMax.h | 2 +- panda/src/physx/Sources.pp | 322 ++- panda/src/physx/SourcesTemplate.pp | 39 - panda/src/physx/config_physx.cxx | 115 +- panda/src/physx/config_physx.h | 53 +- panda/src/physx/createComposite.py | 19 - panda/src/physx/generateCode.py | 1021 -------- panda/src/physx/physxActor.I | 72 + panda/src/physx/physxActor.cxx | 1663 ++++++++++++ panda/src/physx/physxActor.h | 227 ++ panda/src/physx/physxActorDesc.I | 80 +- panda/src/physx/physxActorDesc.cxx | 189 +- panda/src/physx/physxActorDesc.h | 50 +- panda/src/physx/physxActorNode.I | 79 - panda/src/physx/physxActorNode.cxx | 1190 --------- panda/src/physx/physxActorNode.h | 178 -- panda/src/physx/physxBodyDesc.I | 278 +-- panda/src/physx/physxBodyDesc.cxx | 410 ++- panda/src/physx/physxBodyDesc.h | 92 +- panda/src/physx/physxBounds3.I | 187 +- panda/src/physx/physxBounds3.cxx | 289 ++- panda/src/physx/physxBounds3.h | 65 +- panda/src/physx/physxBox.I | 43 +- panda/src/physx/physxBox.cxx | 133 +- panda/src/physx/physxBox.h | 44 +- ...mitSoftPairDesc.I => physxBoxController.I} | 30 +- panda/src/physx/physxBoxController.cxx | 85 + panda/src/physx/physxBoxController.h | 72 + panda/src/physx/physxBoxControllerDesc.I | 59 + panda/src/physx/physxBoxControllerDesc.cxx | 43 + panda/src/physx/physxBoxControllerDesc.h | 49 + ...sxTemplate.h => physxBoxForceFieldShape.I} | 46 +- panda/src/physx/physxBoxForceFieldShape.cxx | 96 + panda/src/physx/physxBoxForceFieldShape.h | 77 + panda/src/physx/physxBoxForceFieldShapeDesc.I | 59 + .../src/physx/physxBoxForceFieldShapeDesc.cxx | 44 + panda/src/physx/physxBoxForceFieldShapeDesc.h | 50 + panda/src/physx/physxBoxShape.I | 24 +- panda/src/physx/physxBoxShape.cxx | 122 +- panda/src/physx/physxBoxShape.h | 53 +- panda/src/physx/physxBoxShapeDesc.I | 47 +- panda/src/physx/physxBoxShapeDesc.cxx | 56 +- panda/src/physx/physxBoxShapeDesc.h | 27 +- panda/src/physx/physxCapsule.I | 42 +- panda/src/physx/physxCapsule.cxx | 160 +- panda/src/physx/physxCapsule.h | 41 +- panda/src/physx/physxCapsuleController.I | 36 + panda/src/physx/physxCapsuleController.cxx | 108 + panda/src/physx/physxCapsuleController.h | 90 + panda/src/physx/physxCapsuleControllerDesc.I | 59 + .../src/physx/physxCapsuleControllerDesc.cxx | 64 + panda/src/physx/physxCapsuleControllerDesc.h | 50 + panda/src/physx/physxCapsuleForceFieldShape.I | 36 + .../src/physx/physxCapsuleForceFieldShape.cxx | 111 + panda/src/physx/physxCapsuleForceFieldShape.h | 81 + .../physx/physxCapsuleForceFieldShapeDesc.I | 59 + .../physx/physxCapsuleForceFieldShapeDesc.cxx | 64 + .../physx/physxCapsuleForceFieldShapeDesc.h | 51 + panda/src/physx/physxCapsuleShape.I | 24 +- panda/src/physx/physxCapsuleShape.cxx | 130 +- panda/src/physx/physxCapsuleShape.h | 62 +- panda/src/physx/physxCapsuleShapeDesc.I | 99 +- panda/src/physx/physxCapsuleShapeDesc.cxx | 55 +- panda/src/physx/physxCapsuleShapeDesc.h | 32 +- panda/src/physx/physxConstraintDominance.I | 57 + panda/src/physx/physxConstraintDominance.cxx | 60 + panda/src/physx/physxConstraintDominance.h | 57 + panda/src/physx/physxContactHandler.cxx | 129 - panda/src/physx/physxContactHandler.h | 67 - panda/src/physx/physxContactPair.I | 36 + panda/src/physx/physxContactPair.cxx | 129 + panda/src/physx/physxContactPair.h | 79 + panda/src/physx/physxContactPoint.I | 36 + panda/src/physx/physxContactPoint.cxx | 114 + panda/src/physx/physxContactPoint.h | 82 + panda/src/physx/physxContactReport.I | 36 + panda/src/physx/physxContactReport.cxx | 101 + panda/src/physx/physxContactReport.h | 48 + panda/src/physx/physxController.I | 79 + panda/src/physx/physxController.cxx | 389 +++ panda/src/physx/physxController.h | 120 + ...hysxTemplate.cxx => physxControllerDesc.I} | 21 +- panda/src/physx/physxControllerDesc.cxx | 148 ++ panda/src/physx/physxControllerDesc.h | 54 + panda/src/physx/physxControllerReport.I | 36 + panda/src/physx/physxControllerReport.cxx | 105 + panda/src/physx/physxControllerReport.h | 48 + panda/src/physx/physxConvexForceFieldShape.I | 36 + .../src/physx/physxConvexForceFieldShape.cxx | 63 + panda/src/physx/physxConvexForceFieldShape.h | 73 + .../physx/physxConvexForceFieldShapeDesc.I | 59 + .../physx/physxConvexForceFieldShapeDesc.cxx | 29 + .../physx/physxConvexForceFieldShapeDesc.h | 49 + panda/src/physx/physxConvexMesh.I | 59 + panda/src/physx/physxConvexMesh.cxx | 76 + panda/src/physx/physxConvexMesh.h | 79 + panda/src/physx/physxConvexMeshDesc.I | 54 + panda/src/physx/physxConvexMeshDesc.cxx | 130 + panda/src/physx/physxConvexMeshDesc.h | 51 + panda/src/physx/physxConvexShape.I | 36 + panda/src/physx/physxConvexShape.cxx | 63 + panda/src/physx/physxConvexShape.h | 74 + panda/src/physx/physxConvexShapeDesc.I | 59 + panda/src/physx/physxConvexShapeDesc.cxx | 29 + panda/src/physx/physxConvexShapeDesc.h | 49 + panda/src/physx/physxCylindricalJoint.I | 36 + panda/src/physx/physxCylindricalJoint.cxx | 76 + panda/src/physx/physxCylindricalJoint.h | 76 + panda/src/physx/physxCylindricalJointDesc.I | 59 + ...mplate.I => physxCylindricalJointDesc.cxx} | 9 +- panda/src/physx/physxCylindricalJointDesc.h | 46 + panda/src/physx/physxD6Joint.I | 24 +- panda/src/physx/physxD6Joint.cxx | 107 +- panda/src/physx/physxD6Joint.h | 49 +- panda/src/physx/physxD6JointDesc.I | 119 +- panda/src/physx/physxD6JointDesc.cxx | 1004 ++++---- panda/src/physx/physxD6JointDesc.h | 126 +- panda/src/physx/physxDebugGeomNode.I | 389 +++ panda/src/physx/physxDebugGeomNode.cxx | 102 + panda/src/physx/physxDebugGeomNode.h | 109 + panda/src/physx/physxDistanceJoint.I | 36 + panda/src/physx/physxDistanceJoint.cxx | 76 + panda/src/physx/physxDistanceJoint.h | 75 + panda/src/physx/physxDistanceJointDesc.I | 59 + panda/src/physx/physxDistanceJointDesc.cxx | 115 + panda/src/physx/physxDistanceJointDesc.h | 58 + panda/src/physx/physxEnums.cxx | 60 + panda/src/physx/physxEnums.h | 623 +++++ panda/src/physx/physxFileStream.cxx | 186 ++ panda/src/physx/physxFileStream.h | 51 + panda/src/physx/physxFixedJoint.I | 36 + panda/src/physx/physxFixedJoint.cxx | 76 + panda/src/physx/physxFixedJoint.h | 75 + panda/src/physx/physxFixedJointDesc.I | 59 + ...JointHandler.I => physxFixedJointDesc.cxx} | 7 +- panda/src/physx/physxFixedJointDesc.h | 47 + panda/src/physx/physxForceField.I | 60 + panda/src/physx/physxForceField.cxx | 160 ++ panda/src/physx/physxForceField.h | 98 + panda/src/physx/physxForceFieldDesc.I | 59 + panda/src/physx/physxForceFieldDesc.cxx | 225 ++ panda/src/physx/physxForceFieldDesc.h | 74 + panda/src/physx/physxForceFieldShape.I | 50 + panda/src/physx/physxForceFieldShape.cxx | 175 ++ panda/src/physx/physxForceFieldShape.h | 91 + panda/src/physx/physxForceFieldShapeDesc.I | 26 + panda/src/physx/physxForceFieldShapeDesc.cxx | 103 + panda/src/physx/physxForceFieldShapeDesc.h | 54 + panda/src/physx/physxForceFieldShapeGroup.I | 62 + panda/src/physx/physxForceFieldShapeGroup.cxx | 218 ++ panda/src/physx/physxForceFieldShapeGroup.h | 98 + .../src/physx/physxForceFieldShapeGroupDesc.I | 59 + .../physx/physxForceFieldShapeGroupDesc.cxx | 81 + .../src/physx/physxForceFieldShapeGroupDesc.h | 54 + panda/src/physx/physxGroupsMask.I | 160 ++ panda/src/physx/physxGroupsMask.cxx | 156 ++ panda/src/physx/physxGroupsMask.h | 67 + panda/src/physx/physxHeightField.I | 59 + panda/src/physx/physxHeightField.cxx | 82 + panda/src/physx/physxHeightField.h | 98 + panda/src/physx/physxHeightFieldDesc.I | 99 + panda/src/physx/physxHeightFieldDesc.cxx | 135 + panda/src/physx/physxHeightFieldDesc.h | 63 + panda/src/physx/physxHeightFieldShape.I | 36 + panda/src/physx/physxHeightFieldShape.cxx | 63 + panda/src/physx/physxHeightFieldShape.h | 84 + panda/src/physx/physxHeightFieldShapeDesc.I | 48 + panda/src/physx/physxHeightFieldShapeDesc.cxx | 118 + panda/src/physx/physxHeightFieldShapeDesc.h | 55 + panda/src/physx/physxJoint.I | 65 +- panda/src/physx/physxJoint.cxx | 448 ++-- panda/src/physx/physxJoint.h | 91 +- panda/src/physx/physxJointDesc.I | 135 +- panda/src/physx/physxJointDesc.cxx | 313 ++- panda/src/physx/physxJointDesc.h | 72 +- panda/src/physx/physxJointDriveDesc.I | 72 +- panda/src/physx/physxJointDriveDesc.cxx | 94 +- panda/src/physx/physxJointDriveDesc.h | 38 +- panda/src/physx/physxJointHandler.cxx | 84 - panda/src/physx/physxJointHandler.h | 60 - panda/src/physx/physxJointLimitDesc.I | 48 + panda/src/physx/physxJointLimitDesc.cxx | 82 + panda/src/physx/physxJointLimitDesc.h | 48 + panda/src/physx/physxJointLimitSoftDesc.I | 113 +- panda/src/physx/physxJointLimitSoftDesc.cxx | 94 +- panda/src/physx/physxJointLimitSoftDesc.h | 41 +- .../src/physx/physxJointLimitSoftPairDesc.cxx | 73 - panda/src/physx/physxJointLimitSoftPairDesc.h | 55 - panda/src/physx/physxKitchen.I | 40 + panda/src/physx/physxKitchen.cxx | 141 ++ panda/src/physx/physxKitchen.h | 54 + panda/src/physx/physxManager.I | 279 ++- panda/src/physx/physxManager.cxx | 490 ++-- panda/src/physx/physxManager.h | 119 +- panda/src/physx/physxMask.I | 47 + panda/src/physx/physxMask.cxx | 100 + panda/src/physx/physxMask.h | 56 + panda/src/physx/physxMaterial.I | 47 +- panda/src/physx/physxMaterial.cxx | 537 ++-- panda/src/physx/physxMaterial.h | 121 +- panda/src/physx/physxMaterialDesc.I | 158 +- panda/src/physx/physxMaterialDesc.cxx | 281 ++- panda/src/physx/physxMaterialDesc.h | 57 +- panda/src/physx/physxMemoryReadBuffer.cxx | 112 + panda/src/physx/physxMemoryReadBuffer.h | 50 + panda/src/physx/physxMemoryWriteBuffer.cxx | 116 + panda/src/physx/physxMemoryWriteBuffer.h | 52 + panda/src/physx/physxMeshPool.I | 35 + panda/src/physx/physxMeshPool.cxx | 225 ++ panda/src/physx/physxMeshPool.h | 70 + panda/src/physx/physxMotorDesc.I | 48 + panda/src/physx/physxMotorDesc.cxx | 82 + panda/src/physx/physxMotorDesc.h | 53 + panda/src/physx/physxObject.I | 135 + panda/src/physx/physxObject.cxx | 42 + panda/src/physx/physxObject.h | 88 + panda/src/physx/physxObjectCollection.I | 114 + ...actHandler.I => physxObjectCollection.cxx} | 7 +- panda/src/physx/physxObjectCollection.h | 45 + panda/src/physx/physxOverlapReport.I | 35 + panda/src/physx/physxOverlapReport.cxx | 84 + panda/src/physx/physxOverlapReport.h | 60 + panda/src/physx/physxPlane.I | 93 +- panda/src/physx/physxPlane.cxx | 210 +- panda/src/physx/physxPlane.h | 54 +- panda/src/physx/physxPlaneShape.I | 24 +- panda/src/physx/physxPlaneShape.cxx | 79 +- panda/src/physx/physxPlaneShape.h | 64 +- panda/src/physx/physxPlaneShapeDesc.I | 59 +- panda/src/physx/physxPlaneShapeDesc.cxx | 47 +- panda/src/physx/physxPlaneShapeDesc.h | 31 +- panda/src/physx/physxPointInPlaneJoint.I | 36 + panda/src/physx/physxPointInPlaneJoint.cxx | 76 + panda/src/physx/physxPointInPlaneJoint.h | 80 + panda/src/physx/physxPointInPlaneJointDesc.I | 59 + .../src/physx/physxPointInPlaneJointDesc.cxx | 16 + panda/src/physx/physxPointInPlaneJointDesc.h | 46 + panda/src/physx/physxPointOnLineJoint.I | 36 + panda/src/physx/physxPointOnLineJoint.cxx | 76 + panda/src/physx/physxPointOnLineJoint.h | 79 + panda/src/physx/physxPointOnLineJointDesc.I | 59 + panda/src/physx/physxPointOnLineJointDesc.cxx | 16 + panda/src/physx/physxPointOnLineJointDesc.h | 46 + panda/src/physx/physxPrismaticJoint.I | 36 + panda/src/physx/physxPrismaticJoint.cxx | 76 + panda/src/physx/physxPrismaticJoint.h | 76 + panda/src/physx/physxPrismaticJointDesc.I | 59 + ...rHandler.I => physxPrismaticJointDesc.cxx} | 7 +- panda/src/physx/physxPrismaticJointDesc.h | 46 + panda/src/physx/physxPulleyJoint.I | 36 + panda/src/physx/physxPulleyJoint.cxx | 163 ++ panda/src/physx/physxPulleyJoint.h | 82 + panda/src/physx/physxPulleyJointDesc.I | 59 + panda/src/physx/physxPulleyJointDesc.cxx | 162 ++ panda/src/physx/physxPulleyJointDesc.h | 62 + panda/src/physx/physxRay.I | 27 +- panda/src/physx/physxRay.cxx | 138 +- panda/src/physx/physxRay.h | 39 +- panda/src/physx/physxRaycastHit.I | 36 + panda/src/physx/physxRaycastHit.cxx | 74 + panda/src/physx/physxRaycastHit.h | 51 + panda/src/physx/physxRaycastReport.I | 35 + panda/src/physx/physxRaycastReport.cxx | 89 + panda/src/physx/physxRaycastReport.h | 56 + panda/src/physx/physxRevoluteJoint.I | 36 + panda/src/physx/physxRevoluteJoint.cxx | 315 +++ panda/src/physx/physxRevoluteJoint.h | 94 + panda/src/physx/physxRevoluteJointDesc.I | 59 + panda/src/physx/physxRevoluteJointDesc.cxx | 214 ++ panda/src/physx/physxRevoluteJointDesc.h | 68 + panda/src/physx/physxScene.I | 53 +- panda/src/physx/physxScene.cxx | 2219 ++++++++++------- panda/src/physx/physxScene.h | 321 ++- panda/src/physx/physxSceneDesc.I | 316 +-- panda/src/physx/physxSceneDesc.cxx | 376 +-- panda/src/physx/physxSceneDesc.h | 90 +- panda/src/physx/physxSceneStats2.I | 58 +- panda/src/physx/physxSceneStats2.cxx | 24 +- panda/src/physx/physxSceneStats2.h | 16 +- panda/src/physx/physxSegment.I | 68 +- panda/src/physx/physxSegment.cxx | 190 +- panda/src/physx/physxSegment.h | 48 +- panda/src/physx/physxShape.I | 53 +- panda/src/physx/physxShape.cxx | 658 ++--- panda/src/physx/physxShape.h | 125 +- panda/src/physx/physxShapeDesc.I | 130 +- panda/src/physx/physxShapeDesc.cxx | 323 ++- panda/src/physx/physxShapeDesc.h | 68 +- panda/src/physx/physxSphere.I | 69 +- panda/src/physx/physxSphere.cxx | 117 +- panda/src/physx/physxSphere.h | 42 +- panda/src/physx/physxSphereForceFieldShape.I | 36 + .../src/physx/physxSphereForceFieldShape.cxx | 87 + panda/src/physx/physxSphereForceFieldShape.h | 78 + .../physx/physxSphereForceFieldShapeDesc.I | 59 + .../physx/physxSphereForceFieldShapeDesc.cxx | 38 + .../physx/physxSphereForceFieldShapeDesc.h | 49 + panda/src/physx/physxSphereShape.I | 24 +- panda/src/physx/physxSphereShape.cxx | 82 +- panda/src/physx/physxSphereShape.h | 55 +- panda/src/physx/physxSphereShapeDesc.I | 59 +- panda/src/physx/physxSphereShapeDesc.cxx | 29 +- panda/src/physx/physxSphereShapeDesc.h | 26 +- panda/src/physx/physxSphericalJoint.I | 36 + panda/src/physx/physxSphericalJoint.cxx | 133 + panda/src/physx/physxSphericalJoint.h | 84 + panda/src/physx/physxSphericalJointDesc.I | 59 + panda/src/physx/physxSphericalJointDesc.cxx | 259 ++ panda/src/physx/physxSphericalJointDesc.h | 71 + panda/src/physx/physxSpringDesc.I | 48 + panda/src/physx/physxSpringDesc.cxx | 82 + panda/src/physx/physxSpringDesc.h | 50 + panda/src/physx/physxTriangleMesh.I | 59 + panda/src/physx/physxTriangleMesh.cxx | 76 + panda/src/physx/physxTriangleMesh.h | 77 + panda/src/physx/physxTriangleMeshDesc.I | 61 + panda/src/physx/physxTriangleMeshDesc.cxx | 199 ++ panda/src/physx/physxTriangleMeshDesc.h | 56 + panda/src/physx/physxTriangleMeshShape.I | 36 + panda/src/physx/physxTriangleMeshShape.cxx | 63 + panda/src/physx/physxTriangleMeshShape.h | 74 + panda/src/physx/physxTriangleMeshShapeDesc.I | 59 + .../src/physx/physxTriangleMeshShapeDesc.cxx | 29 + panda/src/physx/physxTriangleMeshShapeDesc.h | 49 + panda/src/physx/physxTriggerHandler.cxx | 72 - panda/src/physx/physxTriggerHandler.h | 57 - panda/src/physx/physxTriggerReport.I | 36 + panda/src/physx/physxTriggerReport.cxx | 93 + panda/src/physx/physxTriggerReport.h | 48 + panda/src/physx/physxUtilLib.I | 25 +- panda/src/physx/physxUtilLib.cxx | 1621 ++++++------ panda/src/physx/physxUtilLib.h | 171 +- panda/src/physx/physxWheelShape.I | 36 + panda/src/physx/physxWheelShape.cxx | 316 +++ panda/src/physx/physxWheelShape.h | 133 + panda/src/physx/physxWheelShapeDesc.I | 59 + panda/src/physx/physxWheelShapeDesc.cxx | 202 ++ panda/src/physx/physxWheelShapeDesc.h | 65 + panda/src/physx/physx_composite.cxx | 82 +- panda/src/physx/physx_enumerations.h | 826 ------ .../physx_enumerations_for_interrogate.h | 826 ------ 357 files changed, 29810 insertions(+), 12071 deletions(-) create mode 100644 dtool/src/parser-inc/NxBoxController.h create mode 100644 dtool/src/parser-inc/NxCapsuleController.h delete mode 100644 dtool/src/parser-inc/NxCloth.h create mode 100644 dtool/src/parser-inc/NxController.h create mode 100644 dtool/src/parser-inc/NxControllerManager.h create mode 100644 dtool/src/parser-inc/NxCooking.h create mode 100644 dtool/src/parser-inc/NxExtended.h delete mode 100644 dtool/src/parser-inc/NxFluid.h create mode 100644 dtool/src/parser-inc/NxStream.h delete mode 100644 panda/src/physx/SourcesTemplate.pp delete mode 100644 panda/src/physx/createComposite.py delete mode 100644 panda/src/physx/generateCode.py create mode 100644 panda/src/physx/physxActor.I create mode 100644 panda/src/physx/physxActor.cxx create mode 100644 panda/src/physx/physxActor.h delete mode 100644 panda/src/physx/physxActorNode.I delete mode 100644 panda/src/physx/physxActorNode.cxx delete mode 100644 panda/src/physx/physxActorNode.h rename panda/src/physx/{physxJointLimitSoftPairDesc.I => physxBoxController.I} (61%) create mode 100644 panda/src/physx/physxBoxController.cxx create mode 100644 panda/src/physx/physxBoxController.h create mode 100644 panda/src/physx/physxBoxControllerDesc.I create mode 100644 panda/src/physx/physxBoxControllerDesc.cxx create mode 100644 panda/src/physx/physxBoxControllerDesc.h rename panda/src/physx/{physxTemplate.h => physxBoxForceFieldShape.I} (50%) create mode 100644 panda/src/physx/physxBoxForceFieldShape.cxx create mode 100644 panda/src/physx/physxBoxForceFieldShape.h create mode 100644 panda/src/physx/physxBoxForceFieldShapeDesc.I create mode 100644 panda/src/physx/physxBoxForceFieldShapeDesc.cxx create mode 100644 panda/src/physx/physxBoxForceFieldShapeDesc.h create mode 100644 panda/src/physx/physxCapsuleController.I create mode 100644 panda/src/physx/physxCapsuleController.cxx create mode 100644 panda/src/physx/physxCapsuleController.h create mode 100644 panda/src/physx/physxCapsuleControllerDesc.I create mode 100644 panda/src/physx/physxCapsuleControllerDesc.cxx create mode 100644 panda/src/physx/physxCapsuleControllerDesc.h create mode 100644 panda/src/physx/physxCapsuleForceFieldShape.I create mode 100644 panda/src/physx/physxCapsuleForceFieldShape.cxx create mode 100644 panda/src/physx/physxCapsuleForceFieldShape.h create mode 100644 panda/src/physx/physxCapsuleForceFieldShapeDesc.I create mode 100644 panda/src/physx/physxCapsuleForceFieldShapeDesc.cxx create mode 100644 panda/src/physx/physxCapsuleForceFieldShapeDesc.h create mode 100644 panda/src/physx/physxConstraintDominance.I create mode 100644 panda/src/physx/physxConstraintDominance.cxx create mode 100644 panda/src/physx/physxConstraintDominance.h delete mode 100644 panda/src/physx/physxContactHandler.cxx delete mode 100644 panda/src/physx/physxContactHandler.h create mode 100644 panda/src/physx/physxContactPair.I create mode 100644 panda/src/physx/physxContactPair.cxx create mode 100644 panda/src/physx/physxContactPair.h create mode 100644 panda/src/physx/physxContactPoint.I create mode 100644 panda/src/physx/physxContactPoint.cxx create mode 100644 panda/src/physx/physxContactPoint.h create mode 100644 panda/src/physx/physxContactReport.I create mode 100644 panda/src/physx/physxContactReport.cxx create mode 100644 panda/src/physx/physxContactReport.h create mode 100644 panda/src/physx/physxController.I create mode 100644 panda/src/physx/physxController.cxx create mode 100644 panda/src/physx/physxController.h rename panda/src/physx/{physxTemplate.cxx => physxControllerDesc.I} (54%) create mode 100644 panda/src/physx/physxControllerDesc.cxx create mode 100644 panda/src/physx/physxControllerDesc.h create mode 100644 panda/src/physx/physxControllerReport.I create mode 100644 panda/src/physx/physxControllerReport.cxx create mode 100644 panda/src/physx/physxControllerReport.h create mode 100644 panda/src/physx/physxConvexForceFieldShape.I create mode 100644 panda/src/physx/physxConvexForceFieldShape.cxx create mode 100644 panda/src/physx/physxConvexForceFieldShape.h create mode 100644 panda/src/physx/physxConvexForceFieldShapeDesc.I create mode 100644 panda/src/physx/physxConvexForceFieldShapeDesc.cxx create mode 100644 panda/src/physx/physxConvexForceFieldShapeDesc.h create mode 100644 panda/src/physx/physxConvexMesh.I create mode 100644 panda/src/physx/physxConvexMesh.cxx create mode 100644 panda/src/physx/physxConvexMesh.h create mode 100644 panda/src/physx/physxConvexMeshDesc.I create mode 100644 panda/src/physx/physxConvexMeshDesc.cxx create mode 100644 panda/src/physx/physxConvexMeshDesc.h create mode 100644 panda/src/physx/physxConvexShape.I create mode 100644 panda/src/physx/physxConvexShape.cxx create mode 100644 panda/src/physx/physxConvexShape.h create mode 100644 panda/src/physx/physxConvexShapeDesc.I create mode 100644 panda/src/physx/physxConvexShapeDesc.cxx create mode 100644 panda/src/physx/physxConvexShapeDesc.h create mode 100644 panda/src/physx/physxCylindricalJoint.I create mode 100644 panda/src/physx/physxCylindricalJoint.cxx create mode 100644 panda/src/physx/physxCylindricalJoint.h create mode 100644 panda/src/physx/physxCylindricalJointDesc.I rename panda/src/physx/{physxTemplate.I => physxCylindricalJointDesc.cxx} (78%) create mode 100644 panda/src/physx/physxCylindricalJointDesc.h create mode 100644 panda/src/physx/physxDebugGeomNode.I create mode 100644 panda/src/physx/physxDebugGeomNode.cxx create mode 100644 panda/src/physx/physxDebugGeomNode.h create mode 100644 panda/src/physx/physxDistanceJoint.I create mode 100644 panda/src/physx/physxDistanceJoint.cxx create mode 100644 panda/src/physx/physxDistanceJoint.h create mode 100644 panda/src/physx/physxDistanceJointDesc.I create mode 100644 panda/src/physx/physxDistanceJointDesc.cxx create mode 100644 panda/src/physx/physxDistanceJointDesc.h create mode 100644 panda/src/physx/physxEnums.cxx create mode 100644 panda/src/physx/physxEnums.h create mode 100644 panda/src/physx/physxFileStream.cxx create mode 100644 panda/src/physx/physxFileStream.h create mode 100644 panda/src/physx/physxFixedJoint.I create mode 100644 panda/src/physx/physxFixedJoint.cxx create mode 100644 panda/src/physx/physxFixedJoint.h create mode 100644 panda/src/physx/physxFixedJointDesc.I rename panda/src/physx/{physxJointHandler.I => physxFixedJointDesc.cxx} (79%) create mode 100644 panda/src/physx/physxFixedJointDesc.h create mode 100644 panda/src/physx/physxForceField.I create mode 100644 panda/src/physx/physxForceField.cxx create mode 100644 panda/src/physx/physxForceField.h create mode 100644 panda/src/physx/physxForceFieldDesc.I create mode 100644 panda/src/physx/physxForceFieldDesc.cxx create mode 100644 panda/src/physx/physxForceFieldDesc.h create mode 100644 panda/src/physx/physxForceFieldShape.I create mode 100644 panda/src/physx/physxForceFieldShape.cxx create mode 100644 panda/src/physx/physxForceFieldShape.h create mode 100644 panda/src/physx/physxForceFieldShapeDesc.I create mode 100644 panda/src/physx/physxForceFieldShapeDesc.cxx create mode 100644 panda/src/physx/physxForceFieldShapeDesc.h create mode 100644 panda/src/physx/physxForceFieldShapeGroup.I create mode 100644 panda/src/physx/physxForceFieldShapeGroup.cxx create mode 100644 panda/src/physx/physxForceFieldShapeGroup.h create mode 100644 panda/src/physx/physxForceFieldShapeGroupDesc.I create mode 100644 panda/src/physx/physxForceFieldShapeGroupDesc.cxx create mode 100644 panda/src/physx/physxForceFieldShapeGroupDesc.h create mode 100644 panda/src/physx/physxGroupsMask.I create mode 100644 panda/src/physx/physxGroupsMask.cxx create mode 100644 panda/src/physx/physxGroupsMask.h create mode 100644 panda/src/physx/physxHeightField.I create mode 100644 panda/src/physx/physxHeightField.cxx create mode 100644 panda/src/physx/physxHeightField.h create mode 100644 panda/src/physx/physxHeightFieldDesc.I create mode 100644 panda/src/physx/physxHeightFieldDesc.cxx create mode 100644 panda/src/physx/physxHeightFieldDesc.h create mode 100644 panda/src/physx/physxHeightFieldShape.I create mode 100644 panda/src/physx/physxHeightFieldShape.cxx create mode 100644 panda/src/physx/physxHeightFieldShape.h create mode 100644 panda/src/physx/physxHeightFieldShapeDesc.I create mode 100644 panda/src/physx/physxHeightFieldShapeDesc.cxx create mode 100644 panda/src/physx/physxHeightFieldShapeDesc.h delete mode 100644 panda/src/physx/physxJointHandler.cxx delete mode 100644 panda/src/physx/physxJointHandler.h create mode 100644 panda/src/physx/physxJointLimitDesc.I create mode 100644 panda/src/physx/physxJointLimitDesc.cxx create mode 100644 panda/src/physx/physxJointLimitDesc.h delete mode 100644 panda/src/physx/physxJointLimitSoftPairDesc.cxx delete mode 100644 panda/src/physx/physxJointLimitSoftPairDesc.h create mode 100644 panda/src/physx/physxKitchen.I create mode 100644 panda/src/physx/physxKitchen.cxx create mode 100644 panda/src/physx/physxKitchen.h create mode 100644 panda/src/physx/physxMask.I create mode 100644 panda/src/physx/physxMask.cxx create mode 100644 panda/src/physx/physxMask.h create mode 100644 panda/src/physx/physxMemoryReadBuffer.cxx create mode 100644 panda/src/physx/physxMemoryReadBuffer.h create mode 100644 panda/src/physx/physxMemoryWriteBuffer.cxx create mode 100644 panda/src/physx/physxMemoryWriteBuffer.h create mode 100644 panda/src/physx/physxMeshPool.I create mode 100644 panda/src/physx/physxMeshPool.cxx create mode 100644 panda/src/physx/physxMeshPool.h create mode 100644 panda/src/physx/physxMotorDesc.I create mode 100644 panda/src/physx/physxMotorDesc.cxx create mode 100644 panda/src/physx/physxMotorDesc.h create mode 100644 panda/src/physx/physxObject.I create mode 100644 panda/src/physx/physxObject.cxx create mode 100644 panda/src/physx/physxObject.h create mode 100644 panda/src/physx/physxObjectCollection.I rename panda/src/physx/{physxContactHandler.I => physxObjectCollection.cxx} (79%) create mode 100644 panda/src/physx/physxObjectCollection.h create mode 100644 panda/src/physx/physxOverlapReport.I create mode 100644 panda/src/physx/physxOverlapReport.cxx create mode 100644 panda/src/physx/physxOverlapReport.h create mode 100644 panda/src/physx/physxPointInPlaneJoint.I create mode 100644 panda/src/physx/physxPointInPlaneJoint.cxx create mode 100644 panda/src/physx/physxPointInPlaneJoint.h create mode 100644 panda/src/physx/physxPointInPlaneJointDesc.I create mode 100644 panda/src/physx/physxPointInPlaneJointDesc.cxx create mode 100644 panda/src/physx/physxPointInPlaneJointDesc.h create mode 100644 panda/src/physx/physxPointOnLineJoint.I create mode 100644 panda/src/physx/physxPointOnLineJoint.cxx create mode 100644 panda/src/physx/physxPointOnLineJoint.h create mode 100644 panda/src/physx/physxPointOnLineJointDesc.I create mode 100644 panda/src/physx/physxPointOnLineJointDesc.cxx create mode 100644 panda/src/physx/physxPointOnLineJointDesc.h create mode 100644 panda/src/physx/physxPrismaticJoint.I create mode 100644 panda/src/physx/physxPrismaticJoint.cxx create mode 100644 panda/src/physx/physxPrismaticJoint.h create mode 100644 panda/src/physx/physxPrismaticJointDesc.I rename panda/src/physx/{physxTriggerHandler.I => physxPrismaticJointDesc.cxx} (79%) create mode 100644 panda/src/physx/physxPrismaticJointDesc.h create mode 100644 panda/src/physx/physxPulleyJoint.I create mode 100644 panda/src/physx/physxPulleyJoint.cxx create mode 100644 panda/src/physx/physxPulleyJoint.h create mode 100644 panda/src/physx/physxPulleyJointDesc.I create mode 100644 panda/src/physx/physxPulleyJointDesc.cxx create mode 100644 panda/src/physx/physxPulleyJointDesc.h create mode 100644 panda/src/physx/physxRaycastHit.I create mode 100644 panda/src/physx/physxRaycastHit.cxx create mode 100644 panda/src/physx/physxRaycastHit.h create mode 100644 panda/src/physx/physxRaycastReport.I create mode 100644 panda/src/physx/physxRaycastReport.cxx create mode 100644 panda/src/physx/physxRaycastReport.h create mode 100644 panda/src/physx/physxRevoluteJoint.I create mode 100644 panda/src/physx/physxRevoluteJoint.cxx create mode 100644 panda/src/physx/physxRevoluteJoint.h create mode 100644 panda/src/physx/physxRevoluteJointDesc.I create mode 100644 panda/src/physx/physxRevoluteJointDesc.cxx create mode 100644 panda/src/physx/physxRevoluteJointDesc.h create mode 100644 panda/src/physx/physxSphereForceFieldShape.I create mode 100644 panda/src/physx/physxSphereForceFieldShape.cxx create mode 100644 panda/src/physx/physxSphereForceFieldShape.h create mode 100644 panda/src/physx/physxSphereForceFieldShapeDesc.I create mode 100644 panda/src/physx/physxSphereForceFieldShapeDesc.cxx create mode 100644 panda/src/physx/physxSphereForceFieldShapeDesc.h create mode 100644 panda/src/physx/physxSphericalJoint.I create mode 100644 panda/src/physx/physxSphericalJoint.cxx create mode 100644 panda/src/physx/physxSphericalJoint.h create mode 100644 panda/src/physx/physxSphericalJointDesc.I create mode 100644 panda/src/physx/physxSphericalJointDesc.cxx create mode 100644 panda/src/physx/physxSphericalJointDesc.h create mode 100644 panda/src/physx/physxSpringDesc.I create mode 100644 panda/src/physx/physxSpringDesc.cxx create mode 100644 panda/src/physx/physxSpringDesc.h create mode 100644 panda/src/physx/physxTriangleMesh.I create mode 100644 panda/src/physx/physxTriangleMesh.cxx create mode 100644 panda/src/physx/physxTriangleMesh.h create mode 100644 panda/src/physx/physxTriangleMeshDesc.I create mode 100644 panda/src/physx/physxTriangleMeshDesc.cxx create mode 100644 panda/src/physx/physxTriangleMeshDesc.h create mode 100644 panda/src/physx/physxTriangleMeshShape.I create mode 100644 panda/src/physx/physxTriangleMeshShape.cxx create mode 100644 panda/src/physx/physxTriangleMeshShape.h create mode 100644 panda/src/physx/physxTriangleMeshShapeDesc.I create mode 100644 panda/src/physx/physxTriangleMeshShapeDesc.cxx create mode 100644 panda/src/physx/physxTriangleMeshShapeDesc.h delete mode 100644 panda/src/physx/physxTriggerHandler.cxx delete mode 100644 panda/src/physx/physxTriggerHandler.h create mode 100644 panda/src/physx/physxTriggerReport.I create mode 100644 panda/src/physx/physxTriggerReport.cxx create mode 100644 panda/src/physx/physxTriggerReport.h create mode 100644 panda/src/physx/physxWheelShape.I create mode 100644 panda/src/physx/physxWheelShape.cxx create mode 100644 panda/src/physx/physxWheelShape.h create mode 100644 panda/src/physx/physxWheelShapeDesc.I create mode 100644 panda/src/physx/physxWheelShapeDesc.cxx create mode 100644 panda/src/physx/physxWheelShapeDesc.h delete mode 100644 panda/src/physx/physx_enumerations.h delete mode 100644 panda/src/physx/physx_enumerations_for_interrogate.h diff --git a/dtool/src/parser-inc/NxBoxController.h b/dtool/src/parser-inc/NxBoxController.h new file mode 100644 index 0000000000..bf826a945a --- /dev/null +++ b/dtool/src/parser-inc/NxBoxController.h @@ -0,0 +1,28 @@ +// Filename: NxBoxController.h +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +// This file, and all the other files in this directory, aren't +// intended to be compiled--they're just parsed by CPPParser (and +// interrogate) in lieu of the actual system headers, to generate the +// interrogate database. + +#ifndef NXBOXCONTROLLER_H +#define NXBOXCONTROLLER_H + +class NxBoxController; +class NxBoxControllerDesc; +class NxControllerDesc; +class NxController; + +#endif // NXBOXCONTROLLER_H diff --git a/dtool/src/parser-inc/NxCapsuleController.h b/dtool/src/parser-inc/NxCapsuleController.h new file mode 100644 index 0000000000..a3e3bfc66c --- /dev/null +++ b/dtool/src/parser-inc/NxCapsuleController.h @@ -0,0 +1,28 @@ +// Filename: NxCapsuleController.h +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +// This file, and all the other files in this directory, aren't +// intended to be compiled--they're just parsed by CPPParser (and +// interrogate) in lieu of the actual system headers, to generate the +// interrogate database. + +#ifndef NXCAPSULECONTROLLER_H +#define NXCAPSULECONTROLLER_H + +class NxCapsuleController; +class NxCapsuleControllerDesc; +class NxControllerDesc; +class NxController; + +#endif // NXCAPSULECONTROLLER_H diff --git a/dtool/src/parser-inc/NxCloth.h b/dtool/src/parser-inc/NxCloth.h deleted file mode 100644 index ff35c16564..0000000000 --- a/dtool/src/parser-inc/NxCloth.h +++ /dev/null @@ -1,2 +0,0 @@ -#undef NX_USE_CLOTH_API -#define NX_USE_CLOTH_API false diff --git a/dtool/src/parser-inc/NxController.h b/dtool/src/parser-inc/NxController.h new file mode 100644 index 0000000000..6fd5d7fff3 --- /dev/null +++ b/dtool/src/parser-inc/NxController.h @@ -0,0 +1,30 @@ +// Filename: NxController.h +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +// This file, and all the other files in this directory, aren't +// intended to be compiled--they're just parsed by CPPParser (and +// interrogate) in lieu of the actual system headers, to generate the +// interrogate database. + +#ifndef NXCONTROLLER_H +#define NXCONTROLLER_H + +class NxController; +class NxControllerDesc; +class NxUserControllerHitReport; +class NxControllerShapeHit; +class NxControllersHit; +class NxControllerAction; + +#endif // NXCONTROLLER_H diff --git a/dtool/src/parser-inc/NxControllerManager.h b/dtool/src/parser-inc/NxControllerManager.h new file mode 100644 index 0000000000..2b6e92e8fd --- /dev/null +++ b/dtool/src/parser-inc/NxControllerManager.h @@ -0,0 +1,25 @@ +// Filename: NxControllerManager.h +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +// This file, and all the other files in this directory, aren't +// intended to be compiled--they're just parsed by CPPParser (and +// interrogate) in lieu of the actual system headers, to generate the +// interrogate database. + +#ifndef NXCONTROLLERMANAGER_H +#define NXCONTROLLERMANAGER_H + +class NxControllerManager; + +#endif // NXCONTROLLERMANAGER_H diff --git a/dtool/src/parser-inc/NxCooking.h b/dtool/src/parser-inc/NxCooking.h new file mode 100644 index 0000000000..a7cacab1eb --- /dev/null +++ b/dtool/src/parser-inc/NxCooking.h @@ -0,0 +1,25 @@ +// Filename: NxCooking.h +// Created by: enn0x (12Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +// This file, and all the other files in this directory, aren't +// intended to be compiled--they're just parsed by CPPParser (and +// interrogate) in lieu of the actual system headers, to generate the +// interrogate database. + +#ifndef NX_COOKING_H +#define NX_COOKING_H + +class NxCookingInterface; + +#endif // NX_COOKING_H diff --git a/dtool/src/parser-inc/NxExtended.h b/dtool/src/parser-inc/NxExtended.h new file mode 100644 index 0000000000..e23ff0dc51 --- /dev/null +++ b/dtool/src/parser-inc/NxExtended.h @@ -0,0 +1,25 @@ +// Filename: NxExtended.h +// Created by: enn0x (02Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +// This file, and all the other files in this directory, aren't +// intended to be compiled--they're just parsed by CPPParser (and +// interrogate) in lieu of the actual system headers, to generate the +// interrogate database. + +#ifndef NXEXTENDED_H +#define NXEXTENDED_H + +class NxExtendedVec3; + +#endif // NXEXTENDED_H diff --git a/dtool/src/parser-inc/NxFluid.h b/dtool/src/parser-inc/NxFluid.h deleted file mode 100644 index c7b9d9206e..0000000000 --- a/dtool/src/parser-inc/NxFluid.h +++ /dev/null @@ -1,2 +0,0 @@ -#undef NX_USE_FLUID_API -#define NX_USE_FLUID_API false diff --git a/dtool/src/parser-inc/NxPhysics.h b/dtool/src/parser-inc/NxPhysics.h index 764c90a290..950c3c19c7 100644 --- a/dtool/src/parser-inc/NxPhysics.h +++ b/dtool/src/parser-inc/NxPhysics.h @@ -1,5 +1,5 @@ // Filename: NxPhysics.h -// Created by: pratt (Apr 26, 2006) +// Created by: enn0x (02Sep09) // //////////////////////////////////////////////////////////////////// // @@ -20,151 +20,129 @@ #ifndef NXPHYSICS_H #define NXPHYSICS_H -#define NX_CALL_CONV +class NxActor; +class NxActorDesc; +class NxBodyDesc; +class NxBoxForceFieldShape; +class NxBoxForceFieldShapeDesc; +class NxBoxShape; +class NxBoxShapeDesc; +class NxCapsuleForceFieldShape; +class NxCapsuleForceFieldShapeDesc; +class NxCapsuleShape; +class NxCapsuleShapeDesc; +class NxConvexMesh; +class NxConvexMeshDesc; +class NxConvexForceFieldShape; +class NxConvexForceFieldShapeDesc; +class NxConvexShape; +class NxConvexShapeDesc; +class NxForceField; +class NxForceFieldDesc; +class NxForceFieldLinearKernelDesc; +class NxForceFieldLinearKernel; +class NxForceFieldShape; +class NxForceFieldShapeDesc; +class NxForceFieldShapeGroup; +class NxForceFieldShapeGroupDesc; +class NxHeightFieldShape; +class NxHeightFieldShapeDesc; +class NxHeightField; +class NxHeightFieldDesc; +class NxHeightFieldSample; +class NxMaterial; +class NxMaterialDesc; +class NxPlaneShape; +class NxPlaneShapeDesc; +class NxPhysicsSDK; +class NxRay; +class NxRaycastHit; +class NxScene; +class NxSceneDesc; +class NxShape; +class NxShapeDesc; +class NxSphereForceFieldShape; +class NxSphereForceFieldShapeDesc; +class NxSphereShape; +class NxSphereShapeDesc; +class NxTriangleMesh; +class NxTriangleMeshDesc; +class NxTriangleMeshShape; +class NxTriangleMeshShapeDesc; +class NxJointDesc; +class NxCylindricalJointDesc; +class NxD6JointDesc; +class NxDistanceJointDesc; +class NxFixedJointDesc; +class NxPointInPlaneJointDesc; +class NxPointOnLineJointDesc; +class NxPrismaticJointDesc; +class NxPulleyJointDesc; +class NxRevoluteJointDesc; +class NxSphericalJointDesc; +class NxJoint; +class NxCylindricalJoint; +class NxD6Joint; +class NxDistanceJoint; +class NxFixedJoint; +class NxPointInPlaneJoint; +class NxPointOnLineJoint; +class NxPrismaticJoint; +class NxPulleyJoint; +class NxRevoluteJoint; +class NxSphericalJoint; +class NxMotorDesc; +class NxSpringDesc; +class NxJointLimitDesc; +class NxJointLimitPairDesc; +class NxJointLimitSoftDesc; +class NxJointLimitSoftPairDesc; +class NxJointDriveDesc; +class NxUserRaycastReport; +class NxBounds3; +class NxWheelShape; +class NxWheelShapeDesc; +class NxContactPair; +class NxUserContactReport; +class NxCloth; +class NxClothDesc; +class NxClothMesh; +class NxClothMeshDesc; +class NxMeshData; +class NxConstraintDominance; +class NxRemoteDebugger; +class NxGroupsMask; +class NxSceneStats2; +class NxSoftBody; +class NxSoftBodyDesc; +class NxSoftBodyMesh; +class NxSoftBodyMeshDesc; -#include "NxFoundation.h" //include the all of the foundation SDK +enum NxSDKCreateError; +enum NxAssertResponse; +enum NxErrorCode; +enum NxTriggerFlag; +enum NxHeightFieldAxis; +template class NxUserEntityReport; -//////////////general: - -#include "NxScene.h" -#include "NxSceneDesc.h" - -#include "NxActor.h" -#include "NxActorDesc.h" - -#include "NxMaterial.h" -#include "NxMaterialDesc.h" - -#include "NxContactStreamIterator.h" - -#include "NxUserContactReport.h" -#include "NxUserNotify.h" -#include "NxUserRaycastReport.h" -#include "NxUserEntityReport.h" - -#include "NxBodyDesc.h" - -#include "NxEffector.h" - -#include "NxSpringAndDamperEffector.h" -#include "NxSpringAndDamperEffectorDesc.h" - -#include "NxScheduler.h" - -//#if NX_USE_FLUID_API -//#include "fluids/NxFluid.h" -//#include "fluids/NxFluidDesc.h" -//#include "fluids/NxFluidEmitter.h" -//#include "fluids/NxFluidEmitterDesc.h" -//#endif -// -//#if NX_USE_CLOTH_API -//#include "cloth/NxCloth.h" -//#include "cloth/NxClothDesc.h" -//#endif - -#include "NxCCDSkeleton.h" -#include "NxTriangle.h" -#include "NxScheduler.h" -#include "NxSceneStats.h" -#include "NxSceneStats2.h" -/////////////joints: - -#include "NxJoint.h" - -#include "NxJointLimitDesc.h" -#include "NxJointLimitPairDesc.h" -#include "NxMotorDesc.h" -#include "NxSpringDesc.h" - -#include "NxPointInPlaneJoint.h" -#include "NxPointInPlaneJointDesc.h" - -#include "NxPointOnLineJoint.h" -#include "NxPointOnLineJointDesc.h" - -#include "NxRevoluteJoint.h" -#include "NxRevoluteJointDesc.h" - -#include "NxPrismaticJoint.h" -#include "NxPrismaticJointDesc.h" - -#include "NxCylindricalJoint.h" -#include "NxCylindricalJointDesc.h" - -#include "NxSphericalJoint.h" -#include "NxSphericalJointDesc.h" - -#include "NxFixedJoint.h" -#include "NxFixedJointDesc.h" - -#include "NxDistanceJoint.h" -#include "NxDistanceJointDesc.h" - -#include "NxPulleyJoint.h" -#include "NxPulleyJointDesc.h" - -#include "NxD6Joint.h" -#include "NxD6JointDesc.h" - -//////////////shapes: - -#include "NxShape.h" -#include "NxShapeDesc.h" - -#include "NxBoxShape.h" -#include "NxBoxShapeDesc.h" - -#include "NxCapsuleShape.h" -#include "NxCapsuleShapeDesc.h" - -#include "NxPlaneShape.h" -#include "NxPlaneShapeDesc.h" - -#include "NxSphereShape.h" -#include "NxSphereShapeDesc.h" - -#include "NxTriangleMesh.h" -#include "NxTriangleMeshDesc.h" - -#include "NxTriangleMeshShape.h" -#include "NxTriangleMeshShapeDesc.h" - -#include "NxConvexMesh.h" -#include "NxConvexMeshDesc.h" - -#include "NxConvexShape.h" -#include "NxConvexShapeDesc.h" - -#include "NxHeightField.h" -#include "NxHeightFieldDesc.h" - -#include "NxHeightFieldShape.h" -#include "NxHeightFieldShapeDesc.h" -#include "NxHeightFieldSample.h" - -#include "NxWheelShape.h" -#include "NxWheelShapeDesc.h" -//////////////utils: - -#include "NxInertiaTensor.h" -#include "NxIntersectionBoxBox.h" -#include "NxIntersectionPointTriangle.h" -#include "NxIntersectionRayPlane.h" -#include "NxIntersectionRaySphere.h" -#include "NxIntersectionRayTriangle.h" -#include "NxIntersectionSegmentBox.h" -#include "NxIntersectionSegmentCapsule.h" -#include "NxIntersectionSweptSpheres.h" -#include "NxPMap.h" -#include "NxSmoothNormals.h" -#include "NxConvexHull.h" -#include "NxAllocateable.h" -#include "NxExportedUtils.h" - -#include "PhysXLoader.h" +class NxU8; +class NxU16; +class NxU32; +class NxI32; +class NxReal; +class NxF32; +class NxVec3; +class NxMat33; +class NxMat34; +class NxQuat; +class NxBox; +class NxSphere; +class NxSegment; +class NxCapsule; +class NxPlane; +class NxUtilLib; #endif // NXPHYSICS_H diff --git a/dtool/src/parser-inc/NxStream.h b/dtool/src/parser-inc/NxStream.h new file mode 100644 index 0000000000..cd80eab090 --- /dev/null +++ b/dtool/src/parser-inc/NxStream.h @@ -0,0 +1,25 @@ +// Filename: NxStream.h +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +// This file, and all the other files in this directory, aren't +// intended to be compiled--they're just parsed by CPPParser (and +// interrogate) in lieu of the actual system headers, to generate the +// interrogate database. + +#ifndef NX_STREAM_H +#define NX_STREAM_H + +class NxStream; + +#endif // NX_STREAM_H diff --git a/dtool/src/parser-inc/Sources.pp b/dtool/src/parser-inc/Sources.pp index 942131c60f..29185b94e9 100644 --- a/dtool/src/parser-inc/Sources.pp +++ b/dtool/src/parser-inc/Sources.pp @@ -14,7 +14,9 @@ intfloat_readwrite.h mathematics.h rational.h rtp.h \ rtsp.h rtspcodes.h setjmp.h tinyxml.h winsock2.h \ ode/ode.h collision_trimesh.h artools.h \ - NxPhysics.h cloth/NxCloth.h fluids/NxFluid.h \ + NxBoxController.h NxCapsuleController.h NxController.h \ + NxControllerManager.h NxCooking.h NxExtended.h \ + NxPhysics.h NxStream.h \ netinet/tcp.h netinet/ip.h sys/socket.h \ rfftw.h libtar.h malloc.h ucontext.h ctype.h \ libavutil/avutil.h libavformat/avformat.h \ diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 4e3f7fe427..b233f4bb14 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -54,7 +54,7 @@ PkgListSet(MAYAVERSIONS + MAXVERSIONS + DXVERSIONS + [ "FMODEX","OPENAL","NVIDIACG","OPENSSL","FREETYPE","WX", "FFTW","ARTOOLKIT","SQUISH","ODE","DIRECTCAM","NPAPI", "OPENCV","FFMPEG","SWSCALE","FCOLLADA","GTK2","PANDATOOL", - "OPENGL","X11","XF86DGA", + "OPENGL","X11","XF86DGA","PHYSX", ]) CheckPandaSourceTree() @@ -262,10 +262,12 @@ SdkLocateMacOSX(OSXTARGET) SdkLocatePython(RTDIST) SdkLocateVisualStudio() SdkLocateMSPlatform() +SdkLocatePhysX() SdkAutoDisableDirectX() SdkAutoDisableMaya() SdkAutoDisableMax() +SdkAutoDisablePhysX() if (RTDIST and SDK["PYTHONVERSION"] != "python2.6" and DISTRIBUTOR == "cmu"): exit("The CMU rtdist distribution must be built against Python 2.6!") @@ -406,6 +408,19 @@ if (COMPILER=="MSVC"): LibName(pkg, SDK[pkg] + '/lib/mesh.lib') LibName(pkg, SDK[pkg] + '/lib/maxutil.lib') LibName(pkg, SDK[pkg] + '/lib/paramblk2.lib') + if (PkgSkip("PHYSX")==0): + DefSymbol("PHYSX", SDK["PHYSXVERSION"], "1") + DefSymbol("PHYSX", "NX32", "1") + LibName("PHYSX", SDK["PHYSX"] + "/lib/Win32/PhysXLoader.lib") + LibName("PHYSX", SDK["PHYSX"] + "/lib/Win32/NxCharacter.lib") + IncDirectory("PHYSX", SDK["PHYSX"] + "/Physics/include") + IncDirectory("PHYSX", SDK["PHYSX"] + "/PhysXLoader/include") + IncDirectory("PHYSX", SDK["PHYSX"] + "/NxCharacter/include") + IncDirectory("PHYSX", SDK["PHYSX"] + "/NxExtensions/include") + IncDirectory("PHYSX", SDK["PHYSX"] + "/Foundation/include") + IncDirectory("PHYSX", SDK["PHYSX"] + "/Cooking/include") + # We need to be able to find NxCharacter.dll when importing code library libpandaphysx + AddToPathEnv("PATH", SDK["PHYSX"]+"/../Bin/win32/") if (COMPILER=="LINUX"): if (PkgSkip("PYTHON")==0): @@ -528,6 +543,21 @@ if (COMPILER=="LINUX"): LibName(pkg, "-lIMFbase") if (sys.platform == "darwin"): LibName(pkg, "-dylib_file /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib") + if (PkgSkip("PHYSX")==0): + DefSymbol("PHYSX", SDK["PHYSXVERSION"], "1") + DefSymbol("PHYSX", "LINUX", "1") + DefSymbol("PHYSX", "CORELIB", "1") + DefSymbol("PHYSX", "NX_DISABLE_FLUIDS", "1") + DefSymbol("PHYSX", "NX32", "1") + IncDirectory("PHYSX", SDK["PHYSX"] + "/Physics/include") + IncDirectory("PHYSX", SDK["PHYSX"] + "/PhysXLoader/include") + IncDirectory("PHYSX", SDK["PHYSX"] + "/NxCharacter/include") + IncDirectory("PHYSX", SDK["PHYSX"] + "/NxExtensions/include") + IncDirectory("PHYSX", SDK["PHYSX"] + "/Foundation/include") + IncDirectory("PHYSX", SDK["PHYSX"] + "/Cooking/include") + LibDirectory("PHYSX", SDK["PHYSXLIBS"]) + LibName("PHYSX", "-lPhysXLoader") + LibName("PHYSX", "-lNxCharacter") DefSymbol("ALWAYS", "MAKEPANDA", "") DefSymbol("WITHINPANDA", "WITHIN_PANDA", "1") @@ -1872,6 +1902,10 @@ if (PkgSkip("PANDATOOL")==0): CopyAllHeaders('pandatool/src/win-stats') CopyAllHeaders('pandatool/src/xfileprogs') +if (PkgSkip("PHYSX")==0): + CopyAllHeaders('panda/src/physx') + CopyAllHeaders('panda/metalibs/pandaphysx') + ######################################################################## # # These definitions are syntactic shorthand. They make it easy @@ -3095,6 +3129,37 @@ if (PkgSkip("ODE")==0 and not RUNTIME): TargetAdd('libpandaode.dll', input=COMMON_PANDA_LIBS) TargetAdd('libpandaode.dll', opts=['WINUSER', 'ODE']) +# +# DIRECTORY: panda/src/physx/ +# + +if (PkgSkip("PHYSX")==0): + OPTS=['DIR:panda/src/physx', 'BUILDING:PANDAPHYSX', 'PHYSX'] + TargetAdd('physx_composite.obj', opts=OPTS, input='physx_composite.cxx') + IGATEFILES=GetDirectoryContents('panda/src/physx', ["*.h", "*_composite.cxx"]) + TargetAdd('libpandaphysx.in', opts=OPTS, input=IGATEFILES) + TargetAdd('libpandaphysx.in', opts=['IMOD:pandaphysx', 'ILIB:libpandaphysx', 'SRCDIR:panda/src/physx']) + TargetAdd('libpandaphysx_igate.obj', input='libpandaphysx.in', opts=["DEPENDENCYONLY"]) + +# +# DIRECTORY: panda/metalibs/pandaphysx/ +# + +if (PkgSkip("PHYSX")==0): + OPTS=['DIR:panda/metalibs/pandaphysx', 'BUILDING:PANDAPHYSX', 'PHYSX'] + TargetAdd('pandaphysx_pandaphysx.obj', opts=OPTS, input='pandaphysx.cxx') + + TargetAdd('libpandaphysx_module.obj', input='libpandaphysx.in') + TargetAdd('libpandaphysx_module.obj', opts=OPTS) + TargetAdd('libpandaphysx_module.obj', opts=['IMOD:pandaphysx', 'ILIB:libpandaphysx']) + + TargetAdd('libpandaphysx.dll', input='pandaphysx_pandaphysx.obj') + TargetAdd('libpandaphysx.dll', input='libpandaphysx_module.obj') + TargetAdd('libpandaphysx.dll', input='physx_composite.obj') + TargetAdd('libpandaphysx.dll', input='libpandaphysx_igate.obj') + TargetAdd('libpandaphysx.dll', input=COMMON_PANDA_LIBS) + TargetAdd('libpandaphysx.dll', opts=['WINUSER', 'PHYSX']) + # # DIRECTORY: panda/src/physics/ # @@ -4382,6 +4447,8 @@ if (PkgSkip("PYTHON")==0): TargetAdd('PandaModules.py', input='libpandaegg.dll') if (PkgSkip("ODE")==0): TargetAdd('PandaModules.py', input='libpandaode.dll') + if (PkgSkip("PHYSX")==0): + TargetAdd('PandaModules.py', input='libpandaphysx.dll') # # Generate the models directory and samples directory diff --git a/makepanda/makepandacore.py b/makepanda/makepandacore.py index 21c16d20c6..f9745b51b4 100644 --- a/makepanda/makepandacore.py +++ b/makepanda/makepandacore.py @@ -574,6 +574,19 @@ def ListRegistryKeys(path): _winreg.CloseKey(key) return result +def ListRegistryValues(path): + result = [] + index = 0 + key = TryRegistryKey(path) + if (key != 0): + try: + while (1): + result.append(_winreg.EnumValue(key, index)[0]) + index = index + 1 + except: pass + _winreg.CloseKey(key) + return result + def GetRegistryKey(path, subkey): if (platform.architecture()[0]=="64bit"): path = path.replace("SOFTWARE\\", "SOFTWARE\\Wow6432Node\\") @@ -1399,6 +1412,27 @@ def SdkLocateMacOSX(osxtarget=None): else: SDK["MACOSX"] = "" +PHYSXVERSIONINFO=[ + ("PHYSX281","v2.8.1"), + ("PHYSX283","v2.8.3"), +] + +def SdkLocatePhysX(): + for (ver,key) in PHYSXVERSIONINFO: + if (sys.platform == "win32"): + folders = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\Folders" + for folder in ListRegistryValues(folders): + if folder.endswith("NVIDIA PhysX SDK\\%s\\SDKs\\" % key): + SDK["PHYSX"] = folder + SDK["PHYSXVERSION"] = ver + elif (sys.platform.startswith("linux")): + incpath = "/usr/include/PhysX/%s/SDKs" % key + libpath = "/usr/lib/PhysX/%s" % key + if (os.path.isdir(incpath) and os.path.isdir(libpath)): + SDK["PHYSX"] = incpath + SDK["PHYSXVERSION"] = ver + SDK["PHYSXLIBS"] = libpath + ######################################################################## ## ## SDK Auto-Disables @@ -1439,6 +1473,12 @@ def SdkAutoDisableMax(): WARNINGS.append("I have automatically added this command-line option: --no-"+version.lower()) PkgDisable(version) +def SdkAutoDisablePhysX(): + if ("PHYSX" not in SDK) and (PkgSkip("PHYSX")==0): + PkgDisable("PHYSX") + WARNINGS.append("I cannot locate SDK for PhysX") + WARNINGS.append("I have automatically added this command-line option: --no-physx") + ######################################################################## ## ## Visual Studio comes with a script called VSVARS32.BAT, which diff --git a/panda/metalibs/pandaphysx/Sources.pp b/panda/metalibs/pandaphysx/Sources.pp index 55620581a7..00cccb2155 100644 --- a/panda/metalibs/pandaphysx/Sources.pp +++ b/panda/metalibs/pandaphysx/Sources.pp @@ -5,24 +5,28 @@ // under Windows). #define DIR_TYPE metalib -#define BUILDING_DLL BUILDING_PANDAPHYSX #define BUILD_DIRECTORY $[HAVE_PHYSX] +#define BUILDING_DLL BUILDING_PANDAPHYSX -#if $[eq $[LINK_IN_PHYSX],] - // We don't have any components if we're linking the Physics library - // directly into Panda. - #define COMPONENT_LIBS \ - physx -#endif +#define COMPONENT_LIBS \ + physx -#define LOCAL_LIBS linmath putil express -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolbase:c dtoolutil:c dtool:m prc:c +#define LOCAL_LIBS \ + linmath \ + putil \ + express + +#define OTHER_LIBS \ + interrogatedb:c \ + dconfig:c \ + dtoolconfig:m \ + dtoolbase:c \ + dtoolutil:c \ + dtool:m \ + prc:c #begin metalib_target - #define TARGET pandaphysx - - #define SOURCES pandaphysx.cxx pandaphysx.h - #define INSTALL_HEADERS pandaphysx.h - + #define TARGET pandaphysx + #define SOURCES pandaphysx.cxx pandaphysx.h + #define INSTALL_HEADERS pandaphysx.h #end metalib_target diff --git a/panda/metalibs/pandaphysx/pandaphysx.cxx b/panda/metalibs/pandaphysx/pandaphysx.cxx index 4cfe3c6084..a480b65fdb 100644 --- a/panda/metalibs/pandaphysx/pandaphysx.cxx +++ b/panda/metalibs/pandaphysx/pandaphysx.cxx @@ -1,13 +1,10 @@ // Filename: pandaphysx.cxx -// Created by: pratt (Apr 20, 2006) +// Created by: pratt (20Apr2006) // //////////////////////////////////////////////////////////////////// #include "pandaphysx.h" - -#ifndef LINK_IN_PHYSX #include "config_physx.h" -#endif // By including checkPandaVersion.h, we guarantee that runtime // attempts to load libpandaphysx.so/.dll will fail if they @@ -25,7 +22,5 @@ //////////////////////////////////////////////////////////////////// void init_libpandaphysx() { -#ifndef LINK_IN_PHYSX init_libphysx(); -#endif } diff --git a/panda/metalibs/pandaphysx/pandaphysx.h b/panda/metalibs/pandaphysx/pandaphysx.h index 25b8bc2c8c..1cdaa1a4be 100644 --- a/panda/metalibs/pandaphysx/pandaphysx.h +++ b/panda/metalibs/pandaphysx/pandaphysx.h @@ -1,5 +1,5 @@ // Filename: pandaphysx.h -// Created by: pratt (Apr 20, 2006) +// Created by: pratt (20Apr2006) // //////////////////////////////////////////////////////////////////// diff --git a/panda/src/physx/NoMinMax.h b/panda/src/physx/NoMinMax.h index 0ec4927d2c..52eec8521f 100644 --- a/panda/src/physx/NoMinMax.h +++ b/panda/src/physx/NoMinMax.h @@ -1,5 +1,5 @@ // Filename: NoMinMax.h -// Created by: pratt (Apr 26, 2006) +// Created by: pratt (26Apr2006) // //////////////////////////////////////////////////////////////////// // diff --git a/panda/src/physx/Sources.pp b/panda/src/physx/Sources.pp index df379fd50c..9d01560a20 100644 --- a/panda/src/physx/Sources.pp +++ b/panda/src/physx/Sources.pp @@ -9,130 +9,342 @@ #define USE_PACKAGES physx #define LOCAL_LIBS pgraph linmath #define COMBINED_SOURCES $[TARGET]_composite.cxx - #define INTERROGATE_OPTIONS $[INTERROGATE_OPTIONS] -DHAVE_PHYSX + #define INTERROGATE_OPTIONS $[INTERROGATE_OPTIONS] #define SOURCES \ NoMinMax.h \ - config_physx.h \ - physxManager.I physxManager.h \ - physxContactHandler.I physxContactHandler.h \ - physxTriggerHandler.I physxTriggerHandler.h \ - physxJointHandler.I physxJointHandler.h \ - physxActorNode.I physxActorNode.h \ + config_physx.h \ + physxActor.I physxActor.h \ physxActorDesc.I physxActorDesc.h \ physxBodyDesc.I physxBodyDesc.h \ physxBounds3.I physxBounds3.h \ physxBox.I physxBox.h \ - physxJoint.I physxJoint.h \ + physxBoxController.I physxBoxController.h \ + physxBoxControllerDesc.I physxBoxControllerDesc.h \ + physxBoxForceFieldShape.I physxBoxForceFieldShape.h \ + physxBoxForceFieldShapeDesc.I physxBoxForceFieldShapeDesc.h \ + physxBoxShape.I physxBoxShape.h \ + physxBoxShapeDesc.I physxBoxShapeDesc.h \ + physxCapsule.I physxCapsule.h \ + physxCapsuleController.I physxCapsuleController.h \ + physxCapsuleControllerDesc.I physxCapsuleControllerDesc.h \ + physxCapsuleForceFieldShape.I physxCapsuleForceFieldShape.h \ + physxCapsuleForceFieldShapeDesc.I physxCapsuleForceFieldShapeDesc.h \ + physxCapsuleShape.I physxCapsuleShape.h \ + physxCapsuleShapeDesc.I physxCapsuleShapeDesc.h \ + physxConstraintDominance.I physxConstraintDominance.h \ + physxContactPair.I physxContactPair.h \ + physxContactPoint.I physxContactPoint.h \ + physxContactReport.I physxContactReport.h \ + physxController.I physxController.h \ + physxControllerDesc.I physxControllerDesc.h \ + physxControllerReport.I physxControllerReport.h \ + physxConvexForceFieldShape.I physxConvexForceFieldShape.h \ + physxConvexForceFieldShapeDesc.I physxConvexForceFieldShapeDesc.h \ + physxConvexMesh.I physxConvexMesh.h \ + physxConvexMeshDesc.I physxConvexMeshDesc.h \ + physxConvexShape.I physxConvexShape.h \ + physxConvexShapeDesc.I physxConvexShapeDesc.h \ + physxCylindricalJoint.I physxCylindricalJoint.h \ + physxCylindricalJointDesc.I physxCylindricalJointDesc.h \ physxD6Joint.I physxD6Joint.h \ - physxJointDesc.I physxJointDesc.h \ physxD6JointDesc.I physxD6JointDesc.h \ + physxDebugGeomNode.I physxDebugGeomNode.h \ + physxDistanceJoint.I physxDistanceJoint.h \ + physxDistanceJointDesc.I physxDistanceJointDesc.h \ + physxEnums.I physxEnums.h \ + physxFileStream.I physxFileStream.h \ + physxFixedJoint.I physxFixedJoint.h \ + physxFixedJointDesc.I physxFixedJointDesc.h \ + physxForceField.I physxForceField.h \ + physxForceFieldDesc.I physxForceFieldDesc.h \ + physxForceFieldShape.I physxForceFieldShape.h \ + physxForceFieldShapeDesc.I physxForceFieldShapeDesc.h \ + physxForceFieldShapeGroup.I physxForceFieldShapeGroup.h \ + physxForceFieldShapeGroupDesc.I physxForceFieldShapeGroupDesc.h \ + physxGroupsMask.I physxGroupsMask.h \ + physxHeightField.I physxHeightField.h \ + physxHeightFieldDesc.I physxHeightFieldDesc.h \ + physxHeightFieldShape.I physxHeightFieldShape.h \ + physxHeightFieldShapeDesc.I physxHeightFieldShapeDesc.h \ + physxJoint.I physxJoint.h \ + physxJointDesc.I physxJointDesc.h \ physxJointDriveDesc.I physxJointDriveDesc.h \ + physxJointLimitDesc.I physxJointLimitDesc.h \ physxJointLimitSoftDesc.I physxJointLimitSoftDesc.h \ - physxJointLimitSoftPairDesc.I physxJointLimitSoftPairDesc.h \ + physxKitchen.I physxKitchen.h \ + physxManager.I physxManager.h \ + physxMask.I physxMask.h \ physxMaterial.I physxMaterial.h \ physxMaterialDesc.I physxMaterialDesc.h \ + physxMemoryReadBuffer.I physxMemoryReadBuffer.h \ + physxMemoryWriteBuffer.I physxMemoryWriteBuffer.h \ + physxMeshPool.I physxMeshPool.h \ + physxMotorDesc.I physxMotorDesc.h \ + physxObject.I physxObject.h \ + physxObjectCollection.I physxObjectCollection.h \ + physxOverlapReport.I physxOverlapReport.h \ physxPlane.I physxPlane.h \ + physxPlaneShape.I physxPlaneShape.h \ + physxPlaneShapeDesc.I physxPlaneShapeDesc.h \ + physxPointInPlaneJoint.I physxPointInPlaneJoint.h \ + physxPointInPlaneJointDesc.I physxPointInPlaneJointDesc.h \ + physxPointOnLineJoint.I physxPointOnLineJoint.h \ + physxPointOnLineJointDesc.I physxPointOnLineJointDesc.h \ + physxPrismaticJoint.I physxPrismaticJoint.h \ + physxPrismaticJointDesc.I physxPrismaticJointDesc.h \ + physxPulleyJoint.I physxPulleyJoint.h \ + physxPulleyJointDesc.I physxPulleyJointDesc.h \ physxRay.I physxRay.h \ + physxRaycastHit.I physxRaycastHit.h \ + physxRaycastReport.I physxRaycastReport.h \ + physxRevoluteJoint.I physxRevoluteJoint.h \ + physxRevoluteJointDesc.I physxRevoluteJointDesc.h \ physxScene.I physxScene.h \ physxSceneDesc.I physxSceneDesc.h \ physxSceneStats2.I physxSceneStats2.h \ physxSegment.I physxSegment.h \ - physxCapsule.I physxCapsule.h \ physxShape.I physxShape.h \ - physxBoxShape.I physxBoxShape.h \ - physxCapsuleShape.I physxCapsuleShape.h \ - physxPlaneShape.I physxPlaneShape.h \ - physxSphereShape.I physxSphereShape.h \ physxShapeDesc.I physxShapeDesc.h \ - physxBoxShapeDesc.I physxBoxShapeDesc.h \ - physxCapsuleShapeDesc.I physxCapsuleShapeDesc.h \ - physxPlaneShapeDesc.I physxPlaneShapeDesc.h \ - physxSphereShapeDesc.I physxSphereShapeDesc.h \ physxSphere.I physxSphere.h \ + physxSphereForceFieldShape.I physxSphereForceFieldShape.h \ + physxSphereForceFieldShapeDesc.I physxSphereForceFieldShapeDesc.h \ + physxSphereShape.I physxSphereShape.h \ + physxSphereShapeDesc.I physxSphereShapeDesc.h \ + physxSphericalJoint.I physxSphericalJoint.h \ + physxSphericalJointDesc.I physxSphericalJointDesc.h \ + physxSpringDesc.I physxSpringDesc.h \ + physxTriangleMesh.I physxTriangleMesh.h \ + physxTriangleMeshDesc.I physxTriangleMeshDesc.h \ + physxTriangleMeshShape.I physxTriangleMeshShape.h \ + physxTriangleMeshShapeDesc.I physxTriangleMeshShapeDesc.h \ + physxTriggerReport.I physxTriggerReport.h \ physxUtilLib.I physxUtilLib.h \ + physxWheelShape.I physxWheelShape.h \ + physxWheelShapeDesc.I physxWheelShapeDesc.h \ #define INCLUDED_SOURCES \ - physxManager.cxx \ - physxContactHandler.cxx \ - physxTriggerHandler.cxx \ - physxJointHandler.cxx \ - physxActorNode.cxx \ + physxActor.cxx \ physxActorDesc.cxx \ physxBodyDesc.cxx \ physxBounds3.cxx \ physxBox.cxx \ - physxJoint.cxx \ + physxBoxController.cxx \ + physxBoxControllerDesc.cxx \ + physxBoxForceFieldShape.cxx \ + physxBoxForceFieldShapeDesc.cxx \ + physxBoxShape.cxx \ + physxBoxShapeDesc.cxx \ + physxCapsule.cxx \ + physxCapsuleController.cxx \ + physxCapsuleControllerDesc.cxx \ + physxCapsuleForceFieldShape.cxx \ + physxCapsuleForceFieldShapeDesc.cxx \ + physxCapsuleShape.cxx \ + physxCapsuleShapeDesc.cxx \ + physxConstraintDominance.cxx \ + physxContactPair.cxx \ + physxContactPoint.cxx \ + physxContactReport.cxx \ + physxController.cxx \ + physxControllerDesc.cxx \ + physxControllerReport.cxx \ + physxConvexForceFieldShape.cxx \ + physxConvexForceFieldShapeDesc.cxx \ + physxConvexMesh.cxx \ + physxConvexMeshDesc.cxx \ + physxConvexShape.cxx \ + physxConvexShapeDesc.cxx \ + physxCylindricalJoint.cxx \ + physxCylindricalJointDesc.cxx \ physxD6Joint.cxx \ - physxJointDesc.cxx \ physxD6JointDesc.cxx \ + physxDebugGeomNode.cxx \ + physxDistanceJoint.cxx \ + physxDistanceJointDesc.cxx \ + physxEnums.cxx \ + physxFileStream.cxx \ + physxFixedJoint.cxx \ + physxFixedJointDesc.cxx \ + physxForceField.cxx \ + physxForceFieldDesc.cxx \ + physxForceFieldShape.cxx \ + physxForceFieldShapeDesc.cxx \ + physxForceFieldShapeGroup.cxx \ + physxForceFieldShapeGroupDesc.cxx \ + physxGroupsMask.cxx \ + physxHeightField.cxx \ + physxHeightFieldDesc.cxx \ + physxHeightFieldShape.cxx \ + physxHeightFieldShapeDesc.cxx \ + physxJoint.cxx \ + physxJointDesc.cxx \ physxJointDriveDesc.cxx \ + physxJointLimitDesc.cxx \ physxJointLimitSoftDesc.cxx \ - physxJointLimitSoftPairDesc.cxx \ + physxKitchen.cxx \ + physxManager.cxx \ + physxMask.cxx \ physxMaterial.cxx \ physxMaterialDesc.cxx \ + physxMemoryReadBuffer.cxx \ + physxMemoryWriteBuffer.cxx \ + physxMeshPool.cxx \ + physxMotorDesc.cxx \ + physxObject.cxx \ + physxObjectCollection.cxx \ + physxOverlapReport.cxx \ physxPlane.cxx \ + physxPlaneShape.cxx \ + physxPlaneShapeDesc.cxx \ + physxPointInPlaneJoint.cxx \ + physxPointInPlaneJointDesc.cxx \ + physxPointOnLineJoint.cxx \ + physxPointOnLineJointDesc.cxx \ + physxPrismaticJoint.cxx \ + physxPrismaticJointDesc.cxx \ + physxPulleyJoint.cxx \ + physxPulleyJointDesc.cxx \ physxRay.cxx \ + physxRaycastHit.cxx \ + physxRaycastReport.cxx \ + physxRevoluteJoint.cxx \ + physxRevoluteJointDesc.cxx \ physxScene.cxx \ physxSceneDesc.cxx \ physxSceneStats2.cxx \ physxSegment.cxx \ - physxCapsule.cxx \ physxShape.cxx \ - physxBoxShape.cxx \ - physxCapsuleShape.cxx \ - physxPlaneShape.cxx \ - physxSphereShape.cxx \ physxShapeDesc.cxx \ - physxBoxShapeDesc.cxx \ - physxCapsuleShapeDesc.cxx \ - physxPlaneShapeDesc.cxx \ - physxSphereShapeDesc.cxx \ physxSphere.cxx \ + physxSphereForceFieldShape.cxx \ + physxSphereForceFieldShapeDesc.cxx \ + physxSphereShape.cxx \ + physxSphereShapeDesc.cxx \ + physxSphericalJoint.cxx \ + physxSphericalJointDesc.cxx \ + physxSpringDesc.cxx \ + physxTriangleMesh.cxx \ + physxTriangleMeshDesc.cxx \ + physxTriangleMeshShape.cxx \ + physxTriangleMeshShapeDesc.cxx \ + physxTriggerReport.cxx \ physxUtilLib.cxx \ + physxWheelShape.cxx \ + physxWheelShapeDesc.cxx \ #define INSTALL_HEADERS \ NoMinMax.h \ - config_physx.h \ - physxManager.I physxManager.h \ - physxContactHandler.I physxContactHandler.h \ - physxTriggerHandler.I physxTriggerHandler.h \ - physxJointHandler.I physxJointHandler.h \ - physxActorNode.I physxActorNode.h \ + config_physx.h \ + physxActor.I physxActor.h \ physxActorDesc.I physxActorDesc.h \ physxBodyDesc.I physxBodyDesc.h \ physxBounds3.I physxBounds3.h \ physxBox.I physxBox.h \ - physxJoint.I physxJoint.h \ + physxBoxController.I physxBoxController.h \ + physxBoxControllerDesc.I physxBoxControllerDesc.h \ + physxBoxForceFieldShape.I physxBoxForceFieldShape.h \ + physxBoxForceFieldShapeDesc.I physxBoxForceFieldShapeDesc.h \ + physxBoxShape.I physxBoxShape.h \ + physxBoxShapeDesc.I physxBoxShapeDesc.h \ + physxCapsule.I physxCapsule.h \ + physxCapsuleController.I physxCapsuleController.h \ + physxCapsuleControllerDesc.I physxCapsuleControllerDesc.h \ + physxCapsuleForceFieldShape.I physxCapsuleForceFieldShape.h \ + physxCapsuleForceFieldShapeDesc.I physxCapsuleForceFieldShapeDesc.h \ + physxCapsuleShape.I physxCapsuleShape.h \ + physxCapsuleShapeDesc.I physxCapsuleShapeDesc.h \ + physxConstraintDominance.I physxConstraintDominance.h \ + physxContactPair.I physxContactPair.h \ + physxContactPoint.I physxContactPoint.h \ + physxContactReport.I physxContactReport.h \ + physxController.I physxController.h \ + physxControllerDesc.I physxControllerDesc.h \ + physxControllerReport.I physxControllerReport.h \ + physxConvexForceFieldShape.I physxConvexForceFieldShape.h \ + physxConvexForceFieldShapeDesc.I physxConvexForceFieldShapeDesc.h \ + physxConvexMesh.I physxConvexMesh.h \ + physxConvexMeshDesc.I physxConvexMeshDesc.h \ + physxConvexShape.I physxConvexShape.h \ + physxConvexShapeDesc.I physxConvexShapeDesc.h \ + physxCylindricalJoint.I physxCylindricalJoint.h \ + physxCylindricalJointDesc.I physxCylindricalJointDesc.h \ physxD6Joint.I physxD6Joint.h \ - physxJointDesc.I physxJointDesc.h \ physxD6JointDesc.I physxD6JointDesc.h \ + physxDebugGeomNode.I physxDebugGeomNode.h \ + physxDistanceJoint.I physxDistanceJoint.h \ + physxDistanceJointDesc.I physxDistanceJointDesc.h \ + physxEnums.I physxEnums.h \ + physxFileStream.I physxFileStream.h \ + physxFixedJoint.I physxFixedJoint.h \ + physxFixedJointDesc.I physxFixedJointDesc.h \ + physxForceField.I physxForceField.h \ + physxForceFieldDesc.I physxForceFieldDesc.h \ + physxForceFieldShape.I physxForceFieldShape.h \ + physxForceFieldShapeDesc.I physxForceFieldShapeDesc.h \ + physxForceFieldShapeGroup.I physxForceFieldShapeGroup.h \ + physxForceFieldShapeGroupDesc.I physxForceFieldShapeGroupDesc.h \ + physxGroupsMask.I physxGroupsMask.h \ + physxHeightField.I physxHeightField.h \ + physxHeightFieldDesc.I physxHeightFieldDesc.h \ + physxHeightFieldShape.I physxHeightFieldShape.h \ + physxHeightFieldShapeDesc.I physxHeightFieldShapeDesc.h \ + physxJoint.I physxJoint.h \ + physxJointDesc.I physxJointDesc.h \ physxJointDriveDesc.I physxJointDriveDesc.h \ + physxJointLimitDesc.I physxJointLimitDesc.h \ physxJointLimitSoftDesc.I physxJointLimitSoftDesc.h \ - physxJointLimitSoftPairDesc.I physxJointLimitSoftPairDesc.h \ + physxKitchen.I physxKitchen.h \ + physxManager.I physxManager.h \ + physxMask.I physxMask.h \ physxMaterial.I physxMaterial.h \ physxMaterialDesc.I physxMaterialDesc.h \ + physxMemoryReadBuffer.I physxMemoryReadBuffer.h \ + physxMemoryWriteBuffer.I physxMemoryWriteBuffer.h \ + physxMeshPool.I physxMeshPool.h \ + physxMotorDesc.I physxMotorDesc.h \ + physxObject.I physxObject.h \ + physxObjectCollection.I physxObjectCollection.h \ + physxOverlapReport.I physxOverlapReport.h \ physxPlane.I physxPlane.h \ + physxPlaneShape.I physxPlaneShape.h \ + physxPlaneShapeDesc.I physxPlaneShapeDesc.h \ + physxPointInPlaneJoint.I physxPointInPlaneJoint.h \ + physxPointInPlaneJointDesc.I physxPointInPlaneJointDesc.h \ + physxPointOnLineJoint.I physxPointOnLineJoint.h \ + physxPointOnLineJointDesc.I physxPointOnLineJointDesc.h \ + physxPrismaticJoint.I physxPrismaticJoint.h \ + physxPrismaticJointDesc.I physxPrismaticJointDesc.h \ + physxPulleyJoint.I physxPulleyJoint.h \ + physxPulleyJointDesc.I physxPulleyJointDesc.h \ physxRay.I physxRay.h \ + physxRaycastHit.I physxRaycastHit.h \ + physxRaycastReport.I physxRaycastReport.h \ + physxRevoluteJoint.I physxRevoluteJoint.h \ + physxRevoluteJointDesc.I physxRevoluteJointDesc.h \ physxScene.I physxScene.h \ physxSceneDesc.I physxSceneDesc.h \ physxSceneStats2.I physxSceneStats2.h \ physxSegment.I physxSegment.h \ - physxCapsule.I physxCapsule.h \ physxShape.I physxShape.h \ - physxBoxShape.I physxBoxShape.h \ - physxCapsuleShape.I physxCapsuleShape.h \ - physxPlaneShape.I physxPlaneShape.h \ - physxSphereShape.I physxSphereShape.h \ physxShapeDesc.I physxShapeDesc.h \ - physxBoxShapeDesc.I physxBoxShapeDesc.h \ - physxCapsuleShapeDesc.I physxCapsuleShapeDesc.h \ - physxPlaneShapeDesc.I physxPlaneShapeDesc.h \ - physxSphereShapeDesc.I physxSphereShapeDesc.h \ physxSphere.I physxSphere.h \ + physxSphereForceFieldShape.I physxSphereForceFieldShape.h \ + physxSphereForceFieldShapeDesc.I physxSphereForceFieldShapeDesc.h \ + physxSphereShape.I physxSphereShape.h \ + physxSphereShapeDesc.I physxSphereShapeDesc.h \ + physxSphericalJoint.I physxSphericalJoint.h \ + physxSphericalJointDesc.I physxSphericalJointDesc.h \ + physxSpringDesc.I physxSpringDesc.h \ + physxTriangleMesh.I physxTriangleMesh.h \ + physxTriangleMeshDesc.I physxTriangleMeshDesc.h \ + physxTriangleMeshShape.I physxTriangleMeshShape.h \ + physxTriangleMeshShapeDesc.I physxTriangleMeshShapeDesc.h \ + physxTriggerReport.I physxTriggerReport.h \ physxUtilLib.I physxUtilLib.h \ + physxWheelShape.I physxWheelShape.h \ + physxWheelShapeDesc.I physxWheelShapeDesc.h \ #define IGATESCAN all #end lib_target - diff --git a/panda/src/physx/SourcesTemplate.pp b/panda/src/physx/SourcesTemplate.pp deleted file mode 100644 index 9fd370ec91..0000000000 --- a/panda/src/physx/SourcesTemplate.pp +++ /dev/null @@ -1,39 +0,0 @@ -#define BUILD_DIRECTORY $[HAVE_PHYSX] - -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolutil:c dtoolbase:c dtool:m prc:c - -#begin lib_target - #define TARGET physx - #define BUILD_TARGET $[HAVE_PHYSX] - #define USE_PACKAGES physx - #define LOCAL_LIBS pgraph linmath - #define COMBINED_SOURCES $[TARGET]_composite.cxx - #define INTERROGATE_OPTIONS $[INTERROGATE_OPTIONS] -DHAVE_PHYSX - - #define SOURCES \ - NoMinMax.h \ - config_physx.h \ - physxManager.I physxManager.h \ - physxContactHandler.I physxContactHandler.h \ - physxTriggerHandler.I physxTriggerHandler.h \ - physxJointHandler.I physxJointHandler.h \ -//headers - #define INCLUDED_SOURCES \ - physxManager.cxx \ - physxContactHandler.cxx \ - physxTriggerHandler.cxx \ - physxJointHandler.cxx \ -//cxx - #define INSTALL_HEADERS \ - NoMinMax.h \ - config_physx.h \ - physxManager.I physxManager.h \ - physxContactHandler.I physxContactHandler.h \ - physxTriggerHandler.I physxTriggerHandler.h \ - physxJointHandler.I physxJointHandler.h \ -//headers - #define IGATESCAN all - -#end lib_target - diff --git a/panda/src/physx/config_physx.cxx b/panda/src/physx/config_physx.cxx index 5194822320..62ff5e8ae2 100644 --- a/panda/src/physx/config_physx.cxx +++ b/panda/src/physx/config_physx.cxx @@ -1,5 +1,5 @@ -// Filename: config_physics.cxx -// Created by: pratt (Apr 18, 2006) +// Filename: config_physx.cxx +// Created by: enn0x (01Sep09) // //////////////////////////////////////////////////////////////////// // @@ -13,17 +13,48 @@ //////////////////////////////////////////////////////////////////// #include "config_physx.h" +#include "pandaSystem.h" -#include "dconfig.h" - -#include "physxActorNode.h" -#include "physxJoint.h" -#include "physxD6Joint.h" -#include "physxShape.h" +#include "physxActor.h" +#include "physxBoxController.h" +#include "physxBoxForceFieldShape.h" #include "physxBoxShape.h" +#include "physxCapsuleController.h" +#include "physxCapsuleForceFieldShape.h" #include "physxCapsuleShape.h" +#include "physxContactPair.h" +#include "physxContactPoint.h" +#include "physxController.h" +#include "physxConvexMesh.h" +#include "physxConvexForceFieldShape.h" +#include "physxConvexShape.h" +#include "physxCylindricalJoint.h" +#include "physxD6Joint.h" +#include "physxDebugGeomNode.h" +#include "physxDistanceJoint.h" +#include "physxFixedJoint.h" +#include "physxForceField.h" +#include "physxForceFieldShape.h" +#include "physxForceFieldShapeGroup.h" +#include "physxHeightField.h" +#include "physxHeightFieldShape.h" +#include "physxJoint.h" +#include "physxMaterial.h" +#include "physxObject.h" #include "physxPlaneShape.h" +#include "physxPointInPlaneJoint.h" +#include "physxPointOnLineJoint.h" +#include "physxPrismaticJoint.h" +#include "physxPulleyJoint.h" +#include "physxRevoluteJoint.h" +#include "physxScene.h" +#include "physxShape.h" +#include "physxSphereForceFieldShape.h" #include "physxSphereShape.h" +#include "physxSphericalJoint.h" +#include "physxTriangleMesh.h" +#include "physxTriangleMeshShape.h" +#include "physxWheelShape.h" ConfigureDef(config_physx); NotifyCategoryDef(physx, ""); @@ -32,15 +63,27 @@ ConfigureFn(config_physx) { init_libphysx(); } -ConfigVariableBool physx_want_visual_debugger -("physx-want-visual-debugger", false); +ConfigVariableBool physx_want_vrd +("physx-want-vrd", false, +PRC_DESC("Specified wether the manager should try to connect to the NVIDIA " + "PhysX visual debugger or not. Connection is established when " + "the first instance of PhysxManager is created.")); -ConfigVariableString physx_visual_debugger_host -("physx-visual-debugger-host", "localhost"); +ConfigVariableString physx_vrd_host +("physx-vrd-host", "localhost", +PRC_DESC("Specified the host where the NVIDIA PhysX visual debugger is running" + "on. Only used if the config-varibale 'physx-want-visual-debugger' " + "is set to 'true'.")); -ConfigVariableInt physx_visual_debugger_port -("physx-visual-debugger-port", 5425); +ConfigVariableInt physx_vrd_port +("physx-visual-debugger-port", 5425, +PRC_DESC("Specified the port where the NVIDIA PhysX visual debugger is running" + "on. Only used if the config-varibale 'physx-want-visual-debugger' " + "is set to 'true'.")); +ConfigVariableEnum physx_up_axis +("physx-up-axis", PhysxEnums::Z_up, +PRC_DESC("Set the up direction for controllers and heightfields.")); //////////////////////////////////////////////////////////////////// // Function: init_libphysx @@ -58,12 +101,48 @@ init_libphysx() { } initialized = true; - PhysxActorNode::init_type(); - PhysxJoint::init_type(); - PhysxD6Joint::init_type(); - PhysxShape::init_type(); + PhysxActor::init_type(); + PhysxBoxController::init_type(); + PhysxBoxForceFieldShape::init_type(); PhysxBoxShape::init_type(); + PhysxCapsuleController::init_type(); + PhysxCapsuleForceFieldShape::init_type(); PhysxCapsuleShape::init_type(); + PhysxContactPair::init_type(); + PhysxContactPoint::init_type(); + PhysxController::init_type(); + PhysxConvexMesh::init_type(); + PhysxConvexForceFieldShape::init_type(); + PhysxConvexShape::init_type(); + PhysxCylindricalJoint::init_type(); + PhysxD6Joint::init_type(); + PhysxDebugGeomNode::init_type(); + PhysxDistanceJoint::init_type(); + PhysxFixedJoint::init_type(); + PhysxForceField::init_type(); + PhysxForceFieldShape::init_type(); + PhysxForceFieldShapeGroup::init_type(); + PhysxHeightField::init_type(); + PhysxHeightFieldShape::init_type(); + PhysxJoint::init_type(); + PhysxMaterial::init_type(); + PhysxObject::init_type(); PhysxPlaneShape::init_type(); + PhysxPointInPlaneJoint::init_type(); + PhysxPointOnLineJoint::init_type(); + PhysxPrismaticJoint::init_type(); + PhysxPulleyJoint::init_type(); + PhysxRevoluteJoint::init_type(); + PhysxScene::init_type(); + PhysxShape::init_type(); + PhysxSphereForceFieldShape::init_type(); PhysxSphereShape::init_type(); + PhysxSphericalJoint::init_type(); + PhysxTriangleMesh::init_type(); + PhysxTriangleMeshShape::init_type(); + PhysxWheelShape::init_type(); + + PandaSystem *ps = PandaSystem::get_global_ptr(); + ps->add_system("PhysX"); } + diff --git a/panda/src/physx/config_physx.h b/panda/src/physx/config_physx.h index eb1fcb2ccb..acb80ed995 100644 --- a/panda/src/physx/config_physx.h +++ b/panda/src/physx/config_physx.h @@ -1,5 +1,5 @@ // Filename: config_physx.h -// Created by: pratt (Apr 18, 2006) +// Created by: enn0x (01Sep09) // //////////////////////////////////////////////////////////////////// // @@ -17,54 +17,21 @@ #include "pandabase.h" #include "notifyCategoryProxy.h" +#include "configVariableBool.h" +#include "configVariableEnum.h" +#include "configVariableInt.h" #include "dconfig.h" +#include "physxEnums.h" + ConfigureDecl(config_physx, EXPCL_PANDAPHYSX, EXPTP_PANDAPHYSX); NotifyCategoryDecl(physx, EXPCL_PANDAPHYSX, EXPTP_PANDAPHYSX); -extern EXPCL_PANDA ConfigVariableBool physx_want_visual_debugger; -extern EXPCL_PANDA ConfigVariableString physx_visual_debugger_host; -extern EXPCL_PANDA ConfigVariableInt physx_visual_debugger_port; +extern EXPCL_PANDAPHYSX ConfigVariableBool physx_want_vrd; +extern EXPCL_PANDAPHYSX ConfigVariableString physx_vrd_host; +extern EXPCL_PANDAPHYSX ConfigVariableInt physx_vrd_port; +extern EXPCL_PANDAPHYSX ConfigVariableEnum physx_up_axis; extern EXPCL_PANDAPHYSX void init_libphysx(); -// These macros get stripped out in a non-debug build (like asserts). -// Use them like cout but with paranthesis aroud the cout input. -// e.g. foo_debug("The value of bar is " << bar); -#ifndef NDEBUG //[ - // Non-release build: - #define PHYSX_DEBUG - - #define physx_spam(msg) \ - if (physx_cat.is_spam()) { \ - physx_cat->spam() << msg << endl; \ - } else {} - - #define physx_debug(msg) \ - if (physx_cat.is_debug()) { \ - physx_cat->debug() << msg << endl; \ - } else {} - - #define physx_info(msg) \ - physx_cat->info() << msg << endl - - #define physx_warning(msg) \ - physx_cat->warning() << msg << endl - - // defining NX_USER_DEBUG_MODE causes the PhysX SDK to output extra - // information to NxUserOutputStream. - #define NX_USER_DEBUG_MODE -#else //][ - // Release build: - #undef PHYSX_DEBUG - - #define physx_spam(msg) ((void)0) - #define physx_debug(msg) ((void)0) - #define physx_info(msg) ((void)0) - #define physx_warning(msg) ((void)0) -#endif //] - -#define physx_error(msg) \ - physx_cat->error() << msg << endl - #endif // CONFIG_PHYSX_H diff --git a/panda/src/physx/createComposite.py b/panda/src/physx/createComposite.py deleted file mode 100644 index 0fa99f4099..0000000000 --- a/panda/src/physx/createComposite.py +++ /dev/null @@ -1,19 +0,0 @@ - -import os -import os.path - -def createComposite(): - filesToOmit = ( - "physx_composite.cxx", - "physxTemplate.cxx", - ) - - compositeFile = file( "physx_composite.cxx", "w" ) - compositeFile.write( "\n" ) - - for filename in os.listdir( os.getcwd() ): - if filename.endswith( ".cxx" ) and (filename not in filesToOmit): - compositeFile.write( '#include "%s"\n' % filename ) - -if __name__ == "__main__": - createComposite() diff --git a/panda/src/physx/generateCode.py b/panda/src/physx/generateCode.py deleted file mode 100644 index 2e43dea673..0000000000 --- a/panda/src/physx/generateCode.py +++ /dev/null @@ -1,1021 +0,0 @@ - -import os.path -import re -import xmltramp - -docDir = "C:\\pratt\\schellGames\\physxDoxy\\2.7.3\\doc\\xml" - -membersToOmit = ( - "user_data", - "get_type", - "get_internal", - "load", - "create_fluid_hardware_triangle_mesh", - "get_center", - "get_extents", - "get_rot", - "physx_ray_capsule_intersect", - "is_point_in_plane_joint", - "is_point_on_line_joint", - "get_actors", - "get_actor_group_pair_array", - "get_filter_ops", - "get_island_array_from_actor", - "get_material_array", - "physx_compute_sphere", - "l_vec_base3f_obb_sqr_dist", -) - -stringConversions = [ - ("NX_INLINE", "INLINE"), - ("NX_BOOL", "bool"), - ("NxI64", "PN_int64"), - ("NxI32", "int"), - ("NxI16", "short"), - ("NxI8", "char"), - ("NxU64", "PN_uint64"), - ("NxU32", "unsigned int"), - ("NxU16", "unsigned short"), - ("NxU8", "unsigned char"), - ("NxF32", "float"), - ("NxF64", "double"), - ("NxReal", "float"), - ("NxActorGroup", "unsigned short"), - ("NxCollisionGroup", "unsigned short"), - ("NxMaterialIndex", "unsigned short"), - ("NxSubmeshIndex", "unsigned int"), - ("NxTriangleID", "unsigned int"), - ("NxVec3", "LVecBase3f"), - ("NxPoint", "LVecBase3f"), - ("NxMat33", "LMatrix3f"), - ("NxMat34", "LMatrix4f"), - ("NxQuat", "LQuaternionf"), - ("Nx", "Physx"), -] -reConversions = [] -for pair in stringConversions: - reConversions.append( (re.compile( pair[0] ), pair[1]) ) - -convertFromFunctions = { - "LVecBase3f" : "PhysxManager::lVecBase3_to_nxVec3", - "LMatrix3f" : "PhysxManager::lMatrix3_to_nxMat33", - "LMatrix4f" : "PhysxManager::lMatrix4_to_nxMat34", - "LQuaternionf" : "PhysxManager::lQuaternion_to_nxQuat", -} - -convertToFunctions = { - "LVecBase3f" : "PhysxManager::nxVec3_to_lVecBase3", - "LMatrix3f" : "PhysxManager::nxMat33_to_lMatrix3", - "LMatrix4f" : "PhysxManager::nxMat34_to_lMatrix4", - "LQuaternionf" : "PhysxManager::nxQuat_to_lQuaternion", -} - -builtinTypes = ( - "void", - "bool", - "int", - "float", - "double", - "char", - "unsigned char", - "signed char", - "unsigned int", - "signed int", - "short int", - "unsigned short int", - "signed short int", - "long int", - "signed long int", - "unsigned long int", - "long double", -) - -#subClasses = { -# "PhysxBoxShape" : "PhysxShape", -# "PhysxCapsuleShape" : "PhysxShape", -# "PhysxPlaneShape" : "PhysxShape", -# "PhysxSphereShape" : "PhysxShape", -# "PhysxD6Joint" : "PhysxJoint", -# "PhysxD6JointDesc" : "PhysxJointDesc", -# "PhysxActorNode" : "PandaNode", -#} - -typedWritableReferenceCountClasses = ( - "BoxShape", - "CapsuleShape", - "D6Joint", - "Joint", - "PlaneShape", - "Shape", - "SphereShape", -) - -classNameConversions = { - "Actor" : "ActorNode", -} - -def generateClassCode( name, isStruct=False ): - underscoredName = getUnderscoredFromMixedCase( name ) - if isStruct: - xmlfile = file( os.path.join( docDir, "struct_nx_%s.xml" % underscoredName ) ) - else: - xmlfile = file( os.path.join( docDir, "class_nx_%s.xml" % underscoredName ) ) - doc = xmltramp.seed( xmlfile ) - xmlfile.close() - - if hasattr( doc[0], "basecompoundref" ): - className = str( doc[0].basecompoundref ).replace( "Nx", "Physx" ) - prot = doc[0].basecompoundref( "prot" ) - virt = doc[0].basecompoundref( "virt" ) - if virt == "virtual": - baseClassRef = "%s virtual %s" % (prot, className) - else: - baseClassRef = "%s %s" % (prot, className) - else: - baseClassRef = None - - structors = {} - methods = {} - attributes = {} - for section in doc[0]["sectiondef":]: - if (section( "kind" ) == "public-func") or (section( "kind" ) == "user-defined"): - for member in section["memberdef":]: - memberName = str( member.name ) - method = {} - method["type"] = str( member.type ) - method["argsstring"] = str( member.argsstring ) - method["const"] = member( "const" ) == "yes" - method["params"] = [] - for param in member["param":]: - if hasattr( param, "type" ) and hasattr( param, "declname" ): - method["params"].append( [str( param.type ), str( param.declname )] ) - if (memberName == "Nx" + name) or (memberName == "~Nx" + name): - structors[memberName] = method - else: - methods[memberName] = method - elif section( "kind" ) == "public-attrib": - for member in section["memberdef":]: - memberName = str( member.name ) - variable = {} - variable["type"] = "INLINE " + str( member.type ) - attributes[memberName] = variable - - convertNames( structors, underscoreNames=False ) - convertNames( methods ) - convertNames( attributes ) - - filterMembers( structors ) - filterMembers( methods ) - filterMembers( attributes ) - - createHeader( name, structors, methods, attributes, baseClassRef ) - createCxx( name, structors, methods, attributes ) - createInline( name, structors, methods, attributes ) - -def convertNames( memberDict, underscoreNames=True ): - for memberName in memberDict.keys(): - info = memberDict[memberName] - for key in info.keys(): - if key == "type": - info[key] = convertString( info[key] ) - rawType = getRawType( info[key] ) - if (rawType not in builtinTypes) and ("INLINE" in info[key]): - info[key] = info[key].replace( "INLINE", "" ).strip() - if rawType.startswith( "Physx" ) and (rawType[5:] in classNameConversions): - info[key] = info[key].replace( "Physx" + rawType[5:], "Physx" + classNameConversions[rawType[5:]] ).strip() - elif key == "argsstring": - info[key] = convertString( info[key] ) - elif key == "params": - for param in info[key]: - param[0] = convertString( param[0] ) - param[1] = getUnderscoredFromMixedCase( convertString( param[1] ) ) - rawType = getRawType( param[0] ) - if (rawType not in builtinTypes) and ("INLINE" in info["type"]): - param[0] = param[0].replace( "INLINE", "" ).strip() - if rawType.startswith( "Physx" ) and (rawType[5:] in classNameConversions): - param[0] = param[0].replace( "Physx" + rawType[5:], "Physx" + classNameConversions[rawType[5:]] ).strip() - elif key == "const": - pass - else: - raise - - memberDict[memberName]["originalName"] = memberName - if underscoreNames: - newMemberName = getUnderscoredFromMixedCase( convertString( memberName ) ) - else: - newMemberName = convertString( memberName ) - - if newMemberName != memberName: - del memberDict[memberName] - memberDict[newMemberName] = info - -def filterMembers( memberDict ): - for memberName in memberDict.keys(): - info = memberDict[memberName] - rawType = getRawType( info["type"] ) - if memberName in membersToOmit: - del memberDict[memberName] - elif rawType.startswith( "Physx" ) and (not isNameKnown( rawType[5:] )): - del memberDict[memberName] - elif info["type"].count( "*" ) > 1: - del memberDict[memberName] - elif memberDict[memberName].has_key( "params" ): - for param in memberDict[memberName]["params"]: - rawType = getRawType( param[0] ) - if rawType.startswith( "Physx" ) and (not isNameKnown( rawType[5:] )): - del memberDict[memberName] - break - -def convertString( s ): - for pattern, replacement in reConversions: - s = pattern.sub( replacement, s ) - return s - -def createHeader( name, structors, methods, attributes, baseClassRef ): - templateFile = file( "physxTemplate.h" ) - templateString = templateFile.read() - templateFile.close() - - lowerPattern = re.compile( "template" ) - upperPattern = re.compile( "TEMPLATE" ) - capsPattern = re.compile( "Template" ) - typeHeaderPattern = re.compile( "//typedWritableReferenceCountHeader" ) - superHeaderPattern = re.compile( "//superHeader\n" ) - forwardsPattern = re.compile( "//forwardDeclarations\n" ) - baseClassRefPattern = re.compile( "/\*baseclassref\*/" ) - structorsPattern = re.compile( "//publicstructors" ) - methodsPattern = re.compile( "//publicmethods" ) - attributesPattern = re.compile( "//publicattributes" ) - nxReferencePattern = re.compile( "//nxreference" ) - typeInfoPattern = re.compile( "//typeinfo\n" ) - - nName = name - if name in classNameConversions: - name = classNameConversions[name] - - if name in typedWritableReferenceCountClasses: - if baseClassRef is None: - baseClassRef = "public TypedWritableReferenceCount" - templateString = typeInfoPattern.sub( getTypeInfo( name, baseClassRef ), templateString ) - else: - templateString = typeInfoPattern.sub( "", templateString ) - - if baseClassRef is not None: - templateString = superHeaderPattern.sub( '#include "%s.h"\n\n' % lowerFirst( baseClassRef.split()[1] ), templateString ) - templateString = baseClassRefPattern.sub( ": %s " % baseClassRef, templateString ) - else: - templateString = superHeaderPattern.sub( "", templateString ) - templateString = baseClassRefPattern.sub( "", templateString ) - - templateString = lowerPattern.sub( lowerFirst( name ), templateString ) - templateString = upperPattern.sub( name.upper(), templateString ) - templateString = capsPattern.sub( name, templateString ) - templateString = forwardsPattern.sub( getForwardDeclarations( name, structors, methods, attributes, baseClassRef ), templateString ) - templateString = structorsPattern.sub( getMethodHeaders( structors ), templateString ) - templateString = methodsPattern.sub( getMethodHeaders( methods ), templateString ) - templateString = attributesPattern.sub( getAttributeHeaders( attributes ), templateString ) - - if name in avoidPointerNames: - templateString = nxReferencePattern.sub( " Nx%s %s;" % (nName, "n" + nName), templateString ) - else: - templateString = nxReferencePattern.sub( " Nx%s *%s;" % (nName, "n" + nName), templateString ) - - outputFile = file( "generated/physx" + name + ".h", "w" ) - outputFile.write( templateString ) - outputFile.close() - -def getIncludes( name, structors, methods, attributes, baseClassRef=None ): - rawTypes = [] - for method in structors.values() + methods.values(): - for param in method["params"]: - rawTypes.append( getRawType( param[0] ) ) - for member in methods.values() + attributes.values(): - rawTypes.append( getRawType( member["type"] ) ) - if baseClassRef is not None: - for part in baseClassRef.split(): - rawTypes.append( part ) - - includeDict = {} - for rawType in rawTypes: - if rawType.startswith( "Physx" ) and isBuiltName( rawType[5:] ) and (rawType[5:] != name): - includeDict['#include "%s.h"\n' % (rawType[0].lower() + rawType[1:])] = True - elif rawType.startswith( "L" ): - includeDict['#include "luse.h"\n'] = True - - includes = includeDict.keys() - includes.sort() - return "".join( includes ) - -def getForwardDeclarations( name, structors, methods, attributes, baseClassRef=None ): - rawTypes = [] - for method in structors.values() + methods.values(): - for param in method["params"]: - rawTypes.append( getRawType( param[0] ) ) - for member in methods.values() + attributes.values(): - rawTypes.append( getRawType( member["type"] ) ) - - if baseClassRef is not None: - baseClass = baseClassRef.split()[1] - else: - baseClass = None - forwardDict = {} # use a dictionary to avoid duplicates - for rawType in rawTypes: - if rawType.startswith( "Physx" ) and isBuiltName( rawType[5:] ) and (rawType[5:] != name) and (rawType != baseClass): - forwardDict["class %s;\n" % rawType] = True - - forwards = forwardDict.keys() - forwards.sort() - - if len( forwards ) > 0: - return "".join( forwards ) + "\n" - else: - return "" - -def getMethodHeaders( methodDict ): - s = "" - names = methodDict.keys() - names.sort() - for name in names: - method = methodDict[name] - s += " " - if method["type"] != "": - s += "%s " % method["type"] - s += "%s(%s)" % (name, getParamString( method["params"] )) - if method["const"]: - s += " const" - s += ";\n" - - return s - -def getAttributeHeaders( attributeDict ): - getters = "" - setters = "" - names = attributeDict.keys() - names.sort() - for name in names: - attribute = attributeDict[name] - type = attribute["type"] - rawType = getRawType( type ) - if (rawType not in builtinTypes) and (not type.endswith( "*" )) and (not convertFromFunctions.has_key( rawType )) and (rawType not in enumerations.keys()): - type += " &" - getters += " %s get_%s() const;\n" % (type, name) - if "INLINE" in type: - setters += " INLINE void set_%s(%s value);\n" % (name, type.replace( "INLINE", "" ).strip()) - else: - setters += " void set_%s(%s value);\n" % (name, type.replace( "INLINE", "" ).strip()) - if getters != "": - return "%s\n%s" % (getters, setters) - else: - return "" - -def getTypeInfo( className, baseClassRef ): - typeInfoString = """ - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - %(superName)s::init_type(); - register_type(_type_handle, "Physx%(className)s", - %(superName)s::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() { - init_type(); - return get_class_type(); - } - -private: - static TypeHandle _type_handle; -""" - content = {} - content["className"] = className - content["superName"] = baseClassRef.split()[1] - return typeInfoString % content - -def createCxx( name, structors, methods, attributes ): - templateFile = file( "physxTemplate.cxx" ) - templateString = templateFile.read() - templateFile.close() - - lowerPattern = re.compile( "template" ) - upperPattern = re.compile( "TEMPLATE" ) - capsPattern = re.compile( "Template" ) - includesPattern = re.compile( "//includes" ) - typeHandlePattern = re.compile( "//typehandle" ) - structorsPattern = re.compile( "//publicstructors\n" ) - methodsPattern = re.compile( "//publicmethods\n" ) - attributesPattern = re.compile( "//publicattributes\n" ) - - pName = name - if name in classNameConversions: - pName = classNameConversions[name] - - if pName in typedWritableReferenceCountClasses: - templateString = typeHandlePattern.sub( "TypeHandle Physx%s::_type_handle;\n" % pName, templateString ) - else: - templateString = typeHandlePattern.sub( "", templateString ) - - templateString = lowerPattern.sub( lowerFirst( pName ), templateString ) - templateString = upperPattern.sub( pName.upper(), templateString ) - templateString = capsPattern.sub( pName, templateString ) - templateString = includesPattern.sub( getIncludes( name, structors, methods, attributes ), templateString ) - templateString = structorsPattern.sub( getMethodSource( name, structors, doInline=False, doCode=False ), templateString ) - templateString = methodsPattern.sub( getMethodSource( name, methods, doInline=False, doCode=True ), templateString ) - templateString = attributesPattern.sub( getAttributeSource( name, attributes, doInline=False ), templateString ) - - outputFile = file( "generated/physx" + pName + ".cxx", "w" ) - outputFile.write( templateString ) - outputFile.close() - -def createInline( name, structors, methods, attributes ): - templateFile = file( "physxTemplate.I" ) - templateString = templateFile.read() - templateFile.close() - - lowerPattern = re.compile( "template" ) - upperPattern = re.compile( "TEMPLATE" ) - capsPattern = re.compile( "Template" ) - structorsPattern = re.compile( "//publicstructors\n" ) - methodsPattern = re.compile( "//publicmethods\n" ) - attributesPattern = re.compile( "//publicattributes\n" ) - - pName = name - if name in classNameConversions: - pName = classNameConversions[name] - - templateString = lowerPattern.sub( lowerFirst( pName ), templateString ) - templateString = upperPattern.sub( pName.upper(), templateString ) - templateString = capsPattern.sub( pName, templateString ) - templateString = structorsPattern.sub( getMethodSource( name, structors, doInline=True, doCode=False ), templateString ) - templateString = methodsPattern.sub( getMethodSource( name, methods, doInline=True, doCode=True ), templateString ) - templateString = attributesPattern.sub( getAttributeSource( name, attributes, doInline=True ), templateString ) - - outputFile = file( "generated/physx" + pName + ".I", "w" ) - outputFile.write( templateString ) - outputFile.close() - -def getMethodSource( className, methodDict, doInline=False, doCode=True ): - if className in avoidPointerNames: - attribOperator = "." - else: - attribOperator = "->" - - pClassName = className - if className in classNameConversions: - pClassName = classNameConversions[className] - - result = "" - - methodString = """//////////////////////////////////////////////////////////////////// -// Function : %(name)s -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -%(type)s%(class)s:: -%(name)s%(params)s%(const)s { -%(code)s -} - -""" - names = methodDict.keys() - names.sort() - for name in names: - method = methodDict[name] - if (("INLINE" in method["type"]) and doInline) or (("INLINE" not in method["type"]) and (not doInline)): - content = {} - content["name"] = name - if method["type"] != "": - content["type"] = "%s " % method["type"] - else: - content["type"] = "" - content["class"] = "Physx" + pClassName - content["params"] = "(%s)" % getParamString( method["params"] ) - if method["const"]: - content["const"] = " const" - else: - content["const"] = "" - - nxObject = "n" + className - nxMethodName = method["originalName"] - callerParamString = getCallerParamString( method["params"] ) - - if name.startswith( "create" ): - content["code"] = ' throw "Not Implemented";' - elif doCode: - if method.has_key( "code" ): - content["code"] = method["code"] % nxObject - elif ("void" in method["type"]) and ("*" not in method["type"]): - content["code"] = " %s%s%s(%s);" % (nxObject, attribOperator, nxMethodName, callerParamString) - else: - inner = "%s%s%s(%s)" % (nxObject, attribOperator, nxMethodName, callerParamString) - content["code"] = " return %s;" % wrapValue( method["type"], inner, isReturnValue=True ) - - if className not in avoidPointerNames: - if ("void" in method["type"]) and ("*" not in method["type"]): - content["code"] = (" nassertv(%s != NULL);\n\n" % nxObject) + content["code"] - elif ("bool" in method["type"]) and ("*" not in method["type"]): - content["code"] = (" nassertr(%s != NULL, false);\n\n" % nxObject) + content["code"] - elif ("float" in method["type"]) and ("*" not in method["type"]): - content["code"] = (" nassertr(%s != NULL, -1.0f);\n\n" % nxObject) + content["code"] - elif ("unsigned int" in method["type"]) and ("*" not in method["type"]): - content["code"] = (" nassertr(%s != NULL, -1);\n\n" % nxObject) + content["code"] - elif ("unsigned short" in method["type"]) and ("*" not in method["type"]): - content["code"] = (" nassertr(%s != NULL, -1);\n\n" % nxObject) + content["code"] - elif ("LVecBase3f" in method["type"]) and ("*" not in method["type"]): - content["code"] = (" nassertr(%s != NULL, *((LVecBase3f *)NULL));\n\n" % nxObject) + content["code"] - elif ("LMatrix3f" in method["type"]) and ("*" not in method["type"]): - content["code"] = (" nassertr(%s != NULL, *((LMatrix3f *)NULL));\n\n" % nxObject) + content["code"] - elif ("LMatrix4f" in method["type"]) and ("*" not in method["type"]): - content["code"] = (" nassertr(%s != NULL, *((LMatrix4f *)NULL));\n\n" % nxObject) + content["code"] - elif ("LQuaternionf" in method["type"]) and ("*" not in method["type"]): - content["code"] = (" nassertr(%s != NULL, *((LQuaternionf *)NULL));\n\n" % nxObject) + content["code"] - elif ("PhysxScene" in method["type"]) and ("*" not in method["type"]): - content["code"] = (" nassertr(%s != NULL, *((PhysxScene *)NULL));\n\n" % nxObject) + content["code"] - elif ("PhysxJointState" in method["type"]) and ("*" not in method["type"]): - content["code"] = (" nassertr(%s != NULL, physx_js_unbound);\n\n" % nxObject) + content["code"] - elif "*" in method["type"]: - content["code"] = (" nassertr(%s != NULL, NULL);\n\n" % nxObject) + content["code"] - - else: - content["code"] = "" - - result += methodString % content - - return result - -def getAttributeSource( className, attributeDict, doInline=False ): - if className in avoidPointerNames: - attribOperator = "." - else: - attribOperator = "->" - - methodDict = {} - - for name in attributeDict.keys(): - type = attributeDict[name]["type"] - rawType = getRawType( type ) - if (rawType not in builtinTypes) and (not type.endswith( "*" )) and (not convertFromFunctions.has_key( rawType )) and (rawType not in enumerations.keys()): - type += " &" - setterValue = wrapValue( type, "value", isReturnValue=False ) - getter = { - "type" : type, - "const" : True, - "params" : [], - "code" : " return %%s%s%s;" % (attribOperator, attributeDict[name]["originalName"]), - "originalName" : getMixedCaseFromUnderscored( "get_" + name ), - } - setter = { - "type" : "void", - "const" : False, - "params" : [[type.replace( "INLINE", "" ).strip(), "value"]], - "code" : " %%s%s%s = %s;" % (attribOperator, attributeDict[name]["originalName"], setterValue), - "originalName" : getMixedCaseFromUnderscored( "set_" + name ), - } - methodDict["get_" + name] = getter - methodDict["set_" + name] = setter - - if "INLINE" in type: - setter["type"] = "INLINE void" - - if convertFromFunctions.has_key( rawType ): - valueString = "%%s%s%s" % (attribOperator, attributeDict[name]["originalName"]) - getter["code"] = " return %s;" % getConvertedValue( type, valueString, False ) - getter["type"] = type - elif rawType in enumerations.keys(): - valueString = "%%s%s%s" % (attribOperator, attributeDict[name]["originalName"]) - getter["code"] = " return %s;" % wrapValue( rawType, valueString, isReturnValue=True ) - elif rawType.startswith( "Physx" ) and isBuiltName( rawType[5:] ): - getter["code"] = ' throw "Not Implemented"; // return %%s%s%s;' % (attribOperator, attributeDict[name]["originalName"]) - - return getMethodSource( className, methodDict, doInline=doInline, doCode=True ) - -def getParamString( params ): - items = ["%s %s" % (param[0], param[1]) for param in params] - return ", ".join( items ) - -def getCallerParamString( params ): - items = [] - for param in params: - items.append( wrapValue( param[0], param[1] ) ) - return ", ".join( items ) - -def wrapValue( type, valueString, isReturnValue=False ): - rawType = getRawType( type ) - if rawType in builtinTypes: - return valueString - elif (not isReturnValue) and convertFromFunctions.has_key( rawType ): - return getConvertedValue( type, valueString, not isReturnValue ) - elif isReturnValue and convertToFunctions.has_key( rawType ): - return getConvertedValue( type, valueString, not isReturnValue ) - elif rawType.startswith( "Physx" ) and isBuiltName( rawType[5:] ): - if isReturnValue: - if "*" in type: - return "(%s *)(%s->userData)" % (rawType, valueString) - else: - return "*((%s *)(%s.userData))" % (rawType, valueString) - else: - if "*" in type: - if rawType[5:] in avoidPointerNames: - return "&(%s->%s)" % (valueString, "n" + rawType[5:]) - else: - return "%s->%s" % (valueString, "n" + rawType[5:]) - else: - if rawType[5:] in avoidPointerNames: - return "%s.%s" % (valueString, "n" + rawType[5:]) - else: - return "*(%s.%s)" % (valueString, "n" + rawType[5:]) - elif rawType in enumerations.keys(): - if isReturnValue: - return "(%s)%s" % (rawType, valueString) - else: - return "(%s)%s" % ("Nx" + rawType[5:], valueString) - else: - return valueString - -def isNameKnown( name ): - if name in allBuiltNames: - return True - elif name in classNameConversions.values(): - return True - elif enumerations.has_key( "Physx" + name ): - return True - else: - return False - -def isBuiltName( name ): - return (name in allBuiltNames) or (name in classNameConversions.values()) - -def getUnderscoredFromMixedCase( name ): - return re.sub( r"(?<=[a-z])[A-Z]|(?", name ).lower() - -def getMixedCaseFromUnderscored( name ): - return re.sub( r"_([a-z])", lambda m: (m.group( 1 ).upper()), name ) - -def lowerFirst( name ): - return name[0].lower() + name[1:] - -def getRawType( type ): - rawType = type.replace( "const", "" ) - rawType = rawType.replace( "INLINE", "" ) - rawType = rawType.strip( " *&" ) - return rawType - -def getConvertedValue( type, valueString, convertFrom=True ): - rawType = getRawType( type ) - if convertFrom: - func = convertFromFunctions[rawType] - else: - func = convertToFunctions[rawType] - if "*" in type: - return "&%s(*%s)" % (func, valueString) - else: - return "%s(%s)" % (func, valueString) - -def generateEnumerationFile(): - global enumerations - enumerations = {} - locations = {} - for group in ("cloth", "fluids", "foundation", "physics", "softbody"): - getEnumerations( group, enumerations, locations ) - - enumerationContent = [] - enumerationContentForInterrogate = [] - names = enumerations.keys() - names.sort() - for name in names: - if name not in ["PhysxMemoryType"]: - enumerationContent.append( "enum %s {\n" % name ) - enumerationContentForInterrogate.append( "enum %s {\n" % name ) - nonInitializedItems, namesToInitializers = enumerations[name] - for nxValue in nonInitializedItems: - parts = nxValue.split( "_" )[1:] - parts = ["physx"] + [part.lower() for part in parts] - physxValue = "_".join( parts ) - enumerationContent.append( " %s = %s,\n" % (physxValue, nxValue) ) - enumerationContentForInterrogate.append( " %s,\n" % physxValue ) - for nxValue in namesToInitializers.keys(): - parts = nxValue.split( "_" )[1:] - parts = ["physx"] + [part.lower() for part in parts] - physxValue = "_".join( parts ) - enumerationContent.append( " %s = %s,\n" % (physxValue, nxValue) ) - - initializer = namesToInitializers[nxValue] - enumerationContentForInterrogate.append( " %s = %s,\n" % (physxValue, initializer) ) - - enumerationContent.append( "};\n\n" ) - enumerationContentForInterrogate.append( "};\n\n" ) - - enumerationTemplate = """// Filename: physx_enumerations.h -// Created by: pratt (Apr 20, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifndef PHYSX_ENUMERATIONS_H -#define PHYSX_ENUMERATIONS_H - -#ifdef HAVE_PHYSX - -#include "NoMinMax.h" -#include "NxPhysics.h" - -%s - -#endif // HAVE_PHYSX - -#endif // PHYSX_ENUMERATIONS_H -""" - - outputFile = file( "generated/physx_enumerations.h", "w" ) - outputFile.write( enumerationTemplate % "".join( enumerationContent ) ) - outputFile.close() - - outputFile = file( "generated/physx_enumerations_for_interrogate.h", "w" ) - outputFile.write( enumerationTemplate % "".join( enumerationContentForInterrogate ) ) - outputFile.close() - -def getEnumerations( group, enumerations, locations ): - xmlfile = file( os.path.join( docDir, "group__%s.xml" % group ) ) - doc = xmltramp.seed( xmlfile ) - xmlfile.close() - - for section in doc.compounddef["sectiondef":]: - if section( "kind" ) == "enum": - for enumeration in section["memberdef":]: - name = str( enumeration.name ).replace( "Nx", "Physx" ) - nonInitializedItems = [] - namesToInitializers = {} - for value in enumeration["enumvalue":]: - try: - initializer = str( value.initializer ) - try: - eval( initializer ) - namesToInitializers[str( value.name )] = initializer - except: - # Avoid creating enum values that we know will - # not work, i.e. bitwise ORs of previous values. - pass - except: - nonInitializedItems.append( str( value.name ) ) - enumerations[name] = (nonInitializedItems, namesToInitializers) - location = os.path.basename( str( enumeration["location"]( "file" ) ) ) - if group == "cloth": - location = "cloth/" + location - elif group == "fluids": - location = "fluids/" + location - elif group == "softbody": - location = "softbody/" + location - locations[location] = True - -def generateSourcesPP( names ): - templateFile = file( "SourcesTemplate.pp" ) - templateString = templateFile.read() - templateFile.close() - - headerLines = [] - sourceLines = [] - - for name in names: - if name == "Actor": - name = "ActorNode" - headerLines.append( " physx%s.I physx%s.h \\\n" % (name, name) ) - sourceLines.append( " physx%s.cxx \\\n" % name ) - - headersPattern = re.compile( "//headers" ) - cxxPattern = re.compile( "//cxx" ) - - templateString = headersPattern.sub( "".join( headerLines ), templateString ) - templateString = cxxPattern.sub( "".join( sourceLines ), templateString ) - - outputFile = file( "generated/Sources.pp", "w" ) - outputFile.write( templateString ) - outputFile.close() - -buildNowNames = [ - "Actor", - "ActorDesc", - "BodyDesc", - "Bounds3", - "Box", - "Joint", - "D6Joint", - "JointDesc", - "D6JointDesc", - "JointDriveDesc", - "JointLimitSoftDesc", - "JointLimitSoftPairDesc", - "Material", - "MaterialDesc", - "Plane", - "Ray", - "Scene", - "SceneDesc", - "SceneStats2", - "Segment", - "Capsule", - "Shape", - "BoxShape", - "CapsuleShape", - "PlaneShape", - "SphereShape", - "ShapeDesc", - "BoxShapeDesc", - "CapsuleShapeDesc", - "PlaneShapeDesc", - "SphereShapeDesc", - "Sphere", - "UtilLib", -] -buildNowStructs = [ -] - -allBuiltNames = [ - "Actor", - "ActorDesc", - "BodyDesc", - "Bounds3", - "Box", - "Joint", - "D6Joint", - "JointDesc", - "D6JointDesc", - "JointDriveDesc", - "JointLimitSoftDesc", - "JointLimitSoftPairDesc", - "Material", - "MaterialDesc", - "Plane", - "Ray", - "Scene", - "SceneDesc", - "SceneStats2", - "Segment", - "Capsule", - "Shape", - "BoxShape", - "CapsuleShape", - "PlaneShape", - "SphereShape", - "ShapeDesc", - "BoxShapeDesc", - "CapsuleShapeDesc", - "PlaneShapeDesc", - "SphereShapeDesc", - "Sphere", - "UtilLib", -] - -expectedNames = [ - "Actor", - "ActorDesc", - "BodyDesc", - "Bounds3", - "Box", - "Cloth", - "ClothDesc", - "ClothMesh", - "ContactPair", - "ContactStreamIterator", - "ConvexMesh", - "ConvexMeshDesc", - "Effector", - "SpringAndDamperEffector", - "Fluid", - "FluidDesc", - "FluidEmitter", - "FluidEmitterDesc", - "GroupsMask", - "HeightField", - "HeightFieldDesc", - "Joint", - "CylindricalJoint", - "D6Joint", - "DistanceJoint", - "FixedJoint", - "PointInPlaneJoint", - "PointOnLineJoint", - "PrismaticJoint", - "PulleyJoint", - "RevoluteJoint", - "SphericalJoint", - "JointDesc", - "CylindricalJointDesc", - "D6JointDesc", - "DistanceJointDesc", - "FixedJointDesc", - "PointInPlaneJointDesc", - "PointOnLineJointDesc", - "PrismaticJointDesc", - "PulleyJointDesc", - "RevoluteJointDesc", - "SphericalJointDesc", - "JointDriveDesc", - "JointLimitDesc", - "JointLimitPairDesc", - "JointLimitSoftDesc", - "JointLimitSoftPairDesc", - "Material", - "MaterialDesc", - "MeshData", - "MotorDesc", - "PairFlag", - "ParticleData", - "Plane", - "PMap", - "Ray", - "Scene", - "SceneDesc", - "SceneStats2", - "Segment", - "Capsule", - "Shape", - "BoxShape", - "CapsuleShape", - "ConvexShape", - "PlaneShape", - "SphereShape", - "TriangleMeshShape", - "WheelShape", - "ShapeDesc", - "BoxShapeDesc", - "CapsuleShapeDesc", - "ConvexShapeDesc", - "PlaneShapeDesc", - "SphereShapeDesc", - "TriangleMeshShapeDesc", - "WheelShapeDesc", - "SimpleTriangleMesh", - "ClothMeshDesc", - "TriangleMeshDesc", - "Sphere", - "SpringAndDamperEffectorDesc", - "SpringDesc", - "TireFunctionDesc", - "UtilLib", - "WheelContactData", -] - -avoidPointerNames = [ - "ActorDesc", - "ActorDescBase", - "BodyDesc", - "ClothDesc", - "ConvexMeshDesc", - "FluidDesc", - "FluidEmitterDesc", - "HeightFieldDesc", - "CylindricalJointDesc", - "D6JointDesc", - "DistanceJointDesc", - "FixedJointDesc", - "PointInPlaneJointDesc", - "PointOnLineJointDesc", - "PrismaticJointDesc", - "PulleyJointDesc", - "RevoluteJointDesc", - "SphericalJointDesc", - "JointDriveDesc", - "JointLimitDesc", - "JointLimitPairDesc", - "JointLimitSoftDesc", - "JointLimitSoftPairDesc", - "MaterialDesc", - "MotorDesc", - "SceneDesc", - "ShapeDesc", - "BoxShapeDesc", - "CapsuleShapeDesc", - "ConvexShapeDesc", - "PlaneShapeDesc", - "SphereShapeDesc", - "TriangleMeshShapeDesc", - "WheelShapeDesc", - "ClothMeshDesc", - "TriangleMeshDesc", - "SpringAndDamperEffectorDesc", - "SpringDesc", - "TireFunctionDesc", -] - -if __name__ == "__main__": - if not os.path.exists( "generated" ): - os.mkdir( "generated" ) - generateEnumerationFile() - generateSourcesPP( allBuiltNames ) - for name in buildNowNames: - print name - generateClassCode( name ) - for name in buildNowStructs: - print name - generateClassCode( name, isStruct=True ) - diff --git a/panda/src/physx/physxActor.I b/panda/src/physx/physxActor.I new file mode 100644 index 0000000000..8595c7bbdb --- /dev/null +++ b/panda/src/physx/physxActor.I @@ -0,0 +1,72 @@ +// Filename: physxActor.I +// Created by: enn0x (14Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxActor:: +PhysxActor() : PhysxObject() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxActor:: +~PhysxActor() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxActor:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxActor:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " " << get_name( ) + << " (at 0x" << this << ")"; + + if (!_np.is_empty()) { + out << " NP:" << _np; + } + + if (_controller) { + out << " C:0x" << _controller; + } + + out << "\n"; + + _shapes.ls(out, indent_level); +} + diff --git a/panda/src/physx/physxActor.cxx b/panda/src/physx/physxActor.cxx new file mode 100644 index 0000000000..2232cfe9c4 --- /dev/null +++ b/panda/src/physx/physxActor.cxx @@ -0,0 +1,1663 @@ +// Filename: physxActor.cxx +// Created by: enn0x (14Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxActor.h" +#include "physxActorDesc.h" +#include "physxBodyDesc.h" +#include "physxShapeDesc.h" +#include "physxManager.h" + +TypeHandle PhysxActor::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +link(NxActor *actorPtr) { + + // Link self + _ptr = actorPtr; + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_actors.add(this); + + // Link shapes + NxShape * const *shapes = _ptr->getShapes(); + NxU32 nShapes = _ptr->getNbShapes(); + + for (NxU32 i=0; i < nShapes; i++) { + if (shapes[i]->getName() == NULL) shapes[i]->setName(""); + + PT(PhysxShape) shape = PhysxShape::factory(shapes[i]->getType()); + shape->link(shapes[i]); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +unlink() { + + // Unlink shapes + NxShape * const *shapes = _ptr->getShapes(); + NxU32 nShapes = _ptr->getNbShapes(); + + for (NxU32 i=0; i < nShapes; i++) { + PT(PhysxShape) shape = (PhysxShape *)shapes[i]->userData; + shape->unlink(); + } + + // Unlink self + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_actors.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::release +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +release() { + + nassertv(_error_type == ET_ok); + + unlink(); + _ptr->getScene().releaseActor(*_ptr); + _ptr = NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::link_controller +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +link_controller(PT(PhysxController) controller) { + + _controller = controller; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::save_body_to_desc +// Access: Published +// Description: Saves the body information of a dynamic actor to +// the passed body descriptor. +//////////////////////////////////////////////////////////////////// +bool PhysxActor:: +save_body_to_desc(PhysxBodyDesc &bodyDesc) const { + + nassertr(_error_type == ET_ok, false); + return _ptr->saveBodyToDesc(bodyDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::save_to_desc +// Access: Published +// Description: Saves the state of the actor to the passed +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +save_to_desc(PhysxActorDesc &actorDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(actorDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_name +// Access: Published +// Description: Sets a name string for the object that can be +// retrieved with get_name(). +// This is for debugging and is not used by the +// engine. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_name(const char *name) { + + nassertv(_error_type == ET_ok); + _ptr->setName(name); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_name +// Access: Published +// Description: Retrieves the name string. +//////////////////////////////////////////////////////////////////// +const char *PhysxActor:: +get_name() const { + + nassertr(_error_type == ET_ok, ""); + return _ptr->getName(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::update_transform +// Access: Public +// Description: Updates the transform of an assigned NodePath. If +// the actor has been created by a PhysxController +// then this method will update the NodePath's +// transform from the controller's transform. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +update_transform(const LMatrix4f m) { + + // Active transforms are update AFTER scene.fetchResults() has + // been called, and thus can contain removed objects. So either + // update transforms after scene.fetchResults() - which means + // poor performance - or check if an actor has been removed here + // in this method. + if (_error_type != ET_ok) return; + + if (_np.is_empty()) return; + + if (_controller) { + LVector3f hpr(_controller->get_h(), 0.0f, 0.0f); + LPoint3f pos = _controller->get_pos(); + _np.set_transform(_np.get_top(), TransformState::make_pos_hpr(pos, hpr)); + } + else { + _np.set_transform(_np.get_top(), TransformState::make_mat(m)); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_global_pos +// Access: Published +// Description: Retrieves the actors world space position. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxActor:: +get_global_pos() const { + + nassertr(_error_type == ET_ok, LPoint3f::zero()); + return PhysxManager::nxVec3_to_point3(_ptr->getGlobalPosition()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_global_mat +// Access: Published +// Description: Retrieves the actors world space transform. +//////////////////////////////////////////////////////////////////// +LMatrix4f PhysxActor:: +get_global_mat() const { + + nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat()); + return PhysxManager::nxMat34_to_mat4(_ptr->getGlobalPose()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_global_quat +// Access: Published +// Description: Retrieves the actors world space orientation. +//////////////////////////////////////////////////////////////////// +LQuaternionf PhysxActor:: +get_global_quat() const { + + nassertr(_error_type == ET_ok, LQuaternionf::zero()); + return PhysxManager::nxQuat_to_quat(_ptr->getGlobalOrientation()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_global_pos +// Access: Published +// Description: Method for setting a dynamic actor's position in +// the world. Please see set_global_mat for some +// caveats. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_global_pos(const LPoint3f &pos) { + + nassertv(_error_type == ET_ok); + nassertv_always(!pos.is_nan()); + + _ptr->setGlobalPosition(PhysxManager::point3_to_nxVec3(pos)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_global_mat +// Access: Published +// Description: Method for setting a dynamic actor's transform +// matrix in the world. +// +// This method instantaneously changes the actor space +// to world space transformation. +// +// One should exercise restraint in making use of +// these methods. +// +// Static actors should not be moved at all. There are +// various internal data structures for static actors +// which may need to be recomputed when one moves. +// Also, moving static actors will not interact +// correctly with dynamic actors or joints. If you +// would like to directly control an actor's position +// and would like to have it correctly interact with +// dynamic bodies and joints, you should create a +// dynamic body with the BF_kinematic flag, and then +// use the move_lobal_*() commands to move it along +// a path! +// +// When briefly moving dynamic actors, one should not: +// - Move actors into other actors, thus causing +// interpenetration (an invalid physical state). +// - Move an actor that is connected by a joint to +// another away from the other (thus causing joint +// error). +// - When moving jointed actors the joints' cached +// transform information is destroyed and recreated +// next frame; thus this call is expensive for +// jointed actors. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_global_mat(const LMatrix4f &mat) { + + nassertv(_error_type == ET_ok); + nassertv_always(!mat.is_nan()); + + _ptr->setGlobalPose(PhysxManager::mat4_to_nxMat34(mat)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_global_hpr +// Access: Published +// Description: Method for setting a dynamic actor's orientation in +// the world. Please see set_global_mat for some +// caveats. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_global_hpr(float h, float p, float r) { + + nassertv(_error_type == ET_ok); + + LQuaternionf q; + q.set_hpr(LVector3f(h, p, r)); + _ptr->setGlobalOrientationQuat(PhysxManager::quat_to_nxQuat(q)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::attach_node_path +// Access: Published +// Description: Attaches a node path to this actor. The node +// path's transform will be updated automatically if +// the actor's transform changes (and only then). +// +// Note: any non-uniform scale or shear set on the +// NodePath's transform will be overwritten at the +// time of the first update. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +attach_node_path(const NodePath &np) { + + nassertv(_error_type == ET_ok); + nassertv_always(!np.is_empty()); + + _np = NodePath(np); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::detach_node_path +// Access: Published +// Description: Detaches a previously assigned NodePath from this +// actor. The NodePath's transform will no longer +// be updated from the actor's transform. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +detach_node_path() { + + nassertv(_error_type == ET_ok); + + _np = NodePath(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_node_path +// Access: Published +// Description: Retrieves a previously attached NodePath. An empty +// NodePath will be returned if no NodePath has been +// attached to this actor. +//////////////////////////////////////////////////////////////////// +NodePath PhysxActor:: +get_node_path() const { + + nassertr(_error_type == ET_ok, NodePath::fail()); + + return _np; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_scene +// Access: Published +// Description: Retrieves the scene which this actor belongs to. +//////////////////////////////////////////////////////////////////// +PT(PhysxScene) PhysxActor:: +get_scene() const { + + nassertr(_error_type == ET_ok, NULL); + + NxScene *scenePtr = &(_ptr->getScene()); + PhysxScene *scene = (PhysxScene *)(scenePtr->userData); + + return scene; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_num_shapes +// Access: Published +// Description: Returns the number of shapes assigned to the +// actor. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxActor:: +get_num_shapes() const { + + nassertr(_error_type == ET_ok, -1); + + return _ptr->getNbShapes(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::create_shape +// Access: Published +// Description: Creates a new shape and adds it to the list of +// shapes of this actor. +// +// Mass properties of dynamic actors will not +// automatically be recomputed to reflect the new mass +// distribution implied by the shape. Follow this call +// with a call to update_mass_from_shapes() to do +// that. +//////////////////////////////////////////////////////////////////// +PT(PhysxShape) PhysxActor:: +create_shape(PhysxShapeDesc &desc) { + + nassertr(_error_type == ET_ok, NULL); + nassertr(desc.is_valid(),NULL); + + PT(PhysxShape) shape = PhysxShape::factory(desc.ptr()->getType()); + nassertr(shape, NULL); + + NxShape *shapePtr = _ptr->createShape(*desc.ptr()); + nassertr(shapePtr, NULL); + + shape->link(shapePtr); + + return shape; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_shape +// Access: Published +// Description: Retrieves an individual shape from the actor's +// array of shapes. Index must be in the range from +// zero to (number-of-shapes minus 1). +//////////////////////////////////////////////////////////////////// +PT(PhysxShape) PhysxActor:: +get_shape(unsigned int idx) const { + + nassertr(_error_type == ET_ok, NULL); + nassertr_always(idx < _ptr->getNbShapes(), NULL); + + NxShape * const *shapes = _ptr->getShapes(); + NxShape *shapePtr = shapes[idx]; + PhysxShape *shape = (PhysxShape *)(shapePtr->userData); + + return shape; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_shape_by_name +// Access: Published +// Description: Retrieves an individual shape from the actor's +// array of shapes. The first shape for which the +// shape's name matches the specified name is +// returned, or NULL if no shape has a matching name. +//////////////////////////////////////////////////////////////////// +PT(PhysxShape) PhysxActor:: +get_shape_by_name(const char *name) const { + + nassertr(_error_type == ET_ok, NULL); + + NxShape * const *shapes = _ptr->getShapes(); + NxShape *shapePtr = NULL; + NxU32 nShapes = _ptr->getNbShapes(); + + for (NxU32 i=0; i < nShapes; i++) { + shapePtr = shapes[i]; + + if (strcmp(shapePtr->getName(), name) == 0) { + return (PhysxShape *) shapePtr->userData; + } + } + + return NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::add_force +// Access: Published +// Description: Applies a force (or impulse) defined in the global +// coordinate frame to the actor. +// +// This will not induce a torque. +// +// Mode determines if the torque is to be conventional +// or impulsive. +// +// The actor must be dynamic. +// This call wakes the actor if it is sleeping and the +// wakeup parameter is true (default). +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +add_force(const LVector3f force, PhysxForceMode mode, bool wakeup) { + + nassertv(_error_type == ET_ok); + nassertv_always(!force.is_nan()); + + _ptr->addForce(PhysxManager::vec3_to_nxVec3(force), (NxForceMode)mode, wakeup); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::add_force_at_pos +// Access: Published +// Description: Applies a force (or impulse) defined in the global +// coordinate frame, acting at a particular point in +// global coordinates, to the actor. +// +// Note that if the force does not act along the +// center of mass of the actor, this will also add the +// corresponding torque. Because forces are reset at +// the end of every timestep, you can maintain a total +// external force on an object by calling this once +// every frame. +// +// Mode determines if the torque is to be conventional +// or impulsive. +// +// The actor must be dynamic. +// This call wakes the actor if it is sleeping and the +// wakeup parameter is true (default). +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +add_force_at_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode, bool wakeup) { + + nassertv(_error_type == ET_ok); + nassertv_always(!force.is_nan()); + nassertv_always(!pos.is_nan()); + + _ptr->addForceAtPos(PhysxManager::vec3_to_nxVec3(force), PhysxManager::point3_to_nxVec3(pos), (NxForceMode)mode, wakeup); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::add_force_at_local_pos +// Access: Published +// Description: Applies a force (or impulse) defined in the global +// coordinate frame, acting at a particular point in +// local coordinates, to the actor. +// +// Note that if the force does not act along the +// center of mass of the actor, this will also add +// the corresponding torque. Because forces are reset +// at the end of every timestep, you can maintain a +// total external force on an object by calling this +// once every frame. +// +// Mode determines if the torque is to be conventional +// or impulsive. +// +// The actor must be dynamic. +// This call wakes the actor if it is sleeping and the +// wakeup parameter is true (default). +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +add_force_at_local_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode, bool wakeup) { + + nassertv(_error_type == ET_ok); + nassertv_always(!force.is_nan()); + nassertv_always(!pos.is_nan()); + + _ptr->addForceAtLocalPos(PhysxManager::vec3_to_nxVec3(force), PhysxManager::point3_to_nxVec3(pos), (NxForceMode)mode, wakeup); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::add_torque +// Access: Published +// Description: Applies an impulsive torque defined in the global +// coordinate frame to the actor. +// +// Mode determines if the torque is to be conventional +// or impulsive. +// +// The actor must be dynamic. +// This call wakes the actor if it is sleeping and the +// wakeup parameter is true (default). +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +add_torque(const LVector3f torque, PhysxForceMode mode, bool wakeup) { + + nassertv(_error_type == ET_ok); + nassertv_always(!torque.is_nan()); + + _ptr->addTorque(PhysxManager::vec3_to_nxVec3(torque), (NxForceMode)mode, wakeup); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::add_local_force +// Access: Published +// Description: Applies a force (or impulse) defined in the actor +// local coordinate frame to the actor. +// This will not induce a torque. +// +// Mode determines if the torque is to be conventional +// or impulsive. +// +// The actor must be dynamic. +// This call wakes the actor if it is sleeping and the +// wakeup parameter is true (default). +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +add_local_force(const LVector3f force, PhysxForceMode mode, bool wakeup) { + + nassertv(_error_type == ET_ok); + nassertv_always(!force.is_nan()); + + _ptr->addLocalForce(PhysxManager::vec3_to_nxVec3(force), (NxForceMode)mode, wakeup); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::add_local_force_at_pos +// Access: Published +// Description: Applies a force (or impulse) defined in the actor +// local coordinate frame, acting at a particular +// point in global coordinates, to the actor. +// +// Note that if the force does not act along the +// center of mass of the actor, this will also add +// the corresponding torque. Because forces are reset +// at the end of every timestep, you can maintain a +// total external force on an object by calling this +// once every frame. +// +// Mode determines if the torque is to be conventional +// or impulsive. +// +// The actor must be dynamic. +// This call wakes the actor if it is sleeping and the +// wakeup parameter is true (default). +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +add_local_force_at_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode, bool wakeup) { + + nassertv(_error_type == ET_ok); + nassertv_always(!force.is_nan()); + nassertv_always(!pos.is_nan()); + + _ptr->addLocalForceAtPos(PhysxManager::vec3_to_nxVec3(force), PhysxManager::point3_to_nxVec3(pos), (NxForceMode)mode, wakeup); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::add_local_force_at_local_pos +// Access: Published +// Description: Applies a force (or impulse) defined in the actor +// local coordinate frame, acting at a particular +// point in local coordinates, to the actor. +// +// Note that if the force does not act along the +// center of mass of the actor, this will also add the +// corresponding torque. Because forces are reset at +// the end of every timestep, you can maintain a total +// external force on an object by calling this once +// every frame. +// +// Mode determines if the torque is to be conventional +// or impulsive. +// +// The actor must be dynamic. +// This call wakes the actor if it is sleeping and the +// wakeup parameter is true (default). +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +add_local_force_at_local_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode, bool wakeup) { + + nassertv(_error_type == ET_ok); + nassertv_always(!force.is_nan()); + nassertv_always(!pos.is_nan()); + + _ptr->addLocalForceAtLocalPos(PhysxManager::vec3_to_nxVec3(force), PhysxManager::point3_to_nxVec3(pos), (NxForceMode)mode, wakeup); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::add_local_torque +// Access: Published +// Description: Applies an impulsive torque defined in the actor +// local coordinate frame to the actor. +// +// Mode determines if the torque is to be conventional +// or impulsive. +// +// The actor must be dynamic. +// This call wakes the actor if it is sleeping and the +// wakeup parameter is true (default). +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +add_local_torque(const LVector3f torque, PhysxForceMode mode, bool wakeup) { + + nassertv(_error_type == ET_ok); + nassertv_always(!torque.is_nan()); + + _ptr->addLocalTorque(PhysxManager::vec3_to_nxVec3(torque), (NxForceMode)mode, wakeup); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::update_mass_from_shapes +// Access: Published +// Description: Recomputes a dynamic actor's mass properties from +// its shapes. +// +// Given a constant density or total mass, the actors +// mass properties can be recomputed using the shapes +// attached to the actor. If the actor has no shapes, +// then only the totalMass parameter can be used. If +// all shapes in the actor are trigger shapes +// (non-physical), the call will fail. +// +// The mass of each shape is either the shape's local +// density (as specified in the PhysxShapeDesc; +// default 1.0) multiplied by the shape's volume or a +// directly specified shape mass. +// +// The inertia tensor, mass frame and center of mass +// will always be recomputed. If there are no shapes +// in the actor, the mass will be totalMass, and the +// mass frame will be set to the center of the actor. +// +// If you supply a non-zero total mass, the actor's +// mass and inertia will first be computed as above +// and then scaled to fit this total mass. +// +// If you supply a non-zero density, the actor's mass +// and inertia will first be computed as above and +// then scaled by this factor. +// +// Either totalMass or density must be non-zero. +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +bool PhysxActor:: +update_mass_from_shapes(float density, float totalMass) { + + nassertr(_error_type == ET_ok, false); + return _ptr->updateMassFromShapes(density, totalMass); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::compute_kinetic_energy +// Access: Published +// Description: Computes the total kinetic (rotational and +// translational) energy of the object. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +float PhysxActor:: +compute_kinetic_energy() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->computeKineticEnergy(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::is_dynamic +// Access: Published +// Description: Returns true if the actor is dynamic. +//////////////////////////////////////////////////////////////////// +bool PhysxActor:: +is_dynamic() const { + + nassertr(_error_type == ET_ok, false); + return _ptr->isDynamic(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_shape_group +// Access: Published +// Description: Sets the collision group for all shapes of this +// actor. See PhysxShape.setGroup(). +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_shape_group(unsigned int group) { + + nassertv(_error_type == ET_ok); + nassertv(group >= 0 && group < 32); + + NxShape * const *shapes = _ptr->getShapes(); + NxU32 nShapes = _ptr->getNbShapes(); + + for (NxU32 i=0; i < nShapes; i++) { + shapes[i]->setGroup( group ); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_body_flag +// Access: Published +// Description: Raise or lower individual BodyFlag flags. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_body_flag(PhysxBodyFlag flag, bool value) { + + if (value == true) { + _ptr->raiseBodyFlag((NxBodyFlag)flag); + } + else { + _ptr->clearBodyFlag((NxBodyFlag)flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_body_flag +// Access: Published +// Description: Return the specified BodyFlag flag. +//////////////////////////////////////////////////////////////////// +bool PhysxActor:: +get_body_flag(PhysxBodyFlag flag) const { + + nassertr(_error_type == ET_ok, false); + return ptr()->readBodyFlag((NxBodyFlag)flag); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_actor_flag +// Access: Published +// Description: Raise or lower individual ActorFlag flags. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_actor_flag(PhysxActorFlag flag, bool value) { + + if (value == true) { + _ptr->raiseActorFlag((NxActorFlag)flag); + } + else { + _ptr->clearActorFlag((NxActorFlag)flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_actor_flag +// Access: Published +// Description: Return the specified ActorFlag flag. +//////////////////////////////////////////////////////////////////// +bool PhysxActor:: +get_actor_flag(PhysxActorFlag flag) const { + + nassertr(_error_type == ET_ok, false); + return ptr()->readActorFlag((NxActorFlag)flag); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_contact_report_flag +// Access: Published +// Description: Sets the actor's contact report flags. +// +// These flags are used to determine the kind of +// report that is generated for interactions with +// other actors. +// +// Please note: If the actor is part of an interacting +// pair for which the contact report generation is +// controlled already through any other mechanism +// (for example by use of +// PhysxScene::set_actor_pair_flags) +// then the union of all the specified contact report +// flags will be used to generate the report. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_contact_report_flag(PhysxContactPairFlag flag, bool value) { + + nassertv(_error_type == ET_ok); + + NxU32 flags = _ptr->getContactReportFlags(); + + if (value == true) { + flags |= flag; + } + else { + flags &= ~(flag); + } + + _ptr->setContactReportFlags(flags); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_contact_report_threshold +// Access: Published +// Description: Sets the force threshold for contact reports. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_contact_report_threshold(float threshold) { + + nassertv(_error_type == ET_ok); + nassertv(threshold >= 0.0f); + + _ptr->setContactReportThreshold(threshold); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_group +// Access: Published +// Description: Assigns the actor to a user defined group of +// actors. The actor group must be an integer in +// between 0 and 0x7fff (32767). +// +// This is similar to NxShape groups, except those are +// only five bits and serve a different purpose. +// +// The PhysxScene::set_actor_group_pair_flags() lets +// you set certain behaviors for pairs of actor +// groups. +// +// By default every actor is created in group 0. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_group(unsigned int group) { + + nassertv(_error_type == ET_ok); + nassertv(group >= 0 && group < 0x8000); + + ptr()->setGroup(group); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_group +// Access: Published +// Description: Retrieves the actor group this actor is assigned +// to. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxActor:: +get_group() const { + + nassertr(_error_type == ET_ok, 0); + + return ptr()->getGroup(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_dominance_group +// Access: Published +// Description: Assigns dynamic actors a dominance group +// identifier. Dominance groups are integere in the +// range from 0 to 31. +// +// This is similar to shape groups, except those serve +// a different purpose. +// +// The PhysxScene::set_dominance_group_pair() lets you +// set certain behaviors for pairs of dominance +// groups. +// +// By default every actor is created in group 0. +// Static actors must stay in group 0; thus you can +// only call this on dynamic actors. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_dominance_group(unsigned int group) { + + nassertv(_error_type == ET_ok); + nassertv(group >= 0 && group < 32); + nassertv(is_dynamic() == true); + + _ptr->setDominanceGroup(group); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_dominance_group +// Access: Published +// Description: Retrieves the dominance group of this actor. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxActor:: +get_dominance_group() const { + + nassertr(_error_type == ET_ok, 0); + + return ptr()->getDominanceGroup(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_angular_damping +// Access: Published +// Description: Sets the angular damping coefficient. Zero +// represents no damping. The angular damping +// coefficient must be nonnegative. The actor must be +// dynamic. +// Default: 0.05 +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_angular_damping(float angDamp) { + + nassertv(_error_type == ET_ok); + nassertv(angDamp >= 0.0f); + + _ptr->setAngularDamping(angDamp); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_angular_damping +// Access: Published +// Description: Returns the angular damping coefficient. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +float PhysxActor:: +get_angular_damping() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getAngularDamping(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_linear_damping +// Access: Published +// Description: Sets the linear damping coefficient. Zero +// represents no damping. The damping coefficient must +// be nonnegative. The actor must be dynamic. +// Default: 0 +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_linear_damping(float linDamp) { + + nassertv(_error_type == ET_ok); + nassertv(linDamp >= 0.0f); + + _ptr->setLinearDamping(linDamp); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_linear_damping +// Access: Published +// Description: Retrieves the linear damping coefficient. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +float PhysxActor:: +get_linear_damping() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getLinearDamping(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_linear_velocity +// Access: Published +// Description: Sets the linear velocity of the actor. +// +// Note that if you continuously set the velocity of +// an actor yourself, forces such as gravity or +// friction will not be able to manifest themselves, +// because forces directly influence only the +// velocity/momentum of an actor. +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_linear_velocity(const LVector3f &linVel) { + + nassertv(_error_type == ET_ok); + nassertv(_ptr->isDynamic()); + + _ptr->setLinearVelocity(PhysxManager::vec3_to_nxVec3(linVel)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_angular_velocity +// Access: Published +// Description: Sets the angular velocity of the actor. +// +// Note that if you continuously set the angular +// velocity of an actor yourself, forces such as +// friction will not be able to rotate the actor, +// because forces directly influence only the +// velocity/momentum. +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_angular_velocity(const LVector3f &angVel) { + + nassertv(_error_type == ET_ok); + nassertv(_ptr->isDynamic()); + + _ptr->setAngularVelocity(PhysxManager::vec3_to_nxVec3(angVel)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_max_angular_velocity +// Access: Published +// Description: Lets you set the maximum angular velocity permitted +// for this actor. +// +// Because for various internal computations, very +// quickly rotating actors introduce error into the +// simulation, which leads to undesired results. +// +// With PhysxManager::set_parameter(PP_max_angular_velocity) +// you can set the default maximum velocity for actors +// created after the call. Bodies' high angular +// velocities are clamped to this value. +// +// However, because some actors, such as car wheels, +// should be able to rotate quickly, you can override +// the default setting on a per-actor basis with the +// below call. Note that objects such as wheels which +// are approximated with spherical or other smooth +// collision primitives can be simulated with +// stability at a much higher angular velocity than, +// say, a box that has corners. +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_max_angular_velocity(float maxAngVel) { + + nassertv(_error_type == ET_ok); + nassertv(_ptr->isDynamic()); + + _ptr->setMaxAngularVelocity(maxAngVel); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_linear_velocity +// Access: Published +// Description: Returns the linear velocity of an actor. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxActor:: +get_linear_velocity() const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(_ptr->getLinearVelocity()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_angular_velocity +// Access: Published +// Description: Returns the angular velocity of the actor. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxActor:: +get_angular_velocity() const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(_ptr->getAngularVelocity()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_max_angular_velocity +// Access: Published +// Description: Returns the maximum angular velocity permitted +// for this actor. +//////////////////////////////////////////////////////////////////// +float PhysxActor:: +get_max_angular_velocity() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getMaxAngularVelocity(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_point_velocity +// Access: Published +// Description: Computes the velocity of a point given in world +// coordinates if it were attached to the actor and +// moving with it. +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxActor:: +get_point_velocity(const LPoint3f &point) const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + nassertr_always(!point.is_nan(), LVector3f::zero()); + + NxVec3 nPoint = PhysxManager::point3_to_nxVec3(point); + return PhysxManager::nxVec3_to_vec3(_ptr->getPointVelocity(nPoint)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_local_point_velocity +// Access: Published +// Description: Computes the velocity of a point given in body +// local coordinates as if it were attached to the +// actor and moving with it. +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxActor:: +get_local_point_velocity(const LPoint3f &point) const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + nassertr_always(!point.is_nan(), LVector3f::zero()); + + NxVec3 nPoint = PhysxManager::point3_to_nxVec3(point); + return PhysxManager::nxVec3_to_vec3(_ptr->getLocalPointVelocity(nPoint)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_linear_momentum +// Access: Published +// Description: Sets the linear momentum of the actor. +// Note that if you continuously set the linear +// momentum of an actor yourself, forces such as +// gravity or friction will not be able to manifest +// themselves, because forces directly influence only +// the velocity/momentum of a actor. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_linear_momentum(const LVector3f &momentum) { + + nassertv(_error_type == ET_ok); + _ptr->setLinearMomentum(PhysxManager::vec3_to_nxVec3(momentum)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_angular_momentum +// Access: Published +// Description: Sets the angular momentum of the actor. +// Note that if you continuously set the angular +// velocity of an actor yourself, forces such as +// friction will not be able to rotate the actor, +// because forces directly influence only the velocity +// of actor. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_angular_momentum(const LVector3f &momentum) { + + nassertv(_error_type == ET_ok); + _ptr->setAngularMomentum(PhysxManager::vec3_to_nxVec3(momentum)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_linear_momentum +// Access: Published +// Description: Retrieves the linear momentum of an actor. +// The momentum is equal to the velocity times the +// mass. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxActor:: +get_linear_momentum() const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(_ptr->getLinearMomentum()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_angular_momentum +// Access: Published +// Description: Retrieves the angular momentum of an actor. +// The angular momentum is equal to the angular +// velocity times the global space inertia tensor. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxActor:: +get_angular_momentum() const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(_ptr->getAngularMomentum()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_sleep_linear_velocity +// Access: Published +// Description: Sets the linear velocity below which an actor may +// go to sleep. Actors whose linear velocity is above +// this threshold will not be put to sleep. +// +// Setting the sleep angular/linear velocity only +// makes sense when the BF_energy_sleep_test is not +// set. +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_sleep_linear_velocity(float threshold) { + + nassertv(_error_type == ET_ok); + _ptr->setSleepLinearVelocity(threshold); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_sleep_angular_velocity +// Access: Published +// Description: Sets the angular velocity below which an actor may +// go to sleep. Actors whose angular velocity is +// above this threshold will not be put to sleep. +// +// Setting the sleep angular/linear velocity only +// makes sense when the BF_energy_sleep_test is not +// set. +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_sleep_angular_velocity(float threshold) { + + nassertv(_error_type == ET_ok); + _ptr->setSleepAngularVelocity(threshold); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_sleep_energy_threshold +// Access: Published +// Description: Sets the energy threshold below which an actor may +// go to sleep. Actors whose kinematic energy is above +// this threshold will not be put to sleep. +// +// Setting the sleep energy threshold only makes sense +// when the BF_energy_sleep_test is set. There are +// also other types of sleeping that uses the linear +// and angular velocities directly instead of the +// energy. +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_sleep_energy_threshold(float threshold) { + + nassertv(_error_type == ET_ok); + _ptr->setSleepEnergyThreshold(threshold); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_sleep_linear_velocity +// Access: Published +// Description: Returns the linear velocity below which an actor +// may go to sleep. Actors whose linear velocity is +// above this threshold will not be put to sleep. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +float PhysxActor:: +get_sleep_linear_velocity() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getSleepLinearVelocity(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_sleep_angular_velocity +// Access: Published +// Description: Returns the angular velocity below which an actor +// may go to sleep. Actors whose angular velocity is +// above this threshold will not be put to sleep. +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +float PhysxActor:: +get_sleep_angular_velocity() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getSleepAngularVelocity(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_sleep_energy_threshold +// Access: Published +// Description: Returns the energy below which an actor may go to +// sleep. Actors whose energy is above this threshold +// will not be put to sleep. The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +float PhysxActor:: +get_sleep_energy_threshold() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getSleepEnergyThreshold(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::is_sleeping +// Access: Published +// Description: Returns true if this body is sleeping. +// +// When an actor does not move for a period of time, +// it is no longer simulated in order to save time. +// This state is called sleeping. However, because the +// object automatically wakes up when it is either +// touched by an awake object, or one of its +// properties is changed by the user, the entire sleep +// mechanism should be transparent to the user. +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +bool PhysxActor:: +is_sleeping() const { + + nassertr(_error_type == ET_ok, false); + return _ptr->isSleeping(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::wake_up +// Access: Published +// Description: Wakes up the actor if it is sleeping. +// +// The wakeCounterValue determines how long until the +// body is put to sleep, a value of zero means that +// the body is sleeping. wake_up(0) is equivalent to +// PhysxActor::put_to_sleep(). +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +wake_up(float wakeCounterValue) { + + nassertv(_error_type == ET_ok); + _ptr->wakeUp(wakeCounterValue); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::put_to_sleep +// Access: Published +// Description: Forces the actor to sleep. +// +// The actor will stay asleep until the next call to +// simulate, and will not wake up until then even when +// otherwise it would (for example a force is applied +// to it). It can however wake up during the next +// do_physics call. +// +// The actor must be dynamic. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +put_to_sleep() { + + nassertv(_error_type == ET_ok); + _ptr->putToSleep(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_mass +// Access: Published +// Description: Sets the mass of a dynamic actor. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_mass(float mass) { + + nassertv(_error_type == ET_ok); + _ptr->setMass(mass); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_mass +// Access: Published +// Description: Returns the mass of the actor. +//////////////////////////////////////////////////////////////////// +float PhysxActor:: +get_mass() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getMass(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_c_mass_offset_local_mat +// Access: Published +// Description: Sets the matrix of the center of mass relative +// to the actor. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_c_mass_offset_local_mat(const LMatrix4f &mat) { + + nassertv(_error_type == ET_ok); + _ptr->setCMassOffsetLocalPose(PhysxManager::mat4_to_nxMat34(mat)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_c_mass_offset_local_pos +// Access: Published +// Description: Sets the position of the center of mass relative +// to the actor. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_c_mass_offset_local_pos(const LPoint3f &pos) { + + nassertv(_error_type == ET_ok); + _ptr->setCMassOffsetLocalPosition(PhysxManager::point3_to_nxVec3(pos)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_c_mass_offset_local_orientation +// Access: Published +// Description: Sets the orientation of the center of mass relative +// to the actor. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_c_mass_offset_local_orientation(const LMatrix3f &mat) { + + nassertv(_error_type == ET_ok); + _ptr->setCMassOffsetLocalOrientation(PhysxManager::mat3_to_nxMat33(mat)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_c_mass_offset_global_mat +// Access: Published +// Description: Sets the matrix of the center of mass relative +// to world space. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_c_mass_offset_global_mat(const LMatrix4f &mat) { + + nassertv(_error_type == ET_ok); + _ptr->setCMassOffsetGlobalPose(PhysxManager::mat4_to_nxMat34(mat)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_c_mass_offset_global_pos +// Access: Published +// Description: Sets the position of the center of mass relative +// to world space. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_c_mass_offset_global_pos(const LPoint3f &pos) { + + nassertv(_error_type == ET_ok); + _ptr->setCMassOffsetGlobalPosition(PhysxManager::point3_to_nxVec3(pos)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_c_mass_offset_global_orientation +// Access: Published +// Description: Sets the orientation of the center of mass relative +// to world space. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_c_mass_offset_global_orientation(const LMatrix3f &mat) { + + nassertv(_error_type == ET_ok); + _ptr->setCMassOffsetGlobalOrientation(PhysxManager::mat3_to_nxMat33(mat)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_c_mass_global_mat +// Access: Published +// Description: Moves the actor by setting the transform of the +// center of mass. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_c_mass_global_mat(const LMatrix4f &mat) { + + nassertv(_error_type == ET_ok); + _ptr->setCMassGlobalPose(PhysxManager::mat4_to_nxMat34(mat)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_c_mass_global_pos +// Access: Published +// Description: Moves the actor by setting the position of the +// center of mass. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_c_mass_global_pos(const LPoint3f &pos) { + + nassertv(_error_type == ET_ok); + _ptr->setCMassGlobalPosition(PhysxManager::point3_to_nxVec3(pos)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_c_mass_global_orientation +// Access: Published +// Description: Moves the actor by setting the orientation of the +// center of mass. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_c_mass_global_orientation(const LMatrix3f &mat) { + + nassertv(_error_type == ET_ok); + _ptr->setCMassGlobalOrientation(PhysxManager::mat3_to_nxMat33(mat)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::set_mass_space_inertia_tensor +// Access: Published +// Description: Sets the inertia tensor, using a parameter +// specified in mass space coordinates. +//////////////////////////////////////////////////////////////////// +void PhysxActor:: +set_mass_space_inertia_tensor(const LVector3f &m) { + + nassertv(_error_type == ET_ok); + _ptr->setMassSpaceInertiaTensor(PhysxManager::vec3_to_nxVec3(m)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_c_mass_global_mat +// Access: Published +// Description: Returns the center of mass transform in world +// space. +//////////////////////////////////////////////////////////////////// +LMatrix4f PhysxActor:: +get_c_mass_global_mat() const { + + nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat()); + return PhysxManager::nxMat34_to_mat4(_ptr->getCMassGlobalPose()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_c_mass_global_pos +// Access: Published +// Description: Returns the center of mass position in world +// space. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxActor:: +get_c_mass_global_pos() const { + + nassertr(_error_type == ET_ok, LPoint3f::zero()); + return PhysxManager::nxVec3_to_point3(_ptr->getCMassGlobalPosition()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_c_mass_global_orientation +// Access: Published +// Description: Returns the center of mass orientation in world +// space. +//////////////////////////////////////////////////////////////////// +LMatrix3f PhysxActor:: +get_c_mass_global_orientation() const { + + nassertr(_error_type == ET_ok, LMatrix3f::ident_mat()); + return PhysxManager::nxMat33_to_mat3(_ptr->getCMassGlobalOrientation()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_c_mass_local_mat +// Access: Published +// Description: Returns the center of mass transform relative +// to the actor. +//////////////////////////////////////////////////////////////////// +LMatrix4f PhysxActor:: +get_c_mass_local_mat() const { + + nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat()); + return PhysxManager::nxMat34_to_mat4(_ptr->getCMassLocalPose()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_c_mass_local_pos +// Access: Published +// Description: Returns the center of mass position relative to +// the actor. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxActor:: +get_c_mass_local_pos() const { + + nassertr(_error_type == ET_ok, LPoint3f::zero()); + return PhysxManager::nxVec3_to_point3(_ptr->getCMassLocalPosition()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_c_mass_local_orientation +// Access: Published +// Description: Returns the center of mass orientation relative to +// the actor. +//////////////////////////////////////////////////////////////////// +LMatrix3f PhysxActor:: +get_c_mass_local_orientation() const { + + nassertr(_error_type == ET_ok, LMatrix3f::ident_mat()); + return PhysxManager::nxMat33_to_mat3(_ptr->getCMassLocalOrientation()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_mass_space_inertia_tensor +// Access: Published +// Description: Returns the diagonal inertia tensor of the actor +// relative to the mass coordinate frame. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxActor:: +get_mass_space_inertia_tensor() const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(_ptr->getMassSpaceInertiaTensor()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_global_inertia_tensor +// Access: Published +// Description: Returns the inertia tensor of the actor relative +// to the world coordinate frame. +//////////////////////////////////////////////////////////////////// +LMatrix3f PhysxActor:: +get_global_inertia_tensor() const { + + nassertr(_error_type == ET_ok, LMatrix3f::ident_mat()); + return PhysxManager::nxMat33_to_mat3(_ptr->getGlobalInertiaTensor()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActor::get_global_inertia_tensor_inverse +// Access: Published +// Description: Returns the inverse of the inertia tensor of the +// actor relative to the world coordinate frame. +//////////////////////////////////////////////////////////////////// +LMatrix3f PhysxActor:: +get_global_inertia_tensor_inverse() const { + + nassertr(_error_type == ET_ok, LMatrix3f::ident_mat()); + return PhysxManager::nxMat33_to_mat3(_ptr->getGlobalInertiaTensorInverse()); +} + diff --git a/panda/src/physx/physxActor.h b/panda/src/physx/physxActor.h new file mode 100644 index 0000000000..af57be2233 --- /dev/null +++ b/panda/src/physx/physxActor.h @@ -0,0 +1,227 @@ +// Filename: physxActor.h +// Created by: enn0x (14Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXACTOR_H +#define PHYSXACTOR_H + +#include "pandabase.h" +#include "nodePath.h" +#include "lmatrix.h" +#include "lvector3.h" +#include "lpoint3.h" +#include "lquaternion.h" + +#include "physxObject.h" +#include "physxObjectCollection.h" +#include "physxEnums.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxController; +class PhysxScene; +class PhysxShape; +class PhysxShapeDesc; +class PhysxActorDesc; +class PhysxBodyDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxActor +// Description : Actors are the main simulation objects. Actors +// are owned by a scene (PhysxScene). +// +// An actor may optionally encapsulate a dynamic rigid +// body by setting the body member of the actor's +// descriptor when it is created. Otherwise the actor +// will be static (fixed in the world). +// +// Instances of PhysxActor are created by calling +// PhysxScene::create_actor() and destroyed by calling +// PhysxActor::release(). +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxActor : public PhysxObject, public PhysxEnums { + +PUBLISHED: + INLINE PhysxActor(); + INLINE ~PhysxActor(); + + bool save_body_to_desc(PhysxBodyDesc &bodyDesc) const; + void save_to_desc(PhysxActorDesc &actorDesc) const; + + void set_name(const char *name); + void set_global_pos(const LPoint3f &pos); + void set_global_mat(const LMatrix4f &mat); + void set_global_hpr(float h, float p, float r); + void set_body_flag(PhysxBodyFlag flag, bool value); + void set_actor_flag(PhysxActorFlag flag, bool value); + void set_contact_report_flag(PhysxContactPairFlag flag, bool value); + void set_contact_report_threshold(float threshold); + void set_group(unsigned int group); + void set_dominance_group(unsigned int group); + void set_shape_group( unsigned int group ); + + const char *get_name() const; + LPoint3f get_global_pos() const; + LMatrix4f get_global_mat() const; + LQuaternionf get_global_quat() const; + bool get_body_flag(PhysxBodyFlag flag) const; + bool get_actor_flag(PhysxActorFlag flag) const; + unsigned int get_group() const; + unsigned int get_dominance_group() const; + + bool is_dynamic() const; + float compute_kinetic_energy() const; + bool update_mass_from_shapes(float density, float totalMass); + + PT(PhysxScene) get_scene() const; + + // NodePath + void attach_node_path(const NodePath &np); + void detach_node_path(); + NodePath get_node_path() const; + + // Shapes + unsigned int get_num_shapes() const; + PT(PhysxShape) create_shape(PhysxShapeDesc &desc); + PT(PhysxShape) get_shape(unsigned int idx) const; + PT(PhysxShape) get_shape_by_name(const char *name) const; + MAKE_SEQ(get_shapes, get_num_shapes, get_shape); + + // Forces + void add_force(const LVector3f force, + PhysxForceMode mode=FM_force, bool wakeup=true); + void add_force_at_pos(const LVector3f force, const LPoint3f &pos, + PhysxForceMode mode=FM_force, bool wakeup=true); + void add_force_at_local_pos(const LVector3f force, const LPoint3f &pos, + PhysxForceMode mode=FM_force, bool wakeup=true); + void add_torque(const LVector3f torque, + PhysxForceMode mode=FM_force, bool wakeup=true); + void add_local_force(const LVector3f force, + PhysxForceMode mode=FM_force, bool wakeup=true); + void add_local_force_at_pos(const LVector3f force, const LPoint3f &pos, + PhysxForceMode mode=FM_force, bool wakeup=true); + void add_local_force_at_local_pos(const LVector3f force, const LPoint3f &pos, + PhysxForceMode mode=FM_force, bool wakeup=true); + void add_local_torque(const LVector3f torque, + PhysxForceMode mode=FM_force, bool wakeup=true); + + // Mass manipulation + void set_mass(float mass); + void set_c_mass_offset_local_mat(const LMatrix4f &mat); + void set_c_mass_offset_local_pos(const LPoint3f &pos); + void set_c_mass_offset_local_orientation(const LMatrix3f &mat); + void set_c_mass_offset_global_mat(const LMatrix4f &mat); + void set_c_mass_offset_global_pos(const LPoint3f &pos); + void set_c_mass_offset_global_orientation(const LMatrix3f &mat); + void set_c_mass_global_mat(const LMatrix4f &mat); + void set_c_mass_global_pos(const LPoint3f &pos); + void set_c_mass_global_orientation(const LMatrix3f &mat); + void set_mass_space_inertia_tensor(const LVector3f &m); + + float get_mass() const; + LMatrix4f get_c_mass_global_mat() const; + LPoint3f get_c_mass_global_pos() const; + LMatrix3f get_c_mass_global_orientation() const; + LMatrix4f get_c_mass_local_mat() const; + LPoint3f get_c_mass_local_pos() const; + LMatrix3f get_c_mass_local_orientation() const; + LVector3f get_mass_space_inertia_tensor() const; + LMatrix3f get_global_inertia_tensor() const; + LMatrix3f get_global_inertia_tensor_inverse() const; + + // Damping + void set_linear_damping(float linDamp); + void set_angular_damping(float angDamp); + float get_linear_damping() const; + float get_angular_damping() const; + + // Vecocity + void set_linear_velocity(const LVector3f &linVel); + void set_angular_velocity(const LVector3f &angVel); + void set_max_angular_velocity(float maxAngVel); + + LVector3f get_linear_velocity() const; + LVector3f get_angular_velocity() const; + float get_max_angular_velocity() const; + + // Point Velocity + LVector3f get_point_velocity(const LPoint3f &point) const; + LVector3f get_local_point_velocity(const LPoint3f &point) const; + + // Momentum + void set_linear_momentum(const LVector3f &momentum); + void set_angular_momentum(const LVector3f &momentum); + LVector3f get_linear_momentum() const; + LVector3f get_angular_momentum() const; + + // Sleeping + void set_sleep_linear_velocity(float threshold); + void set_sleep_angular_velocity(float threshold); + void set_sleep_energy_threshold(float threshold); + float get_sleep_linear_velocity() const; + float get_sleep_angular_velocity() const; + float get_sleep_energy_threshold() const; + bool is_sleeping() const; + void wake_up(float wakeCounterValue=NX_SLEEP_INTERVAL); + void put_to_sleep(); + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +public: + void update_transform(const LMatrix4f m); + +//////////////////////////////////////////////////////////////////// +PUBLISHED: + void release(); + +public: + INLINE NxActor *ptr() const { return _ptr; }; + + void link_controller(PT(PhysxController) controller); + void link(NxActor *ptr); + void unlink(); + + PhysxObjectCollection _shapes; + +private: + NxActor *_ptr; + NodePath _np; + PT(PhysxController) _controller; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxObject::init_type(); + register_type(_type_handle, "PhysxActor", + PhysxObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxActor.I" + +#endif // PHYSXACTOR_H diff --git a/panda/src/physx/physxActorDesc.I b/panda/src/physx/physxActorDesc.I index 1e8a2f1165..9cee85cf7c 100644 --- a/panda/src/physx/physxActorDesc.I +++ b/panda/src/physx/physxActorDesc.I @@ -1,5 +1,5 @@ // Filename: physxActorDesc.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (05Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,64 +12,48 @@ // //////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxActorDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxActorDesc:: -is_valid() const { - return nActorDesc.isValid(); +INLINE PhysxActorDesc:: +PhysxActorDesc() { + + _desc.name = ""; } //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxActorDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxActorDesc:: +~PhysxActorDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActorDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. //////////////////////////////////////////////////////////////////// INLINE void PhysxActorDesc:: set_to_default() { - nActorDesc.setToDefault(); + + _desc.setToDefault(); } //////////////////////////////////////////////////////////////////// -// Function : get_density -// Access : Published -// Description : +// Function: PhysxActorDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. //////////////////////////////////////////////////////////////////// -INLINE float PhysxActorDesc:: -get_density() const { - return nActorDesc.density; +INLINE bool PhysxActorDesc:: +is_valid() const { + + return _desc.isValid(); } -//////////////////////////////////////////////////////////////////// -// Function : get_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxActorDesc:: -get_flags() const { - return nActorDesc.flags; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_density -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxActorDesc:: -set_density(float value) { - nActorDesc.density = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxActorDesc:: -set_flags(unsigned int value) { - nActorDesc.flags = value; -} - - diff --git a/panda/src/physx/physxActorDesc.cxx b/panda/src/physx/physxActorDesc.cxx index 52bd0ffd6b..a29f07b3cd 100644 --- a/panda/src/physx/physxActorDesc.cxx +++ b/panda/src/physx/physxActorDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxActorDesc.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (05Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,70 +12,159 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxActorDesc.h" -#include "physxShapeDesc.h" #include "physxBodyDesc.h" +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxActorDesc -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxActorDesc:: -PhysxActorDesc() { -} - -//////////////////////////////////////////////////////////////////// -// Function : add_shape -// Access : Published -// Description : +// Function: PhysxActorDesc::add_shape +// Access: Published +// Description: Adds a shape to the list of collision shapes +// composing this actor. //////////////////////////////////////////////////////////////////// void PhysxActorDesc:: -add_shape(PhysxShapeDesc pShapeDesc) { - nActorDesc.shapes.pushBack(pShapeDesc.nShapeDesc); +add_shape(PhysxShapeDesc &desc) { + + _desc.shapes.push_back(desc.ptr()); } //////////////////////////////////////////////////////////////////// -// Function : get_body -// Access : Published -// Description : +// Function: PhysxActorDesc::set_name +// Access: Published +// Description: Sets the optional debug name for the actor. //////////////////////////////////////////////////////////////////// -const PhysxBodyDesc * PhysxActorDesc:: +void PhysxActorDesc:: +set_name(const char *name) { + + _desc.name = name; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActorDesc::set_density +// Access: Published +// Description: Set the density used during mass/intertia +// computation. This value is used if the actor's +// shapes do not have a mass asigned. +//////////////////////////////////////////////////////////////////// +void PhysxActorDesc:: +set_density(float density) { + + _desc.density = density; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActorDesc::set_global_pos +// Access: Published +// Description: Set the position of the actor in global space. +//////////////////////////////////////////////////////////////////// +void PhysxActorDesc:: +set_global_pos(const LPoint3f &pos) { + + _desc.globalPose.t = PhysxManager::point3_to_nxVec3(pos); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActorDesc::set_global_mat +// Access: Published +// Description: Set the position and orientation of the actor +// in global space. Scaling and shear arenot +// supported, even if the matrix contains a scale or +// shear. +//////////////////////////////////////////////////////////////////// +void PhysxActorDesc:: +set_global_mat(const LMatrix4f &mat) { + + _desc.globalPose = PhysxManager::mat4_to_nxMat34(mat); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActorDesc::set_global_hpr +// Access: Published +// Description: Sets the orientation of the actor in global space +// by providing angles for heading, pitch and roll. +//////////////////////////////////////////////////////////////////// +void PhysxActorDesc:: +set_global_hpr(float h, float p, float r) { + + LQuaternionf q; + LMatrix3f rot; + NxMat34 m; + + q.set_hpr(LVector3f(h, p, r)); + q.extract_to_matrix(rot); + + _desc.globalPose.M = PhysxManager::mat3_to_nxMat33(rot); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActorDesc::set_body +// Access: Published +// Description: Sets the body descriptor for this actor. The actor +// will be dynmaic if a body descriptor is set, and +// static if no body descriptor is set. +//////////////////////////////////////////////////////////////////// +void PhysxActorDesc:: +set_body(PhysxBodyDesc &desc) { + + _desc.body = &(desc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActorDesc::get_body +// Access: Published +// Description: Gets the body descriptor for this actor. +//////////////////////////////////////////////////////////////////// +PhysxBodyDesc PhysxActorDesc:: get_body() const { - throw "Not Implemented"; // return nActorDesc.body; + + throw "Not Implemented"; + + //PhysxBodyDesc value; + //value._desc = *(_desc.body); + //return value; } //////////////////////////////////////////////////////////////////// -// Function : get_global_pose -// Access : Published -// Description : +// Function: PhysxActorDesc::get_name +// Access: Published +// Description: Returns the optional debug name for this actor. +//////////////////////////////////////////////////////////////////// +const char *PhysxActorDesc:: +get_name() const { + + return _desc.name; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActorDesc::get_density +// Access: Published +// Description: Returns the actor's density. +//////////////////////////////////////////////////////////////////// +float PhysxActorDesc:: +get_density() const { + + return _desc.density; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActorDesc::get_global_pos +// Access: Published +// Description: Returns the actor's position in global space. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxActorDesc:: +get_global_pos() const { + + return PhysxManager::nxVec3_to_point3(_desc.globalPose.t); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxActorDesc::get_global_mat +// Access: Published +// Description: Returns the actor's transform in global space. //////////////////////////////////////////////////////////////////// LMatrix4f PhysxActorDesc:: -get_global_pose() const { - return PhysxManager::nxMat34_to_lMatrix4(nActorDesc.globalPose); +get_global_mat() const { + + return PhysxManager::nxMat34_to_mat4(_desc.globalPose); } -//////////////////////////////////////////////////////////////////// -// Function : set_body -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorDesc:: -set_body(const PhysxBodyDesc * value) { - nActorDesc.body = &(value->nBodyDesc); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_global_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorDesc:: -set_global_pose(LMatrix4f value) { - nActorDesc.globalPose = PhysxManager::lMatrix4_to_nxMat34(value); -} - -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxActorDesc.h b/panda/src/physx/physxActorDesc.h index dc2e99db64..559dc4cd7c 100644 --- a/panda/src/physx/physxActorDesc.h +++ b/panda/src/physx/physxActorDesc.h @@ -1,5 +1,5 @@ // Filename: physxActorDesc.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (05Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,48 +15,48 @@ #ifndef PHYSXACTORDESC_H #define PHYSXACTORDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "lpoint3.h" +#include "lmatrix.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -class PhysxShapeDesc; -class PhysxBodyDesc; - +#include "NoMinMax.h" #include "NxPhysics.h" +class PhysxBodyDesc; +class PhysxShapeDesc; + //////////////////////////////////////////////////////////////////// // Class : PhysxActorDesc -// Description : +// Description : Descriptor for PhysxActor. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxActorDesc { + PUBLISHED: - PhysxActorDesc(); + INLINE PhysxActorDesc(); + INLINE ~PhysxActorDesc(); - INLINE bool is_valid() const; INLINE void set_to_default(); + INLINE bool is_valid() const; - void add_shape(PhysxShapeDesc pShapeDesc); + void add_shape(PhysxShapeDesc &desc); - const PhysxBodyDesc * get_body() const; - INLINE float get_density() const; - INLINE unsigned int get_flags() const; - LMatrix4f get_global_pose() const; + void set_name(const char *name); + void set_density(float density); + void set_global_pos(const LPoint3f &pos); + void set_global_mat(const LMatrix4f &mat); + void set_global_hpr(float h, float p, float r); + void set_body(PhysxBodyDesc &desc); - void set_body( const PhysxBodyDesc * value ); - INLINE void set_density( float value ); - INLINE void set_flags( unsigned int value ); - void set_global_pose( LMatrix4f value ); + const char *get_name() const; + float get_density() const; + LPoint3f get_global_pos() const; + LMatrix4f get_global_mat() const; + PhysxBodyDesc get_body() const; public: - NxActorDesc nActorDesc; + NxActorDesc _desc; }; #include "physxActorDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXACTORDESC_H diff --git a/panda/src/physx/physxActorNode.I b/panda/src/physx/physxActorNode.I deleted file mode 100644 index 54f24ed9ef..0000000000 --- a/panda/src/physx/physxActorNode.I +++ /dev/null @@ -1,79 +0,0 @@ -// Filename: physxActorNode.I -// Created by: pratt (Apr 7, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function : update_transform -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxActorNode:: -update_transform() { - _disable_transform_changed = true; - get_global_pose_optimized(&_tempMat4); - set_transform(TransformState::make_mat(_tempMat4)); - _disable_transform_changed = false; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_global_pose_optimized -// Access : Published -// Description : This is an optimized version of get_global_pose that -// copies the pose data to a passed matrix rather than -// returning a new matrix, and also optimizes the -// translation from PhysX matrix to Panda matrix. -// It is primarily intended to be used by the -// update_transform method, which is called in a tight -// loop when transforms are copied from the PhysX -// library to Panda. -//////////////////////////////////////////////////////////////////// -INLINE void PhysxActorNode:: -get_global_pose_optimized(LMatrix4f *result) { - nassertv(nActor != NULL); - - nActor->getGlobalPose().getColumnMajor44(_tempCells); - result->set( - _tempCells[0], _tempCells[1], _tempCells[2], _tempCells[3], - _tempCells[4], _tempCells[5], _tempCells[6], _tempCells[7], - _tempCells[8], _tempCells[9], _tempCells[10], _tempCells[11], - _tempCells[12], _tempCells[13], _tempCells[14], _tempCells[15] - ); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_global_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE LMatrix4f PhysxActorNode:: -get_global_pose() const { - nassertr(nActor != NULL, *((LMatrix4f *)NULL)); - - return PhysxManager::nxMat34_to_lMatrix4(nActor->getGlobalPose()); -} - -//////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : Returns true if the NxActor associated with this -// ActorNode is not NULL. The NxActor will be NULL if -// the ActorNode has been released. -//////////////////////////////////////////////////////////////////// -INLINE bool PhysxActorNode:: -is_valid() { - return nActor != NULL; -} - - - - diff --git a/panda/src/physx/physxActorNode.cxx b/panda/src/physx/physxActorNode.cxx deleted file mode 100644 index 0210a23641..0000000000 --- a/panda/src/physx/physxActorNode.cxx +++ /dev/null @@ -1,1190 +0,0 @@ -// Filename: physxActorNode.cxx -// Created by: pratt (Apr 7, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifdef HAVE_PHYSX - -#include "physxActorNode.h" - -#include "luse.h" -#include "physxBodyDesc.h" -#include "physxScene.h" -#include "physxShape.h" -#include "physxShapeDesc.h" -#include "physxBoxShape.h" -#include "physxCapsuleShape.h" -#include "physxPlaneShape.h" -#include "physxSphereShape.h" - -TypeHandle PhysxActorNode::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function : PhysxActorNode -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxActorNode:: -PhysxActorNode(const string &name) : PandaNode(name) { - _disable_transform_changed = false; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_num_shapes -// Access : Published -// Description : Returns the number of PhysxShapes associated with -// this PhysxActorNode. -//////////////////////////////////////////////////////////////////// -unsigned int PhysxActorNode:: -get_num_shapes() { - nassertr(nActor != NULL, -1); - - return nActor->getNbShapes(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_shape -// Access : Published -// Description : Returns the PhysxShape associated with this -// PhysxActorNode at index i. -//////////////////////////////////////////////////////////////////// -PhysxShape *PhysxActorNode:: -get_shape(unsigned int i) { - nassertr(nActor != NULL, NULL); - - if((i >= 0) && (i < nActor->getNbShapes())) { - NxShape * const* nShapes = nActor->getShapes(); - PhysxShape *pShape = (PhysxShape *)nShapes[i]->userData; - return pShape; - } else { - physx_warning( "PhysxActorNode::get_shape: " << this->get_name() << ": index out of bounds; i=" << i ); - return NULL; - } -} - -//////////////////////////////////////////////////////////////////// -// Function : add_force -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -add_force(const LVecBase3f & force, PhysxForceMode mode, bool wakeup) { - nassertv(nActor != NULL); - - nActor->addForce(PhysxManager::lVecBase3_to_nxVec3(force), (NxForceMode)mode, wakeup); -} - -//////////////////////////////////////////////////////////////////// -// Function : add_force_at_local_pos -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -add_force_at_local_pos(const LVecBase3f & force, const LVecBase3f & pos, PhysxForceMode mode, bool wakeup) { - nassertv(nActor != NULL); - - nActor->addForceAtLocalPos(PhysxManager::lVecBase3_to_nxVec3(force), PhysxManager::lVecBase3_to_nxVec3(pos), (NxForceMode)mode, wakeup); -} - -//////////////////////////////////////////////////////////////////// -// Function : add_force_at_pos -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -add_force_at_pos(const LVecBase3f & force, const LVecBase3f & pos, PhysxForceMode mode, bool wakeup) { - nassertv(nActor != NULL); - - nActor->addForceAtPos(PhysxManager::lVecBase3_to_nxVec3(force), PhysxManager::lVecBase3_to_nxVec3(pos), (NxForceMode)mode, wakeup); -} - -//////////////////////////////////////////////////////////////////// -// Function : add_local_force -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -add_local_force(const LVecBase3f & force, PhysxForceMode mode, bool wakeup) { - nassertv(nActor != NULL); - - nActor->addLocalForce(PhysxManager::lVecBase3_to_nxVec3(force), (NxForceMode)mode, wakeup); -} - -//////////////////////////////////////////////////////////////////// -// Function : add_local_force_at_local_pos -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -add_local_force_at_local_pos(const LVecBase3f & force, const LVecBase3f & pos, PhysxForceMode mode, bool wakeup) { - nassertv(nActor != NULL); - - nActor->addLocalForceAtLocalPos(PhysxManager::lVecBase3_to_nxVec3(force), PhysxManager::lVecBase3_to_nxVec3(pos), (NxForceMode)mode, wakeup); -} - -//////////////////////////////////////////////////////////////////// -// Function : add_local_force_at_pos -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -add_local_force_at_pos(const LVecBase3f & force, const LVecBase3f & pos, PhysxForceMode mode, bool wakeup) { - nassertv(nActor != NULL); - - nActor->addLocalForceAtPos(PhysxManager::lVecBase3_to_nxVec3(force), PhysxManager::lVecBase3_to_nxVec3(pos), (NxForceMode)mode, wakeup); -} - -//////////////////////////////////////////////////////////////////// -// Function : add_local_torque -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -add_local_torque(const LVecBase3f & torque, PhysxForceMode mode, bool wakeup) { - nassertv(nActor != NULL); - - nActor->addLocalTorque(PhysxManager::lVecBase3_to_nxVec3(torque), (NxForceMode)mode, wakeup); -} - -//////////////////////////////////////////////////////////////////// -// Function : add_torque -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -add_torque(const LVecBase3f & torque, PhysxForceMode mode, bool wakeup) { - nassertv(nActor != NULL); - - nActor->addTorque(PhysxManager::lVecBase3_to_nxVec3(torque), (NxForceMode)mode, wakeup); -} - -//////////////////////////////////////////////////////////////////// -// Function : clear_actor_flag -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -clear_actor_flag(PhysxActorFlag actor_flag) { - nassertv(nActor != NULL); - - nActor->clearActorFlag((NxActorFlag)actor_flag); -} - -//////////////////////////////////////////////////////////////////// -// Function : clear_body_flag -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -clear_body_flag(PhysxBodyFlag body_flag) { - nassertv(nActor != NULL); - - nActor->clearBodyFlag((NxBodyFlag)body_flag); -} - -//////////////////////////////////////////////////////////////////// -// Function : compute_kinetic_energy -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxActorNode:: -compute_kinetic_energy() const { - nassertr(nActor != NULL, -1.0f); - - return nActor->computeKineticEnergy(); -} - -//////////////////////////////////////////////////////////////////// -// Function : create_shape -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxShape * PhysxActorNode:: -create_shape(const PhysxShapeDesc & desc) { - nassertr(nActor != NULL, NULL); - - // Some pointer nastiness is required to cast PT(PhysxShape) to each - // specific shape type. - NxShape *nShape = nActor->createShape(*(desc.nShapeDesc)); - PT(PhysxShape) pShape; - PhysxShape *pShapePointer; - if(nShape->getType() == NX_SHAPE_BOX) { - pShape = new PhysxBoxShape(); - pShapePointer = (PhysxShape *)pShape; - ((PhysxBoxShape *)pShapePointer)->nBoxShape = (NxBoxShape *)nShape; - } else if(nShape->getType() == NX_SHAPE_CAPSULE) { - pShape = new PhysxCapsuleShape(); - pShapePointer = (PhysxShape *)pShape; - ((PhysxCapsuleShape *)pShapePointer)->nCapsuleShape = (NxCapsuleShape *)nShape; - } else if(nShape->getType() == NX_SHAPE_PLANE) { - pShape = new PhysxPlaneShape(); - pShapePointer = (PhysxShape *)pShape; - ((PhysxPlaneShape *)pShapePointer)->nPlaneShape = (NxPlaneShape *)nShape; - } else if(nShape->getType() == NX_SHAPE_SPHERE) { - pShape = new PhysxSphereShape(); - pShapePointer = (PhysxShape *)pShape; - ((PhysxSphereShape *)pShapePointer)->nSphereShape = (NxSphereShape *)nShape; - } - nShape->userData = pShape; - pShape->nShape = nShape; - return pShape; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_angular_damping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxActorNode:: -get_angular_damping() const { - nassertr(nActor != NULL, -1.0f); - - return nActor->getAngularDamping(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_angular_momentum -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxActorNode:: -get_angular_momentum() const { - nassertr(nActor != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nActor->getAngularMomentum()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxActorNode:: -get_angular_velocity() const { - nassertr(nActor != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nActor->getAngularVelocity()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_c_mass_global_orientation -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LMatrix3f PhysxActorNode:: -get_c_mass_global_orientation() const { - nassertr(nActor != NULL, *((LMatrix3f *)NULL)); - - return PhysxManager::nxMat33_to_lMatrix3(nActor->getCMassGlobalOrientation()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_c_mass_global_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LMatrix4f PhysxActorNode:: -get_c_mass_global_pose() const { - nassertr(nActor != NULL, *((LMatrix4f *)NULL)); - - return PhysxManager::nxMat34_to_lMatrix4(nActor->getCMassGlobalPose()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_c_mass_global_position -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxActorNode:: -get_c_mass_global_position() const { - nassertr(nActor != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nActor->getCMassGlobalPosition()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_c_mass_local_orientation -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LMatrix3f PhysxActorNode:: -get_c_mass_local_orientation() const { - nassertr(nActor != NULL, *((LMatrix3f *)NULL)); - - return PhysxManager::nxMat33_to_lMatrix3(nActor->getCMassLocalOrientation()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_c_mass_local_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LMatrix4f PhysxActorNode:: -get_c_mass_local_pose() const { - nassertr(nActor != NULL, *((LMatrix4f *)NULL)); - - return PhysxManager::nxMat34_to_lMatrix4(nActor->getCMassLocalPose()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_c_mass_local_position -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxActorNode:: -get_c_mass_local_position() const { - nassertr(nActor != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nActor->getCMassLocalPosition()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_ccd_motion_threshold -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxActorNode:: -get_ccd_motion_threshold() const { - nassertr(nActor != NULL, -1.0f); - - return nActor->getCCDMotionThreshold(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_global_inertia_tensor -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LMatrix3f PhysxActorNode:: -get_global_inertia_tensor() const { - nassertr(nActor != NULL, *((LMatrix3f *)NULL)); - - return PhysxManager::nxMat33_to_lMatrix3(nActor->getGlobalInertiaTensor()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_global_inertia_tensor_inverse -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LMatrix3f PhysxActorNode:: -get_global_inertia_tensor_inverse() const { - nassertr(nActor != NULL, *((LMatrix3f *)NULL)); - - return PhysxManager::nxMat33_to_lMatrix3(nActor->getGlobalInertiaTensorInverse()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_global_orientation -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LMatrix3f PhysxActorNode:: -get_global_orientation() const { - nassertr(nActor != NULL, *((LMatrix3f *)NULL)); - - return PhysxManager::nxMat33_to_lMatrix3(nActor->getGlobalOrientation()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_global_orientation_quat -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LQuaternionf PhysxActorNode:: -get_global_orientation_quat() const { - nassertr(nActor != NULL, *((LQuaternionf *)NULL)); - - return PhysxManager::nxQuat_to_lQuaternion(nActor->getGlobalOrientationQuat()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_global_position -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxActorNode:: -get_global_position() const { - nassertr(nActor != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nActor->getGlobalPosition()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_group -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned short PhysxActorNode:: -get_group() const { - nassertr(nActor != NULL, -1); - - return nActor->getGroup(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_linear_damping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxActorNode:: -get_linear_damping() const { - nassertr(nActor != NULL, -1.0f); - - return nActor->getLinearDamping(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_linear_momentum -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxActorNode:: -get_linear_momentum() const { - nassertr(nActor != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nActor->getLinearMomentum()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_linear_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxActorNode:: -get_linear_velocity() const { - nassertr(nActor != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nActor->getLinearVelocity()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_local_point_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxActorNode:: -get_local_point_velocity(const LVecBase3f & point) const { - nassertr(nActor != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nActor->getLocalPointVelocity(PhysxManager::lVecBase3_to_nxVec3(point))); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_mass -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxActorNode:: -get_mass() const { - nassertr(nActor != NULL, -1.0f); - - return nActor->getMass(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_mass_space_inertia_tensor -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxActorNode:: -get_mass_space_inertia_tensor() const { - nassertr(nActor != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nActor->getMassSpaceInertiaTensor()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_max_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxActorNode:: -get_max_angular_velocity() const { - nassertr(nActor != NULL, -1.0f); - - return nActor->getMaxAngularVelocity(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_shapes -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxActorNode:: -get_nb_shapes() const { - nassertr(nActor != NULL, -1); - - return nActor->getNbShapes(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_point_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxActorNode:: -get_point_velocity(const LVecBase3f & point) const { - nassertr(nActor != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nActor->getPointVelocity(PhysxManager::lVecBase3_to_nxVec3(point))); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_scene -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxScene & PhysxActorNode:: -get_scene() const { - nassertr(nActor != NULL, *((PhysxScene *)NULL)); - - return *((PhysxScene *)(nActor->getScene().userData)); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_sleep_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxActorNode:: -get_sleep_angular_velocity() const { - nassertr(nActor != NULL, -1.0f); - - return nActor->getSleepAngularVelocity(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_sleep_energy_threshold -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxActorNode:: -get_sleep_energy_threshold() const { - nassertr(nActor != NULL, -1.0f); - - return nActor->getSleepEnergyThreshold(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_sleep_linear_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxActorNode:: -get_sleep_linear_velocity() const { - nassertr(nActor != NULL, -1.0f); - - return nActor->getSleepLinearVelocity(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_solver_iteration_count -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxActorNode:: -get_solver_iteration_count() const { - nassertr(nActor != NULL, -1); - - return nActor->getSolverIterationCount(); -} - -//////////////////////////////////////////////////////////////////// -// Function : is_dynamic -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxActorNode:: -is_dynamic() const { - nassertr(nActor != NULL, false); - - return nActor->isDynamic(); -} - -//////////////////////////////////////////////////////////////////// -// Function : is_group_sleeping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxActorNode:: -is_group_sleeping() const { - nassertr(nActor != NULL, false); - - return nActor->isGroupSleeping(); -} - -//////////////////////////////////////////////////////////////////// -// Function : is_sleeping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxActorNode:: -is_sleeping() const { - nassertr(nActor != NULL, false); - - return nActor->isSleeping(); -} - -//////////////////////////////////////////////////////////////////// -// Function : move_global_orientation -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -move_global_orientation(const LMatrix3f & mat) { - nassertv(nActor != NULL); - - nActor->moveGlobalOrientation(PhysxManager::lMatrix3_to_nxMat33(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : move_global_orientation_quat -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -move_global_orientation_quat(const LQuaternionf & quat) { - nassertv(nActor != NULL); - - nActor->moveGlobalOrientationQuat(PhysxManager::lQuaternion_to_nxQuat(quat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : move_global_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -move_global_pose(const LMatrix4f & mat) { - nassertv(nActor != NULL); - - nActor->moveGlobalPose(PhysxManager::lMatrix4_to_nxMat34(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : move_global_position -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -move_global_position(const LVecBase3f & vec) { - nassertv(nActor != NULL); - - nActor->moveGlobalPosition(PhysxManager::lVecBase3_to_nxVec3(vec)); -} - -//////////////////////////////////////////////////////////////////// -// Function : put_to_sleep -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -put_to_sleep() { - nassertv(nActor != NULL); - - nActor->putToSleep(); -} - -//////////////////////////////////////////////////////////////////// -// Function : raise_actor_flag -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -raise_actor_flag(PhysxActorFlag actor_flag) { - nassertv(nActor != NULL); - - nActor->raiseActorFlag((NxActorFlag)actor_flag); -} - -//////////////////////////////////////////////////////////////////// -// Function : raise_body_flag -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -raise_body_flag(PhysxBodyFlag body_flag) { - nassertv(nActor != NULL); - - nActor->raiseBodyFlag((NxBodyFlag)body_flag); -} - -//////////////////////////////////////////////////////////////////// -// Function : read_actor_flag -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxActorNode:: -read_actor_flag(PhysxActorFlag actor_flag) const { - nassertr(nActor != NULL, false); - - return nActor->readActorFlag((NxActorFlag)actor_flag); -} - -//////////////////////////////////////////////////////////////////// -// Function : read_body_flag -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxActorNode:: -read_body_flag(PhysxBodyFlag body_flag) const { - nassertr(nActor != NULL, false); - - return nActor->readBodyFlag((NxBodyFlag)body_flag); -} - -//////////////////////////////////////////////////////////////////// -// Function : recompute_adaptive_force_counters -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -recompute_adaptive_force_counters() { - nassertv(nActor != NULL); - - nActor->recomputeAdaptiveForceCounters(); -} - -//////////////////////////////////////////////////////////////////// -// Function : release_shape -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -release_shape(PhysxShape & shape) { - nassertv(nActor != NULL); - - nActor->releaseShape(*(shape.nShape)); -} - -//////////////////////////////////////////////////////////////////// -// Function : reset_user_actor_pair_filtering -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -reset_user_actor_pair_filtering() { - nassertv(nActor != NULL); - - nActor->resetUserActorPairFiltering(); -} - -//////////////////////////////////////////////////////////////////// -// Function : save_body_to_desc -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxActorNode:: -save_body_to_desc(PhysxBodyDesc & body_desc) { - nassertr(nActor != NULL, false); - - return nActor->saveBodyToDesc(body_desc.nBodyDesc); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_angular_damping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_angular_damping(float ang_damp) { - nassertv(nActor != NULL); - - nActor->setAngularDamping(ang_damp); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_angular_momentum -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_angular_momentum(const LVecBase3f & ang_moment) { - nassertv(nActor != NULL); - - nActor->setAngularMomentum(PhysxManager::lVecBase3_to_nxVec3(ang_moment)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_angular_velocity(const LVecBase3f & ang_vel) { - nassertv(nActor != NULL); - - nActor->setAngularVelocity(PhysxManager::lVecBase3_to_nxVec3(ang_vel)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_c_mass_global_orientation -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_c_mass_global_orientation(const LMatrix3f & mat) { - nassertv(nActor != NULL); - - nActor->setCMassGlobalOrientation(PhysxManager::lMatrix3_to_nxMat33(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_c_mass_global_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_c_mass_global_pose(const LMatrix4f & mat) { - nassertv(nActor != NULL); - - nActor->setCMassGlobalPose(PhysxManager::lMatrix4_to_nxMat34(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_c_mass_global_position -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_c_mass_global_position(const LVecBase3f & vec) { - nassertv(nActor != NULL); - - nActor->setCMassGlobalPosition(PhysxManager::lVecBase3_to_nxVec3(vec)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_c_mass_offset_global_orientation -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_c_mass_offset_global_orientation(const LMatrix3f & mat) { - nassertv(nActor != NULL); - - nActor->setCMassOffsetGlobalOrientation(PhysxManager::lMatrix3_to_nxMat33(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_c_mass_offset_global_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_c_mass_offset_global_pose(const LMatrix4f & mat) { - nassertv(nActor != NULL); - - nActor->setCMassOffsetGlobalPose(PhysxManager::lMatrix4_to_nxMat34(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_c_mass_offset_global_position -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_c_mass_offset_global_position(const LVecBase3f & vec) { - nassertv(nActor != NULL); - - nActor->setCMassOffsetGlobalPosition(PhysxManager::lVecBase3_to_nxVec3(vec)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_c_mass_offset_local_orientation -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_c_mass_offset_local_orientation(const LMatrix3f & mat) { - nassertv(nActor != NULL); - - nActor->setCMassOffsetLocalOrientation(PhysxManager::lMatrix3_to_nxMat33(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_c_mass_offset_local_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_c_mass_offset_local_pose(const LMatrix4f & mat) { - nassertv(nActor != NULL); - - nActor->setCMassOffsetLocalPose(PhysxManager::lMatrix4_to_nxMat34(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_c_mass_offset_local_position -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_c_mass_offset_local_position(const LVecBase3f & vec) { - nassertv(nActor != NULL); - - nActor->setCMassOffsetLocalPosition(PhysxManager::lVecBase3_to_nxVec3(vec)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_ccd_motion_threshold -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_ccd_motion_threshold(float thresh) { - nassertv(nActor != NULL); - - nActor->setCCDMotionThreshold(thresh); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_global_orientation -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_global_orientation(const LMatrix3f & mat) { - nassertv(nActor != NULL); - - nActor->setGlobalOrientation(PhysxManager::lMatrix3_to_nxMat33(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_global_orientation_quat -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_global_orientation_quat(const LQuaternionf & mat) { - nassertv(nActor != NULL); - - nActor->setGlobalOrientationQuat(PhysxManager::lQuaternion_to_nxQuat(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_global_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_global_pose(const LMatrix4f & mat) { - nassertv(nActor != NULL); - - nActor->setGlobalPose(PhysxManager::lMatrix4_to_nxMat34(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_global_position -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_global_position(const LVecBase3f & vec) { - nassertv(nActor != NULL); - - nActor->setGlobalPosition(PhysxManager::lVecBase3_to_nxVec3(vec)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_group -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_group(unsigned short actor_group) { - nassertv(nActor != NULL); - - nActor->setGroup(actor_group); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_linear_damping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_linear_damping(float lin_damp) { - nassertv(nActor != NULL); - - nActor->setLinearDamping(lin_damp); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_linear_momentum -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_linear_momentum(const LVecBase3f & lin_moment) { - nassertv(nActor != NULL); - - nActor->setLinearMomentum(PhysxManager::lVecBase3_to_nxVec3(lin_moment)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_linear_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_linear_velocity(const LVecBase3f & lin_vel) { - nassertv(nActor != NULL); - - nActor->setLinearVelocity(PhysxManager::lVecBase3_to_nxVec3(lin_vel)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_mass -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_mass(float mass) { - nassertv(nActor != NULL); - - nActor->setMass(mass); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_mass_space_inertia_tensor -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_mass_space_inertia_tensor(const LVecBase3f & m) { - nassertv(nActor != NULL); - - nActor->setMassSpaceInertiaTensor(PhysxManager::lVecBase3_to_nxVec3(m)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_max_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_max_angular_velocity(float max_ang_vel) { - nassertv(nActor != NULL); - - nActor->setMaxAngularVelocity(max_ang_vel); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_sleep_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_sleep_angular_velocity(float threshold) { - nassertv(nActor != NULL); - - nActor->setSleepAngularVelocity(threshold); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_sleep_energy_threshold -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_sleep_energy_threshold(float threshold) { - nassertv(nActor != NULL); - - nActor->setSleepEnergyThreshold(threshold); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_sleep_linear_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_sleep_linear_velocity(float threshold) { - nassertv(nActor != NULL); - - nActor->setSleepLinearVelocity(threshold); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_solver_iteration_count -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -set_solver_iteration_count(unsigned int iter_count) { - nassertv(nActor != NULL); - - nActor->setSolverIterationCount(iter_count); -} - -//////////////////////////////////////////////////////////////////// -// Function : update_mass_from_shapes -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -update_mass_from_shapes(float density, float total_mass) { - nassertv(nActor != NULL); - - nActor->updateMassFromShapes(density, total_mass); -} - -//////////////////////////////////////////////////////////////////// -// Function : wake_up -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -wake_up(float wake_counter_value) { - nassertv(nActor != NULL); - - nActor->wakeUp(wake_counter_value); -} - -//////////////////////////////////////////////////////////////////// -// Function : transform_changed -// Access : private, virtual -// Description : node hook. This function handles outside -// (non-physics) actions on the PhysxActorNode -// and updates the internal representation of the node. -// i.e. copy from PandaNode to PhysxActor -//////////////////////////////////////////////////////////////////// -void PhysxActorNode:: -transform_changed() { - nassertv(nActor != NULL); - - PandaNode::transform_changed(); - - // _disable_transform_changed is used to prevent a recursive loop between - // transform_changed and update_transform. - if(_disable_transform_changed) { - return; - } - - if(nActor->isDynamic()) { - CPT(TransformState) transform = get_transform(); - if(nActor->readBodyFlag(NX_BF_KINEMATIC)) { - // If the Actor is kinematic, use moveGlobalPose - nActor->moveGlobalPose(PhysxManager::lMatrix4_to_nxMat34(transform->get_mat())); - } else { - // If the Actor is just dynamic, use setGlobalPose - nActor->setGlobalPose(PhysxManager::lMatrix4_to_nxMat34(transform->get_mat())); - } - } else { - // If the Actor is static, don't allow the transform to be updated - physx_error("Error: cannot update transform of static PhysxActorNode " << get_name()); - } -} - -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxActorNode.h b/panda/src/physx/physxActorNode.h deleted file mode 100644 index b691a4eb35..0000000000 --- a/panda/src/physx/physxActorNode.h +++ /dev/null @@ -1,178 +0,0 @@ -// Filename: physxActorNode.h -// Created by: pratt (Apr 7, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifndef PHYSXACTORNODE_H -#define PHYSXACTORNODE_H - -#ifdef HAVE_PHYSX - -#include "pandabase.h" -#include "pandaNode.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -class PhysxBodyDesc; -class PhysxScene; -class PhysxShape; -class PhysxShapeDesc; - -#include "NxPhysics.h" - -//////////////////////////////////////////////////////////////////// -// Class : PhysxActorNode -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxActorNode : public PandaNode { -PUBLISHED: - PhysxActorNode(const string &name); - - INLINE void update_transform(); - INLINE void get_global_pose_optimized(LMatrix4f *result); - - unsigned int get_num_shapes(); - PhysxShape *get_shape(unsigned int i); - INLINE bool is_valid(); - - void add_force(const LVecBase3f & force, PhysxForceMode mode, bool wakeup=true); - void add_force_at_local_pos(const LVecBase3f & force, const LVecBase3f & pos, PhysxForceMode mode, bool wakeup=true); - void add_force_at_pos(const LVecBase3f & force, const LVecBase3f & pos, PhysxForceMode mode, bool wakeup=true); - void add_local_force(const LVecBase3f & force, PhysxForceMode mode, bool wakeup=true); - void add_local_force_at_local_pos(const LVecBase3f & force, const LVecBase3f & pos, PhysxForceMode mode, bool wakeup=true); - void add_local_force_at_pos(const LVecBase3f & force, const LVecBase3f & pos, PhysxForceMode mode, bool wakeup=true); - void add_local_torque(const LVecBase3f & torque, PhysxForceMode mode, bool wakeup=true); - void add_torque(const LVecBase3f & torque, PhysxForceMode mode, bool wakeup=true); - void clear_actor_flag(PhysxActorFlag actor_flag); - void clear_body_flag(PhysxBodyFlag body_flag); - float compute_kinetic_energy() const; - PhysxShape * create_shape(const PhysxShapeDesc & desc); - float get_angular_damping() const; - LVecBase3f get_angular_momentum() const; - LVecBase3f get_angular_velocity() const; - LMatrix3f get_c_mass_global_orientation() const; - LMatrix4f get_c_mass_global_pose() const; - LVecBase3f get_c_mass_global_position() const; - LMatrix3f get_c_mass_local_orientation() const; - LMatrix4f get_c_mass_local_pose() const; - LVecBase3f get_c_mass_local_position() const; - float get_ccd_motion_threshold() const; - LMatrix3f get_global_inertia_tensor() const; - LMatrix3f get_global_inertia_tensor_inverse() const; - LMatrix3f get_global_orientation() const; - LQuaternionf get_global_orientation_quat() const; - INLINE LMatrix4f get_global_pose() const; - LVecBase3f get_global_position() const; - unsigned short get_group() const; - float get_linear_damping() const; - LVecBase3f get_linear_momentum() const; - LVecBase3f get_linear_velocity() const; - LVecBase3f get_local_point_velocity(const LVecBase3f & point) const; - float get_mass() const; - LVecBase3f get_mass_space_inertia_tensor() const; - float get_max_angular_velocity() const; - unsigned int get_nb_shapes() const; - LVecBase3f get_point_velocity(const LVecBase3f & point) const; - PhysxScene & get_scene() const; - float get_sleep_angular_velocity() const; - float get_sleep_energy_threshold() const; - float get_sleep_linear_velocity() const; - unsigned int get_solver_iteration_count() const; - bool is_dynamic() const; - bool is_group_sleeping() const; - bool is_sleeping() const; - void move_global_orientation(const LMatrix3f & mat); - void move_global_orientation_quat(const LQuaternionf & quat); - void move_global_pose(const LMatrix4f & mat); - void move_global_position(const LVecBase3f & vec); - void put_to_sleep(); - void raise_actor_flag(PhysxActorFlag actor_flag); - void raise_body_flag(PhysxBodyFlag body_flag); - bool read_actor_flag(PhysxActorFlag actor_flag) const; - bool read_body_flag(PhysxBodyFlag body_flag) const; - void recompute_adaptive_force_counters(); - void release_shape(PhysxShape & shape); - void reset_user_actor_pair_filtering(); - bool save_body_to_desc(PhysxBodyDesc & body_desc); - void set_angular_damping(float ang_damp); - void set_angular_momentum(const LVecBase3f & ang_moment); - void set_angular_velocity(const LVecBase3f & ang_vel); - void set_c_mass_global_orientation(const LMatrix3f & mat); - void set_c_mass_global_pose(const LMatrix4f & mat); - void set_c_mass_global_position(const LVecBase3f & vec); - void set_c_mass_offset_global_orientation(const LMatrix3f & mat); - void set_c_mass_offset_global_pose(const LMatrix4f & mat); - void set_c_mass_offset_global_position(const LVecBase3f & vec); - void set_c_mass_offset_local_orientation(const LMatrix3f & mat); - void set_c_mass_offset_local_pose(const LMatrix4f & mat); - void set_c_mass_offset_local_position(const LVecBase3f & vec); - void set_ccd_motion_threshold(float thresh); - void set_global_orientation(const LMatrix3f & mat); - void set_global_orientation_quat(const LQuaternionf & mat); - void set_global_pose(const LMatrix4f & mat); - void set_global_position(const LVecBase3f & vec); - void set_group(unsigned short actor_group); - void set_linear_damping(float lin_damp); - void set_linear_momentum(const LVecBase3f & lin_moment); - void set_linear_velocity(const LVecBase3f & lin_vel); - void set_mass(float mass); - void set_mass_space_inertia_tensor(const LVecBase3f & m); - void set_max_angular_velocity(float max_ang_vel); - void set_sleep_angular_velocity(float threshold); - void set_sleep_energy_threshold(float threshold); - void set_sleep_linear_velocity(float threshold); - void set_solver_iteration_count(unsigned int iter_count); - void update_mass_from_shapes(float density, float total_mass); - void wake_up(float wake_counter_value); - - -public: - NxActor *nActor; - - bool safe_to_flatten() const { - return false; - } - - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - PandaNode::init_type(); - register_type(_type_handle, "PhysxActorNode", PandaNode::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() { - init_type(); - return get_class_type(); - } - -private: - virtual void transform_changed(); - bool _disable_transform_changed; - - // These variables are used by update_transform and - // get_global_pose_optimized for optimization purposes. - LMatrix4f _tempMat4; - float _tempCells[16]; - - static TypeHandle _type_handle; -}; - -#include "physxActorNode.I" - -#endif // HAVE_PHYSX - -#endif // PHYSXACTORNODE_H diff --git a/panda/src/physx/physxBodyDesc.I b/panda/src/physx/physxBodyDesc.I index 75236b6ade..35b1eb06d5 100644 --- a/panda/src/physx/physxBodyDesc.I +++ b/panda/src/physx/physxBodyDesc.I @@ -1,5 +1,5 @@ // Filename: physxBodyDesc.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (05Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,263 +12,47 @@ // //////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxBodyDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxBodyDesc:: -is_valid() const { - return nBodyDesc.isValid(); +INLINE PhysxBodyDesc:: +PhysxBodyDesc() { + } //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxBodyDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxBodyDesc:: +~PhysxBodyDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. //////////////////////////////////////////////////////////////////// INLINE void PhysxBodyDesc:: set_to_default() { - nBodyDesc.setToDefault(); + + _desc.setToDefault(); } //////////////////////////////////////////////////////////////////// -// Function : get_angular_damping -// Access : Published -// Description : +// Function: PhysxBodyDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. //////////////////////////////////////////////////////////////////// -INLINE float PhysxBodyDesc:: -get_angular_damping() const { - return nBodyDesc.angularDamping; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_ccd_motion_threshold -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxBodyDesc:: -get_ccd_motion_threshold() const { - return nBodyDesc.CCDMotionThreshold; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxBodyDesc:: -get_flags() const { - return nBodyDesc.flags; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_linear_damping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxBodyDesc:: -get_linear_damping() const { - return nBodyDesc.linearDamping; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_mass -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxBodyDesc:: -get_mass() const { - return nBodyDesc.mass; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_max_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxBodyDesc:: -get_max_angular_velocity() const { - return nBodyDesc.maxAngularVelocity; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_sleep_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxBodyDesc:: -get_sleep_angular_velocity() const { - return nBodyDesc.sleepAngularVelocity; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_sleep_damping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxBodyDesc:: -get_sleep_damping() const { - return nBodyDesc.sleepDamping; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_sleep_energy_threshold -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxBodyDesc:: -get_sleep_energy_threshold() const { - return nBodyDesc.sleepEnergyThreshold; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_sleep_linear_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxBodyDesc:: -get_sleep_linear_velocity() const { - return nBodyDesc.sleepLinearVelocity; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_solver_iteration_count -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxBodyDesc:: -get_solver_iteration_count() const { - return nBodyDesc.solverIterationCount; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_wake_up_counter -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxBodyDesc:: -get_wake_up_counter() const { - return nBodyDesc.wakeUpCounter; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_angular_damping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_angular_damping(float value) { - nBodyDesc.angularDamping = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_ccd_motion_threshold -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_ccd_motion_threshold(float value) { - nBodyDesc.CCDMotionThreshold = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_flags(unsigned int value) { - nBodyDesc.flags = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_linear_damping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_linear_damping(float value) { - nBodyDesc.linearDamping = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_mass -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_mass(float value) { - nBodyDesc.mass = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_max_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_max_angular_velocity(float value) { - nBodyDesc.maxAngularVelocity = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_sleep_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_sleep_angular_velocity(float value) { - nBodyDesc.sleepAngularVelocity = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_sleep_damping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_sleep_damping(float value) { - nBodyDesc.sleepDamping = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_sleep_energy_threshold -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_sleep_energy_threshold(float value) { - nBodyDesc.sleepEnergyThreshold = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_sleep_linear_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_sleep_linear_velocity(float value) { - nBodyDesc.sleepLinearVelocity = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_solver_iteration_count -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_solver_iteration_count(unsigned int value) { - nBodyDesc.solverIterationCount = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_wake_up_counter -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBodyDesc:: -set_wake_up_counter(float value) { - nBodyDesc.wakeUpCounter = value; +INLINE bool PhysxBodyDesc:: +is_valid() const { + + return _desc.isValid(); } diff --git a/panda/src/physx/physxBodyDesc.cxx b/panda/src/physx/physxBodyDesc.cxx index deb8d10378..59242ec53e 100644 --- a/panda/src/physx/physxBodyDesc.cxx +++ b/panda/src/physx/physxBodyDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxBodyDesc.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (05Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,102 +12,406 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxBodyDesc.h" -#include "luse.h" - - //////////////////////////////////////////////////////////////////// -// Function : PhysxBodyDesc -// Access : Published -// Description : +// Function: PhysxBodyDesc::set_mass +// Access: Published +// Description: Set the mass of body. //////////////////////////////////////////////////////////////////// -PhysxBodyDesc:: -PhysxBodyDesc() { +void PhysxBodyDesc:: +set_mass(float mass) { + _desc.mass = mass; } //////////////////////////////////////////////////////////////////// -// Function : get_angular_velocity -// Access : Published -// Description : +// Function: PhysxBodyDesc::get_mass +// Access: Published +// Description: Get the mass of body. //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxBodyDesc:: -get_angular_velocity() const { - return PhysxManager::nxVec3_to_lVecBase3(nBodyDesc.angularVelocity); +float PhysxBodyDesc:: +get_mass() const { + + return _desc.mass; } //////////////////////////////////////////////////////////////////// -// Function : get_linear_velocity -// Access : Published -// Description : +// Function: PhysxBodyDesc::set_linear_damping +// Access: Published +// Description: Set the linear damping applied to the body. //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxBodyDesc:: +void PhysxBodyDesc:: +set_linear_damping(float damping) { + + _desc.linearDamping = damping; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_linear_damping +// Access: Published +// Description: Get the linear damping applied to the body. +//////////////////////////////////////////////////////////////////// +float PhysxBodyDesc:: +get_linear_damping() const { + + return _desc.linearDamping; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_angular_damping +// Access: Published +// Description: Set the angular damping applied to the body. +//////////////////////////////////////////////////////////////////// +void PhysxBodyDesc:: +set_angular_damping(float damping) { + + _desc.angularDamping = damping; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_angular_damping +// Access: Published +// Description: Get the angular damping applied to the body. +//////////////////////////////////////////////////////////////////// +float PhysxBodyDesc:: +get_angular_damping() const { + + return _desc.angularDamping; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_linear_velocity +// Access: Published +// Description: Set the linear Velocity of the body. +//////////////////////////////////////////////////////////////////// +void PhysxBodyDesc:: +set_linear_velocity(const LVector3f &velocity) { + + _desc.linearVelocity = PhysxManager::vec3_to_nxVec3(velocity); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_linear_velocity +// Access: Published +// Description: Get the linear Velocity of the body. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxBodyDesc:: get_linear_velocity() const { - return PhysxManager::nxVec3_to_lVecBase3(nBodyDesc.linearVelocity); + + return PhysxManager::nxVec3_to_vec3(_desc.linearVelocity); } //////////////////////////////////////////////////////////////////// -// Function : get_mass_local_pose -// Access : Published -// Description : +// Function: PhysxBodyDesc::set_angular_velocity +// Access: Published +// Description: Set the angular velocity of the body. +//////////////////////////////////////////////////////////////////// +void PhysxBodyDesc:: +set_angular_velocity(const LVector3f &velocity) { + + _desc.angularVelocity = PhysxManager::vec3_to_nxVec3(velocity); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_angular_velocity +// Access: Published +// Description: Get the angular velocity of the body. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxBodyDesc:: +get_angular_velocity() const { + + return PhysxManager::nxVec3_to_vec3(_desc.angularVelocity); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_max_angular_velocity +// Access: Published +// Description: Set the maximum allowed angular velocity for this +// body. +//////////////////////////////////////////////////////////////////// +void PhysxBodyDesc:: +set_max_angular_velocity(float maximum) { + + _desc.maxAngularVelocity = maximum; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_max_angular_velocity +// Access: Published +// Description: Get the maximum allowed angular velocity for this +// body. +//////////////////////////////////////////////////////////////////// +float PhysxBodyDesc:: +get_max_angular_velocity() const { + + return _desc.maxAngularVelocity; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_sleep_linear_velocity +// Access: Published +// Description: Set the maximum linear velocity at which the body +// can go to sleep. +//////////////////////////////////////////////////////////////////// +void PhysxBodyDesc:: +set_sleep_linear_velocity(float velocity) { + + _desc.sleepLinearVelocity = velocity; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_sleep_linear_velocity +// Access: Published +// Description: Get the maximum linear velocity at which the body +// can go to sleep. +//////////////////////////////////////////////////////////////////// +float PhysxBodyDesc:: +get_sleep_linear_velocity() const { + + return _desc.sleepLinearVelocity; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_sleep_angular_velocity +// Access: Published +// Description: Set the maximum angular velocity at which body +// can go to sleep. +//////////////////////////////////////////////////////////////////// +void PhysxBodyDesc:: +set_sleep_angular_velocity(float velocity) { + + _desc.sleepAngularVelocity = velocity; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_sleep_angular_velocity +// Access: Published +// Description: Get the maximum angular velocity at which body +// can go to sleep. +//////////////////////////////////////////////////////////////////// +float PhysxBodyDesc:: +get_sleep_angular_velocity() const { + + return _desc.sleepAngularVelocity; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_solver_iteration_count +// Access: Published +// Description: Set the number of solver iterations performed +// when processing joint/contacts connected to this +// body. +//////////////////////////////////////////////////////////////////// +void PhysxBodyDesc:: +set_solver_iteration_count(unsigned int count) { + + _desc.solverIterationCount = count; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_solver_iteration_count +// Access: Published +// Description: Get the number of solver iterations performed +// when processing joint/contacts connected to this +// body. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxBodyDesc:: +get_solver_iteration_count() const { + + return _desc.solverIterationCount; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_sleep_energy_threshold +// Access: Published +// Description: Set the threshold for the energy-based sleeping +// algorithm. Only used when the BF_energy_sleep_test +// flag is set. +//////////////////////////////////////////////////////////////////// +void PhysxBodyDesc:: +set_sleep_energy_threshold(float threshold) { + + _desc.sleepEnergyThreshold = threshold; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_sleep_energy_threshold +// Access: Published +// Description: Get the threshold for the energy-based sleeping +// algorithm. Only used when the BF_energy_sleep_test +// flag is set. +//////////////////////////////////////////////////////////////////// +float PhysxBodyDesc:: +get_sleep_energy_threshold() const { + + return _desc.sleepEnergyThreshold; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_sleep_damping +// Access: Published +// Description: Set the damping factor for bodies that are about +// to sleep. +//////////////////////////////////////////////////////////////////// +void PhysxBodyDesc:: +set_sleep_damping(float damping) { + + _desc.sleepDamping = damping; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_sleep_damping +// Access: Published +// Description: Get the damping factor for bodies that are about +// to sleep. +//////////////////////////////////////////////////////////////////// +float PhysxBodyDesc:: +get_sleep_damping() const { + + return _desc.sleepDamping; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_mass_local_mat +// Access: Published +// Description: Set the position and orientation of the center +// of mass. +//////////////////////////////////////////////////////////////////// +void PhysxBodyDesc:: +set_mass_local_mat(const LMatrix4f mat) { + + _desc.massLocalPose = PhysxManager::mat4_to_nxMat34(mat); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_mass_local_mat +// Access: Published +// Description: Get the position and orientation of the center +// of mass. //////////////////////////////////////////////////////////////////// LMatrix4f PhysxBodyDesc:: -get_mass_local_pose() const { - return PhysxManager::nxMat34_to_lMatrix4(nBodyDesc.massLocalPose); +get_mass_local_mat() const { + + return PhysxManager::nxMat34_to_mat4(_desc.massLocalPose); } //////////////////////////////////////////////////////////////////// -// Function : get_mass_space_inertia -// Access : Published -// Description : +// Function: PhysxBodyDesc::set_mass_space_inertia +// Access: Published +// Description: Set the diagonal mass space inertia tensor in +// bodies mass frame. //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxBodyDesc:: +void PhysxBodyDesc:: +set_mass_space_inertia(const LVector3f inertia) { + + _desc.massSpaceInertia = PhysxManager::vec3_to_nxVec3(inertia); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_mass_space_inertia +// Access: Published +// Description: Get the diagonal mass space inertia tensor in +// bodies mass frame. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxBodyDesc:: get_mass_space_inertia() const { - return PhysxManager::nxVec3_to_lVecBase3(nBodyDesc.massSpaceInertia); + + return PhysxManager::nxVec3_to_vec3(_desc.massSpaceInertia); } //////////////////////////////////////////////////////////////////// -// Function : set_angular_velocity -// Access : Published -// Description : +// Function: PhysxBodyDesc::set_flag +// Access: Published +// Description: Raise or lower individual body flags. //////////////////////////////////////////////////////////////////// void PhysxBodyDesc:: -set_angular_velocity(LVecBase3f value) { - nBodyDesc.angularVelocity = PhysxManager::lVecBase3_to_nxVec3(value); +set_flag(const PhysxBodyFlag flag, bool value) { + + if (value == true) { + _desc.flags |= flag; + } + else { + _desc.flags &= ~(flag); + } } //////////////////////////////////////////////////////////////////// -// Function : set_linear_velocity -// Access : Published -// Description : +// Function: PhysxBodyDesc::get_flag +// Access: Published +// Description: Returns the specified body flag. +//////////////////////////////////////////////////////////////////// +bool PhysxBodyDesc:: +get_flag(const PhysxBodyFlag flag) const { + + return (_desc.flags & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_ccd_motion_threshold +// Access: Published +// Description: When CCD is globally enabled, it is still not +// performed if the motion distance of all points on +// the body is below this threshold. //////////////////////////////////////////////////////////////////// void PhysxBodyDesc:: -set_linear_velocity(LVecBase3f value) { - nBodyDesc.linearVelocity = PhysxManager::lVecBase3_to_nxVec3(value); +set_ccd_motion_threshold(float threshold) { + + _desc.CCDMotionThreshold = threshold; } //////////////////////////////////////////////////////////////////// -// Function : set_mass_local_pose -// Access : Published -// Description : +// Function: PhysxBodyDesc::get_ccd_motion_threshold +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxBodyDesc:: +get_ccd_motion_threshold() const { + + return _desc.CCDMotionThreshold; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_wake_up_counter +// Access: Published +// Description: Set the body's initial wake up counter. //////////////////////////////////////////////////////////////////// void PhysxBodyDesc:: -set_mass_local_pose(LMatrix4f value) { - nBodyDesc.massLocalPose = PhysxManager::lMatrix4_to_nxMat34(value); +set_wake_up_counter(float value) { + + _desc.wakeUpCounter = value; } //////////////////////////////////////////////////////////////////// -// Function : set_mass_space_inertia -// Access : Published -// Description : +// Function: PhysxBodyDesc::get_wake_up_counter +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxBodyDesc:: +get_wake_up_counter() const { + + return _desc.wakeUpCounter; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::set_contact_report_threshold +// Access: Published +// Description: Set The force threshold for contact reports. //////////////////////////////////////////////////////////////////// void PhysxBodyDesc:: -set_mass_space_inertia(LVecBase3f value) { - nBodyDesc.massSpaceInertia = PhysxManager::lVecBase3_to_nxVec3(value); +set_contact_report_threshold(float threshold) { + + _desc.contactReportThreshold = threshold; } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxBodyDesc::get_contact_report_threshold +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxBodyDesc:: +get_contact_report_threshold() const { + + return _desc.contactReportThreshold; +} diff --git a/panda/src/physx/physxBodyDesc.h b/panda/src/physx/physxBodyDesc.h index e875dbcbbf..4131d22235 100644 --- a/panda/src/physx/physxBodyDesc.h +++ b/panda/src/physx/physxBodyDesc.h @@ -1,5 +1,5 @@ // Filename: physxBodyDesc.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (05Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,67 +15,69 @@ #ifndef PHYSXBODYDESC_H #define PHYSXBODYDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "lvector3.h" +#include "lmatrix.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "physxEnums.h" +#include "NoMinMax.h" #include "NxPhysics.h" //////////////////////////////////////////////////////////////////// // Class : PhysxBodyDesc -// Description : +// Description : Descriptor for the optional rigid body dynamic +// state of PhysxActor. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxBodyDesc { +class EXPCL_PANDAPHYSX PhysxBodyDesc : public PhysxEnums { + PUBLISHED: - PhysxBodyDesc(); + INLINE PhysxBodyDesc(); + INLINE ~PhysxBodyDesc(); - INLINE bool is_valid() const; INLINE void set_to_default(); + INLINE bool is_valid() const; - INLINE float get_angular_damping() const; - LVecBase3f get_angular_velocity() const; - INLINE float get_ccd_motion_threshold() const; - INLINE unsigned int get_flags() const; - INLINE float get_linear_damping() const; - LVecBase3f get_linear_velocity() const; - INLINE float get_mass() const; - LMatrix4f get_mass_local_pose() const; - LVecBase3f get_mass_space_inertia() const; - INLINE float get_max_angular_velocity() const; - INLINE float get_sleep_angular_velocity() const; - INLINE float get_sleep_damping() const; - INLINE float get_sleep_energy_threshold() const; - INLINE float get_sleep_linear_velocity() const; - INLINE unsigned int get_solver_iteration_count() const; - INLINE float get_wake_up_counter() const; + void set_mass(float mass); + void set_linear_damping(float damping); + void set_angular_damping(float damping); + void set_linear_velocity(const LVector3f &velocity); + void set_angular_velocity(const LVector3f &velocity); + void set_max_angular_velocity(float maximum); + void set_sleep_linear_velocity(float velocity); + void set_sleep_angular_velocity(float velocity); + void set_solver_iteration_count(unsigned int count); + void set_sleep_energy_threshold(float threshold); + void set_sleep_damping(float damping); + void set_mass_local_mat(const LMatrix4f mat); + void set_mass_space_inertia(const LVector3f inertia); + void set_flag(PhysxBodyFlag flag, bool value); + void set_ccd_motion_threshold(float threshold); + void set_wake_up_counter(float value); + void set_contact_report_threshold(float threshold); - INLINE void set_angular_damping( float value ); - void set_angular_velocity( LVecBase3f value ); - INLINE void set_ccd_motion_threshold( float value ); - INLINE void set_flags( unsigned int value ); - INLINE void set_linear_damping( float value ); - void set_linear_velocity( LVecBase3f value ); - INLINE void set_mass( float value ); - void set_mass_local_pose( LMatrix4f value ); - void set_mass_space_inertia( LVecBase3f value ); - INLINE void set_max_angular_velocity( float value ); - INLINE void set_sleep_angular_velocity( float value ); - INLINE void set_sleep_damping(float value); - INLINE void set_sleep_energy_threshold(float value); - INLINE void set_sleep_linear_velocity( float value ); - INLINE void set_solver_iteration_count( unsigned int value ); - INLINE void set_wake_up_counter( float value ); + float get_mass() const; + float get_linear_damping() const; + float get_angular_damping() const; + LVector3f get_linear_velocity() const; + LVector3f get_angular_velocity() const; + float get_max_angular_velocity() const; + float get_sleep_linear_velocity() const; + float get_sleep_angular_velocity() const; + unsigned int get_solver_iteration_count() const; + float get_sleep_energy_threshold() const; + float get_sleep_damping() const; + LMatrix4f get_mass_local_mat() const; + LVector3f get_mass_space_inertia() const; + bool get_flag(PhysxBodyFlag flag) const; + float get_ccd_motion_threshold() const; + float get_wake_up_counter() const; + float get_contact_report_threshold() const; public: - NxBodyDesc nBodyDesc; + NxBodyDesc _desc; }; #include "physxBodyDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXBODYDESC_H diff --git a/panda/src/physx/physxBounds3.I b/panda/src/physx/physxBounds3.I index b70244de33..305ca00180 100644 --- a/panda/src/physx/physxBounds3.I +++ b/panda/src/physx/physxBounds3.I @@ -1,5 +1,5 @@ // Filename: physxBounds3.I -// Created by: pratt (Dec 12, 2007) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,183 +12,24 @@ // //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function : bounds_of_obb -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBounds3:: -bounds_of_obb(const LMatrix3f & orientation, const LVecBase3f & translation, const LVecBase3f & half_dims) { - nassertv(nBounds3 != NULL); - nBounds3->boundsOfOBB(PhysxManager::lMatrix3_to_nxMat33(orientation), PhysxManager::lVecBase3_to_nxVec3(translation), PhysxManager::lVecBase3_to_nxVec3(half_dims)); +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxBounds3:: +PhysxBounds3() { + } //////////////////////////////////////////////////////////////////// -// Function : combine -// Access : Published -// Description : +// Function: PhysxBounds3::Destructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE void PhysxBounds3:: -combine(const PhysxBounds3 & b2) { - nassertv(nBounds3 != NULL); +INLINE PhysxBounds3:: +~PhysxBounds3() { - nBounds3->combine(*(b2.nBounds3)); -} - -//////////////////////////////////////////////////////////////////// -// Function : contain -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE bool PhysxBounds3:: -contain(const LVecBase3f & v) const { - nassertr(nBounds3 != NULL, false); - - return nBounds3->contain(PhysxManager::lVecBase3_to_nxVec3(v)); -} - -//////////////////////////////////////////////////////////////////// -// Function : fatten -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBounds3:: -fatten(float distance) { - nassertv(nBounds3 != NULL); - - nBounds3->fatten(distance); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_dimensions -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBounds3:: -get_dimensions(LVecBase3f & dims) const { - nassertv(nBounds3 != NULL); - - nBounds3->getDimensions(PhysxManager::lVecBase3_to_nxVec3(dims)); -} - -//////////////////////////////////////////////////////////////////// -// Function : include -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBounds3:: -include(const LVecBase3f & v) { - nassertv(nBounds3 != NULL); - - nBounds3->include(PhysxManager::lVecBase3_to_nxVec3(v)); -} - -//////////////////////////////////////////////////////////////////// -// Function : intersects -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE bool PhysxBounds3:: -intersects(const PhysxBounds3 & b) const { - nassertr(nBounds3 != NULL, false); - - return nBounds3->intersects(*(b.nBounds3)); -} - -//////////////////////////////////////////////////////////////////// -// Function : intersects2d -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE bool PhysxBounds3:: -intersects2d(const PhysxBounds3 & b, unsigned axis_to_ignore) const { - nassertr(nBounds3 != NULL, false); - - return nBounds3->intersects2D(*(b.nBounds3), axis_to_ignore); -} - -//////////////////////////////////////////////////////////////////// -// Function : is_empty -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE bool PhysxBounds3:: -is_empty() const { - nassertr(nBounds3 != NULL, false); - - return nBounds3->isEmpty(); -} - -//////////////////////////////////////////////////////////////////// -// Function : scale -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBounds3:: -scale(float scale) { - nassertv(nBounds3 != NULL); - - nBounds3->scale(scale); -} - -//////////////////////////////////////////////////////////////////// -// Function : set -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBounds3:: -set(const LVecBase3f & min, const LVecBase3f & max) { - nassertv(nBounds3 != NULL); - - nBounds3->set(PhysxManager::lVecBase3_to_nxVec3(min), PhysxManager::lVecBase3_to_nxVec3(max)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_center_extents -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBounds3:: -set_center_extents(const LVecBase3f & c, const LVecBase3f & e) { - nassertv(nBounds3 != NULL); - - nBounds3->setCenterExtents(PhysxManager::lVecBase3_to_nxVec3(c), PhysxManager::lVecBase3_to_nxVec3(e)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_empty -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBounds3:: -set_empty() { - nassertv(nBounds3 != NULL); - - nBounds3->setEmpty(); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_infinite -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBounds3:: -set_infinite() { - nassertv(nBounds3 != NULL); - - nBounds3->setInfinite(); -} - -//////////////////////////////////////////////////////////////////// -// Function : transform -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBounds3:: -transform(const LMatrix3f & orientation, const LVecBase3f & translation) { - nassertv(nBounds3 != NULL); - - nBounds3->transform(PhysxManager::lMatrix3_to_nxMat33(orientation), PhysxManager::lVecBase3_to_nxVec3(translation)); } diff --git a/panda/src/physx/physxBounds3.cxx b/panda/src/physx/physxBounds3.cxx index 9d6b938cd8..c38a302973 100644 --- a/panda/src/physx/physxBounds3.cxx +++ b/panda/src/physx/physxBounds3.cxx @@ -1,5 +1,5 @@ // Filename: physxBounds3.cxx -// Created by: pratt (Dec 12, 2007) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,80 +12,267 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxBounds3.h" - -#include "luse.h" - +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxBounds3 -// Access : Published -// Description : +// Function: PhysxBounds3::get_max +// Access: Published +// Description: Returns the minimum corner of the bounding box. //////////////////////////////////////////////////////////////////// -PhysxBounds3:: -PhysxBounds3() { - nBounds3 = new NxBounds3(); -} - -//////////////////////////////////////////////////////////////////// -// Function : ~PhysxBounds3 -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxBounds3:: -~PhysxBounds3() { - delete nBounds3; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_max -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxBounds3:: +LPoint3f PhysxBounds3:: get_max() const { - nassertr(nBounds3 != NULL, *((LVecBase3f *)NULL)); - return PhysxManager::nxVec3_to_lVecBase3(nBounds3->max); + return PhysxManager::nxVec3_to_point3(_bounds.max); } //////////////////////////////////////////////////////////////////// -// Function : get_min -// Access : Published -// Description : +// Function: PhysxBounds3::get_min +// Access: Published +// Description: Returns the maximum corner of the bounding box. //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxBounds3:: +LPoint3f PhysxBounds3:: get_min() const { - nassertr(nBounds3 != NULL, *((LVecBase3f *)NULL)); - return PhysxManager::nxVec3_to_lVecBase3(nBounds3->min); + return PhysxManager::nxVec3_to_point3(_bounds.min); } //////////////////////////////////////////////////////////////////// -// Function : set_max -// Access : Published -// Description : +// Function: PhysxBounds3::get_center +// Access: Published +// Description: Returns the center of the bounding box. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxBounds3:: +get_center() const { + + NxVec3 center; + _bounds.getCenter(center); + return PhysxManager::nxVec3_to_point3(center); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::get_dimensions +// Access: Published +// Description: Returns the extents of the bounding box. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxBounds3:: +get_dimensions() const { + + NxVec3 dims; + _bounds.getDimensions(dims); + return PhysxManager::nxVec3_to_vec3(dims); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::set_max +// Access: Published +// Description: Sets the maximum corner of the bounding box. //////////////////////////////////////////////////////////////////// void PhysxBounds3:: -set_max(LVecBase3f value) { - nassertv(nBounds3 != NULL); +set_max(LPoint3f value) { - nBounds3->max = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv(!value.is_nan()); + + _bounds.max = PhysxManager::point3_to_nxVec3(value); } //////////////////////////////////////////////////////////////////// -// Function : set_min -// Access : Published -// Description : +// Function: PhysxBounds3::set_min +// Access: Published +// Description: Sets the minimum corner of the bounding box. //////////////////////////////////////////////////////////////////// void PhysxBounds3:: -set_min(LVecBase3f value) { - nassertv(nBounds3 != NULL); +set_min(LPoint3f value) { - nBounds3->min = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv(!value.is_nan()); + + _bounds.min = PhysxManager::point3_to_nxVec3(value); } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::bounds_of_obb +// Access: Published +// Description: Sets this to the AABB (axis ligned bounding box) +// of the OBB (oriented bounding box). The OBB is +// described by orientation, translation and half +// dimensions. +//////////////////////////////////////////////////////////////////// +void PhysxBounds3:: +bounds_of_obb(const LMatrix3f &orientation, const LPoint3f &translation, const LVector3f &half_dims) { + + nassertv(!orientation.is_nan()); + nassertv(!translation.is_nan()); + nassertv(!half_dims.is_nan()); + + _bounds.boundsOfOBB(PhysxManager::mat3_to_nxMat33(orientation), + PhysxManager::point3_to_nxVec3(translation), + PhysxManager::vec3_to_nxVec3(half_dims)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::combine +// Access: Published +// Description: Sets this to the union of this and b2. +//////////////////////////////////////////////////////////////////// +void PhysxBounds3:: +combine(const PhysxBounds3 &b2) { + + _bounds.combine(b2._bounds); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::contain +// Access: Published +// Description: Returns TRUE if these bounds contain the point v. +//////////////////////////////////////////////////////////////////// +bool PhysxBounds3:: +contain(const LPoint3f &p) const { + + nassertr(!p.is_nan(), false); + + return _bounds.contain(PhysxManager::point3_to_nxVec3(p)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::fatten +// Access: Published +// Description: Fattens the AABB in all three dimensions by the +// given distance. +//////////////////////////////////////////////////////////////////// +void PhysxBounds3:: +fatten(float distance) { + + _bounds.fatten(distance); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::include +// Access: Published +// Description: Expands the volume to include the point v. +//////////////////////////////////////////////////////////////////// +void PhysxBounds3:: +include(const LPoint3f &p) { + + nassertv(!p.is_nan()); + _bounds.include(PhysxManager::point3_to_nxVec3(p)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::intersects +// Access: Published +// Description: Returns TRUE if the intersection of this and b is +// is not empty. +//////////////////////////////////////////////////////////////////// +bool PhysxBounds3:: +intersects(const PhysxBounds3 &b) const { + + return _bounds.intersects(b._bounds); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::intersects2d +// Access: Published +// Description: Indicates whether the intersection of this and b +// is empty or not in the plane orthogonal to the +// axis passed (X = 0, Y = 1 or Z = 2). +//////////////////////////////////////////////////////////////////// +bool PhysxBounds3:: +intersects2d(const PhysxBounds3 &b, unsigned axis_to_ignore) const { + + return _bounds.intersects2D(b._bounds, axis_to_ignore); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::is_empty +// Access: Published +// Description: Returns TRUE if the bounding box is empty. +//////////////////////////////////////////////////////////////////// +bool PhysxBounds3:: +is_empty() const { + + return _bounds.isEmpty(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::scale +// Access: Published +// Description: Scales the AABB by the given factor. +//////////////////////////////////////////////////////////////////// +void PhysxBounds3:: +scale(float scale) { + + _bounds.scale(scale); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::set +// Access: Published +// Description: Setup this AABB from minimum corner and maximum +// corner. +//////////////////////////////////////////////////////////////////// +void PhysxBounds3:: +set(const LPoint3f &min, const LPoint3f &max) { + + nassertv(!min.is_nan()); + nassertv(!max.is_nan()); + + _bounds.set(PhysxManager::point3_to_nxVec3(min), + PhysxManager::point3_to_nxVec3(max)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::set_center_extents +// Access: Published +// Description: Setup this AABB from center point and extents +// vector. +//////////////////////////////////////////////////////////////////// +void PhysxBounds3:: +set_center_extents(const LPoint3f ¢er, const LVector3f &extents) { + + nassertv(!center.is_nan()); + nassertv(!extents.is_nan()); + + _bounds.setCenterExtents(PhysxManager::point3_to_nxVec3(center), + PhysxManager::vec3_to_nxVec3(extents)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::set_empty +// Access: Published +// Description: Sets empty to TRUE. +//////////////////////////////////////////////////////////////////// +void PhysxBounds3:: +set_empty() { + + _bounds.setEmpty(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::set_infinite +// Access: Published +// Description: Sets infinite bounds. +//////////////////////////////////////////////////////////////////// +void PhysxBounds3:: +set_infinite() { + + _bounds.setInfinite(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBounds3::transform +// Access: Published +// Description: Transforms this volume as if it was an axis aligned +// bounding box, and then assigns the results' bounds +// to this. The orientation is applied first, then the +// translation. +//////////////////////////////////////////////////////////////////// +void PhysxBounds3:: +transform(const LMatrix3f &orientation, const LPoint3f &translation) { + + nassertv(!orientation.is_nan()); + nassertv(!translation.is_nan()); + + _bounds.transform(PhysxManager::mat3_to_nxMat33(orientation), + PhysxManager::point3_to_nxVec3(translation)); +} diff --git a/panda/src/physx/physxBounds3.h b/panda/src/physx/physxBounds3.h index d8bc4b13fe..6860ed15b8 100644 --- a/panda/src/physx/physxBounds3.h +++ b/panda/src/physx/physxBounds3.h @@ -1,5 +1,5 @@ // Filename: physxBounds3.h -// Created by: pratt (Dec 12, 2007) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,53 +15,54 @@ #ifndef PHYSXBOUNDS3_H #define PHYSXBOUNDS3_H -#ifdef HAVE_PHYSX - #include "pandabase.h" - -#include "physx_enumerations.h" -#include "physxManager.h" #include "luse.h" +#include "config_physx.h" + #include "NxPhysics.h" //////////////////////////////////////////////////////////////////// // Class : PhysxBounds3 -// Description : +// Description : Represention of a axis aligned bounding box. +// The box is stored as minimum and maximum extent +// corners. Alternate representation would be center +// and dimensions. May be empty or nonempty. If not +// empty, min <= max has to hold. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxBounds3 { + PUBLISHED: - PhysxBounds3(); - ~PhysxBounds3(); + INLINE PhysxBounds3(); + INLINE ~PhysxBounds3(); - INLINE void bounds_of_obb(const LMatrix3f & orientation, const LVecBase3f & translation, const LVecBase3f & half_dims); - INLINE void combine(const PhysxBounds3 & b2); - INLINE bool contain(const LVecBase3f & v) const; - INLINE void fatten(float distance); - INLINE void get_dimensions(LVecBase3f & dims) const; - INLINE void include(const LVecBase3f & v); - INLINE bool intersects(const PhysxBounds3 & b) const; - INLINE bool intersects2d(const PhysxBounds3 & b, unsigned axis_to_ignore) const; - INLINE bool is_empty() const; - INLINE void scale(float scale); - INLINE void set(const LVecBase3f & min, const LVecBase3f & max); - INLINE void set_center_extents(const LVecBase3f & c, const LVecBase3f & e); - INLINE void set_empty(); - INLINE void set_infinite(); - INLINE void transform(const LMatrix3f & orientation, const LVecBase3f & translation); + void bounds_of_obb(const LMatrix3f &orientation, const LPoint3f &translation, const LVector3f &half_dims); + void combine(const PhysxBounds3 &b2); + bool contain(const LPoint3f &p) const; + void fatten(float distance); + void include(const LPoint3f &v); + bool intersects(const PhysxBounds3 &b) const; + bool intersects2d(const PhysxBounds3 &b, unsigned axis_to_ignore) const; + bool is_empty() const; + void scale(float scale); + void set(const LPoint3f &min, const LPoint3f &max); + void set_center_extents(const LPoint3f ¢er, const LVector3f &extents); + void set_empty(); + void set_infinite(); + void transform(const LMatrix3f &orientation, const LPoint3f &translation); - LVecBase3f get_max() const; - LVecBase3f get_min() const; + LPoint3f get_max() const; + LPoint3f get_min() const; + LPoint3f get_center() const; + LVector3f get_dimensions() const; - void set_max(LVecBase3f value); - void set_min(LVecBase3f value); + void set_max(LPoint3f value); + void set_min(LPoint3f value); public: - NxBounds3 *nBounds3; + NxBounds3 _bounds; }; #include "physxBounds3.I" -#endif // HAVE_PHYSX - -#endif // PHYSXBOUNDS3_H +#endif // PHYSBOUNDS3_H diff --git a/panda/src/physx/physxBox.I b/panda/src/physx/physxBox.I index 216b56d77d..458f366e9e 100644 --- a/panda/src/physx/physxBox.I +++ b/panda/src/physx/physxBox.I @@ -1,5 +1,5 @@ // Filename: physxBox.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,39 +12,24 @@ // //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE bool PhysxBox:: -is_valid() const { - nassertr(nBox != NULL, false); - return nBox->isValid(); +//////////////////////////////////////////////////////////////////// +// Function: PhysxBox::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxBox:: +PhysxBox() { + } //////////////////////////////////////////////////////////////////// -// Function : rotate -// Access : Published -// Description : +// Function: PhysxBox::Destructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE void PhysxBox:: -rotate(const LMatrix4f & mtx, PhysxBox & obb) const { - nassertv(nBox != NULL); +INLINE PhysxBox:: +~PhysxBox() { - nBox->rotate(PhysxManager::lMatrix4_to_nxMat34(mtx), *(obb.nBox)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_empty -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxBox:: -set_empty() { - nassertv(nBox != NULL); - - nBox->setEmpty(); } diff --git a/panda/src/physx/physxBox.cxx b/panda/src/physx/physxBox.cxx index 397c5ecc8d..1ee31b72d6 100644 --- a/panda/src/physx/physxBox.cxx +++ b/panda/src/physx/physxBox.cxx @@ -1,5 +1,5 @@ // Filename: physxBox.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,114 +12,127 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxBox.h" - -#include "luse.h" - +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxBox -// Access : Published -// Description : +// Function: PhysxBox::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// PhysxBox:: -PhysxBox() { - nBox = new NxBox(); +PhysxBox(const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot) { + + _box = NxBox(PhysxManager::point3_to_nxVec3(center), + PhysxManager::vec3_to_nxVec3(extents), + PhysxManager::mat3_to_nxMat33(rot)); } //////////////////////////////////////////////////////////////////// -// Function : PhysxBox -// Access : Published -// Description : +// Function: PhysxBox::is_valid +// Access: Published +// Description: Returns TRUE if the box is valid. //////////////////////////////////////////////////////////////////// -PhysxBox:: -PhysxBox(const LVecBase3f & _center, const LVecBase3f & _extents, const LMatrix3f & _rot) { - nBox = new NxBox(PhysxManager::lVecBase3_to_nxVec3(_center), PhysxManager::lVecBase3_to_nxVec3(_extents), PhysxManager::lMatrix3_to_nxMat33(_rot)); +bool PhysxBox:: +is_valid() const { + + return _box.isValid(); } //////////////////////////////////////////////////////////////////// -// Function : ~PhysxBox -// Access : Published -// Description : +// Function: PhysxBox::rotate +// Access: Published +// Description: Recomputes the box after an arbitrary transform by +// a 4x4 matrix. //////////////////////////////////////////////////////////////////// -PhysxBox:: -~PhysxBox() { - delete nBox; +void PhysxBox:: +rotate(const LMatrix4f &m, PhysxBox &obb) const { + + nassertv(!m.is_nan()); + + _box.rotate(PhysxManager::mat4_to_nxMat34(m), obb._box); } //////////////////////////////////////////////////////////////////// -// Function : get_center -// Access : Published -// Description : +// Function: PhysxBox::set_empty +// Access: Published +// Description: Setups an empty box. //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxBox:: +void PhysxBox:: +set_empty() { + + _box.setEmpty(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBox::get_center +// Access: Published +// Description: Return center of the box. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxBox:: get_center() const { - nassertr(nBox != NULL, *((LVecBase3f *)NULL)); - return PhysxManager::nxVec3_to_lVecBase3(nBox->center); + return PhysxManager::nxVec3_to_point3(_box.GetCenter()); } //////////////////////////////////////////////////////////////////// -// Function : get_extents -// Access : Published -// Description : +// Function: PhysxBox::get_extents +// Access: Published +// Description: Returns the extents (radii) of the box. //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxBox:: +LVector3f PhysxBox:: get_extents() const { - nassertr(nBox != NULL, *((LVecBase3f *)NULL)); - return PhysxManager::nxVec3_to_lVecBase3(nBox->extents); + return PhysxManager::nxVec3_to_vec3(_box.GetExtents()); } //////////////////////////////////////////////////////////////////// -// Function : get_rot -// Access : Published -// Description : +// Function: PhysxBox::get_rot +// Access: Published +// Description: Return the rotation of the box. //////////////////////////////////////////////////////////////////// LMatrix3f PhysxBox:: get_rot() const { - nassertr(nBox != NULL, *((LMatrix3f *)NULL)); - return PhysxManager::nxMat33_to_lMatrix3(nBox->rot); + return PhysxManager::nxMat33_to_mat3(_box.GetRot()); } //////////////////////////////////////////////////////////////////// -// Function : set_center -// Access : Published -// Description : +// Function: PhysxBox::set_center +// Access: Published +// Description: Sets the center of the box. //////////////////////////////////////////////////////////////////// void PhysxBox:: -set_center(LVecBase3f value) { - nassertv(nBox != NULL); +set_center(LPoint3f center) { - nBox->center = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv(!center.is_nan()); + + _box.center = PhysxManager::vec3_to_nxVec3(center); } //////////////////////////////////////////////////////////////////// -// Function : set_extents -// Access : Published -// Description : +// Function: PhysxBox::set_extents +// Access: Published +// Description: Sets the extents of the box. //////////////////////////////////////////////////////////////////// void PhysxBox:: -set_extents(LVecBase3f value) { - nassertv(nBox != NULL); +set_extents(LVector3f extents) { - nBox->extents = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv(!extents.is_nan()); + + _box.extents = PhysxManager::vec3_to_nxVec3(extents); } //////////////////////////////////////////////////////////////////// -// Function : set_rot -// Access : Published -// Description : +// Function: PhysxBox::set_rot +// Access: Published +// Description: Sets the rotation of the box. //////////////////////////////////////////////////////////////////// void PhysxBox:: -set_rot(LMatrix3f value) { - nassertv(nBox != NULL); +set_rot(LMatrix3f rot) { - nBox->rot = PhysxManager::lMatrix3_to_nxMat33(value); + nassertv(!rot.is_nan()); + + _box.rot = PhysxManager::mat3_to_nxMat33(rot); } -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxBox.h b/panda/src/physx/physxBox.h index d61098b6cc..bac1ae79ad 100644 --- a/panda/src/physx/physxBox.h +++ b/panda/src/physx/physxBox.h @@ -1,5 +1,5 @@ // Filename: physxBox.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,44 +15,42 @@ #ifndef PHYSXBOX_H #define PHYSXBOX_H -#ifdef HAVE_PHYSX - #include "pandabase.h" - -#include "physx_enumerations.h" -#include "physxManager.h" #include "luse.h" -#include "NxPhysics.h" +#include "config_physx.h" //////////////////////////////////////////////////////////////////// // Class : PhysxBox -// Description : +// Description : Represents an oriented bounding box, as a center +// point, extents(radii) and a rotation. i.e. the +// center of the box is at the center point, the box +// is rotated around this point with the rotation and +// it is 2*extents in width, height and depth. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxBox { + PUBLISHED: - PhysxBox(); - PhysxBox(const LVecBase3f & _center, const LVecBase3f & _extents, const LMatrix3f & _rot); - ~PhysxBox(); + INLINE PhysxBox(); + INLINE ~PhysxBox(); + PhysxBox(const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot); - INLINE bool is_valid() const; - INLINE void rotate(const LMatrix4f & mtx, PhysxBox & obb) const; - INLINE void set_empty(); + bool is_valid() const; + void rotate(const LMatrix4f &m, PhysxBox &obb) const; + void set_empty(); - LVecBase3f get_center() const; - LVecBase3f get_extents() const; + LPoint3f get_center() const; + LVector3f get_extents() const; LMatrix3f get_rot() const; - void set_center( LVecBase3f value ); - void set_extents( LVecBase3f value ); - void set_rot( LMatrix3f value ); + void set_center(LPoint3f center); + void set_extents(LVector3f extents); + void set_rot(LMatrix3f rot); public: - NxBox *nBox; + NxBox _box; }; #include "physxBox.I" -#endif // HAVE_PHYSX - -#endif // PHYSXBOX_H +#endif // PHYSBOX_H diff --git a/panda/src/physx/physxJointLimitSoftPairDesc.I b/panda/src/physx/physxBoxController.I similarity index 61% rename from panda/src/physx/physxJointLimitSoftPairDesc.I rename to panda/src/physx/physxBoxController.I index a3431770f1..c3bde9405c 100644 --- a/panda/src/physx/physxJointLimitSoftPairDesc.I +++ b/panda/src/physx/physxBoxController.I @@ -1,5 +1,5 @@ -// Filename: physxJointLimitSoftPairDesc.I -// Created by: pratt (Jun 20, 2006) +// Filename: physxBoxController.I +// Created by: enn0x (24Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,23 +12,25 @@ // //////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxBoxController::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxJointLimitSoftPairDesc:: -is_valid() const { - return nJointLimitSoftPairDesc.isValid(); +INLINE PhysxBoxController:: +PhysxBoxController() : PhysxController() { + } //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxBoxController::Destructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE void PhysxJointLimitSoftPairDesc:: -set_to_default() { - nJointLimitSoftPairDesc.setToDefault(); +INLINE PhysxBoxController:: +~PhysxBoxController() { + } diff --git a/panda/src/physx/physxBoxController.cxx b/panda/src/physx/physxBoxController.cxx new file mode 100644 index 0000000000..731c5a1239 --- /dev/null +++ b/panda/src/physx/physxBoxController.cxx @@ -0,0 +1,85 @@ +// Filename: physxBoxController.cxx +// Created by: enn0x (24Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxBoxController.h" +#include "physxManager.h" + +TypeHandle PhysxBoxController::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxController::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxBoxController:: +link(NxController *controllerPtr) { + + nassertv(controllerPtr->getType() == NX_CONTROLLER_BOX); + + // Link self + _ptr = (NxBoxController *)controllerPtr; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getActor()->getScene().userData; + scene->_controllers.add(this); + + // Link actor + PT(PhysxActor) actor = new PhysxActor(); + actor->link(_ptr->getActor()); + actor->link_controller(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxController::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxBoxController:: +unlink() { + + // Unlink actor + PT(PhysxActor) actor = (PhysxActor *)ptr()->getActor()->userData; + actor->unlink(); + + // Unlink self + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getActor()->getScene().userData; + scene->_controllers.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxController::set_extents +// Access: Published +// Description: Sets controller's extents. +//////////////////////////////////////////////////////////////////// +void PhysxBoxController:: +set_extents(const LVector3f &extents) { + + nassertv(_error_type == ET_ok); + _ptr->setExtents(PhysxManager::vec3_to_nxVec3(extents)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxController::get_extents +// Access: Published +// Description: Returns controller's extents. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxBoxController:: +get_extents() const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(_ptr->getExtents()); +} + diff --git a/panda/src/physx/physxBoxController.h b/panda/src/physx/physxBoxController.h new file mode 100644 index 0000000000..1ac470f80f --- /dev/null +++ b/panda/src/physx/physxBoxController.h @@ -0,0 +1,72 @@ +// Filename: physxBoxController.h +// Created by: enn0x (24Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXBOXCONTROLLER_H +#define PHYSXBOXCONTROLLER_H + +#include "pandabase.h" +#include "lvector3.h" + +#include "physxController.h" + +#include "NxBoxController.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxBoxController +// Description : Box character controller. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxBoxController : public PhysxController { + +PUBLISHED: + INLINE PhysxBoxController(); + INLINE ~PhysxBoxController(); + + void set_extents(const LVector3f &extents); + LVector3f get_extents() const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxController *ptr() const { return (NxController *)_ptr; }; + + void link(NxController *controllerPtr); + void unlink(); + +private: + NxBoxController *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxController::init_type(); + register_type(_type_handle, "PhysxBoxController", + PhysxController::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxBoxController.I" + +#endif // PHYSXBOXCONTROLLER_H diff --git a/panda/src/physx/physxBoxControllerDesc.I b/panda/src/physx/physxBoxControllerDesc.I new file mode 100644 index 0000000000..002d2fd34c --- /dev/null +++ b/panda/src/physx/physxBoxControllerDesc.I @@ -0,0 +1,59 @@ +// Filename: physxBoxControllerDesc.I +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxControllerDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxBoxControllerDesc:: +PhysxBoxControllerDesc() : PhysxControllerDesc() { + + _desc.upDirection = (NxHeightFieldAxis)physx_up_axis.get_value(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxControllerDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxBoxControllerDesc:: +~PhysxBoxControllerDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxControllerDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxBoxControllerDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxControllerDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxBoxControllerDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxBoxControllerDesc.cxx b/panda/src/physx/physxBoxControllerDesc.cxx new file mode 100644 index 0000000000..30123a3a78 --- /dev/null +++ b/panda/src/physx/physxBoxControllerDesc.cxx @@ -0,0 +1,43 @@ +// Filename: physxBoxControllerDesc.cxx +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxBoxControllerDesc.h" +#include "physxManager.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxControllerDesc::set_extents +// Access: Published +// Description: Sets the dimensions of the box. +// +// The dimensions are the 'radii' of the box, +// meaning 1/2 extents in x dimension, 1/2 extents +// in y dimension, 1/2 extents in z dimension. +//////////////////////////////////////////////////////////////////// +void PhysxBoxControllerDesc:: +set_extents(const LVector3f &extents) { + + _desc.extents = PhysxManager::vec3_to_nxVec3(extents); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxControllerDesc::get_extents +// Access: Published +// Description: Returns the dimensions of the box. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxBoxControllerDesc:: +get_extents() const { + + return PhysxManager::nxVec3_to_vec3(_desc.extents); +} + diff --git a/panda/src/physx/physxBoxControllerDesc.h b/panda/src/physx/physxBoxControllerDesc.h new file mode 100644 index 0000000000..c9d63c3820 --- /dev/null +++ b/panda/src/physx/physxBoxControllerDesc.h @@ -0,0 +1,49 @@ +// Filename: physxBoxControllerDesc.h +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXBOXCONTROLLERDESC_H +#define PHYSXBOXCONTROLLERDESC_H + +#include "pandabase.h" +#include "lvector3.h" + +#include "physxControllerDesc.h" + +#include "NxBoxController.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxBoxControllerDesc +// Description : Descriptor class for PhysxBoxController. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxBoxControllerDesc : public PhysxControllerDesc { + +PUBLISHED: + INLINE PhysxBoxControllerDesc(); + INLINE ~PhysxBoxControllerDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_extents(const LVector3f &extents); + + LVector3f get_extents() const; + +public: + NxControllerDesc *ptr() const { return (NxControllerDesc *)&_desc; }; + NxBoxControllerDesc _desc; +}; + +#include "physxBoxControllerDesc.I" + +#endif // PHYSXBOXCONTROLLERDESC_H diff --git a/panda/src/physx/physxTemplate.h b/panda/src/physx/physxBoxForceFieldShape.I similarity index 50% rename from panda/src/physx/physxTemplate.h rename to panda/src/physx/physxBoxForceFieldShape.I index 52cbc97cd2..2c6bbbafa0 100644 --- a/panda/src/physx/physxTemplate.h +++ b/panda/src/physx/physxBoxForceFieldShape.I @@ -1,5 +1,5 @@ -// Filename: physxTemplate.h -// Created by: pratt (Dec 12, 2007) +// Filename: physxBoxForceFieldShape.I +// Created by: enn0x (15Nov09) // //////////////////////////////////////////////////////////////////// // @@ -12,37 +12,25 @@ // //////////////////////////////////////////////////////////////////// -#ifndef PHYSXTEMPLATE_H -#define PHYSXTEMPLATE_H -#ifdef HAVE_PHYSX - -#include "pandabase.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -//superHeader -//forwardDeclarations -#include "NxPhysics.h" //////////////////////////////////////////////////////////////////// -// Class : PhysxTemplate -// Description : +// Function: PhysxBoxForceFieldShape::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxTemplate /*baseclassref*/{ -PUBLISHED: -//publicstructors -//publicmethods -//publicattributes -public: -//nxreference -//typeinfo -}; +INLINE PhysxBoxForceFieldShape:: +PhysxBoxForceFieldShape() : PhysxForceFieldShape() { -#include "physxTemplate.I" +} -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxForceFieldShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxBoxForceFieldShape:: +~PhysxBoxForceFieldShape() { + +} -#endif // PHYSXTEMPLATE_H diff --git a/panda/src/physx/physxBoxForceFieldShape.cxx b/panda/src/physx/physxBoxForceFieldShape.cxx new file mode 100644 index 0000000000..ecea5ce0d7 --- /dev/null +++ b/panda/src/physx/physxBoxForceFieldShape.cxx @@ -0,0 +1,96 @@ +// Filename: physxBoxForceFieldShape.cxx +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxBoxForceFieldShape.h" +#include "physxBoxForceFieldShapeDesc.h" +#include "physxManager.h" + +TypeHandle PhysxBoxForceFieldShape::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxForceFieldShape::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxBoxForceFieldShape:: +link(NxForceFieldShape *shapePtr) { + + _ptr = shapePtr->isBox(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)_ptr->getShapeGroup().userData; + group->_shapes.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxForceFieldShape::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxBoxForceFieldShape:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)_ptr->getShapeGroup().userData; + group->_shapes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxBoxForceFieldShape::save_to_desc +// Access : Published +// Description : Saves the state of the shape object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxBoxForceFieldShape:: +save_to_desc(PhysxBoxForceFieldShapeDesc &shapeDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxForceFieldShape::set_dimensions +// Access: Published +// Description: Sets the box dimensions. +// +// The dimensions are the 'radii' of the box, +// meaning 1/2 extents in x dimension, 1/2 extents +// in y dimension, 1/2 extents in z dimension. +//////////////////////////////////////////////////////////////////// +void PhysxBoxForceFieldShape:: +set_dimensions(const LVector3f &vec) { + + nassertv(_error_type == ET_ok); + _ptr->setDimensions(PhysxManager::vec3_to_nxVec3(vec)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxForceFieldShape::get_dimensions +// Access: Published +// Description: Retrieves the dimensions of the box. +// +// The dimensions are the 'radii' of the box, +// meaning 1/2 extents in x dimension, 1/2 extents +// in y dimension, 1/2 extents in z dimension. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxBoxForceFieldShape:: +get_dimensions() const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(_ptr->getDimensions()); +} + diff --git a/panda/src/physx/physxBoxForceFieldShape.h b/panda/src/physx/physxBoxForceFieldShape.h new file mode 100644 index 0000000000..fd7ce6503b --- /dev/null +++ b/panda/src/physx/physxBoxForceFieldShape.h @@ -0,0 +1,77 @@ +// Filename: physxBoxForceFieldShape.h +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXBOXFORCEFIELDSHAPE_H +#define PHYSXBOXFORCEFIELDSHAPE_H + +#include "pandabase.h" +#include "lvector3.h" + +#include "physxForceFieldShape.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxBoxForceFieldShapeDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxBoxForceFieldShape +// Description : A box shaped region used to define a force field. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxBoxForceFieldShape : public PhysxForceFieldShape { + +PUBLISHED: + INLINE PhysxBoxForceFieldShape(); + INLINE ~PhysxBoxForceFieldShape(); + + void save_to_desc(PhysxBoxForceFieldShapeDesc &shapeDesc) const; + + void set_dimensions(const LVector3f &dimensions); + LVector3f get_dimensions() const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxForceFieldShape *ptr() const { return (NxForceFieldShape *)_ptr; }; + + void link(NxForceFieldShape *shapePtr); + void unlink(); + +private: + NxBoxForceFieldShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxForceFieldShape::init_type(); + register_type(_type_handle, "PhysxBoxForceFieldShape", + PhysxForceFieldShape::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxBoxForceFieldShape.I" + +#endif // PHYSXBOXFORCEFIELDSHAPE_H diff --git a/panda/src/physx/physxBoxForceFieldShapeDesc.I b/panda/src/physx/physxBoxForceFieldShapeDesc.I new file mode 100644 index 0000000000..168e2f47e4 --- /dev/null +++ b/panda/src/physx/physxBoxForceFieldShapeDesc.I @@ -0,0 +1,59 @@ +// Filename: physxBoxForceFieldShapeDesc.I +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxForceFieldShapeDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxBoxForceFieldShapeDesc:: +PhysxBoxForceFieldShapeDesc() : PhysxForceFieldShapeDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxForceFieldShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxBoxForceFieldShapeDesc:: +~PhysxBoxForceFieldShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxForceFieldShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxBoxForceFieldShapeDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxForceFieldShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxBoxForceFieldShapeDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxBoxForceFieldShapeDesc.cxx b/panda/src/physx/physxBoxForceFieldShapeDesc.cxx new file mode 100644 index 0000000000..98e66affad --- /dev/null +++ b/panda/src/physx/physxBoxForceFieldShapeDesc.cxx @@ -0,0 +1,44 @@ +// Filename: physxBoxForceFieldShapeDesc.cxx +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxBoxForceFieldShapeDesc.h" +#include "physxManager.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxForceFieldShapeDesc::set_dimensions +// Access: Published +// Description: Sets the dimensions of the box. +// +// The dimensions are the 'radii' of the box, +// meaning 1/2 extents in x dimension, 1/2 extents +// in y dimension, 1/2 extents in z dimension. +//////////////////////////////////////////////////////////////////// +void PhysxBoxForceFieldShapeDesc:: +set_dimensions(const LVector3f &dimensions) { + + nassertv(!dimensions.is_nan()); + _desc.dimensions = PhysxManager::vec3_to_nxVec3(dimensions); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxForceFieldShapeDesc::get_dimensions +// Access: Published +// Description: Returns the dimensions of the box. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxBoxForceFieldShapeDesc:: +get_dimensions() const { + + return PhysxManager::nxVec3_to_vec3(_desc.dimensions); +} + diff --git a/panda/src/physx/physxBoxForceFieldShapeDesc.h b/panda/src/physx/physxBoxForceFieldShapeDesc.h new file mode 100644 index 0000000000..910874eaf7 --- /dev/null +++ b/panda/src/physx/physxBoxForceFieldShapeDesc.h @@ -0,0 +1,50 @@ +// Filename: physxBoxForceFieldShapeDesc.h +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXBOXFORCEFIELDSHAPEDESC_H +#define PHYSXBOXFORCEFIELDSHAPEDESC_H + +#include "pandabase.h" +#include "lvector3.h" + +#include "physxForceFieldShapeDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxBoxForceFieldShapeDesc +// Description : Descriptor for a box force field shape. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxBoxForceFieldShapeDesc : public PhysxForceFieldShapeDesc { + +PUBLISHED: + INLINE PhysxBoxForceFieldShapeDesc(); + INLINE ~PhysxBoxForceFieldShapeDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_dimensions(const LVector3f &dimensions); + + LVector3f get_dimensions() const; + +public: + NxForceFieldShapeDesc *ptr() const { return (NxForceFieldShapeDesc *)&_desc; }; + NxBoxForceFieldShapeDesc _desc; +}; + +#include "physxBoxForceFieldShapeDesc.I" + +#endif // PHYSXBOXFORCEFIELDSHAPEDESC_H diff --git a/panda/src/physx/physxBoxShape.I b/panda/src/physx/physxBoxShape.I index d9c4dd4582..730f806b10 100644 --- a/panda/src/physx/physxBoxShape.I +++ b/panda/src/physx/physxBoxShape.I @@ -1,5 +1,5 @@ // Filename: physxBoxShape.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,3 +12,25 @@ // //////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxBoxShape:: +PhysxBoxShape() : PhysxShape() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxBoxShape:: +~PhysxBoxShape() { + +} + diff --git a/panda/src/physx/physxBoxShape.cxx b/panda/src/physx/physxBoxShape.cxx index f6334ffa92..66972a4f8a 100644 --- a/panda/src/physx/physxBoxShape.cxx +++ b/panda/src/physx/physxBoxShape.cxx @@ -1,5 +1,5 @@ // Filename: physxBoxShape.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,63 +12,85 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxBoxShape.h" - -#include "luse.h" -#include "physxBox.h" #include "physxBoxShapeDesc.h" +#include "physxManager.h" TypeHandle PhysxBoxShape::_type_handle; //////////////////////////////////////////////////////////////////// -// Function : get_dimensions -// Access : Published -// Description : +// Function: PhysxBoxShape::link +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxBoxShape:: +void PhysxBoxShape:: +link(NxShape *shapePtr) { + + _ptr = shapePtr->isBox(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxShape::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxBoxShape:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxBoxShape::save_to_desc +// Access : Published +// Description : Saves the state of the shape object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxBoxShape:: +save_to_desc(PhysxBoxShapeDesc &shapeDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxShape::set_dimensions +// Access: Published +// Description: Sets the box dimensions. +// +// The dimensions are the 'radii' of the box, +// meaning 1/2 extents in x dimension, 1/2 extents +// in y dimension, 1/2 extents in z dimension. +//////////////////////////////////////////////////////////////////// +void PhysxBoxShape:: +set_dimensions(const LVector3f &vec) { + + nassertv(_error_type == ET_ok); + _ptr->setDimensions(PhysxManager::vec3_to_nxVec3(vec)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxShape::get_dimensions +// Access: Published +// Description: Retrieves the dimensions of the box. +// +// The dimensions are the 'radii' of the box, +// meaning 1/2 extents in x dimension, 1/2 extents +// in y dimension, 1/2 extents in z dimension. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxBoxShape:: get_dimensions() const { - nassertr(nBoxShape != NULL, *((LVecBase3f *)NULL)); - return PhysxManager::nxVec3_to_lVecBase3(nBoxShape->getDimensions()); + nassertr(_error_type == ET_ok, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(_ptr->getDimensions()); } -//////////////////////////////////////////////////////////////////// -// Function : get_world_obb -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxBoxShape:: -get_world_obb(PhysxBox & obb) const { - nassertv(nBoxShape != NULL); - - nBoxShape->getWorldOBB(*(obb.nBox)); -} - -//////////////////////////////////////////////////////////////////// -// Function : save_to_desc -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxBoxShape:: -save_to_desc(PhysxBoxShapeDesc & desc) const { - nassertv(nBoxShape != NULL); - - nBoxShape->saveToDesc(desc.nBoxShapeDesc); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_dimensions -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxBoxShape:: -set_dimensions(const LVecBase3f & vec) { - nassertv(nBoxShape != NULL); - - nBoxShape->setDimensions(PhysxManager::lVecBase3_to_nxVec3(vec)); -} - -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxBoxShape.h b/panda/src/physx/physxBoxShape.h index dfbfcdb08f..c430997781 100644 --- a/panda/src/physx/physxBoxShape.h +++ b/panda/src/physx/physxBoxShape.h @@ -1,5 +1,5 @@ // Filename: physxBoxShape.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,43 +15,60 @@ #ifndef PHYSXBOXSHAPE_H #define PHYSXBOXSHAPE_H -#ifdef HAVE_PHYSX - #include "pandabase.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "lvector3.h" #include "physxShape.h" -class PhysxBox; -class PhysxBoxShapeDesc; - +#include "NoMinMax.h" #include "NxPhysics.h" +class PhysxBoxShapeDesc; + //////////////////////////////////////////////////////////////////// // Class : PhysxBoxShape -// Description : +// Description : A box shaped collision detection primitive. Each +// shape is owned by the actor which it is attached +// to. +// +// An instance can be created by calling the +// createShape() method of the PhysxActor object that +// will own it, with a PhysxBoxShapeDesc object as the +// parameter, or by adding the shape descriptor to the +// PhysxActorDesc class before creating the actor. +// +// The shape is deleted by calling release() on the +// shape itself. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxBoxShape : public PhysxShape { + PUBLISHED: + INLINE PhysxBoxShape(); + INLINE ~PhysxBoxShape(); - LVecBase3f get_dimensions() const; - void get_world_obb(PhysxBox & obb) const; - void save_to_desc(PhysxBoxShapeDesc & desc) const; - void set_dimensions(const LVecBase3f & vec); + void save_to_desc(PhysxBoxShapeDesc &shapeDesc) const; + void set_dimensions(const LVector3f &dimensions); + LVector3f get_dimensions() const; +//////////////////////////////////////////////////////////////////// public: - NxBoxShape *nBoxShape; + INLINE NxShape *ptr() const { return (NxShape *)_ptr; }; + void link(NxShape *shapePtr); + void unlink(); + +private: + NxBoxShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: static TypeHandle get_class_type() { return _type_handle; } static void init_type() { PhysxShape::init_type(); - register_type(_type_handle, "PhysxBoxShape", + register_type(_type_handle, "PhysxBoxShape", PhysxShape::get_class_type()); } virtual TypeHandle get_type() const { @@ -68,6 +85,4 @@ private: #include "physxBoxShape.I" -#endif // HAVE_PHYSX - #endif // PHYSXBOXSHAPE_H diff --git a/panda/src/physx/physxBoxShapeDesc.I b/panda/src/physx/physxBoxShapeDesc.I index 5113831345..e2503a02c9 100644 --- a/panda/src/physx/physxBoxShapeDesc.I +++ b/panda/src/physx/physxBoxShapeDesc.I @@ -1,5 +1,5 @@ // Filename: physxBoxShapeDesc.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (08Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,23 +12,48 @@ // //////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxBoxShapeDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxBoxShapeDesc:: -is_valid() const { - return nBoxShapeDesc.isValid(); +INLINE PhysxBoxShapeDesc:: +PhysxBoxShapeDesc() : PhysxShapeDesc() { + + _desc.name = ""; } //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxBoxShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxBoxShapeDesc:: +~PhysxBoxShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. //////////////////////////////////////////////////////////////////// INLINE void PhysxBoxShapeDesc:: set_to_default() { - nBoxShapeDesc.setToDefault(); + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxBoxShapeDesc:: +is_valid() const { + + return _desc.isValid(); } diff --git a/panda/src/physx/physxBoxShapeDesc.cxx b/panda/src/physx/physxBoxShapeDesc.cxx index dcd6f633e6..5c955b4cdb 100644 --- a/panda/src/physx/physxBoxShapeDesc.cxx +++ b/panda/src/physx/physxBoxShapeDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxBoxShapeDesc.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (08Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,43 +12,33 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxBoxShapeDesc.h" - -#include "luse.h" - +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxBoxShapeDesc -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxBoxShapeDesc:: -PhysxBoxShapeDesc() -: PhysxShapeDesc( &nBoxShapeDesc ) { - -} - -//////////////////////////////////////////////////////////////////// -// Function : get_dimensions -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxBoxShapeDesc:: -get_dimensions() const { - return PhysxManager::nxVec3_to_lVecBase3(nBoxShapeDesc.dimensions); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_dimensions -// Access : Published -// Description : +// Function: PhysxBoxShapeDesc::set_dimensions +// Access: Published +// Description: Sets the dimensions of the box. +// +// The dimensions are the 'radii' of the box, +// meaning 1/2 extents in x dimension, 1/2 extents +// in y dimension, 1/2 extents in z dimension. //////////////////////////////////////////////////////////////////// void PhysxBoxShapeDesc:: -set_dimensions(LVecBase3f value) { - nBoxShapeDesc.dimensions = PhysxManager::lVecBase3_to_nxVec3(value); +set_dimensions(const LVector3f &dimensions) { + + nassertv(!dimensions.is_nan()); + _desc.dimensions = PhysxManager::vec3_to_nxVec3(dimensions); } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxBoxShapeDesc::get_dimensions +// Access: Published +// Description: Returns the dimensions of the box. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxBoxShapeDesc:: +get_dimensions() const { + + return PhysxManager::nxVec3_to_vec3(_desc.dimensions); +} diff --git a/panda/src/physx/physxBoxShapeDesc.h b/panda/src/physx/physxBoxShapeDesc.h index 532be0c53b..21cd5811e1 100644 --- a/panda/src/physx/physxBoxShapeDesc.h +++ b/panda/src/physx/physxBoxShapeDesc.h @@ -1,5 +1,5 @@ // Filename: physxBoxShapeDesc.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (08Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,39 +15,36 @@ #ifndef PHYSXBOXSHAPEDESC_H #define PHYSXBOXSHAPEDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "lvector3.h" #include "physxShapeDesc.h" +#include "NoMinMax.h" #include "NxPhysics.h" //////////////////////////////////////////////////////////////////// // Class : PhysxBoxShapeDesc -// Description : +// Description : Descriptor class for PhysxBoxShape. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxBoxShapeDesc : public PhysxShapeDesc { + PUBLISHED: - PhysxBoxShapeDesc(); + INLINE PhysxBoxShapeDesc(); + INLINE ~PhysxBoxShapeDesc(); - INLINE bool is_valid() const; INLINE void set_to_default(); + INLINE bool is_valid() const; - LVecBase3f get_dimensions() const; + void set_dimensions(const LVector3f &dimensions); - void set_dimensions( LVecBase3f value ); + LVector3f get_dimensions() const; public: - NxBoxShapeDesc nBoxShapeDesc; + NxShapeDesc *ptr() const { return (NxShapeDesc *)&_desc; }; + NxBoxShapeDesc _desc; }; #include "physxBoxShapeDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXBOXSHAPEDESC_H diff --git a/panda/src/physx/physxCapsule.I b/panda/src/physx/physxCapsule.I index 5cf3966aa5..8d901da7d8 100644 --- a/panda/src/physx/physxCapsule.I +++ b/panda/src/physx/physxCapsule.I @@ -1,5 +1,5 @@ // Filename: physxCapsule.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,27 +12,35 @@ // //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function : get_radius -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxCapsule:: -get_radius() const { - nassertr(nCapsule != NULL, -1.0f); - return nCapsule->radius; +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsule:: +PhysxCapsule() { + } //////////////////////////////////////////////////////////////////// -// Function : set_radius -// Access : Published -// Description : +// Function: PhysxCapsule::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE void PhysxCapsule:: -set_radius(float value) { - nassertv(nCapsule != NULL); +INLINE PhysxCapsule:: +PhysxCapsule(const PhysxSegment &segment, float radius) { + + _capsule = NxCapsule(segment._segment, radius); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsule:: +~PhysxCapsule() { - nCapsule->radius = value; } diff --git a/panda/src/physx/physxCapsule.cxx b/panda/src/physx/physxCapsule.cxx index 456d391ad0..029c1b9fb5 100644 --- a/panda/src/physx/physxCapsule.cxx +++ b/panda/src/physx/physxCapsule.cxx @@ -1,5 +1,5 @@ // Filename: physxCapsule.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,32 +12,158 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxCapsule.h" - -#include "physxSegment.h" - +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxCapsule -// Access : Published -// Description : +// Function: PhysxCapsule::get_radius +// Access: Published +// Description: Returns the capsule's radius. //////////////////////////////////////////////////////////////////// -PhysxCapsule:: -PhysxCapsule(const PhysxSegment & seg, float _radius) { +float PhysxCapsule:: +get_radius() const { + return _capsule.radius; } //////////////////////////////////////////////////////////////////// -// Function : ~PhysxCapsule -// Access : Published -// Description : +// Function: PhysxCapsule::set_radius +// Access: Published +// Description: Sets the capsule's radius. //////////////////////////////////////////////////////////////////// -PhysxCapsule:: -~PhysxCapsule() { +void PhysxCapsule:: +set_radius(float radius) { + _capsule.radius = radius; } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::get_p0 +// Access: Published +// Description: Returns the start point of the segment. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxCapsule:: +get_p0() const { + + return PhysxManager::nxVec3_to_vec3(_capsule.p0); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::set_p0 +// Access: Published +// Description: Sets the start point of the segment. +//////////////////////////////////////////////////////////////////// +void PhysxCapsule:: +set_p0(LPoint3f p) { + + nassertv(!p.is_nan()); + + _capsule.p0 = PhysxManager::vec3_to_nxVec3(p); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::get_p1 +// Access: Published +// Description: Returns the end point of the segment. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxCapsule:: +get_p1() const { + + return PhysxManager::nxVec3_to_vec3(_capsule.p1); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::set_p1 +// Access: Published +// Description: Sets the end point of the segment. +//////////////////////////////////////////////////////////////////// +void PhysxCapsule:: +set_p1(LPoint3f p) { + + nassertv(!p.is_nan()); + + _capsule.p1 = PhysxManager::vec3_to_nxVec3(p); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::get_origin +// Access: Published +// Description: Returns the start point of the segment. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxCapsule:: +get_origin() const { + + return PhysxManager::nxVec3_to_point3(_capsule.getOrigin()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::compute_direction +// Access: Published +// Description: Returns the direction vector from the segment's +// start point to it's end point. +//////////////////////////////////////////////////////////////////// +void PhysxCapsule:: +compute_direction(LPoint3f &dir) const { + + nassertv(!dir.is_nan()); + + NxVec3 nDir = PhysxManager::point3_to_nxVec3(dir); + _capsule.computeDirection(nDir); + PhysxManager::update_point3_from_nxVec3(dir, nDir); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::compute_length +// Access: Published +// Description: Returns the distance from the segment's start point +// to it's end point. +//////////////////////////////////////////////////////////////////// +float PhysxCapsule:: +compute_length() const { + + return _capsule.computeLength(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::compute_point +// Access: Published +// Description: Computes a point on the segment. +//////////////////////////////////////////////////////////////////// +void PhysxCapsule:: +compute_point(LPoint3f &p, float t) const { + + nassertv(!p.is_nan()); + + NxVec3 nP = PhysxManager::point3_to_nxVec3(p); + _capsule.computePoint(nP, t); + PhysxManager::update_point3_from_nxVec3(p, nP); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::compute_square_length +// Access: Published +// Description: Returns the square distance from the segment's +// start point to it's end point. +//////////////////////////////////////////////////////////////////// +float PhysxCapsule:: +compute_square_length() const { + + return _capsule.computeSquareLength(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsule::set_origin_direction +// Access: Published +// Description: Setup this capsule from origin (start point) and +// direction vector. +//////////////////////////////////////////////////////////////////// +void PhysxCapsule:: +set_origin_direction(const LPoint3f &origin, const LVector3f &direction) { + + nassertv(!origin.is_nan()); + nassertv(!direction.is_nan()); + + _capsule.setOriginDirection(PhysxManager::point3_to_nxVec3(origin), + PhysxManager::vec3_to_nxVec3(direction)); +} diff --git a/panda/src/physx/physxCapsule.h b/panda/src/physx/physxCapsule.h index 33c38cec42..7d32826e27 100644 --- a/panda/src/physx/physxCapsule.h +++ b/panda/src/physx/physxCapsule.h @@ -1,5 +1,5 @@ // Filename: physxCapsule.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,38 +15,41 @@ #ifndef PHYSXCAPSULE_H #define PHYSXCAPSULE_H -#ifdef HAVE_PHYSX - #include "pandabase.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - +#include "config_physx.h" #include "physxSegment.h" -#include "NxPhysics.h" - //////////////////////////////////////////////////////////////////// // Class : PhysxCapsule -// Description : +// Description : Represents a capsule. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxCapsule : public PhysxSegment { +class EXPCL_PANDAPHYSX PhysxCapsule { + PUBLISHED: - PhysxCapsule(const PhysxSegment & seg, float _radius); - ~PhysxCapsule(); + INLINE PhysxCapsule(); + INLINE PhysxCapsule(const PhysxSegment &segment, float radius); + INLINE ~PhysxCapsule(); + void compute_direction(LPoint3f &dir) const; + float compute_length() const; + void compute_point(LPoint3f &p, float t) const; + float compute_square_length() const; + LPoint3f get_origin() const; + void set_origin_direction(const LPoint3f &origin, const LVector3f &direction); - INLINE float get_radius() const; + float get_radius() const; + LPoint3f get_p0() const; + LPoint3f get_p1() const; - INLINE void set_radius( float value ); + void set_radius(float value); + void set_p0(LPoint3f p); + void set_p1(LPoint3f p); public: - NxCapsule *nCapsule; + NxCapsule _capsule; }; #include "physxCapsule.I" -#endif // HAVE_PHYSX - -#endif // PHYSXCAPSULE_H +#endif // PHYSCAPSULE_H diff --git a/panda/src/physx/physxCapsuleController.I b/panda/src/physx/physxCapsuleController.I new file mode 100644 index 0000000000..7c4e23e631 --- /dev/null +++ b/panda/src/physx/physxCapsuleController.I @@ -0,0 +1,36 @@ +// Filename: physxCapsuleController.I +// Created by: enn0x (24Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleController::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsuleController:: +PhysxCapsuleController() : PhysxController() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleController::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsuleController:: +~PhysxCapsuleController() { + +} + diff --git a/panda/src/physx/physxCapsuleController.cxx b/panda/src/physx/physxCapsuleController.cxx new file mode 100644 index 0000000000..6313774c21 --- /dev/null +++ b/panda/src/physx/physxCapsuleController.cxx @@ -0,0 +1,108 @@ +// Filename: physxCapsuleController.cxx +// Created by: enn0x (24Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxCapsuleController.h" + +TypeHandle PhysxCapsuleController::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleController::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleController:: +link(NxController *controllerPtr) { + + nassertv(controllerPtr->getType() == NX_CONTROLLER_CAPSULE); + + // Link self + _ptr = (NxCapsuleController *)controllerPtr; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getActor()->getScene().userData; + scene->_controllers.add(this); + + // Link actor + PT(PhysxActor) actor = new PhysxActor(); + actor->link(_ptr->getActor()); + actor->link_controller(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleController::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleController:: +unlink() { + + // Unlink actor + PT(PhysxActor) actor = (PhysxActor *)ptr()->getActor()->userData; + actor->unlink(); + + // Unlink self + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getActor()->getScene().userData; + scene->_controllers.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleController::set_radius +// Access: Published +// Description: Resets the controller's radius. +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleController:: +set_radius(float radius) { + + nassertv(_error_type == ET_ok); + _ptr->setRadius(radius); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleController::set_height +// Access: Published +// Description: Resets the controller's height. +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleController:: +set_height(float height) { + + nassertv(_error_type == ET_ok); + _ptr->setHeight(height); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleController::get_radius +// Access: Published +// Description: Returns the controller's radius. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleController:: +get_radius() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getRadius(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleController::get_height +// Access: Published +// Description: Returns the controller's height. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleController:: +get_height() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getHeight(); +} + diff --git a/panda/src/physx/physxCapsuleController.h b/panda/src/physx/physxCapsuleController.h new file mode 100644 index 0000000000..3cf064a7a8 --- /dev/null +++ b/panda/src/physx/physxCapsuleController.h @@ -0,0 +1,90 @@ +// Filename: physxCapsuleController.h +// Created by: enn0x (24Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCAPSULECONTROLLER_H +#define PHYSXCAPSULECONTROLLER_H + +#include "pandabase.h" +#include "lvector3.h" + +#include "physxController.h" + +#include "NxCapsuleController.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxCapsuleController +// Description : A capsule character controller. +// +// The capsule is defined as a position, a vertical +// height, and a radius. The height is the same height +// as for PhysxCapsuleShape objects, i.e. the distance +// between the two sphere centers at the end of the +// capsule. In other words: +// +// p = pos (returned by controller) +// h = height +// r = radius +// +// p = center of capsule +// top sphere center = p.y + h*0.5 +// bottom sphere center = p.y - h*0.5 +// top capsule point = p.y + h*0.5 + r +// bottom capsule point = p.y - h*0.5 - r +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxCapsuleController : public PhysxController { + +PUBLISHED: + INLINE PhysxCapsuleController(); + INLINE ~PhysxCapsuleController(); + + void set_radius(float radius); + void set_height(float height); + float get_radius() const; + float get_height() const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxController *ptr() const { return (NxController *)_ptr; }; + + void link(NxController *controllerPtr); + void unlink(); + +private: + NxCapsuleController *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxController::init_type(); + register_type(_type_handle, "PhysxCapsuleController", + PhysxController::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxCapsuleController.I" + +#endif // PHYSXCAPSULECONTROLLER_H diff --git a/panda/src/physx/physxCapsuleControllerDesc.I b/panda/src/physx/physxCapsuleControllerDesc.I new file mode 100644 index 0000000000..3f4334d99f --- /dev/null +++ b/panda/src/physx/physxCapsuleControllerDesc.I @@ -0,0 +1,59 @@ +// Filename: physxCapsuleControllerDesc.I +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleControllerDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsuleControllerDesc:: +PhysxCapsuleControllerDesc() : PhysxControllerDesc() { + + _desc.upDirection = (NxHeightFieldAxis)physx_up_axis.get_value(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleControllerDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsuleControllerDesc:: +~PhysxCapsuleControllerDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleControllerDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxCapsuleControllerDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleControllerDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxCapsuleControllerDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxCapsuleControllerDesc.cxx b/panda/src/physx/physxCapsuleControllerDesc.cxx new file mode 100644 index 0000000000..ceee92029d --- /dev/null +++ b/panda/src/physx/physxCapsuleControllerDesc.cxx @@ -0,0 +1,64 @@ +// Filename: physxCapsuleControllerDesc.cxx +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxCapsuleControllerDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleControllerDesc::set_radius +// Access: Published +// Description: Sets the radius of the capsule's hemispherical +// ends and its trunk. +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleControllerDesc:: +set_radius(float radius) { + + _desc.radius = radius; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleControllerDesc::set_height +// Access: Published +// Description: Sets the distance between the two hemispherical +// ends of the capsule. +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleControllerDesc:: +set_height(float height) { + + _desc.height = height; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleControllerDesc::get_radius +// Access: Published +// Description: The radius of the capsule's hemispherical ends +// and its trunk. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleControllerDesc:: +get_radius() const { + + return _desc.radius; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleControllerDesc::get_height +// Access: Published +// Description: The distance between the two hemispherical ends +// of the capsule. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleControllerDesc:: +get_height() const { + + return _desc.height; +} + diff --git a/panda/src/physx/physxCapsuleControllerDesc.h b/panda/src/physx/physxCapsuleControllerDesc.h new file mode 100644 index 0000000000..0cdb9eb630 --- /dev/null +++ b/panda/src/physx/physxCapsuleControllerDesc.h @@ -0,0 +1,50 @@ +// Filename: physxCapsuleControllerDesc.h +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCAPSULECONTROLLERDESC_H +#define PHYSXCAPSULECONTROLLERDESC_H + +#include "pandabase.h" + +#include "physxControllerDesc.h" + +#include "NxCapsuleController.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxCapsuleControllerDesc +// Description : Descriptor class for PhysxCapsuleController. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxCapsuleControllerDesc : public PhysxControllerDesc { + +PUBLISHED: + INLINE PhysxCapsuleControllerDesc(); + INLINE ~PhysxCapsuleControllerDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_radius(float radius); + void set_height(float height); + + float get_radius() const; + float get_height() const; + +public: + NxControllerDesc *ptr() const { return (NxControllerDesc *)&_desc; }; + NxCapsuleControllerDesc _desc; +}; + +#include "physxCapsuleControllerDesc.I" + +#endif // PHYSXCAPSULECONTROLLERDESC_H diff --git a/panda/src/physx/physxCapsuleForceFieldShape.I b/panda/src/physx/physxCapsuleForceFieldShape.I new file mode 100644 index 0000000000..f4cc2b9a94 --- /dev/null +++ b/panda/src/physx/physxCapsuleForceFieldShape.I @@ -0,0 +1,36 @@ +// Filename: physxCapsuleForceFieldShape.I +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsuleForceFieldShape:: +PhysxCapsuleForceFieldShape() : PhysxForceFieldShape() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsuleForceFieldShape:: +~PhysxCapsuleForceFieldShape() { + +} + diff --git a/panda/src/physx/physxCapsuleForceFieldShape.cxx b/panda/src/physx/physxCapsuleForceFieldShape.cxx new file mode 100644 index 0000000000..fc0f84b035 --- /dev/null +++ b/panda/src/physx/physxCapsuleForceFieldShape.cxx @@ -0,0 +1,111 @@ +// Filename: physxCapsuleForceFieldShape.cxx +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxCapsuleForceFieldShape.h" +#include "physxCapsuleForceFieldShapeDesc.h" + +TypeHandle PhysxCapsuleForceFieldShape::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShape::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleForceFieldShape:: +link(NxForceFieldShape *shapePtr) { + + _ptr = shapePtr->isCapsule(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)_ptr->getShapeGroup().userData; + group->_shapes.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShape::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleForceFieldShape:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)_ptr->getShapeGroup().userData; + group->_shapes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxCapsuleForceFieldShape::save_to_desc +// Access : Published +// Description : Saves the state of the shape object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleForceFieldShape:: +save_to_desc(PhysxCapsuleForceFieldShapeDesc &shapeDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShape::set_radius +// Access: Published +// Description: Alters the radius of the capsule. +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleForceFieldShape:: +set_radius(float radius) { + + nassertv(_error_type == ET_ok); + _ptr->setRadius(radius); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShape::set_height +// Access: Published +// Description: Alters the height of the capsule. +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleForceFieldShape:: +set_height(float height) { + + nassertv(_error_type == ET_ok); + _ptr->setHeight(height); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShape::get_radius +// Access: Published +// Description: Retrieves the radius of the capsule. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleForceFieldShape:: +get_radius() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getRadius(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShape::get_height +// Access: Published +// Description: Retrieves the height of the capsule. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleForceFieldShape:: +get_height() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getHeight(); +} + diff --git a/panda/src/physx/physxCapsuleForceFieldShape.h b/panda/src/physx/physxCapsuleForceFieldShape.h new file mode 100644 index 0000000000..4f478cfc43 --- /dev/null +++ b/panda/src/physx/physxCapsuleForceFieldShape.h @@ -0,0 +1,81 @@ +// Filename: physxCapsuleForceFieldShape.h +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCAPSULEFORCEFIELDSHAPE_H +#define PHYSXCAPSULEFORCEFIELDSHAPE_H + +#include "pandabase.h" +#include "lvector3.h" + +#include "physxForceFieldShape.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxCapsuleForceFieldShapeDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxCapsuleForceFieldShape +// Description : A capsule shaped region used to define a force +// field. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxCapsuleForceFieldShape : public PhysxForceFieldShape { + +PUBLISHED: + INLINE PhysxCapsuleForceFieldShape(); + INLINE ~PhysxCapsuleForceFieldShape(); + + void save_to_desc(PhysxCapsuleForceFieldShapeDesc &shapeDesc) const; + + void set_radius(float radius); + void set_height(float height); + + float get_radius() const; + float get_height() const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxForceFieldShape *ptr() const { return (NxForceFieldShape *)_ptr; }; + + void link(NxForceFieldShape *shapePtr); + void unlink(); + +private: + NxCapsuleForceFieldShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxForceFieldShape::init_type(); + register_type(_type_handle, "PhysxCapsuleForceFieldShape", + PhysxForceFieldShape::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxCapsuleForceFieldShape.I" + +#endif // PHYSXCAPSULEFORCEFIELDSHAPE_H diff --git a/panda/src/physx/physxCapsuleForceFieldShapeDesc.I b/panda/src/physx/physxCapsuleForceFieldShapeDesc.I new file mode 100644 index 0000000000..301345d4e0 --- /dev/null +++ b/panda/src/physx/physxCapsuleForceFieldShapeDesc.I @@ -0,0 +1,59 @@ +// Filename: physxCapsuleForceFieldShapeDesc.I +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShapeDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsuleForceFieldShapeDesc:: +PhysxCapsuleForceFieldShapeDesc() : PhysxForceFieldShapeDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsuleForceFieldShapeDesc:: +~PhysxCapsuleForceFieldShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxCapsuleForceFieldShapeDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxCapsuleForceFieldShapeDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxCapsuleForceFieldShapeDesc.cxx b/panda/src/physx/physxCapsuleForceFieldShapeDesc.cxx new file mode 100644 index 0000000000..82145ccdef --- /dev/null +++ b/panda/src/physx/physxCapsuleForceFieldShapeDesc.cxx @@ -0,0 +1,64 @@ +// Filename: physxCapsuleForceFieldShapeDesc.cxx +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxCapsuleForceFieldShapeDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShapeDesc::set_radius +// Access: Published +// Description: Sets the radius of the capsule's hemispherical +// ends and its trunk. +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleForceFieldShapeDesc:: +set_radius(float radius) { + + _desc.radius = radius; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShapeDesc::set_height +// Access: Published +// Description: Sets the distance between the two hemispherical +// ends of the capsule. +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleForceFieldShapeDesc:: +set_height(float height) { + + _desc.height = height; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShapeDesc::get_radius +// Access: Published +// Description: The radius of the capsule's hemispherical ends +// and its trunk. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleForceFieldShapeDesc:: +get_radius() const { + + return _desc.radius; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleForceFieldShapeDesc::get_height +// Access: Published +// Description: The distance between the two hemispherical ends +// of the capsule. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleForceFieldShapeDesc:: +get_height() const { + + return _desc.height; +} + diff --git a/panda/src/physx/physxCapsuleForceFieldShapeDesc.h b/panda/src/physx/physxCapsuleForceFieldShapeDesc.h new file mode 100644 index 0000000000..91453f19d4 --- /dev/null +++ b/panda/src/physx/physxCapsuleForceFieldShapeDesc.h @@ -0,0 +1,51 @@ +// Filename: physxCapsuleForceFieldShapeDesc.h +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCAPSULEFORCEFIELDSHAPEDESC_H +#define PHYSXCAPSULEFORCEFIELDSHAPEDESC_H + +#include "pandabase.h" + +#include "physxForceFieldShapeDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxCapsuleForceFieldShapeDesc +// Description : Descriptor for a capsule force field shape. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxCapsuleForceFieldShapeDesc : public PhysxForceFieldShapeDesc { + +PUBLISHED: + INLINE PhysxCapsuleForceFieldShapeDesc(); + INLINE ~PhysxCapsuleForceFieldShapeDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_radius(float radius); + void set_height(float height); + + float get_radius() const; + float get_height() const; + +public: + NxForceFieldShapeDesc *ptr() const { return (NxForceFieldShapeDesc *)&_desc; }; + NxCapsuleForceFieldShapeDesc _desc; +}; + +#include "physxCapsuleForceFieldShapeDesc.I" + +#endif // PHYSXCAPSULEFORCEFIELDSHAPEDESC_H diff --git a/panda/src/physx/physxCapsuleShape.I b/panda/src/physx/physxCapsuleShape.I index 97494e198e..b24267e48a 100644 --- a/panda/src/physx/physxCapsuleShape.I +++ b/panda/src/physx/physxCapsuleShape.I @@ -1,5 +1,5 @@ // Filename: physxCapsuleShape.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,3 +12,25 @@ // //////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsuleShape:: +PhysxCapsuleShape() : PhysxShape() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsuleShape:: +~PhysxCapsuleShape() { + +} + diff --git a/panda/src/physx/physxCapsuleShape.cxx b/panda/src/physx/physxCapsuleShape.cxx index 68967cd006..231d464300 100644 --- a/panda/src/physx/physxCapsuleShape.cxx +++ b/panda/src/physx/physxCapsuleShape.cxx @@ -1,5 +1,5 @@ // Filename: physxCapsuleShape.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,98 +12,100 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxCapsuleShape.h" - -#include "physxCapsule.h" #include "physxCapsuleShapeDesc.h" TypeHandle PhysxCapsuleShape::_type_handle; //////////////////////////////////////////////////////////////////// -// Function : get_height -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxCapsuleShape:: -get_height() const { - nassertr(nCapsuleShape != NULL, -1.0f); - - return nCapsuleShape->getHeight(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_radius -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxCapsuleShape:: -get_radius() const { - nassertr(nCapsuleShape != NULL, -1.0f); - - return nCapsuleShape->getRadius(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_world_capsule -// Access : Published -// Description : +// Function: PhysxCapsuleShape::link +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// void PhysxCapsuleShape:: -get_world_capsule(PhysxCapsule & world_capsule) const { - nassertv(nCapsuleShape != NULL); +link(NxShape *shapePtr) { - nCapsuleShape->getWorldCapsule(*(world_capsule.nCapsule)); + _ptr = shapePtr->isCapsule(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.add(this); } //////////////////////////////////////////////////////////////////// -// Function : save_to_desc -// Access : Published -// Description : +// Function: PhysxCapsuleShape::unlink +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// void PhysxCapsuleShape:: -save_to_desc(PhysxCapsuleShapeDesc & desc) const { - nassertv(nCapsuleShape != NULL); +unlink() { - nCapsuleShape->saveToDesc(desc.nCapsuleShapeDesc); + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.remove(this); } //////////////////////////////////////////////////////////////////// -// Function : set_dimensions +// Function : PhysxCapsuleShape::save_to_desc // Access : Published -// Description : +// Description : Saves the state of the shape object to a +// descriptor. //////////////////////////////////////////////////////////////////// void PhysxCapsuleShape:: -set_dimensions(float radius, float height) { - nassertv(nCapsuleShape != NULL); +save_to_desc(PhysxCapsuleShapeDesc &shapeDesc) const { - nCapsuleShape->setDimensions(radius, height); + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); } //////////////////////////////////////////////////////////////////// -// Function : set_height -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxCapsuleShape:: -set_height(float height) { - nassertv(nCapsuleShape != NULL); - - nCapsuleShape->setHeight(height); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_radius -// Access : Published -// Description : +// Function: PhysxCapsuleShape::set_radius +// Access: Published +// Description: Alters the radius of the capsule. //////////////////////////////////////////////////////////////////// void PhysxCapsuleShape:: set_radius(float radius) { - nassertv(nCapsuleShape != NULL); - nCapsuleShape->setRadius(radius); + nassertv(_error_type == ET_ok); + _ptr->setRadius(radius); } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleShape::set_height +// Access: Published +// Description: Alters the height of the capsule. +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleShape:: +set_height(float height) { + + nassertv(_error_type == ET_ok); + _ptr->setHeight(height); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleShape::get_radius +// Access: Published +// Description: Retrieves the radius of the capsule. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleShape:: +get_radius() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getRadius(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleShape::get_height +// Access: Published +// Description: Retrieves the height of the capsule. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleShape:: +get_height() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getHeight(); +} diff --git a/panda/src/physx/physxCapsuleShape.h b/panda/src/physx/physxCapsuleShape.h index dfa78e7e84..56b11dc15b 100644 --- a/panda/src/physx/physxCapsuleShape.h +++ b/panda/src/physx/physxCapsuleShape.h @@ -1,5 +1,5 @@ // Filename: physxCapsuleShape.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,46 +15,68 @@ #ifndef PHYSXCAPSULESHAPE_H #define PHYSXCAPSULESHAPE_H -#ifdef HAVE_PHYSX - #include "pandabase.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "lvector3.h" #include "physxShape.h" -class PhysxCapsule; -class PhysxCapsuleShapeDesc; - +#include "NoMinMax.h" #include "NxPhysics.h" +class PhysxCapsuleShapeDesc; + //////////////////////////////////////////////////////////////////// // Class : PhysxCapsuleShape -// Description : +// Description : A capsule shaped collision detection primitive, +// also known as a line swept sphere. 'radius' is the +// radius of the capsule's hemispherical ends and its +// trunk. 'height' is the distance between the two +// hemispherical ends of the capsule. The height is +// along the capsule's Y axis. Each shape is owned by +// an actor that it is attached to. +// +// An instance can be created by calling the +// createShape() method of the PhysxActor object that +// should own it, with a PhysxCapsuleShapeDesc object +// as the parameter, or by adding the shape descriptor +// into the PhysxActorDesc class before creating the +// actor. +// +// The shape is deleted by calling release() on the +// shape itself. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxCapsuleShape : public PhysxShape { + PUBLISHED: + INLINE PhysxCapsuleShape(); + INLINE ~PhysxCapsuleShape(); + + void save_to_desc(PhysxCapsuleShapeDesc &shapeDesc) const; - float get_height() const; - float get_radius() const; - void get_world_capsule(PhysxCapsule & world_capsule) const; - void save_to_desc(PhysxCapsuleShapeDesc & desc) const; - void set_dimensions(float radius, float height); - void set_height(float height); void set_radius(float radius); + void set_height(float height); + float get_radius() const; + float get_height() const; +//////////////////////////////////////////////////////////////////// public: - NxCapsuleShape *nCapsuleShape; + INLINE NxShape *ptr() const { return (NxShape *)_ptr; }; + void link(NxShape *shapePtr); + void unlink(); + +private: + NxCapsuleShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: static TypeHandle get_class_type() { return _type_handle; } static void init_type() { PhysxShape::init_type(); - register_type(_type_handle, "PhysxCapsuleShape", + register_type(_type_handle, "PhysxCapsuleShape", PhysxShape::get_class_type()); } virtual TypeHandle get_type() const { @@ -71,6 +93,4 @@ private: #include "physxCapsuleShape.I" -#endif // HAVE_PHYSX - #endif // PHYSXCAPSULESHAPE_H diff --git a/panda/src/physx/physxCapsuleShapeDesc.I b/panda/src/physx/physxCapsuleShapeDesc.I index 47a3be93ca..e8980b4d18 100644 --- a/panda/src/physx/physxCapsuleShapeDesc.I +++ b/panda/src/physx/physxCapsuleShapeDesc.I @@ -1,5 +1,5 @@ // Filename: physxCapsuleShapeDesc.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (11Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,83 +12,48 @@ // //////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxCapsuleShapeDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxCapsuleShapeDesc:: -is_valid() const { - return nCapsuleShapeDesc.isValid(); +INLINE PhysxCapsuleShapeDesc:: +PhysxCapsuleShapeDesc() : PhysxShapeDesc() { + + _desc.name = ""; } //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxCapsuleShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCapsuleShapeDesc:: +~PhysxCapsuleShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. //////////////////////////////////////////////////////////////////// INLINE void PhysxCapsuleShapeDesc:: set_to_default() { - nCapsuleShapeDesc.setToDefault(); + + _desc.setToDefault(); } //////////////////////////////////////////////////////////////////// -// Function : get_flags -// Access : Published -// Description : +// Function: PhysxCapsuleShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. //////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxCapsuleShapeDesc:: -get_flags() const { - return nCapsuleShapeDesc.flags; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_height -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxCapsuleShapeDesc:: -get_height() const { - return nCapsuleShapeDesc.height; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_radius -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxCapsuleShapeDesc:: -get_radius() const { - return nCapsuleShapeDesc.radius; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxCapsuleShapeDesc:: -set_flags(unsigned int value) { - nCapsuleShapeDesc.flags = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_height -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxCapsuleShapeDesc:: -set_height(float value) { - nCapsuleShapeDesc.height = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_radius -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxCapsuleShapeDesc:: -set_radius(float value) { - nCapsuleShapeDesc.radius = value; +INLINE bool PhysxCapsuleShapeDesc:: +is_valid() const { + + return _desc.isValid(); } diff --git a/panda/src/physx/physxCapsuleShapeDesc.cxx b/panda/src/physx/physxCapsuleShapeDesc.cxx index fd1b9b40e2..dd46aed2f8 100644 --- a/panda/src/physx/physxCapsuleShapeDesc.cxx +++ b/panda/src/physx/physxCapsuleShapeDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxCapsuleShapeDesc.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (11Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,22 +12,53 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxCapsuleShapeDesc.h" - - //////////////////////////////////////////////////////////////////// -// Function : PhysxCapsuleShapeDesc -// Access : Published -// Description : +// Function: PhysxCapsuleShapeDesc::set_radius +// Access: Published +// Description: Sets the radius of the capsule's hemispherical +// ends and its trunk. //////////////////////////////////////////////////////////////////// -PhysxCapsuleShapeDesc:: -PhysxCapsuleShapeDesc() -: PhysxShapeDesc( &nCapsuleShapeDesc ) { +void PhysxCapsuleShapeDesc:: +set_radius(float radius) { + _desc.radius = radius; } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleShapeDesc::set_height +// Access: Published +// Description: Sets the distance between the two hemispherical +// ends of the capsule. +//////////////////////////////////////////////////////////////////// +void PhysxCapsuleShapeDesc:: +set_height(float height) { + + _desc.height = height; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleShapeDesc::get_radius +// Access: Published +// Description: The radius of the capsule's hemispherical ends +// and its trunk. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleShapeDesc:: +get_radius() const { + + return _desc.radius; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCapsuleShapeDesc::get_height +// Access: Published +// Description: The distance between the two hemispherical ends +// of the capsule. +//////////////////////////////////////////////////////////////////// +float PhysxCapsuleShapeDesc:: +get_height() const { + + return _desc.height; +} diff --git a/panda/src/physx/physxCapsuleShapeDesc.h b/panda/src/physx/physxCapsuleShapeDesc.h index adc9b2472f..faeb7d9c20 100644 --- a/panda/src/physx/physxCapsuleShapeDesc.h +++ b/panda/src/physx/physxCapsuleShapeDesc.h @@ -1,5 +1,5 @@ // Filename: physxCapsuleShapeDesc.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (11Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,43 +15,37 @@ #ifndef PHYSXCAPSULESHAPEDESC_H #define PHYSXCAPSULESHAPEDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - #include "physxShapeDesc.h" +#include "NoMinMax.h" #include "NxPhysics.h" //////////////////////////////////////////////////////////////////// // Class : PhysxCapsuleShapeDesc -// Description : +// Description : Descriptor class for PhysxCapsuleShape. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxCapsuleShapeDesc : public PhysxShapeDesc { + PUBLISHED: - PhysxCapsuleShapeDesc(); + INLINE PhysxCapsuleShapeDesc(); + INLINE ~PhysxCapsuleShapeDesc(); - INLINE bool is_valid() const; INLINE void set_to_default(); + INLINE bool is_valid() const; - INLINE unsigned int get_flags() const; - INLINE float get_height() const; - INLINE float get_radius() const; + void set_radius(float radius); + void set_height(float height); - INLINE void set_flags( unsigned int value ); - INLINE void set_height( float value ); - INLINE void set_radius( float value ); + float get_radius() const; + float get_height() const; public: - NxCapsuleShapeDesc nCapsuleShapeDesc; + NxShapeDesc *ptr() const { return (NxShapeDesc *)&_desc; }; + NxCapsuleShapeDesc _desc; }; #include "physxCapsuleShapeDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXCAPSULESHAPEDESC_H diff --git a/panda/src/physx/physxConstraintDominance.I b/panda/src/physx/physxConstraintDominance.I new file mode 100644 index 0000000000..8455f7f738 --- /dev/null +++ b/panda/src/physx/physxConstraintDominance.I @@ -0,0 +1,57 @@ +// Filename: physxConstraintDominance.I +// Created by: enn0x (22Dec09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConstraintDominance::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConstraintDominance:: +PhysxConstraintDominance(float d0, float d1) : _dominance(d0, d1) { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConstraintDominance::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConstraintDominance:: +~PhysxConstraintDominance() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConstraintDominance::get_dominance +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE NxConstraintDominance PhysxConstraintDominance:: +get_dominance() const { + + return _dominance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConstraintDominance::set_dominance +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxConstraintDominance:: +set_dominance(NxConstraintDominance value) { + + _dominance = value; +} + diff --git a/panda/src/physx/physxConstraintDominance.cxx b/panda/src/physx/physxConstraintDominance.cxx new file mode 100644 index 0000000000..35af6fd2c8 --- /dev/null +++ b/panda/src/physx/physxConstraintDominance.cxx @@ -0,0 +1,60 @@ +// Filename: physxConstraintDominance.cxx +// Created by: enn0x (22Dec09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxConstraintDominance.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConstraintDominance::get_0 +// Access: Published +// Description: Retruns the first dominance factor. +//////////////////////////////////////////////////////////////////// +float PhysxConstraintDominance:: +get_0() const { + + return _dominance.dominance0; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConstraintDominance::get_1 +// Access: Published +// Description: Returns the second dominance factor. +//////////////////////////////////////////////////////////////////// +float PhysxConstraintDominance:: +get_1() const { + + return _dominance.dominance1; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConstraintDominance::set_0 +// Access: Published +// Description: Sets the first dominance factor. +//////////////////////////////////////////////////////////////////// +void PhysxConstraintDominance:: +set_0(float d0) { + + _dominance.dominance0 = d0; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConstraintDominance::set_1 +// Access: Published +// Description: Sets the second dominance factor. +//////////////////////////////////////////////////////////////////// +void PhysxConstraintDominance:: +set_1(float d1) { + + _dominance.dominance1 = d1; +} + diff --git a/panda/src/physx/physxConstraintDominance.h b/panda/src/physx/physxConstraintDominance.h new file mode 100644 index 0000000000..fe43ed7724 --- /dev/null +++ b/panda/src/physx/physxConstraintDominance.h @@ -0,0 +1,57 @@ +// Filename: physxConstraintDominance.h +// Created by: enn0x (22Dec09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONSTRAINTDOMINANCE_H +#define PHYSXCONSTRAINTDOMINANCE_H + +#include "pandabase.h" +#include "lvector3.h" +#include "lpoint3.h" + +#include "config_physx.h" + +class PhysxShape; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxConstraintDominance +// Description : Expresses the dominance relationship of a +// constraint. For the time being only three settings +// are permitted:. (1.0f, 1.0f), (0.0f, 1.0f), and +// (1.0f, 0.0f). +// +// See PhysxScene::set_dominance_group_pair for a +// detailed explanation of dominance behaviour. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxConstraintDominance { + +PUBLISHED: + INLINE PhysxConstraintDominance(float d0, float d1); + INLINE ~PhysxConstraintDominance(); + + float get_0() const; + float get_1() const; + void set_0(float d0); + void set_1(float d1); + +public: + INLINE void set_dominance(NxConstraintDominance value); + INLINE NxConstraintDominance get_dominance() const; + +private: + NxConstraintDominance _dominance; +}; + +#include "physxConstraintDominance.I" + +#endif // PHYSXCONSTRAINTDOMINANCE_H diff --git a/panda/src/physx/physxContactHandler.cxx b/panda/src/physx/physxContactHandler.cxx deleted file mode 100644 index dfa0132066..0000000000 --- a/panda/src/physx/physxContactHandler.cxx +++ /dev/null @@ -1,129 +0,0 @@ -// Filename: physxContactHandler.cxx -// Created by: pratt (May 25, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifdef HAVE_PHYSX - -#include "physxContactHandler.h" - -#include "eventParameter.h" -#include "eventStorePandaNode.h" -#include "throw_event.h" - -//////////////////////////////////////////////////////////////////// -// Function : PhysxContactHandler -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxContactHandler:: -PhysxContactHandler() { - threshold = 0.01f; -} - -//////////////////////////////////////////////////////////////////// -// Function : clear_events -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxContactHandler:: -clear_events() { - events.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function : throw_events -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxContactHandler:: -throw_events() { - pvector::const_iterator events_iter; - PhysxContactEvent event; - string on_start_name = "physxOnContactStart"; - string on_end_name = "physxOnContactEnd"; - string on_touch_name = "physxOnContactTouch"; - for(events_iter = events.begin(); events_iter != events.end(); ++events_iter) { - event = *events_iter; - Event *ev = NULL; - if(event.flags & NX_NOTIFY_ON_START_TOUCH) { - ev = new Event(on_start_name); - } else if(event.flags & NX_NOTIFY_ON_END_TOUCH) { - ev = new Event(on_end_name); - } else if(event.flags & NX_NOTIFY_ON_TOUCH) { - ev = new Event(on_touch_name); - } - if(ev != NULL) { - PT(PhysxActorNode) pActorNode1 = (PhysxActorNode *)event.nActor1->userData; - PT(PhysxActorNode) pActorNode2 = (PhysxActorNode *)event.nActor2->userData; - ev->add_parameter(EventParameter(new EventStorePandaNode(pActorNode1))); - ev->add_parameter(EventParameter(new EventStorePandaNode(pActorNode2))); - ev->add_parameter(EventParameter(event.sumNormalForce.x)); - ev->add_parameter(EventParameter(event.sumNormalForce.y)); - ev->add_parameter(EventParameter(event.sumNormalForce.z)); - ev->add_parameter(EventParameter(event.sumFrictionForce.x)); - ev->add_parameter(EventParameter(event.sumFrictionForce.y)); - ev->add_parameter(EventParameter(event.sumFrictionForce.z)); - EventQueue::get_global_event_queue()->queue_event(ev); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function : set_threshold -// Access : Published -// Description : Contacts will only be reported if the magnitude -// of the normal force squared is greater than this -// threshold value. -// Default: 0.01 -//////////////////////////////////////////////////////////////////// -void PhysxContactHandler:: -set_threshold( float value ) { - threshold = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_threshold -// Access : Published -// Description : Contacts will only be reported if the magnitude -// of the normal force squared is greater than this -// threshold value. -// Default: 0.01 -//////////////////////////////////////////////////////////////////// -float PhysxContactHandler:: -get_threshold() { - return threshold; -} - -//////////////////////////////////////////////////////////////////// -// Function : onContactNotify -// Access : public -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxContactHandler:: -onContactNotify(NxContactPair &pair, NxU32 flags) { - if(pair.sumNormalForce.magnitudeSquared() >= threshold) { - PhysxContactEvent event; - event.nActor1 = pair.actors[0]; - event.nActor2 = pair.actors[1]; -// PhysxActorNode *pActorNode1 = (PhysxActorNode *)pair.actors[0]->userData; -// PhysxActorNode *pActorNode2 = (PhysxActorNode *)pair.actors[1]->userData; -// event.actorName1 = pActorNode1->get_name(); -// event.actorName2 = pActorNode2->get_name(); - event.sumNormalForce = pair.sumNormalForce; - event.sumFrictionForce = pair.sumFrictionForce; - event.flags = flags; - events.push_back(event); - } -} - -#endif // HAVE_PHYSX diff --git a/panda/src/physx/physxContactHandler.h b/panda/src/physx/physxContactHandler.h deleted file mode 100644 index 1eb94f3557..0000000000 --- a/panda/src/physx/physxContactHandler.h +++ /dev/null @@ -1,67 +0,0 @@ -// Filename: physxContactHandler.h -// Created by: pratt (May 25, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifndef PHYSXCONTACTHANDLER_H -#define PHYSXCONTACTHANDLER_H - -#ifdef HAVE_PHYSX - -#include "pandabase.h" -#include "pvector.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -class PhysxShape; - -#include "NxPhysics.h" - -//////////////////////////////////////////////////////////////////// -// Class : PhysxContactHandler -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxContactHandler : public NxUserContactReport { -PUBLISHED: - PhysxContactHandler(); - - void clear_events(); - void throw_events(); - - void set_threshold(float value); - float get_threshold(); - -public: - void onContactNotify(NxContactPair& pair, NxU32 flags); - -private: - float threshold; - struct PhysxContactEvent { - NxActor *nActor1; - NxActor *nActor2; -// string actorName1; -// string actorName2; - NxVec3 sumNormalForce; - NxVec3 sumFrictionForce; - NxU32 flags; - }; - - pvector events; -}; - -#include "physxContactHandler.I" - -#endif // HAVE_PHYSX - -#endif // PHYSXCONTACTHANDLER_H diff --git a/panda/src/physx/physxContactPair.I b/panda/src/physx/physxContactPair.I new file mode 100644 index 0000000000..81c661b0ae --- /dev/null +++ b/panda/src/physx/physxContactPair.I @@ -0,0 +1,36 @@ +// Filename: physxContactPair.I +// Created by: enn0x (19Dec09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPair::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxContactPair:: +PhysxContactPair(const NxContactPair pair) { + + _pair = pair; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPair::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxContactPair:: +~PhysxContactPair() { + +} + diff --git a/panda/src/physx/physxContactPair.cxx b/panda/src/physx/physxContactPair.cxx new file mode 100644 index 0000000000..a1893fa336 --- /dev/null +++ b/panda/src/physx/physxContactPair.cxx @@ -0,0 +1,129 @@ +// Filename: physxContactPair.cxx +// Created by: enn0x (19Dec09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxContactPair.h" +#include "physxManager.h" +#include "physxActor.h" +#include "physxContactPoint.h" + +TypeHandle PhysxContactPair::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPair::get_actor_a +// Access: Published +// Description: Returns the first of the two actors that makes up +// this pair. +//////////////////////////////////////////////////////////////////// +PT(PhysxActor) PhysxContactPair:: +get_actor_a() const { + + NxActor *actorPtr = _pair.actors[0]; + return (actorPtr == NULL) ? NULL : (PhysxActor *)actorPtr->userData; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPair::get_actor_b +// Access: Published +// Description: Returns the second of the two actors that make up +// his pair. +//////////////////////////////////////////////////////////////////// +PT(PhysxActor) PhysxContactPair:: +get_actor_b() const { + + NxActor *actorPtr = _pair.actors[1]; + return (actorPtr == NULL) ? NULL : (PhysxActor *)actorPtr->userData; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPair::get_sum_normal_force +// Access: Published +// Description: Returns the total contact normal force that was +// applied for this pair, to maintain nonpenetration +// constraints. +// +// You should set the ContactPairFlag +// CPF_notify_forces in order to receive this value. +// +// @see PhysxScene::set_actor_pair_flag +// @see PhysxScene::set_actor_group_pair_flag +//////////////////////////////////////////////////////////////////// +LVector3f PhysxContactPair:: +get_sum_normal_force() const { + + return PhysxManager::nxVec3_to_vec3(_pair.sumNormalForce); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPair::get_sum_friction_force +// Access: Published +// Description: Returns the total tangential force that was applied +// for this pair. +// +// You should set the ContactPairFlag +// CPF_notify_forces in order to receive this value. +// +// @see PhysxScene::set_actor_pair_flag +// @see PhysxScene::set_actor_group_pair_flag +//////////////////////////////////////////////////////////////////// +LVector3f PhysxContactPair:: +get_sum_friction_force() const { + + return PhysxManager::nxVec3_to_vec3(_pair.sumFrictionForce); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPair::get_num_contact_points +// Access: Published +// Description: Returns the total number of contact points reported +// in this pair's contact stream. +// +// This method is a helper for iterating over the +// pair's contact stream. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxContactPair:: +get_num_contact_points() { + + if (_contacts.size() == 0) { + NxContactStreamIterator it(_pair.stream); + while(it.goNextPair()) { + while(it.goNextPatch()) { + while(it.goNextPoint()) { + PhysxContactPoint cp; + cp.set(it); + _contacts.push_back(cp); + } + } + } + } + + return _contacts.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPair::get_contact_point +// Access: Published +// Description: Returns an instance of PhysxContactPoint, which +// represents a single entry of this pair's contact +// stream. +// +// This method is a helper for iterating over the +// pair's contact stream. +//////////////////////////////////////////////////////////////////// +PhysxContactPoint PhysxContactPair:: +get_contact_point(unsigned int idx) const { + + nassertr(idx < _contacts.size(), PhysxContactPoint::empty()); + return _contacts[idx]; +} + diff --git a/panda/src/physx/physxContactPair.h b/panda/src/physx/physxContactPair.h new file mode 100644 index 0000000000..9436fd680e --- /dev/null +++ b/panda/src/physx/physxContactPair.h @@ -0,0 +1,79 @@ +// Filename: physxContactPair.h +// Created by: enn0x (19Dec09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONTACTPAIR_H +#define PHYSXCONTACTPAIR_H + +#include "pandabase.h" +#include "lvector3.h" +#include "typedReferenceCount.h" +#include "pvector.h" + +#include "config_physx.h" + +class PhysxShape; +class PhysxContactPoint; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxContactPair +// Description : An instance of this class is send with contact +// reporting events. It contains detailed information +// on the contact. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxContactPair : public TypedReferenceCount { + +PUBLISHED: + INLINE ~PhysxContactPair(); + + PT(PhysxActor) get_actor_a() const; + PT(PhysxActor) get_actor_b() const; + LVector3f get_sum_normal_force() const; + LVector3f get_sum_friction_force() const; + + unsigned int get_num_contact_points(); + PhysxContactPoint get_contact_point(unsigned int idx) const; + MAKE_SEQ(get_contact_points, get_num_contact_points, get_contact_point); + +public: + INLINE PhysxContactPair(const NxContactPair pair); + +private: + NxContactPair _pair; + pvector _contacts; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + TypedReferenceCount::init_type(); + register_type(_type_handle, "PhysxContactPair", + TypedReferenceCount::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxContactPair.I" + +#endif // PHYSXCONTACTPAIR_H diff --git a/panda/src/physx/physxContactPoint.I b/panda/src/physx/physxContactPoint.I new file mode 100644 index 0000000000..bed1fcd52b --- /dev/null +++ b/panda/src/physx/physxContactPoint.I @@ -0,0 +1,36 @@ +// Filename: physxContactPoint.I +// Created by: enn0x (20Dec09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPoint::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxContactPoint:: +PhysxContactPoint() { + + //_hit = hit; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPoint::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxContactPoint:: +~PhysxContactPoint() { + +} + diff --git a/panda/src/physx/physxContactPoint.cxx b/panda/src/physx/physxContactPoint.cxx new file mode 100644 index 0000000000..4f7cbaa34b --- /dev/null +++ b/panda/src/physx/physxContactPoint.cxx @@ -0,0 +1,114 @@ +// Filename: physxContactPoint.cxx +// Created by: enn0x (20Dec09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxContactPoint.h" +#include "physxManager.h" +#include "physxShape.h" + +TypeHandle PhysxContactPoint::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPoint::set +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxContactPoint:: +set(NxContactStreamIterator it) { + + _point = it.getPoint(); + _normal = it.getPatchNormal(); + _normal_force = it.getPointNormalForce(); + _separation = it.getSeparation(); + _feature_index0 = it.getFeatureIndex0(); + _feature_index1 = it.getFeatureIndex1(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPoint::empty +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PhysxContactPoint PhysxContactPoint:: +empty() { + + return PhysxContactPoint(); +} + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPoint::get_point +// Access: Published +// Description: Returns the contact point position. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxContactPoint:: +get_point() const { + + return PhysxManager::nxVec3_to_point3(_point); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPoint::get_normal +// Access: Published +// Description: Retrieves the patch normal. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxContactPoint:: +get_normal() const { + + return PhysxManager::nxVec3_to_vec3(_normal); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPoint::get_normal_force +// Access: Published +// Description: Retrieves the point normal force. +//////////////////////////////////////////////////////////////////// +float PhysxContactPoint:: +get_normal_force() const { + + return _normal_force; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPoint::get_separation +// Access: Published +// Description: Return the separation for the contact point. +//////////////////////////////////////////////////////////////////// +float PhysxContactPoint:: +get_separation() const { + + return _separation; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPoint::get_feature_index0 +// Access: Published +// Description: Retrieves the feature index. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxContactPoint:: +get_feature_index0() const { + + return _feature_index0; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactPoint::get_feature_index1 +// Access: Published +// Description: Retrieves the feature index. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxContactPoint:: +get_feature_index1() const { + + return _feature_index1; +} + diff --git a/panda/src/physx/physxContactPoint.h b/panda/src/physx/physxContactPoint.h new file mode 100644 index 0000000000..1c666db868 --- /dev/null +++ b/panda/src/physx/physxContactPoint.h @@ -0,0 +1,82 @@ +// Filename: physxContactPoint.h +// Created by: enn0x (20Dec09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONTACTPOINT_H +#define PHYSXCONTACTPOINT_H + +#include "pandabase.h" +#include "lvector3.h" +#include "lpoint3.h" +#include "typedObject.h" + +#include "config_physx.h" + +class PhysxShape; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxContactPoint +// Description : A helper structure for iterating over contact +// streams reported by PhysxContactPair. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxContactPoint : public TypedObject { + +PUBLISHED: + INLINE PhysxContactPoint(); + INLINE ~PhysxContactPoint(); + + LPoint3f get_point() const; + LVector3f get_normal() const; + float get_normal_force() const; + float get_separation() const; + unsigned int get_feature_index0() const; + unsigned int get_feature_index1() const; + +public: + static PhysxContactPoint empty(); + + void set(NxContactStreamIterator it); + +private: + NxVec3 _point; + NxVec3 _normal; + NxReal _normal_force; + NxReal _separation; + NxU32 _feature_index0; + NxU32 _feature_index1; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + TypedReferenceCount::init_type(); + register_type(_type_handle, "PhysxContactPoint", + TypedReferenceCount::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxContactPoint.I" + +#endif // PHYSXCONTACTPOINT_H diff --git a/panda/src/physx/physxContactReport.I b/panda/src/physx/physxContactReport.I new file mode 100644 index 0000000000..dbd4b76862 --- /dev/null +++ b/panda/src/physx/physxContactReport.I @@ -0,0 +1,36 @@ +// Filename: physxContactReport.I +// Created by: enn0x (19Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactReport::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxContactReport:: +PhysxContactReport() : NxUserContactReport() { + + _enabled = false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactReport::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxContactReport:: +~PhysxContactReport() { + +} + diff --git a/panda/src/physx/physxContactReport.cxx b/panda/src/physx/physxContactReport.cxx new file mode 100644 index 0000000000..33d2f1b691 --- /dev/null +++ b/panda/src/physx/physxContactReport.cxx @@ -0,0 +1,101 @@ +// Filename: physxContactReport.cxx +// Created by: enn0x (19Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxContactReport.h" +#include "physxContactPair.h" +#include "physxManager.h" + +#include "event.h" +#include "eventQueue.h" +#include "eventParameter.h" + +PStatCollector PhysxContactReport::_pcollector("App:PhysX:Contact Reporting"); + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactReport::enable +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxContactReport:: +enable() { + + _enabled = true; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactReport::disable +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxContactReport:: +disable() { + + _enabled = false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactReport::is_enabled +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxContactReport:: +is_enabled() const { + + return _enabled; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxContactReport::onContactNotify +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxContactReport:: +onContactNotify(NxContactPair &pair, NxU32 flags) { + + if (!_enabled) { + return; + } + + _pcollector.start(); + + Event *event; + if (flags & NX_NOTIFY_ON_START_TOUCH) { + event = new Event("physx-contact-start"); + } + else if (flags & NX_NOTIFY_ON_END_TOUCH) { + event = new Event("physx-contact-stop"); + } + else if (flags & NX_NOTIFY_ON_TOUCH) { + event = new Event("physx-contact-touch"); + } + else if (flags & NX_NOTIFY_ON_START_TOUCH_FORCE_THRESHOLD) { + event = new Event("physx-contact-start-force-threshold"); + } + else if (flags & NX_NOTIFY_ON_END_TOUCH_FORCE_THRESHOLD) { + event = new Event("physx-contact-stop-force-threshold"); + } + else if (flags & NX_NOTIFY_ON_TOUCH_FORCE_THRESHOLD) { + event = new Event("physx-contact-touch-force-threshold"); + } + else { + return; + } + + PT(PhysxContactPair) ppair = new PhysxContactPair(pair); + event->add_parameter(EventParameter(ppair)); + EventQueue::get_global_event_queue()->queue_event(event); + + _pcollector.stop(); +} + diff --git a/panda/src/physx/physxContactReport.h b/panda/src/physx/physxContactReport.h new file mode 100644 index 0000000000..7883a12b73 --- /dev/null +++ b/panda/src/physx/physxContactReport.h @@ -0,0 +1,48 @@ +// Filename: physxContactReport.h +// Created by: enn0x (19Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONTACTREPORT_H +#define PHYSXCONTACTREPORT_H + +#include "pandabase.h" +#include "pStatCollector.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxContactReport +// Description : Implementation of the NxUserContactReport +// interface. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxContactReport : public NxUserContactReport { + +public: + INLINE PhysxContactReport(); + INLINE ~PhysxContactReport(); + + void enable(); + void disable(); + bool is_enabled() const; + + void onContactNotify(NxContactPair& pair, NxU32 flags); + +private: + bool _enabled; + static PStatCollector _pcollector; +}; + +#include "physxContactReport.I" + +#endif // PHYSXCONTACTREPORT_H diff --git a/panda/src/physx/physxController.I b/panda/src/physx/physxController.I new file mode 100644 index 0000000000..41bf5c867e --- /dev/null +++ b/panda/src/physx/physxController.I @@ -0,0 +1,79 @@ +// Filename: physxController.I +// Created by: enn0x (24Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::Constructor +// Access: Protected +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxController:: +PhysxController() : PhysxObject() { + + _speed = NxVec3(0.0f, 0.0f, 0.0f); + _omega = 0.0f; + _heading = 0.0f; + + _jumping = false; + _jump_time = 0.0f; + _jump_v0 = 0.0f; + + _sharpness = 1.0f; + _min_dist = 0.0001f; + + _up_vector = NxVec3(0.0f, 1.0f, 0.0f); + _up_axis = (NxHeightFieldAxis)physx_up_axis.get_value(); + + switch (_up_axis) { + case NX_Z: + _up_quat = NxQuat(90.0f, NxVec3(1.0f, 0.0f, 0.0f)); + break; + case NX_Y: + _up_quat = NxQuat(0.0f, NxVec3(1.0f, 0.0f, 0.0f)); + break; + default: + physx_cat.error() << "only y-up and z-up are permitted" << endl; + } + + _up_quat_inv = _up_quat; + _up_quat_inv.invert(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxController:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxController:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " (at 0x" << this << ")"; + + out << " A:0x" << get_actor(); + out << "\n"; +} + diff --git a/panda/src/physx/physxController.cxx b/panda/src/physx/physxController.cxx new file mode 100644 index 0000000000..07e2c2837e --- /dev/null +++ b/panda/src/physx/physxController.cxx @@ -0,0 +1,389 @@ +// Filename: physxController.cxx +// Created by: enn0x (24Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "event.h" +#include "eventQueue.h" +#include "eventParameter.h" + +#include "physxController.h" +#include "physxManager.h" +#include "physxActor.h" +#include "physxBoxController.h" +#include "physxCapsuleController.h" + +TypeHandle PhysxController::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::release +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxController:: +release() { + + nassertv(_error_type == ET_ok); + + unlink(); + get_actor()->get_scene()->cm()->releaseController(*ptr()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::factory +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxController) PhysxController:: +factory(NxControllerType controllerType) { + + switch (controllerType) { + + case NX_CONTROLLER_BOX: + return new PhysxBoxController(); + + case NX_CONTROLLER_CAPSULE: + return new PhysxCapsuleController(); + + } + + physx_cat.error() << "Unknown controller type.\n"; + return NULL; +} + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::get_actor +// Access: Published +// Description: Retrieves the actor which this controller is +// associated with. +//////////////////////////////////////////////////////////////////// +PT(PhysxActor) PhysxController:: +get_actor() const { + + nassertr(_error_type == ET_ok, NULL); + return (PhysxActor *)(ptr()->getActor()->userData); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::set_pos +// Access: Published +// Description: Sets the position of the controller is global +// space. This can be used for initial placement or +// for teleporting the character. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +set_pos(const LPoint3f &pos) { + + nassertv(_error_type == ET_ok); + ptr()->setPosition(PhysxManager::point3_to_nxExtVec3(pos)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::get_pos +// Access: Published +// Description: Retruns the position of the controller is global +// space. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxController:: +get_pos() const { + + nassertr(_error_type == ET_ok, LPoint3f::zero()); + return PhysxManager::nxExtVec3_to_point3(ptr()->getPosition()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::set_sharpness +// Access: Published +// Description: Sharpness is used to smooth motion with a feedback +// filter, having a value between 0 (so smooth it +// doesn't move) and 1 (no smoothing = unfiltered +// motion). Sharpness can ease the motion curve when +// the auto-step feature is used with boxes. +// Default value is 1.0. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +set_sharpness(float sharpness) { + + nassertv(_error_type == ET_ok); + nassertv(sharpness > 0.0f); + nassertv(sharpness <= 1.0f); + + _sharpness = sharpness; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::get_sharpness +// Access: Published +// Description: Returns the sharpness used to ease the motion curve +// when the auto-step feature is used. +// Default value is 1.0. +//////////////////////////////////////////////////////////////////// +float PhysxController:: +get_sharpness() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _sharpness; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::set_collision +// Access: Published +// Description: Enable/Disable collisions for this controller and +// actor. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +set_collision(bool enable) { + + nassertv(_error_type == ET_ok); + ptr()->setCollision(enable); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::set_min_distance +// Access: Published +// Description: Sets the the minimum travelled distance to consider +// when moving the controller. If travelled distance +// is smaller, the character doesn't move. This is +// used to stop the recursive motion algorithm when +// remaining distance to travel is small. +// The default value is 0.0001. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +set_min_distance(float min_dist) { + + nassertv(_error_type == ET_ok); + nassertv(min_dist > 0.0f); + + _min_dist = min_dist; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::set_step_offset +// Access: Published +// Description: Sets the step height/offset for the controller. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +set_step_offset(float offset) { + + nassertv(_error_type == ET_ok); + nassertv(offset > 0.0f); + + ptr()->setStepOffset(offset); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::set_global_speed +// Access: Published +// Description: Sets the linear speed of the controller in global +// space. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +set_global_speed(const LVector3f &speed) { + + nassertv(_error_type == ET_ok); + nassertv_always(!speed.is_nan()); + + _speed = NxVec3(speed.get_x(), speed.get_y(), speed.get_z()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::set_local_speed +// Access: Published +// Description: Sets the linear speed of the controller in local +// coordinates. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +set_local_speed(const LVector3f &speed) { + + nassertv(_error_type == ET_ok); + nassertv_always(!speed.is_nan()); + + NodePath np = get_actor()->get_node_path(); + nassertv(!np.is_empty()); + + NxQuat q = ptr()->getActor()->getGlobalOrientationQuat(); + NxVec3 s = NxVec3(speed.get_x(), speed.get_y(), speed.get_z()); + _speed = (q * _up_quat_inv).rot(s); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::set_omega +// Access: Published +// Description: Sets the angular velocity (degrees per second) +// of the controller. The angular velocity is used to +// compute the new heading when updating the +// controller. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +set_omega(float omega) { + + nassertv(_error_type == ET_ok); + _omega = omega; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::set_h +// Access: Published +// Description: Sets the heading of the controller is global +// space. Note: only heading is supported. Pitch and +// roll are constrained by PhysX in order to alyways +// keep the character upright. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +set_h(float heading) { + + nassertv(_error_type == ET_ok); + + _heading = heading; + NxQuat q(_heading, _up_vector); + ptr()->getActor()->moveGlobalOrientationQuat(_up_quat * q); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::get_h +// Access: Published +// Description: Returns the heading of the controller in global +// space. +//////////////////////////////////////////////////////////////////// +float PhysxController:: +get_h() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _heading; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::report_scene_changed +// Access: Published +// Description: The character controller uses caching in order to +// speed up collision testing, this caching can not +// detect when static objects have changed in the +// scene. You need to call this method when such +// changes have been made. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +report_scene_changed() { + + nassertv(_error_type == ET_ok); + ptr()->reportSceneChanged(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::update +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxController:: +update(float dt) { + + nassertv(_error_type == ET_ok); + + // Speed + NxU32 mask = 0xFFFFFFFF; + NxU32 collision_flags; + NxVec3 gravity; + + ptr()->getActor()->getScene().getGravity(gravity); + + NxVec3 d = (_speed + gravity) * dt; + + NxReal heightDelta = get_jump_height(dt, gravity); + if (heightDelta != 0.0f) { + ((_up_axis == NX_Z) ? d.z : d.y) += heightDelta; + } + + ptr()->move(d, mask, _min_dist, collision_flags, _sharpness); + + if (collision_flags & NXCC_COLLISION_DOWN) { + stop_jump(); + } + + // Omega + if (_omega != 0.0f) { + NxReal delta = _omega * dt; + _heading += delta; + NxQuat q(_heading, _up_vector); + ptr()->getActor()->moveGlobalOrientationQuat(_up_quat * q); + } + + // Reset speed and omega + _speed.zero(); + _omega = 0.0f; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::get_jump_height +// Access: Private +// Description: +//////////////////////////////////////////////////////////////////// +NxReal PhysxController:: +get_jump_height(float dt, NxVec3 &gravity) { + + if (_jumping == false) { + return 0.0f; + } + + _jump_time += dt; + + float G = (_up_axis == NX_Z) ? gravity.z : gravity.y; + float h = 2.0f * G * _jump_time * _jump_time + _jump_v0 * _jump_time; + return (h - G) * dt; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::start_jump +// Access: Published +// Description: Enters the jump mode. The parameter is the intial +// upward velocity of the character. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +start_jump(float v0) { + + nassertv(_error_type == ET_ok); + + if (_jumping == true) { + return; + } + + _jumping = true; + _jump_time = 0.0f; + _jump_v0 = v0; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxController::stop_jump +// Access: Published +// Description: Leaves the jump mode. This method is automatically +// called if a ground collision is detected. Usually +// users need not call this method. +//////////////////////////////////////////////////////////////////// +void PhysxController:: +stop_jump() { + + nassertv(_error_type == ET_ok); + + if (_jumping == false) { + return; + } + + _jumping = false; + + //NxVec3 v = ptr()->getActor()->getLinearVelocity(); + //double velocity = (_up_axis == NX_Z) ? v.z : v.y; + + Event *event = new Event("physx-controller-down"); + event->add_parameter(EventParameter(this)); + //event->add_parameter(EventParameter(velocity)); + EventQueue::get_global_event_queue()->queue_event(event); +} + diff --git a/panda/src/physx/physxController.h b/panda/src/physx/physxController.h new file mode 100644 index 0000000000..9bfde905a2 --- /dev/null +++ b/panda/src/physx/physxController.h @@ -0,0 +1,120 @@ +// Filename: physxController.h +// Created by: enn0x (24Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONTROLLER_H +#define PHYSXCONTROLLER_H + +#include "pandabase.h" +#include "pointerTo.h" +#include "lpoint3.h" +#include "lmatrix.h" +#include "lquaternion.h" + +#include "physxObject.h" +#include "physxEnums.h" + +#include "NxController.h" + +class PhysxActor; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxController +// Description : Abstract base class for character controllers. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxController : public PhysxObject, public PhysxEnums { + +PUBLISHED: + void release(); + + PT(PhysxActor) get_actor() const; + + void set_pos(const LPoint3f &pos); + void set_sharpness(float sharpness); + void set_collision(bool enable); + void set_min_distance(float min_dist); + void set_step_offset(float offset); + + LPoint3f get_pos() const; + float get_sharpness() const; + + void set_global_speed(const LVector3f &speed); + void set_local_speed(const LVector3f &speed); + void set_omega(float omega); + void set_h(float heading); + float get_h() const; + + void report_scene_changed(); + void start_jump(float v0); + void stop_jump(); + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +public: + void update(float dt); + + static PT(PhysxController) factory(NxControllerType shapeType); + + virtual NxController *ptr() const = 0; + + virtual void link(NxController *controllerPtr) = 0; + virtual void unlink() = 0; + +protected: + INLINE PhysxController(); + +private: + NxReal get_jump_height(float dt, NxVec3 &gravity); + + float _sharpness; + float _min_dist; + + bool _jumping; + float _jump_time; + float _jump_v0; + + float _omega; + float _heading; + NxVec3 _speed; + + NxVec3 _up_vector; + NxQuat _up_quat; + NxQuat _up_quat_inv; + NxHeightFieldAxis _up_axis; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxObject::init_type(); + register_type(_type_handle, "PhysxController", + PhysxObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxController.I" + +#endif // PHYSXCONTROLLER_H diff --git a/panda/src/physx/physxTemplate.cxx b/panda/src/physx/physxControllerDesc.I similarity index 54% rename from panda/src/physx/physxTemplate.cxx rename to panda/src/physx/physxControllerDesc.I index 1b82b41537..de3d3bf50d 100644 --- a/panda/src/physx/physxTemplate.cxx +++ b/panda/src/physx/physxControllerDesc.I @@ -1,5 +1,5 @@ -// Filename: physxTemplate.cxx -// Created by: pratt (Dec 12, 2007) +// Filename: physxControllerDesc.I +// Created by: enn0x (22Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,14 +12,15 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX -#include "physxTemplate.h" -//includes -//typehandle -//publicstructors -//publicmethods -//publicattributes -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerDesc::Constructor +// Access: Protected +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxControllerDesc:: +PhysxControllerDesc() { + +} diff --git a/panda/src/physx/physxControllerDesc.cxx b/panda/src/physx/physxControllerDesc.cxx new file mode 100644 index 0000000000..8ae3a0103b --- /dev/null +++ b/panda/src/physx/physxControllerDesc.cxx @@ -0,0 +1,148 @@ +// Filename: physxControllerDesc.cxx +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxControllerDesc.h" +#include "physxManager.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerDesc::set_pos +// Access: Published +// Description: Set the position of the character. +//////////////////////////////////////////////////////////////////// +void PhysxControllerDesc:: +set_pos(const LPoint3f &pos) { + + ptr()->position = PhysxManager::point3_to_nxExtVec3(pos); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerDesc::set_slope_limit +// Access: Published +// Description: Sets the maximum slope which the character can walk +// up. In general it is desirable to limit where the +// character can walk, in particular it is unrealistic +// for the character to be able to climb arbitary +// slopes. +// The value is expressed in degrees. +// Default: 45.0 degrees. +//////////////////////////////////////////////////////////////////// +void PhysxControllerDesc:: +set_slope_limit(float slopeLimit) { + + ptr()->slopeLimit = cosf(NxMath::degToRad(slopeLimit)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerDesc::set_skin_width +// Access: Published +// Description: Sets the skin width used by the controller. +// A "skin" around the controller is necessary to +// avoid numerical precision issues. +// This is dependant on the scale of the users world, +// but should be a small, positive non zero value. +// Default: 0.1 +//////////////////////////////////////////////////////////////////// +void PhysxControllerDesc:: +set_skin_width(float skinWidth) { + + ptr()->skinWidth = skinWidth; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerDesc::set_step_offset +// Access: Published +// Description: Defines the maximum height of an obstacle which the +// character can climb. +// A small value will mean that the character gets +// stuck and cannot walk up stairs etc, a value which +// is too large will mean that the character can climb +// over unrealistically high obstacles. +// Default: 0.5 +//////////////////////////////////////////////////////////////////// +void PhysxControllerDesc:: +set_step_offset(float stepOffset) { + + ptr()->stepOffset = stepOffset; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerDesc::set_interaction_flag +// Access: Published +// Description: The interaction flag controls if a character +// controller collides with other controllers. +// The default is to collide with other controllers. +//////////////////////////////////////////////////////////////////// +void PhysxControllerDesc:: +set_interaction_flag(bool interactionFlag) { + + ptr()->interactionFlag = (NxCCTInteractionFlag)interactionFlag; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerDesc::get_pos +// Access: Published +// Description: Returns the position of the character. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxControllerDesc:: +get_pos() const { + + return PhysxManager::nxExtVec3_to_point3(ptr()->position); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerDesc::get_slope_limit +// Access: Published +// Description: Returns the maximum slope which the character can +// walk up. +//////////////////////////////////////////////////////////////////// +float PhysxControllerDesc:: +get_slope_limit() const { + + return NxMath::radToDeg(acosf(ptr()->slopeLimit)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerDesc::get_skin_width +// Access: Published +// Description: Returns the skin width used by the controller. +//////////////////////////////////////////////////////////////////// +float PhysxControllerDesc:: +get_skin_width() const { + + return ptr()->skinWidth; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerDesc::get_step_offset +// Access: Published +// Description: Returns the maximum height of an obstacle which the +// character can climb. +//////////////////////////////////////////////////////////////////// +float PhysxControllerDesc:: +get_step_offset() const { + + return ptr()->stepOffset; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerDesc::get_interaction_flag +// Access: Published +// Description: Returns the interaction flag. +//////////////////////////////////////////////////////////////////// +bool PhysxControllerDesc:: +get_interaction_flag() const { + + return (ptr()->interactionFlag) ? true : false; +} + diff --git a/panda/src/physx/physxControllerDesc.h b/panda/src/physx/physxControllerDesc.h new file mode 100644 index 0000000000..49cb9a16b3 --- /dev/null +++ b/panda/src/physx/physxControllerDesc.h @@ -0,0 +1,54 @@ +// Filename: physxControllerDesc.h +// Created by: enn0x (22Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONTROLLERDESC_H +#define PHYSXCONTROLLERDESC_H + +#include "pandabase.h" +#include "lpoint3.h" + +#include "NxController.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxControllerDesc +// Description : Descriptor class for a character controller. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxControllerDesc { + +PUBLISHED: + virtual void set_to_default() = 0; + virtual bool is_valid() const = 0; + + void set_pos(const LPoint3f &pos); + void set_slope_limit(float slopeLimit); + void set_skin_width(float skinWidth); + void set_step_offset(float setpOffset); + void set_interaction_flag(bool interactionFlag); + + LPoint3f get_pos() const; + float get_slope_limit() const; + float get_skin_width() const; + float get_step_offset() const; + bool get_interaction_flag() const; + +public: + virtual NxControllerDesc *ptr() const = 0; + +protected: + INLINE PhysxControllerDesc(); +}; + +#include "physxControllerDesc.I" + +#endif // PHYSXCONTROLLERDESC_H diff --git a/panda/src/physx/physxControllerReport.I b/panda/src/physx/physxControllerReport.I new file mode 100644 index 0000000000..6267154074 --- /dev/null +++ b/panda/src/physx/physxControllerReport.I @@ -0,0 +1,36 @@ +// Filename: physxControllerReport.I +// Created by: enn0x (24Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerReport::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxControllerReport:: +PhysxControllerReport() : NxUserControllerHitReport() { + + _enabled = false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerReport::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxControllerReport:: +~PhysxControllerReport() { + +} + diff --git a/panda/src/physx/physxControllerReport.cxx b/panda/src/physx/physxControllerReport.cxx new file mode 100644 index 0000000000..6f4cb7b337 --- /dev/null +++ b/panda/src/physx/physxControllerReport.cxx @@ -0,0 +1,105 @@ +// Filename: physxControllerReport.cxx +// Created by: enn0x (24Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxControllerReport.h" + +PStatCollector PhysxControllerReport::_pcollector("App:PhysX:Controller Reporting"); + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerReport::enable +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxControllerReport:: +enable() { + + _enabled = true; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerReport::disable +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxControllerReport:: +disable() { + + _enabled = false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerReport::is_enabled +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxControllerReport:: +is_enabled() const { + + return _enabled; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerReport::onShapeHit +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxControllerAction PhysxControllerReport:: +onShapeHit( const NxControllerShapeHit& hit ) { + + if (!_enabled) { + return NX_ACTION_NONE; + } + + _pcollector.start(); + + if (1 && hit.shape) { + NxActor& actor = hit.shape->getActor(); + if (actor.isDynamic() && !actor.readBodyFlag(NX_BF_KINEMATIC)) { + if (hit.dir.z == 0.0f) { + NxF32 controllerMass = hit.controller->getActor()->getMass(); + NxF32 coeff = actor.getMass() * hit.length * controllerMass; + actor.addForceAtLocalPos(hit.dir*coeff, NxVec3(0,0,0), NX_IMPULSE); + } + } + } + + _pcollector.stop(); + + return NX_ACTION_NONE; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxControllerReport::onControllerHit +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxControllerAction PhysxControllerReport:: +onControllerHit(const NxControllersHit& hit) { + + if (!_enabled) { + return NX_ACTION_NONE; + } + + _pcollector.start(); + + if (1 && hit.other) { + // For now other controllers are unpushable. --TODO-- + //return NX_ACTION_PUSH; is not implemented! + } + + _pcollector.stop(); + + return NX_ACTION_NONE; +} + diff --git a/panda/src/physx/physxControllerReport.h b/panda/src/physx/physxControllerReport.h new file mode 100644 index 0000000000..3cdcc8aa18 --- /dev/null +++ b/panda/src/physx/physxControllerReport.h @@ -0,0 +1,48 @@ +// Filename: physxControllerReport.h +// Created by: enn0x (24Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONTROLLERREPORT_H +#define PHYSXCONTROLLERREPORT_H + +#include "pandabase.h" +#include "pStatCollector.h" + +#include "NxController.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxControllerReport +// Description : Implementation of the NxUserControllerHitReport +// interface. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxControllerReport : public NxUserControllerHitReport { + +public: + INLINE PhysxControllerReport(); + INLINE ~PhysxControllerReport(); + + void enable(); + void disable(); + bool is_enabled() const; + + virtual NxControllerAction onShapeHit(const NxControllerShapeHit& hit); + virtual NxControllerAction onControllerHit(const NxControllersHit& hit); + +private: + bool _enabled; + static PStatCollector _pcollector; +}; + +#include "physxControllerReport.I" + +#endif // PHYSXCONTROLLERREPORT_H diff --git a/panda/src/physx/physxConvexForceFieldShape.I b/panda/src/physx/physxConvexForceFieldShape.I new file mode 100644 index 0000000000..a38be7ee2e --- /dev/null +++ b/panda/src/physx/physxConvexForceFieldShape.I @@ -0,0 +1,36 @@ +// Filename: physxConvexForceFieldShape.I +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexForceFieldShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexForceFieldShape:: +PhysxConvexForceFieldShape() : PhysxForceFieldShape() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexForceFieldShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexForceFieldShape:: +~PhysxConvexForceFieldShape() { + +} + diff --git a/panda/src/physx/physxConvexForceFieldShape.cxx b/panda/src/physx/physxConvexForceFieldShape.cxx new file mode 100644 index 0000000000..22c1d21cbe --- /dev/null +++ b/panda/src/physx/physxConvexForceFieldShape.cxx @@ -0,0 +1,63 @@ +// Filename: physxConvexForceFieldShape.cxx +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxConvexForceFieldShape.h" +#include "physxConvexForceFieldShapeDesc.h" + +TypeHandle PhysxConvexForceFieldShape::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexForceFieldShape::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxConvexForceFieldShape:: +link(NxForceFieldShape *shapePtr) { + + _ptr = shapePtr->isConvex(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)_ptr->getShapeGroup().userData; + group->_shapes.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexForceFieldShape::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxConvexForceFieldShape:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)_ptr->getShapeGroup().userData; + group->_shapes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxConvexForceFieldShape::save_to_desc +// Access : Published +// Description : Saves the state of the shape object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxConvexForceFieldShape:: +save_to_desc(PhysxConvexForceFieldShapeDesc &shapeDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); +} + diff --git a/panda/src/physx/physxConvexForceFieldShape.h b/panda/src/physx/physxConvexForceFieldShape.h new file mode 100644 index 0000000000..dade678cdc --- /dev/null +++ b/panda/src/physx/physxConvexForceFieldShape.h @@ -0,0 +1,73 @@ +// Filename: physxConvexForceFieldShape.h +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONVEXFORCEFIELDSHAPE_H +#define PHYSXCONVEXFORCEFIELDSHAPE_H + +#include "pandabase.h" + +#include "physxForceFieldShape.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxConvexForceFieldShapeDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxConvexForceFieldShape +// Description : A convex shaped region used to define force field. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxConvexForceFieldShape : public PhysxForceFieldShape { + +PUBLISHED: + INLINE PhysxConvexForceFieldShape(); + INLINE ~PhysxConvexForceFieldShape(); + + void save_to_desc(PhysxConvexForceFieldShapeDesc &shapeDesc) const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxForceFieldShape *ptr() const { return (NxForceFieldShape *)_ptr; }; + + void link(NxForceFieldShape *shapePtr); + void unlink(); + +private: + NxConvexForceFieldShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxForceFieldShape::init_type(); + register_type(_type_handle, "PhysxConvexForceFieldShape", + PhysxForceFieldShape::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxConvexForceFieldShape.I" + +#endif // PHYSXCONVEXFORCEFIELDSHAPE_H diff --git a/panda/src/physx/physxConvexForceFieldShapeDesc.I b/panda/src/physx/physxConvexForceFieldShapeDesc.I new file mode 100644 index 0000000000..81e7b789ed --- /dev/null +++ b/panda/src/physx/physxConvexForceFieldShapeDesc.I @@ -0,0 +1,59 @@ +// Filename: physxConvexForceFieldShapeDesc.I +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexForceFieldShapeDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexForceFieldShapeDesc:: +PhysxConvexForceFieldShapeDesc() : PhysxForceFieldShapeDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexForceFieldShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexForceFieldShapeDesc:: +~PhysxConvexForceFieldShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexForceFieldShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxConvexForceFieldShapeDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexForceFieldShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxConvexForceFieldShapeDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxConvexForceFieldShapeDesc.cxx b/panda/src/physx/physxConvexForceFieldShapeDesc.cxx new file mode 100644 index 0000000000..1e13253ad5 --- /dev/null +++ b/panda/src/physx/physxConvexForceFieldShapeDesc.cxx @@ -0,0 +1,29 @@ +// Filename: physxConvexForceFieldShapeDesc.cxx +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxConvexForceFieldShapeDesc.h" +#include "physxConvexMesh.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexForceFieldShapeDesc::set_mesh +// Access: Published +// Description: Sets the convex mesh for this force field shape. +//////////////////////////////////////////////////////////////////// +void PhysxConvexForceFieldShapeDesc:: +set_mesh(PT(PhysxConvexMesh) mesh) { + + _desc.meshData = mesh->ptr(); +} + + diff --git a/panda/src/physx/physxConvexForceFieldShapeDesc.h b/panda/src/physx/physxConvexForceFieldShapeDesc.h new file mode 100644 index 0000000000..bef2c9fbac --- /dev/null +++ b/panda/src/physx/physxConvexForceFieldShapeDesc.h @@ -0,0 +1,49 @@ +// Filename: physxConvexForceFieldShapeDesc.h +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONVEXFORCEFIELDSHAPEDESC_H +#define PHYSXCONVEXFORCEFIELDSHAPEDESC_H + +#include "pandabase.h" + +#include "physxForceFieldShapeDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxConvexMesh; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxConvexForceFieldShapeDesc +// Description : A descriptor for a convex force field shape. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxConvexForceFieldShapeDesc : public PhysxForceFieldShapeDesc { + +PUBLISHED: + INLINE PhysxConvexForceFieldShapeDesc(); + INLINE ~PhysxConvexForceFieldShapeDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_mesh(PT(PhysxConvexMesh) mesh); + +public: + NxForceFieldShapeDesc *ptr() const { return (NxForceFieldShapeDesc *)&_desc; }; + NxConvexForceFieldShapeDesc _desc; +}; + +#include "physxConvexForceFieldShapeDesc.I" + +#endif // PHYSXCONVEXFORCEFIELDSHAPEDESC_H diff --git a/panda/src/physx/physxConvexMesh.I b/panda/src/physx/physxConvexMesh.I new file mode 100644 index 0000000000..d1e466a32f --- /dev/null +++ b/panda/src/physx/physxConvexMesh.I @@ -0,0 +1,59 @@ +// Filename: physxConvexMesh.I +// Created by: enn0x (13Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMesh::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexMesh:: +PhysxConvexMesh() : PhysxObject() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMesh::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexMesh:: +~PhysxConvexMesh() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMesh::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxConvexMesh:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMesh::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxConvexMesh:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " (at 0x" << this << ")\n"; +} + diff --git a/panda/src/physx/physxConvexMesh.cxx b/panda/src/physx/physxConvexMesh.cxx new file mode 100644 index 0000000000..bbaa073f08 --- /dev/null +++ b/panda/src/physx/physxConvexMesh.cxx @@ -0,0 +1,76 @@ +// Filename: physxConvexMesh.cxx +// Created by: enn0x (13Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxConvexMesh.h" +#include "physxMeshPool.h" + +TypeHandle PhysxConvexMesh::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMesh::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxConvexMesh:: +link(NxConvexMesh *meshPtr) { + + // Link self + PhysxManager::get_global_ptr()->_convex_meshes.add(this); + _ptr = meshPtr; + _error_type = ET_ok; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMesh::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxConvexMesh:: +unlink() { + + // Unlink self + _error_type = ET_released; + PhysxManager::get_global_ptr()->_convex_meshes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMesh::release +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxConvexMesh:: +release() { + + nassertv(_error_type == ET_ok); + + unlink(); + NxGetPhysicsSDK()->releaseConvexMesh(*_ptr); + _ptr = NULL; + + PhysxMeshPool::release_convex_mesh(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMesh::get_reference_count +// Access: Published +// Description: Returns the reference count for shared meshes. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxConvexMesh:: +get_reference_count() const { + + nassertr(_error_type == ET_ok, 0); + + return _ptr->getReferenceCount(); +} + diff --git a/panda/src/physx/physxConvexMesh.h b/panda/src/physx/physxConvexMesh.h new file mode 100644 index 0000000000..37d6beccab --- /dev/null +++ b/panda/src/physx/physxConvexMesh.h @@ -0,0 +1,79 @@ +// Filename: physxConvexMesh.h +// Created by: enn0x (13Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONVEXMESH_H +#define PHYSXCONVEXMESH_H + +#include "pandabase.h" + +#include "physxObject.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxConvexMesh +// Description : A Convex Mesh. Internally represented as a list of +// convex polygons. The number of polygons is +// limited to 256. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxConvexMesh : public PhysxObject { + +PUBLISHED: + unsigned int get_reference_count() const; + +//////////////////////////////////////////////////////////////////// +PUBLISHED: + void release(); + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +public: + INLINE PhysxConvexMesh(); + INLINE ~PhysxConvexMesh(); + + INLINE NxConvexMesh *ptr() const { return _ptr; }; + + void link(NxConvexMesh *meshPtr); + void unlink(); + +private: + NxConvexMesh *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxObject::init_type(); + register_type(_type_handle, "PhysxConvexMesh", + PhysxObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxConvexMesh.I" + +#endif // PHYSXCONVEXMESH_H diff --git a/panda/src/physx/physxConvexMeshDesc.I b/panda/src/physx/physxConvexMeshDesc.I new file mode 100644 index 0000000000..1ea501776a --- /dev/null +++ b/panda/src/physx/physxConvexMeshDesc.I @@ -0,0 +1,54 @@ +// Filename: physxConvexMeshDesc.I +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMeshDesc::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexMeshDesc:: +PhysxConvexMeshDesc() { + + _desc.flags = NX_CF_COMPUTE_CONVEX; + _desc.pointStrideBytes = sizeof(NxVec3); + _desc.points = NULL; + + _vertices = NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMeshDesc::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexMeshDesc:: +~PhysxConvexMeshDesc() { + + if (_vertices) { + delete [] _vertices; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMeshDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxConvexMeshDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxConvexMeshDesc.cxx b/panda/src/physx/physxConvexMeshDesc.cxx new file mode 100644 index 0000000000..265ec26e14 --- /dev/null +++ b/panda/src/physx/physxConvexMeshDesc.cxx @@ -0,0 +1,130 @@ +// Filename: physxConvexMeshDesc.cxx +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxConvexMeshDesc.h" +#include "physxManager.h" + +#include "nodePathCollection.h" +#include "geomNode.h" +#include "geomVertexReader.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMeshDesc::set_num_vertices +// Access: Published +// Description: Sets the number of vertices to be stored within +// this convex mesh. The function allocates memory +// for the vertices, but it does not set any vertices. +// +// This method must be called before any calls to +// set_vertex are done! +// +// The number of vertices in a single convex mesh has +// to be smaller than 256. +//////////////////////////////////////////////////////////////////// +void PhysxConvexMeshDesc:: +set_num_vertices(unsigned int numVertices) { + + nassertv_always(numVertices < 256); + + if (_desc.points) { + delete [] _vertices; + } + + _vertices = new NxVec3[numVertices]; + + _desc.numVertices = numVertices; + _desc.points = _vertices; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMeshDesc::set_vertex +// Access: Published +// Description: Sets a single vertex. You have to call the function +// set_num_vertices before you can call this function. +//////////////////////////////////////////////////////////////////// +void PhysxConvexMeshDesc:: +set_vertex(unsigned int idx, const LPoint3f &vert) { + + nassertv(_desc.numVertices > idx); + _vertices[idx] = PhysxManager::point3_to_nxVec3(vert); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMeshDesc::get_desc +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +const NxConvexMeshDesc &PhysxConvexMeshDesc:: +get_desc() const { + + return _desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexMeshDesc::set_from_node_path +// Access: Published +// Description: A convenience method to set the mesh data from +// a NodePath in a single call. The method iterates +// over the NodePath geoms and collects data for +// the convex mesh. +// +// Do not use the following function when using this +// one: +// - set_num_vertices +// - set_vertex +//////////////////////////////////////////////////////////////////// +void PhysxConvexMeshDesc:: +set_from_node_path(const NodePath &np) { + + pvector dataVertices; + + // Collect data from NodePath + NodePathCollection npc = np.find_all_matches( "**/+GeomNode" ); + for (int i=0; iget_num_geoms(); j++) { + CPT(Geom) geom = gnode->get_geom(j); + CPT(GeomVertexData) vdata = geom->get_vertex_data(); + GeomVertexReader reader = GeomVertexReader(vdata, InternalName::get_vertex()); + + while (!reader.is_at_end()) { + dataVertices.push_back(reader.get_data3f()); + } + } + } + + // Set descriptor members + int i; + + NxU32 numVertices = dataVertices.size(); + + _vertices = new NxVec3[numVertices]; + + i = 0; + pvector::const_iterator it; + for (it=dataVertices.begin(); it!=dataVertices.end(); it++) { + LPoint3f v = *it; + + _vertices[i].x = v.get_x(); + _vertices[i].y = v.get_y(); + _vertices[i].z = v.get_z(); + i++; + } + + _desc.numVertices = numVertices; + _desc.points = _vertices; +} + diff --git a/panda/src/physx/physxConvexMeshDesc.h b/panda/src/physx/physxConvexMeshDesc.h new file mode 100644 index 0000000000..91772ff678 --- /dev/null +++ b/panda/src/physx/physxConvexMeshDesc.h @@ -0,0 +1,51 @@ +// Filename: physxConvexMeshDesc.h +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONVEXMESHDESC_H +#define PHYSXCONVEXMESHDESC_H + +#include "pandabase.h" +#include "lpoint3.h" +#include "nodePath.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxConvexMeshDesc +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxConvexMeshDesc { + +PUBLISHED: + INLINE PhysxConvexMeshDesc(); + INLINE ~PhysxConvexMeshDesc(); + + INLINE bool is_valid() const; + + void set_num_vertices(unsigned int n); + void set_vertex(unsigned int idx, const LPoint3f &vert); + void set_from_node_path(const NodePath &np); + +public: + const NxConvexMeshDesc &get_desc() const; + +private: + NxVec3 *_vertices; + NxConvexMeshDesc _desc; +}; + +#include "physxConvexMeshDesc.I" + +#endif // PHYSXCONVEXMESHDESC_H diff --git a/panda/src/physx/physxConvexShape.I b/panda/src/physx/physxConvexShape.I new file mode 100644 index 0000000000..db1dd53069 --- /dev/null +++ b/panda/src/physx/physxConvexShape.I @@ -0,0 +1,36 @@ +// Filename: physxConvexShape.I +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexShape:: +PhysxConvexShape() : PhysxShape() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexShape:: +~PhysxConvexShape() { + +} + diff --git a/panda/src/physx/physxConvexShape.cxx b/panda/src/physx/physxConvexShape.cxx new file mode 100644 index 0000000000..c607375394 --- /dev/null +++ b/panda/src/physx/physxConvexShape.cxx @@ -0,0 +1,63 @@ +// Filename: physxConvexShape.cxx +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxConvexShape.h" +#include "physxConvexShapeDesc.h" + +TypeHandle PhysxConvexShape::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexShape::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxConvexShape:: +link(NxShape *shapePtr) { + + _ptr = shapePtr->isConvexMesh(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexShape::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxConvexShape:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxConvexShape::save_to_desc +// Access : Published +// Description : Saves the state of the shape object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxConvexShape:: +save_to_desc(PhysxConvexShapeDesc &shapeDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); +} + diff --git a/panda/src/physx/physxConvexShape.h b/panda/src/physx/physxConvexShape.h new file mode 100644 index 0000000000..485ad0c2a4 --- /dev/null +++ b/panda/src/physx/physxConvexShape.h @@ -0,0 +1,74 @@ +// Filename: physxConvexShape.h +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONVEXSHAPE_H +#define PHYSXCONVEXSHAPE_H + +#include "pandabase.h" + +#include "physxShape.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxConvexShapeDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxConvexShape +// Description : A shapes which is used to represent an instance of +// an convex mesh. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxConvexShape : public PhysxShape { + +PUBLISHED: + INLINE PhysxConvexShape(); + INLINE ~PhysxConvexShape(); + + void save_to_desc(PhysxConvexShapeDesc &shapeDesc) const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxShape *ptr() const { return (NxShape *)_ptr; }; + + void link(NxShape *shapePtr); + void unlink(); + +private: + NxConvexShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxShape::init_type(); + register_type(_type_handle, "PhysxConvexShape", + PhysxShape::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxConvexShape.I" + +#endif // PHYSXCONVEXSHAPE_H diff --git a/panda/src/physx/physxConvexShapeDesc.I b/panda/src/physx/physxConvexShapeDesc.I new file mode 100644 index 0000000000..735f65d2ea --- /dev/null +++ b/panda/src/physx/physxConvexShapeDesc.I @@ -0,0 +1,59 @@ +// Filename: physxConvexShapeDesc.I +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexShapeDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexShapeDesc:: +PhysxConvexShapeDesc() : PhysxShapeDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxConvexShapeDesc:: +~PhysxConvexShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxConvexShapeDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxConvexShapeDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxConvexShapeDesc.cxx b/panda/src/physx/physxConvexShapeDesc.cxx new file mode 100644 index 0000000000..d902cefdb1 --- /dev/null +++ b/panda/src/physx/physxConvexShapeDesc.cxx @@ -0,0 +1,29 @@ +// Filename: physxConvexShapeDesc.cxx +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxConvexShapeDesc.h" +#include "physxConvexMesh.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxConvexShapeDesc::set_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxConvexShapeDesc:: +set_mesh(PT(PhysxConvexMesh) mesh) { + + _desc.meshData = mesh->ptr(); +} + + diff --git a/panda/src/physx/physxConvexShapeDesc.h b/panda/src/physx/physxConvexShapeDesc.h new file mode 100644 index 0000000000..d8670a1192 --- /dev/null +++ b/panda/src/physx/physxConvexShapeDesc.h @@ -0,0 +1,49 @@ +// Filename: physxConvexShapeDesc.h +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCONVEXSHAPEDESC_H +#define PHYSXCONVEXSHAPEDESC_H + +#include "pandabase.h" + +#include "physxShapeDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxConvexMesh; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxConvexShapeDesc +// Description : Descriptor class for PhysxConvexShape. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxConvexShapeDesc : public PhysxShapeDesc { + +PUBLISHED: + INLINE PhysxConvexShapeDesc(); + INLINE ~PhysxConvexShapeDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_mesh(PT(PhysxConvexMesh) mesh); + +public: + NxShapeDesc *ptr() const { return (NxShapeDesc *)&_desc; }; + NxConvexShapeDesc _desc; +}; + +#include "physxConvexShapeDesc.I" + +#endif // PHYSXCONVEXSHAPEDESC_H diff --git a/panda/src/physx/physxCylindricalJoint.I b/panda/src/physx/physxCylindricalJoint.I new file mode 100644 index 0000000000..5ec371bbe5 --- /dev/null +++ b/panda/src/physx/physxCylindricalJoint.I @@ -0,0 +1,36 @@ +// Filename: physxCylindricalJoint.I +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCylindricalJoint::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCylindricalJoint:: +PhysxCylindricalJoint() : PhysxJoint() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCylindricalJoint::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCylindricalJoint:: +~PhysxCylindricalJoint() { + +} + diff --git a/panda/src/physx/physxCylindricalJoint.cxx b/panda/src/physx/physxCylindricalJoint.cxx new file mode 100644 index 0000000000..826f1dffbb --- /dev/null +++ b/panda/src/physx/physxCylindricalJoint.cxx @@ -0,0 +1,76 @@ +// Filename: physxCylindricalJoint.cxx +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxCylindricalJoint.h" +#include "physxCylindricalJointDesc.h" + +TypeHandle PhysxCylindricalJoint::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCylindricalJoint::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxCylindricalJoint:: +link(NxJoint *jointPtr) { + + _ptr = jointPtr->isCylindricalJoint(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCylindricalJoint::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxCylindricalJoint:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxCylindricalJoint::save_to_desc +// Access : Published +// Description : Saves the state of the joint object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxCylindricalJoint:: +save_to_desc(PhysxCylindricalJointDesc &jointDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxCylindricalJoint::load_from_desc +// Access : Published +// Description : Loads the entire state of the joint from a +// descriptor with a single call. +//////////////////////////////////////////////////////////////////// +void PhysxCylindricalJoint:: +load_from_desc(const PhysxCylindricalJointDesc &jointDesc) { + + nassertv(_error_type == ET_ok); + _ptr->loadFromDesc(jointDesc._desc); +} + diff --git a/panda/src/physx/physxCylindricalJoint.h b/panda/src/physx/physxCylindricalJoint.h new file mode 100644 index 0000000000..e9dc52981e --- /dev/null +++ b/panda/src/physx/physxCylindricalJoint.h @@ -0,0 +1,76 @@ +// Filename: physxCylindricalJoint.h +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCYLINDRICALJOINT_H +#define PHYSXCYLINDRICALJOINT_H + +#include "pandabase.h" + +#include "physxJoint.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxCylindricalJointDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxCylindricalJoint +// Description : Cylindrical Joints permit relative translational +// movement between two bodies along an axis, and also +// relative rotation along the axis. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxCylindricalJoint : public PhysxJoint { + +PUBLISHED: + INLINE PhysxCylindricalJoint(); + INLINE ~PhysxCylindricalJoint(); + + void save_to_desc(PhysxCylindricalJointDesc &jointDesc) const; + void load_from_desc(const PhysxCylindricalJointDesc &jointDesc); + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxJoint *ptr() const { return (NxJoint *)_ptr; }; + + void link(NxJoint *jointPtr); + void unlink(); + +private: + NxCylindricalJoint *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxJoint::init_type(); + register_type(_type_handle, "PhysxCylindricalJoint", + PhysxJoint::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxCylindricalJoint.I" + +#endif // PHYSXCYLINDRICALJOINT_H diff --git a/panda/src/physx/physxCylindricalJointDesc.I b/panda/src/physx/physxCylindricalJointDesc.I new file mode 100644 index 0000000000..864085af3a --- /dev/null +++ b/panda/src/physx/physxCylindricalJointDesc.I @@ -0,0 +1,59 @@ +// Filename: physxCylindricalJointDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCylindricalJointDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCylindricalJointDesc:: +PhysxCylindricalJointDesc() : PhysxJointDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCylindricalJointDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCylindricalJointDesc:: +~PhysxCylindricalJointDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCylindricalJointDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxCylindricalJointDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCylindricalJointDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxCylindricalJointDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxTemplate.I b/panda/src/physx/physxCylindricalJointDesc.cxx similarity index 78% rename from panda/src/physx/physxTemplate.I rename to panda/src/physx/physxCylindricalJointDesc.cxx index 22be1136c9..1b1129b11d 100644 --- a/panda/src/physx/physxTemplate.I +++ b/panda/src/physx/physxCylindricalJointDesc.cxx @@ -1,5 +1,5 @@ -// Filename: physxTemplate.I -// Created by: pratt (Dec 12, 2007) +// Filename: physxCylindricalJointDesc.cxx +// Created by: enn0x (28Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,6 +12,5 @@ // //////////////////////////////////////////////////////////////////// -//publicstructors -//publicmethods -//publicattributes +#include "physxCylindricalJointDesc.h" + diff --git a/panda/src/physx/physxCylindricalJointDesc.h b/panda/src/physx/physxCylindricalJointDesc.h new file mode 100644 index 0000000000..a44737a900 --- /dev/null +++ b/panda/src/physx/physxCylindricalJointDesc.h @@ -0,0 +1,46 @@ +// Filename: physxCylindricalJointDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCYLINDRICALJOINTDESC_H +#define PHYSXCYLINDRICALJOINTDESC_H + +#include "pandabase.h" + +#include "physxJointDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxCylindricalJointDesc +// Description : Descriptor class for sliding joint. See +// PhysxCylindricalJoint. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxCylindricalJointDesc : public PhysxJointDesc { + +PUBLISHED: + INLINE PhysxCylindricalJointDesc(); + INLINE ~PhysxCylindricalJointDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + +public: + NxJointDesc *ptr() const { return (NxJointDesc *)&_desc; }; + NxCylindricalJointDesc _desc; +}; + +#include "physxCylindricalJointDesc.I" + +#endif // PHYSXCYLINDRICALJOINTDESC_H diff --git a/panda/src/physx/physxD6Joint.I b/panda/src/physx/physxD6Joint.I index 33a3c1dbc0..435bdfcbf3 100644 --- a/panda/src/physx/physxD6Joint.I +++ b/panda/src/physx/physxD6Joint.I @@ -1,5 +1,5 @@ // Filename: physxD6Joint.I -// Created by: pratt (Jun 16, 2006) +// Created by: enn0x (02Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,3 +12,25 @@ // //////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6Joint::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxD6Joint:: +PhysxD6Joint() : PhysxJoint() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6Joint::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxD6Joint:: +~PhysxD6Joint() { + +} + diff --git a/panda/src/physx/physxD6Joint.cxx b/panda/src/physx/physxD6Joint.cxx index 8eb1d7495c..5f832534d4 100644 --- a/panda/src/physx/physxD6Joint.cxx +++ b/panda/src/physx/physxD6Joint.cxx @@ -1,5 +1,5 @@ // Filename: physxD6Joint.cxx -// Created by: pratt (Jun 16, 2006) +// Created by: enn0x (02Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,86 +12,113 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxD6Joint.h" - -#include "luse.h" #include "physxD6JointDesc.h" TypeHandle PhysxD6Joint::_type_handle; //////////////////////////////////////////////////////////////////// -// Function : load_from_desc -// Access : Published -// Description : +// Function: PhysxD6Joint::link +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// void PhysxD6Joint:: -load_from_desc(const PhysxD6JointDesc & desc) { - nassertv(nD6Joint != NULL); +link(NxJoint *jointPtr) { - nD6Joint->loadFromDesc(desc.nD6JointDesc); + _ptr = jointPtr->isD6Joint(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.add(this); } //////////////////////////////////////////////////////////////////// -// Function : save_to_desc -// Access : Published -// Description : +// Function: PhysxD6Joint::unlink +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// void PhysxD6Joint:: -save_to_desc(PhysxD6JointDesc & desc) { - nassertv(nD6Joint != NULL); +unlink() { - nD6Joint->saveToDesc(desc.nD6JointDesc); + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.remove(this); } //////////////////////////////////////////////////////////////////// -// Function : set_drive_angular_velocity +// Function : PhysxD6Joint::save_to_desc // Access : Published -// Description : +// Description : Saves the state of the joint object to a +// descriptor. //////////////////////////////////////////////////////////////////// void PhysxD6Joint:: -set_drive_angular_velocity(const LVecBase3f & ang_vel) { - nassertv(nD6Joint != NULL); +save_to_desc(PhysxD6JointDesc &jointDesc) const { - nD6Joint->setDriveAngularVelocity(PhysxManager::lVecBase3_to_nxVec3(ang_vel)); + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(jointDesc._desc); } //////////////////////////////////////////////////////////////////// -// Function : set_drive_linear_velocity +// Function : PhysxD6Joint::load_from_desc // Access : Published -// Description : +// Description : Loads the entire state of the joint from a +// descriptor with a single call. //////////////////////////////////////////////////////////////////// void PhysxD6Joint:: -set_drive_linear_velocity(const LVecBase3f & lin_vel) { - nassertv(nD6Joint != NULL); +load_from_desc(const PhysxD6JointDesc &jointDesc) { - nD6Joint->setDriveLinearVelocity(PhysxManager::lVecBase3_to_nxVec3(lin_vel)); + nassertv(_error_type == ET_ok); + _ptr->loadFromDesc(jointDesc._desc); } //////////////////////////////////////////////////////////////////// -// Function : set_drive_orientation -// Access : Published -// Description : +// Function: PhysxD6Joint::set_drive_angular_velocity +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// void PhysxD6Joint:: -set_drive_orientation(const LQuaternionf & orientation) { - nassertv(nD6Joint != NULL); +set_drive_angular_velocity(const LVector3f &v) { - nD6Joint->setDriveOrientation(PhysxManager::lQuaternion_to_nxQuat(orientation)); + nassertv(_error_type == ET_ok); + _ptr->setDriveAngularVelocity(PhysxManager::vec3_to_nxVec3(v)); } //////////////////////////////////////////////////////////////////// -// Function : set_drive_position -// Access : Published -// Description : +// Function: PhysxD6Joint::set_drive_linear_velocity +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// void PhysxD6Joint:: -set_drive_position(const LVecBase3f & position) { - nassertv(nD6Joint != NULL); +set_drive_linear_velocity(const LVector3f &v) { - nD6Joint->setDrivePosition(PhysxManager::lVecBase3_to_nxVec3(position)); + nassertv(_error_type == ET_ok); + _ptr->setDriveLinearVelocity(PhysxManager::vec3_to_nxVec3(v)); } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6Joint::set_drive_orientation +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6Joint:: +set_drive_orientation(const LQuaternionf &quat) { + + nassertv(_error_type == ET_ok); + _ptr->setDriveOrientation(PhysxManager::quat_to_nxQuat(quat)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6Joint::set_drive_position +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6Joint:: +set_drive_position(const LPoint3f &pos) { + + nassertv(_error_type == ET_ok); + _ptr->setDrivePosition(PhysxManager::point3_to_nxVec3(pos)); +} diff --git a/panda/src/physx/physxD6Joint.h b/panda/src/physx/physxD6Joint.h index d391080c9b..336f3fec37 100644 --- a/panda/src/physx/physxD6Joint.h +++ b/panda/src/physx/physxD6Joint.h @@ -1,5 +1,5 @@ // Filename: physxD6Joint.h -// Created by: pratt (Jun 16, 2006) +// Created by: enn0x (02Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,44 +15,55 @@ #ifndef PHYSXD6JOINT_H #define PHYSXD6JOINT_H -#ifdef HAVE_PHYSX - #include "pandabase.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - #include "physxJoint.h" -class PhysxD6JointDesc; - +#include "NoMinMax.h" #include "NxPhysics.h" +class PhysxD6JointDesc; + //////////////////////////////////////////////////////////////////// // Class : PhysxD6Joint -// Description : +// Description : A D6 joint is a general constraint between two +// actors. It allows the user to individually define +// the linear and rotational degrees of freedom. It +// also allows the user to configure the joint with +// limits and driven degrees of freedom as they wish. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxD6Joint : public PhysxJoint { + PUBLISHED: + INLINE PhysxD6Joint(); + INLINE ~PhysxD6Joint(); - void load_from_desc(const PhysxD6JointDesc & desc); - void save_to_desc(PhysxD6JointDesc & desc); - void set_drive_angular_velocity(const LVecBase3f & ang_vel); - void set_drive_linear_velocity(const LVecBase3f & lin_vel); - void set_drive_orientation(const LQuaternionf & orientation); - void set_drive_position(const LVecBase3f & position); + void save_to_desc(PhysxD6JointDesc &jointDesc) const; + void load_from_desc(const PhysxD6JointDesc &jointDesc); + void set_drive_angular_velocity(const LVector3f &v); + void set_drive_linear_velocity(const LVector3f &v); + void set_drive_orientation(const LQuaternionf &quat); + void set_drive_position(const LPoint3f &pos); +//////////////////////////////////////////////////////////////////// public: - NxD6Joint *nD6Joint; + INLINE NxJoint *ptr() const { return (NxJoint *)_ptr; }; + void link(NxJoint *jointPtr); + void unlink(); + +private: + NxD6Joint *_ptr; + +//////////////////////////////////////////////////////////////////// +public: static TypeHandle get_class_type() { return _type_handle; } static void init_type() { PhysxJoint::init_type(); - register_type(_type_handle, "PhysxD6Joint", + register_type(_type_handle, "PhysxD6Joint", PhysxJoint::get_class_type()); } virtual TypeHandle get_type() const { @@ -69,6 +80,4 @@ private: #include "physxD6Joint.I" -#endif // HAVE_PHYSX - #endif // PHYSXD6JOINT_H diff --git a/panda/src/physx/physxD6JointDesc.I b/panda/src/physx/physxD6JointDesc.I index 1e318af583..15015bf815 100644 --- a/panda/src/physx/physxD6JointDesc.I +++ b/panda/src/physx/physxD6JointDesc.I @@ -1,5 +1,5 @@ // Filename: physxD6JointDesc.I -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (01Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,103 +12,48 @@ // //////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxD6JointDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxD6JointDesc:: -is_valid() const { - return nD6JointDesc.isValid(); +INLINE PhysxD6JointDesc:: +PhysxD6JointDesc() : PhysxJointDesc() { + + _desc.name = ""; } //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxD6JointDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxD6JointDesc:: +~PhysxD6JointDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. //////////////////////////////////////////////////////////////////// INLINE void PhysxD6JointDesc:: set_to_default() { - nD6JointDesc.setToDefault(); + + _desc.setToDefault(); } //////////////////////////////////////////////////////////////////// -// Function : get_flags -// Access : Published -// Description : +// Function: PhysxD6JointDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. //////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxD6JointDesc:: -get_flags() const { - return nD6JointDesc.flags; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_gear_ratio -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxD6JointDesc:: -get_gear_ratio() const { - return nD6JointDesc.gearRatio; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_projection_angle -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxD6JointDesc:: -get_projection_angle() const { - return nD6JointDesc.projectionAngle; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_projection_distance -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxD6JointDesc:: -get_projection_distance() const { - return nD6JointDesc.projectionDistance; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxD6JointDesc:: -set_flags(unsigned int value) { - nD6JointDesc.flags = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_gear_ratio -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxD6JointDesc:: -set_gear_ratio(float value) { - nD6JointDesc.gearRatio = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_projection_angle -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxD6JointDesc:: -set_projection_angle(float value) { - nD6JointDesc.projectionAngle = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_projection_distance -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxD6JointDesc:: -set_projection_distance(float value) { - nD6JointDesc.projectionDistance = value; +INLINE bool PhysxD6JointDesc:: +is_valid() const { + + return _desc.isValid(); } diff --git a/panda/src/physx/physxD6JointDesc.cxx b/panda/src/physx/physxD6JointDesc.cxx index 29f34dd000..eab55c0f78 100644 --- a/panda/src/physx/physxD6JointDesc.cxx +++ b/panda/src/physx/physxD6JointDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxD6JointDesc.cxx -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (01Octp09) // //////////////////////////////////////////////////////////////////// // @@ -12,447 +12,611 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxD6JointDesc.h" - -#include "luse.h" +#include "physxManager.h" #include "physxJointDriveDesc.h" #include "physxJointLimitSoftDesc.h" -#include "physxJointLimitSoftPairDesc.h" - //////////////////////////////////////////////////////////////////// -// Function : PhysxD6JointDesc -// Access : Published -// Description : +// Function: PhysxD6JointDesc::set_x_motion +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -PhysxD6JointDesc:: -PhysxD6JointDesc() -: PhysxJointDesc( &nD6JointDesc ) { -} +void PhysxD6JointDesc:: +set_x_motion(PhysxD6JointMotion xMotion) { - - -//////////////////////////////////////////////////////////////////// -// Function : get_drive_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxD6JointDesc:: -get_drive_angular_velocity() const { - return PhysxManager::nxVec3_to_lVecBase3(nD6JointDesc.driveAngularVelocity); + _desc.xMotion = (NxD6JointMotion)xMotion; } //////////////////////////////////////////////////////////////////// -// Function : get_drive_linear_velocity -// Access : Published -// Description : +// Function: PhysxD6JointDesc::set_y_motion +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxD6JointDesc:: +void PhysxD6JointDesc:: +set_y_motion(PhysxD6JointMotion yMotion) { + + _desc.yMotion = (NxD6JointMotion)yMotion; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_z_motion +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_z_motion(PhysxD6JointMotion zMotion) { + + _desc.zMotion = (NxD6JointMotion)zMotion; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_swing1_motion +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_swing1_motion(PhysxD6JointMotion swing1Motion) { + + _desc.swing1Motion = (NxD6JointMotion)swing1Motion; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_swing2_motion +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_swing2_motion(PhysxD6JointMotion swing2Motion) { + + _desc.swing2Motion = (NxD6JointMotion)swing2Motion; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_twist_motion +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_twist_motion(PhysxD6JointMotion twistMotion) { + + _desc.twistMotion = (NxD6JointMotion)twistMotion; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_x_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_x_drive(const PhysxJointDriveDesc &drive) { + + _desc.xDrive = drive._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_y_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_y_drive(const PhysxJointDriveDesc &drive) { + + _desc.yDrive = drive._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_z_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_z_drive(const PhysxJointDriveDesc &drive) { + + _desc.zDrive = drive._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_swing_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_swing_drive(const PhysxJointDriveDesc &drive) { + + _desc.swingDrive = drive._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_twist_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_twist_drive(const PhysxJointDriveDesc &drive) { + + _desc.twistDrive = drive._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_slerp_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_slerp_drive(const PhysxJointDriveDesc &drive) { + + _desc.slerpDrive = drive._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_flag +// Access: Published +// Description: Sets or clears a single D6JointFlag flag. +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_flag(PhysxD6JointFlag flag, bool value) { + + if (value == true) { + _desc.flags |= flag; + } + else { + _desc.flags &= ~(flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_linear_limit +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_linear_limit(const PhysxJointLimitSoftDesc &limit) { + + _desc.linearLimit = limit._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_swing1_limit +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_swing1_limit(const PhysxJointLimitSoftDesc &limit) { + + _desc.swing1Limit = limit._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_swing2_limit +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_swing2_limit(const PhysxJointLimitSoftDesc &limit) { + + _desc.swing2Limit = limit._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_twist_limit_low +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_twist_limit_low(const PhysxJointLimitSoftDesc &limit) { + + _desc.twistLimit.low = limit._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_twist_limit_high +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_twist_limit_high(const PhysxJointLimitSoftDesc &limit) { + + _desc.twistLimit.high = limit._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_projection_distance +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_projection_distance(float distance) { + + _desc.projectionDistance = distance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_projection_angle +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_projection_angle(float angle) { + + _desc.projectionAngle = angle; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_gear_ratio +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_gear_ratio(float ratio) { + + _desc.gearRatio = ratio; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_drive_position +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_drive_position(const LPoint3f &pos) { + + nassertv(!pos.is_nan()); + _desc.drivePosition = PhysxManager::point3_to_nxVec3(pos); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_drive_linear_velocity +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_drive_linear_velocity(const LVector3f &v) { + + nassertv(!v.is_nan()); + _desc.driveLinearVelocity = PhysxManager::vec3_to_nxVec3(v); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_drive_angular_velocity +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_drive_angular_velocity(const LVector3f &v) { + + nassertv(!v.is_nan()); + _desc.driveAngularVelocity = PhysxManager::vec3_to_nxVec3(v); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_drive_orientation +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_drive_orientation(const LQuaternionf &quat) { + + _desc.driveOrientation = PhysxManager::quat_to_nxQuat(quat); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::set_projection_mode +// Access: Published +// Description: Use this to enable joint projection. +// Default is PM_none. +//////////////////////////////////////////////////////////////////// +void PhysxD6JointDesc:: +set_projection_mode(PhysxProjectionMode mode) { + + _desc.projectionMode = (NxJointProjectionMode)mode; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_x_motion +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxD6JointMotion PhysxD6JointDesc:: +get_x_motion() const { + + return (PhysxD6JointMotion)_desc.xMotion; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_y_motion +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxD6JointMotion PhysxD6JointDesc:: +get_y_motion() const { + + return (PhysxD6JointMotion)_desc.yMotion; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_z_motion +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxD6JointMotion PhysxD6JointDesc:: +get_z_motion() const { + + return (PhysxD6JointMotion)_desc.zMotion; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_swing1_motion +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxD6JointMotion PhysxD6JointDesc:: +get_swing1_motion() const { + + return (PhysxD6JointMotion)_desc.swing1Motion; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_swing2_motion +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxD6JointMotion PhysxD6JointDesc:: +get_swing2_motion() const { + + return (PhysxD6JointMotion)_desc.swing2Motion; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_twist_motion +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxD6JointMotion PhysxD6JointDesc:: +get_twist_motion() const { + + return (PhysxD6JointMotion)_desc.twistMotion; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_x_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointDriveDesc PhysxD6JointDesc:: +get_x_drive() const { + + PhysxJointDriveDesc value; + value._desc = _desc.xDrive; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_y_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointDriveDesc PhysxD6JointDesc:: +get_y_drive() const { + + PhysxJointDriveDesc value; + value._desc = _desc.yDrive; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_z_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointDriveDesc PhysxD6JointDesc:: +get_z_drive() const { + + PhysxJointDriveDesc value; + value._desc = _desc.zDrive; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_swing_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointDriveDesc PhysxD6JointDesc:: +get_swing_drive() const { + + PhysxJointDriveDesc value; + value._desc = _desc.swingDrive; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_twist_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointDriveDesc PhysxD6JointDesc:: +get_twist_drive() const { + + PhysxJointDriveDesc value; + value._desc = _desc.twistDrive; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_slerp_drive +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointDriveDesc PhysxD6JointDesc:: +get_slerp_drive() const { + + PhysxJointDriveDesc value; + value._desc = _desc.slerpDrive; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_flag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxD6JointDesc:: +get_flag(PhysxD6JointFlag flag) const { + + return (_desc.flags & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_linear_limit +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointLimitSoftDesc PhysxD6JointDesc:: +get_linear_limit() const { + + PhysxJointLimitSoftDesc value; + value._desc = _desc.linearLimit; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_swing1_limit +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointLimitSoftDesc PhysxD6JointDesc:: +get_swing1_limit() const { + + PhysxJointLimitSoftDesc value; + value._desc = _desc.swing1Limit; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_swing2_limit +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointLimitSoftDesc PhysxD6JointDesc:: +get_swing2_limit() const { + + PhysxJointLimitSoftDesc value; + value._desc = _desc.swing2Limit; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_twist_limit_low +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointLimitSoftDesc PhysxD6JointDesc:: +get_twist_limit_low() const { + + PhysxJointLimitSoftDesc value; + value._desc = _desc.twistLimit.low; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_twist_limit_high +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointLimitSoftDesc PhysxD6JointDesc:: +get_twist_limit_high() const { + + PhysxJointLimitSoftDesc value; + value._desc = _desc.twistLimit.high; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_projection_distance +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxD6JointDesc:: +get_projection_distance() const { + + return _desc.projectionDistance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_projection_angle +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxD6JointDesc:: +get_projection_angle() const { + + return _desc.projectionAngle; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_gear_ratio +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxD6JointDesc:: +get_gear_ratio() const { + + return _desc.gearRatio; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_drive_position +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxD6JointDesc:: +get_drive_position() const { + + return PhysxManager::nxVec3_to_point3(_desc.drivePosition); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_drive_linear_velocity +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LVector3f PhysxD6JointDesc:: get_drive_linear_velocity() const { - return PhysxManager::nxVec3_to_lVecBase3(nD6JointDesc.driveLinearVelocity); + + return PhysxManager::nxVec3_to_vec3(_desc.driveLinearVelocity); } //////////////////////////////////////////////////////////////////// -// Function : get_drive_orientation -// Access : Published -// Description : +// Function: PhysxD6JointDesc::get_drive_angular_velocity +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LVector3f PhysxD6JointDesc:: +get_drive_angular_velocity() const { + + return PhysxManager::nxVec3_to_vec3(_desc.driveAngularVelocity); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxD6JointDesc::get_drive_orientation +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// LQuaternionf PhysxD6JointDesc:: get_drive_orientation() const { - return PhysxManager::nxQuat_to_lQuaternion(nD6JointDesc.driveOrientation); + + return PhysxManager::nxQuat_to_quat(_desc.driveOrientation); } //////////////////////////////////////////////////////////////////// -// Function : get_drive_position -// Access : Published -// Description : +// Function: PhysxD6JointDesc::get_projection_mode +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxD6JointDesc:: -get_drive_position() const { - return PhysxManager::nxVec3_to_lVecBase3(nD6JointDesc.drivePosition); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_linear_limit -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointLimitSoftDesc & PhysxD6JointDesc:: -get_linear_limit() const { - throw "Not Implemented"; // return nD6JointDesc.linearLimit; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_projection_mode -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointProjectionMode PhysxD6JointDesc:: +PhysxEnums::PhysxProjectionMode PhysxD6JointDesc:: get_projection_mode() const { - return (PhysxJointProjectionMode)nD6JointDesc.projectionMode; + + return (PhysxProjectionMode)_desc.projectionMode; } -//////////////////////////////////////////////////////////////////// -// Function : get_slerp_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointDriveDesc & PhysxD6JointDesc:: -get_slerp_drive() const { - throw "Not Implemented"; // return nD6JointDesc.slerpDrive; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_swing1_limit -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointLimitSoftDesc & PhysxD6JointDesc:: -get_swing1_limit() const { - throw "Not Implemented"; // return nD6JointDesc.swing1Limit; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_swing1_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxD6JointMotion PhysxD6JointDesc:: -get_swing1_motion() const { - return (PhysxD6JointMotion)nD6JointDesc.swing1Motion; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_swing2_limit -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointLimitSoftDesc & PhysxD6JointDesc:: -get_swing2_limit() const { - throw "Not Implemented"; // return nD6JointDesc.swing2Limit; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_swing2_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxD6JointMotion PhysxD6JointDesc:: -get_swing2_motion() const { - return (PhysxD6JointMotion)nD6JointDesc.swing2Motion; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_swing_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointDriveDesc & PhysxD6JointDesc:: -get_swing_drive() const { - throw "Not Implemented"; // return nD6JointDesc.swingDrive; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_twist_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointDriveDesc & PhysxD6JointDesc:: -get_twist_drive() const { - throw "Not Implemented"; // return nD6JointDesc.twistDrive; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_twist_limit -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointLimitSoftPairDesc & PhysxD6JointDesc:: -get_twist_limit() const { - throw "Not Implemented"; // return nD6JointDesc.twistLimit; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_twist_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxD6JointMotion PhysxD6JointDesc:: -get_twist_motion() const { - return (PhysxD6JointMotion)nD6JointDesc.twistMotion; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_x_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointDriveDesc & PhysxD6JointDesc:: -get_x_drive() const { - throw "Not Implemented"; // return nD6JointDesc.xDrive; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_x_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxD6JointMotion PhysxD6JointDesc:: -get_x_motion() const { - return (PhysxD6JointMotion)nD6JointDesc.xMotion; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_y_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointDriveDesc & PhysxD6JointDesc:: -get_y_drive() const { - throw "Not Implemented"; // return nD6JointDesc.yDrive; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_y_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxD6JointMotion PhysxD6JointDesc:: -get_y_motion() const { - return (PhysxD6JointMotion)nD6JointDesc.yMotion; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_z_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointDriveDesc & PhysxD6JointDesc:: -get_z_drive() const { - throw "Not Implemented"; // return nD6JointDesc.zDrive; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_z_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxD6JointMotion PhysxD6JointDesc:: -get_z_motion() const { - return (PhysxD6JointMotion)nD6JointDesc.zMotion; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_drive_angular_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_drive_angular_velocity(LVecBase3f value) { - nD6JointDesc.driveAngularVelocity = PhysxManager::lVecBase3_to_nxVec3(value); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_drive_linear_velocity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_drive_linear_velocity(LVecBase3f value) { - nD6JointDesc.driveLinearVelocity = PhysxManager::lVecBase3_to_nxVec3(value); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_drive_orientation -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_drive_orientation(LQuaternionf value) { - nD6JointDesc.driveOrientation = PhysxManager::lQuaternion_to_nxQuat(value); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_drive_position -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_drive_position(LVecBase3f value) { - nD6JointDesc.drivePosition = PhysxManager::lVecBase3_to_nxVec3(value); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_linear_limit -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_linear_limit(PhysxJointLimitSoftDesc & value) { - nD6JointDesc.linearLimit = value.nJointLimitSoftDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_projection_mode -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_projection_mode(PhysxJointProjectionMode value) { - nD6JointDesc.projectionMode = (NxJointProjectionMode)value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_slerp_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_slerp_drive(PhysxJointDriveDesc & value) { - nD6JointDesc.slerpDrive = value.nJointDriveDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_swing1_limit -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_swing1_limit(PhysxJointLimitSoftDesc & value) { - nD6JointDesc.swing1Limit = value.nJointLimitSoftDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_swing1_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_swing1_motion(PhysxD6JointMotion value) { - nD6JointDesc.swing1Motion = (NxD6JointMotion)value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_swing2_limit -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_swing2_limit(PhysxJointLimitSoftDesc & value) { - nD6JointDesc.swing2Limit = value.nJointLimitSoftDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_swing2_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_swing2_motion(PhysxD6JointMotion value) { - nD6JointDesc.swing2Motion = (NxD6JointMotion)value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_swing_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_swing_drive(PhysxJointDriveDesc & value) { - nD6JointDesc.swingDrive = value.nJointDriveDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_twist_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_twist_drive(PhysxJointDriveDesc & value) { - nD6JointDesc.twistDrive = value.nJointDriveDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_twist_limit -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_twist_limit(PhysxJointLimitSoftPairDesc & value) { - nD6JointDesc.twistLimit = value.nJointLimitSoftPairDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_twist_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_twist_motion(PhysxD6JointMotion value) { - nD6JointDesc.twistMotion = (NxD6JointMotion)value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_x_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_x_drive(PhysxJointDriveDesc & value) { - nD6JointDesc.xDrive = value.nJointDriveDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_x_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_x_motion(PhysxD6JointMotion value) { - nD6JointDesc.xMotion = (NxD6JointMotion)value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_y_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_y_drive(PhysxJointDriveDesc & value) { - nD6JointDesc.yDrive = value.nJointDriveDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_y_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_y_motion(PhysxD6JointMotion value) { - nD6JointDesc.yMotion = (NxD6JointMotion)value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_z_drive -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_z_drive(PhysxJointDriveDesc & value) { - nD6JointDesc.zDrive = value.nJointDriveDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_z_motion -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxD6JointDesc:: -set_z_motion(PhysxD6JointMotion value) { - nD6JointDesc.zMotion = (NxD6JointMotion)value; -} - -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxD6JointDesc.h b/panda/src/physx/physxD6JointDesc.h index 0199131cda..c448cb2fba 100644 --- a/panda/src/physx/physxD6JointDesc.h +++ b/panda/src/physx/physxD6JointDesc.h @@ -1,5 +1,5 @@ // Filename: physxD6JointDesc.h -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (01Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,91 +15,91 @@ #ifndef PHYSXD6JOINTDESC_H #define PHYSXD6JOINTDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "lvector3.h" +#include "lpoint3.h" +#include "lquaternion.h" #include "physxJointDesc.h" +#include "NoMinMax.h" +#include "NxPhysics.h" + class PhysxJointDriveDesc; class PhysxJointLimitSoftDesc; -class PhysxJointLimitSoftPairDesc; - -#include "NxPhysics.h" //////////////////////////////////////////////////////////////////// // Class : PhysxD6JointDesc -// Description : +// Description : //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxD6JointDesc : public PhysxJointDesc { + PUBLISHED: - PhysxD6JointDesc(); + INLINE PhysxD6JointDesc(); + INLINE ~PhysxD6JointDesc(); - INLINE bool is_valid() const; INLINE void set_to_default(); + INLINE bool is_valid() const; - LVecBase3f get_drive_angular_velocity() const; - LVecBase3f get_drive_linear_velocity() const; + void set_flag(PhysxD6JointFlag flag, bool value); + void set_projection_distance(float distance); + void set_projection_angle(float angle); + void set_gear_ratio(float ratio); + void set_drive_position(const LPoint3f &pos); + void set_drive_linear_velocity(const LVector3f &v); + void set_drive_angular_velocity(const LVector3f &v); + void set_drive_orientation(const LQuaternionf &quat); + void set_projection_mode(PhysxProjectionMode mode); + void set_x_motion(PhysxD6JointMotion xMotion); + void set_y_motion(PhysxD6JointMotion yMotion); + void set_z_motion(PhysxD6JointMotion zMotion); + void set_swing1_motion(PhysxD6JointMotion xMotion); + void set_swing2_motion(PhysxD6JointMotion yMotion); + void set_twist_motion(PhysxD6JointMotion zMotion); + void set_x_drive(const PhysxJointDriveDesc &drive); + void set_y_drive(const PhysxJointDriveDesc &drive); + void set_z_drive(const PhysxJointDriveDesc &drive); + void set_swing_drive(const PhysxJointDriveDesc &drive); + void set_twist_drive(const PhysxJointDriveDesc &drive); + void set_slerp_drive(const PhysxJointDriveDesc &drive); + void set_linear_limit(const PhysxJointLimitSoftDesc &limit); + void set_swing1_limit(const PhysxJointLimitSoftDesc &limit); + void set_swing2_limit(const PhysxJointLimitSoftDesc &limit); + void set_twist_limit_low(const PhysxJointLimitSoftDesc &limit); + void set_twist_limit_high(const PhysxJointLimitSoftDesc &limit); + + bool get_flag(PhysxD6JointFlag flag) const; + float get_projection_distance() const; + float get_projection_angle() const; + float get_gear_ratio() const; + LPoint3f get_drive_position() const; + LVector3f get_drive_linear_velocity() const; + LVector3f get_drive_angular_velocity() const; LQuaternionf get_drive_orientation() const; - LVecBase3f get_drive_position() const; - INLINE unsigned int get_flags() const; - INLINE float get_gear_ratio() const; - PhysxJointLimitSoftDesc & get_linear_limit() const; - INLINE float get_projection_angle() const; - INLINE float get_projection_distance() const; - PhysxJointProjectionMode get_projection_mode() const; - PhysxJointDriveDesc & get_slerp_drive() const; - PhysxJointLimitSoftDesc & get_swing1_limit() const; - PhysxD6JointMotion get_swing1_motion() const; - PhysxJointLimitSoftDesc & get_swing2_limit() const; - PhysxD6JointMotion get_swing2_motion() const; - PhysxJointDriveDesc & get_swing_drive() const; - PhysxJointDriveDesc & get_twist_drive() const; - PhysxJointLimitSoftPairDesc & get_twist_limit() const; - PhysxD6JointMotion get_twist_motion() const; - PhysxJointDriveDesc & get_x_drive() const; + PhysxProjectionMode get_projection_mode() const; PhysxD6JointMotion get_x_motion() const; - PhysxJointDriveDesc & get_y_drive() const; PhysxD6JointMotion get_y_motion() const; - PhysxJointDriveDesc & get_z_drive() const; PhysxD6JointMotion get_z_motion() const; - - void set_drive_angular_velocity( LVecBase3f value ); - void set_drive_linear_velocity( LVecBase3f value ); - void set_drive_orientation( LQuaternionf value ); - void set_drive_position( LVecBase3f value ); - INLINE void set_flags( unsigned int value ); - INLINE void set_gear_ratio( float value ); - void set_linear_limit( PhysxJointLimitSoftDesc & value ); - INLINE void set_projection_angle( float value ); - INLINE void set_projection_distance( float value ); - void set_projection_mode( PhysxJointProjectionMode value ); - void set_slerp_drive( PhysxJointDriveDesc & value ); - void set_swing1_limit( PhysxJointLimitSoftDesc & value ); - void set_swing1_motion( PhysxD6JointMotion value ); - void set_swing2_limit( PhysxJointLimitSoftDesc & value ); - void set_swing2_motion( PhysxD6JointMotion value ); - void set_swing_drive( PhysxJointDriveDesc & value ); - void set_twist_drive( PhysxJointDriveDesc & value ); - void set_twist_limit( PhysxJointLimitSoftPairDesc & value ); - void set_twist_motion( PhysxD6JointMotion value ); - void set_x_drive( PhysxJointDriveDesc & value ); - void set_x_motion( PhysxD6JointMotion value ); - void set_y_drive( PhysxJointDriveDesc & value ); - void set_y_motion( PhysxD6JointMotion value ); - void set_z_drive( PhysxJointDriveDesc & value ); - void set_z_motion( PhysxD6JointMotion value ); + PhysxD6JointMotion get_swing1_motion() const; + PhysxD6JointMotion get_swing2_motion() const; + PhysxD6JointMotion get_twist_motion() const; + PhysxJointDriveDesc get_x_drive() const; + PhysxJointDriveDesc get_y_drive() const; + PhysxJointDriveDesc get_z_drive() const; + PhysxJointDriveDesc get_swing_drive() const; + PhysxJointDriveDesc get_twist_drive() const; + PhysxJointDriveDesc get_slerp_drive() const; + PhysxJointLimitSoftDesc get_linear_limit() const; + PhysxJointLimitSoftDesc get_swing1_limit() const; + PhysxJointLimitSoftDesc get_swing2_limit() const; + PhysxJointLimitSoftDesc get_twist_limit_low() const; + PhysxJointLimitSoftDesc get_twist_limit_high() const; public: - NxD6JointDesc nD6JointDesc; + NxJointDesc *ptr() const { return (NxJointDesc *)&_desc; }; + NxD6JointDesc _desc; }; #include "physxD6JointDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXD6JOINTDESC_H diff --git a/panda/src/physx/physxDebugGeomNode.I b/panda/src/physx/physxDebugGeomNode.I new file mode 100644 index 0000000000..ac6b9f5804 --- /dev/null +++ b/panda/src/physx/physxDebugGeomNode.I @@ -0,0 +1,389 @@ +// Filename: physxDebugGeomNode.I +// Created by: enn0x (15Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxDebugGeomNode:: +PhysxDebugGeomNode() : GeomNode("debug") { + + _scale = 1.0f; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxDebugGeomNode:: +~PhysxDebugGeomNode() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_world_axes +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_world_axes(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_WORLD_AXES, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_body_axes +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_body_axes(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_BODY_AXES, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_body_mass_axes +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_body_mass_axes(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_BODY_MASS_AXES, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_body_lin_velocity +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_body_lin_velocity(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_BODY_LIN_VELOCITY, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_body_ang_velocity +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_body_ang_velocity(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_BODY_ANG_VELOCITY, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_body_joint_groups +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_body_joint_groups(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_BODY_JOINT_GROUPS, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_joint_local_axes +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_joint_local_axes(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_JOINT_LOCAL_AXES, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_joint_world_axes +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_joint_world_axes(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_JOINT_WORLD_AXES, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_joint_limits +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_joint_limits(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_JOINT_LIMITS, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_contact_point +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_contact_point(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_CONTACT_POINT, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_contact_normal +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_contact_normal(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_CONTACT_NORMAL, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_contact_error +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_contact_error(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_CONTACT_ERROR, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_contact_force +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_contact_force(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_CONTACT_FORCE, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_actor_axes +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_actor_axes(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_ACTOR_AXES, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_aabbs +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_aabbs(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_AABBS, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_shapes +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_shapes(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_SHAPES, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_axes +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_axes(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_AXES, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_compounds +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_compounds(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_COMPOUNDS, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_vnormals +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_vnormals(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_VNORMALS, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_fnormals +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_fnormals(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_FNORMALS, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_edges +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_edges(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_EDGES, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_spheres +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_spheres(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_SPHERES, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_static +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_static(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_STATIC, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_dynamic +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_dynamic(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_DYNAMIC, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_free +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_free(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_FREE, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_ccd +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_ccd(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_CCD, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_collision_skeletons +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_collision_skeletons(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_COLLISION_SKELETONS, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_cloth_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_cloth_mesh(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_CLOTH_MESH, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_cloth_validbounds +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_cloth_validbounds(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_CLOTH_VALIDBOUNDS, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_softbody_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_softbody_mesh(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_SOFTBODY_MESH, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_softbody_validbounds +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_softbody_validbounds(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_SOFTBODY_VALIDBOUNDS, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::visualize_force_fields +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDebugGeomNode:: +visualize_force_fields(bool value) { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZE_FORCE_FIELDS, value); +} + diff --git a/panda/src/physx/physxDebugGeomNode.cxx b/panda/src/physx/physxDebugGeomNode.cxx new file mode 100644 index 0000000000..7fada006ed --- /dev/null +++ b/panda/src/physx/physxDebugGeomNode.cxx @@ -0,0 +1,102 @@ +// Filename: physxDebugGeomNode.cxx +// Created by: enn0x (15Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxDebugGeomNode.h" + +TypeHandle PhysxDebugGeomNode::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::update +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxDebugGeomNode:: +update(NxScene *scenePtr) { + + if (get_num_parents() == 0) { + return; + } + + const NxDebugRenderable *renderable = scenePtr->getDebugRenderable(); + if (!renderable) { + remove_all_geoms(); + physx_cat.warning() << "Could no get debug renderable." << endl; + return; + } + + const NxDebugLine *lines = renderable->getLines(); + NxU32 n = renderable->getNbLines(); + + _segs.reset(); + + for (NxU32 i=0; i>8)&0xff) / 255.0f; + NxF32 r = NxF32((lines[i].color>>16)&0xff) / 255.0f; + + NxVec3 p0 = lines[i].p0; + NxVec3 p1 = lines[i].p1; + + _segs.set_color(r, g, b); + _segs.move_to(p0.x, p0.y, p0.z); + _segs.draw_to(p1.x, p1.y, p1.z); + } + + GeomNode *node = _segs.create(); + remove_all_geoms(); + add_geoms_from(node); + delete node; + + physx_cat.spam() << "Updated PhysxDebugGeomNode geometry (" << n << " lines)\n"; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::on +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxDebugGeomNode:: +on() { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZATION_SCALE, _scale); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::off +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxDebugGeomNode:: +off() { + + NxGetPhysicsSDK()->setParameter(NX_VISUALIZATION_SCALE, 0.0f); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDebugGeomNode::toggle +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxDebugGeomNode:: +toggle() { + + if (NxGetPhysicsSDK()->getParameter(NX_VISUALIZATION_SCALE) == 0.0f) { + on(); + } + else { + off(); + } +} + diff --git a/panda/src/physx/physxDebugGeomNode.h b/panda/src/physx/physxDebugGeomNode.h new file mode 100644 index 0000000000..23e29bae5a --- /dev/null +++ b/panda/src/physx/physxDebugGeomNode.h @@ -0,0 +1,109 @@ +// Filename: physxDebugGeomNode.h +// Created by: enn0x (15Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXDEBUGGEOMNODE_H +#define PHYSXDEBUGGEOMNODE_H + +#include "pandabase.h" +#include "pointerTo.h" +#include "geomNode.h" +#include "transformState.h" +#include "lineSegs.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxScene; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxDebugGeomNode +// Description : Renderable geometry which represents visualizations +// of physics objects. Intended to help with +// debugging code. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxDebugGeomNode : public GeomNode { + +PUBLISHED: + INLINE PhysxDebugGeomNode(); + INLINE ~PhysxDebugGeomNode(); + + void on(); + void off(); + void toggle(); + + INLINE void visualize_world_axes(bool value); + INLINE void visualize_body_axes(bool value); + INLINE void visualize_body_mass_axes(bool value); + INLINE void visualize_body_lin_velocity(bool value); + INLINE void visualize_body_ang_velocity(bool value); + INLINE void visualize_body_joint_groups(bool value); + INLINE void visualize_joint_local_axes(bool value); + INLINE void visualize_joint_world_axes(bool value); + INLINE void visualize_joint_limits(bool value); + INLINE void visualize_contact_point(bool value); + INLINE void visualize_contact_normal(bool value); + INLINE void visualize_contact_error(bool value); + INLINE void visualize_contact_force(bool value); + INLINE void visualize_actor_axes(bool value); + INLINE void visualize_collision_aabbs(bool value); + INLINE void visualize_collision_shapes(bool value); + INLINE void visualize_collision_axes(bool value); + INLINE void visualize_collision_compounds(bool value); + INLINE void visualize_collision_vnormals(bool value); + INLINE void visualize_collision_fnormals(bool value); + INLINE void visualize_collision_edges(bool value); + INLINE void visualize_collision_spheres(bool value); + INLINE void visualize_collision_static(bool value); + INLINE void visualize_collision_dynamic(bool value); + INLINE void visualize_collision_free(bool value); + INLINE void visualize_collision_ccd(bool value); + INLINE void visualize_collision_skeletons(bool value); + INLINE void visualize_cloth_mesh(bool value); + INLINE void visualize_cloth_validbounds(bool value); + INLINE void visualize_softbody_mesh(bool value); + INLINE void visualize_softbody_validbounds(bool value); + INLINE void visualize_force_fields(bool value); + +public: + void update(NxScene *scenePtr); + +private: + LineSegs _segs; + float _scale; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + GeomNode::init_type(); + register_type(_type_handle, "PhysxDebugGeomNode", + GeomNode::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxDebugGeomNode.I" + +#endif // PHYSXDEBUGGEOMNODE_H diff --git a/panda/src/physx/physxDistanceJoint.I b/panda/src/physx/physxDistanceJoint.I new file mode 100644 index 0000000000..05e07a807f --- /dev/null +++ b/panda/src/physx/physxDistanceJoint.I @@ -0,0 +1,36 @@ +// Filename: physxDistanceJoint.I +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJoint::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxDistanceJoint:: +PhysxDistanceJoint() : PhysxJoint() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJoint::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxDistanceJoint:: +~PhysxDistanceJoint() { + +} + diff --git a/panda/src/physx/physxDistanceJoint.cxx b/panda/src/physx/physxDistanceJoint.cxx new file mode 100644 index 0000000000..ae868038e9 --- /dev/null +++ b/panda/src/physx/physxDistanceJoint.cxx @@ -0,0 +1,76 @@ +// Filename: physxDistanceJoint.cxx +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxDistanceJoint.h" +#include "physxDistanceJointDesc.h" + +TypeHandle PhysxDistanceJoint::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJoint::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxDistanceJoint:: +link(NxJoint *jointPtr) { + + _ptr = jointPtr->isDistanceJoint(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJoint::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxDistanceJoint:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxDistanceJoint::save_to_desc +// Access : Published +// Description : Saves the state of the joint object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxDistanceJoint:: +save_to_desc(PhysxDistanceJointDesc &jointDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxDistanceJoint::load_from_desc +// Access : Published +// Description : Loads the entire state of the joint from a +// descriptor with a single call. +//////////////////////////////////////////////////////////////////// +void PhysxDistanceJoint:: +load_from_desc(const PhysxDistanceJointDesc &jointDesc) { + + nassertv(_error_type == ET_ok); + _ptr->loadFromDesc(jointDesc._desc); +} + diff --git a/panda/src/physx/physxDistanceJoint.h b/panda/src/physx/physxDistanceJoint.h new file mode 100644 index 0000000000..fc9de58b51 --- /dev/null +++ b/panda/src/physx/physxDistanceJoint.h @@ -0,0 +1,75 @@ +// Filename: physxDistanceJoint.h +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXDISTANCEJOINT_H +#define PHYSXDISTANCEJOINT_H + +#include "pandabase.h" + +#include "physxJoint.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxDistanceJointDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxDistanceJoint +// Description : A distance joint maintains a certain distance +// between two points on two actors. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxDistanceJoint : public PhysxJoint { + +PUBLISHED: + INLINE PhysxDistanceJoint(); + INLINE ~PhysxDistanceJoint(); + + void save_to_desc(PhysxDistanceJointDesc &jointDesc) const; + void load_from_desc(const PhysxDistanceJointDesc &jointDesc); + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxJoint *ptr() const { return (NxJoint *)_ptr; }; + + void link(NxJoint *jointPtr); + void unlink(); + +private: + NxDistanceJoint *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxJoint::init_type(); + register_type(_type_handle, "PhysxDistanceJoint", + PhysxJoint::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxDistanceJoint.I" + +#endif // PHYSXDISTANCEJOINT_H diff --git a/panda/src/physx/physxDistanceJointDesc.I b/panda/src/physx/physxDistanceJointDesc.I new file mode 100644 index 0000000000..6df3d51425 --- /dev/null +++ b/panda/src/physx/physxDistanceJointDesc.I @@ -0,0 +1,59 @@ +// Filename: physxDistanceJointDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxDistanceJointDesc:: +PhysxDistanceJointDesc() : PhysxJointDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxDistanceJointDesc:: +~PhysxDistanceJointDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxDistanceJointDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxDistanceJointDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxDistanceJointDesc.cxx b/panda/src/physx/physxDistanceJointDesc.cxx new file mode 100644 index 0000000000..eb7e885b66 --- /dev/null +++ b/panda/src/physx/physxDistanceJointDesc.cxx @@ -0,0 +1,115 @@ +// Filename: physxDistanceJointDesc.cxx +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxDistanceJointDesc.h" +#include "physxSpringDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::set_max_distance +// Access: Published +// Description: Sets the maximum rest length of the rope or rod +// between the two anchor points. +//////////////////////////////////////////////////////////////////// +void PhysxDistanceJointDesc:: +set_max_distance(float distance) { + + _desc.maxDistance = distance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::set_min_distance +// Access: Published +// Description: Sets the minimum rest length of the rope or rod +// between the two anchor points +//////////////////////////////////////////////////////////////////// +void PhysxDistanceJointDesc:: +set_min_distance(float distance) { + + _desc.minDistance = distance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::set_spring +// Access: Published +// Description: Makes the joint springy. The spring.targetValue +// is not used. +//////////////////////////////////////////////////////////////////// +void PhysxDistanceJointDesc:: +set_spring(const PhysxSpringDesc &spring) { + + _desc.spring = spring._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::set_flag +// Access: Published +// Description: Sets or clears a single DistanceJointFlag flag. +//////////////////////////////////////////////////////////////////// +void PhysxDistanceJointDesc:: +set_flag(PhysxDistanceJointFlag flag, bool value) { + + if (value == true) { + _desc.flags |= flag; + } + else { + _desc.flags &= ~(flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::get_max_distance +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxDistanceJointDesc:: +get_max_distance() const { + + return _desc.maxDistance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::get_min_distance +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxDistanceJointDesc:: +get_min_distance() const { + + return _desc.minDistance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::get_spring +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxSpringDesc PhysxDistanceJointDesc:: +get_spring() const { + + PhysxSpringDesc value; + value._desc = _desc.spring; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxDistanceJointDesc::get_flag +// Access: Published +// Description: Return a single DistanceJointFlag flag. +//////////////////////////////////////////////////////////////////// +bool PhysxDistanceJointDesc:: +get_flag(PhysxDistanceJointFlag flag) const { + + return (_desc.flags & flag) ? true : false; +} + diff --git a/panda/src/physx/physxDistanceJointDesc.h b/panda/src/physx/physxDistanceJointDesc.h new file mode 100644 index 0000000000..10d577718c --- /dev/null +++ b/panda/src/physx/physxDistanceJointDesc.h @@ -0,0 +1,58 @@ +// Filename: physxDistanceJointDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXDISTANCEJOINTDESC_H +#define PHYSXDISTANCEJOINTDESC_H + +#include "pandabase.h" + +#include "physxJointDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxSpringDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxDistanceJointDesc +// Description : Descriptor class for distance joint. See +// PhysxDistanceJoint. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxDistanceJointDesc : public PhysxJointDesc { + +PUBLISHED: + INLINE PhysxDistanceJointDesc(); + INLINE ~PhysxDistanceJointDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_max_distance(float distance); + void set_min_distance(float distance); + void set_spring(const PhysxSpringDesc &spring); + void set_flag(PhysxDistanceJointFlag flag, bool value); + + float get_max_distance() const; + float get_min_distance() const; + bool get_flag(PhysxDistanceJointFlag flag) const; + PhysxSpringDesc get_spring() const; + +public: + NxJointDesc *ptr() const { return (NxJointDesc *)&_desc; }; + NxDistanceJointDesc _desc; +}; + +#include "physxDistanceJointDesc.I" + +#endif // PHYSXDISTANCEJOINTDESC_H diff --git a/panda/src/physx/physxEnums.cxx b/panda/src/physx/physxEnums.cxx new file mode 100644 index 0000000000..b4cb8332dd --- /dev/null +++ b/panda/src/physx/physxEnums.cxx @@ -0,0 +1,60 @@ +// Filename: physxEnums.cxx +// Created by: enn0x (23Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxEnums.h" + +#include "string_utils.h" +#include "config_util.h" + +ostream & +operator << (ostream &out, PhysxEnums::PhysxUpAxis axis) { + + switch (axis) { + case PhysxEnums::X_up: + return out << "x"; + + case PhysxEnums::Y_up: + return out << "y"; + + case PhysxEnums::Z_up: + return out << "z"; + } + + return out << "**invalid PhysxEnums::PhysxUpAxis value: (" << (int)axis << ")**"; +} + +istream & +operator >> (istream &in, PhysxEnums::PhysxUpAxis &axis) { + + string word; + in >> word; + + if (cmp_nocase(word, "x") == 0) { + axis = PhysxEnums::X_up; + } + else if (cmp_nocase(word, "y") == 0) { + axis = PhysxEnums::Y_up; + } + else if (cmp_nocase(word, "z") == 0) { + axis = PhysxEnums::Z_up; + } + else { + physx_cat->error() + << "Invalid up-axis string: " << word << "\n"; + axis = PhysxEnums::Z_up; + } + + return in; +} + diff --git a/panda/src/physx/physxEnums.h b/panda/src/physx/physxEnums.h new file mode 100644 index 0000000000..08278cea99 --- /dev/null +++ b/panda/src/physx/physxEnums.h @@ -0,0 +1,623 @@ +// Filename: physxEnums.h +// Created by: enn0x (23Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXENUMS_H +#define PHYSXENUMS_H + +#include "pandabase.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +#ifdef CPPPARSER + +// PhysxParameter +#define NX_PENALTY_FORCE 0 +#define NX_SKIN_WIDTH 1 +#define NX_DEFAULT_SLEEP_LIN_VEL_SQUARED 2 +#define NX_DEFAULT_SLEEP_ANG_VEL_SQUARED 3 +#define NX_BOUNCE_THRESHOLD 4 +#define NX_DYN_FRICT_SCALING 5 +#define NX_STA_FRICT_SCALING 6 +#define NX_MAX_ANGULAR_VELOCITY 7 +#define NX_CONTINUOUS_CD 8 +#define NX_VISUALIZATION_SCALE 9 +#define NX_VISUALIZE_WORLD_AXES 10 +#define NX_VISUALIZE_BODY_AXES 11 +#define NX_VISUALIZE_BODY_MASS_AXES 12 +#define NX_VISUALIZE_BODY_LIN_VELOCITY 13 +#define NX_VISUALIZE_BODY_ANG_VELOCITY 14 +#define NX_VISUALIZE_BODY_JOINT_GROUPS 22 +#define NX_VISUALIZE_JOINT_LOCAL_AXES 27 +#define NX_VISUALIZE_JOINT_WORLD_AXES 28 +#define NX_VISUALIZE_JOINT_LIMITS 29 +#define NX_VISUALIZE_CONTACT_POINT 33 +#define NX_VISUALIZE_CONTACT_NORMAL 34 +#define NX_VISUALIZE_CONTACT_ERROR 35 +#define NX_VISUALIZE_CONTACT_FORCE 36 +#define NX_VISUALIZE_ACTOR_AXES 37 +#define NX_VISUALIZE_COLLISION_AABBS 38 +#define NX_VISUALIZE_COLLISION_SHAPES 39 +#define NX_VISUALIZE_COLLISION_AXES 40 +#define NX_VISUALIZE_COLLISION_COMPOUNDS 41 +#define NX_VISUALIZE_COLLISION_VNORMALS 42 +#define NX_VISUALIZE_COLLISION_FNORMALS 43 +#define NX_VISUALIZE_COLLISION_EDGES 44 +#define NX_VISUALIZE_COLLISION_SPHERES 45 +#define NX_VISUALIZE_COLLISION_STATIC 47 +#define NX_VISUALIZE_COLLISION_DYNAMIC 48 +#define NX_VISUALIZE_COLLISION_FREE 49 +#define NX_VISUALIZE_COLLISION_CCD 50 +#define NX_VISUALIZE_COLLISION_SKELETONS 51 +#define NX_VISUALIZE_FLUID_EMITTERS 52 +#define NX_VISUALIZE_FLUID_POSITION 53 +#define NX_VISUALIZE_FLUID_VELOCITY 54 +#define NX_VISUALIZE_FLUID_KERNEL_RADIUS 55 +#define NX_VISUALIZE_FLUID_BOUNDS 56 +#define NX_VISUALIZE_FLUID_PACKETS 57 +#define NX_VISUALIZE_FLUID_MOTION_LIMIT 58 +#define NX_VISUALIZE_FLUID_DYN_COLLISION 59 +#define NX_VISUALIZE_FLUID_STC_COLLISION 60 +#define NX_VISUALIZE_FLUID_MESH_PACKETS 61 +#define NX_VISUALIZE_FLUID_DRAINS 62 +#define NX_VISUALIZE_FLUID_PACKET_DATA 90 +#define NX_VISUALIZE_CLOTH_MESH 63 +#define NX_VISUALIZE_CLOTH_COLLISIONS 64 +#define NX_VISUALIZE_CLOTH_SELFCOLLISIONS 65 +#define NX_VISUALIZE_CLOTH_WORKPACKETS 66 +#define NX_VISUALIZE_CLOTH_SLEEP 67 +#define NX_VISUALIZE_CLOTH_SLEEP_VERTEX 94 +#define NX_VISUALIZE_CLOTH_TEARABLE_VERTICES 80 +#define NX_VISUALIZE_CLOTH_TEARING 81 +#define NX_VISUALIZE_CLOTH_ATTACHMENT 82 +#define NX_VISUALIZE_CLOTH_VALIDBOUNDS 92 +#define NX_VISUALIZE_SOFTBODY_MESH 83 +#define NX_VISUALIZE_SOFTBODY_COLLISIONS 84 +#define NX_VISUALIZE_SOFTBODY_WORKPACKETS 85 +#define NX_VISUALIZE_SOFTBODY_SLEEP 86 +#define NX_VISUALIZE_SOFTBODY_SLEEP_VERTEX 95 +#define NX_VISUALIZE_SOFTBODY_TEARABLE_VERTICES 87 +#define NX_VISUALIZE_SOFTBODY_TEARING 88 +#define NX_VISUALIZE_SOFTBODY_ATTACHMENT 89 +#define NX_VISUALIZE_SOFTBODY_VALIDBOUNDS 93 +#define NX_ADAPTIVE_FORCE 68 +#define NX_COLL_VETO_JOINTED 69 +#define NX_TRIGGER_TRIGGER_CALLBACK 70 +#define NX_SELECT_HW_ALGO 71 +#define NX_VISUALIZE_ACTIVE_VERTICES 72 +#define NX_CCD_EPSILON 73 +#define NX_SOLVER_CONVERGENCE_THRESHOLD 74 +#define NX_BBOX_NOISE_LEVEL 75 +#define NX_IMPLICIT_SWEEP_CACHE_SIZE 76 +#define NX_DEFAULT_SLEEP_ENERGY 77 +#define NX_CONSTANT_FLUID_MAX_PACKETS 78 +#define NX_CONSTANT_FLUID_MAX_PARTICLES_PER_STEP 79 +#define NX_VISUALIZE_FORCE_FIELDS 91 +#define NX_ASYNCHRONOUS_MESH_CREATION 96 +#define NX_FORCE_FIELD_CUSTOM_KERNEL_EPSILON 97 +#define NX_IMPROVED_SPRING_SOLVER 98 + +#ifdef PHYSX283 +#define NX_FAST_MASSIVE_BP_VOLUME_DELETION 99 +#define NX_LEGACY_JOINT_DRIVE 100 +#endif /* PHYSX283 */ + +// PhysxActorFlag +#define NX_AF_DISABLE_COLLISION 1<<0 +#define NX_AF_DISABLE_RESPONSE 1<<1 +#define NX_AF_LOCK_COM 1<<2 +#define NX_AF_FLUID_DISABLE_COLLISION 1<<3 +#define NX_AF_CONTACT_MODIFICATION 1<<4 +#define NX_AF_FORCE_CONE_FRICTION 1<<5 +#define NX_AF_USER_ACTOR_PAIR_FILTERING 1<<6 + +// PhysxBodyFlag +#define NX_BF_DISABLE_GRAVITY 1<<0 +#define NX_BF_FROZEN_POS_X 1<<1 +#define NX_BF_FROZEN_POS_Y 1<<2 +#define NX_BF_FROZEN_POS_Z 1<<3 +#define NX_BF_FROZEN_ROT_X 1<<4 +#define NX_BF_FROZEN_ROT_Y 1<<5 +#define NX_BF_FROZEN_ROT_Z 1<<6 +#define NX_BF_FROZEN_POS 256 +#define NX_BF_FROZEN_ROT 131072 +#define NX_BF_FROZEN 131328 +#define NX_BF_KINEMATIC 1<<7 +#define NX_BF_VISUALIZATION 1<<8 +#define NX_BF_FILTER_SLEEP_VEL 1<<10 +#define NX_BF_ENERGY_SLEEP_TEST 1<<11 + +// PhysxBroadPhaseType +#define NX_BP_TYPE_SAP_SINGLE 0 +#define NX_BP_TYPE_SAP_MULTI 1 + +// PhysxContactPairFlag +#define NX_IGNORE_PAIR 1<<0 +#define NX_NOTIFY_ON_START_TOUCH 1<<1 +#define NX_NOTIFY_ON_END_TOUCH 1<<2 +#define NX_NOTIFY_ON_TOUCH 1<<3 +#define NX_NOTIFY_ON_IMPACT 1<<4 +#define NX_NOTIFY_ON_ROLL 1<<5 +#define NX_NOTIFY_ON_SLIDE 1<<6 +#define NX_NOTIFY_FORCES 1<<7 +#define NX_NOTIFY_ON_START_TOUCH_FORCE_THRESHOLD 1<<8 +#define NX_NOTIFY_ON_END_TOUCH_FORCE_THRESHOLD 1<<9 +#define NX_NOTIFY_ON_TOUCH_FORCE_THRESHOLD 1<<10 +#define NX_NOTIFY_CONTACT_MODIFICATION 1<<16 + +// PhysxCombineMode +#define NX_CM_AVERAGE 0 +#define NX_CM_MIN 1 +#define NX_CM_MULTIPLY 2 +#define NX_CM_MAX 3 + +// PhysxD6JointDriveType +#define NX_D6JOINT_DRIVE_POSITION 1<<0 +#define NX_D6JOINT_DRIVE_VELOCITY 1<<1 + +// PhysxD6JointFlag +#define NX_D6JOINT_SLERP_DRIVE 1<<0 +#define NX_D6JOINT_GEAR_ENABLED 1<<1 + +// PhysxD6JointMotion +#define NX_D6JOINT_MOTION_LOCKED 0 +#define NX_D6JOINT_MOTION_LIMITED 1 +#define NX_D6JOINT_MOTION_FREE 2 + +// PhysxDistanceJointFlag +#define NX_DJF_MAX_DISTANCE_ENABLED 1<<0 +#define NX_DJF_MIN_DISTANCE_ENABLED 1<<1 +#define NX_DJF_SPRING_ENABLED 1<<2 + +// PhysxFilterOp +#define NX_FILTEROP_AND 0 +#define NX_FILTEROP_OR 1 +#define NX_FILTEROP_XOR 2 +#define NX_FILTEROP_NAND 3 +#define NX_FILTEROP_NOR 4 +#define NX_FILTEROP_NXOR 5 +#define NX_FILTEROP_SWAP_AND 6 + +// PhysxForceFieldCoordinates +#define NX_FFC_CARTESIAN 0 +#define NX_FFC_SPHERICAL 1 +#define NX_FFC_CYLINDRICAL 2 +#define NX_FFC_TOROIDAL 3 + +// PhysxForceFieldShapeGroupFlag +#define NX_FFSG_EXCLUDE_GROUP 1 + +// PhysxMaterialFlag +#define NX_MF_ANISOTROPIC 1<<0 +#define NX_MF_DISABLE_FRICTION 1<<4 +#define NX_MF_DISABLE_STRONG_FRICTION 1<<5 + +// PhysxForceMode +#define NX_FORCE 0 +#define NX_IMPULSE 1 +#define NX_VELOCITY_CHANGE 2 +#define NX_SMOOTH_IMPULSE 3 +#define NX_SMOOTH_VELOCITY_CHANGE 4 +#define NX_ACCELERATION 5 + +// PhysxJointFlag +#define NX_JF_COLLISION_ENABLED 1<<0 +#define NX_JF_VISUALIZATION 1<<1 + +// PhysxProjectionMode +#define NX_JPM_NONE 0 +#define NX_JPM_POINT_MINDIST 1 +#define NX_JPM_LINEAR_MINDIST 2 + +// PhysxPruningStructure +#define NX_PRUNING_NONE 0 +#define NX_PRUNING_OCTREE 1 +#define NX_PRUNING_QUADTREE 2 +#define NX_PRUNING_DYNAMIC_AABB_TREE 3 +#define NX_PRUNING_STATIC_AABB_TREE 4 + +// PhysxPulleyJointFlag +#define NX_PJF_IS_RIGID 1<<0 +#define NX_PJF_MOTOR_ENABLED 1<<1 + +// PhysxRevoluteJointFlag +#define NX_RJF_LIMIT_ENABLED 1<<0 +#define NX_RJF_MOTOR_ENABLED 1<<1 +#define NX_RJF_SPRING_ENABLED 1<<2 + +// PhysxSceneFlag +#define NX_SF_DISABLE_SSE 0x1 +#define NX_SF_DISABLE_COLLISIONS 0x2 +#define NX_SF_SIMULATE_SEPARATE_THREAD 0x4 +#define NX_SF_ENABLE_MULTITHREAD 0x8 +#define NX_SF_ENABLE_ACTIVETRANSFORMS 0x10 +#define NX_SF_RESTRICTED_SCENE 0x20 +#define NX_SF_DISABLE_SCENE_MUTEX 0x40 +#define NX_SF_FORCE_CONE_FRICTION 0x80 +#define NX_SF_SEQUENTIAL_PRIMARY 0x80*2 +#define NX_SF_FLUID_PERFORMANCE_HINT 0x80*4 +#define NX_SF_ALTERNATIVE_FLUID_TRIANGLE_COLLISION 0x80*8 +#define NX_SF_MULTITHREADED_FORCEFIELD 0x80*16 + +// PhysxShapeFlag +#define NX_TRIGGER_ON_ENTER 1<<0 +#define NX_TRIGGER_ON_LEAVE 1<<1 +#define NX_TRIGGER_ON_STAY 1<<2 +#define NX_TRIGGER_ENABLE 7 +#define NX_SF_VISUALIZATION 1<<3 +#define NX_SF_DISABLE_COLLISION 1<<4 +#define NX_SF_FEATURE_INDICES 1<<5 +#define NX_SF_DISABLE_RAYCASTING 1<<6 +#define NX_SF_POINT_CONTACT_FORCE 1<<7 +#define NX_SF_FLUID_DRAIN 1<<8 +#define NX_SF_FLUID_DISABLE_COLLISION 1<<10 +#define NX_SF_FLUID_TWOWAY 1<<11 +#define NX_SF_DISABLE_RESPONSE 1<<12 +#define NX_SF_DYNAMIC_DYNAMIC_CCD 1<<13 +#define NX_SF_DISABLE_SCENE_QUERIES 1<<14 +#define NX_SF_CLOTH_DRAIN 1<<15 +#define NX_SF_CLOTH_DISABLE_COLLISION 1<<16 +#define NX_SF_CLOTH_TWOWAY 1<<17 +#define NX_SF_SOFTBODY_DRAIN 1<<18 +#define NX_SF_SOFTBODY_DISABLE_COLLISION 1<<19 +#define NX_SF_SOFTBODY_TWOWAY 1<<20 + +// PhysxShapesType +#define NX_STATIC_SHAPES 1<<0 +#define NX_DYNAMIC_SHAPES 1<<1 +#define NX_ALL_SHAPES (1<<0|1<<1) + +// PhysxSphericalJointFlag +#define NX_SJF_TWIST_LIMIT_ENABLED 1<<0 +#define NX_SJF_SWING_LIMIT_ENABLED 1<<1 +#define NX_SJF_TWIST_SPRING_ENABLED 1<<2 +#define NX_SJF_SWING_SPRING_ENABLED 1<<3 +#define NX_SJF_JOINT_SPRING_ENABLED 1<<4 +#define NX_SJF_PERPENDICULAR_DIR_CONSTRAINTS 1<<5 + +// PhysxUpAxis +#define NX_X 1 +#define NX_Y 2 +#define NX_Z 3 + +// PhysxWheelShapeFlag +#define NX_WF_WHEEL_AXIS_CONTACT_NORMAL 1<<0 +#define NX_WF_INPUT_LAT_SLIPVELOCITY 1<<1 +#define NX_WF_INPUT_LNG_SLIPVELOCITY 1<<2 +#define NX_WF_UNSCALED_SPRING_BEHAVIOR 1<<3 +#define NX_WF_AXLE_SPEED_OVERRIDE 1<<4 +#define NX_WF_EMULATE_LEGACY_WHEEL 1<<5 +#define NX_WF_CLAMPED_FRICTION 1<<6 + +#endif // CPPPARSER + +//////////////////////////////////////////////////////////////////// +// Class : BamEnums +// Description : This class exists just to provide scoping for the +// enums shared by PhysX classes. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxEnums { +PUBLISHED: + + enum PhysxParameter { + P_penalty_force = NX_PENALTY_FORCE, + P_skin_width = NX_SKIN_WIDTH, + P_default_sleep_lin_vel_squared = NX_DEFAULT_SLEEP_LIN_VEL_SQUARED, + P_default_sleep_ang_vel_squared = NX_DEFAULT_SLEEP_ANG_VEL_SQUARED, + P_bounce_threshold = NX_BOUNCE_THRESHOLD, + P_dyn_frict_scaling = NX_DYN_FRICT_SCALING, + P_sta_frict_scaling = NX_STA_FRICT_SCALING, + P_max_angular_velocity = NX_MAX_ANGULAR_VELOCITY, + P_continuous_cd = NX_CONTINUOUS_CD, + P_visualization_scale = NX_VISUALIZATION_SCALE, + P_adaptive_force = NX_ADAPTIVE_FORCE, + P_coll_veta_jointed = NX_COLL_VETO_JOINTED, + P_trigger_trigger_callback = NX_TRIGGER_TRIGGER_CALLBACK, + P_select_hw_algo = NX_SELECT_HW_ALGO, + P_ccd_epsilon = NX_CCD_EPSILON, + P_solver_convergence_threshold = NX_SOLVER_CONVERGENCE_THRESHOLD, + P_bbox_noise_level = NX_BBOX_NOISE_LEVEL, + P_implicit_sweep_cache_size = NX_IMPLICIT_SWEEP_CACHE_SIZE, + P_default_sleep_energy = NX_DEFAULT_SLEEP_ENERGY, + P_constant_fluid_max_packets = NX_CONSTANT_FLUID_MAX_PACKETS, + P_constant_fluid_max_particles_per_step = NX_CONSTANT_FLUID_MAX_PARTICLES_PER_STEP, + P_asynchronous_mesh_creation = NX_ASYNCHRONOUS_MESH_CREATION, + P_force_field_custom_kernel_epsilon = NX_FORCE_FIELD_CUSTOM_KERNEL_EPSILON, + P_improved_spring_solver = NX_IMPROVED_SPRING_SOLVER, + +#ifndef LINUX /* The following enums are only defined in SDK version 2.8.1 */ + P_fast_massive_bp_volume_deletion = NX_FAST_MASSIVE_BP_VOLUME_DELETION, + P_legacy_joint_drive = NX_LEGACY_JOINT_DRIVE, +#endif /* LINUX */ + + P_visualize_world_axes = NX_VISUALIZE_WORLD_AXES, + P_visualize_body_axes = NX_VISUALIZE_BODY_AXES, + P_visualize_body_mass_axes = NX_VISUALIZE_BODY_MASS_AXES, + P_visualize_body_lin_velocity = NX_VISUALIZE_BODY_LIN_VELOCITY, + P_visualize_body_ang_velocity = NX_VISUALIZE_BODY_ANG_VELOCITY, + P_visualize_body_joint_groups = NX_VISUALIZE_BODY_JOINT_GROUPS, + P_visualize_joint_local_axes = NX_VISUALIZE_JOINT_LOCAL_AXES, + P_visualize_joint_world_axes = NX_VISUALIZE_JOINT_WORLD_AXES, + P_visualize_joint_limits = NX_VISUALIZE_JOINT_LIMITS, + P_visualize_contact_point = NX_VISUALIZE_CONTACT_POINT, + P_visualize_contact_normal = NX_VISUALIZE_CONTACT_NORMAL, + P_visualize_contact_error = NX_VISUALIZE_CONTACT_ERROR, + P_visualize_contact_force = NX_VISUALIZE_CONTACT_FORCE, + P_visualize_actor_axes = NX_VISUALIZE_ACTOR_AXES, + P_visualize_collision_aabbs = NX_VISUALIZE_COLLISION_AABBS, + P_visualize_collision_shapes = NX_VISUALIZE_COLLISION_SHAPES, + P_visualize_collision_axes = NX_VISUALIZE_COLLISION_AXES, + P_visualize_collision_compounds = NX_VISUALIZE_COLLISION_COMPOUNDS, + P_visualize_collision_vnormals = NX_VISUALIZE_COLLISION_VNORMALS, + P_visualize_collision_fnormals = NX_VISUALIZE_COLLISION_FNORMALS, + P_visualize_collision_edges = NX_VISUALIZE_COLLISION_EDGES, + P_visualize_collision_spheres = NX_VISUALIZE_COLLISION_SPHERES, + P_visualize_collision_static = NX_VISUALIZE_COLLISION_STATIC, + P_visualize_collision_dynamic = NX_VISUALIZE_COLLISION_DYNAMIC, + P_visualize_collision_free = NX_VISUALIZE_COLLISION_FREE, + P_visualize_collision_ccd = NX_VISUALIZE_COLLISION_CCD, + P_visualize_collision_skeletons = NX_VISUALIZE_COLLISION_SKELETONS, + P_visualize_fluid_emitters = NX_VISUALIZE_FLUID_EMITTERS, + P_visualize_fluid_position = NX_VISUALIZE_FLUID_POSITION, + P_visualize_fluid_velocity = NX_VISUALIZE_FLUID_VELOCITY, + P_visualize_fluid_kernel_radius = NX_VISUALIZE_FLUID_KERNEL_RADIUS, + P_visualize_fluid_bounds = NX_VISUALIZE_FLUID_BOUNDS, + P_visualize_fluid_packets = NX_VISUALIZE_FLUID_PACKETS, + P_visualize_fluid_motion_limit = NX_VISUALIZE_FLUID_MOTION_LIMIT, + P_visualize_fluid_dyn_collision = NX_VISUALIZE_FLUID_DYN_COLLISION, + P_visualize_fluid_stc_collision = NX_VISUALIZE_FLUID_STC_COLLISION, + P_visualize_fluid_mesh_packets = NX_VISUALIZE_FLUID_MESH_PACKETS, + P_visualize_fluid_drains = NX_VISUALIZE_FLUID_DRAINS, + P_visualize_fluid_packet_data = NX_VISUALIZE_FLUID_PACKET_DATA, + P_visualize_cloth_mesh = NX_VISUALIZE_CLOTH_MESH, + P_visualize_cloth_collisions = NX_VISUALIZE_CLOTH_COLLISIONS, + P_visualize_cloth_selfcollisions = NX_VISUALIZE_CLOTH_SELFCOLLISIONS, + P_visualize_cloth_workpackets = NX_VISUALIZE_CLOTH_WORKPACKETS, + P_visualize_cloth_sleep = NX_VISUALIZE_CLOTH_SLEEP, + P_visualize_cloth_sleep_vertex = NX_VISUALIZE_CLOTH_SLEEP_VERTEX, + P_visualize_cloth_tearable_vertices = NX_VISUALIZE_CLOTH_TEARABLE_VERTICES, + P_visualize_cloth_tearing = NX_VISUALIZE_CLOTH_TEARING, + P_visualize_cloth_attachment = NX_VISUALIZE_CLOTH_ATTACHMENT, + P_visualize_cloth_validbounds = NX_VISUALIZE_CLOTH_VALIDBOUNDS, + P_visualize_softbody_mesh = NX_VISUALIZE_SOFTBODY_MESH, + P_visualize_softbody_collisions = NX_VISUALIZE_SOFTBODY_COLLISIONS, + P_visualize_softbody_workpackets = NX_VISUALIZE_SOFTBODY_WORKPACKETS, + P_visualize_softbody_sleep = NX_VISUALIZE_SOFTBODY_SLEEP, + P_visualize_softbody_sleep_vertex = NX_VISUALIZE_SOFTBODY_SLEEP_VERTEX, + P_visualize_softbody_tearable_vertices = NX_VISUALIZE_SOFTBODY_TEARABLE_VERTICES, + P_visualize_softbody_tearing = NX_VISUALIZE_SOFTBODY_TEARING, + P_visualize_softbody_attachment = NX_VISUALIZE_SOFTBODY_ATTACHMENT, + P_visualize_softbody_validbounds = NX_VISUALIZE_SOFTBODY_VALIDBOUNDS, + P_visualize_active_vertices = NX_VISUALIZE_ACTIVE_VERTICES, + P_visualize_force_fields = NX_VISUALIZE_FORCE_FIELDS, + }; + + enum PhysxActorFlag { + AF_disable_collision = NX_AF_DISABLE_COLLISION, + AF_disable_response = NX_AF_DISABLE_RESPONSE, + AF_lock_com = NX_AF_LOCK_COM, + AF_fluid_disable_collision = NX_AF_FLUID_DISABLE_COLLISION, + AF_contact_modification = NX_AF_CONTACT_MODIFICATION, + AF_force_cone_friction = NX_AF_FORCE_CONE_FRICTION, + AF_user_actor_pair_filtering = NX_AF_USER_ACTOR_PAIR_FILTERING + }; + + enum PhysxBodyFlag { + BF_disable_gravity = NX_BF_DISABLE_GRAVITY, + Bf_frozen_pos_x = NX_BF_FROZEN_POS_X, + BF_frozen_pos_y = NX_BF_FROZEN_POS_Y, + BF_frozen_pos_z = NX_BF_FROZEN_POS_Z, + BF_frozen_rot_x = NX_BF_FROZEN_ROT_X, + BF_frozen_rot_y = NX_BF_FROZEN_ROT_Y, + BF_frozen_rot_z = NX_BF_FROZEN_ROT_Z, + BF_frozen_pos = NX_BF_FROZEN_POS, + BF_frozen_rot = NX_BF_FROZEN_ROT, + BF_frozen = NX_BF_FROZEN, + BF_kinematic = NX_BF_KINEMATIC, + BF_visualization = NX_BF_VISUALIZATION, + BF_filter_sleep_vel = NX_BF_FILTER_SLEEP_VEL, + BF_energy_sleep_test = NX_BF_ENERGY_SLEEP_TEST + }; + + enum PhysxBroadPhaseType { + BPT_sap_single = NX_BP_TYPE_SAP_SINGLE, + BPT_sap_multi = NX_BP_TYPE_SAP_MULTI + }; + + enum PhysxContactPairFlag { + CPF_ignore_pair = NX_IGNORE_PAIR, + CPF_notify_on_start_touch = NX_NOTIFY_ON_START_TOUCH, + CPF_notify_on_end_touch = NX_NOTIFY_ON_END_TOUCH, + CPF_notify_on_touch = NX_NOTIFY_ON_TOUCH, + CPF_notify_on_impact = NX_NOTIFY_ON_IMPACT, + CPF_notify_on_roll = NX_NOTIFY_ON_ROLL, + CPF_notify_on_slide = NX_NOTIFY_ON_SLIDE, + CPF_notify_forces = NX_NOTIFY_FORCES, + CPF_notify_on_start_touch_threshold = NX_NOTIFY_ON_START_TOUCH_FORCE_THRESHOLD, + CPF_notify_on_end_touch_threshold = NX_NOTIFY_ON_END_TOUCH_FORCE_THRESHOLD, + CPF_notify_on_touch_threshold = NX_NOTIFY_ON_TOUCH_FORCE_THRESHOLD, + CPF_notify_contact_modifications = NX_NOTIFY_CONTACT_MODIFICATION + }; + + enum PhysxCombineMode { + CM_average = NX_CM_AVERAGE, + CM_min = NX_CM_MIN, + CM_multiply = NX_CM_MULTIPLY, + CM_max = NX_CM_MAX + }; + + enum PhysxD6JointDriveType { + D6_joint_drive_position = NX_D6JOINT_DRIVE_POSITION, + D6_joint_drive_velocity = NX_D6JOINT_DRIVE_VELOCITY + }; + + enum PhysxD6JointFlag { + D6_joint_slerp_drive = NX_D6JOINT_SLERP_DRIVE, + D6_joint_gear_disabled = NX_D6JOINT_GEAR_ENABLED + }; + + enum PhysxD6JointMotion { + D6_joint_motion_locked = NX_D6JOINT_MOTION_LOCKED, + D6_joint_motion_limited = NX_D6JOINT_MOTION_LIMITED, + D6_joint_motion_free = NX_D6JOINT_MOTION_FREE + }; + + enum PhysxDistanceJointFlag { + DJF_max_distance_enabled = NX_DJF_MAX_DISTANCE_ENABLED, + DJF_mix_distance_enabled = NX_DJF_MIN_DISTANCE_ENABLED, + DJF_spring_enabled = NX_DJF_SPRING_ENABLED + }; + + enum PhysxFilterOp { + FO_and = NX_FILTEROP_AND, + FO_or = NX_FILTEROP_OR, + FO_xor = NX_FILTEROP_XOR, + FO_nand = NX_FILTEROP_NAND, + FO_nor = NX_FILTEROP_NOR, + FO_nxor = NX_FILTEROP_NXOR, + FO_swap_and = NX_FILTEROP_SWAP_AND + }; + + enum PhysxForceFieldCoordinates { + FFC_cartesian, + FFC_spherical, + FFC_cylindrical, + FFC_toroidal, + }; + + enum PhysxForceFieldShapeGroupFlag { + FFSG_exclude_group = NX_FFSG_EXCLUDE_GROUP + }; + + enum PhysxForceMode { + FM_force = NX_FORCE, + FM_impulse = NX_IMPULSE, + FM_velocity_change = NX_VELOCITY_CHANGE, + FM_smooth_impulse = NX_SMOOTH_IMPULSE, + FM_smooth_velocity_change = NX_SMOOTH_VELOCITY_CHANGE, + FM_acceleration = NX_ACCELERATION + }; + + enum PhysxJointFlag { + JF_collision_enabled = NX_JF_COLLISION_ENABLED, + JF_visualization = NX_JF_VISUALIZATION + }; + + enum PhysxMaterialFlag { + MF_anisotropic = NX_MF_ANISOTROPIC, + MF_disable_friction = NX_MF_DISABLE_FRICTION, + MF_disable_strong_friction = NX_MF_DISABLE_STRONG_FRICTION + }; + + enum PhysxProjectionMode { + PM_none = NX_JPM_NONE, + PM_point_mindist = NX_JPM_POINT_MINDIST, + PM_linear_mindist = NX_JPM_LINEAR_MINDIST + }; + + enum PhysxPruningStructure { + PS_none = NX_PRUNING_NONE, + PS_octree = NX_PRUNING_OCTREE, + PS_quadtree = NX_PRUNING_QUADTREE, + PS_dynamic_aabb_tree = NX_PRUNING_DYNAMIC_AABB_TREE, + PS_static_aabb_tree = NX_PRUNING_STATIC_AABB_TREE + }; + + enum PhysxPulleyJointFlag { + PJF_is_rigid = NX_PJF_IS_RIGID, + PJF_motor_enabled = NX_PJF_MOTOR_ENABLED + }; + + enum PhysxRevoluteJointFlag { + RJF_limit_enabled = NX_RJF_LIMIT_ENABLED, + RJF_motor_enabled = NX_RJF_MOTOR_ENABLED, + RJF_spring_enabled = NX_RJF_SPRING_ENABLED + }; + + enum PhysxSceneFlag { + SF_disable_sse = NX_SF_DISABLE_SSE, + SF_disable_collisions = NX_SF_DISABLE_COLLISIONS, + SF_restricted_scene = NX_SF_RESTRICTED_SCENE, + SF_disable_scene_mutex = NX_SF_DISABLE_SCENE_MUTEX, + SF_force_cone_friction = NX_SF_FORCE_CONE_FRICTION, + SF_sequential_primary = NX_SF_SEQUENTIAL_PRIMARY, + SF_fluid_performance_hint = NX_SF_FLUID_PERFORMANCE_HINT, + //SF_alternative_fluid_triangle_collision = NX_SF_ALTERNATIVE_FLUID_TRIANGLE_COLLISION, + //SF_multithreaded_forcefield = NX_SF_MULTITHREADED_FORCEFIELD, + //SF_simulate_separate_thread = NX_SF_SIMULATE_SEPARATE_THREAD, + //SF_enable_multithread = NX_SF_ENABLE_MULTITHREAD, + }; + + enum PhysxShapeFlag { + SF_trigger_on_enter = NX_TRIGGER_ON_ENTER, + SF_trigger_on_leave = NX_TRIGGER_ON_LEAVE, + SF_trigger_on_stay = NX_TRIGGER_ON_STAY, + SF_trigger_enable = NX_TRIGGER_ENABLE, + SF_visualization = NX_SF_VISUALIZATION, + SF_disable_collision = NX_SF_DISABLE_COLLISION, + SF_disable_raycasting = NX_SF_DISABLE_RAYCASTING, + SF_disable_response = NX_SF_DISABLE_RESPONSE, + SF_disable_scene_queries = NX_SF_DISABLE_SCENE_QUERIES, + SF_point_contact_force = NX_SF_POINT_CONTACT_FORCE, + SF_feature_indices = NX_SF_FEATURE_INDICES, + SF_dynamic_dynamic_ccd = NX_SF_DYNAMIC_DYNAMIC_CCD, + SF_fluid_drain = NX_SF_FLUID_DRAIN, + SF_fluid_disable_collision = NX_SF_FLUID_DISABLE_COLLISION, + SF_fluid_twoway = NX_SF_FLUID_TWOWAY, + SF_cloth_drain = NX_SF_CLOTH_DRAIN, + SF_cloth_disable_collision = NX_SF_CLOTH_DISABLE_COLLISION, + SF_cloth_twoway = NX_SF_CLOTH_TWOWAY, + SF_softbody_drain = NX_SF_SOFTBODY_DRAIN, + SF_softbody_disable_collision = NX_SF_SOFTBODY_DISABLE_COLLISION, + SF_softbody_twoway = NX_SF_SOFTBODY_TWOWAY + }; + + enum PhysxShapesType { + ST_static = NX_STATIC_SHAPES , + ST_dynamic = NX_DYNAMIC_SHAPES , + ST_all = NX_ALL_SHAPES + }; + + enum PhysxSphericalJointFlag { + SJF_twist_limit_enabled = NX_SJF_TWIST_LIMIT_ENABLED, + SJF_swing_limit_enabled = NX_SJF_SWING_LIMIT_ENABLED, + SJF_twist_spring_enabled = NX_SJF_TWIST_SPRING_ENABLED, + SJF_swing_spring_enabled = NX_SJF_SWING_SPRING_ENABLED, + SJF_joint_spring_enabled = NX_SJF_JOINT_SPRING_ENABLED, + SJF_perpendicular_dir_constraints = NX_SJF_PERPENDICULAR_DIR_CONSTRAINTS + }; + + enum PhysxUpAxis { + X_up = NX_X, + Y_up = NX_Y, + Z_up = NX_Z + }; + + enum PhysxWheelShapeFlag { + WSF_wheel_axis_contact_normal = NX_WF_WHEEL_AXIS_CONTACT_NORMAL, + WSF_input_lat_slipvelocity = NX_WF_INPUT_LAT_SLIPVELOCITY, + WSF_input_lng_slipvelocity = NX_WF_INPUT_LNG_SLIPVELOCITY, + WSF_unscaled_spring_behavior = NX_WF_UNSCALED_SPRING_BEHAVIOR, + WSF_axle_speed_override = NX_WF_AXLE_SPEED_OVERRIDE, + WSF_emulate_legacy_wheel = NX_WF_EMULATE_LEGACY_WHEEL, + WSF_clamped_friction = NX_WF_CLAMPED_FRICTION + }; + +}; + +EXPCL_PANDAPHYSX ostream &operator << (ostream &out, PhysxEnums::PhysxUpAxis axis); +EXPCL_PANDAPHYSX istream &operator >> (istream &in, PhysxEnums::PhysxUpAxis &axis); + +#endif + diff --git a/panda/src/physx/physxFileStream.cxx b/panda/src/physx/physxFileStream.cxx new file mode 100644 index 0000000000..3720416fe4 --- /dev/null +++ b/panda/src/physx/physxFileStream.cxx @@ -0,0 +1,186 @@ +// Filename: physxFileStream.cxx +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxFileStream.h" + +#include "stdio.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PhysxFileStream::PhysxFileStream(const char *filename, bool load) : fp(NULL) +{ + fp = fopen(filename, load ? "rb" : "wb"); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PhysxFileStream::~PhysxFileStream() +{ + if (fp) fclose(fp); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::readByte +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxU8 PhysxFileStream::readByte() const +{ + NxU8 b; + size_t r = fread(&b, sizeof(NxU8), 1, fp); + NX_ASSERT(r); + return b; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::readWord +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxU16 PhysxFileStream::readWord() const +{ + NxU16 w; + size_t r = fread(&w, sizeof(NxU16), 1, fp); + NX_ASSERT(r); + return w; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::readDword +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxU32 PhysxFileStream::readDword() const +{ + NxU32 d; + size_t r = fread(&d, sizeof(NxU32), 1, fp); + NX_ASSERT(r); + return d; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::readFloat +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxFileStream::readFloat() const +{ + NxReal f; + size_t r = fread(&f, sizeof(NxReal), 1, fp); + NX_ASSERT(r); + return f; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::readDouble +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +double PhysxFileStream::readDouble() const +{ + NxF64 f; + size_t r = fread(&f, sizeof(NxF64), 1, fp); + NX_ASSERT(r); + return f; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::readBuffer +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxFileStream::readBuffer(void *buffer, NxU32 size) const +{ + size_t w = fread(buffer, size, 1, fp); + NX_ASSERT(w); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::storeByte +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxFileStream::storeByte(NxU8 b) +{ + size_t w = fwrite(&b, sizeof(NxU8), 1, fp); + NX_ASSERT(w); + return *this; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::storeWord +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxFileStream::storeWord(NxU16 w) +{ + size_t ww = fwrite(&w, sizeof(NxU16), 1, fp); + NX_ASSERT(ww); + return *this; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::storeDword +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxFileStream::storeDword(NxU32 d) +{ + size_t w = fwrite(&d, sizeof(NxU32), 1, fp); + NX_ASSERT(w); + return *this; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::storeFloat +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxFileStream::storeFloat(NxReal f) +{ + size_t w = fwrite(&f, sizeof(NxReal), 1, fp); + NX_ASSERT(w); + return *this; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::storeDouble +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxFileStream::storeDouble(NxF64 f) +{ + size_t w = fwrite(&f, sizeof(NxF64), 1, fp); + NX_ASSERT(w); + return *this; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFileStream::storeBuffer +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxFileStream::storeBuffer(const void *buffer, NxU32 size) +{ + size_t w = fwrite(buffer, size, 1, fp); + NX_ASSERT(w); + return *this; +} + diff --git a/panda/src/physx/physxFileStream.h b/panda/src/physx/physxFileStream.h new file mode 100644 index 0000000000..4edb92af3f --- /dev/null +++ b/panda/src/physx/physxFileStream.h @@ -0,0 +1,51 @@ +// Filename: physxFileStream.h +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXFILESTREAM_H +#define PHYSXFILESTREAM_H + +#include "pandabase.h" + +#include "NoMinMax.h" +#include "NxStream.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxFileStream +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxFileStream : public NxStream { + +public: + PhysxFileStream(const char *filename, bool load); + virtual ~PhysxFileStream(); + + virtual NxU8 readByte() const; + virtual NxU16 readWord() const; + virtual NxU32 readDword() const; + virtual float readFloat() const; + virtual double readDouble() const; + virtual void readBuffer(void *buffer, NxU32 size) const; + + virtual NxStream &storeByte(NxU8 b); + virtual NxStream &storeWord(NxU16 w); + virtual NxStream &storeDword(NxU32 d); + virtual NxStream &storeFloat(NxReal f); + virtual NxStream &storeDouble(NxF64 f); + virtual NxStream &storeBuffer(const void *buffer, NxU32 size); + +private: + FILE* fp; +}; + +#endif // PHYSXFILESTREAM_H diff --git a/panda/src/physx/physxFixedJoint.I b/panda/src/physx/physxFixedJoint.I new file mode 100644 index 0000000000..489f30e98f --- /dev/null +++ b/panda/src/physx/physxFixedJoint.I @@ -0,0 +1,36 @@ +// Filename: physxFixedJoint.I +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFixedJoint::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxFixedJoint:: +PhysxFixedJoint() : PhysxJoint() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFixedJoint::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxFixedJoint:: +~PhysxFixedJoint() { + +} + diff --git a/panda/src/physx/physxFixedJoint.cxx b/panda/src/physx/physxFixedJoint.cxx new file mode 100644 index 0000000000..8cfe7c0cbf --- /dev/null +++ b/panda/src/physx/physxFixedJoint.cxx @@ -0,0 +1,76 @@ +// Filename: physxFixedJoint.cxx +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxFixedJoint.h" +#include "physxFixedJointDesc.h" + +TypeHandle PhysxFixedJoint::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFixedJoint::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxFixedJoint:: +link(NxJoint *jointPtr) { + + _ptr = jointPtr->isFixedJoint(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFixedJoint::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxFixedJoint:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxFixedJoint::save_to_desc +// Access : Published +// Description : Saves the state of the joint object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxFixedJoint:: +save_to_desc(PhysxFixedJointDesc &jointDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxFixedJoint::load_from_desc +// Access : Published +// Description : Loads the entire state of the joint from a +// descriptor with a single call. +//////////////////////////////////////////////////////////////////// +void PhysxFixedJoint:: +load_from_desc(const PhysxFixedJointDesc &jointDesc) { + + nassertv(_error_type == ET_ok); + _ptr->loadFromDesc(jointDesc._desc); +} + diff --git a/panda/src/physx/physxFixedJoint.h b/panda/src/physx/physxFixedJoint.h new file mode 100644 index 0000000000..6da3ab3f17 --- /dev/null +++ b/panda/src/physx/physxFixedJoint.h @@ -0,0 +1,75 @@ +// Filename: physxFixedJoint.h +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXFIXEDJOINT_H +#define PHYSXFIXEDJOINT_H + +#include "pandabase.h" + +#include "physxJoint.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxFixedJointDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxFixedJoint +// Description : A fixed joint permits no relative movement between +// two bodies. ie the bodies are glued together. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxFixedJoint : public PhysxJoint { + +PUBLISHED: + INLINE PhysxFixedJoint(); + INLINE ~PhysxFixedJoint(); + + void save_to_desc(PhysxFixedJointDesc &jointDesc) const; + void load_from_desc(const PhysxFixedJointDesc &jointDesc); + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxJoint *ptr() const { return (NxJoint *)_ptr; }; + + void link(NxJoint *jointPtr); + void unlink(); + +private: + NxFixedJoint *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxJoint::init_type(); + register_type(_type_handle, "PhysxFixedJoint", + PhysxJoint::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxFixedJoint.I" + +#endif // PHYSXFIXEDJOINT_H diff --git a/panda/src/physx/physxFixedJointDesc.I b/panda/src/physx/physxFixedJointDesc.I new file mode 100644 index 0000000000..bf7b2b42c8 --- /dev/null +++ b/panda/src/physx/physxFixedJointDesc.I @@ -0,0 +1,59 @@ +// Filename: physxFixedJointDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFixedJointDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxFixedJointDesc:: +PhysxFixedJointDesc() : PhysxJointDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFixedJointDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxFixedJointDesc:: +~PhysxFixedJointDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFixedJointDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxFixedJointDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxFixedJointDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxFixedJointDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxJointHandler.I b/panda/src/physx/physxFixedJointDesc.cxx similarity index 79% rename from panda/src/physx/physxJointHandler.I rename to panda/src/physx/physxFixedJointDesc.cxx index 41fd12fb91..0953b3464e 100644 --- a/panda/src/physx/physxJointHandler.I +++ b/panda/src/physx/physxFixedJointDesc.cxx @@ -1,5 +1,5 @@ -// Filename: physxJointHandler.I -// Created by: pratt (Jul 9, 2006) +// Filename: physxFixedJointDesc.cxx +// Created by: enn0x (28Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,6 +12,5 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX +#include "physxFixedJointDesc.h" -#endif // HAVE_PHYSX diff --git a/panda/src/physx/physxFixedJointDesc.h b/panda/src/physx/physxFixedJointDesc.h new file mode 100644 index 0000000000..c714d5d7ad --- /dev/null +++ b/panda/src/physx/physxFixedJointDesc.h @@ -0,0 +1,47 @@ +// Filename: physxFixedJointDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXFIXEDJOINTDESC_H +#define PHYSXFIXEDJOINTDESC_H + +#include "pandabase.h" + +#include "physxJointDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxFixedJointDesc +// Description : Descriptor class for fixed joint. A fixed joint +// permits no relative movement between two bodies, +// i. e. the bodies are glued together. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxFixedJointDesc : public PhysxJointDesc { + +PUBLISHED: + INLINE PhysxFixedJointDesc(); + INLINE ~PhysxFixedJointDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + +public: + NxJointDesc *ptr() const { return (NxJointDesc *)&_desc; }; + NxFixedJointDesc _desc; +}; + +#include "physxFixedJointDesc.I" + +#endif // PHYSXFIXEDJOINTDESC_H diff --git a/panda/src/physx/physxForceField.I b/panda/src/physx/physxForceField.I new file mode 100644 index 0000000000..8b480b4dde --- /dev/null +++ b/panda/src/physx/physxForceField.I @@ -0,0 +1,60 @@ +// Filename: physxForceField.I +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxForceField:: +PhysxForceField() : PhysxObject() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxForceField:: +~PhysxForceField() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxForceField:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxForceField:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " " << get_name() + << " (at 0x" << this << ")\n"; +} + diff --git a/panda/src/physx/physxForceField.cxx b/panda/src/physx/physxForceField.cxx new file mode 100644 index 0000000000..25401762f5 --- /dev/null +++ b/panda/src/physx/physxForceField.cxx @@ -0,0 +1,160 @@ +// Filename: physxForceField.cxx +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxForceField.h" +#include "physxForceFieldDesc.h" +#include "physxForceFieldShapeGroup.h" +#include "physxScene.h" + +TypeHandle PhysxForceField::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceField:: +link(NxForceField *materialPtr) { + + // Link self + _ptr = materialPtr; + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_forcefields.add(this); + + // Link include shape group + PT(PhysxForceFieldShapeGroup) group = new PhysxForceFieldShapeGroup(); + group->link(&(_ptr->getIncludeShapeGroup())); + _ptr->getIncludeShapeGroup().setName(""); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceField:: +unlink() { + + // Unlink inlcude shape group + PT(PhysxForceFieldShapeGroup) group = (PhysxForceFieldShapeGroup *)(_ptr->getIncludeShapeGroup().userData); + group->unlink(); + + // Unlink self + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_forcefields.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::release +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceField:: +release() { + + nassertv(_error_type == ET_ok); + + unlink(); + _ptr->getScene().releaseForceField(*_ptr); + _ptr = NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::set_name +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceField:: +set_name(const char *name) { + + nassertv(_error_type == ET_ok); + _ptr->setName(name); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::get_name +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +const char *PhysxForceField:: +get_name() const { + + nassertr(_error_type == ET_ok, ""); + return _ptr->getName(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::get_scene +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxScene) PhysxForceField:: +get_scene() const { + + nassertr(_error_type == ET_ok, NULL); + return (PhysxScene *)(_ptr->getScene().userData); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::get_include_shape_group +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxForceFieldShapeGroup) PhysxForceField:: +get_include_shape_group() const { + + nassertr(_error_type == ET_ok, NULL); + return (PhysxForceFieldShapeGroup *)(_ptr->getIncludeShapeGroup().userData); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::get_num_shape_groups +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +unsigned int PhysxForceField:: +get_num_shape_groups() const { + + nassertr(_error_type == ET_ok, NULL); + return _ptr->getNbShapeGroups(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceField::get_shape_group +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxForceFieldShapeGroup) PhysxForceField:: +get_shape_group(unsigned int idx) const { + + nassertr(_error_type == ET_ok, NULL); + nassertr_always(idx < _ptr->getNbShapeGroups(), NULL); + + NxForceFieldShapeGroup *groupPtr; + NxU32 nGroups = _ptr->getNbShapeGroups(); + + _ptr->resetShapeGroupsIterator(); + for (NxU32 i=0; i <= idx; i++) { + groupPtr = _ptr->getNextShapeGroup(); + } + + return (PhysxForceFieldShapeGroup *)(groupPtr->userData); +} + diff --git a/panda/src/physx/physxForceField.h b/panda/src/physx/physxForceField.h new file mode 100644 index 0000000000..d5afcd8786 --- /dev/null +++ b/panda/src/physx/physxForceField.h @@ -0,0 +1,98 @@ +// Filename: physxForceField.h +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXFORCEFIELD_H +#define PHYSXFORCEFIELD_H + +#include "pandabase.h" +#include "lvector3.h" + +#include "physxObject.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxScene; +class PhysxForceFieldDesc; +class PhysxForceFieldShapeGroup; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxForceField +// Description : A force field effector. Instances of this object +// automate the application of forces onto rigid +// bodies, fluid, soft bodies and cloth. +// Force fields allow you to implement for example +// gusts of wind, dust devils, vacuum cleaners or +// anti-gravity zones. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxForceField : public PhysxObject { + +PUBLISHED: + INLINE PhysxForceField(); + INLINE ~PhysxForceField(); + + //void load_from_desc(const PhysxForceFieldDesc &materialDesc); + //void save_to_desc(PhysxForceFieldDesc &materialDesc) const; + + void set_name(const char *name); + + const char *get_name() const; + PT(PhysxScene) get_scene() const; + PT(PhysxForceFieldShapeGroup) get_include_shape_group() const; + + unsigned int get_num_shape_groups() const; + PT(PhysxForceFieldShapeGroup) get_shape_group(unsigned int idx) const; + MAKE_SEQ(get_shape_groups, get_num_shape_groups, get_shape_group); + +//////////////////////////////////////////////////////////////////// +PUBLISHED: + void release(); + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +public: + INLINE NxForceField *ptr() const { return _ptr; }; + + void link(NxForceField *ptr); + void unlink(); + +private: + NxForceField *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxObject::init_type(); + register_type(_type_handle, "PhysxForceField", + PhysxObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxForceField.I" + +#endif // PHYSXFORCEFIELD_H diff --git a/panda/src/physx/physxForceFieldDesc.I b/panda/src/physx/physxForceFieldDesc.I new file mode 100644 index 0000000000..180138f2ad --- /dev/null +++ b/panda/src/physx/physxForceFieldDesc.I @@ -0,0 +1,59 @@ +// Filename: physxForceFieldDesc.I +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxForceFieldDesc:: +PhysxForceFieldDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxForceFieldDesc:: +~PhysxForceFieldDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxForceFieldDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxForceFieldDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxForceFieldDesc.cxx b/panda/src/physx/physxForceFieldDesc.cxx new file mode 100644 index 0000000000..72c35917f4 --- /dev/null +++ b/panda/src/physx/physxForceFieldDesc.cxx @@ -0,0 +1,225 @@ +// Filename: physxForceFieldDesc.cxx +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxForceFieldDesc.h" +#include "physxForceFieldShapeDesc.h" +#include "physxForceFieldShapeGroup.h" +#include "physxManager.h" +#include "physxActor.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_name +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_name(const char *name) { + + _desc.name = name; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_pos +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_pos(const LPoint3f &pos) { + + _desc.pose.t = PhysxManager::point3_to_nxVec3(pos); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_mat +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_mat(const LMatrix4f &mat) { + + _desc.pose = PhysxManager::mat4_to_nxMat34(mat); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_hpr +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_hpr(float h, float p, float r) { + + LQuaternionf q; + LMatrix3f rot; + NxMat34 m; + + q.set_hpr(LVector3f(h, p, r)); + q.extract_to_matrix(rot); + + _desc.pose.M = PhysxManager::mat3_to_nxMat33(rot); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_kernel_constant +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_kernel_constant(const LVector3f &constant) { + + _kernel.constant = PhysxManager::vec3_to_nxVec3(constant); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_kernel_position_target +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_kernel_position_target(const LPoint3f &target) { + + _kernel.positionTarget = PhysxManager::point3_to_nxVec3(target); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_kernel_velocity_target +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_kernel_velocity_target(const LVector3f &target) { + + _kernel.velocityTarget = PhysxManager::vec3_to_nxVec3(target); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_kernel_torus_radius +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_kernel_torus_radius(float radius) { + + _kernel.torusRadius = radius; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_kernel_falloff_linear +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_kernel_falloff_linear(const LVector3f &falloff) { + + _kernel.falloffLinear = PhysxManager::vec3_to_nxVec3(falloff); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_kernel_falloff_quadratic +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_kernel_falloff_quadratic(const LVector3f &falloff) { + + _kernel.falloffQuadratic = PhysxManager::vec3_to_nxVec3(falloff); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_kernel_noise +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_kernel_noise(const LVector3f &noise) { + + _kernel.noise = PhysxManager::vec3_to_nxVec3(noise); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_kernel_position_multiplier +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_kernel_position_multiplier(const LMatrix3f &multiplier) { + + _kernel.positionMultiplier = PhysxManager::mat3_to_nxMat33(multiplier); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_kernel_velocity_multiplier +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_kernel_velocity_multiplier(const LMatrix3f &multiplier) { + + _kernel.velocityMultiplier = PhysxManager::mat3_to_nxMat33(multiplier); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::create_kernel +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +create_kernel(NxScene *scenePtr) { + + _desc.kernel = scenePtr->createForceFieldLinearKernel(_kernel); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_coordinates +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_coordinates(PhysxForceFieldCoordinates coordinates) { + + _desc.coordinates = (NxForceFieldCoordinates) coordinates; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::add_include_group_shape +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +add_include_group_shape(PhysxForceFieldShapeDesc &desc) { + + _desc.includeGroupShapes.push_back(desc.ptr()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::add_shape_group +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +add_shape_group(PT(PhysxForceFieldShapeGroup) group) { + + _desc.shapeGroups.push_back(group->ptr()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldDesc::set_actor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldDesc:: +set_actor(PT(PhysxActor) actor) { + + _desc.actor = actor->ptr(); +} + diff --git a/panda/src/physx/physxForceFieldDesc.h b/panda/src/physx/physxForceFieldDesc.h new file mode 100644 index 0000000000..cfc1098998 --- /dev/null +++ b/panda/src/physx/physxForceFieldDesc.h @@ -0,0 +1,74 @@ +// Filename: physxForceFieldDesc.h +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXFORCEFIELDDESC_H +#define PHYSXFORCEFIELDDESC_H + +#include "pandabase.h" +#include "lvector3.h" +#include "lpoint3.h" +#include "lmatrix.h" + +#include "physxEnums.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxActor; +class PhysxForceFieldShapeDesc; +class PhysxForceFieldShapeGroup; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxForceFieldDesc +// Description : Descriptor class for force fields. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxForceFieldDesc : public PhysxEnums { + +PUBLISHED: + INLINE PhysxForceFieldDesc(); + INLINE ~PhysxForceFieldDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_name(const char *name); + void set_pos(const LPoint3f &pos); + void set_mat(const LMatrix4f &mat); + void set_hpr(float h, float p, float r); + void set_coordinates(PhysxForceFieldCoordinates coordinates); + void set_actor(PT(PhysxActor) actor); + + void set_kernel_constant(const LVector3f &constant); + void set_kernel_position_target(const LPoint3f &target); + void set_kernel_position_multiplier(const LMatrix3f &multiplier); + void set_kernel_velocity_target(const LVector3f &target); + void set_kernel_velocity_multiplier(const LMatrix3f &multiplier); + void set_kernel_torus_radius(float radius); + void set_kernel_falloff_linear(const LVector3f &falloff); + void set_kernel_falloff_quadratic(const LVector3f &falloff); + void set_kernel_noise(const LVector3f &noise); + + void add_include_group_shape(PhysxForceFieldShapeDesc &shapeDesc); + void add_shape_group(PT(PhysxForceFieldShapeGroup) group); + +public: + void create_kernel(NxScene *scenePtr); + + NxForceFieldDesc _desc; + NxForceFieldLinearKernelDesc _kernel; +}; + +#include "physxForceFieldDesc.I" + +#endif // PHYSXFORCEFIELDDESC_H diff --git a/panda/src/physx/physxForceFieldShape.I b/panda/src/physx/physxForceFieldShape.I new file mode 100644 index 0000000000..93d543476e --- /dev/null +++ b/panda/src/physx/physxForceFieldShape.I @@ -0,0 +1,50 @@ +// Filename: physxForceFieldShape.I +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::Constructor +// Access: Protected +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxForceFieldShape:: +PhysxForceFieldShape() : PhysxObject() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxForceFieldShape:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxForceFieldShape:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " " << get_name() + << " (at 0x" << this << ")\n"; +} + diff --git a/panda/src/physx/physxForceFieldShape.cxx b/panda/src/physx/physxForceFieldShape.cxx new file mode 100644 index 0000000000..af63b360ed --- /dev/null +++ b/panda/src/physx/physxForceFieldShape.cxx @@ -0,0 +1,175 @@ +// Filename: physxForceFieldShape.cxx +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxForceFieldShape.h" +#include "physxForceFieldShapeGroup.h" +#include "physxForceField.h" +#include "physxBoxForceFieldShape.h" +#include "physxCapsuleForceFieldShape.h" +#include "physxSphereForceFieldShape.h" +#include "physxConvexForceFieldShape.h" +#include "physxManager.h" + +TypeHandle PhysxForceFieldShape::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::release +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShape:: +release() { + + nassertv(_error_type == ET_ok); + + unlink(); + ptr()->getShapeGroup().releaseShape(*ptr()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::factory +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxForceFieldShape) PhysxForceFieldShape:: +factory(NxShapeType shapeType) { + + switch (shapeType) { + + case NX_SHAPE_SPHERE: + return new PhysxSphereForceFieldShape(); + + case NX_SHAPE_BOX: + return new PhysxBoxForceFieldShape(); + + case NX_SHAPE_CAPSULE: + return new PhysxCapsuleForceFieldShape(); + + case NX_SHAPE_CONVEX: + return new PhysxConvexForceFieldShape(); + } + + physx_cat.error() << "Unknown shape type.\n"; + return NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::get_force_field +// Access: Published +// Description: Returns the owning force field if this is a shape +// of an include group, else NULL will be returned. +//////////////////////////////////////////////////////////////////// +PT(PhysxForceField) PhysxForceFieldShape:: +get_force_field() const { + + nassertr(_error_type == ET_ok, NULL); + + NxForceField *fieldPtr = ptr()->getForceField(); + if (fieldPtr == NULL) { + return NULL; + } + return (PhysxForceField *)(fieldPtr->userData); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::get_shape_group +// Access: Published +// Description: Returns the owning force field shape group. +//////////////////////////////////////////////////////////////////// +PT(PhysxForceFieldShapeGroup) PhysxForceFieldShape:: +get_shape_group() const { + + nassertr(_error_type == ET_ok, NULL); + return (PhysxForceFieldShapeGroup *)(ptr()->getShapeGroup().userData); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::set_name +// Access: Published +// Description: Sets a name string for this object. The name can +// be retrieved again with get_name(). +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShape:: +set_name(const char *name) { + + nassertv(_error_type == ET_ok); + ptr()->setName(name); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::get_name +// Access: Published +// Description: Returns the name string. +//////////////////////////////////////////////////////////////////// +const char *PhysxForceFieldShape:: +get_name() const { + + nassertr(_error_type == ET_ok, ""); + return ptr()->getName(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::set_mat +// Access: Published +// Description: Sets the force field shape's transform. +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShape:: +set_mat(const LMatrix4f &mat) { + + nassertv(_error_type == ET_ok); + + ptr()->setPose(PhysxManager::mat4_to_nxMat34(mat)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::get_mat +// Access: Published +// Description: Returns the force field shape's transform. +//////////////////////////////////////////////////////////////////// +LMatrix4f PhysxForceFieldShape:: +get_mat() const { + + nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat()); + + return PhysxManager::nxMat34_to_mat4(ptr()->getPose()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::set_pos +// Access: Published +// Description: Sets the force field shape's translation. +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShape:: +set_pos(const LPoint3f &pos) { + + nassertv(_error_type == ET_ok); + + NxMat34 pose = ptr()->getPose(); + pose.t = PhysxManager::point3_to_nxVec3(pos); + ptr()->setPose(pose); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShape::get_pos +// Access: Published +// Description: Returns the force field shape's translation. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxForceFieldShape:: +get_pos() const { + + nassertr(_error_type == ET_ok, LPoint3f::zero()); + + return PhysxManager::nxVec3_to_point3(ptr()->getPose().t); +} + diff --git a/panda/src/physx/physxForceFieldShape.h b/panda/src/physx/physxForceFieldShape.h new file mode 100644 index 0000000000..f7e1ee7b7a --- /dev/null +++ b/panda/src/physx/physxForceFieldShape.h @@ -0,0 +1,91 @@ +// Filename: physxForceFieldShape.h +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXFORCEFIELDSHAPE_H +#define PHYSXFORCEFIELDSHAPE_H + +#include "pandabase.h" +#include "pointerTo.h" +#include "lpoint3.h" +#include "lmatrix.h" +#include "lquaternion.h" + +#include "physxObject.h" +#include "physxEnums.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxForceField; +class PhysxForceFieldShapeGroup; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxForceFieldShape +// Description : Abstract base class for force field shapes. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxForceFieldShape : public PhysxObject, public PhysxEnums { + +PUBLISHED: + void release(); + + PT(PhysxForceField) get_force_field() const; + PT(PhysxForceFieldShapeGroup) get_shape_group() const; + + void set_name(const char *name); + void set_mat(const LMatrix4f &mat); + void set_pos(const LPoint3f &pos); + + const char *get_name() const; + LMatrix4f get_mat() const; + LPoint3f get_pos() const; + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +public: + static PT(PhysxForceFieldShape) factory(NxShapeType shapeType); + + virtual NxForceFieldShape *ptr() const = 0; + + virtual void link(NxForceFieldShape *shapePtr) = 0; + virtual void unlink() = 0; + +protected: + INLINE PhysxForceFieldShape(); + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxObject::init_type(); + register_type(_type_handle, "PhysxForceFieldShape", + PhysxObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxForceFieldShape.I" + +#endif // PHYSXFORCEFIELDSHAPE_H diff --git a/panda/src/physx/physxForceFieldShapeDesc.I b/panda/src/physx/physxForceFieldShapeDesc.I new file mode 100644 index 0000000000..70f596151d --- /dev/null +++ b/panda/src/physx/physxForceFieldShapeDesc.I @@ -0,0 +1,26 @@ +// Filename: physxForceFieldShapeDesc.I +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeDesc::Constructor +// Access: Protected +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxForceFieldShapeDesc:: +PhysxForceFieldShapeDesc() { + +} + diff --git a/panda/src/physx/physxForceFieldShapeDesc.cxx b/panda/src/physx/physxForceFieldShapeDesc.cxx new file mode 100644 index 0000000000..e235b218d8 --- /dev/null +++ b/panda/src/physx/physxForceFieldShapeDesc.cxx @@ -0,0 +1,103 @@ +// Filename: physxForceFieldShapeDesc.cxx +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxForceFieldShapeDesc.h" +#include "physxManager.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeDesc::set_name +// Access: Published +// Description: Sets a possible debug name. +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeDesc:: +set_name(const char *name) { + + ptr()->name = name; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeDesc::set_pos +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeDesc:: +set_pos(const LPoint3f &pos) { + + nassertv(!pos.is_nan()); + ptr()->pose.t = PhysxManager::point3_to_nxVec3(pos); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeDesc::set_mat +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeDesc:: +set_mat(const LMatrix4f &mat) { + + nassertv(!mat.is_nan()); + ptr()->pose = PhysxManager::mat4_to_nxMat34(mat); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeDesc::set_hpr +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeDesc:: +set_hpr(float h, float p, float r) { + + LQuaternionf q; + LMatrix3f rot; + NxMat34 m; + + q.set_hpr(LVector3f(h, p, r)); + q.extract_to_matrix(rot); + + ptr()->pose.M = PhysxManager::mat3_to_nxMat33(rot); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeDesc::get_name +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +const char *PhysxForceFieldShapeDesc:: +get_name() const { + + return ptr()->name; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeDesc::get_pos +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxForceFieldShapeDesc:: +get_pos() const { + + return PhysxManager::nxVec3_to_point3(ptr()->pose.t); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeDesc::get_mat +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LMatrix4f PhysxForceFieldShapeDesc:: +get_mat() const { + + return PhysxManager::nxMat34_to_mat4(ptr()->pose); +} + diff --git a/panda/src/physx/physxForceFieldShapeDesc.h b/panda/src/physx/physxForceFieldShapeDesc.h new file mode 100644 index 0000000000..2af9d3acc7 --- /dev/null +++ b/panda/src/physx/physxForceFieldShapeDesc.h @@ -0,0 +1,54 @@ +// Filename: physxForceFieldShapeDesc.h +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXFORCEFIELDSHAPEDESC_H +#define PHYSXFORCEFIELDSHAPEDESC_H + +#include "pandabase.h" +#include "lpoint3.h" +#include "lmatrix.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxForceFieldShapeDesc +// Description : Abstract base class for descriptors for force +// field shapes descriptors. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxForceFieldShapeDesc { + +PUBLISHED: + virtual void set_to_default() = 0; + virtual bool is_valid() const = 0; + + void set_name(const char *name); + void set_pos(const LPoint3f &pos); + void set_mat(const LMatrix4f &mat); + void set_hpr(float h, float p, float r); + + const char *get_name() const; + LPoint3f get_pos() const; + LMatrix4f get_mat() const; + +public: + virtual NxForceFieldShapeDesc *ptr() const = 0; + +protected: + INLINE PhysxForceFieldShapeDesc(); +}; + +#include "physxForceFieldShapeDesc.I" + +#endif // PHYSXFORCEFIELDSHAPEDESC_H diff --git a/panda/src/physx/physxForceFieldShapeGroup.I b/panda/src/physx/physxForceFieldShapeGroup.I new file mode 100644 index 0000000000..cfaa82c2ea --- /dev/null +++ b/panda/src/physx/physxForceFieldShapeGroup.I @@ -0,0 +1,62 @@ +// Filename: physxForceFieldShapeGroup.I +// Created by: enn0x (11Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxForceFieldShapeGroup:: +PhysxForceFieldShapeGroup() : PhysxObject() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxForceFieldShapeGroup:: +~PhysxForceFieldShapeGroup() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxForceFieldShapeGroup:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxForceFieldShapeGroup:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " " << get_name() + << " (at 0x" << this << ")\n"; + + _shapes.ls(out, indent_level); +} + diff --git a/panda/src/physx/physxForceFieldShapeGroup.cxx b/panda/src/physx/physxForceFieldShapeGroup.cxx new file mode 100644 index 0000000000..9239151f95 --- /dev/null +++ b/panda/src/physx/physxForceFieldShapeGroup.cxx @@ -0,0 +1,218 @@ +// Filename: physxForceFieldShapeGroup.cxx +// Created by: enn0x (11Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxForceFieldShapeGroup.h" +#include "physxForceFieldShapeGroupDesc.h" +#include "physxForceField.h" +#include "physxForceFieldShape.h" + +TypeHandle PhysxForceFieldShapeGroup::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeGroup:: +link(NxForceFieldShapeGroup *groupPtr) { + + // Link self + _ptr = groupPtr; + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_ffgroups.add(this); + + // Link shapes + NxU32 nShapes = _ptr->getNbShapes(); + _ptr->resetShapesIterator(); + for (NxU32 i=0; i < nShapes; i++) { + NxForceFieldShape *shapePtr = _ptr->getNextShape(); + PT(PhysxForceFieldShape) shape = PhysxForceFieldShape::factory(shapePtr->getType()); + shape->link(shapePtr); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeGroup:: +unlink() { + + // Unlink shapes + NxU32 nShapes = _ptr->getNbShapes(); + _ptr->resetShapesIterator(); + for (NxU32 i=0; i < nShapes; i++) { + NxForceFieldShape *shapePtr = _ptr->getNextShape(); + PT(PhysxForceFieldShape) shape = (PhysxForceFieldShape *)shapePtr->userData; + shape->unlink(); + } + + // Unlink self + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_ffgroups.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::release +// Access: Published +// Description: Releases the force field shape. +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeGroup:: +release() { + + nassertv(_error_type == ET_ok); + + unlink(); + _ptr->getScene().releaseForceFieldShapeGroup(*_ptr); + _ptr = NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::get_scene +// Access: Published +// Description: Returns the scene that owns this force field shape +// group. +//////////////////////////////////////////////////////////////////// +PT(PhysxScene) PhysxForceFieldShapeGroup:: +get_scene() const { + + nassertr(_error_type == ET_ok, NULL); + return (PhysxScene *)(_ptr->getScene().userData); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::get_force_field +// Access: Published +// Description: Returns the force field of this group if this is +// an include group. If not NULL will be returned. +//////////////////////////////////////////////////////////////////// +PT(PhysxForceField) PhysxForceFieldShapeGroup:: +get_force_field() const { + + nassertr(_error_type == ET_ok, NULL); + + if (_ptr->getForceField() == NULL) { + return NULL; + } + else { + return (PhysxForceField *)(_ptr->getForceField()->userData); + } +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxForceFieldShapeGroup::save_to_desc +// Access : Published +// Description : Saves the state of the force field shape group +// object to a descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeGroup:: +save_to_desc(PhysxForceFieldShapeGroupDesc &groupDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(groupDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::set_name +// Access: Published +// Description: Sets a name string for the object that can be +// retrieved with get_name(). +// This is for debugging and is not used by the +// engine. +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeGroup:: +set_name(const char *name) { + + nassertv(_error_type == ET_ok); + _ptr->setName(name); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::get_name +// Access: Published +// Description: Returns the name string. +//////////////////////////////////////////////////////////////////// +const char *PhysxForceFieldShapeGroup:: +get_name() const { + + nassertr(_error_type == ET_ok, ""); + return _ptr->getName(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::get_num_shapes +// Access: Published +// Description: Returns the number of shapes assigned to the +// force field shape group. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxForceFieldShapeGroup:: +get_num_shapes() const { + + nassertr(_error_type == ET_ok, -1); + + return _ptr->getNbShapes(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::create_shape +// Access: Published +// Description: Creates a force field shape and adds it to the +// group. +//////////////////////////////////////////////////////////////////// +PT(PhysxForceFieldShape) PhysxForceFieldShapeGroup:: +create_shape(PhysxForceFieldShapeDesc &desc) { + + nassertr(_error_type == ET_ok, NULL); + nassertr(desc.is_valid(),NULL); + + PT(PhysxForceFieldShape) shape = PhysxForceFieldShape::factory(desc.ptr()->getType()); + nassertr(shape, NULL); + + NxForceFieldShape *shapePtr = _ptr->createShape(*desc.ptr()); + nassertr(shapePtr, NULL); + + shape->link(shapePtr); + + return shape; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroup::get_shape +// Access: Published +// Description: Returns the i-th shape in the force field group. +//////////////////////////////////////////////////////////////////// +PT(PhysxForceFieldShape) PhysxForceFieldShapeGroup:: +get_shape(unsigned int idx) const { + + nassertr(_error_type == ET_ok, NULL); + nassertr_always(idx < _ptr->getNbShapes(), NULL); + + NxForceFieldShape *shapePtr; + NxU32 nShapes = _ptr->getNbShapes(); + + _ptr->resetShapesIterator(); + for (NxU32 i=0; i <= idx; i++) { + shapePtr = _ptr->getNextShape(); + } + + return (PhysxForceFieldShape *)(shapePtr->userData); +} + diff --git a/panda/src/physx/physxForceFieldShapeGroup.h b/panda/src/physx/physxForceFieldShapeGroup.h new file mode 100644 index 0000000000..bb22db997c --- /dev/null +++ b/panda/src/physx/physxForceFieldShapeGroup.h @@ -0,0 +1,98 @@ +// Filename: physxForceFieldShapeGroup.h +// Created by: enn0x (11Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXFORCEFIELDSHAPEGROUP_H +#define PHYSXFORCEFIELDSHAPEGROUP_H + +#include "pandabase.h" + +#include "physxObject.h" +#include "physxEnums.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxScene; +class PhysxForceField; +class PhysxForceFieldShape; +class PhysxForceFieldShapeDesc; +class PhysxForceFieldShapeGroupDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxForceFieldShapeGroup +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxForceFieldShapeGroup : public PhysxObject, public PhysxEnums { + +PUBLISHED: + INLINE PhysxForceFieldShapeGroup(); + INLINE ~PhysxForceFieldShapeGroup(); + + void save_to_desc(PhysxForceFieldShapeGroupDesc &groupDesc) const; + + PT(PhysxScene) get_scene() const; + PT(PhysxForceField) get_force_field() const; + const char *get_name() const; + + void set_name(const char *name); + + // Shapes + unsigned int get_num_shapes() const; + PT(PhysxForceFieldShape) create_shape(PhysxForceFieldShapeDesc &desc); + PT(PhysxForceFieldShape) get_shape(unsigned int idx) const; + MAKE_SEQ(get_shapes, get_num_shapes, get_shape); + +//////////////////////////////////////////////////////////////////// +PUBLISHED: + void release(); + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +public: + INLINE NxForceFieldShapeGroup *ptr() const { return _ptr; }; + + void link(NxForceFieldShapeGroup *ptr); + void unlink(); + + PhysxObjectCollection _shapes; + +private: + NxForceFieldShapeGroup *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxObject::init_type(); + register_type(_type_handle, "PhysxForceFieldShapeGroup", + PhysxObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxForceFieldShapeGroup.I" + +#endif // PHYSXFORCEFIELDSHAPEGROUP_H diff --git a/panda/src/physx/physxForceFieldShapeGroupDesc.I b/panda/src/physx/physxForceFieldShapeGroupDesc.I new file mode 100644 index 0000000000..a8ee47c586 --- /dev/null +++ b/panda/src/physx/physxForceFieldShapeGroupDesc.I @@ -0,0 +1,59 @@ +// Filename: physxForceFieldShapeGroupDesc.I +// Created by: enn0x (11Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroupDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxForceFieldShapeGroupDesc:: +PhysxForceFieldShapeGroupDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroupDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxForceFieldShapeGroupDesc:: +~PhysxForceFieldShapeGroupDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroupDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxForceFieldShapeGroupDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroupDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxForceFieldShapeGroupDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxForceFieldShapeGroupDesc.cxx b/panda/src/physx/physxForceFieldShapeGroupDesc.cxx new file mode 100644 index 0000000000..ee4260538b --- /dev/null +++ b/panda/src/physx/physxForceFieldShapeGroupDesc.cxx @@ -0,0 +1,81 @@ +// Filename: physxForceFieldShapeGroupDesc.cxx +// Created by: enn0x (11Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxForceFieldShapeGroupDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroupDesc::add_shape +// Access: Published +// Description: Adds a shape to the list of force field shapes +// composing this shape group. +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeGroupDesc:: +add_shape(PhysxForceFieldShapeDesc &desc) { + + _desc.shapes.push_back(desc.ptr()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroupDesc::set_name +// Access: Published +// Description: Sets the optional debug name for the force field +// shape group. +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeGroupDesc:: +set_name(const char *name) { + + _desc.name = name; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroupDesc::get_name +// Access: Published +// Description: Returns the optional debug name for this force +// field shape group. +//////////////////////////////////////////////////////////////////// +const char *PhysxForceFieldShapeGroupDesc:: +get_name() const { + + return _desc.name; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroupDesc::set_flag +// Access: Published +// Description: Raise or lower individual force field shape group +// flags. +//////////////////////////////////////////////////////////////////// +void PhysxForceFieldShapeGroupDesc:: +set_flag(const PhysxForceFieldShapeGroupFlag flag, bool value) { + + if (value == true) { + _desc.flags |= flag; + } + else { + _desc.flags &= ~(flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxForceFieldShapeGroupDesc::get_flag +// Access: Published +// Description: Returns the specified force field shape group +// flag. +//////////////////////////////////////////////////////////////////// +bool PhysxForceFieldShapeGroupDesc:: +get_flag(const PhysxForceFieldShapeGroupFlag flag) const { + + return (_desc.flags & flag) ? true : false; +} + diff --git a/panda/src/physx/physxForceFieldShapeGroupDesc.h b/panda/src/physx/physxForceFieldShapeGroupDesc.h new file mode 100644 index 0000000000..23903ce8f1 --- /dev/null +++ b/panda/src/physx/physxForceFieldShapeGroupDesc.h @@ -0,0 +1,54 @@ +// Filename: physxForceFieldShapeGroupDesc.h +// Created by: enn0x (11Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXFORCEFIELDSHAPEGROUPDESC_H +#define PHYSXFORCEFIELDSHAPEGROUPDESC_H + +#include "pandabase.h" + +#include "physxEnums.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxForceFieldShapeDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxForceFieldShapeGroupDesc +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxForceFieldShapeGroupDesc : public PhysxEnums { + +PUBLISHED: + INLINE PhysxForceFieldShapeGroupDesc(); + INLINE ~PhysxForceFieldShapeGroupDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void add_shape(PhysxForceFieldShapeDesc &desc); + + void set_name(const char *name); + void set_flag(PhysxForceFieldShapeGroupFlag flag, bool value); + + const char *get_name() const; + bool get_flag(PhysxForceFieldShapeGroupFlag flag) const; + +public: + NxForceFieldShapeGroupDesc _desc; +}; + +#include "physxForceFieldShapeGroupDesc.I" + +#endif // PHYSXFORCEFIELDSHAPEGROUPDESC_H diff --git a/panda/src/physx/physxGroupsMask.I b/panda/src/physx/physxGroupsMask.I new file mode 100644 index 0000000000..3e23b9c611 --- /dev/null +++ b/panda/src/physx/physxGroupsMask.I @@ -0,0 +1,160 @@ +// Filename: physxGroupsMask.cxx +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxGroupsMask:: +PhysxGroupsMask() { + + _mask.bits0 = 0x00000000; + _mask.bits1 = 0x00000000; + _mask.bits2 = 0x00000000; + _mask.bits3 = 0x00000000; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxGroupsMask:: +PhysxGroupsMask(NxGroupsMask mask) + : _mask(mask) { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxGroupsMask:: +~PhysxGroupsMask() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::get_mask +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE NxGroupsMask PhysxGroupsMask:: +get_mask() const { + + return _mask; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::set_mask +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxGroupsMask:: +set_mask(NxGroupsMask mask) { + + _mask = mask; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::get_bits0 +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE unsigned int PhysxGroupsMask:: +get_bits0() const { + + return _mask.bits0; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::set_bits0 +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxGroupsMask:: +set_bits0(unsigned int bits) { + + _mask.bits0 = (NxU32) bits; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::get_bits1 +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE unsigned int PhysxGroupsMask:: +get_bits1() const { + + return _mask.bits1; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::set_bits1 +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxGroupsMask:: +set_bits1(unsigned int bits) { + + _mask.bits1 = (NxU32) bits; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::get_bits2 +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE unsigned int PhysxGroupsMask:: +get_bits2() const { + + return _mask.bits2; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::set_bits2 +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxGroupsMask:: +set_bits2(unsigned int bits) { + + _mask.bits2 = (NxU32) bits; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::get_bits3 +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE unsigned int PhysxGroupsMask:: +get_bits3() const { + + return _mask.bits3; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::set_bits3 +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxGroupsMask:: +set_bits3(unsigned int bits) { + + _mask.bits3 = (NxU32) bits; +} + diff --git a/panda/src/physx/physxGroupsMask.cxx b/panda/src/physx/physxGroupsMask.cxx new file mode 100644 index 0000000000..44e370cf14 --- /dev/null +++ b/panda/src/physx/physxGroupsMask.cxx @@ -0,0 +1,156 @@ +// Filename: physxGroupsMask.cxx +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxGroupsMask.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::all_on +// Access: Published +// Description: Returns a PhysxGroupsMask whose bits are all on. +//////////////////////////////////////////////////////////////////// +PhysxGroupsMask PhysxGroupsMask:: +all_on() { + + PhysxGroupsMask mask; + mask._mask.bits0 = 0xffffffff; + mask._mask.bits1 = 0xffffffff; + mask._mask.bits2 = 0xffffffff; + mask._mask.bits3 = 0xffffffff; + return mask; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::all_off +// Access: Published +// Description: Returns a PhysxGroupsMask whose bits are all off. +//////////////////////////////////////////////////////////////////// +PhysxGroupsMask PhysxGroupsMask:: +all_off() { + + PhysxGroupsMask mask; + + mask._mask.bits0 = 0x0000000; + mask._mask.bits1 = 0x0000000; + mask._mask.bits2 = 0x0000000; + mask._mask.bits3 = 0x0000000; + + return mask; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::set_bit +// Access: Published +// Description: Sets the nth bit on. +// Index must be in the range [0, 127]. +//////////////////////////////////////////////////////////////////// +void PhysxGroupsMask:: +set_bit(unsigned int idx) { + + nassertv_always(idx >= 0 && idx <= 127); + + NxU32 bits = 1 << (idx % 32); + + if (idx < 32) { + _mask.bits0 |= bits; + } + else if (idx < 64) { + _mask.bits1 |= bits; + } + else if (idx < 96) { + _mask.bits2 |= bits; + } + else { + _mask.bits3 |= bits; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::clear_bit +// Access: Published +// Description: Sets the nth bit off. +// Index must be in the range [0, 127]. +//////////////////////////////////////////////////////////////////// +void PhysxGroupsMask:: +clear_bit(unsigned int idx) { + + nassertv_always(idx >= 0 && idx <= 127); + + NxU32 bits = 1 << (idx % 32); + + if (idx < 32) { + _mask.bits0 = _mask.bits0 & ~bits; + } + else if (idx < 64) { + _mask.bits1 = _mask.bits1 & ~bits; + } + else if (idx < 96) { + _mask.bits2 = _mask.bits2 & ~bits; + } + else { + _mask.bits3 = _mask.bits3 & ~bits; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::get_bit +// Access: Published +// Description: Returns true if the nth bit is set, false if it is +// cleared. +// Index must be in the range [0, 127]. +//////////////////////////////////////////////////////////////////// +bool PhysxGroupsMask:: +get_bit(unsigned int idx) const { + + nassertr_always(idx >= 0 && idx <= 127, false); + + NxU32 bits = 1 << (idx % 32); + + if (idx < 32) { + return (_mask.bits0 & bits) ? true : false; + } + else if (idx < 64) { + return (_mask.bits1 & bits) ? true : false; + } + else if (idx < 96) { + return (_mask.bits2 & bits) ? true : false; + } + else { + return (_mask.bits3 & bits) ? true : false; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxGroupsMask::output +// Access: Published +// Description: Writes the PhysxGroupsMask out as a list of ones and +// zeros. +//////////////////////////////////////////////////////////////////// +void PhysxGroupsMask:: +output(ostream &out) const { + + string name0; + string name1; + string name2; + string name3; + + for (int i=0; i<32; i++) { + name0 += (_mask.bits0 & (1 << i)) ? '1' : '0'; + name1 += (_mask.bits1 & (1 << i)) ? '1' : '0'; + name2 += (_mask.bits2 & (1 << i)) ? '1' : '0'; + name3 += (_mask.bits3 & (1 << i)) ? '1' : '0'; + } + + out << "/" << name0 << "-" << name1 << "-" << name2 << "-" << name3 << "/"; +} + diff --git a/panda/src/physx/physxGroupsMask.h b/panda/src/physx/physxGroupsMask.h new file mode 100644 index 0000000000..df59424d40 --- /dev/null +++ b/panda/src/physx/physxGroupsMask.h @@ -0,0 +1,67 @@ +// Filename: physxGroupsMask.h +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXGROUPSMASK_H +#define PHYSXGROUPSMASK_H + +#include "pandabase.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxGroupsMask +// Description : 128-bit bitmask class. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxGroupsMask { + +PUBLISHED: + INLINE PhysxGroupsMask(); + INLINE PhysxGroupsMask(NxGroupsMask mask); + INLINE ~PhysxGroupsMask(); + + void set_bit(unsigned int idx); + void clear_bit(unsigned int idx); + bool get_bit(unsigned int idx) const; + + void output(ostream &out) const; + + static PhysxGroupsMask all_on(); + static PhysxGroupsMask all_off(); + + INLINE unsigned int get_bits0() const; + INLINE unsigned int get_bits1() const; + INLINE unsigned int get_bits2() const; + INLINE unsigned int get_bits3() const; + + INLINE void set_bits0( unsigned int bits ); + INLINE void set_bits1( unsigned int bits ); + INLINE void set_bits2( unsigned int bits ); + INLINE void set_bits3( unsigned int bits ); + +public: + INLINE NxGroupsMask get_mask() const; + INLINE void set_mask(NxGroupsMask mask); + + NxGroupsMask _mask; +}; + +INLINE ostream &operator << (ostream &out, const PhysxGroupsMask &mask) { + mask.output(out); + return out; +} + +#include "physxGroupsMask.I" + +#endif // PHYSXGROUPSMASK_H diff --git a/panda/src/physx/physxHeightField.I b/panda/src/physx/physxHeightField.I new file mode 100644 index 0000000000..fde2ec7e88 --- /dev/null +++ b/panda/src/physx/physxHeightField.I @@ -0,0 +1,59 @@ +// Filename: physxHeightField.I +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightField::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxHeightField:: +PhysxHeightField() : PhysxObject() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightField::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxHeightField:: +~PhysxHeightField() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightField::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxHeightField:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightField::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxHeightField:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " (at 0x" << this << ")\n"; +} + diff --git a/panda/src/physx/physxHeightField.cxx b/panda/src/physx/physxHeightField.cxx new file mode 100644 index 0000000000..2543921656 --- /dev/null +++ b/panda/src/physx/physxHeightField.cxx @@ -0,0 +1,82 @@ +// Filename: physxHeightField.cxx +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxHeightField.h" + +TypeHandle PhysxHeightField::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightField::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightField:: +link(NxHeightField *hfPtr) { + + PhysxManager::get_global_ptr()->_heightfields.add(this); + _ptr = hfPtr; + _error_type = ET_ok; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightField::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightField:: +unlink() { + + _error_type = ET_released; + PhysxManager::get_global_ptr()->_heightfields.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightField::release +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightField:: +release() { + + nassertv(_error_type == ET_ok); + + unlink(); + NxGetPhysicsSDK()->releaseHeightField(*_ptr); + _ptr = NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightField::get_height +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxHeightField:: +get_height(float x, float y) const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getHeight(x, y); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightField::get_reference_count +// Access: Published +// Description: Returns the reference count for shared meshes. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxHeightField:: +get_reference_count() const { + + nassertr(_error_type == ET_ok, 0); + return _ptr->getReferenceCount(); +} + diff --git a/panda/src/physx/physxHeightField.h b/panda/src/physx/physxHeightField.h new file mode 100644 index 0000000000..ada7e70c35 --- /dev/null +++ b/panda/src/physx/physxHeightField.h @@ -0,0 +1,98 @@ +// Filename: physxHeightField.h +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXHEIGHTFIELD_H +#define PHYSXHEIGHTFIELD_H + +#include "pandabase.h" +#include "lvector3.h" + +#include "physxObject.h" +#include "physxContactReport.h" +#include "physxControllerReport.h" +#include "physxTriggerReport.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxHeightField +// Description : A height field object. +// Height fields work in a similar way as triangle +// meshes specified to act as height fields, with +// some important differences: +// +// Triangle meshes can be made of nonuniform geometry, +// while height fields are regular, rectangular grids. +// This means that with PhysxHeightField, you +// sacrifice flexibility in return for improved +// performance and decreased memory consumption. +// +// Height fields are referenced by shape instances of +// type PhysxHeightFieldShape. +// +// To create an instance of this class call +// PhysxManager::create_height_field(), and +// PhysxHeightField::release() to release it. This is +// only possible once you have released all of its +// PhysxHeightFiedShape instances before. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxHeightField : public PhysxObject { + +PUBLISHED: + void release(); + + unsigned int get_reference_count() const; + float get_height(float x, float y) const; + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +public: + INLINE PhysxHeightField(); + INLINE ~PhysxHeightField(); + + INLINE NxHeightField *ptr() const { return _ptr; }; + + void link(NxHeightField *ptr); + void unlink(); + +private: + NxHeightField *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxObject::init_type(); + register_type(_type_handle, "PhysxHeightField", + PhysxObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxHeightField.I" + +#endif // PHYSXHEIGHTFIELD_H diff --git a/panda/src/physx/physxHeightFieldDesc.I b/panda/src/physx/physxHeightFieldDesc.I new file mode 100644 index 0000000000..19623497be --- /dev/null +++ b/panda/src/physx/physxHeightFieldDesc.I @@ -0,0 +1,99 @@ +// Filename: physxHeightFieldDesc.I +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxHeightFieldDesc:: +PhysxHeightFieldDesc() { + + _samples = NULL; + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxHeightFieldDesc:: +~PhysxHeightFieldDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxHeightFieldDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxHeightFieldDesc:: +is_valid() const { + + return _desc.isValid(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::set_size +// Access: Private +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxHeightFieldDesc:: +set_size(unsigned int num_rows, unsigned int num_columns) { + + if (_samples) { + unset_size(); + } + + _desc.format = NX_HF_S16_TM; + _desc.nbRows = (NxU32) num_rows; + _desc.nbColumns = (NxU32) num_columns; + _desc.sampleStride = sizeof(NxU32); + + _samples = new NxU32[_desc.nbColumns * _desc.nbRows]; + _desc.samples = _samples; + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::unset_size +// Access: Private +// Description: Releases the memory allocated for the height field +// samples. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxHeightFieldDesc:: +unset_size() { + + if (_samples) { + _desc.nbRows = (NxU32) 0; + _desc.nbColumns = (NxU32) 0; + _desc.samples = NULL; + delete[] _samples; + } +} + diff --git a/panda/src/physx/physxHeightFieldDesc.cxx b/panda/src/physx/physxHeightFieldDesc.cxx new file mode 100644 index 0000000000..5027652d3f --- /dev/null +++ b/panda/src/physx/physxHeightFieldDesc.cxx @@ -0,0 +1,135 @@ +// Filename: physxHeightFieldDesc.cxx +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxHeightFieldDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::set_convex_edge_threshold +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldDesc:: +set_convex_edge_threshold(float threshold) { + + _desc.convexEdgeThreshold = threshold; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::set_thickness +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldDesc:: +set_thickness(float thickness) { + + _desc.thickness = thickness; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::set_image +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldDesc:: +set_image(const PNMImage &image, unsigned short materialIndex) { + + NxU32 _32K = 32767; // (1<<15)-1; + NxU32 _64K = 65535; // (1<<16)-1; + + NxU32 nbRows = image.get_x_size(); + NxU32 nbColumns = image.get_y_size(); + + set_size(nbRows, nbColumns); + + NxU8 *currentByte = (NxU8 *)(_desc.samples); + + for (NxU32 row=0; row < nbRows; row++) { + for (NxU32 column=0; column < nbColumns; column++) { + + NxHeightFieldSample* currentSample = (NxHeightFieldSample *)currentByte; + + NxReal fvalue = image.get_bright(row, column); + NxI16 ivalue = (NxI16)((fvalue - 0.5f) * _32K); + + currentSample->height = (NxI16)ivalue; + currentSample->tessFlag = (NxU8)0; + currentSample->materialIndex0 = (NxU8)materialIndex; + currentSample->materialIndex1 = (NxU8)materialIndex; + + currentByte += _desc.sampleStride; + } + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::set_material_index +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldDesc:: +set_material_index(unsigned int row, unsigned int column, unsigned short materialIndex0, unsigned short materialIndex1) { + + nassertv(_desc.samples); + nassertv(row < _desc.nbRows); + nassertv(column < _desc.nbColumns); + + NxU32 idx = row * _desc.nbColumns + column; + NxU8 *byte = (NxU8 *)_desc.samples + _desc.sampleStride * idx; + NxHeightFieldSample* sample = (NxHeightFieldSample *)byte; + + //NxHeightFieldSample* sample = ((NxHeightFieldSample *)_desc.samples) + idx; + + sample->materialIndex0 = (NxU8)materialIndex0; + sample->materialIndex1 = (NxU8)materialIndex1; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::set_height +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldDesc:: +set_height(unsigned int row, unsigned int column, short height) { + + nassertv(_desc.samples); + nassertv(row < _desc.nbRows); + nassertv(column < _desc.nbColumns); + + NxU32 idx = row * _desc.nbColumns + column; + NxU8 *byte = (NxU8 *)_desc.samples + _desc.sampleStride * idx; + NxHeightFieldSample* sample = (NxHeightFieldSample *)byte; + + sample->height = (NxI16)height; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldDesc::set_tess_flag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldDesc:: +set_tess_flag(unsigned int row, unsigned int column, unsigned short value) { + + nassertv(_desc.samples); + nassertv(row < _desc.nbRows); + nassertv(column < _desc.nbColumns); + + NxU32 idx = row * _desc.nbColumns + column; + NxU8 *byte = (NxU8 *)_desc.samples + _desc.sampleStride * idx; + NxHeightFieldSample* sample = (NxHeightFieldSample *)byte; + + nassertv(value < 2); + sample->tessFlag = (NxU8)value; +} + diff --git a/panda/src/physx/physxHeightFieldDesc.h b/panda/src/physx/physxHeightFieldDesc.h new file mode 100644 index 0000000000..f8ca4e822f --- /dev/null +++ b/panda/src/physx/physxHeightFieldDesc.h @@ -0,0 +1,63 @@ +// Filename: physxHeightFieldDesc.h +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXHEIGHTFIELDDESC_H +#define PHYSXHEIGHTFIELDDESC_H + +#include "pandabase.h" +#include "pnmImage.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxHeightFieldDesc +// Description : Descriptor class for height fields. The height +// field data is copied when a PhysxHeightField object +// is created from this descriptor. After the call +// the user may discard the original height data (e.g. +// release the PNGImage). +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxHeightFieldDesc { + +PUBLISHED: + INLINE PhysxHeightFieldDesc(); + INLINE ~PhysxHeightFieldDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + INLINE void set_size(unsigned int num_rows, unsigned int num_columns); + + void set_image(const PNMImage &image, unsigned short materialIndex=0); + void set_thickness(float thickness); + void set_convex_edge_threshold(float threshold); + + void set_height(unsigned int row, unsigned int column, short height); + void set_tess_flag(unsigned int row, unsigned int column, unsigned short value); + void set_material_index(unsigned int row, unsigned int column, + unsigned short materialIndex0, unsigned short materialIndex1); + +public: + NxHeightFieldDesc _desc; + +private: + NxU32 *_samples; + + INLINE void unset_size(); +}; + +#include "physxHeightFieldDesc.I" + +#endif // PHYSXHEIGHTFIELDDESC_H diff --git a/panda/src/physx/physxHeightFieldShape.I b/panda/src/physx/physxHeightFieldShape.I new file mode 100644 index 0000000000..3a6fd84560 --- /dev/null +++ b/panda/src/physx/physxHeightFieldShape.I @@ -0,0 +1,36 @@ +// Filename: physxHeightFieldShape.I +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxHeightFieldShape:: +PhysxHeightFieldShape() : PhysxShape() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxHeightFieldShape:: +~PhysxHeightFieldShape() { + +} + diff --git a/panda/src/physx/physxHeightFieldShape.cxx b/panda/src/physx/physxHeightFieldShape.cxx new file mode 100644 index 0000000000..71b5291533 --- /dev/null +++ b/panda/src/physx/physxHeightFieldShape.cxx @@ -0,0 +1,63 @@ +// Filename: physxHeightFieldShape.cxx +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxHeightFieldShape.h" +#include "physxHeightFieldShapeDesc.h" + +TypeHandle PhysxHeightFieldShape::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShape::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldShape:: +link(NxShape *shapePtr) { + + _ptr = shapePtr->isHeightField(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShape::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldShape:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxHeightFieldShape::save_to_desc +// Access : Published +// Description : Saves the state of the shape object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldShape:: +save_to_desc(PhysxHeightFieldShapeDesc &shapeDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); +} + diff --git a/panda/src/physx/physxHeightFieldShape.h b/panda/src/physx/physxHeightFieldShape.h new file mode 100644 index 0000000000..bc07b92bd6 --- /dev/null +++ b/panda/src/physx/physxHeightFieldShape.h @@ -0,0 +1,84 @@ +// Filename: physxHeightFieldShape.h +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXHEIGHTFIELDSHAPE_H +#define PHYSXHEIGHTFIELDSHAPE_H + +#include "pandabase.h" + +#include "physxShape.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxHeightFieldShapeDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxHeightFieldShape +// Description : This class is a shape instance of a height field +// object of type PhysxHeightField. Each shape is +// owned by an actor that it is attached to. +// +// An instance can be created by calling the +// createShape() method of the PhysxActor object that +// should own it, with a PhysxHeightFieldShapeDesc +// object as the parameter, or by adding the shape +// descriptor into the PhysxActorDesc class before +// creating the actor. +// +// The shape is deleted by calling release() on the +// shape itself. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxHeightFieldShape : public PhysxShape { + +PUBLISHED: + INLINE PhysxHeightFieldShape(); + INLINE ~PhysxHeightFieldShape(); + + void save_to_desc(PhysxHeightFieldShapeDesc &shapeDesc) const; + +public: + INLINE NxShape *ptr() const { return (NxShape *)_ptr; }; + + void link(NxShape *shapePtr); + void unlink(); + +private: + NxHeightFieldShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxShape::init_type(); + register_type(_type_handle, "PhysxHeightFieldShape", + PhysxShape::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxHeightFieldShape.I" + +#endif // PHYSXHEIGHTFIELDSHAPE_H diff --git a/panda/src/physx/physxHeightFieldShapeDesc.I b/panda/src/physx/physxHeightFieldShapeDesc.I new file mode 100644 index 0000000000..578cd6a0ac --- /dev/null +++ b/panda/src/physx/physxHeightFieldShapeDesc.I @@ -0,0 +1,48 @@ +// Filename: physxHeightFieldShapeDesc.I +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShapeDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxHeightFieldShapeDesc:: +PhysxHeightFieldShapeDesc() : PhysxShapeDesc() { + + set_to_default(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxHeightFieldShapeDesc:: +~PhysxHeightFieldShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxHeightFieldShapeDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxHeightFieldShapeDesc.cxx b/panda/src/physx/physxHeightFieldShapeDesc.cxx new file mode 100644 index 0000000000..07c53d68c3 --- /dev/null +++ b/panda/src/physx/physxHeightFieldShapeDesc.cxx @@ -0,0 +1,118 @@ +// Filename: physxHeightFieldShapeDesc.cxx +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxHeightFieldShapeDesc.h" +#include "physxHeightField.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldShapeDesc:: +set_to_default() { + + _desc.setToDefault(); + + _desc.name = ""; + + _desc.shapeFlags = NX_SF_FEATURE_INDICES | NX_SF_VISUALIZATION; + _desc.meshFlags = NX_MESH_SMOOTH_SPHERE_COLLISIONS; + _desc.materialIndexHighBits = (NxMaterialIndex)0; + _desc.holeMaterial = (NxMaterialIndex)0; + _desc.localPose = PhysxManager::mat4_to_nxMat34(LMatrix4f::y_to_z_up_mat()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShapeDesc::set_hole_material +// Access: Published +// Description: Sets the the material index that designates holes +// in the height field. This number is compared +// directly to sample materials. Consequently the +// high 9 bits must be zero. +// Default value is 0. +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldShapeDesc:: +set_hole_material(unsigned short index) { + + _desc.holeMaterial = (NxMaterialIndex)index; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShapeDesc::set_material_index_high_bits +// Access: Published +// Description: Sets the high 9 bits of this number are used to +// complete the material indices in the samples. The +// remaining low 7 bits must be zero. +// Default value is 0. +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldShapeDesc:: +set_material_index_high_bits(unsigned short index) { + + _desc.materialIndexHighBits = (NxMaterialIndex)index; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShapeDesc::get_hole_material +// Access: Published +// Description: Returns the the material index that designates +// holes in the height field. +//////////////////////////////////////////////////////////////////// +unsigned short PhysxHeightFieldShapeDesc:: +get_hole_material() const { + + return (unsigned short)_desc.holeMaterial; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShapeDesc::get_material_index_hight_bits +// Access: Published +// Description: Returns the high 9 bits of this number are used to +// complete the material indices in the samples. +//////////////////////////////////////////////////////////////////// +unsigned short PhysxHeightFieldShapeDesc:: +get_material_index_hight_bits() const { + + return (unsigned short)_desc.materialIndexHighBits; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShapeDesc::set_dimensions +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldShapeDesc:: +set_dimensions(const LVector3f &dimensions) { + + NxU32 _64K = 65535; // (1<<16)-1; + + NxU32 nbRows = _desc.heightField->getNbRows(); + NxU32 nbColumns = _desc.heightField->getNbColumns(); + + _desc.rowScale = dimensions.get_x() / nbRows; + _desc.columnScale = dimensions.get_y() / nbColumns; + _desc.heightScale = dimensions.get_z() / _64K; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxHeightFieldShapeDesc::set_height_field +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxHeightFieldShapeDesc:: +set_height_field(const PhysxHeightField &hf) { + + _desc.heightField = hf.ptr(); +} + diff --git a/panda/src/physx/physxHeightFieldShapeDesc.h b/panda/src/physx/physxHeightFieldShapeDesc.h new file mode 100644 index 0000000000..38c5e187cb --- /dev/null +++ b/panda/src/physx/physxHeightFieldShapeDesc.h @@ -0,0 +1,55 @@ +// Filename: physxHeightFieldShapeDesc.h +// Created by: enn0x (15Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXHEIGHTFIELDSHAPEDESC_H +#define PHYSXHEIGHTFIELDSHAPEDESC_H + +#include "pandabase.h" + +#include "physxShapeDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxHeightField; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxHeightFieldShapeDesc +// Description : Descriptor class for PhysxHeightFieldShape. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxHeightFieldShapeDesc : public PhysxShapeDesc { + +PUBLISHED: + INLINE PhysxHeightFieldShapeDesc(); + INLINE ~PhysxHeightFieldShapeDesc(); + + void set_to_default(); + INLINE bool is_valid() const; + + void set_height_field(const PhysxHeightField &hf); + void set_dimensions(const LVector3f &dimensions); + void set_hole_material(unsigned short index); + void set_material_index_high_bits(unsigned short index); + + unsigned short get_hole_material() const; + unsigned short get_material_index_hight_bits() const; + +public: + NxShapeDesc *ptr() const { return (NxShapeDesc *)&_desc; }; + NxHeightFieldShapeDesc _desc; +}; + +#include "physxHeightFieldShapeDesc.I" + +#endif // PHYSXHEIGHTFIELDSHAPEDESC_H diff --git a/panda/src/physx/physxJoint.I b/panda/src/physx/physxJoint.I index 9230f621c9..bc97ba65a9 100644 --- a/panda/src/physx/physxJoint.I +++ b/panda/src/physx/physxJoint.I @@ -1,5 +1,5 @@ // Filename: physxJoint.I -// Created by: pratt (Jun 16, 2006) +// Created by: enn0x (02Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,38 +15,49 @@ //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : Returns true if the NxJoint associated with this -// Joint is not NULL. The NxJoint will be NULL if -// the Joint has been released. +// Function: PhysxJoint::Constructor +// Access: Protected +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxJoint:: -is_valid() { - return nJoint != NULL; +INLINE PhysxJoint:: +PhysxJoint() : PhysxObject() { + } //////////////////////////////////////////////////////////////////// -// Function : get_app_data -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void * PhysxJoint:: -get_app_data() const { - nassertr(nJoint != NULL, NULL); - - return nJoint->appData; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_app_data -// Access : Published -// Description : +// Function: PhysxJoint::ls +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// INLINE void PhysxJoint:: -set_app_data(void * value) { - nassertv(nJoint != NULL); +ls() const { - nJoint->appData = value; + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJoint::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxJoint:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " " << get_name( ) + << " (at 0x" << this << ")"; + + NxActor *actorPtr[2]; + ptr()->getActors(&actorPtr[0], &actorPtr[1]); + + if (actorPtr[0]) { + out << " A1:0x" << actorPtr[0]->userData; + } + + if (actorPtr[1]) { + out << " A2:0x" << actorPtr[1]->userData; + } + + out << "\n"; } diff --git a/panda/src/physx/physxJoint.cxx b/panda/src/physx/physxJoint.cxx index 28548c0834..c745787849 100644 --- a/panda/src/physx/physxJoint.cxx +++ b/panda/src/physx/physxJoint.cxx @@ -1,5 +1,5 @@ // Filename: physxJoint.cxx -// Created by: pratt (Jun 16, 2006) +// Created by: enn0x (02Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,249 +12,335 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxJoint.h" - -#include "luse.h" -#include "physxD6Joint.h" +#include "physxManager.h" +#include "physxActor.h" #include "physxScene.h" +#include "physxCylindricalJoint.h" +#include "physxDistanceJoint.h" +#include "physxFixedJoint.h" +#include "physxPointInPlaneJoint.h" +#include "physxPointOnLineJoint.h" +#include "physxPrismaticJoint.h" +#include "physxPulleyJoint.h" +#include "physxRevoluteJoint.h" +#include "physxSphericalJoint.h" +#include "physxD6Joint.h" TypeHandle PhysxJoint::_type_handle; //////////////////////////////////////////////////////////////////// -// Function : add_limit_plane -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxJoint:: -add_limit_plane(const LVecBase3f & normal, const LVecBase3f & point_in_plane, float restitution) { - nassertr(nJoint != NULL, false); - - return nJoint->addLimitPlane(PhysxManager::lVecBase3_to_nxVec3(normal), PhysxManager::lVecBase3_to_nxVec3(point_in_plane), restitution); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_breakable -// Access : Published -// Description : +// Function: PhysxJoint::release +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// void PhysxJoint:: -get_breakable(float & max_force, float & max_torque) { - nassertv(nJoint != NULL); +release() { - nJoint->getBreakable(max_force, max_torque); + nassertv(_error_type == ET_ok); + + unlink(); + ptr()->getScene().releaseJoint(*ptr()); } //////////////////////////////////////////////////////////////////// -// Function : get_global_anchor -// Access : Published -// Description : +// Function: PhysxJoint::factory +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxJoint:: -get_global_anchor() const { - nassertr(nJoint != NULL, *((LVecBase3f *)NULL)); +PT(PhysxJoint) PhysxJoint:: +factory(NxJointType shapeType) { - return PhysxManager::nxVec3_to_lVecBase3(nJoint->getGlobalAnchor()); + switch (shapeType) { + + case NX_JOINT_PRISMATIC: + return new PhysxPrismaticJoint(); + + case NX_JOINT_REVOLUTE: + return new PhysxRevoluteJoint(); + + case NX_JOINT_CYLINDRICAL: + return new PhysxCylindricalJoint(); + + case NX_JOINT_SPHERICAL: + return new PhysxSphericalJoint(); + + case NX_JOINT_POINT_ON_LINE: + return new PhysxPointOnLineJoint(); + + case NX_JOINT_POINT_IN_PLANE: + return new PhysxPointInPlaneJoint(); + + case NX_JOINT_DISTANCE: + return new PhysxDistanceJoint(); + + case NX_JOINT_PULLEY: + return new PhysxPulleyJoint(); + + case NX_JOINT_FIXED: + return new PhysxFixedJoint(); + + case NX_JOINT_D6: + return new PhysxD6Joint(); + } + + physx_cat.error() << "Unknown joint type.\n"; + return NULL; } //////////////////////////////////////////////////////////////////// -// Function : get_global_axis -// Access : Published -// Description : +// Function: PhysxJoint::set_name +// Access: Published +// Description: Sets a name string for this object. The name can +// be retrieved again with get_name(). +// This is for debugging and is not used by the +// physics engine. //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxJoint:: -get_global_axis() const { - nassertr(nJoint != NULL, *((LVecBase3f *)NULL)); +void PhysxJoint:: +set_name(const char *name) { - return PhysxManager::nxVec3_to_lVecBase3(nJoint->getGlobalAxis()); + nassertv(_error_type == ET_ok); + ptr()->setName(name); } //////////////////////////////////////////////////////////////////// -// Function : get_limit_point -// Access : Published -// Description : +// Function: PhysxJoint::get_name +// Access: Published +// Description: Returns the name string. //////////////////////////////////////////////////////////////////// -bool PhysxJoint:: -get_limit_point(LVecBase3f & world_limit_point) { - nassertr(nJoint != NULL, false); - - return nJoint->getLimitPoint(PhysxManager::lVecBase3_to_nxVec3(world_limit_point)); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_name -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -const char * PhysxJoint:: +const char *PhysxJoint:: get_name() const { - nassertr(nJoint != NULL, NULL); - return nJoint->getName(); + nassertr(_error_type == ET_ok, ""); + return ptr()->getName(); } //////////////////////////////////////////////////////////////////// -// Function : get_next_limit_plane -// Access : Published -// Description : +// Function: PhysxJoint::get_actor +// Access: Published +// Description: Retrieves the actor which this joint is associated +// with. //////////////////////////////////////////////////////////////////// -bool PhysxJoint:: -get_next_limit_plane(LVecBase3f & plane_normal, float & plane_d, float * restitution) { - nassertr(nJoint != NULL, false); +PT(PhysxActor) PhysxJoint:: +get_actor(unsigned int idx) const { - return nJoint->getNextLimitPlane(PhysxManager::lVecBase3_to_nxVec3(plane_normal), plane_d, restitution); + nassertr_always(idx < 2, NULL); + nassertr(_error_type == ET_ok, NULL); + + NxActor *actorPtr[2]; + ptr()->getActors(&actorPtr[0], &actorPtr[1]); + return (PhysxActor *)(actorPtr[idx]->userData); } //////////////////////////////////////////////////////////////////// -// Function : get_scene -// Access : Published -// Description : +// Function: PhysxJoint::get_scene +// Access: Published +// Description: Retrieves the scene which this joint is associated +// with. //////////////////////////////////////////////////////////////////// -PhysxScene & PhysxJoint:: +PT(PhysxScene) PhysxJoint:: get_scene() const { - nassertr(nJoint != NULL, *((PhysxScene *)NULL)); - return *((PhysxScene *)(nJoint->getScene().userData)); + nassertr(_error_type == ET_ok, NULL); + return (PhysxScene *)(ptr()->getScene().userData); } //////////////////////////////////////////////////////////////////// -// Function : get_state -// Access : Published -// Description : +// Function: PhysxJoint::set_global_anchor +// Access: Published +// Description: Sets the point where the two actors are attached, +// specified in global coordinates. //////////////////////////////////////////////////////////////////// -PhysxJointState PhysxJoint:: -get_state() { - nassertr(nJoint != NULL, physx_js_unbound); +void PhysxJoint:: +set_global_anchor(const LPoint3f &anchor) { - return (PhysxJointState)nJoint->getState(); + nassertv(_error_type == ET_ok); + ptr()->setGlobalAnchor(PhysxManager::point3_to_nxVec3(anchor)); } //////////////////////////////////////////////////////////////////// -// Function : has_more_limit_planes -// Access : Published -// Description : +// Function: PhysxJoint::get_global_anchor +// Access: Published +// Description: Retrieves the joint anchor. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxJoint:: +get_global_anchor() const { + + nassertr(_error_type == ET_ok, LPoint3f::zero()); + return PhysxManager::nxVec3_to_point3(ptr()->getGlobalAnchor()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJoint::set_global_axis +// Access: Published +// Description: Sets the direction of the joint's primary axis, +// specified in global coordinates. +//////////////////////////////////////////////////////////////////// +void PhysxJoint:: +set_global_axis(const LVector3f &axis) { + + nassertv(_error_type == ET_ok); + ptr()->setGlobalAxis(PhysxManager::vec3_to_nxVec3(axis)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJoint::get_global_axis +// Access: Published +// Description: Retrieves the joint axis. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxJoint:: +get_global_axis() const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(ptr()->getGlobalAxis()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJoint::set_breakable +// Access: Published +// Description: Sets the maximum force magnitude that the joint +// is able to withstand without breaking. +// +// If the joint force rises above this threshold, the +// joint breaks, and becomes disabled. +// +// There are two values, one for linear forces, and +// one for angular forces. Both values are used +// directly as a value for the maximum impulse +// tolerated by the joint constraints. +// +// Both force values are NX_MAX_REAL by default. +// This setting makes the joint unbreakable. The values +// should always be nonnegative. +// +// The distinction between maxForce and maxTorque is +// dependent on how the joint is implemented +// internally, which may not be obvious. For example +// what appears to be an angular degree of freedom may +// be constrained indirectly by a linear constraint. +// +// So in most practical applications the user should +// set both maxTorque and maxForce to low values. +//////////////////////////////////////////////////////////////////// +void PhysxJoint:: +set_breakable(float maxForce, float maxTorque) { + + nassertv(_error_type == ET_ok); + ptr()->setBreakable(maxForce, maxTorque); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJoint::set_use_acceleration_spring +// Access: Published +// Description: Switch between acceleration and force based spring. +//////////////////////////////////////////////////////////////////// +void PhysxJoint:: +set_use_acceleration_spring(bool value) { + + nassertv(_error_type == ET_ok); + ptr()->setUseAccelerationSpring(value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJoint::get_use_acceleration_spring +// Access: Published +// Description: Checks whether acceleration spring is used. //////////////////////////////////////////////////////////////////// bool PhysxJoint:: -has_more_limit_planes() { - nassertr(nJoint != NULL, false); +get_use_acceleration_spring() const { - return nJoint->hasMoreLimitPlanes(); + nassertr(_error_type == ET_ok, false); + return ptr()->getUseAccelerationSpring(); } //////////////////////////////////////////////////////////////////// -// Function : is -// Access : Published -// Description : +// Function: PhysxJoint::set_solver_extrapolation_factor +// Access: Published +// Description: Sets the solver extrapolation factor. //////////////////////////////////////////////////////////////////// -void * PhysxJoint:: -is(PhysxJointType type) { - nassertr(nJoint != NULL, NULL); +void PhysxJoint:: +set_solver_extrapolation_factor(float factor) { - return nJoint->is((NxJointType)type); + nassertv(_error_type == ET_ok); + ptr()->setSolverExtrapolationFactor(factor); } //////////////////////////////////////////////////////////////////// -// Function : is_d6_joint -// Access : Published -// Description : +// Function: PhysxJoint::get_solver_extrapolation_factor +// Access: Published +// Description: Retrieves the solver extrapolation factor. //////////////////////////////////////////////////////////////////// -PhysxD6Joint * PhysxJoint:: -is_d6_joint() { - nassertr(nJoint != NULL, NULL); +float PhysxJoint:: +get_solver_extrapolation_factor() const { - return (PhysxD6Joint *)(nJoint->isD6Joint()->userData); + nassertr(_error_type == ET_ok, false); + return ptr()->getSolverExtrapolationFactor(); } //////////////////////////////////////////////////////////////////// -// Function : purge_limit_planes -// Access : Published -// Description : +// Function: PhysxJoint::set_limit_point +// Access: Published +// Description: Sets the limit point. +// The point is specified in the global coordinate +// frame. +// +// All types of joints may be limited with the same +// system: You may elect a point attached to one of +// the two actors to act as the limit point. You may +// also specify several planes attached to the other +// actor. +// +// The points and planes move together with the actor +// they are attached to. +// +// The simulation then makes certain that the pair +// of actors only move relative to each other so that +// the limit point stays on the positive side of all +// limit planes. +// +// The default limit point is (0,0,0) in the local +// frame of actor2. Calling this deletes all existing +// limit planes +//////////////////////////////////////////////////////////////////// +void PhysxJoint:: +set_limit_point(const LPoint3f &pos, bool isOnActor2) { + + nassertv(_error_type == ET_ok); + ptr()->setLimitPoint(PhysxManager::point3_to_nxVec3(pos), isOnActor2); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJoint::add_limit_plane +// Access: Published +// Description: Adds a limit plane. +// The parameters are given in global coordinates. +// The plane is affixed to the actor that does not +// have the limit point. +// +// The normal of the plane points toward the positive +// side of the plane, and thus toward the limit point. +// If the normal points away from the limit point at +// the time of this call, the method returns false +// and the limit plane is ignored. +//////////////////////////////////////////////////////////////////// +void PhysxJoint:: +add_limit_plane(const LVector3f &normal, const LPoint3f &pointInPlane, float restitution) { + + nassertv(_error_type == ET_ok); + ptr()->addLimitPlane(PhysxManager::vec3_to_nxVec3(normal), + PhysxManager::point3_to_nxVec3(pointInPlane), + restitution); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJoint::purge_limit_planes +// Access: Published +// Description: Deletes all limit planes added to the joint. //////////////////////////////////////////////////////////////////// void PhysxJoint:: purge_limit_planes() { - nassertv(nJoint != NULL); - nJoint->purgeLimitPlanes(); + nassertv(_error_type == ET_ok); + ptr()->purgeLimitPlanes(); } -//////////////////////////////////////////////////////////////////// -// Function : reset_limit_plane_iterator -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJoint:: -reset_limit_plane_iterator() { - nassertv(nJoint != NULL); - - nJoint->resetLimitPlaneIterator(); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_breakable -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJoint:: -set_breakable(float max_force, float max_torque) { - nassertv(nJoint != NULL); - - nJoint->setBreakable(max_force, max_torque); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_global_anchor -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJoint:: -set_global_anchor(const LVecBase3f & vec) { - nassertv(nJoint != NULL); - - nJoint->setGlobalAnchor(PhysxManager::lVecBase3_to_nxVec3(vec)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_global_axis -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJoint:: -set_global_axis(const LVecBase3f & vec) { - nassertv(nJoint != NULL); - - nJoint->setGlobalAxis(PhysxManager::lVecBase3_to_nxVec3(vec)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_limit_point -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJoint:: -set_limit_point(const LVecBase3f & point, bool point_is_on_actor2) { - nassertv(nJoint != NULL); - - nJoint->setLimitPoint(PhysxManager::lVecBase3_to_nxVec3(point), point_is_on_actor2); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_name -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJoint:: -set_name(const char * name) { - nassertv(nJoint != NULL); - - // Because the PhysX engine does not store its own copy of names, - // we keep a local copy on this instance. Otherwise, it would be - // very easy for names to be declared in python and then - // invalidated when the string is reclaimed from reference - // counting. - _name_store = name; - nJoint->setName(_name_store.c_str()); -} - -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxJoint.h b/panda/src/physx/physxJoint.h index 1b568439de..5709c787b9 100644 --- a/panda/src/physx/physxJoint.h +++ b/panda/src/physx/physxJoint.h @@ -1,5 +1,5 @@ // Filename: physxJoint.h -// Created by: pratt (Jun 16, 2006) +// Created by: enn0x (02Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,63 +15,74 @@ #ifndef PHYSXJOINT_H #define PHYSXJOINT_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "pointerTo.h" +#include "lpoint3.h" +#include "lvector3.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -#include "typedWritableReferenceCount.h" - -class PhysxD6Joint; -class PhysxScene; +#include "physxObject.h" +#include "physxEnums.h" +#include "NoMinMax.h" #include "NxPhysics.h" +class PhysxActor; +class PhysxScene; + //////////////////////////////////////////////////////////////////// // Class : PhysxJoint -// Description : +// Description : Abstract base class for the different types of +// joints. All joints are used to connect two dynamic +// actors, or an actor and the environment. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxJoint : public TypedWritableReferenceCount { +class EXPCL_PANDAPHYSX PhysxJoint : public PhysxObject, public PhysxEnums { + PUBLISHED: - INLINE bool is_valid(); + void release(); + + PT(PhysxActor) get_actor(unsigned int idx) const; + PT(PhysxScene) get_scene() const; - bool add_limit_plane(const LVecBase3f & normal, const LVecBase3f & point_in_plane, float restitution); - void get_breakable(float & max_force, float & max_torque); - LVecBase3f get_global_anchor() const; - LVecBase3f get_global_axis() const; - bool get_limit_point(LVecBase3f & world_limit_point); - const char * get_name() const; - bool get_next_limit_plane(LVecBase3f & plane_normal, float & plane_d, float * restitution); - PhysxScene & get_scene() const; - PhysxJointState get_state(); - bool has_more_limit_planes(); - void * is(PhysxJointType type); - PhysxD6Joint * is_d6_joint(); void purge_limit_planes(); - void reset_limit_plane_iterator(); - void set_breakable(float max_force, float max_torque); - void set_global_anchor(const LVecBase3f & vec); - void set_global_axis(const LVecBase3f & vec); - void set_limit_point(const LVecBase3f & point, bool point_is_on_actor2); - void set_name(const char * name); - INLINE void * get_app_data() const; + void set_name(const char *name); + void set_global_anchor(const LPoint3f &anchor); + void set_global_axis(const LVector3f &axis); + void set_breakable(float maxForce, float maxTorque); + void set_solver_extrapolation_factor(float factor); + void set_use_acceleration_spring(bool value); + void set_limit_point(const LPoint3f &pos, bool isOnActor2=true); + void add_limit_plane(const LVector3f &normal, const LPoint3f &pointInPlane, float restitution=0.0f); - INLINE void set_app_data( void * value ); + const char *get_name() const; + LPoint3f get_global_anchor() const; + LVector3f get_global_axis() const; + float get_solver_extrapolation_factor() const; + bool get_use_acceleration_spring() const; + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; public: - NxJoint *nJoint; + static PT(PhysxJoint) factory(NxJointType shapeType); + virtual NxJoint *ptr() const = 0; + + virtual void link(NxJoint *shapePtr) = 0; + virtual void unlink() = 0; + +protected: + INLINE PhysxJoint(); + +//////////////////////////////////////////////////////////////////// +public: static TypeHandle get_class_type() { return _type_handle; } static void init_type() { - TypedWritableReferenceCount::init_type(); - register_type(_type_handle, "PhysxJoint", - TypedWritableReferenceCount::get_class_type()); + PhysxObject::init_type(); + register_type(_type_handle, "PhysxJoint", + PhysxObject::get_class_type()); } virtual TypeHandle get_type() const { return get_class_type(); @@ -83,12 +94,8 @@ public: private: static TypeHandle _type_handle; - - string _name_store; }; #include "physxJoint.I" -#endif // HAVE_PHYSX - #endif // PHYSXJOINT_H diff --git a/panda/src/physx/physxJointDesc.I b/panda/src/physx/physxJointDesc.I index 3093e51d13..2ada7ec510 100644 --- a/panda/src/physx/physxJointDesc.I +++ b/panda/src/physx/physxJointDesc.I @@ -1,5 +1,5 @@ // Filename: physxJointDesc.I -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (28Sep09) // //////////////////////////////////////////////////////////////////// // @@ -13,131 +13,14 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE bool PhysxJointDesc:: -is_valid() const { - nassertr(nJointDesc != NULL, false); - return nJointDesc->isValid(); +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::Constructor +// Access: Protected +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxJointDesc:: +PhysxJointDesc() { + } -//////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointDesc:: -set_to_default() { - nassertv(nJointDesc != NULL); - - nJointDesc->setToDefault(); -} - - -//////////////////////////////////////////////////////////////////// -// Function : get_joint_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxJointDesc:: -get_joint_flags() const { - nassertr(nJointDesc != NULL, -1); - - return nJointDesc->jointFlags; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_max_force -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxJointDesc:: -get_max_force() const { - nassertr(nJointDesc != NULL, -1.0f); - - return nJointDesc->maxForce; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_max_torque -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxJointDesc:: -get_max_torque() const { - nassertr(nJointDesc != NULL, -1.0f); - - return nJointDesc->maxTorque; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_name -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE const char * PhysxJointDesc:: -get_name() const { - nassertr(nJointDesc != NULL, NULL); - - return nJointDesc->name; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_joint_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointDesc:: -set_joint_flags(unsigned int value) { - nassertv(nJointDesc != NULL); - - nJointDesc->jointFlags = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_max_force -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointDesc:: -set_max_force(float value) { - nassertv(nJointDesc != NULL); - - nJointDesc->maxForce = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_max_torque -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointDesc:: -set_max_torque(float value) { - nassertv(nJointDesc != NULL); - - nJointDesc->maxTorque = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_name -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointDesc:: -set_name(const char * value) { - nassertv(nJointDesc != NULL); - - // Because the PhysX engine does not store its own copy of names, - // we keep a local copy on this instance. Otherwise, it would be - // very easy for names to be declared in python and then - // invalidated when the string is reclaimed from reference - // counting. - _name_store = value; - nJointDesc->name = _name_store.c_str(); -} - - diff --git a/panda/src/physx/physxJointDesc.cxx b/panda/src/physx/physxJointDesc.cxx index ed6ad1acc2..da0ac1aa08 100644 --- a/panda/src/physx/physxJointDesc.cxx +++ b/panda/src/physx/physxJointDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxJointDesc.cxx -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (28Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,140 +12,255 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxJointDesc.h" - -#include "luse.h" -#include "physxActorNode.h" +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxJointDesc -// Access : protected -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointDesc:: -PhysxJointDesc(NxJointDesc *subJointDesc) { - nJointDesc = subJointDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : ~PhysxJointDesc -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointDesc:: -~PhysxJointDesc() { - -} - -//////////////////////////////////////////////////////////////////// -// Function : set_global_anchor -// Access : Published -// Description : +// Function: PhysxJointDesc::set_name +// Access: Published +// Description: Sets a possible debug name. //////////////////////////////////////////////////////////////////// void PhysxJointDesc:: -set_global_anchor(const LVecBase3f & ws_anchor) { - nassertv(nJointDesc != NULL); +set_name(const char *name) { - nJointDesc->setGlobalAnchor(PhysxManager::lVecBase3_to_nxVec3(ws_anchor)); + ptr()->name = name; } //////////////////////////////////////////////////////////////////// -// Function : set_global_axis -// Access : Published -// Description : +// Function: PhysxJointDesc::set_max_force +// Access: Published +// Description: Set a possible debug name. //////////////////////////////////////////////////////////////////// void PhysxJointDesc:: -set_global_axis(const LVecBase3f & ws_axis) { - nassertv(nJointDesc != NULL); +set_max_force(float force) { - nJointDesc->setGlobalAxis(PhysxManager::lVecBase3_to_nxVec3(ws_axis)); + ptr()->maxForce = force; } //////////////////////////////////////////////////////////////////// -// Function : get_local_anchor -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxJointDesc:: -get_local_anchor(int index) const { - nassertr(nJointDesc != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nJointDesc->localAnchor[index]); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_local_axis -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxJointDesc:: -get_local_axis(int index) const { - nassertr(nJointDesc != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nJointDesc->localAxis[index]); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_local_normal -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxJointDesc:: -get_local_normal(int index) const { - nassertr(nJointDesc != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nJointDesc->localNormal[index]); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_actor -// Access : Published -// Description : +// Function: PhysxJointDesc::set_max_torque +// Access: Published +// Description: Set the maximum angular force (torque) that the +// joint can withstand before breaking, must be +// positive. //////////////////////////////////////////////////////////////////// void PhysxJointDesc:: -set_actor(int index, PhysxActorNode * value) { - nassertv(nJointDesc != NULL); +set_max_torque(float torque) { - nJointDesc->actor[index] = value->nActor; + ptr()->maxTorque = torque; } //////////////////////////////////////////////////////////////////// -// Function : set_local_anchor -// Access : Published -// Description : +// Function: PhysxJointDesc::set_solver_extrapolation_factor +// Access: Published +// Description: Set the extrapolation factor for solving joint +// constraints. //////////////////////////////////////////////////////////////////// void PhysxJointDesc:: -set_local_anchor(int index, LVecBase3f value) { - nassertv(nJointDesc != NULL); +set_solver_extrapolation_factor(float factor) { - nJointDesc->localAnchor[index] = PhysxManager::lVecBase3_to_nxVec3(value); + ptr()->solverExtrapolationFactor = factor; } //////////////////////////////////////////////////////////////////// -// Function : set_local_axis -// Access : Published -// Description : +// Function: PhysxJointDesc::set_actor +// Access: Published +// Description: Set the two actors connected by the joint. +// idx must be either 0 or 1. //////////////////////////////////////////////////////////////////// void PhysxJointDesc:: -set_local_axis(int index, LVecBase3f value) { - nassertv(nJointDesc != NULL); +set_actor(unsigned int idx, const PhysxActor &actor) { - nJointDesc->localAxis[index] = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv_always(idx < 2); + ptr()->actor[idx] = actor.ptr(); } //////////////////////////////////////////////////////////////////// -// Function : set_local_normal -// Access : Published -// Description : +// Function: PhysxJointDesc::set_local_normal +// Access: Published +// Description: Set the X axis of joint space, in actor[i]'s space, +// orthogonal to localAxis[i]. +// idx must be either 0 or 1. //////////////////////////////////////////////////////////////////// void PhysxJointDesc:: -set_local_normal(int index, LVecBase3f value) { - nassertv(nJointDesc != NULL); +set_local_normal(unsigned int idx, const LVector3f &normal) { - nJointDesc->localNormal[index] = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv_always(idx < 2); + ptr()->localNormal[idx] = PhysxManager::vec3_to_nxVec3(normal); } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::set_local_axis +// Access: Published +// Description: Set the Z axis of joint space, in actor[i]'s space. +// This is the primary axis of the joint. +// idx must be either 0 or 1. +//////////////////////////////////////////////////////////////////// +void PhysxJointDesc:: +set_local_axis(unsigned int idx, const LVector3f &axis) { + + nassertv_always(idx < 2); + ptr()->localAxis[idx] = PhysxManager::vec3_to_nxVec3(axis); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::set_local_anchor +// Access: Published +// Description: Set the attachment point of joint in actor[i]'s +// space. idx must be either 0 or 1. +//////////////////////////////////////////////////////////////////// +void PhysxJointDesc:: +set_local_anchor(unsigned int idx, const LPoint3f &anchor) { + + nassertv_always(idx < 2); + ptr()->localAnchor[idx] = PhysxManager::point3_to_nxVec3(anchor); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::set_joint_flag +// Access: Published +// Description: Set or clear a single JointFlag. +//////////////////////////////////////////////////////////////////// +void PhysxJointDesc:: +set_joint_flag(PhysxJointFlag flag, bool value) { + + if (value == true) { + ptr()->jointFlags |= flag; + } + else { + ptr()->jointFlags &= ~(flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::set_global_axis +// Access: Published +// Description: Set the local axis/normal using a world space axis. +//////////////////////////////////////////////////////////////////// +void PhysxJointDesc:: +set_global_axis(const LVector3f &axis) { + + ptr()->setGlobalAxis(PhysxManager::vec3_to_nxVec3(axis)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::set_global_anchor +// Access: Published +// Description: Set the anchor using a world space point. +//////////////////////////////////////////////////////////////////// +void PhysxJointDesc:: +set_global_anchor(const LPoint3f &anchor) { + + ptr()->setGlobalAnchor(PhysxManager::point3_to_nxVec3(anchor)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::get_name +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +const char *PhysxJointDesc:: +get_name() const { + + return ptr()->name; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::get_max_force +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointDesc:: +get_max_force() const { + + return ptr()->maxForce; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::get_max_torque +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointDesc:: +get_max_torque() const { + + return ptr()->maxTorque; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::get_solver_extrapolation_factor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointDesc:: +get_solver_extrapolation_factor() const { + + return ptr()->solverExtrapolationFactor; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::get_local_normal +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LVector3f PhysxJointDesc:: +get_local_normal(unsigned int idx) const { + + nassertr_always(idx < 2, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(ptr()->localNormal[idx]); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::get_local_axis +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LVector3f PhysxJointDesc:: +get_local_axis(unsigned int idx) const { + + nassertr_always(idx < 2, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(ptr()->localAxis[idx]); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::get_local_anchor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxJointDesc:: +get_local_anchor(unsigned int idx) const { + + nassertr_always(idx < 2, LPoint3f::zero()); + return PhysxManager::nxVec3_to_point3(ptr()->localAnchor[idx]); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::get_joint_flag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxJointDesc:: +get_joint_flag(const PhysxJointFlag flag) const { + + return (ptr()->jointFlags & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDesc::get_actor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxActor) PhysxJointDesc:: +get_actor(unsigned int idx) const { + + nassertr_always(idx < 2, NULL); + + NxActor *actorPtr = ptr()->actor[idx]; + if (actorPtr == NULL) { + return NULL; + } + else { + return (PhysxActor *)(actorPtr->userData); + } +} diff --git a/panda/src/physx/physxJointDesc.h b/panda/src/physx/physxJointDesc.h index 0378285a09..e2116739c4 100644 --- a/panda/src/physx/physxJointDesc.h +++ b/panda/src/physx/physxJointDesc.h @@ -1,5 +1,5 @@ // Filename: physxJointDesc.h -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (28Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,60 +15,56 @@ #ifndef PHYSXJOINTDESC_H #define PHYSXJOINTDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "lpoint3.h" +#include "lvector3.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -class PhysxActorNode; +#include "physxEnums.h" +#include "NoMinMax.h" #include "NxPhysics.h" +class PhysxActor; + //////////////////////////////////////////////////////////////////// // Class : PhysxJointDesc -// Description : +// Description : Abstract base class for joint descriptors. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxJointDesc { +class EXPCL_PANDAPHYSX PhysxJointDesc : public PhysxEnums { + PUBLISHED: - ~PhysxJointDesc(); + virtual void set_to_default() = 0; + virtual bool is_valid() const = 0; - INLINE bool is_valid() const; - void set_global_anchor(const LVecBase3f & ws_anchor); - void set_global_axis(const LVecBase3f & ws_axis); - INLINE void set_to_default(); + void set_name(const char *name); + void set_joint_flag(PhysxJointFlag flag, bool value); + void set_max_force(float force); + void set_max_torque(float torque); + void set_solver_extrapolation_factor(float factor); + void set_global_axis(const LVector3f &axis); + void set_global_anchor(const LPoint3f &anchor); + void set_local_normal(unsigned int idx, const LVector3f &normal); + void set_local_axis(unsigned int idx, const LVector3f &axis); + void set_local_anchor(unsigned int idx, const LPoint3f &anchor); + void set_actor(unsigned int idx, const PhysxActor &actor); - INLINE unsigned int get_joint_flags() const; - LVecBase3f get_local_anchor(int index) const; - LVecBase3f get_local_axis(int index) const; - LVecBase3f get_local_normal(int index) const; - INLINE float get_max_force() const; - INLINE float get_max_torque() const; - INLINE const char * get_name() const; - - void set_actor(int index, PhysxActorNode * value); - INLINE void set_joint_flags(unsigned int value); - void set_local_anchor(int index, LVecBase3f value); - void set_local_axis(int index, LVecBase3f value); - void set_local_normal(int index, LVecBase3f value); - INLINE void set_max_force(float value); - INLINE void set_max_torque(float value); - INLINE void set_name(const char * value); + const char *get_name() const; + bool get_joint_flag(PhysxJointFlag flag) const; + float get_max_force() const; + float get_max_torque() const; + float get_solver_extrapolation_factor() const; + LVector3f get_local_normal(unsigned int idx) const; + LVector3f get_local_axis(unsigned int idx) const; + LPoint3f get_local_anchor(unsigned int idx) const; + PT(PhysxActor) get_actor(unsigned int idx) const; public: - NxJointDesc *nJointDesc; + virtual NxJointDesc *ptr() const = 0; protected: - PhysxJointDesc(NxJointDesc *subJointDesc); - -private: - string _name_store; + INLINE PhysxJointDesc(); }; #include "physxJointDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXJOINTDESC_H diff --git a/panda/src/physx/physxJointDriveDesc.I b/panda/src/physx/physxJointDriveDesc.I index 2a0ef92839..bd4907251c 100644 --- a/panda/src/physx/physxJointDriveDesc.I +++ b/panda/src/physx/physxJointDriveDesc.I @@ -1,5 +1,5 @@ // Filename: physxJointDriveDesc.I -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (01Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,63 +12,37 @@ // //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// -// Function : get_damping -// Access : Published -// Description : +// Function: PhysxJointDriveDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE float PhysxJointDriveDesc:: -get_damping() const { - return nJointDriveDesc.damping; +INLINE PhysxJointDriveDesc:: +PhysxJointDriveDesc() { + } //////////////////////////////////////////////////////////////////// -// Function : get_force_limit -// Access : Published -// Description : +// Function: PhysxJointDriveDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE float PhysxJointDriveDesc:: -get_force_limit() const { - return nJointDriveDesc.forceLimit; +INLINE PhysxJointDriveDesc:: +PhysxJointDriveDesc(float spring, float damping, float forceLimit) { + + _desc.spring = spring; + _desc.damping = damping; + _desc.forceLimit = forceLimit; } //////////////////////////////////////////////////////////////////// -// Function : get_spring -// Access : Published -// Description : +// Function: PhysxJointDriveDesc::Destructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE float PhysxJointDriveDesc:: -get_spring() const { - return nJointDriveDesc.spring; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_damping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointDriveDesc:: -set_damping(float value) { - nJointDriveDesc.damping = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_force_limit -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointDriveDesc:: -set_force_limit(float value) { - nJointDriveDesc.forceLimit = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_spring -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointDriveDesc:: -set_spring(float value) { - nJointDriveDesc.spring = value; +INLINE PhysxJointDriveDesc:: +~PhysxJointDriveDesc() { + } diff --git a/panda/src/physx/physxJointDriveDesc.cxx b/panda/src/physx/physxJointDriveDesc.cxx index 37086731b5..0b64e7e207 100644 --- a/panda/src/physx/physxJointDriveDesc.cxx +++ b/panda/src/physx/physxJointDriveDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxJointDriveDesc.cxx -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (01Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,21 +12,93 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxJointDriveDesc.h" - - //////////////////////////////////////////////////////////////////// -// Function : PhysxJointDriveDesc -// Access : Published -// Description : +// Function: PhysxJointDriveDesc::spring +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -PhysxJointDriveDesc:: -PhysxJointDriveDesc() { +void PhysxJointDriveDesc:: +set_spring(float spring) { + _desc.spring = spring; } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDriveDesc::set_damping +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxJointDriveDesc:: +set_damping(float damping) { + + _desc.damping = damping; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDriveDesc::set_force_limit +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxJointDriveDesc:: +set_force_limit(float forceLimit) { + + _desc.forceLimit = forceLimit; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDriveDesc::set_drive_type +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxJointDriveDesc:: +set_drive_type(PhysxD6JointDriveType driveType) { + + _desc.driveType = (NxD6JointDriveType)driveType; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDriveDesc::get_spring +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointDriveDesc:: +get_spring() const { + + return _desc.spring; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDriveDesc::get_damping +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointDriveDesc:: +get_damping() const { + + return _desc.damping; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDriveDesc::get_force_limit +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointDriveDesc:: +get_force_limit() const { + + return _desc.forceLimit; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointDriveDesc::get_drive_type +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxD6JointDriveType PhysxJointDriveDesc:: +get_drive_type() const { + + return (PhysxD6JointDriveType)_desc.driveType.bitField; +} diff --git a/panda/src/physx/physxJointDriveDesc.h b/panda/src/physx/physxJointDriveDesc.h index 4374c25eb3..fa3ff18bbe 100644 --- a/panda/src/physx/physxJointDriveDesc.h +++ b/panda/src/physx/physxJointDriveDesc.h @@ -1,5 +1,5 @@ // Filename: physxJointDriveDesc.h -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (01Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,39 +15,39 @@ #ifndef PHYSXJOINTDRIVEDESC_H #define PHYSXJOINTDRIVEDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "physxEnums.h" +#include "NoMinMax.h" #include "NxPhysics.h" //////////////////////////////////////////////////////////////////// // Class : PhysxJointDriveDesc -// Description : +// Description : Used to describe drive properties for a +// PhysxD6Joint. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxJointDriveDesc { +class PhysxJointDriveDesc : public PhysxEnums { + PUBLISHED: - PhysxJointDriveDesc(); + INLINE PhysxJointDriveDesc(); + INLINE PhysxJointDriveDesc(float sping, float damping, float forceLimit); + INLINE ~PhysxJointDriveDesc(); + void set_drive_type(PhysxD6JointDriveType type); + void set_spring(float spring); + void set_damping(float damping); + void set_force_limit(float limit); - INLINE float get_damping() const; - INLINE float get_force_limit() const; - INLINE float get_spring() const; - - INLINE void set_damping( float value ); - INLINE void set_force_limit( float value ); - INLINE void set_spring( float value ); + PhysxD6JointDriveType get_drive_type() const; + float get_spring() const; + float get_damping() const; + float get_force_limit() const; public: - NxJointDriveDesc nJointDriveDesc; + NxJointDriveDesc _desc; }; #include "physxJointDriveDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXJOINTDRIVEDESC_H diff --git a/panda/src/physx/physxJointHandler.cxx b/panda/src/physx/physxJointHandler.cxx deleted file mode 100644 index abb3240b7d..0000000000 --- a/panda/src/physx/physxJointHandler.cxx +++ /dev/null @@ -1,84 +0,0 @@ -// Filename: physxJointHandler.cxx -// Created by: pratt (Jul 9, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifdef HAVE_PHYSX - -#include "physxJointHandler.h" - -#include "eventParameter.h" -#include "throw_event.h" - -//////////////////////////////////////////////////////////////////// -// Function : clear_events -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJointHandler:: -clear_events() { - events.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function : throw_events -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJointHandler:: -throw_events() { - pvector::const_iterator events_iter; - PhysxJointEvent event; - for(events_iter = events.begin(); events_iter != events.end(); ++events_iter) { - event = *events_iter; - PT(PhysxJoint) pJoint = (PhysxJoint *)(event.brokenJoint->userData); - throw_event("physxOnJointBreak", EventParameter(event.breakingForce), EventParameter(pJoint)); - } -} - -//////////////////////////////////////////////////////////////////// -// Function : onJointBreak -// Access : public -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxJointHandler:: -onJointBreak(NxReal breakingForce, NxJoint &brokenJoint) { - PhysxJointEvent event; - event.breakingForce = breakingForce; - event.brokenJoint = &brokenJoint; - events.push_back(event); - - PhysxJoint *pJoint = (PhysxJoint *)event.brokenJoint->userData; - return false; // Do not release the joint -} - -//////////////////////////////////////////////////////////////////// -// Function : onWake -// Access : public -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJointHandler:: -onWake(NxActor **actors, NxU32 count) { - // currently not implemented; need to rework the whole reporting interface -} - -//////////////////////////////////////////////////////////////////// -// Function : onSleep -// Access : public -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJointHandler:: -onSleep(NxActor **actors, NxU32 count) { - // currently not implemented; need to rework the whole reporting interface -} - -#endif // HAVE_PHYSX diff --git a/panda/src/physx/physxJointHandler.h b/panda/src/physx/physxJointHandler.h deleted file mode 100644 index 6f1d8665c9..0000000000 --- a/panda/src/physx/physxJointHandler.h +++ /dev/null @@ -1,60 +0,0 @@ -// Filename: physxJointHandler.h -// Created by: pratt (Jul 9, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifndef PHYSXJOINTHANDLER_H -#define PHYSXJOINTHANDLER_H - -#ifdef HAVE_PHYSX - -#include "pandabase.h" -#include "pvector.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -class PhysxJoint; - -#include "NxPhysics.h" - -//////////////////////////////////////////////////////////////////// -// Class : PhysxJointHandler -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxJointHandler : public NxUserNotify { -PUBLISHED: - void clear_events(); - void throw_events(); - -public: - bool onJointBreak(NxReal breakingForce, NxJoint &brokenJoint); - - // currently not implemented; need to rework the whole reporting interface - void onWake(NxActor **actors, NxU32 count); - void onSleep(NxActor **actors, NxU32 count); - -private: - struct PhysxJointEvent { - NxReal breakingForce; - NxJoint *brokenJoint; - }; - - pvector events; -}; - -#include "physxJointHandler.I" - -#endif // HAVE_PHYSX - -#endif // PHYSXJOINTHANDLER_H diff --git a/panda/src/physx/physxJointLimitDesc.I b/panda/src/physx/physxJointLimitDesc.I new file mode 100644 index 0000000000..8881d096ac --- /dev/null +++ b/panda/src/physx/physxJointLimitDesc.I @@ -0,0 +1,48 @@ +// Filename: physxJointLimitDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxJointLimitDesc:: +PhysxJointLimitDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxJointLimitDesc:: +PhysxJointLimitDesc(float value, float restitution, float hardness) { + + _desc.value = value; + _desc.restitution = restitution; + _desc.hardness = hardness; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxJointLimitDesc:: +~PhysxJointLimitDesc() { + +} + diff --git a/panda/src/physx/physxJointLimitDesc.cxx b/panda/src/physx/physxJointLimitDesc.cxx new file mode 100644 index 0000000000..e741c8c197 --- /dev/null +++ b/panda/src/physx/physxJointLimitDesc.cxx @@ -0,0 +1,82 @@ +// Filename: physxJointLimitDesc.cxx +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxJointLimitDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitDesc::set_value +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxJointLimitDesc:: +set_value(float value) { + + _desc.value = value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitDesc::set_restitution +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxJointLimitDesc:: +set_restitution(float restitution) { + + _desc.restitution = restitution; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitDesc::set_hardness +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxJointLimitDesc:: +set_hardness(float hardness) { + + _desc.hardness = hardness; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitDesc::get_value +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointLimitDesc:: +get_value() const { + + return _desc.value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitDesc::get_restitution +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointLimitDesc:: +get_restitution() const { + + return _desc.restitution; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitDesc::get_hardness +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointLimitDesc:: +get_hardness() const { + + return _desc.hardness; +} + diff --git a/panda/src/physx/physxJointLimitDesc.h b/panda/src/physx/physxJointLimitDesc.h new file mode 100644 index 0000000000..0473f78da2 --- /dev/null +++ b/panda/src/physx/physxJointLimitDesc.h @@ -0,0 +1,48 @@ +// Filename: physxJointLimitDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXJOINTLIMITDESC_H +#define PHYSXJOINTLIMITDESC_H + +#include "pandabase.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxJointLimitDesc +// Description : Describes a joint limit. +//////////////////////////////////////////////////////////////////// +class PhysxJointLimitDesc { + +PUBLISHED: + INLINE PhysxJointLimitDesc(); + INLINE PhysxJointLimitDesc(float value, float restitution, float hardness); + INLINE ~PhysxJointLimitDesc(); + + void set_value(float value); + void set_restitution(float restitution); + void set_hardness(float hardness); + + float get_value() const; + float get_restitution() const; + float get_hardness() const; + +public: + NxJointLimitDesc _desc; +}; + +#include "physxJointLimitDesc.I" + +#endif // PHYSXJOINTLIMITDESC_H diff --git a/panda/src/physx/physxJointLimitSoftDesc.I b/panda/src/physx/physxJointLimitSoftDesc.I index c707f28f3d..4f861f0e39 100644 --- a/panda/src/physx/physxJointLimitSoftDesc.I +++ b/panda/src/physx/physxJointLimitSoftDesc.I @@ -1,5 +1,5 @@ // Filename: physxJointLimitSoftDesc.I -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (01Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,103 +12,38 @@ // //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxJointLimitSoftDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxJointLimitSoftDesc:: -is_valid() const { - return nJointLimitSoftDesc.isValid(); +INLINE PhysxJointLimitSoftDesc:: +PhysxJointLimitSoftDesc() { + } //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxJointLimitSoftDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE void PhysxJointLimitSoftDesc:: -set_to_default() { - nJointLimitSoftDesc.setToDefault(); +INLINE PhysxJointLimitSoftDesc:: +PhysxJointLimitSoftDesc(float value, float restitution, float spring, float damping) { + + _desc.value = value; + _desc.restitution = restitution; + _desc.spring = spring; + _desc.damping = damping; } //////////////////////////////////////////////////////////////////// -// Function : get_damping -// Access : Published -// Description : +// Function: PhysxJointLimitSoftDesc::Destructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE float PhysxJointLimitSoftDesc:: -get_damping() const { - return nJointLimitSoftDesc.damping; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_restitution -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxJointLimitSoftDesc:: -get_restitution() const { - return nJointLimitSoftDesc.restitution; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_spring -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxJointLimitSoftDesc:: -get_spring() const { - return nJointLimitSoftDesc.spring; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_value -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxJointLimitSoftDesc:: -get_value() const { - return nJointLimitSoftDesc.value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_damping -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointLimitSoftDesc:: -set_damping(float value) { - nJointLimitSoftDesc.damping = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_restitution -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointLimitSoftDesc:: -set_restitution(float value) { - nJointLimitSoftDesc.restitution = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_spring -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointLimitSoftDesc:: -set_spring(float value) { - nJointLimitSoftDesc.spring = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_value -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxJointLimitSoftDesc:: -set_value(float value) { - nJointLimitSoftDesc.value = value; +INLINE PhysxJointLimitSoftDesc:: +~PhysxJointLimitSoftDesc() { + } diff --git a/panda/src/physx/physxJointLimitSoftDesc.cxx b/panda/src/physx/physxJointLimitSoftDesc.cxx index 2acd135536..5eab99f184 100644 --- a/panda/src/physx/physxJointLimitSoftDesc.cxx +++ b/panda/src/physx/physxJointLimitSoftDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxJointLimitSoftDesc.cxx -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (01Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,21 +12,93 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxJointLimitSoftDesc.h" - - //////////////////////////////////////////////////////////////////// -// Function : PhysxJointLimitSoftDesc -// Access : Published -// Description : +// Function: PhysxJointLimitSoftDesc::set_value +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -PhysxJointLimitSoftDesc:: -PhysxJointLimitSoftDesc() { +void PhysxJointLimitSoftDesc:: +set_value(float value) { + _desc.value = value; } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitSoftDesc::set_restitution +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxJointLimitSoftDesc:: +set_restitution(float restitution) { + + _desc.restitution = restitution; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitSoftDesc::set_spring +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxJointLimitSoftDesc:: +set_spring(float spring) { + + _desc.spring = spring; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitSoftDesc::set_damping +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxJointLimitSoftDesc:: +set_damping(float damping) { + + _desc.damping = damping; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitSoftDesc::get_value +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointLimitSoftDesc:: +get_value() const { + + return _desc.value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitSoftDesc::get_restitution +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointLimitSoftDesc:: +get_restitution() const { + + return _desc.restitution; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitSoftDesc::get_spring +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointLimitSoftDesc:: +get_spring() const { + + return _desc.spring; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxJointLimitSoftDesc::get_damping +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxJointLimitSoftDesc:: +get_damping() const { + + return _desc.damping; +} diff --git a/panda/src/physx/physxJointLimitSoftDesc.h b/panda/src/physx/physxJointLimitSoftDesc.h index 73d83202fe..1443daf789 100644 --- a/panda/src/physx/physxJointLimitSoftDesc.h +++ b/panda/src/physx/physxJointLimitSoftDesc.h @@ -1,5 +1,5 @@ // Filename: physxJointLimitSoftDesc.h -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (01Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,43 +15,36 @@ #ifndef PHYSXJOINTLIMITSOFTDESC_H #define PHYSXJOINTLIMITSOFTDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - +#include "NoMinMax.h" #include "NxPhysics.h" //////////////////////////////////////////////////////////////////// // Class : PhysxJointLimitSoftDesc -// Description : +// Description : Describes a joint limit. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxJointLimitSoftDesc { +class PhysxJointLimitSoftDesc { + PUBLISHED: - PhysxJointLimitSoftDesc(); + INLINE PhysxJointLimitSoftDesc(); + INLINE PhysxJointLimitSoftDesc(float value, float restitution, float spring, float damping); + INLINE ~PhysxJointLimitSoftDesc(); - INLINE bool is_valid() const; - INLINE void set_to_default(); + void set_value(float value); + void set_restitution(float restitution); + void set_spring(float spring); + void set_damping(float damping); - INLINE float get_damping() const; - INLINE float get_restitution() const; - INLINE float get_spring() const; - INLINE float get_value() const; - - INLINE void set_damping( float value ); - INLINE void set_restitution( float value ); - INLINE void set_spring( float value ); - INLINE void set_value( float value ); + float get_value() const; + float get_restitution() const; + float get_spring() const; + float get_damping() const; public: - NxJointLimitSoftDesc nJointLimitSoftDesc; + NxJointLimitSoftDesc _desc; }; #include "physxJointLimitSoftDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXJOINTLIMITSOFTDESC_H diff --git a/panda/src/physx/physxJointLimitSoftPairDesc.cxx b/panda/src/physx/physxJointLimitSoftPairDesc.cxx deleted file mode 100644 index 10dc30028c..0000000000 --- a/panda/src/physx/physxJointLimitSoftPairDesc.cxx +++ /dev/null @@ -1,73 +0,0 @@ -// Filename: physxJointLimitSoftPairDesc.cxx -// Created by: pratt (Jun 20, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifdef HAVE_PHYSX - -#include "physxJointLimitSoftPairDesc.h" - -#include "physxJointLimitSoftDesc.h" - - -//////////////////////////////////////////////////////////////////// -// Function : PhysxJointLimitSoftPairDesc -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointLimitSoftPairDesc:: -PhysxJointLimitSoftPairDesc() { - -} - -//////////////////////////////////////////////////////////////////// -// Function : get_high -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointLimitSoftDesc & PhysxJointLimitSoftPairDesc:: -get_high() const { - throw "Not Implemented"; // return nJointLimitSoftPairDesc.high; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_low -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJointLimitSoftDesc & PhysxJointLimitSoftPairDesc:: -get_low() const { - throw "Not Implemented"; // return nJointLimitSoftPairDesc.low; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_high -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJointLimitSoftPairDesc:: -set_high(PhysxJointLimitSoftDesc & value) { - nJointLimitSoftPairDesc.high = value.nJointLimitSoftDesc; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_low -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxJointLimitSoftPairDesc:: -set_low(PhysxJointLimitSoftDesc & value) { - nJointLimitSoftPairDesc.low = value.nJointLimitSoftDesc; -} - -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxJointLimitSoftPairDesc.h b/panda/src/physx/physxJointLimitSoftPairDesc.h deleted file mode 100644 index 3283d5d974..0000000000 --- a/panda/src/physx/physxJointLimitSoftPairDesc.h +++ /dev/null @@ -1,55 +0,0 @@ -// Filename: physxJointLimitSoftPairDesc.h -// Created by: pratt (Jun 20, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifndef PHYSXJOINTLIMITSOFTPAIRDESC_H -#define PHYSXJOINTLIMITSOFTPAIRDESC_H - -#ifdef HAVE_PHYSX - -#include "pandabase.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -class PhysxJointLimitSoftDesc; - -#include "NxPhysics.h" - -//////////////////////////////////////////////////////////////////// -// Class : PhysxJointLimitSoftPairDesc -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxJointLimitSoftPairDesc { -PUBLISHED: - PhysxJointLimitSoftPairDesc(); - - INLINE bool is_valid() const; - INLINE void set_to_default(); - - PhysxJointLimitSoftDesc & get_high() const; - PhysxJointLimitSoftDesc & get_low() const; - - void set_high( PhysxJointLimitSoftDesc & value ); - void set_low( PhysxJointLimitSoftDesc & value ); - -public: - NxJointLimitSoftPairDesc nJointLimitSoftPairDesc; -}; - -#include "physxJointLimitSoftPairDesc.I" - -#endif // HAVE_PHYSX - -#endif // PHYSXJOINTLIMITSOFTPAIRDESC_H diff --git a/panda/src/physx/physxKitchen.I b/panda/src/physx/physxKitchen.I new file mode 100644 index 0000000000..f320b511b1 --- /dev/null +++ b/panda/src/physx/physxKitchen.I @@ -0,0 +1,40 @@ +// Filename: physxKitchen.I +// Created by: enn0x (12Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxKitchen::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxKitchen:: +PhysxKitchen() { + + _cooking = NxGetCookingLib( NX_PHYSICS_SDK_VERSION ); + + bool status = _cooking->NxInitCooking(); + nassertv_always( status ); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxKitchen::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxKitchen:: +~PhysxKitchen() { + + _cooking->NxCloseCooking(); +} + diff --git a/panda/src/physx/physxKitchen.cxx b/panda/src/physx/physxKitchen.cxx new file mode 100644 index 0000000000..1caa72faca --- /dev/null +++ b/panda/src/physx/physxKitchen.cxx @@ -0,0 +1,141 @@ +// Filename: physxKitchen.cxx +// Created by: enn0x (12Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxKitchen.h" +#include "physxConvexMesh.h" +#include "physxConvexMeshDesc.h" +#include "physxTriangleMesh.h" +#include "physxTriangleMeshDesc.h" +#include "physxFileStream.h" +#include "physxMemoryReadBuffer.h" +#include "physxMemoryWriteBuffer.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxKitchen::set_cooking_params +// Access: Published +// Description: Sets two parameters which affect mesh cooking: +// +// Skin width for convex meshes: +// Specifies the amount to inflate the convex mesh by +// when the new convex hull generator is used. +// Inflating the mesh allows the user to hide +// interpenetration errors by increasing the size of +// the collision mesh with respect to the size of the +// rendered geometry. +// Default value: 0.025f +// +// Hint to choose speed or less memory for collision +// structures. +// Default value: false +//////////////////////////////////////////////////////////////////// +void PhysxKitchen:: +set_cooking_params(float skinWidth, bool hintCollisionSpeed) { + + NxCookingParams params; + + params.targetPlatform = PLATFORM_PC; + params.skinWidth = skinWidth; + params.hintCollisionSpeed = hintCollisionSpeed; + + _cooking->NxSetCookingParams(params); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxKitchen::cook_convex_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxKitchen:: +cook_convex_mesh(const PhysxConvexMeshDesc &meshDesc, const Filename &filename) { + + nassertr_always(!filename.empty(), false); + nassertr_always(filename.touch(), false); + nassertr_always(meshDesc.is_valid(), false); + + PhysxFileStream stream = PhysxFileStream(filename.c_str(), false); + return _cooking->NxCookConvexMesh(meshDesc.get_desc(), stream); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxKitchen::cook_triangle_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxKitchen:: +cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc, const Filename &filename) { + + nassertr_always(!filename.empty(), false); + nassertr_always(filename.touch(), false); + nassertr_always(meshDesc.is_valid(), false); + + PhysxFileStream stream = PhysxFileStream(filename.c_str(), false); + return _cooking->NxCookTriangleMesh(meshDesc.get_desc(), stream); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxKitchen::cook_convex_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxConvexMesh) PhysxKitchen:: +cook_convex_mesh(const PhysxConvexMeshDesc &meshDesc) { + + nassertr_always(meshDesc.is_valid(), false); + + PhysxMemoryWriteBuffer buffer; + bool status = _cooking->NxCookConvexMesh(meshDesc.get_desc(), buffer); + nassertr(status, NULL); + + NxPhysicsSDK *sdk = NxGetPhysicsSDK(); + nassertr(sdk, NULL); + + PT(PhysxConvexMesh) mesh = new PhysxConvexMesh(); + nassertr(mesh, NULL); + + NxConvexMesh *meshPtr = sdk->createConvexMesh(PhysxMemoryReadBuffer(buffer.data)); + nassertr(meshPtr, NULL); + + mesh->link(meshPtr); + + return mesh; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxKitchen::cook_triangle_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxTriangleMesh) PhysxKitchen:: +cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc) { + + nassertr_always(meshDesc.is_valid(), false); + + PhysxMemoryWriteBuffer buffer; + bool status = _cooking->NxCookTriangleMesh(meshDesc.get_desc(), buffer); + nassertr(status, NULL); + + NxPhysicsSDK *sdk = NxGetPhysicsSDK(); + nassertr(sdk, NULL); + + PT(PhysxTriangleMesh) mesh = new PhysxTriangleMesh(); + nassertr(mesh, NULL); + + NxTriangleMesh *meshPtr = sdk->createTriangleMesh(PhysxMemoryReadBuffer(buffer.data)); + nassertr(meshPtr, NULL); + + mesh->link(meshPtr); + + return mesh; +} + diff --git a/panda/src/physx/physxKitchen.h b/panda/src/physx/physxKitchen.h new file mode 100644 index 0000000000..d527c9de38 --- /dev/null +++ b/panda/src/physx/physxKitchen.h @@ -0,0 +1,54 @@ +// Filename: physxKitchen.h +// Created by: enn0x (12Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXKITCHEN_H +#define PHYSXKITCHEN_H + +#include "pandabase.h" +#include "filename.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" +#include "NxCooking.h" + +class PhysxConvexMesh; +class PhysxConvexMeshDesc; +class PhysxTriangleMesh; +class PhysxTriangleMeshDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxKitchen +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxKitchen { + +PUBLISHED: + INLINE PhysxKitchen(); + INLINE ~PhysxKitchen(); + + void set_cooking_params(float skinWidth, bool hintCollisionSpeed); + + bool cook_convex_mesh(const PhysxConvexMeshDesc &meshDesc, const Filename &filename); + bool cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc, const Filename &filename); + + PT(PhysxConvexMesh) cook_convex_mesh(const PhysxConvexMeshDesc &meshDesc); + PT(PhysxTriangleMesh) cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc); + +private: + NxCookingInterface *_cooking; +}; + +#include "physxKitchen.I" + +#endif // PHYSXKITCHEN_H diff --git a/panda/src/physx/physxManager.I b/panda/src/physx/physxManager.I index 0b4daf8e4b..2a1a497d09 100644 --- a/panda/src/physx/physxManager.I +++ b/panda/src/physx/physxManager.I @@ -1,5 +1,5 @@ // Filename: physxManager.I -// Created by: pratt (Apr 6, 2006) +// Created by: enn0x (01Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,94 +12,233 @@ // //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// -// Function : nxVec3_to_lVecBase3 -// Access : Public -// Description : convert NxVec3 to LVecBase3f +// Function: PhysxManager::get_sdk +// Access: Public +// Description: Returns a pointer to the NxPhysicsSDK. //////////////////////////////////////////////////////////////////// -INLINE LVecBase3f PhysxManager:: -nxVec3_to_lVecBase3(const NxVec3 &vec) { - return LVecBase3f(vec.x, vec.y, vec.z); +INLINE NxPhysicsSDK *PhysxManager:: +get_sdk() const { + + return _sdk; } //////////////////////////////////////////////////////////////////// -// Function : nxMat33_to_lMatrix3 -// Access : Public -// Description : convert NxMat33 to LMatrix3f -//////////////////////////////////////////////////////////////////// -INLINE LMatrix3f PhysxManager:: -nxMat33_to_lMatrix3(const NxMat33 &mat) { - float cells[9]; - mat.getColumnMajor(cells); - return LMatrix3f( - cells[0], cells[1], cells[2], - cells[3], cells[4], cells[5], - cells[6], cells[7], cells[8] - ); -} - -//////////////////////////////////////////////////////////////////// -// Function : nxMat34_to_lMatrix4 -// Access : Public -// Description : convert NxMat34 to LMatrix4f -//////////////////////////////////////////////////////////////////// -INLINE LMatrix4f PhysxManager:: -nxMat34_to_lMatrix4(const NxMat34 &mat) { - return LMatrix4f(nxMat33_to_lMatrix3(mat.M), nxVec3_to_lVecBase3(mat.t)); -} - -//////////////////////////////////////////////////////////////////// -// Function : nxQuat_to_lQuaternion -// Access : Public -// Description : convert NxQuat to LQuaternionf -//////////////////////////////////////////////////////////////////// -INLINE LQuaternionf PhysxManager:: -nxQuat_to_lQuaternion(const NxQuat &quat) { - return LQuaternionf(quat.w, quat.x, quat.y, quat.z); -} - -//////////////////////////////////////////////////////////////////// -// Function : lVecBase3_to_nxVec3 -// Access : Public -// Description : convert LVecBase3f to NxVec3 +// Function: PhysxManager::vec3_to_nxVec3 +// Access: Public +// Description: Converts from LVector3f to NxVec3. //////////////////////////////////////////////////////////////////// INLINE NxVec3 PhysxManager:: -lVecBase3_to_nxVec3(const LVecBase3f &vec) { - return NxVec3(vec.get_x(), vec.get_y(), vec.get_z()); +vec3_to_nxVec3(const LVector3f &v) { + + return NxVec3(v.get_x(), v.get_y(), v.get_z()); } //////////////////////////////////////////////////////////////////// -// Function : lMatrix3_to_nxMat33 -// Access : Public -// Description : convert LMatrix3f to NxMat33 +// Function: PhysxManager::nxVec3_to_vec3 +// Access: Public +// Description: Converts from NxVec3 to LVector3f. //////////////////////////////////////////////////////////////////// -INLINE NxMat33 PhysxManager:: -lMatrix3_to_nxMat33(const LMatrix3f &mat) { - const float *cells = mat.get_data(); - NxMat33 nMat; - nMat.setColumnMajor(cells); - return nMat; +INLINE LVector3f PhysxManager:: +nxVec3_to_vec3(const NxVec3 &v) { + + return LVector3f(v.x, v.y, v.z); } //////////////////////////////////////////////////////////////////// -// Function : lMatrix4_to_nxMat34 -// Access : Public -// Description : convert LMatrix4f to NxMat34 +// Function: PhysxManager::vec3_to_nxExtVec3 +// Access: Public +// Description: Converts from LVector3f to NxExtendedVec3. //////////////////////////////////////////////////////////////////// -INLINE NxMat34 PhysxManager:: -lMatrix4_to_nxMat34(const LMatrix4f &mat) { - NxMat33 nxmat = lMatrix3_to_nxMat33(mat.get_upper_3()); - NxVec3 nxvec = lVecBase3_to_nxVec3(mat.get_row3( 3 )); - return NxMat34(nxmat, nxvec); +INLINE NxExtendedVec3 PhysxManager:: +vec3_to_nxExtVec3(const LVector3f &v) { + + return NxExtendedVec3(v.get_x(), v.get_y(), v.get_z()); } //////////////////////////////////////////////////////////////////// -// Function : lQuaternion_to_nxQuat -// Access : Public -// Description : convert LQuaternionf to NxQuat +// Function: PhysxManager::nxExtVec3_to_vec3 +// Access: Public +// Description: Converts from NxExtendedVec3 to LVector3f. +//////////////////////////////////////////////////////////////////// +INLINE LVector3f PhysxManager:: +nxExtVec3_to_vec3(const NxExtendedVec3 &v) { + + return LVector3f(v.x, v.y, v.z); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::point3_to_nxVec3 +// Access: Public +// Description: Converts from LPoint3f to NxVec3. +//////////////////////////////////////////////////////////////////// +INLINE NxVec3 PhysxManager:: +point3_to_nxVec3(const LPoint3f &p) { + + return NxVec3(p.get_x(), p.get_y(), p.get_z()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::nxVec3_to_point3 +// Access: Public +// Description: Converts from NxVec3 to LPoint3f. +//////////////////////////////////////////////////////////////////// +INLINE LPoint3f PhysxManager:: +nxVec3_to_point3(const NxVec3 &p) { + + return LPoint3f(p.x, p.y, p.z); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::point3_to_nxExtVec3 +// Access: Public +// Description: Converts from LPoint3f to NxExtendedVec3. +//////////////////////////////////////////////////////////////////// +INLINE NxExtendedVec3 PhysxManager:: +point3_to_nxExtVec3(const LPoint3f &p) { + + return NxExtendedVec3(p.get_x(), p.get_y(), p.get_z()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::nxExtVec3_to_point3 +// Access: Public +// Description: Converts from NxExtendedVec3 to LPoint3f. +//////////////////////////////////////////////////////////////////// +INLINE LPoint3f PhysxManager:: +nxExtVec3_to_point3(const NxExtendedVec3 &p) { + + return LPoint3f(p.x, p.y, p.z); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::quat_to_nxQuat +// Access: Public +// Description: Converts from LQuaternionf to NxQuat. //////////////////////////////////////////////////////////////////// INLINE NxQuat PhysxManager:: -lQuaternion_to_nxQuat(const LQuaternionf &quat) { - return NxQuat(NxVec3(quat.get_i(), quat.get_j(), quat.get_k()), quat.get_r()); +quat_to_nxQuat(const LQuaternionf &q) { + + NxQuat nxq; + nxq.setXYZW(q.get_i(), q.get_j(), q.get_k(), q.get_r()); + return nxq; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::nxQuat_to_quat +// Access: Public +// Description: Converts from NxQuat to LQuaternionf. +//////////////////////////////////////////////////////////////////// +INLINE LQuaternionf PhysxManager:: +nxQuat_to_quat(const NxQuat &q) { + + return LQuaternionf(q.w, q.x, q.y, q.z); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::mat4_to_nxMat34 +// Access: Public +// Description: Converts from LMatrix4f to NxMat34. +//////////////////////////////////////////////////////////////////// +INLINE NxMat34 PhysxManager:: +mat4_to_nxMat34(const LMatrix4f &m) { + + NxMat33 mat = mat3_to_nxMat33(m.get_upper_3()); + NxVec3 v = vec3_to_nxVec3(m.get_row3(3)); + return NxMat34(mat, v); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::nxMat34_to_mat4 +// Access: Public +// Description: Converts from NxMat34 to LMatrix4f. +//////////////////////////////////////////////////////////////////// +INLINE LMatrix4f PhysxManager:: +nxMat34_to_mat4(const NxMat34 &m) { + + return LMatrix4f(nxMat33_to_mat3(m.M), nxVec3_to_vec3(m.t)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::mat3_to_nxMat33 +// Access: Public +// Description: Converts from LMatrix3f to NxMat33. +//////////////////////////////////////////////////////////////////// +INLINE NxMat33 PhysxManager:: +mat3_to_nxMat33(const LMatrix3f &m) { + + NxMat33 mat; + mat.setColumnMajor(m.get_data()); + return mat; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::nxMat33_to_mat3 +// Access: Public +// Description: Converts from NxMat33 to LMatrix3f. +//////////////////////////////////////////////////////////////////// +INLINE LMatrix3f PhysxManager:: +nxMat33_to_mat3(const NxMat33 &m) { + + float cells[9]; + m.getColumnMajor(cells); + return LMatrix3f(cells[0], cells[1], cells[2], + cells[3], cells[4], cells[5], + cells[6], cells[7], cells[8]); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::update_vec3_from_nxVec3 +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxManager:: +update_vec3_from_nxVec3(LVector3f &v, const NxVec3 &nVec) { + + v.set_x(nVec.x); + v.set_y(nVec.y); + v.set_z(nVec.z); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::update_point3_from_nxVec3 +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxManager:: +update_point3_from_nxVec3(LPoint3f &p, const NxVec3 &nVec) { + + p.set_x(nVec.x); + p.set_y(nVec.y); + p.set_z(nVec.z); +} + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxManager:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxManager:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << "PhysxManager\n"; + + _scenes.ls(out, indent_level); + _heightfields.ls(out, indent_level); + _convex_meshes.ls(out, indent_level); + _triangle_meshes.ls(out, indent_level); } diff --git a/panda/src/physx/physxManager.cxx b/panda/src/physx/physxManager.cxx index 74448cf987..94c01689f1 100644 --- a/panda/src/physx/physxManager.cxx +++ b/panda/src/physx/physxManager.cxx @@ -1,5 +1,5 @@ // Filename: physxManager.cxx -// Created by: pratt (Apr 6, 2006) +// Created by: enn0x (01Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,203 +12,411 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxManager.h" -#include "config_physx.h" - #include "physxScene.h" #include "physxSceneDesc.h" -#include "physxMaterial.h" + +PhysxManager *PhysxManager::_global_ptr; +PhysxManager::PhysxOutputStream PhysxManager::_outputStream; //////////////////////////////////////////////////////////////////// -// Function : PhysxManager -// Access : Published -// Description : +// Function: PhysxManager::Constructor +// Access: Protected +// Description: //////////////////////////////////////////////////////////////////// PhysxManager:: PhysxManager() { - nPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, &debugStream); - if(!nPhysicsSDK) { - //TODO: handle better + + // Create PhysX SDK + NxSDKCreateError error; + NxPhysicsSDKDesc desc = NxPhysicsSDKDesc(); + + _sdk = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, &_outputStream, desc, &error); + + if (error == NXCE_NO_ERROR) { + physx_cat.info() << "PhysX subsystem initialized. Number of PPUs=" + << _sdk->getNbPPUs() << endl; } - if(physx_want_visual_debugger) { - physx_info( "connecting to visual debugger at (" << physx_visual_debugger_host << ":" << physx_visual_debugger_port << ")" ); - nRemoteDebugger = nPhysicsSDK->getFoundationSDK().getRemoteDebugger(); - nRemoteDebugger->connect( physx_visual_debugger_host.c_str(), physx_visual_debugger_port ); - if(! nRemoteDebugger->isConnected()) { - physx_warning( "Warning: could not connect to visual debugger" ); + else { + physx_cat.error() << "Error when setting up the PhysX subsystem: " + << get_sdk_error_string(error) << endl; + } + + nassertv_always(error == NXCE_NO_ERROR); + nassertv_always(_sdk); + + // Set some default parameters + _sdk->setParameter(NX_VISUALIZATION_SCALE, 0.0f); + _sdk->setParameter(NX_VISUALIZE_COLLISION_SHAPES, true); + _sdk->setParameter(NX_VISUALIZE_ACTOR_AXES, true); + _sdk->setParameter(NX_VISUALIZE_BODY_LIN_VELOCITY, true); + _sdk->setParameter(NX_VISUALIZE_COLLISION_AABBS, false); + _sdk->setParameter(NX_VISUALIZE_COLLISION_VNORMALS, false); + _sdk->setParameter(NX_VISUALIZE_COLLISION_FNORMALS, false); + _sdk->setParameter(NX_VISUALIZE_FORCE_FIELDS, false); + + // Connect VDR + if(physx_want_vrd) { + physx_cat.info() << "Connecting to visual remote debugger at (" + << physx_vrd_host << ":" + << physx_vrd_port << ")" << endl; + + NxRemoteDebugger *debugger = _sdk->getFoundationSDK().getRemoteDebugger(); + + debugger->connect(physx_vrd_host.c_str(), + physx_vrd_port); + + if (!debugger->isConnected()) { + physx_cat.warning() << "Could not connect to visual remot debugger!" << endl; } } + } //////////////////////////////////////////////////////////////////// -// Function : ~PhysxManager -// Access : Published -// Description : +// Function: PhysxManager::Destructor +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// PhysxManager:: ~PhysxManager() { - nPhysicsSDK->release(); + + // Disconnect VRD + if(physx_want_vrd) { + NxRemoteDebugger *debugger = _sdk->getFoundationSDK().getRemoteDebugger(); + if (!debugger->isConnected()) { + debugger->disconnect(); + } + } + + // Release PhysX SDK + NxReleasePhysicsSDK(_sdk); } //////////////////////////////////////////////////////////////////// -// Function : set_parameter -// Access : Published -// Description : +// Function: PhysxManager::get_global_ptr +// Access: Published +// Description: Returns a pointer to the global PhysxManager +// object. //////////////////////////////////////////////////////////////////// -void PhysxManager:: -set_parameter(PhysxParameter parameterType, float value) { - nPhysicsSDK->setParameter((NxParameter)parameterType, value); +PhysxManager *PhysxManager:: +get_global_ptr() { + + if (_global_ptr == (PhysxManager *)NULL) { + _global_ptr = new PhysxManager; + } + + return _global_ptr; } //////////////////////////////////////////////////////////////////// -// Function : get_parameter -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxManager:: -get_parameter(PhysxParameter parameterType) { - return nPhysicsSDK->getParameter((NxParameter)parameterType); -} - -//////////////////////////////////////////////////////////////////// -// Function : create_scene -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxScene * PhysxManager:: -create_scene(PhysxSceneDesc &sceneDesc) { - // use active transforms - sceneDesc.nSceneDesc.flags |= NX_SF_ENABLE_ACTIVETRANSFORMS; - - NxScene *nScene = nPhysicsSDK->createScene(sceneDesc.nSceneDesc); - PhysxScene *pScene = new PhysxScene(); - nScene->userData = pScene; - pScene->nScene = nScene; - - // hack job for now -- set some defaults for the default material - NxMaterial *defaultMaterial = nScene->getMaterialFromIndex(0); - defaultMaterial->setRestitution(0.0f); - defaultMaterial->setStaticFriction(0.5f); - defaultMaterial->setDynamicFriction(0.5f); - - // Create PhysxMaterial for default material - PhysxMaterial *pMaterial = new PhysxMaterial(); - pMaterial->nMaterial = defaultMaterial; - defaultMaterial->userData = pMaterial; - - return pScene; -} - -//////////////////////////////////////////////////////////////////// -// Function : release_scene -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxManager:: -release_scene(PhysxScene *scene) { - nPhysicsSDK->releaseScene(*(scene->nScene)); - delete scene; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_num_scenes -// Access : Published -// Description : +// Function: PhysxManager::get_num_scenes +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// unsigned int PhysxManager:: -get_num_scenes() { - return nPhysicsSDK->getNbScenes(); +get_num_scenes() const { + + return _sdk->getNbScenes(); } //////////////////////////////////////////////////////////////////// -// Function : get_scene -// Access : Published -// Description : +// Function: PhysxManager::create_scene +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -PhysxScene * PhysxManager:: -get_scene(unsigned int i) { - return (PhysxScene *)nPhysicsSDK->getScene(i)->userData; +PT(PhysxScene) PhysxManager:: +create_scene(PhysxSceneDesc &desc) { + + nassertr(desc.is_valid(),NULL); + + //_desc.timeStepMethod = NX_TIMESTEP_FIXED; + //_desc.maxTimestep = 1.0f / 240.0f; + //_desc.maxIter = 8; + + desc._desc.flags |= NX_SF_ENABLE_ACTIVETRANSFORMS; + desc._desc.flags |= NX_SF_SIMULATE_SEPARATE_THREAD; + + PT(PhysxScene) scene = new PhysxScene(); + nassertr(scene, NULL); + + NxScene *scenePtr = _sdk->createScene(desc._desc); + nassertr(scenePtr, NULL); + + scene->link(scenePtr); + + return scene; } //////////////////////////////////////////////////////////////////// -// Function : is_hardware_available -// Access : Published -// Description : +// Function: PhysxManager::get_scene +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxScene) PhysxManager:: +get_scene(unsigned int idx) const { + + nassertr_always(idx < _sdk->getNbScenes(), NULL); + + NxScene *scenePtr = _sdk->getScene(idx); + PhysxScene *scene = (PhysxScene *)(scenePtr->userData); + + return scene; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_num_height_fields +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +unsigned int PhysxManager:: +get_num_height_fields() { + + return _sdk->getNbHeightFields(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::create_height_field +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxHeightField) PhysxManager:: +create_height_field(PhysxHeightFieldDesc &desc) { + + nassertr(desc.is_valid(),NULL); + + PT(PhysxHeightField) hf = new PhysxHeightField(); + nassertr(hf, NULL); + + NxHeightField *hfPtr = _sdk->createHeightField(desc._desc); + nassertr(hfPtr, NULL); + + hf->link(hfPtr); + + return hf; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_height_field +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxHeightField) PhysxManager:: +get_height_field(unsigned int idx) { + + nassertr_always(idx < _sdk->getNbHeightFields(), NULL); + + return (PhysxHeightField *)_heightfields[idx]; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_num_convex_meshes +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +unsigned int PhysxManager:: +get_num_convex_meshes() { + + return _sdk->getNbConvexMeshes(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_convex_mesh +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxConvexMesh) PhysxManager:: +get_convex_mesh(unsigned int idx) { + + nassertr_always(idx < _sdk->getNbConvexMeshes(), NULL); + + return (PhysxConvexMesh *)_convex_meshes[idx]; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_num_triangle_meshes +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +unsigned int PhysxManager:: +get_num_triangle_meshes() { + + return _sdk->getNbTriangleMeshes(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_triangle_mesh +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxTriangleMesh) PhysxManager:: +get_triangle_mesh(unsigned int idx) { + + nassertr_always(idx < _sdk->getNbTriangleMeshes(), NULL); + + return (PhysxTriangleMesh *)_triangle_meshes[idx]; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::is_hardware_available +// Access: Published +// Description: Returns TRUE if a physcis hardware is available +// on the host system. //////////////////////////////////////////////////////////////////// bool PhysxManager:: is_hardware_available() { - return nPhysicsSDK->getHWVersion() != NX_HW_VERSION_NONE; + + return _sdk->getHWVersion() != NX_HW_VERSION_NONE; } //////////////////////////////////////////////////////////////////// -// Function : PhysxOutputStream::reportError -// Access : private -// Description : pass on error messages from the PhysX SDK +// Function: PhysxManager::get_num_ppus +// Access: Published +// Description: Reports the number of PPUs installed in the host +// system. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxManager:: +get_num_ppus() { + + return _sdk->getNbPPUs(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_hw_version +// Access: Published +// Description: Reports the available revision of the PhysX +// Hardware. Returns 0 if there is no hardware present +// in the machine, 1 for the PhysX Athena revision +// 1.0 card. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxManager:: +get_hw_version() { + + return _sdk->getHWVersion(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_internal_version +// Access: Published +// Description: Reports the internal API version number of the SDK. +//////////////////////////////////////////////////////////////////// +const char *PhysxManager:: +get_internal_version() { + + NxU32 apiRev; + NxU32 descRev; + NxU32 branchId; + NxU32 v; + + v = _sdk->getInternalVersion(apiRev, descRev, branchId); + + stringstream version; + version << "version:" << (unsigned int)v + << " apiRef:" << (unsigned int)apiRev + << " descRev:" << (unsigned int)descRev + << " branchId: " << (unsigned int)branchId; + + return version.str().c_str(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::set_parameter +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxManager:: +set_parameter(PhysxParameter param, float value) { + + _sdk->setParameter((NxParameter)param, value); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_parameter +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxManager:: +get_parameter(PhysxParameter param) { + + return _sdk->getParameter((NxParameter)param); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_sdk_error_string +// Access: Private +// Description: Returns the NxSDKCreateError enum as string. +//////////////////////////////////////////////////////////////////// +const char *PhysxManager:: +get_sdk_error_string(const NxSDKCreateError &error) { + + switch (error) { + case NXCE_NO_ERROR: return "NXCE_NO_ERROR"; break; + case NXCE_PHYSX_NOT_FOUND: return "NXCE_PHYSX_NOT_FOUND"; break; + case NXCE_WRONG_VERSION: return "NXCE_WRONG_VERSION"; break; + case NXCE_DESCRIPTOR_INVALID: return "NXCE_DESCRIPTOR_INVALID"; break; + case NXCE_CONNECTION_ERROR: return "NXCE_CONNECTION_ERROR"; break; + case NXCE_RESET_ERROR: return "NXCE_RESET_ERROR"; break; + case NXCE_IN_USE_ERROR: return "NXCE_IN_USE_ERROR"; break; + case NXCE_BUNDLE_ERROR: return "NXCE_BUNDLE_ERROR"; break; + default: return "Unknown error"; break; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxOutputStream::reportError +// Access: Private +// Description: Reports an error code from the PhysX SDK. //////////////////////////////////////////////////////////////////// void PhysxManager::PhysxOutputStream:: reportError(NxErrorCode code, const char *message, const char *file, int line) { - string output = "PhysX SDK Error: "; - switch(code) { - case NXE_NO_ERROR: - output += "NO_ERROR - "; - break; - case NXE_INVALID_PARAMETER: - output += "INVALID_PARAMETER - "; - break; - case NXE_INVALID_OPERATION: - output += "INVALID_OPERATION - "; - break; - case NXE_OUT_OF_MEMORY: - output += "OUT_OF_MEMORY - "; - break; - case NXE_INTERNAL_ERROR: - output += "INTERNAL_ERROR - "; - break; - case NXE_ASSERTION: - output += "ASSERTION - "; - break; - case NXE_DB_INFO: - output += "DB_INFO - "; - break; - case NXE_DB_WARNING: - output += "DB_WARNING - "; - break; - case NXE_DB_PRINT: - output += "DB_PRINT - "; - break; - } + physx_cat.error() << get_error_code_string(code) << ": " + << message << endl; +} - output += message; - - if(code == NXE_NO_ERROR || code == NXE_DB_INFO || code == NXE_DB_PRINT) { - physx_debug(output); - } else { - physx_warning(output); +//////////////////////////////////////////////////////////////////// +// Function: PhysxOutputStream::get_error_code_string +// Access: Private +// Description: Returns the NxSDKCreateError enum as string. +//////////////////////////////////////////////////////////////////// +const char *PhysxManager::PhysxOutputStream:: +get_error_code_string(NxErrorCode code) { + + switch (code) { + case NXE_NO_ERROR: return "NO_ERROR"; break; + case NXE_INVALID_PARAMETER: return "INVALID_PARAMETER"; break; + case NXE_INVALID_OPERATION: return "INVALID_OPERATION"; break; + case NXE_OUT_OF_MEMORY: return "OUT_OF_MEMORY"; break; + case NXE_INTERNAL_ERROR: return "INTERNAL_ERROR"; break; + case NXE_ASSERTION: return "ASSERTION"; break; + case NXE_DB_INFO: return "DB_INFO"; break; + case NXE_DB_WARNING: return "DB_WARNING"; break; + case NXE_DB_PRINT: return "DB_PRINT"; break; + default: return ""; break; } } //////////////////////////////////////////////////////////////////// -// Function : PhysxOutputStream::reportAssertViolation -// Access : private -// Description : +// Function: PhysxOutputStream::reportAssertViolation +// Access: Private +// Description: Reports an assertion violation from the PhysX SDK. //////////////////////////////////////////////////////////////////// NxAssertResponse PhysxManager::PhysxOutputStream:: reportAssertViolation(const char *message, const char *file, int line) { + + physx_cat.error() << "AssertViolation: " << message << endl; + return NX_AR_CONTINUE; } //////////////////////////////////////////////////////////////////// -// Function : PhysxOutputStream::print -// Access : private -// Description : +// Function: PhysxOutputStream::print +// Access: Private +// Description: Prints some debug text from the PhysX SDK. //////////////////////////////////////////////////////////////////// void PhysxManager::PhysxOutputStream:: print(const char *message) { + + nout << message; } -#endif // HAVE_PHYSX - - diff --git a/panda/src/physx/physxManager.h b/panda/src/physx/physxManager.h index 910718777c..12244fbcd3 100644 --- a/panda/src/physx/physxManager.h +++ b/panda/src/physx/physxManager.h @@ -1,5 +1,5 @@ // Filename: physxManager.h -// Created by: pratt (Apr 6, 2006) +// Created by: enn0x (01Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,73 +15,110 @@ #ifndef PHYSXMANAGER_H #define PHYSXMANAGER_H -#ifdef HAVE_PHYSX - #include "pandabase.h" #include "pointerTo.h" #include "luse.h" -#include "physx_enumerations.h" +#include "physxEnums.h" +#include "physxObjectCollection.h" +#include "NoMinMax.h" #include "NxPhysics.h" +#include "NxExtended.h" class PhysxScene; class PhysxSceneDesc; +class PhysxHeightField; +class PhysxHeightFieldDesc; //////////////////////////////////////////////////////////////////// // Class : PhysxManager -// Description : This is the central manager for the Panda interface -// to the Ageia PhysX SDK. +// Description : The central interface to the PhysX subsystem. +// Used e. g. for setting/retrieving global parameters +// or for creating scenes. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxManager { -PUBLISHED: +class EXPCL_PANDAPHYSX PhysxManager : public PhysxEnums { + +protected: PhysxManager(); - ~PhysxManager(); - -// make enumerations available to Python interface -#undef PHYSX_ENUMERATIONS_H -#ifdef CPPPARSER -#include "physx_enumerations_for_interrogate.h" -#else -#include "physx_enumerations.h" -#endif - - void set_parameter(PhysxParameter parameterType, float value); - float get_parameter(PhysxParameter parameterType); - - PhysxScene *create_scene(PhysxSceneDesc &sceneDesc); - void release_scene(PhysxScene *scene); - - unsigned int get_num_scenes(); - PhysxScene *get_scene(unsigned int i); - - bool is_hardware_available(); public: - INLINE static LVecBase3f nxVec3_to_lVecBase3(const NxVec3 &vec); - INLINE static LMatrix3f nxMat33_to_lMatrix3(const NxMat33 &mat); - INLINE static LMatrix4f nxMat34_to_lMatrix4(const NxMat34 &mat); - INLINE static LQuaternionf nxQuat_to_lQuaternion(const NxQuat &quat); + ~PhysxManager(); - INLINE static NxVec3 lVecBase3_to_nxVec3(const LVecBase3f &vec); - INLINE static NxMat33 lMatrix3_to_nxMat33(const LMatrix3f &mat); - INLINE static NxMat34 lMatrix4_to_nxMat34(const LMatrix4f &mat); - INLINE static NxQuat lQuaternion_to_nxQuat(const LQuaternionf &quat); +PUBLISHED: + static PhysxManager *get_global_ptr(); + + void set_parameter(PhysxParameter param, float value); + float get_parameter(PhysxParameter param); + + bool is_hardware_available(); + unsigned int get_num_ppus(); + unsigned int get_hw_version(); + const char *get_internal_version(); + + unsigned int get_num_scenes() const; + PT(PhysxScene) create_scene(PhysxSceneDesc &desc); + PT(PhysxScene) get_scene(unsigned int idx) const; + MAKE_SEQ(get_scenes, get_num_scenes, get_scene); + + unsigned int get_num_height_fields(); + PT(PhysxHeightField) create_height_field(PhysxHeightFieldDesc &desc); + PT(PhysxHeightField) get_height_field(unsigned int idx); + MAKE_SEQ(get_height_fields, get_num_height_fields, get_height_field); + + unsigned int get_num_convex_meshes(); + PT(PhysxConvexMesh) get_convex_mesh(unsigned int idx); + MAKE_SEQ(get_convex_meshes, get_num_convex_meshes, get_convex_mesh); + + unsigned int get_num_triangle_meshes(); + PT(PhysxTriangleMesh) get_triangle_mesh(unsigned int idx); + MAKE_SEQ(get_triangle_meshes, get_num_triangle_meshes, get_triangle_mesh); + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +public: + INLINE NxPhysicsSDK *get_sdk() const; + + PhysxObjectCollection _scenes; + PhysxObjectCollection _heightfields; + PhysxObjectCollection _convex_meshes; + PhysxObjectCollection _triangle_meshes; + + INLINE static NxVec3 vec3_to_nxVec3(const LVector3f &v); + INLINE static LVector3f nxVec3_to_vec3(const NxVec3 &v); + INLINE static NxExtendedVec3 vec3_to_nxExtVec3(const LVector3f &v); + INLINE static LVector3f nxExtVec3_to_vec3(const NxExtendedVec3 &v); + INLINE static NxVec3 point3_to_nxVec3(const LPoint3f &p); + INLINE static LPoint3f nxVec3_to_point3(const NxVec3 &p); + INLINE static NxExtendedVec3 point3_to_nxExtVec3(const LPoint3f &p); + INLINE static LPoint3f nxExtVec3_to_point3(const NxExtendedVec3 &p); + INLINE static NxQuat quat_to_nxQuat(const LQuaternionf &q); + INLINE static LQuaternionf nxQuat_to_quat(const NxQuat &q); + INLINE static NxMat34 mat4_to_nxMat34(const LMatrix4f &m); + INLINE static LMatrix4f nxMat34_to_mat4(const NxMat34 &m); + INLINE static NxMat33 mat3_to_nxMat33(const LMatrix3f &m); + INLINE static LMatrix3f nxMat33_to_mat3(const NxMat33 &m); + + INLINE static void update_vec3_from_nxVec3(LVector3f &v, const NxVec3 &nVec); + INLINE static void update_point3_from_nxVec3(LPoint3f &p, const NxVec3 &nVec); private: - NxPhysicsSDK *nPhysicsSDK; - NxRemoteDebugger *nRemoteDebugger; + NxPhysicsSDK *_sdk; + + static PhysxManager *_global_ptr; class PhysxOutputStream : public NxUserOutputStream { void reportError(NxErrorCode code, const char *message, const char *file, int line); NxAssertResponse reportAssertViolation(const char *message, const char *file, int line); void print(const char *message); + const char *get_error_code_string(NxErrorCode code); }; - PhysxOutputStream debugStream; + static PhysxOutputStream _outputStream; + + static const char *get_sdk_error_string(const NxSDKCreateError &error); }; #include "physxManager.I" -#endif // HAVE_PHYSX - #endif // PHYSXMANAGER_H diff --git a/panda/src/physx/physxMask.I b/panda/src/physx/physxMask.I new file mode 100644 index 0000000000..b93a166cc5 --- /dev/null +++ b/panda/src/physx/physxMask.I @@ -0,0 +1,47 @@ +// Filename: physxMask32.cxx +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMask::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxMask:: +PhysxMask() { + + _mask = 0xffffffff; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMask::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxMask:: +~PhysxMask() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMask::get_mask +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE NxU32 PhysxMask:: +get_mask() const { + + return _mask; +} + diff --git a/panda/src/physx/physxMask.cxx b/panda/src/physx/physxMask.cxx new file mode 100644 index 0000000000..f40cf4c9dc --- /dev/null +++ b/panda/src/physx/physxMask.cxx @@ -0,0 +1,100 @@ +// Filename: physxMask32.cxx +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxMask.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMask::all_on +// Access: Published +// Description: Returns a PhysxMask whose bits are all on. +//////////////////////////////////////////////////////////////////// +PhysxMask PhysxMask:: +all_on() { + + PhysxMask mask; + mask._mask = 0xffffffff; + return mask; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMask::all_off +// Access: Published +// Description: Returns a PhysxMask whose bits are all off. +//////////////////////////////////////////////////////////////////// +PhysxMask PhysxMask:: +all_off() { + + PhysxMask mask; + mask._mask = 0x0000000; + return mask; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMask::set_bit +// Access: Published +// Description: Sets the nth bit on. +// Index must be in the range [0, 31]. +//////////////////////////////////////////////////////////////////// +void PhysxMask:: +set_bit(unsigned int idx) { + + nassertv_always(idx >= 0 && idx <= 31); + _mask = _mask | (1 << idx); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMask::clear_bit +// Access: Published +// Description: Sets the nth bit off. +// Index must be in the range [0, 31]. +//////////////////////////////////////////////////////////////////// +void PhysxMask:: +clear_bit(unsigned int idx) { + + nassertv_always(idx >= 0 && idx <= 31); + _mask = _mask & ~(1 << idx); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMask::get_bit +// Access: Published +// Description: Returns true if the nth bit is set, false if it is +// cleared. +// Index must be in the range [0, 31]. +//////////////////////////////////////////////////////////////////// +bool PhysxMask:: +get_bit(unsigned int idx) const { + + nassertr_always(idx >= 0 && idx <= 31, false); + return (_mask & (1 << idx)) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMask::output +// Access: Published +// Description: Writes the PhysxMask out as a list of ones and +// zeros. +//////////////////////////////////////////////////////////////////// +void PhysxMask:: +output(ostream &out) const { + + string name; + + for (int i=0; i<32; i++) { + name += (_mask & (1 << i)) ? '1' : '0'; + } + + out << "/" << name << "/"; +} + diff --git a/panda/src/physx/physxMask.h b/panda/src/physx/physxMask.h new file mode 100644 index 0000000000..953843014a --- /dev/null +++ b/panda/src/physx/physxMask.h @@ -0,0 +1,56 @@ +// Filename: physxMask32.h +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXMASK_H +#define PHYSXMASK_H + +#include "pandabase.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxMask +// Description : 32-bit bitmask class. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxMask { + +PUBLISHED: + INLINE PhysxMask(); + INLINE ~PhysxMask(); + + void set_bit(unsigned int idx); + void clear_bit(unsigned int idx); + bool get_bit(unsigned int idx) const; + + void output(ostream &out) const; + + static PhysxMask all_on(); + static PhysxMask all_off(); + +public: + INLINE NxU32 get_mask() const; + +private: + NxU32 _mask; +}; + +INLINE ostream &operator << (ostream &out, const PhysxMask &mask) { + mask.output(out); + return out; +} + +#include "physxMask.I" + +#endif // PHYSXMASK_H diff --git a/panda/src/physx/physxMaterial.I b/panda/src/physx/physxMaterial.I index a167f37e7f..448b8f173f 100644 --- a/panda/src/physx/physxMaterial.I +++ b/panda/src/physx/physxMaterial.I @@ -1,5 +1,5 @@ // Filename: physxMaterial.I -// Created by: pratt (Jul 9, 2006) +// Created by: enn0x (21Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,3 +12,48 @@ // //////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxMaterial:: +PhysxMaterial() : PhysxObject() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxMaterial:: +~PhysxMaterial() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxMaterial:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxMaterial:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " (at 0x" << this << ")\n"; +} + diff --git a/panda/src/physx/physxMaterial.cxx b/panda/src/physx/physxMaterial.cxx index c5d6c0a182..f6f2fe5641 100644 --- a/panda/src/physx/physxMaterial.cxx +++ b/panda/src/physx/physxMaterial.cxx @@ -1,5 +1,5 @@ // Filename: physxMaterial.cxx -// Created by: pratt (Jul 9, 2006) +// Created by: enn0x (21Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,274 +12,373 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxMaterial.h" - -#include "luse.h" #include "physxMaterialDesc.h" -#include "physxScene.h" +#include "physxManager.h" +TypeHandle PhysxMaterial::_type_handle; //////////////////////////////////////////////////////////////////// -// Function : get_dir_of_anisotropy -// Access : Published -// Description : +// Function: PhysxMaterial::link +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxMaterial:: -get_dir_of_anisotropy() const { - nassertr(nMaterial != NULL, *((LVecBase3f *)NULL)); +void PhysxMaterial:: +link(NxMaterial *materialPtr) { - return PhysxManager::nxVec3_to_lVecBase3(nMaterial->getDirOfAnisotropy()); + // Link self + _ptr = materialPtr; + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_materials.add(this); } //////////////////////////////////////////////////////////////////// -// Function : get_dynamic_friction -// Access : Published -// Description : +// Function: PhysxMaterial::unlink +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// -float PhysxMaterial:: -get_dynamic_friction() const { - nassertr(nMaterial != NULL, -1.0f); +void PhysxMaterial:: +unlink() { - return nMaterial->getDynamicFriction(); + // Unlink self + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_materials.remove(this); } //////////////////////////////////////////////////////////////////// -// Function : get_dynamic_friction_v -// Access : Published -// Description : +// Function: PhysxMaterial::release +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -float PhysxMaterial:: -get_dynamic_friction_v() const { - nassertr(nMaterial != NULL, -1.0f); +void PhysxMaterial:: +release() { - return nMaterial->getDynamicFrictionV(); + nassertv(_error_type == ET_ok); + + unlink(); + _ptr->getScene().releaseMaterial(*_ptr); + _ptr = NULL; } //////////////////////////////////////////////////////////////////// -// Function : get_flags -// Access : Published -// Description : +// Function: PhysxMaterial::get_scene +// Access: Published +// Description: Returns the scene that owns this material. //////////////////////////////////////////////////////////////////// -unsigned int PhysxMaterial:: -get_flags() const { - nassertr(nMaterial != NULL, -1); +PT(PhysxScene) PhysxMaterial:: +get_scene() const { - return nMaterial->getFlags(); + nassertr(_error_type == ET_ok, NULL); + return (PhysxScene *)(_ptr->getScene().userData); } //////////////////////////////////////////////////////////////////// -// Function : get_friction_combine_mode -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxCombineMode PhysxMaterial:: -get_friction_combine_mode() const { - return (PhysxCombineMode)nMaterial->getFrictionCombineMode(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_material_index -// Access : Published -// Description : +// Function: PhysxMaterial::get_material_index +// Access: Published +// Description: Returns the material index for this material. +// +// Materials are associated with mesh faces and shapes +// using material index identifiers. +// +// If you release a material while its material index +// is still in use by shapes or meshes, the material +// usage of these objects becomes undefined as the +// material index gets recycled. //////////////////////////////////////////////////////////////////// unsigned short PhysxMaterial:: -get_material_index() { - nassertr(nMaterial != NULL, -1); +get_material_index() const { - return nMaterial->getMaterialIndex(); + nassertr(_error_type == ET_ok, 0); + return _ptr->getMaterialIndex(); } //////////////////////////////////////////////////////////////////// -// Function : get_restitution +// Function : PhysxMaterial::load_from_desc // Access : Published -// Description : +// Description : Loads the entire state of the material from a +// descriptor with a single call. +//////////////////////////////////////////////////////////////////// +void PhysxMaterial:: +load_from_desc(const PhysxMaterialDesc &materialDesc) { + + nassertv(_error_type == ET_ok); + _ptr->loadFromDesc(materialDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxMaterial::save_to_desc +// Access : Published +// Description : Saves the state of the material object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxMaterial:: +save_to_desc(PhysxMaterialDesc & materialDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(materialDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::set_restitution +// Access: Published +// Description: Sets the coefficient of restitution. +// A coefficient of 0 makes the object bounce as +// little as possible, higher values up to 1.0 result +// in more bounce. +//////////////////////////////////////////////////////////////////// +void PhysxMaterial:: +set_restitution(float restitution) { + + nassertv(_error_type == ET_ok); + _ptr->setRestitution(restitution); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::get_restitution +// Access: Published +// Description: Returns the coefficient of restitution. //////////////////////////////////////////////////////////////////// float PhysxMaterial:: get_restitution() const { - nassertr(nMaterial != NULL, -1.0f); - return nMaterial->getRestitution(); + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getRestitution(); } //////////////////////////////////////////////////////////////////// -// Function : get_restitution_combine_mode -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxCombineMode PhysxMaterial:: -get_restitution_combine_mode() const { - return (PhysxCombineMode)nMaterial->getRestitutionCombineMode(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_scene -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxScene & PhysxMaterial:: -get_scene() const { - nassertr(nMaterial != NULL, *((PhysxScene *)NULL)); - - return *((PhysxScene *)(nMaterial->getScene().userData)); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_static_friction -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxMaterial:: -get_static_friction() const { - nassertr(nMaterial != NULL, -1.0f); - - return nMaterial->getStaticFriction(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_static_friction_v -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxMaterial:: -get_static_friction_v() const { - nassertr(nMaterial != NULL, -1.0f); - - return nMaterial->getStaticFrictionV(); -} - -//////////////////////////////////////////////////////////////////// -// Function : load_from_desc -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterial:: -load_from_desc(const PhysxMaterialDesc & desc) { - nassertv(nMaterial != NULL); - - nMaterial->loadFromDesc(desc.nMaterialDesc); -} - -//////////////////////////////////////////////////////////////////// -// Function : save_to_desc -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterial:: -save_to_desc(PhysxMaterialDesc & desc) const { - nassertv(nMaterial != NULL); - - nMaterial->saveToDesc(desc.nMaterialDesc); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_dir_of_anisotropy -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterial:: -set_dir_of_anisotropy(const LVecBase3f & vec) { - nassertv(nMaterial != NULL); - - nMaterial->setDirOfAnisotropy(PhysxManager::lVecBase3_to_nxVec3(vec)); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_dynamic_friction -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterial:: -set_dynamic_friction(float coef) { - nassertv(nMaterial != NULL); - - nMaterial->setDynamicFriction(coef); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_dynamic_friction_v -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterial:: -set_dynamic_friction_v(float coef) { - nassertv(nMaterial != NULL); - - nMaterial->setDynamicFrictionV(coef); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterial:: -set_flags(unsigned int flags) { - nassertv(nMaterial != NULL); - - nMaterial->setFlags(flags); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_friction_combine_mode -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterial:: -set_friction_combine_mode(PhysxCombineMode comb_mode) { - nassertv(nMaterial != NULL); - - nMaterial->setFrictionCombineMode((NxCombineMode)comb_mode); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_restitution -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterial:: -set_restitution(float rest) { - nassertv(nMaterial != NULL); - - nMaterial->setRestitution(rest); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_restitution_combine_mode -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterial:: -set_restitution_combine_mode(PhysxCombineMode comb_mode) { - nassertv(nMaterial != NULL); - - nMaterial->setRestitutionCombineMode((NxCombineMode)comb_mode); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_static_friction -// Access : Published -// Description : +// Function: PhysxMaterial::set_static_friction +// Access: Published +// Description: Sets the coefficient of static friction. +// The coefficient of static friction should be in the +// range [0, +inf]. +// If the flag MF_anisotropic is set, then this value +// is used for the primary direction of anisotropy +// (U axis). //////////////////////////////////////////////////////////////////// void PhysxMaterial:: set_static_friction(float coef) { - nassertv(nMaterial != NULL); - nMaterial->setStaticFriction(coef); + nassertv(_error_type == ET_ok); + _ptr->setStaticFriction(coef); } //////////////////////////////////////////////////////////////////// -// Function : set_static_friction_v -// Access : Published -// Description : +// Function: PhysxMaterial::get_static_friction +// Access: Published +// Description: Returns the coefficient of static friction. +//////////////////////////////////////////////////////////////////// +float PhysxMaterial:: +get_static_friction() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getStaticFriction(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::set_dynamic_friction +// Access: Published +// Description: Sets the coefficient of dynamic friction. +// The coefficient of dynamic friction should be in +// [0, +inf]. If set to greater than staticFriction, +// the effective value of staticFriction will be +// increased to match. +// If the flag MF_anisotropic is set, then this value +// is used for the primary direction of anisotropy +// (U axis). +//////////////////////////////////////////////////////////////////// +void PhysxMaterial:: +set_dynamic_friction(float coef) { + + nassertv(_error_type == ET_ok); + _ptr->setDynamicFriction(coef); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::get_dynamic_friction +// Access: Published +// Description: Returns the DynamicFriction value. +//////////////////////////////////////////////////////////////////// +float PhysxMaterial:: +get_dynamic_friction() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getDynamicFriction(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::set_static_friction_v +// Access: Published +// Description: Sets the static friction coefficient along the +// secondary (V) axis. This is used when anisotropic +// friction is being applied. I.e. the flag +// MF_anisotropic is set. //////////////////////////////////////////////////////////////////// void PhysxMaterial:: set_static_friction_v(float coef) { - nassertv(nMaterial != NULL); - nMaterial->setStaticFrictionV(coef); + nassertv(_error_type == ET_ok); + _ptr->setStaticFrictionV(coef); } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::get_static_friction_v +// Access: Published +// Description: Returns the static friction coefficient for the +// V direction. +//////////////////////////////////////////////////////////////////// +float PhysxMaterial:: +get_static_friction_v() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getStaticFrictionV(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::set_dynamic_friction_v +// Access: Published +// Description: Sets the dynamic friction coefficient along the +// secondary (V) axis. This is used when anisotropic +// friction is being applied. I.e. the flag +// MF_anisotropic is set. +//////////////////////////////////////////////////////////////////// +void PhysxMaterial:: +set_dynamic_friction_v(float coef) { + + nassertv(_error_type == ET_ok); + _ptr->setDynamicFrictionV(coef); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::get_dynamic_friction_v +// Access: Published +// Description: Returns the dynamic friction coefficient for the +// V direction. +//////////////////////////////////////////////////////////////////// +float PhysxMaterial:: +get_dynamic_friction_v() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getDynamicFrictionV(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::set_flag +// Access: Published +// Description: Sets the value of a single flag. +//////////////////////////////////////////////////////////////////// +void PhysxMaterial:: +set_flag(PhysxMaterialFlag flag, bool value) { + + nassertv(_error_type == ET_ok); + NxU32 flags = _ptr->getFlags(); + + if (value == true) { + flags |= flag; + } + else { + flags &= ~(flag); + } + + _ptr->setFlags(flags); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::get_flag +// Access: Published +// Description: Returns the value of a single flag. +//////////////////////////////////////////////////////////////////// +bool PhysxMaterial:: +get_flag(PhysxMaterialFlag flag) const { + + nassertr(_error_type == ET_ok, false); + return (_ptr->getFlags() & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::set_dir_of_anisotropy +// Access: Published +// Description: Sets the shape space direction (unit vector) of +// anisotropy. This is only used if the flag +// MF_anisotropic is set. +//////////////////////////////////////////////////////////////////// +void PhysxMaterial:: +set_dir_of_anisotropy(const LVector3f dir) { + + nassertv(_error_type == ET_ok); + _ptr->setDirOfAnisotropy(PhysxManager::vec3_to_nxVec3(dir)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::get_dir_of_anisotropy +// Access: Published +// Description: Returns the direction of anisotropy value. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxMaterial:: +get_dir_of_anisotropy() const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + return PhysxManager::nxVec3_to_vec3(_ptr->getDirOfAnisotropy()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::set_friction_combine_mode +// Access: Published +// Description: Sets the friction combine mode. +// - CM_average : Average: (a + b)/2. +// - CM_min : Minimum: min(a,b). +// - CM_multiply : Multiply: a*b. +// - CM_max : Maximum: max(a,b). +//////////////////////////////////////////////////////////////////// +void PhysxMaterial:: +set_friction_combine_mode(PhysxCombineMode mode) { + + nassertv(_error_type == ET_ok); + _ptr->setFrictionCombineMode((NxCombineMode)mode); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::get_friction_combine_mode +// Access: Published +// Description: Returns the friction combine mode. +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxCombineMode PhysxMaterial:: +get_friction_combine_mode() const { + + nassertr(_error_type == ET_ok, CM_average); + return (PhysxCombineMode)_ptr->getFrictionCombineMode(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::set_restitution_combine_mode +// Access: Published +// Description: Sets the restitution combine mode. +// - CM_average : Average: (a + b)/2. +// - CM_min : Minimum: min(a,b). +// - CM_multiply : Multiply: a*b. +// - CM_max : Maximum: max(a,b). +//////////////////////////////////////////////////////////////////// +void PhysxMaterial:: +set_restitution_combine_mode(PhysxCombineMode mode) { + + nassertv(_error_type == ET_ok); + _ptr->setRestitutionCombineMode((NxCombineMode)mode); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterial::get_restitution_combine_mode +// Access: Published +// Description: Returns the restitution combine mode. +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxCombineMode PhysxMaterial:: +get_restitution_combine_mode() const { + + nassertr(_error_type == ET_ok, CM_average); + return (PhysxCombineMode)_ptr->getRestitutionCombineMode(); +} diff --git a/panda/src/physx/physxMaterial.h b/panda/src/physx/physxMaterial.h index fbfb9b67f6..23d3cf799a 100644 --- a/panda/src/physx/physxMaterial.h +++ b/panda/src/physx/physxMaterial.h @@ -1,5 +1,5 @@ // Filename: physxMaterial.h -// Created by: pratt (Jul 9, 2006) +// Created by: enn0x (21Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,56 +15,111 @@ #ifndef PHYSXMATERIAL_H #define PHYSXMATERIAL_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "lvector3.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -class PhysxMaterialDesc; -class PhysxScene; +#include "physxObject.h" +#include "physxEnums.h" +#include "NoMinMax.h" #include "NxPhysics.h" +class PhysxScene; +class PhysxMaterialDesc; + //////////////////////////////////////////////////////////////////// // Class : PhysxMaterial -// Description : +// Description : A class for describing a shape's surface +// properties. +// +// You can create a material which has different +// friction coefficients depending on the direction +// that a body in contact is trying to move in. This +// is called anisotropic friction. +// +// Anisotropic friction is useful for modeling things +// like sledges, skis etc +// +// When you create an anisotropic material you specify +// the default friction parameters and also friction +// parameters for the V axis. The friction parameters +// for the V axis are applied to motion along the +// direction of anisotropy (dirOfAnisotropy). +// +// Default material: You can change the properties of +// the default material by querying for material +// index 0. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxMaterial { +class EXPCL_PANDAPHYSX PhysxMaterial : public PhysxObject, public PhysxEnums { + PUBLISHED: + INLINE PhysxMaterial(); + INLINE ~PhysxMaterial(); + + PT(PhysxScene) get_scene() const; + unsigned short get_material_index() const; + + void load_from_desc(const PhysxMaterialDesc &materialDesc); + void save_to_desc(PhysxMaterialDesc &materialDesc) const; - LVecBase3f get_dir_of_anisotropy() const; - float get_dynamic_friction() const; - float get_dynamic_friction_v() const; - unsigned int get_flags() const; - PhysxCombineMode get_friction_combine_mode() const; - unsigned short get_material_index(); - float get_restitution() const; - PhysxCombineMode get_restitution_combine_mode() const; - PhysxScene & get_scene() const; - float get_static_friction() const; - float get_static_friction_v() const; - void load_from_desc(const PhysxMaterialDesc & desc); - void save_to_desc(PhysxMaterialDesc & desc) const; - void set_dir_of_anisotropy(const LVecBase3f & vec); void set_dynamic_friction(float coef); - void set_dynamic_friction_v(float coef); - void set_flags(unsigned int flags); - void set_friction_combine_mode(PhysxCombineMode comb_mode); - void set_restitution(float rest); - void set_restitution_combine_mode(PhysxCombineMode comb_mode); void set_static_friction(float coef); + void set_restitution(float rest); + void set_dynamic_friction_v(float coef); void set_static_friction_v(float coef); + void set_dir_of_anisotropy(const LVector3f dir); + void set_flag(PhysxMaterialFlag flag, bool value); + void set_friction_combine_mode(PhysxCombineMode mode); + void set_restitution_combine_mode(PhysxCombineMode mode); + float get_dynamic_friction() const; + float get_static_friction() const; + float get_restitution() const; + float get_dynamic_friction_v() const; + float get_static_friction_v() const; + LVector3f get_dir_of_anisotropy() const; + bool get_flag(PhysxMaterialFlag flag) const; + PhysxCombineMode get_friction_combine_mode() const; + PhysxCombineMode get_restitution_combine_mode() const; + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +//////////////////////////////////////////////////////////////////// +PUBLISHED: + void release(); public: - NxMaterial *nMaterial; + INLINE NxMaterial *ptr() const { return _ptr; }; + + void link(NxMaterial *ptr); + void unlink(); + +private: + NxMaterial *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxObject::init_type(); + register_type(_type_handle, "PhysxMaterial", + PhysxObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; }; #include "physxMaterial.I" -#endif // HAVE_PHYSX - #endif // PHYSXMATERIAL_H diff --git a/panda/src/physx/physxMaterialDesc.I b/panda/src/physx/physxMaterialDesc.I index 1c1bc2eba8..e5e7fef644 100644 --- a/panda/src/physx/physxMaterialDesc.I +++ b/panda/src/physx/physxMaterialDesc.I @@ -1,5 +1,5 @@ // Filename: physxMaterialDesc.I -// Created by: pratt (Jul 9, 2006) +// Created by: enn0x (21Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,143 +12,47 @@ // //////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxMaterialDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxMaterialDesc:: -is_valid() const { - return nMaterialDesc.isValid(); +INLINE PhysxMaterialDesc:: +PhysxMaterialDesc() { + } //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxMaterialDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxMaterialDesc:: +~PhysxMaterialDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. //////////////////////////////////////////////////////////////////// INLINE void PhysxMaterialDesc:: set_to_default() { - nMaterialDesc.setToDefault(); + + _desc.setToDefault(); } //////////////////////////////////////////////////////////////////// -// Function : get_dynamic_friction -// Access : Published -// Description : +// Function: PhysxMaterialDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. //////////////////////////////////////////////////////////////////// -INLINE float PhysxMaterialDesc:: -get_dynamic_friction() const { - return nMaterialDesc.dynamicFriction; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_dynamic_friction_v -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxMaterialDesc:: -get_dynamic_friction_v() const { - return nMaterialDesc.dynamicFrictionV; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxMaterialDesc:: -get_flags() const { - return nMaterialDesc.flags; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_restitution -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxMaterialDesc:: -get_restitution() const { - return nMaterialDesc.restitution; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_static_friction -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxMaterialDesc:: -get_static_friction() const { - return nMaterialDesc.staticFriction; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_static_friction_v -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxMaterialDesc:: -get_static_friction_v() const { - return nMaterialDesc.staticFrictionV; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_dynamic_friction -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxMaterialDesc:: -set_dynamic_friction(float value) { - nMaterialDesc.dynamicFriction = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_dynamic_friction_v -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxMaterialDesc:: -set_dynamic_friction_v(float value) { - nMaterialDesc.dynamicFrictionV = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxMaterialDesc:: -set_flags(unsigned int value) { - nMaterialDesc.flags = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_restitution -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxMaterialDesc:: -set_restitution(float value) { - nMaterialDesc.restitution = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_static_friction -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxMaterialDesc:: -set_static_friction(float value) { - nMaterialDesc.staticFriction = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_static_friction_v -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxMaterialDesc:: -set_static_friction_v(float value) { - nMaterialDesc.staticFrictionV = value; +INLINE bool PhysxMaterialDesc:: +is_valid() const { + + return _desc.isValid(); } diff --git a/panda/src/physx/physxMaterialDesc.cxx b/panda/src/physx/physxMaterialDesc.cxx index 818ea8956e..74348b91e2 100644 --- a/panda/src/physx/physxMaterialDesc.cxx +++ b/panda/src/physx/physxMaterialDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxMaterialDesc.cxx -// Created by: pratt (Jul 9, 2006) +// Created by: enn0x (21Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,82 +12,247 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxMaterialDesc.h" - -#include "luse.h" - +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxMaterialDesc -// Access : Published -// Description : +// Function: PhysxMaterialDesc::set_restitution +// Access: Published +// Description: Sets the coefficient of restitution -- 0 makes the +// object bounce as little as possible, higher values +// up to 1.0 result in more bounce. Note that values +// close to or above 1 may cause stability problems +// and/or increasing energy. Range: [0,1] +// Default: 0.0 //////////////////////////////////////////////////////////////////// -PhysxMaterialDesc:: -PhysxMaterialDesc() { +void PhysxMaterialDesc:: +set_restitution(float restitution) { + _desc.restitution = restitution; } //////////////////////////////////////////////////////////////////// -// Function : get_dir_of_anisotropy -// Access : Published -// Description : +// Function: PhysxMaterialDesc::set_static_friction +// Access: Published +// Description: Sets the coefficient of static friction -- should +// be in [0, +inf]. +// If the flag MF_anisotropic is set, then this value +// is used for the primary direction of anisotropy +// (U axis). //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxMaterialDesc:: +void PhysxMaterialDesc:: +set_static_friction(float coef) { + + _desc.staticFriction = coef; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::set_dynamic_friction +// Access: Published +// Description: Sets the coefficient of dynamic friction -- should +// be in [0, +inf]. If set to greater than +// staticFriction, the effective value of staticFriction +// will be increased to match. +// If the flag MF_anisotropic is set, then this value +// is used for the primary direction of anisotropy +// (U axis). +//////////////////////////////////////////////////////////////////// +void PhysxMaterialDesc:: +set_dynamic_friction(float coef) { + + _desc.dynamicFriction = coef; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::set_static_friction_v +// Access: Published +// Description: Sets the anisotropic static friction coefficient +// for along the secondary (V) axis of anisotropy. +// This is only used if the flag MF_anisotropic is +// set. +//////////////////////////////////////////////////////////////////// +void PhysxMaterialDesc:: +set_static_friction_v(float coef) { + + _desc.staticFrictionV = coef; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::set_dynamic_friction_v +// Access: Published +// Description: Sets the anisotropic dynamic friction coefficient +// for along the secondary (V) axis of anisotropy. +// This is only used if the flag MF_anisotropic is +// set. +//////////////////////////////////////////////////////////////////// +void PhysxMaterialDesc:: +set_dynamic_friction_v(float coef) { + + _desc.dynamicFrictionV = coef; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::set_flag +// Access: Published +// Description: Sets flags which control the behavior of a +// material. +//////////////////////////////////////////////////////////////////// +void PhysxMaterialDesc:: +set_flag(PhysxMaterialFlag flag, bool value) { + + if (value == true) { + _desc.flags |= flag; + } + else { + _desc.flags &= ~(flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::set_dir_of_anisotropy +// Access: Published +// Description: Sets the shape space direction (unit vector) of +// anisotropy. +// This is only used if the flag MF_anisotropic is +// set. +//////////////////////////////////////////////////////////////////// +void PhysxMaterialDesc:: +set_dir_of_anisotropy(const LVector3f dir) { + + _desc.dirOfAnisotropy = PhysxManager::vec3_to_nxVec3(dir); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::set_friction_combine_mode +// Access: Published +// Description: Sets the friction combine mode. +// - CM_average : Average: (a + b)/2. +// - CM_min : Minimum: min(a,b). +// - CM_multiply : Multiply: a*b. +// - CM_max : Maximum: max(a,b). +//////////////////////////////////////////////////////////////////// +void PhysxMaterialDesc:: +set_friction_combine_mode(PhysxCombineMode mode) { + + _desc.frictionCombineMode = (NxCombineMode)mode; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::set_restitution_combine_mode +// Access: Published +// Description: Sets the restitution combine mode. +// - CM_average : Average: (a + b)/2. +// - CM_min : Minimum: min(a,b). +// - CM_multiply : Multiply: a*b. +// - CM_max : Maximum: max(a,b). +//////////////////////////////////////////////////////////////////// +void PhysxMaterialDesc:: +set_restitution_combine_mode(PhysxCombineMode mode) { + + _desc.restitutionCombineMode = (NxCombineMode)mode; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::get_restitution +// Access: Published +// Description: Returns the coefficient of restitution. +//////////////////////////////////////////////////////////////////// +float PhysxMaterialDesc:: +get_restitution() const { + + return _desc.restitution; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::get_static_friction +// Access: Published +// Description: Retruns the coefficient of static friction. +//////////////////////////////////////////////////////////////////// +float PhysxMaterialDesc:: +get_static_friction() const { + + return _desc.staticFriction; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::get_dynamic_friction +// Access: Published +// Description: Returns the coefficient of dynamic friction. +//////////////////////////////////////////////////////////////////// +float PhysxMaterialDesc:: +get_dynamic_friction() const { + + return _desc.dynamicFriction; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::get_static_friction_v +// Access: Published +// Description: Returns the anisotropic static friction coefficient +// for along the secondary (V) axis of anisotropy. +//////////////////////////////////////////////////////////////////// +float PhysxMaterialDesc:: +get_static_friction_v() const { + + return _desc.staticFrictionV; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::get_dynamic_friction_v +// Access: Published +// Description: Returns the anisotropic dynamic friction +// coefficient for along the secondary (V) axis of +// anisotropy. +//////////////////////////////////////////////////////////////////// +float PhysxMaterialDesc:: +get_dynamic_friction_v() const { + + return _desc.dynamicFrictionV; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::get_flag +// Access: Published +// Description: Returns flags which control the behavior of a +// material. +//////////////////////////////////////////////////////////////////// +bool PhysxMaterialDesc:: +get_flag(PhysxMaterialFlag flag) const { + + return (_desc.flags & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMaterialDesc::get_dir_of_anisotropy +// Access: Published +// Description: Returns the shape space direction (unit vector) of +// anisotropy. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxMaterialDesc:: get_dir_of_anisotropy() const { - return PhysxManager::nxVec3_to_lVecBase3(nMaterialDesc.dirOfAnisotropy); + + return PhysxManager::nxVec3_to_vec3(_desc.dirOfAnisotropy); } //////////////////////////////////////////////////////////////////// -// Function : get_friction_combine_mode -// Access : Published -// Description : +// Function: PhysxMaterialDesc::get_friction_combine_mode +// Access: Published +// Description: Returns the friction combine mode. //////////////////////////////////////////////////////////////////// -PhysxCombineMode PhysxMaterialDesc:: +PhysxEnums::PhysxCombineMode PhysxMaterialDesc:: get_friction_combine_mode() const { - return (PhysxCombineMode)nMaterialDesc.frictionCombineMode; + + return (PhysxCombineMode)_desc.frictionCombineMode; } //////////////////////////////////////////////////////////////////// -// Function : get_restitution_combine_mode -// Access : Published -// Description : +// Function: PhysxMaterialDesc::get_restitution_combine_mode +// Access: Published +// Description: Returns the restitution combine mode. //////////////////////////////////////////////////////////////////// -PhysxCombineMode PhysxMaterialDesc:: +PhysxEnums::PhysxCombineMode PhysxMaterialDesc:: get_restitution_combine_mode() const { - return (PhysxCombineMode)nMaterialDesc.restitutionCombineMode; + + return (PhysxCombineMode)_desc.restitutionCombineMode; } -//////////////////////////////////////////////////////////////////// -// Function : set_dir_of_anisotropy -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterialDesc:: -set_dir_of_anisotropy(LVecBase3f value) { - nMaterialDesc.dirOfAnisotropy = PhysxManager::lVecBase3_to_nxVec3(value); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_friction_combine_mode -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterialDesc:: -set_friction_combine_mode(PhysxCombineMode value) { - nMaterialDesc.frictionCombineMode = (NxCombineMode)value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_restitution_combine_mode -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxMaterialDesc:: -set_restitution_combine_mode(PhysxCombineMode value) { - nMaterialDesc.restitutionCombineMode = (NxCombineMode)value; -} - -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxMaterialDesc.h b/panda/src/physx/physxMaterialDesc.h index f381d9788b..cfe83a7f76 100644 --- a/panda/src/physx/physxMaterialDesc.h +++ b/panda/src/physx/physxMaterialDesc.h @@ -1,5 +1,5 @@ // Filename: physxMaterialDesc.h -// Created by: pratt (Jul 9, 2006) +// Created by: enn0x (21Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,53 +15,50 @@ #ifndef PHYSXMATERIALDESC_H #define PHYSXMATERIALDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "physxEnums.h" +#include "NoMinMax.h" #include "NxPhysics.h" //////////////////////////////////////////////////////////////////// // Class : PhysxMaterialDesc -// Description : +// Description : Descriptor class for materials. See PhysxMaterial. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxMaterialDesc { +class EXPCL_PANDAPHYSX PhysxMaterialDesc : public PhysxEnums { + PUBLISHED: - PhysxMaterialDesc(); + INLINE PhysxMaterialDesc(); + INLINE ~PhysxMaterialDesc(); - INLINE bool is_valid() const; INLINE void set_to_default(); + INLINE bool is_valid() const; - LVecBase3f get_dir_of_anisotropy() const; - INLINE float get_dynamic_friction() const; - INLINE float get_dynamic_friction_v() const; - INLINE unsigned int get_flags() const; + void set_dynamic_friction(float coef); + void set_static_friction(float coef); + void set_restitution(float rest); + void set_dynamic_friction_v(float coef); + void set_static_friction_v(float coef); + void set_dir_of_anisotropy(const LVector3f dir); + void set_flag(PhysxMaterialFlag flag, bool value); + void set_friction_combine_mode(PhysxCombineMode mode); + void set_restitution_combine_mode(PhysxCombineMode mode); + + float get_dynamic_friction() const; + float get_static_friction() const; + float get_restitution() const; + float get_dynamic_friction_v() const; + float get_static_friction_v() const; + LVector3f get_dir_of_anisotropy() const; + bool get_flag(PhysxMaterialFlag flag) const; PhysxCombineMode get_friction_combine_mode() const; - INLINE float get_restitution() const; PhysxCombineMode get_restitution_combine_mode() const; - INLINE float get_static_friction() const; - INLINE float get_static_friction_v() const; - - void set_dir_of_anisotropy(LVecBase3f value); - INLINE void set_dynamic_friction(float value); - INLINE void set_dynamic_friction_v(float value); - INLINE void set_flags(unsigned int value); - void set_friction_combine_mode(PhysxCombineMode value); - INLINE void set_restitution(float value); - void set_restitution_combine_mode(PhysxCombineMode value); - INLINE void set_static_friction(float value); - INLINE void set_static_friction_v(float value); public: - NxMaterialDesc nMaterialDesc; + NxMaterialDesc _desc; }; #include "physxMaterialDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXMATERIALDESC_H diff --git a/panda/src/physx/physxMemoryReadBuffer.cxx b/panda/src/physx/physxMemoryReadBuffer.cxx new file mode 100644 index 0000000000..639d54debc --- /dev/null +++ b/panda/src/physx/physxMemoryReadBuffer.cxx @@ -0,0 +1,112 @@ +// Filename: physxMemoryReadBuffer.cxx +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxMemoryReadBuffer.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryReadBuffer::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PhysxMemoryReadBuffer::PhysxMemoryReadBuffer(const NxU8 *data) : buffer(data) +{ + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryReadBuffer::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PhysxMemoryReadBuffer::~PhysxMemoryReadBuffer() +{ + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryReadBuffer::readByte +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxU8 PhysxMemoryReadBuffer::readByte() const +{ + NxU8 b; + memcpy(&b, buffer, sizeof(NxU8)); + buffer += sizeof(NxU8); + return b; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryReadBuffer::readWord +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxU16 PhysxMemoryReadBuffer::readWord() const +{ + NxU16 w; + memcpy(&w, buffer, sizeof(NxU16)); + buffer += sizeof(NxU16); + return w; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryReadBuffer::readDword +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxU32 PhysxMemoryReadBuffer::readDword() const +{ + NxU32 d; + memcpy(&d, buffer, sizeof(NxU32)); + buffer += sizeof(NxU32); + return d; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryReadBuffer::readFloat +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxMemoryReadBuffer::readFloat() const +{ + float f; + memcpy(&f, buffer, sizeof(float)); + buffer += sizeof(float); + return f; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryReadBuffer::readDouble +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +double PhysxMemoryReadBuffer::readDouble() const +{ + double f; + memcpy(&f, buffer, sizeof(double)); + buffer += sizeof(double); + return f; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryReadBuffer::readBuffer +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxMemoryReadBuffer::readBuffer(void *dest, NxU32 size) const +{ + memcpy(dest, buffer, size); + buffer += size; +} + diff --git a/panda/src/physx/physxMemoryReadBuffer.h b/panda/src/physx/physxMemoryReadBuffer.h new file mode 100644 index 0000000000..f33d3fd6da --- /dev/null +++ b/panda/src/physx/physxMemoryReadBuffer.h @@ -0,0 +1,50 @@ +// Filename: physxMemoryReadBuffer.h +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXMEMORYREADBUFFER_H +#define PHYSXMEMORYREADBUFFER_H + +#include "pandabase.h" + +#include "NoMinMax.h" +#include "NxStream.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxMemoryReadBuffer +// Description : +//////////////////////////////////////////////////////////////////// +class PhysxMemoryReadBuffer : public NxStream { + +public: + PhysxMemoryReadBuffer(const NxU8 *data); + virtual ~PhysxMemoryReadBuffer(); + + virtual NxU8 readByte() const; + virtual NxU16 readWord() const; + virtual NxU32 readDword() const; + virtual float readFloat() const; + virtual double readDouble() const; + virtual void readBuffer(void *buffer, NxU32 size) const; + + virtual NxStream &storeByte(NxU8 b) { NX_ASSERT(0); return *this; } + virtual NxStream &storeWord(NxU16 w) { NX_ASSERT(0); return *this; } + virtual NxStream &storeDword(NxU32 d) { NX_ASSERT(0); return *this; } + virtual NxStream &storeFloat(NxReal f) { NX_ASSERT(0); return *this; } + virtual NxStream &storeDouble(NxF64 f) { NX_ASSERT(0); return *this; } + virtual NxStream &storeBuffer(const void *buffer, NxU32 size) { NX_ASSERT(0); return *this; } + + mutable const NxU8 *buffer; +}; + +#endif // PHYSXMEMORYREADBUFFER_H diff --git a/panda/src/physx/physxMemoryWriteBuffer.cxx b/panda/src/physx/physxMemoryWriteBuffer.cxx new file mode 100644 index 0000000000..b84f8c7c7c --- /dev/null +++ b/panda/src/physx/physxMemoryWriteBuffer.cxx @@ -0,0 +1,116 @@ +// Filename: physxMemoryWriteBuffer.cxx +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxMemoryWriteBuffer.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryWriteBuffer::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PhysxMemoryWriteBuffer::PhysxMemoryWriteBuffer() : currentSize(0), maxSize(0), data(NULL) +{ + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryWriteBuffer::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PhysxMemoryWriteBuffer::~PhysxMemoryWriteBuffer() +{ + NxGetPhysicsSDKAllocator()->free(data); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryWriteBuffer::storeByte +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxMemoryWriteBuffer::storeByte(NxU8 b) +{ + storeBuffer(&b, sizeof(NxU8)); + return *this; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryWriteBuffer::storeWord +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxMemoryWriteBuffer::storeWord(NxU16 w) +{ + storeBuffer(&w, sizeof(NxU16)); + return *this; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryWriteBuffer::storeDword +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxMemoryWriteBuffer::storeDword(NxU32 d) +{ + storeBuffer(&d, sizeof(NxU32)); + return *this; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryWriteBuffer::storeFloat +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxMemoryWriteBuffer::storeFloat(NxReal f) +{ + storeBuffer(&f, sizeof(NxReal)); + return *this; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryWriteBuffer::storeDouble +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxMemoryWriteBuffer::storeDouble(NxF64 f) +{ + storeBuffer(&f, sizeof(NxF64)); + return *this; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMemoryWriteBuffer::storeBuffer +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +NxStream &PhysxMemoryWriteBuffer::storeBuffer(const void *buffer, NxU32 size) +{ + NxU32 expectedSize = currentSize + size; + if (expectedSize > maxSize) + { + maxSize = expectedSize + 4096; + + NxU8 *newData = (NxU8 *)NxGetPhysicsSDKAllocator()->malloc(maxSize, NX_MEMORY_PERSISTENT); + if(data) + { + memcpy(newData, data, currentSize); + NxGetPhysicsSDKAllocator()->free(data); + } + data = newData; + } + memcpy(data + currentSize, buffer, size); + currentSize += size; + return *this; +} + diff --git a/panda/src/physx/physxMemoryWriteBuffer.h b/panda/src/physx/physxMemoryWriteBuffer.h new file mode 100644 index 0000000000..6c6a36232d --- /dev/null +++ b/panda/src/physx/physxMemoryWriteBuffer.h @@ -0,0 +1,52 @@ +// Filename: physxMemoryWriteBuffer.h +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXMEMORYWRITEBUFFER_H +#define PHYSXMEMORYWRITEBUFFER_H + +#include "pandabase.h" + +#include "NoMinMax.h" +#include "NxStream.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxMemoryWriteBuffer +// Description : +//////////////////////////////////////////////////////////////////// +class PhysxMemoryWriteBuffer : public NxStream { + +public: + PhysxMemoryWriteBuffer(); + virtual ~PhysxMemoryWriteBuffer(); + + virtual NxU8 readByte() const { NX_ASSERT(0); return 0; } + virtual NxU16 readWord() const { NX_ASSERT(0); return 0; } + virtual NxU32 readDword() const { NX_ASSERT(0); return 0; } + virtual float readFloat() const { NX_ASSERT(0); return 0.0f; } + virtual double readDouble() const { NX_ASSERT(0); return 0.0; } + virtual void readBuffer(void *buffer, NxU32 size) const { NX_ASSERT(0); } + + virtual NxStream &storeByte(NxU8 b); + virtual NxStream &storeWord(NxU16 w); + virtual NxStream &storeDword(NxU32 d); + virtual NxStream &storeFloat(NxReal f); + virtual NxStream &storeDouble(NxF64 f); + virtual NxStream &storeBuffer(const void *buffer, NxU32 size); + + NxU32 currentSize; + NxU32 maxSize; + NxU8 *data; +}; + +#endif // PHYSXMEMORYWRITEBUFFER_H diff --git a/panda/src/physx/physxMeshPool.I b/panda/src/physx/physxMeshPool.I new file mode 100644 index 0000000000..3fdc3c8922 --- /dev/null +++ b/panda/src/physx/physxMeshPool.I @@ -0,0 +1,35 @@ +// Filename: physxMeshPool.I +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMeshPool::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxMeshPool:: +PhysxMeshPool() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMeshPool::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxMeshPool:: +~PhysxMeshPool() { + +} + diff --git a/panda/src/physx/physxMeshPool.cxx b/panda/src/physx/physxMeshPool.cxx new file mode 100644 index 0000000000..ab62da3899 --- /dev/null +++ b/panda/src/physx/physxMeshPool.cxx @@ -0,0 +1,225 @@ +// Filename: physxMeshPool.cxx +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxMeshPool.h" +#include "physxConvexMesh.h" +#include "physxTriangleMesh.h" +#include "physxFileStream.h" + +PhysxMeshPool::ConvexMeshes PhysxMeshPool::_convex_meshes; +PhysxMeshPool::TriangleMeshes PhysxMeshPool::_triangle_meshes; +//PhysxMeshPool::ClothMeshes PhysxMeshPool::_cloth_meshes; +//PhysxMeshPool::SoftbodyMeshes PhysxMeshPool::_softbody_meshes; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMeshPool::prepare_filename +// Access: Private +// Description: Checks if the filename is valid, then resolves the +// filename on the Panda3D model search patch, and +// finally checks if the filename exists. +//////////////////////////////////////////////////////////////////// +bool PhysxMeshPool:: +prepare_filename(Filename &fn) { + + if (fn.empty()) { + // Invalid filename. + physx_cat.error() << "Invalid filename\n"; + return false; + } + + fn.resolve_filename(get_model_path()); + + if (!fn.exists()) { + // Non-existent filename. + physx_cat.error() << "Invalid filename\n"; + return false; + } + + return true; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMeshPool::load_convex_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxConvexMesh) PhysxMeshPool:: +load_convex_mesh(const Filename &filename) { + + Filename fn(filename); + if (!prepare_filename(fn)) return NULL; + + PT(PhysxConvexMesh) mesh; + + ConvexMeshes::iterator it = _convex_meshes.find(fn); + if (it == _convex_meshes.end()) { + // Not found; load mesh. + NxConvexMesh *meshPtr; + PhysxFileStream stream = PhysxFileStream(fn.to_os_specific().c_str(), true); + + mesh = new PhysxConvexMesh(); + nassertr_always(mesh, NULL); + + NxPhysicsSDK *sdk = NxGetPhysicsSDK(); + nassertr_always(sdk, NULL); + + meshPtr = sdk->createConvexMesh(stream); + nassertr_always(meshPtr, NULL); + + mesh->link(meshPtr); + + _convex_meshes.insert(ConvexMeshes::value_type(fn, mesh)); + } + else { + // Found; return previously loaded mesh. + mesh = (*it).second; + } + + return mesh; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMeshPool::load_triangle_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxTriangleMesh) PhysxMeshPool:: +load_triangle_mesh(const Filename &filename) { + + Filename fn(filename); + if (!prepare_filename(fn)) return NULL; + + PT(PhysxTriangleMesh) mesh; + + TriangleMeshes::iterator it = _triangle_meshes.find(fn); + if (it == _triangle_meshes.end()) { + // Not found; load mesh. + NxTriangleMesh *meshPtr; + PhysxFileStream stream = PhysxFileStream(fn.to_os_specific().c_str(), true); + + mesh = new PhysxTriangleMesh(); + nassertr_always(mesh, NULL); + + NxPhysicsSDK *sdk = NxGetPhysicsSDK(); + nassertr_always(sdk, NULL); + + meshPtr = sdk->createTriangleMesh(stream); + nassertr_always(meshPtr, NULL); + + mesh->link(meshPtr); + + _triangle_meshes.insert(TriangleMeshes::value_type(fn, mesh)); + } + else { + // Found; return previously loaded mesh. + mesh = (*it).second; + } + + return mesh; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMeshPool::release_convex_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxMeshPool:: +release_convex_mesh(PT(PhysxConvexMesh) mesh) { + + ConvexMeshes::iterator it; + for (it=_convex_meshes.begin(); it != _convex_meshes.end(); ++it) { + if (mesh == (*it).second) { + _convex_meshes.erase(it); + return true; + } + } + + return false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMeshPool::release_triangle_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxMeshPool:: +release_triangle_mesh(PT(PhysxTriangleMesh) mesh) { + + TriangleMeshes::iterator it; + for (it=_triangle_meshes.begin(); it != _triangle_meshes.end(); ++it) { + if (mesh == (*it).second) { + _triangle_meshes.erase(it); + return true; + } + } + + return false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMeshPool::list_content +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxMeshPool:: +list_contents() { + list_contents( nout ); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMeshPool::list_content +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxMeshPool:: +list_contents( ostream &out ) { + + out << "PhysX mesh pool contents:\n"; + + // Convex meshes + { + ConvexMeshes::const_iterator it; + for (it=_convex_meshes.begin(); it != _convex_meshes.end(); ++it) { + Filename fn = (*it).first; + PT(PhysxConvexMesh) mesh = (*it).second; + + out << " " << fn.get_fullpath() + << " (convex mesh, " << mesh->ptr()->getReferenceCount() + << " references)" << endl; + } + } + + // Triangle meshes + { + TriangleMeshes::const_iterator it; + for (it=_triangle_meshes.begin(); it != _triangle_meshes.end(); ++it) { + Filename fn = (*it).first; + PT(PhysxTriangleMesh) mesh = (*it).second; + + out << " " << fn.get_fullpath() + << " (triangle mesh, " << mesh->ptr()->getReferenceCount() + << " references)\n"; + } + } + + // Summary + NxPhysicsSDK *sdk = NxGetPhysicsSDK(); + + out << " Total number of convex meshes: " << sdk->getNbConvexMeshes() + << " created, " << _convex_meshes.size() << " registred\n"; + + out << " Total number of triangle meshes: " << sdk->getNbTriangleMeshes() + << " created, " << _triangle_meshes.size() << " registred\n"; +} + diff --git a/panda/src/physx/physxMeshPool.h b/panda/src/physx/physxMeshPool.h new file mode 100644 index 0000000000..0024ddc1bd --- /dev/null +++ b/panda/src/physx/physxMeshPool.h @@ -0,0 +1,70 @@ +// Filename: physxMeshPool.h +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXMESHPOOL_H +#define PHYSXMESHPOOL_H + +#include "pandabase.h" +#include "pointerTo.h" +#include "pnotify.h" +#include "pmap.h" +#include "filename.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxConvexMesh; +class PhysxTriangleMesh; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxMeshPool +// Description : This class unifies all references to the same +// filename, so that multiple attempts to load the +// same mesh will return the same pointer. +// The mesh filename is automatically resolved before +// an attempt to load the mesh is made. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxMeshPool { + +PUBLISHED: + INLINE PhysxMeshPool(); + INLINE ~PhysxMeshPool(); + + static PT(PhysxConvexMesh) load_convex_mesh(const Filename &filename); + static PT(PhysxTriangleMesh) load_triangle_mesh(const Filename &filename); + + static bool release_convex_mesh(PT(PhysxConvexMesh) mesh); + static bool release_triangle_mesh(PT(PhysxTriangleMesh) mesh); + + static void list_contents(); + static void list_contents(ostream &out); + +private: + static bool prepare_filename(Filename &fn); + + typedef pmap ConvexMeshes; + typedef pmap TriangleMeshes; + + static ConvexMeshes _convex_meshes; + static TriangleMeshes _triangle_meshes; + + //typedef pmap ClothMeshes; + //typedef pmap SoftbodyMeshes; + //static ClothMeshes _cloth_meshes; + //static SoftbodyMeshes _softbody_meshes; +}; + +#include "physxMeshPool.I" + +#endif // PHYSXMESHPOOL_H diff --git a/panda/src/physx/physxMotorDesc.I b/panda/src/physx/physxMotorDesc.I new file mode 100644 index 0000000000..b41d743ed2 --- /dev/null +++ b/panda/src/physx/physxMotorDesc.I @@ -0,0 +1,48 @@ +// Filename: physxMotorDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMotorDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxMotorDesc:: +PhysxMotorDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMotorDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxMotorDesc:: +PhysxMotorDesc(float velTarget, float maxForce, bool freeSpin) { + + _desc.velTarget = velTarget; + _desc.maxForce = maxForce; + _desc.freeSpin = freeSpin; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMotorDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxMotorDesc:: +~PhysxMotorDesc() { + +} + diff --git a/panda/src/physx/physxMotorDesc.cxx b/panda/src/physx/physxMotorDesc.cxx new file mode 100644 index 0000000000..e2a72360f0 --- /dev/null +++ b/panda/src/physx/physxMotorDesc.cxx @@ -0,0 +1,82 @@ +// Filename: physxMotorDesc.cxx +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxMotorDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMotorDesc::set_vel_target +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxMotorDesc:: +set_vel_target(float velTarget) { + + _desc.velTarget = velTarget; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMotorDesc::set_max_force +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxMotorDesc:: +set_max_force(float maxForce) { + + _desc.maxForce = maxForce; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMotorDesc::set_free_spin +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxMotorDesc:: +set_free_spin(bool freeSpin) { + + _desc.freeSpin = (NX_BOOL)freeSpin; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMotorDesc::get_vel_target +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxMotorDesc:: +get_vel_target() const { + + return _desc.velTarget; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMotorDesc::get_max_force +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxMotorDesc:: +get_max_force() const { + + return _desc.maxForce; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxMotorDesc::get_free_spin +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxMotorDesc:: +get_free_spin() const { + + return (_desc.freeSpin) ? true : false; +} + diff --git a/panda/src/physx/physxMotorDesc.h b/panda/src/physx/physxMotorDesc.h new file mode 100644 index 0000000000..8307550cec --- /dev/null +++ b/panda/src/physx/physxMotorDesc.h @@ -0,0 +1,53 @@ +// Filename: physxMotorDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXMOTORDESC_H +#define PHYSXMOTORDESC_H + +#include "pandabase.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxMotorDesc +// Description : Describes a joint motor. Some joints can be +// motorized, this allows them to apply a force to +// cause attached actors to move. Joints which can be +// motorized: +// - PhysxPulleyJoint +// - PhysxRevoluteJoint +//////////////////////////////////////////////////////////////////// +class PhysxMotorDesc { + +PUBLISHED: + INLINE PhysxMotorDesc(); + INLINE PhysxMotorDesc(float velTarget, float maxForce=0, bool freeSpin=0); + INLINE ~PhysxMotorDesc(); + + void set_vel_target(float velTarget); + void set_max_force(float maxForce); + void set_free_spin(bool freeSpin); + + float get_vel_target() const; + float get_max_force() const; + bool get_free_spin() const; + +public: + NxMotorDesc _desc; +}; + +#include "physxMotorDesc.I" + +#endif // PHYSXMOTORDESC_H diff --git a/panda/src/physx/physxObject.I b/panda/src/physx/physxObject.I new file mode 100644 index 0000000000..a84b3fb380 --- /dev/null +++ b/panda/src/physx/physxObject.I @@ -0,0 +1,135 @@ +// Filename: physxObject.I +// Created by: enn0x (11Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObject::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxObject:: +PhysxObject() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObject::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxObject:: +~PhysxObject() { + +#ifdef HAVE_PYTHON + // Decrement the reference count of all + // held Python objects. + PythonTagData::const_iterator ti; + for (ti = _python_tag_data.begin(); ti != _python_tag_data.end(); ++ti) { + PyObject *value = (*ti).second; + Py_XDECREF(value); + } +#endif // HAVE_PYTHON +} + +#ifdef HAVE_PYTHON +//////////////////////////////////////////////////////////////////// +// Function: PhysxObject::has_python_tags +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxObject:: +has_python_tags() const { + + return _python_tag_data.empty() ? false : true; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObject::set_python_tag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxObject:: +set_python_tag(const string &key, PyObject *value) { + + Py_XINCREF(value); + + pair result; + result = _python_tag_data.insert(PythonTagData::value_type(key, value)); + + if (!result.second) { + // The insert was unsuccessful; that means the key was already + // present in the map. In this case, we should decrement the + // original value's reference count and replace it with the new + // object. + PythonTagData::iterator ti = result.first; + PyObject *old_value = (*ti).second; + Py_XDECREF(old_value); + (*ti).second = value; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObject::get_python_tag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PyObject *PhysxObject:: +get_python_tag(const string &key) const { + + PythonTagData::const_iterator ti; + ti = _python_tag_data.find(key); + + if (ti != _python_tag_data.end()) { + PyObject *result = (*ti).second; + Py_XINCREF(result); + return result; + } + + Py_INCREF(Py_None); + return Py_None; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObject::has_python_tag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxObject:: +has_python_tag(const string &key) const { + + PythonTagData::const_iterator ti; + ti = _python_tag_data.find(key); + return (ti != _python_tag_data.end()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObject::clear_python_tag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxObject:: +clear_python_tag(const string &key) { + + PythonTagData::iterator ti; + ti = _python_tag_data.find(key); + + if (ti != _python_tag_data.end()) { + PyObject *value = (*ti).second; + Py_XDECREF(value); + _python_tag_data.erase(ti); + } +} +#endif // HAVE_PYTHON + diff --git a/panda/src/physx/physxObject.cxx b/panda/src/physx/physxObject.cxx new file mode 100644 index 0000000000..6f22f17129 --- /dev/null +++ b/panda/src/physx/physxObject.cxx @@ -0,0 +1,42 @@ +// Filename: physxObject.cxx +// Created by: enn0x (11Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxObject.h" + +TypeHandle PhysxObject::_type_handle; + +/* +//////////////////////////////////////////////////////////////////// +// Function: PhysxObject::set_mass +// Access: Published +// Description: Set the mass of body. +//////////////////////////////////////////////////////////////////// +void PhysxObject:: +set_mass(float mass) { + + _desc.mass = mass; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObject::get_mass +// Access: Published +// Description: Get the mass of body. +//////////////////////////////////////////////////////////////////// +float PhysxObject:: +get_mass() const { + + return _desc.mass; +} +*/ + diff --git a/panda/src/physx/physxObject.h b/panda/src/physx/physxObject.h new file mode 100644 index 0000000000..b3b0c23505 --- /dev/null +++ b/panda/src/physx/physxObject.h @@ -0,0 +1,88 @@ +// Filename: physxObject.h +// Created by: enn0x (11Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXOBJECT_H +#define PHYSXOBJECT_H + +#include "pandabase.h" +#include "typedReferenceCount.h" + +#ifdef HAVE_PYTHON +#undef _POSIX_C_SOURCE +#include +#endif // HAVE_PYTHON + +//////////////////////////////////////////////////////////////////// +// Class : PhysxObject +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxObject : public TypedReferenceCount { + +#ifdef HAVE_PYTHON +PUBLISHED: + INLINE void set_python_tag(const string &key, PyObject *value); + INLINE PyObject *get_python_tag(const string &key) const; + INLINE bool has_python_tag(const string &key) const; + INLINE void clear_python_tag(const string &key); + INLINE bool has_python_tags() const; +#endif // HAVE_PYTHON + +PUBLISHED: + virtual void ls() const = 0; + virtual void ls(ostream &out, int indent_level=0) const = 0; + +protected: + INLINE PhysxObject(); + INLINE ~PhysxObject(); + + enum ErrorType { + ET_empty, + ET_ok, + ET_released, + ET_fail, + }; + + ErrorType _error_type; + +#ifdef HAVE_PYTHON +private: + typedef phash_map PythonTagData; + PythonTagData _python_tag_data; +#endif // HAVE_PYTHON + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + TypedReferenceCount::init_type(); + register_type(_type_handle, "PhysxObject", + TypedReferenceCount::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxObject.I" + +#endif // PHYSXOBJECT_H diff --git a/panda/src/physx/physxObjectCollection.I b/panda/src/physx/physxObjectCollection.I new file mode 100644 index 0000000000..07cb4191ea --- /dev/null +++ b/panda/src/physx/physxObjectCollection.I @@ -0,0 +1,114 @@ +// Filename: physxObjectCollection.I +// Created by: enn0x (08Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObjectCollection::size +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE unsigned int PhysxObjectCollection:: +size() const { + + return _objects.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObjectCollection::add +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE void PhysxObjectCollection:: +add(PT(T) object) { + + _objects.push_back(object); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObjectCollection::remove +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE void PhysxObjectCollection:: +remove(PT(T) object) { + + typename pvector::iterator it; + + it = find(_objects.begin(), _objects.end(), object); + if (it != _objects.end()) { + _objects.erase(it); + } + else + { + physx_cat.warning() << "object not found in collection" << endl; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObjectCollection::get +// Access: Public +// Description: Returns the n-th PhysxObject in the collection. +// The operator [] is maybe a more convenient way to +// access objects from the collection. +//////////////////////////////////////////////////////////////////// +template +INLINE T *PhysxObjectCollection:: +get(unsigned int index) const { + + nassertr(index < _objects.size(), NULL); + return _objects[index]; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObjectCollection::operator [] +// Access: Public +// Description: Returns the n-th PhysxObject in the collection. +// This is the same as the get() method. +//////////////////////////////////////////////////////////////////// +template +INLINE T *PhysxObjectCollection:: +operator [] (unsigned int index) const { + + nassertr(index < _objects.size(), NULL); + return _objects[index]; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObjectCollection::ls +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE void PhysxObjectCollection:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxObjectCollection::ls +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE void PhysxObjectCollection:: +ls(ostream &out, int indent_level) const { + + for (unsigned int i=0; i < size(); i++) { + get(i)->ls(out, indent_level + 2); + } +} + diff --git a/panda/src/physx/physxContactHandler.I b/panda/src/physx/physxObjectCollection.cxx similarity index 79% rename from panda/src/physx/physxContactHandler.I rename to panda/src/physx/physxObjectCollection.cxx index 23a13798d4..fb8d6992e1 100644 --- a/panda/src/physx/physxContactHandler.I +++ b/panda/src/physx/physxObjectCollection.cxx @@ -1,5 +1,5 @@ -// Filename: physxContactHandler.I -// Created by: pratt (May 25, 2006) +// Filename: physxObjectCollection.cxx +// Created by: enn0x (08Nov09) // //////////////////////////////////////////////////////////////////// // @@ -12,6 +12,5 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX +#include "physxObjectCollection.h" -#endif // HAVE_PHYSX diff --git a/panda/src/physx/physxObjectCollection.h b/panda/src/physx/physxObjectCollection.h new file mode 100644 index 0000000000..b139f857dc --- /dev/null +++ b/panda/src/physx/physxObjectCollection.h @@ -0,0 +1,45 @@ +// Filename: physxObjectCollection.h +// Created by: enn0x (08Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXOBJECTCOLLECTION_H +#define PHYSXOBJECTCOLLECTION_H + +#include "pandabase.h" + +#include "config_physx.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxObjectCollection +// Description : +//////////////////////////////////////////////////////////////////// +template +class EXPCL_PANDAPHYSX PhysxObjectCollection { + +public: + INLINE unsigned int size() const; + INLINE void add(PT(T) object); + INLINE void remove(PT(T) object); + INLINE T *get(unsigned int index) const; + INLINE T *operator [] (unsigned int index) const; + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +private: + pvector _objects; +}; + +#include "physxObjectCollection.I" + +#endif // PHYSOBJECTCOLLECTION_H diff --git a/panda/src/physx/physxOverlapReport.I b/panda/src/physx/physxOverlapReport.I new file mode 100644 index 0000000000..4a1894c55d --- /dev/null +++ b/panda/src/physx/physxOverlapReport.I @@ -0,0 +1,35 @@ +// Filename: physOverlapReport.I +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxOverlapReport::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxOverlapReport:: +PhysxOverlapReport() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxOverlapReport::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxOverlapReport:: +~PhysxOverlapReport() { + +} + diff --git a/panda/src/physx/physxOverlapReport.cxx b/panda/src/physx/physxOverlapReport.cxx new file mode 100644 index 0000000000..7d3964c2e2 --- /dev/null +++ b/panda/src/physx/physxOverlapReport.cxx @@ -0,0 +1,84 @@ +// Filename: physOverlapReport.cxx +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxOverlapReport.h" +#include "physxShape.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxOverlapReport::onEvent +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxOverlapReport:: +onEvent(NxU32 nbEntities, NxShape **entities) { + + for (unsigned int i=0; iuserData; + _overlaps.push_back(shape); + } + + return true; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxOverlapReport::get_num_overlaps +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +unsigned int PhysxOverlapReport:: +get_num_overlaps() const { + + return _overlaps.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxOverlapReport::get_first_overlap +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxShape) PhysxOverlapReport:: +get_first_overlap() { + + _iterator = _overlaps.begin(); + return get_next_overlap(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxOverlapReport::get_next_overlap +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxShape) PhysxOverlapReport:: +get_next_overlap() { + + if (_iterator != _overlaps.end()) { + return *_iterator++; + } + + // No more items. Return empty overlap. + return NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxOverlapReport::get_overlap +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxShape) PhysxOverlapReport:: +get_overlap(unsigned int idx) { + + nassertr(idx < get_num_overlaps(), NULL); + return _overlaps[idx]; +} + diff --git a/panda/src/physx/physxOverlapReport.h b/panda/src/physx/physxOverlapReport.h new file mode 100644 index 0000000000..08e96ba3e7 --- /dev/null +++ b/panda/src/physx/physxOverlapReport.h @@ -0,0 +1,60 @@ +// Filename: physOverlapReport.h +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXOVERLAPREPORT_H +#define PHYSXOVERLAPREPORT_H + +#include "pandabase.h" +#include "pvector.h" +#include "pointerTo.h" + +#include "config_physx.h" + +class PhysxShape; + +class PhysxUserEntityReport : public NxUserEntityReport {}; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxOverlapReport +// Description : Objects of this class are returned by the 'overlap +// shape' methods, for example overlapSphereShapes. +// They contain an iterable list of all sshapes that +// the raycast query produced. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxOverlapReport : public PhysxUserEntityReport { + +PUBLISHED: + unsigned int get_num_overlaps() const; + PT(PhysxShape) get_first_overlap(); + PT(PhysxShape) get_next_overlap(); + PT(PhysxShape) get_overlap(unsigned int idx); + MAKE_SEQ(get_overlaps, get_num_overlaps, get_overlap); + +public: + INLINE PhysxOverlapReport(); + INLINE ~PhysxOverlapReport(); + + virtual bool onEvent(NxU32 nbEntities, NxShape **entities); + +private: + typedef pvector Overlaps; + Overlaps _overlaps; + + typedef Overlaps::const_iterator const_iterator; + const_iterator _iterator; +}; + +#include "physxOverlapReport.I" + +#endif // PHYSXOVERLAPREPORT_H diff --git a/panda/src/physx/physxPlane.I b/panda/src/physx/physxPlane.I index 15c710aa80..e177f7dc4e 100644 --- a/panda/src/physx/physxPlane.I +++ b/panda/src/physx/physxPlane.I @@ -1,5 +1,5 @@ // Filename: physxPlane.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,88 +12,35 @@ // //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function : belongs -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE bool PhysxPlane:: -belongs(const LVecBase3f & p) const { - nassertr(nPlane != NULL, false); - return nPlane->belongs(PhysxManager::lVecBase3_to_nxVec3(p)); +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlane::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPlane:: +PhysxPlane() { + } //////////////////////////////////////////////////////////////////// -// Function : distance -// Access : Published -// Description : +// Function: PhysxPlane::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE float PhysxPlane:: -distance(const LVecBase3f & p) const { - nassertr(nPlane != NULL, -1.0f); +INLINE PhysxPlane:: +PhysxPlane(const PhysxPlane &plane) { - return nPlane->distance(PhysxManager::lVecBase3_to_nxVec3(p)); + _plane = plane._plane; } //////////////////////////////////////////////////////////////////// -// Function : inverse_transform -// Access : Published -// Description : +// Function: PhysxPlane::Destructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE void PhysxPlane:: -inverse_transform(const LMatrix4f & transform, PhysxPlane & transformed) const { - nassertv(nPlane != NULL); +INLINE PhysxPlane:: +~PhysxPlane() { - nPlane->inverseTransform(PhysxManager::lMatrix4_to_nxMat34(transform), *(transformed.nPlane)); } -//////////////////////////////////////////////////////////////////// -// Function : normalize -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxPlane:: -normalize() { - nassertv(nPlane != NULL); - - nPlane->normalize(); -} - -//////////////////////////////////////////////////////////////////// -// Function : transform -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxPlane:: -transform(const LMatrix4f & transform, PhysxPlane & transformed) const { - nassertv(nPlane != NULL); - - nPlane->transform(PhysxManager::lMatrix4_to_nxMat34(transform), *(transformed.nPlane)); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_d -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxPlane:: -get_d() const { - nassertr(nPlane != NULL, -1.0f); - - return nPlane->d; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_d -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxPlane:: -set_d(float value) { - nassertv(nPlane != NULL); - - nPlane->d = value; -} - - diff --git a/panda/src/physx/physxPlane.cxx b/panda/src/physx/physxPlane.cxx index cfeefc8a10..53cf33811b 100644 --- a/panda/src/physx/physxPlane.cxx +++ b/panda/src/physx/physxPlane.cxx @@ -1,5 +1,5 @@ // Filename: physxPlane.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,102 +12,172 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxPlane.h" - -#include "luse.h" - +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxPlane -// Access : Published -// Description : +// Function: PhysxPlane::distance +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -PhysxPlane:: -PhysxPlane(const PhysxPlane & plane) { +float PhysxPlane:: +distance(const LPoint3f &p) const { + nassertr(!p.is_nan(), 0.0f); + + return _plane.distance(PhysxManager::point3_to_nxVec3(p)); } //////////////////////////////////////////////////////////////////// -// Function : ~PhysxPlane -// Access : Published -// Description : +// Function: PhysxPlane::belongs +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -PhysxPlane:: -~PhysxPlane() { +bool PhysxPlane:: +belongs(const LPoint3f &p) const { + nassertr(!p.is_nan(), false); + + return _plane.belongs(PhysxManager::point3_to_nxVec3(p)); } //////////////////////////////////////////////////////////////////// -// Function : point_in_plane -// Access : Published -// Description : +// Function: PhysxPlane::point_in_plane +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxPlane:: +LPoint3f PhysxPlane:: point_in_plane() const { - nassertr(nPlane != NULL, *((LVecBase3f *)NULL)); - return PhysxManager::nxVec3_to_lVecBase3(nPlane->pointInPlane()); + return PhysxManager::nxVec3_to_point3(_plane.pointInPlane()); } //////////////////////////////////////////////////////////////////// -// Function : project -// Access : Published -// Description : +// Function: PhysxPlane::project +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxPlane:: -project(const LVecBase3f & p) const { - nassertr(nPlane != NULL, *((LVecBase3f *)NULL)); +LPoint3f PhysxPlane:: +project(const LPoint3f &p) const { - return PhysxManager::nxVec3_to_lVecBase3(nPlane->project(PhysxManager::lVecBase3_to_nxVec3(p))); + nassertr(!p.is_nan(), LPoint3f::zero()); + + return PhysxManager::nxVec3_to_point3(_plane.project(PhysxManager::point3_to_nxVec3(p))); } //////////////////////////////////////////////////////////////////// -// Function : set -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxPlane & PhysxPlane:: -set(const LVecBase3f & p0, const LVecBase3f & p1, const LVecBase3f & p2) { -// return *((PhysxPlane *)(nPlane->set(PhysxManager::lVecBase3_to_nxVec3(p0), PhysxManager::lVecBase3_to_nxVec3(p1), PhysxManager::lVecBase3_to_nxVec3(p2)).userData)); - throw "Not Implemented"; -} - -//////////////////////////////////////////////////////////////////// -// Function : zero -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxPlane & PhysxPlane:: -zero() { -// return *((PhysxPlane *)(nPlane->zero().userData)); - throw "Not Implemented"; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_normal -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxPlane:: -get_normal() const { - nassertr(nPlane != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nPlane->normal); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_normal -// Access : Published -// Description : +// Function: PhysxPlane::inverse_transform +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// void PhysxPlane:: -set_normal(LVecBase3f value) { - nassertv(nPlane != NULL); +inverse_transform(const LMatrix4f &transform, PhysxPlane &transformed) const { - nPlane->normal = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv(!transform.is_nan()); + + _plane.inverseTransform(PhysxManager::mat4_to_nxMat34(transform), transformed._plane); } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlane::normalize +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPlane:: +normalize() { + + _plane.normalize(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlane::transform +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPlane:: +transform(const LMatrix4f &transform, PhysxPlane &transformed) const { + + nassertv(!transform.is_nan()); + + _plane.transform(PhysxManager::mat4_to_nxMat34(transform), transformed._plane); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlane::get_d +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxPlane:: +get_d() const { + + return _plane.d; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlane::set_d +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPlane:: +set_d(float value) { + + _plane.d = value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlane::get_normal +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LVector3f PhysxPlane:: +get_normal() const { + + return PhysxManager::nxVec3_to_vec3(_plane.normal); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlane::set_normal +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPlane:: +set_normal(LVector3f normal) { + + nassertv(!normal.is_nan()); + + _plane.normal = PhysxManager::vec3_to_nxVec3(normal); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlane::set +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxPlane PhysxPlane:: +set(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &p2) { + + PhysxPlane plane; + + nassertr(!p0.is_nan(), plane); + nassertr(!p1.is_nan(), plane); + nassertr(!p2.is_nan(), plane); + + plane._plane = _plane.set(PhysxManager::point3_to_nxVec3(p0), + PhysxManager::point3_to_nxVec3(p1), + PhysxManager::point3_to_nxVec3(p2)); + return plane; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlane::zero +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxPlane PhysxPlane:: +zero() { + + PhysxPlane plane; + plane._plane = _plane.zero(); + return plane; +} diff --git a/panda/src/physx/physxPlane.h b/panda/src/physx/physxPlane.h index d6c418a896..ff72d5a5ef 100644 --- a/panda/src/physx/physxPlane.h +++ b/panda/src/physx/physxPlane.h @@ -1,5 +1,5 @@ // Filename: physxPlane.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,47 +15,45 @@ #ifndef PHYSXPLANE_H #define PHYSXPLANE_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "lpoint3.h" +#include "lvector3.h" +#include "lmatrix.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -#include "NxPhysics.h" +#include "config_physx.h" //////////////////////////////////////////////////////////////////// // Class : PhysxPlane -// Description : +// Description : //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxPlane { + PUBLISHED: - PhysxPlane(const PhysxPlane & plane); - ~PhysxPlane(); + INLINE PhysxPlane(); + INLINE PhysxPlane(const PhysxPlane &plane); + INLINE ~PhysxPlane(); - INLINE bool belongs(const LVecBase3f & p) const; - INLINE float distance(const LVecBase3f & p) const; - INLINE void inverse_transform(const LMatrix4f & transform, PhysxPlane & transformed) const; - INLINE void normalize(); - LVecBase3f point_in_plane() const; - LVecBase3f project(const LVecBase3f & p) const; - PhysxPlane & set(const LVecBase3f & p0, const LVecBase3f & p1, const LVecBase3f & p2); - INLINE void transform(const LMatrix4f & transform, PhysxPlane & transformed) const; - PhysxPlane & zero(); + float distance(const LPoint3f &p) const; + bool belongs(const LPoint3f &p) const; + void normalize(); + LPoint3f point_in_plane() const; + LPoint3f project(const LPoint3f &p) const; + void transform(const LMatrix4f &transform, PhysxPlane &transformed) const; + void inverse_transform(const LMatrix4f &transform, PhysxPlane &transformed) const; - INLINE float get_d() const; - LVecBase3f get_normal() const; + PhysxPlane set(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &p2); + PhysxPlane zero(); - INLINE void set_d( float value ); - void set_normal( LVecBase3f value ); + float get_d() const; + LVector3f get_normal() const; + + void set_d(float d); + void set_normal(LVector3f normal); public: - NxPlane *nPlane; + NxPlane _plane; }; #include "physxPlane.I" -#endif // HAVE_PHYSX - -#endif // PHYSXPLANE_H +#endif // PHYSPLANE_H diff --git a/panda/src/physx/physxPlaneShape.I b/panda/src/physx/physxPlaneShape.I index 558b3349d6..96c529e972 100644 --- a/panda/src/physx/physxPlaneShape.I +++ b/panda/src/physx/physxPlaneShape.I @@ -1,5 +1,5 @@ // Filename: physxPlaneShape.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,3 +12,25 @@ // //////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlaneShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPlaneShape:: +PhysxPlaneShape() : PhysxShape() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlaneShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPlaneShape:: +~PhysxPlaneShape() { + +} + diff --git a/panda/src/physx/physxPlaneShape.cxx b/panda/src/physx/physxPlaneShape.cxx index bace939cf6..13ac3923a6 100644 --- a/panda/src/physx/physxPlaneShape.cxx +++ b/panda/src/physx/physxPlaneShape.cxx @@ -1,5 +1,5 @@ // Filename: physxPlaneShape.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,50 +12,69 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxPlaneShape.h" - -#include "luse.h" -#include "physxPlane.h" #include "physxPlaneShapeDesc.h" +#include "physxManager.h" TypeHandle PhysxPlaneShape::_type_handle; //////////////////////////////////////////////////////////////////// -// Function : get_plane -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxPlane PhysxPlaneShape:: -get_plane() const { -// return *((PhysxPlane *)(nPlaneShape->getPlane().userData)); - throw "Not Implemented"; -} - -//////////////////////////////////////////////////////////////////// -// Function : save_to_desc -// Access : Published -// Description : +// Function: PhysxPlaneShape::link +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// void PhysxPlaneShape:: -save_to_desc(PhysxPlaneShapeDesc & desc) const { - nassertv(nPlaneShape != NULL); +link(NxShape *shapePtr) { - nPlaneShape->saveToDesc(desc.nPlaneShapeDesc); + _ptr = shapePtr->isPlane(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.add(this); } //////////////////////////////////////////////////////////////////// -// Function : set_plane -// Access : Published -// Description : +// Function: PhysxPlaneShape::unlink +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// void PhysxPlaneShape:: -set_plane(const LVecBase3f & normal, float d) { - nassertv(nPlaneShape != NULL); +unlink() { - nPlaneShape->setPlane(PhysxManager::lVecBase3_to_nxVec3(normal), d); + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.remove(this); } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function : PhysxPlaneShape::save_to_desc +// Access : Published +// Description : Saves the state of the shape object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxPlaneShape:: +save_to_desc(PhysxPlaneShapeDesc &shapeDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlaneShape::set_plane +// Access: Published +// Description: Sets the plane equation. +// - normal: Normal for the plane, in the global +// frame. Range: direction vector +// - d: Distance coefficient of the plane equation. +// Range: (-inf,inf) +//////////////////////////////////////////////////////////////////// +void PhysxPlaneShape:: +set_plane(const LVector3f &normal, float d) { + + nassertv(_error_type == ET_ok); + _ptr->setPlane(PhysxManager::vec3_to_nxVec3(normal), d); +} diff --git a/panda/src/physx/physxPlaneShape.h b/panda/src/physx/physxPlaneShape.h index 3ff60f7cde..9639e77eb8 100644 --- a/panda/src/physx/physxPlaneShape.h +++ b/panda/src/physx/physxPlaneShape.h @@ -1,5 +1,5 @@ // Filename: physxPlaneShape.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,42 +15,72 @@ #ifndef PHYSXPLANESHAPE_H #define PHYSXPLANESHAPE_H -#ifdef HAVE_PHYSX - #include "pandabase.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "lvector3.h" #include "physxShape.h" -class PhysxPlane; -class PhysxPlaneShapeDesc; - +#include "NoMinMax.h" #include "NxPhysics.h" +class PhysxPlaneShapeDesc; + //////////////////////////////////////////////////////////////////// // Class : PhysxPlaneShape -// Description : +// Description : A plane collision detection primitive. By default +// it is configured to be the y == 0 plane. You can +// then set a normal and a d to specify an arbitrary +// plane. d is the distance of the plane from the +// origin along the normal, assuming the normal is +// normalized. Thus the plane equation is: +// normal.x * X + normal.y * Y + normal.z * Z = d +// +// Note: the plane does not represent an infinitely +// thin object, but rather a completely solid +// negative half space (all points p for which +// normal.dot(p) - d < 0 are inside the solid region.) +// +// Each shape is owned by an actor that it is attached +// to. +// +// An instance can be created by calling the +// createShape() method of the PhysxActor object that +// should own it, with a PhysxPlaneShapeDesc object as +// the parameter, or by adding the shape descriptor +// into the PhysxActorDesc class before creating the +// actor. +// +// The shape is deleted by calling release() on the +// shape itself. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxPlaneShape : public PhysxShape { + PUBLISHED: + INLINE PhysxPlaneShape(); + INLINE ~PhysxPlaneShape(); - PhysxPlane get_plane() const; - void save_to_desc(PhysxPlaneShapeDesc & desc) const; - void set_plane(const LVecBase3f & normal, float d); + void save_to_desc(PhysxPlaneShapeDesc &shapeDesc) const; + void set_plane(const LVector3f &normal, float d); +//////////////////////////////////////////////////////////////////// public: - NxPlaneShape *nPlaneShape; + INLINE NxShape *ptr() const { return (NxShape *)_ptr; }; + void link(NxShape *shapePtr); + void unlink(); + +private: + NxPlaneShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: static TypeHandle get_class_type() { return _type_handle; } static void init_type() { PhysxShape::init_type(); - register_type(_type_handle, "PhysxPlaneShape", + register_type(_type_handle, "PhysxPlaneShape", PhysxShape::get_class_type()); } virtual TypeHandle get_type() const { @@ -67,6 +97,4 @@ private: #include "physxPlaneShape.I" -#endif // HAVE_PHYSX - #endif // PHYSXPLANESHAPE_H diff --git a/panda/src/physx/physxPlaneShapeDesc.I b/panda/src/physx/physxPlaneShapeDesc.I index a1bafdec44..0ea6f87c32 100644 --- a/panda/src/physx/physxPlaneShapeDesc.I +++ b/panda/src/physx/physxPlaneShapeDesc.I @@ -1,5 +1,5 @@ // Filename: physxPlaneShapeDesc.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (08Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,43 +12,48 @@ // //////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxPlaneShapeDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxPlaneShapeDesc:: -is_valid() const { - return nPlaneShapeDesc.isValid(); +INLINE PhysxPlaneShapeDesc:: +PhysxPlaneShapeDesc() : PhysxShapeDesc() { + + _desc.name = ""; } //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxPlaneShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPlaneShapeDesc:: +~PhysxPlaneShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPlaneShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. //////////////////////////////////////////////////////////////////// INLINE void PhysxPlaneShapeDesc:: set_to_default() { - nPlaneShapeDesc.setToDefault(); + + _desc.setToDefault(); } //////////////////////////////////////////////////////////////////// -// Function : get_d -// Access : Published -// Description : +// Function: PhysxPlaneShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. //////////////////////////////////////////////////////////////////// -INLINE float PhysxPlaneShapeDesc:: -get_d() const { - return nPlaneShapeDesc.d; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_d -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxPlaneShapeDesc:: -set_d(float value) { - nPlaneShapeDesc.d = value; +INLINE bool PhysxPlaneShapeDesc:: +is_valid() const { + + return _desc.isValid(); } diff --git a/panda/src/physx/physxPlaneShapeDesc.cxx b/panda/src/physx/physxPlaneShapeDesc.cxx index 1b2a8cb105..d526ccb8f7 100644 --- a/panda/src/physx/physxPlaneShapeDesc.cxx +++ b/panda/src/physx/physxPlaneShapeDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxPlaneShapeDesc.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (08Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,43 +12,22 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxPlaneShapeDesc.h" - -#include "luse.h" - +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxPlaneShapeDesc -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxPlaneShapeDesc:: -PhysxPlaneShapeDesc() -: PhysxShapeDesc( &nPlaneShapeDesc ) { - -} - -//////////////////////////////////////////////////////////////////// -// Function : get_normal -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxPlaneShapeDesc:: -get_normal() const { - return PhysxManager::nxVec3_to_lVecBase3(nPlaneShapeDesc.normal); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_normal -// Access : Published -// Description : +// Function: PhysxPlaneShapeDesc::set_plane +// Access: Published +// Description: Sets the parameters of the plane equation. +// normal: Plane normal. +// d: The distance from the origin. //////////////////////////////////////////////////////////////////// void PhysxPlaneShapeDesc:: -set_normal(LVecBase3f value) { - nPlaneShapeDesc.normal = PhysxManager::lVecBase3_to_nxVec3(value); +set_plane(const LVector3f &normal, float d) { + + nassertv(!normal.is_nan()); + + _desc.normal = PhysxManager::vec3_to_nxVec3(normal); + _desc.d = d; } -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxPlaneShapeDesc.h b/panda/src/physx/physxPlaneShapeDesc.h index 5e86cd2749..ee04a51741 100644 --- a/panda/src/physx/physxPlaneShapeDesc.h +++ b/panda/src/physx/physxPlaneShapeDesc.h @@ -1,5 +1,5 @@ // Filename: physxPlaneShapeDesc.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (08Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,41 +15,34 @@ #ifndef PHYSXPLANESHAPEDESC_H #define PHYSXPLANESHAPEDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - #include "physxShapeDesc.h" +#include "lvector3.h" + +#include "NoMinMax.h" #include "NxPhysics.h" //////////////////////////////////////////////////////////////////// // Class : PhysxPlaneShapeDesc -// Description : +// Description : Descriptor class for PhysxPlaneShape. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxPlaneShapeDesc : public PhysxShapeDesc { + PUBLISHED: - PhysxPlaneShapeDesc(); + INLINE PhysxPlaneShapeDesc(); + INLINE ~PhysxPlaneShapeDesc(); - INLINE bool is_valid() const; INLINE void set_to_default(); + INLINE bool is_valid() const; - INLINE float get_d() const; - LVecBase3f get_normal() const; - - INLINE void set_d( float value ); - void set_normal( LVecBase3f value ); + void set_plane(const LVector3f &normal, float d); public: - NxPlaneShapeDesc nPlaneShapeDesc; + NxShapeDesc *ptr() const { return (NxShapeDesc *)&_desc; }; + NxPlaneShapeDesc _desc; }; #include "physxPlaneShapeDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXPLANESHAPEDESC_H diff --git a/panda/src/physx/physxPointInPlaneJoint.I b/panda/src/physx/physxPointInPlaneJoint.I new file mode 100644 index 0000000000..4a60567141 --- /dev/null +++ b/panda/src/physx/physxPointInPlaneJoint.I @@ -0,0 +1,36 @@ +// Filename: physxPointInPlaneJoint.I +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointInPlaneJoint::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPointInPlaneJoint:: +PhysxPointInPlaneJoint() : PhysxJoint() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointInPlaneJoint::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPointInPlaneJoint:: +~PhysxPointInPlaneJoint() { + +} + diff --git a/panda/src/physx/physxPointInPlaneJoint.cxx b/panda/src/physx/physxPointInPlaneJoint.cxx new file mode 100644 index 0000000000..f533ccb4ba --- /dev/null +++ b/panda/src/physx/physxPointInPlaneJoint.cxx @@ -0,0 +1,76 @@ +// Filename: physxPointInPlaneJoint.cxx +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxPointInPlaneJoint.h" +#include "physxPointInPlaneJointDesc.h" + +TypeHandle PhysxPointInPlaneJoint::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointInPlaneJoint::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPointInPlaneJoint:: +link(NxJoint *jointPtr) { + + _ptr = jointPtr->isPointInPlaneJoint(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointInPlaneJoint::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPointInPlaneJoint:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxPointInPlaneJoint::save_to_desc +// Access : Published +// Description : Saves the state of the joint object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxPointInPlaneJoint:: +save_to_desc(PhysxPointInPlaneJointDesc &jointDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxPointInPlaneJoint::load_from_desc +// Access : Published +// Description : Loads the entire state of the joint from a +// descriptor with a single call. +//////////////////////////////////////////////////////////////////// +void PhysxPointInPlaneJoint:: +load_from_desc(const PhysxPointInPlaneJointDesc &jointDesc) { + + nassertv(_error_type == ET_ok); + _ptr->loadFromDesc(jointDesc._desc); +} + diff --git a/panda/src/physx/physxPointInPlaneJoint.h b/panda/src/physx/physxPointInPlaneJoint.h new file mode 100644 index 0000000000..c6b6a0706b --- /dev/null +++ b/panda/src/physx/physxPointInPlaneJoint.h @@ -0,0 +1,80 @@ +// Filename: physxPointInPlaneJoint.h +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXPOINTINPLANEJOINT_H +#define PHYSXPOINTINPLANEJOINT_H + +#include "pandabase.h" + +#include "physxJoint.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxPointInPlaneJointDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxPointInPlaneJoint +// Description : A point in plane joint constrains a point on one +// body to only move inside a plane attached to another +// body. +// The starting point of the point is defined as the +// anchor point. The plane through this point is +// specified by its normal which is the joint axis +// vector. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxPointInPlaneJoint : public PhysxJoint { + +PUBLISHED: + INLINE PhysxPointInPlaneJoint(); + INLINE ~PhysxPointInPlaneJoint(); + + void save_to_desc(PhysxPointInPlaneJointDesc &jointDesc) const; + void load_from_desc(const PhysxPointInPlaneJointDesc &jointDesc); + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxJoint *ptr() const { return (NxJoint *)_ptr; }; + + void link(NxJoint *jointPtr); + void unlink(); + +private: + NxPointInPlaneJoint *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxJoint::init_type(); + register_type(_type_handle, "PhysxPointInPlaneJoint", + PhysxJoint::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxPointInPlaneJoint.I" + +#endif // PHYSXPOINTINPLANEJOINT_H diff --git a/panda/src/physx/physxPointInPlaneJointDesc.I b/panda/src/physx/physxPointInPlaneJointDesc.I new file mode 100644 index 0000000000..5d8d0f518e --- /dev/null +++ b/panda/src/physx/physxPointInPlaneJointDesc.I @@ -0,0 +1,59 @@ +// Filename: physxPointInPlaneJointDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointInPlaneJointDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPointInPlaneJointDesc:: +PhysxPointInPlaneJointDesc() : PhysxJointDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointInPlaneJointDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPointInPlaneJointDesc:: +~PhysxPointInPlaneJointDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointInPlaneJointDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxPointInPlaneJointDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointInPlaneJointDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxPointInPlaneJointDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxPointInPlaneJointDesc.cxx b/panda/src/physx/physxPointInPlaneJointDesc.cxx new file mode 100644 index 0000000000..1251f7b24e --- /dev/null +++ b/panda/src/physx/physxPointInPlaneJointDesc.cxx @@ -0,0 +1,16 @@ +// Filename: physxPointInPlaneJointDesc.cxx +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxPointInPlaneJointDesc.h" + diff --git a/panda/src/physx/physxPointInPlaneJointDesc.h b/panda/src/physx/physxPointInPlaneJointDesc.h new file mode 100644 index 0000000000..e647c1faab --- /dev/null +++ b/panda/src/physx/physxPointInPlaneJointDesc.h @@ -0,0 +1,46 @@ +// Filename: physxPointInPlaneJointDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXPOINTINPLANEJOINTDESC_H +#define PHYSXPOINTINPLANEJOINTDESC_H + +#include "pandabase.h" + +#include "physxJointDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxPointInPlaneJointDesc +// Description : Descriptor class for point-in-plane joint. See +// PhysxPointInPlaneJoint. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxPointInPlaneJointDesc : public PhysxJointDesc { + +PUBLISHED: + INLINE PhysxPointInPlaneJointDesc(); + INLINE ~PhysxPointInPlaneJointDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + +public: + NxJointDesc *ptr() const { return (NxJointDesc *)&_desc; }; + NxPointInPlaneJointDesc _desc; +}; + +#include "physxPointInPlaneJointDesc.I" + +#endif // PHYSXPOINTINPLANEJOINTDESC_H diff --git a/panda/src/physx/physxPointOnLineJoint.I b/panda/src/physx/physxPointOnLineJoint.I new file mode 100644 index 0000000000..836c1d0826 --- /dev/null +++ b/panda/src/physx/physxPointOnLineJoint.I @@ -0,0 +1,36 @@ +// Filename: physxPointOnLineJoint.I +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointOnLineJoint::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPointOnLineJoint:: +PhysxPointOnLineJoint() : PhysxJoint() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointOnLineJoint::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPointOnLineJoint:: +~PhysxPointOnLineJoint() { + +} + diff --git a/panda/src/physx/physxPointOnLineJoint.cxx b/panda/src/physx/physxPointOnLineJoint.cxx new file mode 100644 index 0000000000..7d7be5b833 --- /dev/null +++ b/panda/src/physx/physxPointOnLineJoint.cxx @@ -0,0 +1,76 @@ +// Filename: physxPointOnLineJoint.cxx +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxPointOnLineJoint.h" +#include "physxPointOnLineJointDesc.h" + +TypeHandle PhysxPointOnLineJoint::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointOnLineJoint::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPointOnLineJoint:: +link(NxJoint *jointPtr) { + + _ptr = jointPtr->isPointOnLineJoint(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointOnLineJoint::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPointOnLineJoint:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxPointOnLineJoint::save_to_desc +// Access : Published +// Description : Saves the state of the joint object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxPointOnLineJoint:: +save_to_desc(PhysxPointOnLineJointDesc &jointDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxPointOnLineJoint::load_from_desc +// Access : Published +// Description : Loads the entire state of the joint from a +// descriptor with a single call. +//////////////////////////////////////////////////////////////////// +void PhysxPointOnLineJoint:: +load_from_desc(const PhysxPointOnLineJointDesc &jointDesc) { + + nassertv(_error_type == ET_ok); + _ptr->loadFromDesc(jointDesc._desc); +} + diff --git a/panda/src/physx/physxPointOnLineJoint.h b/panda/src/physx/physxPointOnLineJoint.h new file mode 100644 index 0000000000..6467c024d4 --- /dev/null +++ b/panda/src/physx/physxPointOnLineJoint.h @@ -0,0 +1,79 @@ +// Filename: physxPointOnLineJoint.h +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXPOINTONLINEJOINT_H +#define PHYSXPOINTONLINEJOINT_H + +#include "pandabase.h" + +#include "physxJoint.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxPointOnLineJointDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxPointOnLineJoint +// Description : A point on line joint constrains a point on one +// body to only move along a line attached to another +// body. +// The starting point of the joint is defined as the +// anchor point. The line through this point is +// specified by its direction (axis) vector. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxPointOnLineJoint : public PhysxJoint { + +PUBLISHED: + INLINE PhysxPointOnLineJoint(); + INLINE ~PhysxPointOnLineJoint(); + + void save_to_desc(PhysxPointOnLineJointDesc &jointDesc) const; + void load_from_desc(const PhysxPointOnLineJointDesc &jointDesc); + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxJoint *ptr() const { return (NxJoint *)_ptr; }; + + void link(NxJoint *jointPtr); + void unlink(); + +private: + NxPointOnLineJoint *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxJoint::init_type(); + register_type(_type_handle, "PhysxPointOnLineJoint", + PhysxJoint::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxPointOnLineJoint.I" + +#endif // PHYSXPOINTONLINEJOINT_H diff --git a/panda/src/physx/physxPointOnLineJointDesc.I b/panda/src/physx/physxPointOnLineJointDesc.I new file mode 100644 index 0000000000..7ac49734c3 --- /dev/null +++ b/panda/src/physx/physxPointOnLineJointDesc.I @@ -0,0 +1,59 @@ +// Filename: physxPointOnLineJointDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointOnLineJointDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPointOnLineJointDesc:: +PhysxPointOnLineJointDesc() : PhysxJointDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointOnLineJointDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPointOnLineJointDesc:: +~PhysxPointOnLineJointDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointOnLineJointDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxPointOnLineJointDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPointOnLineJointDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxPointOnLineJointDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxPointOnLineJointDesc.cxx b/panda/src/physx/physxPointOnLineJointDesc.cxx new file mode 100644 index 0000000000..1b661538d4 --- /dev/null +++ b/panda/src/physx/physxPointOnLineJointDesc.cxx @@ -0,0 +1,16 @@ +// Filename: physxPointOnLineJointDesc.cxx +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxPointOnLineJointDesc.h" + diff --git a/panda/src/physx/physxPointOnLineJointDesc.h b/panda/src/physx/physxPointOnLineJointDesc.h new file mode 100644 index 0000000000..a44773e157 --- /dev/null +++ b/panda/src/physx/physxPointOnLineJointDesc.h @@ -0,0 +1,46 @@ +// Filename: physxPointOnLineJointDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXPOINTONLINEJOINTDESC_H +#define PHYSXPOINTONLINEJOINTDESC_H + +#include "pandabase.h" + +#include "physxJointDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxPointOnLineJointDesc +// Description : Descriptor class for point-on-line joint. +// See PhysxPointOnLineJoint. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxPointOnLineJointDesc : public PhysxJointDesc { + +PUBLISHED: + INLINE PhysxPointOnLineJointDesc(); + INLINE ~PhysxPointOnLineJointDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + +public: + NxJointDesc *ptr() const { return (NxJointDesc *)&_desc; }; + NxPointOnLineJointDesc _desc; +}; + +#include "physxPointOnLineJointDesc.I" + +#endif // PHYSXPOINTONLINEJOINTDESC_H diff --git a/panda/src/physx/physxPrismaticJoint.I b/panda/src/physx/physxPrismaticJoint.I new file mode 100644 index 0000000000..91d82dce03 --- /dev/null +++ b/panda/src/physx/physxPrismaticJoint.I @@ -0,0 +1,36 @@ +// Filename: physxPrismaticJoint.I +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPrismaticJoint::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPrismaticJoint:: +PhysxPrismaticJoint() : PhysxJoint() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPrismaticJoint::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPrismaticJoint:: +~PhysxPrismaticJoint() { + +} + diff --git a/panda/src/physx/physxPrismaticJoint.cxx b/panda/src/physx/physxPrismaticJoint.cxx new file mode 100644 index 0000000000..9d080c43af --- /dev/null +++ b/panda/src/physx/physxPrismaticJoint.cxx @@ -0,0 +1,76 @@ +// Filename: physxPrismaticJoint.cxx +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxPrismaticJoint.h" +#include "physxPrismaticJointDesc.h" + +TypeHandle PhysxPrismaticJoint::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPrismaticJoint::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPrismaticJoint:: +link(NxJoint *jointPtr) { + + _ptr = jointPtr->isPrismaticJoint(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPrismaticJoint::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPrismaticJoint:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxPrismaticJoint::save_to_desc +// Access : Published +// Description : Saves the state of the joint object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxPrismaticJoint:: +save_to_desc(PhysxPrismaticJointDesc &jointDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxPrismaticJoint::load_from_desc +// Access : Published +// Description : Loads the entire state of the joint from a +// descriptor with a single call. +//////////////////////////////////////////////////////////////////// +void PhysxPrismaticJoint:: +load_from_desc(const PhysxPrismaticJointDesc &jointDesc) { + + nassertv(_error_type == ET_ok); + _ptr->loadFromDesc(jointDesc._desc); +} + diff --git a/panda/src/physx/physxPrismaticJoint.h b/panda/src/physx/physxPrismaticJoint.h new file mode 100644 index 0000000000..c9b1c555c6 --- /dev/null +++ b/panda/src/physx/physxPrismaticJoint.h @@ -0,0 +1,76 @@ +// Filename: physxPrismaticJoint.h +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXPRISMATICJOINT_H +#define PHYSXPRISMATICJOINT_H + +#include "pandabase.h" + +#include "physxJoint.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxPrismaticJointDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxPrismaticJoint +// Description : A prismatic joint permits relative translational +// movement between two bodies along an axis, but no +// relative rotational movement. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxPrismaticJoint : public PhysxJoint { + +PUBLISHED: + INLINE PhysxPrismaticJoint(); + INLINE ~PhysxPrismaticJoint(); + + void save_to_desc(PhysxPrismaticJointDesc &jointDesc) const; + void load_from_desc(const PhysxPrismaticJointDesc &jointDesc); + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxJoint *ptr() const { return (NxJoint *)_ptr; }; + + void link(NxJoint *jointPtr); + void unlink(); + +private: + NxPrismaticJoint *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxJoint::init_type(); + register_type(_type_handle, "PhysxPrismaticJoint", + PhysxJoint::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxPrismaticJoint.I" + +#endif // PHYSXPRISMATICJOINT_H diff --git a/panda/src/physx/physxPrismaticJointDesc.I b/panda/src/physx/physxPrismaticJointDesc.I new file mode 100644 index 0000000000..86bf6fef74 --- /dev/null +++ b/panda/src/physx/physxPrismaticJointDesc.I @@ -0,0 +1,59 @@ +// Filename: physxPrismaticJointDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPrismaticJointDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPrismaticJointDesc:: +PhysxPrismaticJointDesc() : PhysxJointDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPrismaticJointDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPrismaticJointDesc:: +~PhysxPrismaticJointDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPrismaticJointDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxPrismaticJointDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPrismaticJointDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxPrismaticJointDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxTriggerHandler.I b/panda/src/physx/physxPrismaticJointDesc.cxx similarity index 79% rename from panda/src/physx/physxTriggerHandler.I rename to panda/src/physx/physxPrismaticJointDesc.cxx index ecf01bfa63..0f7899bbe6 100644 --- a/panda/src/physx/physxTriggerHandler.I +++ b/panda/src/physx/physxPrismaticJointDesc.cxx @@ -1,5 +1,5 @@ -// Filename: physxTriggerHandler.I -// Created by: pratt (May 16, 2006) +// Filename: physxPrismaticJointDesc.cxx +// Created by: enn0x (28Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,6 +12,5 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX +#include "physxPrismaticJointDesc.h" -#endif // HAVE_PHYSX diff --git a/panda/src/physx/physxPrismaticJointDesc.h b/panda/src/physx/physxPrismaticJointDesc.h new file mode 100644 index 0000000000..c0320caffd --- /dev/null +++ b/panda/src/physx/physxPrismaticJointDesc.h @@ -0,0 +1,46 @@ +// Filename: physxPrismaticJointDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXPRISMATICJOINTDESC_H +#define PHYSXPRISMATICJOINTDESC_H + +#include "pandabase.h" + +#include "physxJointDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxPrismaticJointDesc +// Description : Descriptor class for prismatic joint. See +// PhysxPrismaticJoint. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxPrismaticJointDesc : public PhysxJointDesc { + +PUBLISHED: + INLINE PhysxPrismaticJointDesc(); + INLINE ~PhysxPrismaticJointDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + +public: + NxJointDesc *ptr() const { return (NxJointDesc *)&_desc; }; + NxPrismaticJointDesc _desc; +}; + +#include "physxPrismaticJointDesc.I" + +#endif // PHYSXPRISMATICJOINTDESC_H diff --git a/panda/src/physx/physxPulleyJoint.I b/panda/src/physx/physxPulleyJoint.I new file mode 100644 index 0000000000..b3104276ee --- /dev/null +++ b/panda/src/physx/physxPulleyJoint.I @@ -0,0 +1,36 @@ +// Filename: physxPulleyJoint.I +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJoint::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPulleyJoint:: +PhysxPulleyJoint() : PhysxJoint() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJoint::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPulleyJoint:: +~PhysxPulleyJoint() { + +} + diff --git a/panda/src/physx/physxPulleyJoint.cxx b/panda/src/physx/physxPulleyJoint.cxx new file mode 100644 index 0000000000..41010ba6cc --- /dev/null +++ b/panda/src/physx/physxPulleyJoint.cxx @@ -0,0 +1,163 @@ +// Filename: physxPulleyJoint.cxx +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxPulleyJoint.h" +#include "physxPulleyJointDesc.h" +#include "physxMotorDesc.h" + +TypeHandle PhysxPulleyJoint::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJoint::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJoint:: +link(NxJoint *jointPtr) { + + _ptr = jointPtr->isPulleyJoint(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJoint::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJoint:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxPulleyJoint::save_to_desc +// Access : Published +// Description : Saves the state of the joint object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJoint:: +save_to_desc(PhysxPulleyJointDesc &jointDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxPulleyJoint::load_from_desc +// Access : Published +// Description : Loads the entire state of the joint from a +// descriptor with a single call. +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJoint:: +load_from_desc(const PhysxPulleyJointDesc &jointDesc) { + + nassertv(_error_type == ET_ok); + _ptr->loadFromDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJoint::set_motor +// Access: Published +// Description: Sets motor parameters for the joint. +// +// For a positive velTarget, the motor pulls the first +// body towards its pulley, for a negative velTarget, +// the motor pulls the second body towards its pulley. +// +// velTarget - the relative velocity the motor is +// trying to achieve. The motor will only be able to +// reach this velocity if the maxForce is sufficiently +// large. If the joint is moving faster than this +// velocity, the motor will actually try to brake. If +// you set this to infinity then the motor will keep +// speeding up, unless there is some sort of +// resistance on the attached bodies. +// +// maxForce - the maximum force the motor can exert. +// Zero disables the motor. Default is 0, should +// be >= 0. Setting this to a very large value if +// velTarget is also very large may not be a good +// idea. +// +// freeSpin - if this flag is set, and if the joint +// is moving faster than velTarget, then neither +// braking nor additional acceleration will result. +// default: false. +// +// This automatically enables the motor. +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJoint:: +set_motor(const PhysxMotorDesc &motor) { + + nassertv(_error_type == ET_ok); + _ptr->setMotor(motor._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJoint::set_flag +// Access: Published +// Description: Sets or clear a single pulley joint flag. +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJoint:: +set_flag(PhysxPulleyJointFlag flag, bool value) { + + nassertv(_error_type == ET_ok); + NxU32 flags = _ptr->getFlags(); + + if (value == true) { + flags |= flag; + } + else { + flags &= ~(flag); + } + + _ptr->setFlags(flags); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJoint::get_flag +// Access: Published +// Description: Retrieves the value of a single PulleyJointFlag. +//////////////////////////////////////////////////////////////////// +bool PhysxPulleyJoint:: +get_flag(PhysxPulleyJointFlag flag) const { + + nassertr(_error_type == ET_ok, false); + return (_ptr->getFlags() & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJoint::get_motor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxMotorDesc PhysxPulleyJoint:: +get_motor() const { + + nassertr(_error_type == ET_ok, false); + + PhysxMotorDesc value; + _ptr->getMotor(value._desc); + return value; +} + diff --git a/panda/src/physx/physxPulleyJoint.h b/panda/src/physx/physxPulleyJoint.h new file mode 100644 index 0000000000..6701f1d1a8 --- /dev/null +++ b/panda/src/physx/physxPulleyJoint.h @@ -0,0 +1,82 @@ +// Filename: physxPulleyJoint.h +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXPULLEYJOINT_H +#define PHYSXPULLEYJOINT_H + +#include "pandabase.h" + +#include "physxJoint.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxMotorDesc; +class PhysxPulleyJointDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxPulleyJoint +// Description : A pulley joint simulates a rope between two +// objects passing over two pulleys. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxPulleyJoint : public PhysxJoint { + +PUBLISHED: + INLINE PhysxPulleyJoint(); + INLINE ~PhysxPulleyJoint(); + + void save_to_desc(PhysxPulleyJointDesc &jointDesc) const; + void load_from_desc(const PhysxPulleyJointDesc &jointDesc); + + void set_motor(const PhysxMotorDesc &motor); + void set_flag(PhysxPulleyJointFlag flag, bool value); + + bool get_flag(PhysxPulleyJointFlag flag) const; + PhysxMotorDesc get_motor() const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxJoint *ptr() const { return (NxJoint *)_ptr; }; + + void link(NxJoint *jointPtr); + void unlink(); + +private: + NxPulleyJoint *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxJoint::init_type(); + register_type(_type_handle, "PhysxPulleyJoint", + PhysxJoint::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxPulleyJoint.I" + +#endif // PHYSXPULLEYJOINT_H diff --git a/panda/src/physx/physxPulleyJointDesc.I b/panda/src/physx/physxPulleyJointDesc.I new file mode 100644 index 0000000000..bd6f03f155 --- /dev/null +++ b/panda/src/physx/physxPulleyJointDesc.I @@ -0,0 +1,59 @@ +// Filename: physxPulleyJointDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPulleyJointDesc:: +PhysxPulleyJointDesc() : PhysxJointDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxPulleyJointDesc:: +~PhysxPulleyJointDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxPulleyJointDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxPulleyJointDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxPulleyJointDesc.cxx b/panda/src/physx/physxPulleyJointDesc.cxx new file mode 100644 index 0000000000..bb150247f4 --- /dev/null +++ b/panda/src/physx/physxPulleyJointDesc.cxx @@ -0,0 +1,162 @@ +// Filename: physxPulleyJointDesc.cxx +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxPulleyJointDesc.h" +#include "physxMotorDesc.h" +#include "physxManager.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::set_distance +// Access: Published +// Description: Sets the rest length of the rope connecting the +// two objects. +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJointDesc:: +set_distance(float distance) { + + _desc.distance = distance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::set_stiffness +// Access: Published +// Description: Sets how stiff the constraint is, between 0 and 1 +// (stiffest) +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJointDesc:: +set_stiffness(float stiffness) { + + _desc.stiffness = stiffness; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::set_ratio +// Access: Published +// Description: Sets the transmission ratio. +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJointDesc:: +set_ratio(float ratio) { + + _desc.ratio = ratio; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::set_flag +// Access: Published +// Description: Sets or clears a single PulleyJointFlag flag. +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJointDesc:: +set_flag(PhysxPulleyJointFlag flag, bool value) { + + if (value == true) { + _desc.flags |= flag; + } + else { + _desc.flags &= ~(flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::set_pulley +// Access: Published +// Description: Sets the suspension points of two bodies in world +// space. +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJointDesc:: +set_pulley(unsigned int idx, const LPoint3f pos) { + + nassertv_always(idx < 2); + _desc.pulley[idx] = PhysxManager::point3_to_nxVec3(pos); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::set_motor +// Access: Published +// Description: Sets an optional joint motor. +//////////////////////////////////////////////////////////////////// +void PhysxPulleyJointDesc:: +set_motor(const PhysxMotorDesc &motor) { + + _desc.motor = motor._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::get_distance +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxPulleyJointDesc:: +get_distance() const { + + return _desc.distance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::get_stiffness +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxPulleyJointDesc:: +get_stiffness() const { + + return _desc.stiffness; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::get_ratio +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxPulleyJointDesc:: +get_ratio() const { + + return _desc.ratio; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::get_flag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxPulleyJointDesc:: +get_flag(PhysxPulleyJointFlag flag) const { + + return (_desc.flags & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::get_pulley +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxPulleyJointDesc:: +get_pulley(unsigned int idx) const { + + nassertr_always(idx < 2, LPoint3f::zero()); + return PhysxManager::nxVec3_to_point3(_desc.pulley[idx]); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxPulleyJointDesc::get_motor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxMotorDesc PhysxPulleyJointDesc:: +get_motor() const { + + PhysxMotorDesc value; + value._desc = _desc.motor; + return value; +} + diff --git a/panda/src/physx/physxPulleyJointDesc.h b/panda/src/physx/physxPulleyJointDesc.h new file mode 100644 index 0000000000..c881f1e799 --- /dev/null +++ b/panda/src/physx/physxPulleyJointDesc.h @@ -0,0 +1,62 @@ +// Filename: physxPulleyJointDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXPULLEYJOINTDESC_H +#define PHYSXPULLEYJOINTDESC_H + +#include "pandabase.h" + +#include "physxJointDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxMotorDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxPulleyJointDesc +// Description : Descriptor class for distance joint. See +// PhysxPulleyJoint. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxPulleyJointDesc : public PhysxJointDesc { + +PUBLISHED: + INLINE PhysxPulleyJointDesc(); + INLINE ~PhysxPulleyJointDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_distance(float distance); + void set_stiffness(float stiffness); + void set_ratio(float ration); + void set_pulley(unsigned int idx, const LPoint3f pos); + void set_motor(const PhysxMotorDesc &motor); + void set_flag(PhysxPulleyJointFlag flag, bool value); + + float get_distance() const; + float get_stiffness() const; + float get_ratio() const; + bool get_flag(PhysxPulleyJointFlag flag) const; + LPoint3f get_pulley(unsigned int idx) const; + PhysxMotorDesc get_motor() const; + +public: + NxJointDesc *ptr() const { return (NxJointDesc *)&_desc; }; + NxPulleyJointDesc _desc; +}; + +#include "physxPulleyJointDesc.I" + +#endif // PHYSXPULLEYJOINTDESC_H diff --git a/panda/src/physx/physxRay.I b/panda/src/physx/physxRay.I index bc95e9058c..b798c28b4a 100644 --- a/panda/src/physx/physxRay.I +++ b/panda/src/physx/physxRay.I @@ -1,5 +1,5 @@ // Filename: physxRay.I -// Created by: pratt (Dec 12, 2007) +// Created by: enn0x (21Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,3 +12,28 @@ // //////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRay::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxRay:: +PhysxRay() { + + _ray.orig = NxVec3(0.0f, 0.0f, 0.0f); + _ray.dir = NxVec3(1.0f, 0.0f, 0.0f); + + _length = NX_MAX_F32; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRay::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxRay:: +~PhysxRay() { + +} + diff --git a/panda/src/physx/physxRay.cxx b/panda/src/physx/physxRay.cxx index 1ff4ea74a8..c622fc4160 100644 --- a/panda/src/physx/physxRay.cxx +++ b/panda/src/physx/physxRay.cxx @@ -1,5 +1,5 @@ // Filename: physxRay.cxx -// Created by: pratt (Dec 12, 2007) +// Created by: enn0x (21Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,90 +12,82 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxRay.h" - -#include "luse.h" - +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxRay -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxRay:: -PhysxRay() { - nRay = new NxRay(); -} - -//////////////////////////////////////////////////////////////////// -// Function : PhysxRay -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxRay:: -PhysxRay(const LVecBase3f & _orig, const LVecBase3f & _dir) { - nRay = new NxRay(PhysxManager::lVecBase3_to_nxVec3(_orig), PhysxManager::lVecBase3_to_nxVec3(_dir)); -} - -//////////////////////////////////////////////////////////////////// -// Function : ~PhysxRay -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxRay:: -~PhysxRay() { - delete nRay; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_dir -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxRay:: -get_dir() const { - nassertr(nRay != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nRay->dir); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_orig -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxRay:: -get_orig() const { - nassertr(nRay != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nRay->orig); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_dir -// Access : Published -// Description : +// Function: PhysxRay::set_origin +// Access: Published +// Description: Sets the ray origin. //////////////////////////////////////////////////////////////////// void PhysxRay:: -set_dir(LVecBase3f value) { - nassertv(nRay != NULL); +set_origin(const LPoint3f &origin) { - nRay->dir = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv_always(!origin.is_nan()); + _ray.orig = PhysxManager::point3_to_nxVec3(origin); } //////////////////////////////////////////////////////////////////// -// Function : set_orig -// Access : Published -// Description : +// Function: PhysxRay::get_origin +// Access: Published +// Description: Returns the ray origin +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxRay:: +get_origin() const { + + return PhysxManager::nxVec3_to_point3(_ray.orig); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRay::set_direction +// Access: Published +// Description: Set the ray direction. It is not required to pass +// a normalized vector. //////////////////////////////////////////////////////////////////// void PhysxRay:: -set_orig(LVecBase3f value) { - nassertv(nRay != NULL); +set_direction(const LVector3f &direction) { - nRay->orig = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv_always(!direction.is_nan()); + + _ray.dir = PhysxManager::vec3_to_nxVec3(direction); + _ray.dir.normalize(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRay::get_direction +// Access: Published +// Description: Returns the ray direction. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxRay:: +get_direction() const { + + return PhysxManager::nxVec3_to_vec3(_ray.dir); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRay::set_length +// Access: Published +// Description: Sets the ray length. If no length is set then the +// ray will be virtually infinite (the maximum +// floating point number will be used, e.g. +// 3.40282346639e+038). +//////////////////////////////////////////////////////////////////// +void PhysxRay:: +set_length(float length) { + + nassertv_always(length > 0.0f); + _length = length; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRay::get_length +// Access: Published +// Description: Returns the ray length. +//////////////////////////////////////////////////////////////////// +float PhysxRay:: +get_length() const { + + return _length; } -#endif // HAVE_PHYSX diff --git a/panda/src/physx/physxRay.h b/panda/src/physx/physxRay.h index 499c19aabc..81c499ffab 100644 --- a/panda/src/physx/physxRay.h +++ b/panda/src/physx/physxRay.h @@ -1,5 +1,5 @@ // Filename: physxRay.h -// Created by: pratt (Dec 12, 2007) +// Created by: enn0x (21Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,39 +15,36 @@ #ifndef PHYSXRAY_H #define PHYSXRAY_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "lvector3.h" +#include "lpoint3.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -#include "NxPhysics.h" +#include "config_physx.h" //////////////////////////////////////////////////////////////////// // Class : PhysxRay -// Description : +// Description : Represents an ray as an origin and direction. +// The ray will be infinite if no length is given. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxRay { + PUBLISHED: - PhysxRay(); - PhysxRay(const LVecBase3f & _orig, const LVecBase3f & _dir); - ~PhysxRay(); + INLINE PhysxRay(); + INLINE ~PhysxRay(); + void set_length(float length); + void set_origin(const LPoint3f &origin); + void set_direction(const LVector3f &direction); - LVecBase3f get_dir() const; - LVecBase3f get_orig() const; - - void set_dir(LVecBase3f value); - void set_orig(LVecBase3f value); + float get_length() const; + LPoint3f get_origin() const; + LVector3f get_direction() const; public: - NxRay *nRay; + NxRay _ray; + NxReal _length; }; #include "physxRay.I" -#endif // HAVE_PHYSX - -#endif // PHYSXRAY_H +#endif // PHYSRAY_H diff --git a/panda/src/physx/physxRaycastHit.I b/panda/src/physx/physxRaycastHit.I new file mode 100644 index 0000000000..340f2c3928 --- /dev/null +++ b/panda/src/physx/physxRaycastHit.I @@ -0,0 +1,36 @@ +// Filename: physxRaycastHit.I +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastHit::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxRaycastHit:: +PhysxRaycastHit(const NxRaycastHit hit) { + + _hit = hit; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastHit::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxRaycastHit:: +~PhysxRaycastHit() { + +} + diff --git a/panda/src/physx/physxRaycastHit.cxx b/panda/src/physx/physxRaycastHit.cxx new file mode 100644 index 0000000000..542bdffb09 --- /dev/null +++ b/panda/src/physx/physxRaycastHit.cxx @@ -0,0 +1,74 @@ +// Filename: physxRaycastHit.cxx +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxRaycastHit.h" +#include "physxManager.h" +#include "physxShape.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastHit::is_empty +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxRaycastHit:: +is_empty() const { + + return (_hit.shape == NULL); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastHit::get_shape +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxShape) PhysxRaycastHit:: +get_shape() const { + + nassertr_always(_hit.shape, NULL); + return (PhysxShape *)_hit.shape->userData; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastHit::get_impact_pos +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxRaycastHit:: +get_impact_pos() const { + + return PhysxManager::nxVec3_to_point3(_hit.worldImpact); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastHit::get_impact_normal +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LVector3f PhysxRaycastHit:: +get_impact_normal() const { + + return PhysxManager::nxVec3_to_vec3(_hit.worldNormal); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastHit::get_distance +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxRaycastHit:: +get_distance() const { + + return _hit.distance; +} + diff --git a/panda/src/physx/physxRaycastHit.h b/panda/src/physx/physxRaycastHit.h new file mode 100644 index 0000000000..c5ca46ad16 --- /dev/null +++ b/panda/src/physx/physxRaycastHit.h @@ -0,0 +1,51 @@ +// Filename: physxRaycastHit.h +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXRAYCASTHIT_H +#define PHYSXRAYCASTHIT_H + +#include "pandabase.h" +#include "lvector3.h" +#include "lpoint3.h" + +#include "config_physx.h" + +class PhysxShape; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxRaycastHit +// Description : This structure captures results for a single +// raycast query. See PhysxScene for raycasting +// methods. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxRaycastHit { + +PUBLISHED: + INLINE PhysxRaycastHit(const NxRaycastHit hit); + INLINE ~PhysxRaycastHit(); + + bool is_empty() const; + + PT(PhysxShape) get_shape() const; + LPoint3f get_impact_pos() const; + LVector3f get_impact_normal() const; + float get_distance() const; + +private: + NxRaycastHit _hit; +}; + +#include "physxRaycastHit.I" + +#endif // PHYSXRAYCASTHIT_H diff --git a/panda/src/physx/physxRaycastReport.I b/panda/src/physx/physxRaycastReport.I new file mode 100644 index 0000000000..9d66902fbc --- /dev/null +++ b/panda/src/physx/physxRaycastReport.I @@ -0,0 +1,35 @@ +// Filename: physxRaycastReport.I +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastReport::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxRaycastReport:: +PhysxRaycastReport() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastReport::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxRaycastReport:: +~PhysxRaycastReport() { + +} + diff --git a/panda/src/physx/physxRaycastReport.cxx b/panda/src/physx/physxRaycastReport.cxx new file mode 100644 index 0000000000..4c03f21939 --- /dev/null +++ b/panda/src/physx/physxRaycastReport.cxx @@ -0,0 +1,89 @@ +// Filename: physxRaycastReport.cxx +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxRaycastReport.h" +#include "physxRaycastHit.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastReport::onRaycast +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxRaycastReport:: +onHit(const NxRaycastHit& hit) { + + _hits.push_back(PhysxRaycastHit(hit)); + return true; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastReport::get_num_hits +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +unsigned int PhysxRaycastReport:: +get_num_hits() const { + + return _hits.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastReport::get_first_hit +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxRaycastHit PhysxRaycastReport:: +get_first_hit() { + + _iterator = _hits.begin(); + return get_next_hit(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastReport::get_next_hit +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxRaycastHit PhysxRaycastReport:: +get_next_hit() { + + if (_iterator != _hits.end()) { + return *_iterator++; + } + + // No more items. Return an empty hit. + NxRaycastHit hit; + hit.shape = NULL; + return PhysxRaycastHit(hit); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRaycastReport::get_hit +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxRaycastHit PhysxRaycastReport:: +get_hit(unsigned int idx) { + + if (!(idx < _hits.size())) + { + // Index out of bounds. Return an empty hit. + NxRaycastHit hit; + hit.shape = NULL; + return PhysxRaycastHit(hit); + } + + return _hits[idx]; +} + diff --git a/panda/src/physx/physxRaycastReport.h b/panda/src/physx/physxRaycastReport.h new file mode 100644 index 0000000000..f9d19ba37d --- /dev/null +++ b/panda/src/physx/physxRaycastReport.h @@ -0,0 +1,56 @@ +// Filename: physxRaycastReport.h +// Created by: enn0x (21Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXRAYCASTREPORT_H +#define PHYSXRAYCASTREPORT_H + +#include "pandabase.h" +#include "pvector.h" + +#include "config_physx.h" + +class PhysxRaycastHit; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxRaycastReport +// Description : Objects of this class are returned by the 'raycast +// all' methods. They contain an iterable list of all +// hits that the raycast query produced. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxRaycastReport : public NxUserRaycastReport { + +PUBLISHED: + unsigned int get_num_hits() const; + PhysxRaycastHit get_first_hit(); + PhysxRaycastHit get_next_hit(); + PhysxRaycastHit get_hit(unsigned int idx); + MAKE_SEQ(get_hits, get_num_hits, get_hit); + +public: + INLINE PhysxRaycastReport(); + INLINE ~PhysxRaycastReport(); + + virtual bool onHit(const NxRaycastHit& hit); + +private: + typedef pvector Hits; + Hits _hits; + + typedef Hits::const_iterator const_iterator; + const_iterator _iterator; +}; + +#include "physxRaycastReport.I" + +#endif // PHYSXRAYCASTREPORT_H diff --git a/panda/src/physx/physxRevoluteJoint.I b/panda/src/physx/physxRevoluteJoint.I new file mode 100644 index 0000000000..b5640107c7 --- /dev/null +++ b/panda/src/physx/physxRevoluteJoint.I @@ -0,0 +1,36 @@ +// Filename: physxRevoluteJoint.I +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxRevoluteJoint:: +PhysxRevoluteJoint() : PhysxJoint() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxRevoluteJoint:: +~PhysxRevoluteJoint() { + +} + diff --git a/panda/src/physx/physxRevoluteJoint.cxx b/panda/src/physx/physxRevoluteJoint.cxx new file mode 100644 index 0000000000..3fa678aa63 --- /dev/null +++ b/panda/src/physx/physxRevoluteJoint.cxx @@ -0,0 +1,315 @@ +// Filename: physxRevoluteJoint.cxx +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxRevoluteJoint.h" +#include "physxRevoluteJointDesc.h" +#include "physxJointLimitDesc.h" +#include "physxMotorDesc.h" +#include "physxSpringDesc.h" + +TypeHandle PhysxRevoluteJoint::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJoint:: +link(NxJoint *jointPtr) { + + _ptr = jointPtr->isRevoluteJoint(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJoint:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxRevoluteJoint::save_to_desc +// Access : Published +// Description : Saves the state of the joint object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJoint:: +save_to_desc(PhysxRevoluteJointDesc &jointDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxRevoluteJoint::load_from_desc +// Access : Published +// Description : Loads the entire state of the joint from a +// descriptor with a single call. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJoint:: +load_from_desc(const PhysxRevoluteJointDesc &jointDesc) { + + nassertv(_error_type == ET_ok); + _ptr->loadFromDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::get_angle +// Access: Published +// Description: Retrieves the current revolute joint angle. +// +// The relative orientation of the bodies is stored +// when the joint is created, or when set_axis() or +// set_anchor() is called. This initial orientation +// returns an angle of zero, and joint angles are +// measured relative to this pose. The angle is in +// the range [-180, 180], with positive angles CCW +// around the axis, measured from body2 to body1. +//////////////////////////////////////////////////////////////////// +float PhysxRevoluteJoint:: +get_angle() const { + + nassertr(_error_type == ET_ok, 0.0f); + return NxMath::radToDeg(_ptr->getAngle()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::get_velocity +// Access: Published +// Description: Retrieves the revolute joint angle's rate of change +// (angular velocity). It is the angular velocity of +// body1 minus body2 projected along the axis. +//////////////////////////////////////////////////////////////////// +float PhysxRevoluteJoint:: +get_velocity() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getVelocity(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::set_projection_mode +// Access: Published +// Description: Sets the joint projection mode. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJoint:: +set_projection_mode(PhysxProjectionMode mode) { + + nassertv(_error_type == ET_ok); + _ptr->setProjectionMode((NxJointProjectionMode)mode); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::get_projection_mode +// Access: Published +// Description: Retrieves the joints projection mode. +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxProjectionMode PhysxRevoluteJoint:: +get_projection_mode() const { + + nassertr(_error_type == ET_ok, PM_none); + return (PhysxProjectionMode)_ptr->getProjectionMode(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::set_flag +// Access: Published +// Description: Sets or clears a single RevoluteJointFlag. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJoint:: +set_flag(PhysxRevoluteJointFlag flag, bool value) { + + nassertv( _error_type == ET_ok ); + NxU32 flags = _ptr->getFlags(); + + if (value == true) { + flags |= flag; + } + else { + flags &= ~(flag); + } + + _ptr->setFlags(flags); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::get_flag +// Access: Published +// Description: Returns the value of a single RevoluteJointFlag. +//////////////////////////////////////////////////////////////////// +bool PhysxRevoluteJoint:: +get_flag(PhysxRevoluteJointFlag flag) const { + + nassertr(_error_type == ET_ok, false); + return (_ptr->getFlags() & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::set_spring +// Access: Published +// Description: Sets spring parameters. +// +// The spring is implicitly integrated so no +// instability should result for arbitrary spring and +// damping constants. Using these settings together +// with a motor is not possible -- the motor will have +// priority and the spring settings are ignored. If +// you would like to simulate your motor's internal +// friction, do this by altering the motor parameters +// directly. +// +// spring - The rotational spring acts along the hinge +// axis and tries to force the joint angle to zero. A +// setting of zero disables the spring. Default is 0, +// should be >= 0. +// +// damper - Damping coefficient; acts against the +// hinge's angular velocity. A setting of zero +// disables the damping. The default is 0, should +// be >= 0. +// +// targetValue - The angle at which the spring is +// relaxed. In [-Pi,Pi]. Default is 0. +// +// This automatically enables the spring +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJoint:: +set_spring(const PhysxSpringDesc &spring) { + + nassertv(_error_type == ET_ok); + _ptr->setSpring(spring._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::set_motor +// Access: Published +// Description: Sets motor parameters for the joint. +// +// For a positive velTarget, the motor pulls the first +// body towards its pulley, for a negative velTarget, +// the motor pulls the second body towards its pulley. +// +// velTarget - the relative velocity the motor is +// trying to achieve. The motor will only be able to +// reach this velocity if the maxForce is sufficiently +// large. If the joint is moving faster than this +// velocity, the motor will actually try to brake. If +// you set this to infinity then the motor will keep +// speeding up, unless there is some sort of +// resistance on the attached bodies. +// +// maxForce - the maximum force the motor can exert. +// Zero disables the motor. Default is 0, should +// be >= 0. Setting this to a very large value if +// velTarget is also very large may not be a good +// idea. +// +// freeSpin - if this flag is set, and if the joint +// is moving faster than velTarget, then neither +// braking nor additional acceleration will result. +// default: false. +// +// This automatically enables the motor. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJoint:: +set_motor(const PhysxMotorDesc &motor) { + + nassertv(_error_type == ET_ok); + _ptr->setMotor(motor._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::set_limits +// Access: Published +// Description: Sets angular joint limits. +// +// If either of these limits are set, any planar +// limits in PhysxJoint are ignored. The limits are +// angles defined the same way as the values +// that get_angle() returns. +// +// The following has to hold: +// +// Pi < lowAngle < highAngle < Pi Both limits are +// disabled by default. +// Also sets coefficients of restitutions for the low +// and high angular limits. These settings are only +// used if valid limits are set using set_limits(). +// These restitution coefficients work the same way as +// for contacts. +// +// The coefficient of restitution determines whether a +// collision with the joint limit is completely +// elastic (like pool balls, restitution = 1, no +// energy is lost in the collision), completely +// inelastic (like putty, restitution = 0, no rebound +// after collision) or somewhere in between. The +// default is 0 for both. +// +// This automatically enables the limit. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJoint:: +set_limits(const PhysxJointLimitDesc &low, const PhysxJointLimitDesc &high) { + + nassertv(_error_type == ET_ok); + + NxJointLimitPairDesc limits; + limits.low = low._desc; + limits.high = high._desc; + _ptr->setLimits(limits); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::get_motor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxMotorDesc PhysxRevoluteJoint:: +get_motor() const { + + nassertr(_error_type == ET_ok, NULL); + + PhysxMotorDesc value; + _ptr->getMotor(value._desc); + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJoint::get_spring +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxSpringDesc PhysxRevoluteJoint:: +get_spring() const { + + nassertr(_error_type == ET_ok, NULL); + + PhysxSpringDesc value; + _ptr->getSpring(value._desc); + return value; +} + diff --git a/panda/src/physx/physxRevoluteJoint.h b/panda/src/physx/physxRevoluteJoint.h new file mode 100644 index 0000000000..ed370df053 --- /dev/null +++ b/panda/src/physx/physxRevoluteJoint.h @@ -0,0 +1,94 @@ +// Filename: physxRevoluteJoint.h +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXREVOLUTEJOINT_H +#define PHYSXREVOLUTEJOINT_H + +#include "pandabase.h" + +#include "physxJoint.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxRevoluteJointDesc; +class PhysxSpringDesc; +class PhysxMotorDesc; +class PhysxJointLimitDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxRevoluteJoint +// Description : A joint which behaves in a similar way to a hinge +// or axel. A hinge joint removes all but a single +// rotational degree of freedom from two objects. The +// axis along which the two bodies may rotate is +// specified with a point and a direction vector. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxRevoluteJoint : public PhysxJoint { + +PUBLISHED: + INLINE PhysxRevoluteJoint(); + INLINE ~PhysxRevoluteJoint(); + + void save_to_desc(PhysxRevoluteJointDesc &jointDesc) const; + void load_from_desc(const PhysxRevoluteJointDesc &jointDesc); + + void set_spring(const PhysxSpringDesc &spring); + void set_motor(const PhysxMotorDesc &motor); + void set_limits(const PhysxJointLimitDesc &low, const PhysxJointLimitDesc &high); + void set_flag(PhysxRevoluteJointFlag flag, bool value); + void set_projection_mode(PhysxProjectionMode mode); + + float get_angle() const; + float get_velocity() const; + bool get_flag(PhysxRevoluteJointFlag flag) const; + PhysxProjectionMode get_projection_mode() const; + PhysxMotorDesc get_motor() const; + PhysxSpringDesc get_spring() const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxJoint *ptr() const { return (NxJoint *)_ptr; }; + + void link(NxJoint *jointPtr); + void unlink(); + +private: + NxRevoluteJoint *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxJoint::init_type(); + register_type(_type_handle, "PhysxRevoluteJoint", + PhysxJoint::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxRevoluteJoint.I" + +#endif // PHYSXREVOLUTEJOINT_H diff --git a/panda/src/physx/physxRevoluteJointDesc.I b/panda/src/physx/physxRevoluteJointDesc.I new file mode 100644 index 0000000000..1da2807e9c --- /dev/null +++ b/panda/src/physx/physxRevoluteJointDesc.I @@ -0,0 +1,59 @@ +// Filename: physxRevoluteJointDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxRevoluteJointDesc:: +PhysxRevoluteJointDesc() : PhysxJointDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxRevoluteJointDesc:: +~PhysxRevoluteJointDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxRevoluteJointDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxRevoluteJointDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxRevoluteJointDesc.cxx b/panda/src/physx/physxRevoluteJointDesc.cxx new file mode 100644 index 0000000000..c090ef5be6 --- /dev/null +++ b/panda/src/physx/physxRevoluteJointDesc.cxx @@ -0,0 +1,214 @@ +// Filename: physxRevoluteJointDesc.cxx +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxRevoluteJointDesc.h" +#include "physxSpringDesc.h" +#include "physxMotorDesc.h" +#include "physxJointLimitDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::set_projection_distance +// Access: Published +// Description: Sets the distance beyond which the joint is +// projected. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJointDesc:: +set_projection_distance(float distance) { + + _desc.projectionDistance = distance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::set_projection_angle +// Access: Published +// Description: Sets the angle beyond which the joint is projected. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJointDesc:: +set_projection_angle(float angle) { + + _desc.projectionAngle = angle; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::set_spring +// Access: Published +// Description: Sets an aptional spring. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJointDesc:: +set_spring(const PhysxSpringDesc &spring) { + + _desc.spring = spring._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::set_flag +// Access: Published +// Description: Sets or clears a single RevoluteJointFlag flag. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJointDesc:: +set_flag(PhysxRevoluteJointFlag flag, bool value) { + + if (value == true) { + _desc.flags |= flag; + } + else { + _desc.flags &= ~(flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::set_projection_mode +// Access: Published +// Description: Use this to enable joint projection. +// Default is PM_none. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJointDesc:: +set_projection_mode(PhysxProjectionMode mode) { + + _desc.projectionMode = (NxJointProjectionMode)mode; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::set_motor +// Access: Published +// Description: Sets an optional joint motor. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJointDesc:: +set_motor(const PhysxMotorDesc &motor) { + + _desc.motor = motor._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::set_limit_low +// Access: Published +// Description: Sets optional limits for the angular motion of the +// joint. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJointDesc:: +set_limit_low(const PhysxJointLimitDesc &low) { + + _desc.limit.low = low._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::set_limit_high +// Access: Published +// Description: Sets optional limits for the angular motion of the +// joint. +//////////////////////////////////////////////////////////////////// +void PhysxRevoluteJointDesc:: +set_limit_high(const PhysxJointLimitDesc &high) { + + _desc.limit.high = high._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::get_projection_distance +// Access: Published +// Description: Return the distance beyond which the joint is +// projected. +//////////////////////////////////////////////////////////////////// +float PhysxRevoluteJointDesc:: +get_projection_distance() const { + + return _desc.projectionDistance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::get_projection_angle +// Access: Published +// Description: Return the angle beyond which the joint is +// projected. +//////////////////////////////////////////////////////////////////// +float PhysxRevoluteJointDesc:: +get_projection_angle() const { + + return _desc.projectionAngle; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::get_spring +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxSpringDesc PhysxRevoluteJointDesc:: +get_spring() const { + + PhysxSpringDesc value; + value._desc = _desc.spring; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::get_flag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxRevoluteJointDesc:: +get_flag(PhysxRevoluteJointFlag flag) const { + + return (_desc.flags & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::get_projection_mode +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxProjectionMode PhysxRevoluteJointDesc:: +get_projection_mode() const { + + return (PhysxProjectionMode)_desc.projectionMode; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::get_motor +// Access: Published +// Description: Sets an optional joint motor. +//////////////////////////////////////////////////////////////////// +PhysxMotorDesc PhysxRevoluteJointDesc:: +get_motor() const { + + PhysxMotorDesc value; + value._desc = _desc.motor; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::get_limit_low +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointLimitDesc PhysxRevoluteJointDesc:: +get_limit_low() const { + + PhysxJointLimitDesc value; + value._desc = _desc.limit.low; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxRevoluteJointDesc::get_limit_high +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointLimitDesc PhysxRevoluteJointDesc:: +get_limit_high() const { + + PhysxJointLimitDesc value; + value._desc = _desc.limit.high; + return value; +} + diff --git a/panda/src/physx/physxRevoluteJointDesc.h b/panda/src/physx/physxRevoluteJointDesc.h new file mode 100644 index 0000000000..f06ab7df45 --- /dev/null +++ b/panda/src/physx/physxRevoluteJointDesc.h @@ -0,0 +1,68 @@ +// Filename: physxRevoluteJointDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXREVOLUTEJOINTDESC_H +#define PHYSXREVOLUTEJOINTDESC_H + +#include "pandabase.h" + +#include "physxJointDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxSpringDesc; +class PhysxMotorDesc; +class PhysxJointLimitDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxRevoluteJointDesc +// Description : Descriptor class for distance joint. See +// PhysxRevoluteJoint. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxRevoluteJointDesc : public PhysxJointDesc { + +PUBLISHED: + INLINE PhysxRevoluteJointDesc(); + INLINE ~PhysxRevoluteJointDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_projection_distance(float distance); + void set_projection_angle(float angle); + void set_spring(const PhysxSpringDesc &spring); + void set_flag(PhysxRevoluteJointFlag flag, bool value); + void set_motor(const PhysxMotorDesc &motor); + void set_limit_low(const PhysxJointLimitDesc &low); + void set_limit_high(const PhysxJointLimitDesc &high); + void set_projection_mode(PhysxProjectionMode mode); + + float get_projection_distance() const; + float get_projection_angle() const; + bool get_flag(PhysxRevoluteJointFlag flag) const; + PhysxSpringDesc get_spring() const; + PhysxMotorDesc get_motor() const; + PhysxJointLimitDesc get_limit_low() const; + PhysxJointLimitDesc get_limit_high() const; + PhysxProjectionMode get_projection_mode() const; + +public: + NxJointDesc *ptr() const { return (NxJointDesc *)&_desc; }; + NxRevoluteJointDesc _desc; +}; + +#include "physxRevoluteJointDesc.I" + +#endif // PHYSXREVOLUTEJOINTDESC_H diff --git a/panda/src/physx/physxScene.I b/panda/src/physx/physxScene.I index 764d01f447..86d4753339 100644 --- a/panda/src/physx/physxScene.I +++ b/panda/src/physx/physxScene.I @@ -1,5 +1,5 @@ // Filename: physxScene.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (14Sep09) // //////////////////////////////////////////////////////////////////// // @@ -14,4 +14,55 @@ +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxScene:: +PhysxScene() : PhysxObject() { + + _debugNode = new PhysxDebugGeomNode(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxScene:: +~PhysxScene() { + + _debugNode = NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxScene:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxScene:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " (at 0x" << this << ")\n"; + + _materials.ls(out, indent_level); + _actors.ls(out, indent_level); + _joints.ls(out, indent_level); + _forcefields.ls(out, indent_level); + _ffgroups.ls(out, indent_level); + _controllers.ls(out, indent_level); +} diff --git a/panda/src/physx/physxScene.cxx b/panda/src/physx/physxScene.cxx index 01bd5868d8..900f8c0ea2 100644 --- a/panda/src/physx/physxScene.cxx +++ b/panda/src/physx/physxScene.cxx @@ -1,5 +1,5 @@ // Filename: physxScene.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (14Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,1024 +12,1547 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxScene.h" - -#include "luse.h" -#include "physxActorNode.h" +#include "physxManager.h" #include "physxActorDesc.h" -#include "physxJoint.h" -#include "physxJointDesc.h" -#include "physxMaterial.h" -#include "physxMaterialDesc.h" -#include "physxSceneDesc.h" +#include "physxForceFieldDesc.h" +#include "physxForceFieldShapeGroupDesc.h" +#include "physxControllerDesc.h" #include "physxSceneStats2.h" -#include "physxShape.h" +#include "physxConstraintDominance.h" -#include "pStatTimer.h" -#include "pStatClient.h" -#include "pStatCollector.h" +TypeHandle PhysxScene::_type_handle; -PStatCollector PhysxScene::_update_pcollector("App:PhysX:Update Panda Graph"); -PStatCollector PhysxScene::_fetch_results_pcollector("App:PhysX:Update Panda Graph:Fetch Results"); -PStatCollector PhysxScene::_update_transforms_pcollector("App:PhysX:Update Panda Graph:Update Transforms"); -PStatCollector PhysxScene::_simulate_pcollector("App:PhysX:Simulate"); -PStatCollector PhysxScene::_flush_stream_pcollector("App:PhysX:Flush Stream"); -PStatCollector PhysxScene::_contact_reporting_pcollector("App:PhysX:Contact Reporting"); -PStatCollector PhysxScene::_trigger_reporting_pcollector("App:PhysX:Trigger Reporting"); -PStatCollector PhysxScene::_joint_reporting_pcollector("App:PhysX:Joint Reporting"); +PStatCollector PhysxScene::_pcollector_fetch_results("App:PhysX:Fetch Results"); +PStatCollector PhysxScene::_pcollector_update_transforms("App:PhysX:Update Transforms"); +PStatCollector PhysxScene::_pcollector_debug_renderer("App:PhysX:Debug Renderer"); +PStatCollector PhysxScene::_pcollector_simulate("App:PhysX:Simulate"); //////////////////////////////////////////////////////////////////// -// Function : update_panda_graph -// Access : Published -// Description : +// Function: PhysxScene::link +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// void PhysxScene:: -update_panda_graph() { - PStatTimer timer(_update_pcollector); +link(NxScene *scenePtr) { - _fetch_results_pcollector.start(); - nScene->fetchResults(NX_RIGID_BODY_FINISHED, true); - _fetch_results_pcollector.stop(); + // Link self + _ptr = scenePtr; + _ptr->userData = this; + _error_type = ET_ok; + PhysxManager::get_global_ptr()->_scenes.add(this); - _update_transforms_pcollector.start(); - PhysxActorNode *pActor; - unsigned int numTransforms; - NxActiveTransform *activeTransforms = nScene->getActiveTransforms(numTransforms); - for(unsigned int i=0; iupdate_transform(); + _cm = NxCreateControllerManager(NxGetPhysicsSDKAllocator()); + nassertv_always(_cm); + + // Link materials + NxMaterial *materials[5]; + NxU32 iterator = 0; + + while (NxU32 i=_ptr->getMaterialArray(materials, 5, iterator)) { + while(i--) { + PT(PhysxMaterial) material = new PhysxMaterial(); + material->link(materials[i]); + } + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxScene:: +unlink() { + + // Unlink controllers + NxU32 nControllers = _cm->getNbControllers(); + + for (NxU32 i=0; i < nControllers; i++) { + NxController *controllerPtr = _cm->getController(i); + PT(PhysxController) controller = (PhysxController *)controllerPtr->getUserData(); + controller->unlink(); + } + + // Unlink actors + NxActor **actors = _ptr->getActors(); + NxU32 nActors = _ptr->getNbActors(); + + for (NxU32 i=0; i < nActors; i++) { + PT(PhysxActor) actor = (PhysxActor *)actors[i]->userData; + + // Actor could have already been unlinked by controller + if (actor) { + actor->unlink(); } } - _update_transforms_pcollector.stop(); + // Unlink joints + NxU32 nJoints = _ptr->getNbJoints(); - _contact_reporting_pcollector.start(); - if(contact_reporting_enabled) { - contact_handler.throw_events(); - } - contact_handler.clear_events(); - _contact_reporting_pcollector.stop(); - - _trigger_reporting_pcollector.start(); - if(trigger_reporting_enabled) { - trigger_handler.throw_events(); - } - trigger_handler.clear_events(); - _trigger_reporting_pcollector.stop(); - - _joint_reporting_pcollector.start(); - if(joint_reporting_enabled) { - joint_handler.throw_events(); - } - joint_handler.clear_events(); - _joint_reporting_pcollector.stop(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_actor -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PT(PhysxActorNode) PhysxScene:: -get_actor(unsigned int index) { - if((index >= 0) && (index < get_nb_actors())) { - NxActor **actors = nScene->getActors(); - return (PhysxActorNode *)(actors[index]->userData); - } else { - return NULL; - } -} - -//////////////////////////////////////////////////////////////////// -// Function : create_actor -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PT(PhysxActorNode) PhysxScene:: -create_actor(const PhysxActorDesc & desc, const string &name) { - NxActor *nActor = nScene->createActor(desc.nActorDesc); - if(nActor == NULL) { - return NULL; + _ptr->resetJointIterator(); + for (NxU32 i=0; i < nJoints; i++) { + NxJoint *jointPtr = _ptr->getNextJoint(); + PT(PhysxJoint) joint = (PhysxJoint *)jointPtr->userData; + joint->unlink(); } - PT(PhysxActorNode) pActor = new PhysxActorNode(name); - nActor->userData = pActor; - pActor->nActor = nActor; + // Unlink force fields + NxForceField **fields = _ptr->getForceFields(); + NxU32 nFields = _ptr->getNbForceFields(); - // Must build PhysxShapes for shapes that were created during the creation - // of the Actor. - unsigned int numShapes = nActor->getNbShapes(); - NxShape * const* shapes = nActor->getShapes(); - for(unsigned int i = 0; i < numShapes; ++i ) { - // Some pointer nastiness is required to cast PT(PhysxShape) to each - // specific shape type. - NxShape *nShape = shapes[i]; - PT(PhysxShape) pShape; - PhysxShape *pShapePointer; - if(nShape->getType() == NX_SHAPE_BOX) { - pShape = new PhysxBoxShape(); - pShapePointer = (PhysxShape *)pShape; - ((PhysxBoxShape *)pShapePointer)->nBoxShape = (NxBoxShape *)nShape; - } else if(nShape->getType() == NX_SHAPE_CAPSULE) { - pShape = new PhysxCapsuleShape(); - pShapePointer = (PhysxShape *)pShape; - ((PhysxCapsuleShape *)pShapePointer)->nCapsuleShape = (NxCapsuleShape *)nShape; - } else if(nShape->getType() == NX_SHAPE_PLANE) { - pShape = new PhysxPlaneShape(); - pShapePointer = (PhysxShape *)pShape; - ((PhysxPlaneShape *)pShapePointer)->nPlaneShape = (NxPlaneShape *)nShape; - } else if(nShape->getType() == NX_SHAPE_SPHERE) { - pShape = new PhysxSphereShape(); - pShapePointer = (PhysxShape *)pShape; - ((PhysxSphereShape *)pShapePointer)->nSphereShape = (NxSphereShape *)nShape; + for (NxU32 i=0; i < nFields; i++) { + PT(PhysxForceField) field = (PhysxForceField *)fields[i]->userData; + field->unlink(); + } + + // Unlink force field shape groups + NxU32 nGroups = _ptr->getNbForceFieldShapeGroups(); + + _ptr->resetForceFieldShapeGroupsIterator(); + for (NxU32 i=0; i < nGroups; i++) { + NxForceFieldShapeGroup *groupPtr = _ptr->getNextForceFieldShapeGroup(); + PT(PhysxForceFieldShapeGroup) group = (PhysxForceFieldShapeGroup *)groupPtr->userData; + group->unlink(); + } + + // Unlink cloths TODO + // Unlink softbodies TODO + + // Unlink materials + NxMaterial *materials[5]; + NxU32 iterator = 0; + + while (NxU32 i=_ptr->getMaterialArray(materials, 5, iterator)) { + while(i--) { + PT(PhysxMaterial) material = (PhysxMaterial *)materials[i]->userData; + material->unlink(); } - nShape->userData = pShape; - pShape->nShape = nShape; + } - // Force the shape to re-store its name string, so that the pointer won't - // be invalidated when the shapeDesc is destroyed. - if(nShape->getName() != NULL) { - pShape->set_name(nShape->getName()); - } else { - pShape->set_name(""); + // Unlink self + NxReleaseControllerManager(_cm); + _ptr->userData = NULL; + _error_type = ET_released; + PhysxManager::get_global_ptr()->_scenes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::release +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxScene:: +release() { + + nassertv(_error_type == ET_ok); + + unlink(); + NxPhysicsSDK *sdk = NxGetPhysicsSDK(); + sdk->releaseScene(*_ptr); + _ptr = NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::simulate +// Access: Published +// Description: Advances the simulation by an elapsedTime time. +// The elapsed time has to be in the range (0, inf). +// +// It is not allowed to modify the physics scene in +// between the simulate(dt) and the fetch_results +// calls! But it is allowed to read from the scene +// and do additional computations, e. g. AI, in +// between these calls. +//////////////////////////////////////////////////////////////////// +void PhysxScene:: +simulate(float dt) { + + nassertv(_error_type == ET_ok); + + _pcollector_simulate.start(); + + // Update all controllers + for (NxU32 i=0; i < _cm->getNbControllers(); i++) { + NxController *controllerPtr = _cm->getController(i); + PhysxController *controller = (PhysxController *)controllerPtr->getUserData(); + controller->update(dt); + } + + _cm->updateControllers(); + + // Simulate and flush streams + _ptr->simulate(dt); + _ptr->flushStream(); + + _pcollector_simulate.stop(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::fetch_results +// Access: Published +// Description: Waits until the simulation has finished, and then +// updates the scene graph with with simulation +// results. +// +// It is not allowed to modify the physics scene in +// between the simulate(dt) and the fetch_results +// calls! But it is allowed to read from the scene +// and do additional computations, e. g. AI, in +// between these calls. +//////////////////////////////////////////////////////////////////// +void PhysxScene:: +fetch_results() { + + nassertv(_error_type == ET_ok); + + _pcollector_fetch_results.start(); + _ptr->fetchResults(NX_RIGID_BODY_FINISHED, true); + _pcollector_fetch_results.stop(); + + // Update node transforms + _pcollector_update_transforms.start(); + + NxU32 nbTransforms = 0; + NxActiveTransform *activeTransforms = _ptr->getActiveTransforms(nbTransforms); + + if (nbTransforms && activeTransforms) { + for (NxU32 i=0; iupdate_transform(m); + } } - - _shapes.push_back(pShape); } + _pcollector_update_transforms.stop(); - pActor->update_transform(); - _actors.push_back(pActor); - return pActor; + // Update debug node + _pcollector_debug_renderer.start(); + _debugNode->update(_ptr); + _pcollector_debug_renderer.stop(); + + nassertv(_ptr->isWritable()); } //////////////////////////////////////////////////////////////////// -// Function : check_results -// Access : Published -// Description : +// Function: PhysxScene::set_timing_variable +// Access: Published +// Description: Sets simulation timing parameters used in simulate. + +//////////////////////////////////////////////////////////////////// +void PhysxScene:: +set_timing_variable() { + + nassertv(_error_type == ET_ok); + _ptr->setTiming(NULL, NULL, NX_TIMESTEP_VARIABLE); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::set_timing_fixed +// Access: Published +// Description: Sets simulation timing parameters used in simulate. +// The elapsed time (parameter "dt" in simulate()) is +// internally subdivided into up to maxIter substeps +// no larger than maxTimestep. If the elapsed time is +// not a multiple of maxTimestep then any remaining +// time is accumulated to be added onto the elapsed +// time for the next time step. If more sub steps than +// maxIter are needed to advance the simulation by +// elapsed time, then the remaining time is also +// accumulated for the next call to simulate(). +// +// This timing method is strongly preferred for +// stable, reproducible simulation. +//////////////////////////////////////////////////////////////////// +void PhysxScene:: +set_timing_fixed(float maxTimestep, unsigned int maxIter) { + + nassertv(_error_type == ET_ok); + _ptr->setTiming(maxTimestep, maxIter, NX_TIMESTEP_FIXED); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::set_gravity +// Access: Published +// Description: Sets a constant gravity for the entire scene. +//////////////////////////////////////////////////////////////////// +void PhysxScene:: +set_gravity(const LVector3f &gravity) { + + nassertv(_error_type == ET_ok); + nassertv_always(!gravity.is_nan()); + + _ptr->setGravity(PhysxManager::vec3_to_nxVec3(gravity)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_gravity +// Access: Published +// Description: Retrieves the current gravity setting. +//////////////////////////////////////////////////////////////////// +LVector3f PhysxScene:: +get_gravity() const { + + nassertr(_error_type == ET_ok, LVector3f::zero()); + + NxVec3 gravity; + _ptr->getGravity(gravity); + return PhysxManager::nxVec3_to_vec3(gravity); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_num_actors +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +unsigned int PhysxScene:: +get_num_actors() const { + + nassertr(_error_type == ET_ok,-1); + + return _ptr->getNbActors(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::create_actor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxActor) PhysxScene:: +create_actor(PhysxActorDesc &desc) { + + nassertr(_error_type == ET_ok, NULL); + nassertr(desc.is_valid(),NULL); + + PT(PhysxActor) actor = new PhysxActor(); + nassertr(actor, NULL); + + NxActor *actorPtr = _ptr->createActor(desc._desc); + nassertr(actorPtr, NULL); + + actor->link(actorPtr); + + return actor; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_actor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PT(PhysxActor) PhysxScene:: +get_actor(unsigned int idx) const { + + nassertr(_error_type == ET_ok, NULL); + nassertr_always(idx < _ptr->getNbActors(), NULL); + + NxActor *actorPtr = _ptr->getActors()[idx]; + PhysxActor *actor = (PhysxActor *)(actorPtr->userData); + + return actor; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_debug_node +// Access: Published +// Description: Retrieves the debug geom node for this scene. The +// debug geom node is used to visualize information +// about the physical scene which can be useful for +// debugging an application. +// +// The debug geom node geometry is generated in global +// coordinates. In order to see correct information +// it is important not to dislocate the debug node. +// Reparent it to render and leave position at +// (0,0,0). +//////////////////////////////////////////////////////////////////// +PT(PhysxDebugGeomNode) PhysxScene:: +get_debug_geom_node() { + + nassertr(_error_type == ET_ok, NULL); + return _debugNode; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::enable_contact_reporting +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxScene:: +enable_contact_reporting(bool enabled) { + + nassertv(_error_type == ET_ok); + + if (enabled) { + _ptr->setUserContactReport(&_contact_report); + _contact_report.enable(); + } + else { + _ptr->setUserContactReport(NULL); + _contact_report.disable(); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::is_contact_reporting_enabled +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// bool PhysxScene:: -check_results(PhysxSimulationStatus status, bool block) { - nassertr(nScene != NULL, false); +is_contact_reporting_enabled() const { - return nScene->checkResults((NxSimulationStatus)status, block); + nassertr(_error_type == ET_ok, false); + + return _contact_report.is_enabled(); } //////////////////////////////////////////////////////////////////// -// Function : create_joint -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJoint *PhysxScene:: -create_joint(const PhysxJointDesc & desc) { - NxJoint *nJoint = nScene->createJoint(*(desc.nJointDesc)); - if(nJoint == NULL) { - return NULL; - } - - PhysxJoint *pJoint; - - if(nJoint->getType() == NX_JOINT_D6) { - pJoint = new PhysxD6Joint(); - ((PhysxD6Joint *)pJoint)->nD6Joint = (NxD6Joint *)nJoint; - } - nJoint->userData = pJoint; - pJoint->nJoint = nJoint; - - // Force the joint to re-store its name string, so that the pointer won't - // be invalidated when the jointDesc is destroyed. - if(nJoint->getName() != NULL) { - pJoint->set_name(nJoint->getName()); - } - - _joints.push_back(pJoint); - return pJoint; -} - -//////////////////////////////////////////////////////////////////// -// Function : create_material -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxMaterial *PhysxScene:: -create_material(const PhysxMaterialDesc & desc) { - NxMaterial *nMaterial = nScene->createMaterial(desc.nMaterialDesc); - if(nMaterial == NULL) { - return NULL; - } - - PhysxMaterial *pMaterial = new PhysxMaterial(); - pMaterial->nMaterial = nMaterial; - nMaterial->userData = pMaterial; - - return pMaterial; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_contact_reporting_enabled -// Access : Published -// Description : +// Function: PhysxScene::enable_trigger_reporting +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// void PhysxScene:: -set_contact_reporting_enabled(bool enabled) { - contact_reporting_enabled = enabled; - if(enabled) { - nScene->setUserContactReport(&contact_handler); - } else { - nScene->setUserContactReport(NULL); +enable_trigger_reporting(bool enabled) { + + nassertv(_error_type == ET_ok); + + if (enabled) { + _ptr->setUserTriggerReport(&_trigger_report); + _trigger_report.enable(); + } + else { + _ptr->setUserTriggerReport(NULL); + _trigger_report.disable(); } } //////////////////////////////////////////////////////////////////// -// Function : is_contact_reporting_enabled -// Access : Published -// Description : +// Function: PhysxScene::is_trigger_reporting_enabled +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// bool PhysxScene:: -is_contact_reporting_enabled() { - return contact_reporting_enabled; +is_trigger_reporting_enabled() const { + + nassertr(_error_type == ET_ok, false); + + return _trigger_report.is_enabled(); } //////////////////////////////////////////////////////////////////// -// Function : set_trigger_reporting_enabled -// Access : Published -// Description : +// Function: PhysxScene::enable_controller_reporting +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// void PhysxScene:: -set_trigger_reporting_enabled(bool enabled) { - trigger_reporting_enabled = enabled; - if(enabled) { - nScene->setUserTriggerReport(&trigger_handler); - } else { - nScene->setUserTriggerReport(NULL); +enable_controller_reporting(bool enabled) { + + nassertv(_error_type == ET_ok); + + if (enabled) { + _controller_report.enable(); + } + else { + _controller_report.disable(); } } //////////////////////////////////////////////////////////////////// -// Function : is_trigger_reporting_enabled -// Access : Published -// Description : +// Function: PhysxScene::is_controller_reporting_enabled +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// bool PhysxScene:: -is_trigger_reporting_enabled() { - return trigger_reporting_enabled; +is_controller_reporting_enabled() const { + + nassertr(_error_type == ET_ok, false); + + return _controller_report.is_enabled(); } //////////////////////////////////////////////////////////////////// -// Function : set_joint_reporting_enabled -// Access : Published -// Description : +// Function: PhysxScene::get_num_materials +// Access: Published +// Description: Return the number of materials in the scene. +// +// Note that the returned value is not related to +// material indices. Those may not be allocated +// continuously, and its values may be higher than +// get_num_materials(). This will also include the +// default material which exists without having to +// be created. //////////////////////////////////////////////////////////////////// -void PhysxScene:: -set_joint_reporting_enabled(bool enabled) { - joint_reporting_enabled = enabled; - if(enabled) { - nScene->setUserNotify(&joint_handler); - } else { - nScene->setUserNotify(NULL); +unsigned int PhysxScene:: +get_num_materials() const { + + nassertr(_error_type == ET_ok, -1); + return _ptr->getNbMaterials(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::create_material +// Access: Published +// Description: Creates a new PhysxMaterial. +// +// The material library consists of an array of +// material objects. Each material has a well defined +// index that can be used to refer to it. If an object +// references an undefined material, the default +// material with index 0 is used instead. +//////////////////////////////////////////////////////////////////// +PT(PhysxMaterial) PhysxScene:: +create_material(PhysxMaterialDesc &desc) { + + nassertr(_error_type == ET_ok, NULL); + nassertr(desc.is_valid(),NULL); + + PT(PhysxMaterial) material = new PhysxMaterial(); + nassertr(material, NULL); + + NxMaterial *materialPtr = _ptr->createMaterial(desc._desc); + nassertr(materialPtr, NULL); + + material->link(materialPtr); + + return material; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::create_material +// Access: Published +// Description: Creates a new PhysxMaterial using the default +// settings of PhysxMaterialDesc. +//////////////////////////////////////////////////////////////////// +PT(PhysxMaterial) PhysxScene:: +create_material() { + + nassertr(_error_type == ET_ok, NULL); + + PT(PhysxMaterial) material = new PhysxMaterial(); + nassertr(material, NULL); + + NxMaterialDesc desc; + desc.setToDefault(); + NxMaterial *materialPtr = _ptr->createMaterial(desc); + nassertr(materialPtr, NULL); + + material->link(materialPtr); + + return material; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_hightest_material_index +// Access: Published +// Description: Returns current highest valid material index. +// +// Note that not all indices below this are valid if +// some of them belong to meshes that have beed +// freed. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxScene:: +get_hightest_material_index() const { + + nassertr(_error_type == ET_ok, -1); + return _ptr->getHighestMaterialIndex(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_material_from_index +// Access: Published +// Description: Retrieves the material with the given material +// index. +// +// There is always at least one material in the Scene, +// the default material (index 0). If the specified +// material index is out of range (larger than +// get_hightest_material_index) or belongs to a +// material that has been released, then the default +// material is returned, but no error is reported. +//////////////////////////////////////////////////////////////////// +PT(PhysxMaterial) PhysxScene:: +get_material_from_index(unsigned int idx) const { + + nassertr(_error_type == ET_ok, NULL); + + NxMaterial *materialPtr = _ptr->getMaterialFromIndex(idx); + + return (PhysxMaterial *)(materialPtr->userData); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_material +// Access: Published +// Description: Retrieves the n-th material from the array of +// materials. See also get_material_from_index, +// which retrieves a material by it's material index. +//////////////////////////////////////////////////////////////////// +PT(PhysxMaterial) PhysxScene:: +get_material(unsigned int idx) const { + + nassertr(_error_type == ET_ok, NULL); + nassertr_always(idx < _ptr->getNbMaterials(), NULL); + + NxU32 n = _ptr->getNbMaterials(); + NxMaterial **materials = new NxMaterial *[n]; + NxU32 materialCount; + NxU32 iterator = 0; + + materialCount = _ptr->getMaterialArray(materials, n, iterator); + nassertr((materialCount == n), NULL); + + NxMaterial *materialPtr = materials[idx]; + delete[] materials; + + return (PhysxMaterial *)(materialPtr->userData); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_num_controllers +// Access: Published +// Description: Return the number of controllers in the scene. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxScene:: +get_num_controllers() const { + + nassertr(_error_type == ET_ok, -1); + return _cm->getNbControllers(); +} + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::create_controller +// Access: Published +// Description: Creates a new character controller. +//////////////////////////////////////////////////////////////////// +PT(PhysxController) PhysxScene:: +create_controller(PhysxControllerDesc &desc) { + + nassertr(_error_type == ET_ok, NULL); + nassertr(desc.is_valid(),NULL); + + PT(PhysxController) controller = PhysxController::factory(desc.ptr()->getType()); + nassertr(controller, NULL); + + desc.ptr()->callback = &_controller_report; + desc.ptr()->userData = controller; + + NxController *controllerPtr = _cm->createController(_ptr,*desc.ptr()); + nassertr(controllerPtr, NULL); + + controller->link(controllerPtr); + controllerPtr->getActor()->setName(""); + + return controller; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_controller +// Access: Published +// Description: Retrieves the n-th controller within the scene. +//////////////////////////////////////////////////////////////////// +PT(PhysxController) PhysxScene:: +get_controller(unsigned int idx) const { + + nassertr(_error_type == ET_ok, NULL); + nassertr_always(idx < _cm->getNbControllers(), NULL); + + NxController *controllerPtr = _cm->getController(idx); + PhysxController *controller = (PhysxController *)(controllerPtr->getUserData()); + + return controller; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_num_joints +// Access: Published +// Description: Returns the number of joints in the scene +// (excluding "dead" joints). Note that this includes +// compartments. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxScene:: +get_num_joints() const { + + nassertr(_error_type == ET_ok, -1); + return _ptr->getNbJoints(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::create_joint +// Access: Published +// Description: Creates a joint in this scene. +//////////////////////////////////////////////////////////////////// +PT(PhysxJoint) PhysxScene:: +create_joint(PhysxJointDesc &desc) { + + nassertr(_error_type == ET_ok, NULL); + nassertr(desc.is_valid(),NULL); + + PT(PhysxJoint) joint = PhysxJoint::factory(desc.ptr()->getType()); + nassertr(joint, NULL); + + NxJoint *jointPtr = _ptr->createJoint(*desc.ptr()); + nassertr(jointPtr, NULL); + + joint->link(jointPtr); + + return joint; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_joint +// Access: Published +// Description: Retrieve the n-th joint from the array of all the +// joints in the scene. +//////////////////////////////////////////////////////////////////// +PT(PhysxJoint) PhysxScene:: +get_joint(unsigned int idx) const { + + nassertr(_error_type == ET_ok, NULL); + nassertr_always(idx < _ptr->getNbJoints(), NULL); + + NxJoint *jointPtr; + NxU32 nJoints = _ptr->getNbJoints(); + + _ptr->resetJointIterator(); + for (NxU32 i=0; i <= idx; i++) { + jointPtr = _ptr->getNextJoint(); } + + return (PhysxJoint *)(jointPtr->userData); } //////////////////////////////////////////////////////////////////// -// Function : is_joint_reporting_enabled -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxScene:: -is_joint_reporting_enabled() { - return joint_reporting_enabled; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_contact_reporting_threshold -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -set_contact_reporting_threshold(float threshold) { - contact_handler.set_threshold(threshold); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_contact_reporting_threshold -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxScene:: -get_contact_reporting_threshold() { - return contact_handler.get_threshold(); -} - -//////////////////////////////////////////////////////////////////// -// Function : flush_caches -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -flush_caches() { - nassertv(nScene != NULL); - - nScene->flushCaches(); -} - -//////////////////////////////////////////////////////////////////// -// Function : flush_stream -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -flush_stream() { - nassertv(nScene != NULL); - - PStatTimer timer(_flush_stream_pcollector); - nScene->flushStream(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_actor_group_pair_flags -// Access : Published -// Description : +// Function: PhysxScene::get_num_force_fields +// Access: Published +// Description: Gets the number of force fields in the scene. //////////////////////////////////////////////////////////////////// unsigned int PhysxScene:: -get_actor_group_pair_flags(unsigned short group1, unsigned short group2) const { - nassertr(nScene != NULL, -1); +get_num_force_fields() const { - return nScene->getActorGroupPairFlags(group1, group2); + nassertr(_error_type == ET_ok, -1); + return _ptr->getNbForceFields(); } //////////////////////////////////////////////////////////////////// -// Function : get_actor_pair_flags -// Access : Published -// Description : +// Function: PhysxScene::create_force_field +// Access: Published +// Description: Creates a force field in this scene. +//////////////////////////////////////////////////////////////////// +PT(PhysxForceField) PhysxScene:: +create_force_field(PhysxForceFieldDesc &desc) { + + nassertr(_error_type == ET_ok, NULL); + + // Create the kernel + desc.create_kernel(_ptr); + nassertr(desc.is_valid(),NULL); + + // Create the force field + PT(PhysxForceField) field = new PhysxForceField(); + nassertr(field, NULL); + + NxForceField *fieldPtr = _ptr->createForceField(desc._desc); + nassertr(fieldPtr, NULL); + + field->link(fieldPtr); + + return field; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_force_field +// Access: Published +// Description: Returns the n-th force field from the array of +// all the force fields in the scene. +//////////////////////////////////////////////////////////////////// +PT(PhysxForceField) PhysxScene:: +get_force_field(unsigned int idx) const { + + nassertr(_error_type == ET_ok, NULL); + nassertr_always(idx < _ptr->getNbForceFields(), NULL); + + NxForceField **fields = _ptr->getForceFields(); + NxForceField *fieldPtr = fields[idx]; + + return (PhysxForceField *)(fieldPtr->userData); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_num_force_field_shape_groups +// Access: Published +// Description: Gets the number of force field shape groups in +// the scene. //////////////////////////////////////////////////////////////////// unsigned int PhysxScene:: -get_actor_pair_flags(PhysxActorNode & actor_a, PhysxActorNode & actor_b) const { - nassertr(nScene != NULL, -1); +get_num_force_field_shape_groups() const { - return nScene->getActorPairFlags(*(actor_a.nActor), *(actor_b.nActor)); + nassertr(_error_type == ET_ok, -1); + return _ptr->getNbForceFieldShapeGroups(); } //////////////////////////////////////////////////////////////////// -// Function : get_bound_for_island_size -// Access : Published -// Description : +// Function: PhysxScene::create_force_field_shape_group +// Access: Published +// Description: Creates a new force field shape group in this +// scene. //////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_bound_for_island_size(PhysxActorNode & actor) { - nassertr(nScene != NULL, -1); +PT(PhysxForceFieldShapeGroup) PhysxScene:: +create_force_field_shape_group(PhysxForceFieldShapeGroupDesc &desc) { - return nScene->getBoundForIslandSize(*(actor.nActor)); + nassertr(_error_type == ET_ok, NULL); + + PT(PhysxForceFieldShapeGroup) group = new PhysxForceFieldShapeGroup(); + nassertr(group, NULL); + + NxForceFieldShapeGroup *groupPtr = _ptr->createForceFieldShapeGroup(desc._desc); + nassertr(groupPtr, NULL); + + group->link(groupPtr); + + return group; } //////////////////////////////////////////////////////////////////// -// Function : get_filter_bool -// Access : Published -// Description : +// Function: PhysxScene::get_force_field_shape_group +// Access: Published +// Description: Returns the n-th force field shape group in this +// scene //////////////////////////////////////////////////////////////////// -bool PhysxScene:: -get_filter_bool() const { - nassertr(nScene != NULL, false); +PT(PhysxForceFieldShapeGroup) PhysxScene:: +get_force_field_shape_group(unsigned int idx) const { - return nScene->getFilterBool(); + nassertr(_error_type == ET_ok, NULL); + nassertr_always(idx < _ptr->getNbForceFieldShapeGroups(), NULL); + + _ptr->resetForceFieldShapeGroupsIterator(); + NxForceFieldShapeGroup *groupPtr = NULL; + idx++; + while (idx-- > 0) { + groupPtr = _ptr->getNextForceFieldShapeGroup(); + } + + return groupPtr ? (PhysxForceFieldShapeGroup *)groupPtr->userData : NULL; } //////////////////////////////////////////////////////////////////// -// Function : get_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_flags() const { - nassertr(nScene != NULL, -1); - - return nScene->getFlags(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_gravity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -get_gravity(LVecBase3f & vec) { - nassertv(nScene != NULL); - - nScene->getGravity(PhysxManager::lVecBase3_to_nxVec3(vec)); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_group_collision_flag -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxScene:: -get_group_collision_flag(unsigned short group1, unsigned short group2) const { - nassertr(nScene != NULL, false); - - return nScene->getGroupCollisionFlag(group1, group2); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_highest_material_index -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned short PhysxScene:: -get_highest_material_index() const { - nassertr(nScene != NULL, -1); - - return nScene->getHighestMaterialIndex(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_material_from_index -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxMaterial * PhysxScene:: -get_material_from_index(unsigned short mat_index) { - nassertr(nScene != NULL, NULL); - - return (PhysxMaterial *)(nScene->getMaterialFromIndex(mat_index)->userData); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_max_cpu_for_load_balancing -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxScene:: -get_max_cpu_for_load_balancing() { - nassertr(nScene != NULL, -1.0f); - - return nScene->getMaxCPUForLoadBalancing(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_actor_group_pairs -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_actor_group_pairs() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbActorGroupPairs(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_actors -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_actors() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbActors(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_cloths -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_cloths() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbCloths(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_compartments -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_compartments() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbCompartments(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_dynamic_shapes -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_dynamic_shapes() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbDynamicShapes(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_effectors -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_effectors() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbEffectors(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_fluids -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_fluids() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbFluids(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_force_fields -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_force_fields() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbForceFields(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_implicit_screen_meshes -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_implicit_screen_meshes() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbImplicitScreenMeshes(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_joints -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_joints() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbJoints(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_materials -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_materials() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbMaterials(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_pairs -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_pairs() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbPairs(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_soft_bodies -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_soft_bodies() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbSoftBodies(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_nb_static_shapes -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_nb_static_shapes() const { - nassertr(nScene != NULL, -1); - - return nScene->getNbStaticShapes(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_next_joint -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxJoint * PhysxScene:: -get_next_joint() { - nassertr(nScene != NULL, NULL); - - return (PhysxJoint *)(nScene->getNextJoint()->userData); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_shape_pair_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_shape_pair_flags(PhysxShape & shape_a, PhysxShape & shape_b) const { - nassertr(nScene != NULL, -1); - - return nScene->getShapePairFlags(*(shape_a.nShape), *(shape_b.nShape)); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_sim_type -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxSimulationType PhysxScene:: -get_sim_type() const { - return (PhysxSimulationType)nScene->getSimType(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_stats2 -// Access : Published -// Description : +// Function: PhysxScene::get_stats2 +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// PhysxSceneStats2 PhysxScene:: get_stats2() const { - return PhysxSceneStats2(nScene->getStats2()); + + nassertr(_error_type == ET_ok, NULL); + return PhysxSceneStats2(_ptr->getStats2()); } //////////////////////////////////////////////////////////////////// -// Function : get_timing -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -get_timing(float & max_timestep, unsigned int & max_iter, PhysxTimeStepMethod & method, unsigned int * num_sub_steps) const { - nassertv(nScene != NULL); - - nScene->getTiming(max_timestep, max_iter, (NxTimeStepMethod &)method, num_sub_steps); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_total_nb_shapes -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxScene:: -get_total_nb_shapes() const { - nassertr(nScene != NULL, -1); - - return nScene->getTotalNbShapes(); -} - -//////////////////////////////////////////////////////////////////// -// Function : is_writable -// Access : Published -// Description : +// Function: PhysxScene::raycast_any_shape +// Access: Published +// Description: Returns true if any shape is intersected by the +// ray. //////////////////////////////////////////////////////////////////// bool PhysxScene:: -is_writable() { - nassertr(nScene != NULL, false); +raycast_any_shape(const PhysxRay &ray, + PhysxShapesType shapesType, + PhysxMask mask, + PhysxGroupsMask *groups) const { - return nScene->isWritable(); + nassertr(_error_type == ET_ok, false); + + NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL; + + return _ptr->raycastAnyShape(ray._ray, (NxShapesType)shapesType, + mask.get_mask(), ray._length, groupsPtr); } //////////////////////////////////////////////////////////////////// -// Function : lock_queries -// Access : Published -// Description : +// Function: PhysxScene::raycast_closest_shape +// Access: Published +// Description: Returns the first shape that is hit along the ray. +// If not shape is hit then an empty raycast hit +// is returned (is_empty() == true). //////////////////////////////////////////////////////////////////// -void PhysxScene:: -lock_queries() { - nassertv(nScene != NULL); +PhysxRaycastHit PhysxScene:: +raycast_closest_shape(const PhysxRay &ray, + PhysxShapesType shapesType, + PhysxMask mask, + PhysxGroupsMask *groups, bool smoothNormal) const { - nScene->lockQueries(); -} + NxRaycastHit hit; -//////////////////////////////////////////////////////////////////// -// Function : poll_for_background_work -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxThreadPollResult PhysxScene:: -poll_for_background_work(PhysxThreadWait wait_type) { - return (PhysxThreadPollResult)nScene->pollForBackgroundWork((NxThreadWait)wait_type); -} + nassertr(_error_type == ET_ok, hit); -//////////////////////////////////////////////////////////////////// -// Function : poll_for_work -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxThreadPollResult PhysxScene:: -poll_for_work(PhysxThreadWait wait_type) { - return (PhysxThreadPollResult)nScene->pollForWork((NxThreadWait)wait_type); -} + NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL; -//////////////////////////////////////////////////////////////////// -// Function : release_actor -// Access : Published -// Description : Releases the PhysxActorNode from the PhysX engine and -// removes it from the Panda scene graph. The -// PhysxActorNode is thereafter dead to the PhysX engine -// and should be discarded by the application code. -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -release_actor(PhysxActorNode & pActor) { - nassertv(nScene != NULL); - - if(pActor.nActor == NULL) { - physx_warning( "release_actor: " << pActor.get_name() << ": unable to release actor; NxActor is already NULL" ); - } else { - physx_debug( "release_actor: " << pActor.get_name() << ", " << &pActor ); - // Remove contained shapes from _shapes. - unsigned int numShapes = pActor.nActor->getNbShapes(); - NxShape * const* shapes = pActor.nActor->getShapes(); - for(unsigned int i = 0; i < numShapes; ++i ) { - NxShape *nShape = shapes[i]; - PT(PhysxShape) pShape = (PhysxShape *)(nShape->userData); - pvector::iterator found; - found = find(_shapes.begin(), _shapes.end(), pShape); - if (found != _shapes.end()) { - _shapes.erase(found); - } - pShape->nShape->userData = NULL; - pShape->nShape = NULL; - } - - // Set back reference pointer to NULL - pActor.nActor->userData = NULL; - - // Remove pActor from _actors. - pvector::iterator found; - found = find(_actors.begin(), _actors.end(), &pActor); - if (found != _actors.end()) { - _actors.erase(found); - } - - // Release the NxActor - nScene->releaseActor(*(pActor.nActor)); - pActor.nActor = NULL; - - // Remove any Panda children - pActor.remove_all_children(); - while(pActor.get_num_parents() > 0) { - pActor.get_parent(0)->remove_child(&pActor); - } + NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE; + if (smoothNormal == true) { + hints |= NX_RAYCAST_NORMAL; } -} - -//////////////////////////////////////////////////////////////////// -// Function : release_joint -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -release_joint(PhysxJoint & pJoint) { - nassertv(nScene != NULL); - - if(pJoint.nJoint == NULL) { - physx_warning( "release_joint: unable to release joint; NxJoint is already NULL" ); - } else { - pvector::iterator found; - found = find(_joints.begin(), _joints.end(), &pJoint); - if (found != _joints.end()) { - _joints.erase(found); - } - nScene->releaseJoint(*(pJoint.nJoint)); - pJoint.nJoint = NULL; + else { + hints |= NX_RAYCAST_FACE_NORMAL; } + + _ptr->raycastClosestShape(ray._ray, (NxShapesType)shapesType, hit, + mask.get_mask(), ray._length, hints); + + + return PhysxRaycastHit(hit); } //////////////////////////////////////////////////////////////////// -// Function : release_material -// Access : Published -// Description : +// Function: PhysxScene::raycast_all_shapes +// Access: Published +// Description: Returns a PhysxRaycastReport object which can be +// used to iterate over all shapes that have been +// hit by the ray. //////////////////////////////////////////////////////////////////// -void PhysxScene:: -release_material(PhysxMaterial & pMaterial) { - nassertv(nScene != NULL); +PhysxRaycastReport PhysxScene:: +raycast_all_shapes(const PhysxRay &ray, + PhysxShapesType shapesType, + PhysxMask mask, + PhysxGroupsMask *groups, bool smoothNormal) const { - if(pMaterial.nMaterial == NULL) { - physx_warning( "release_material: unable to release material; NxMaterial is already NULL" ); - } else { - nScene->releaseMaterial(*(pMaterial.nMaterial)); - pMaterial.nMaterial = NULL; + PhysxRaycastReport report; + + nassertr(_error_type == ET_ok, report); + + NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL; + + NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE; + if (smoothNormal == true) { + hints |= NX_RAYCAST_NORMAL; } + else { + hints |= NX_RAYCAST_FACE_NORMAL; + } + + _ptr->raycastAllShapes(ray._ray, report, (NxShapesType)shapesType, + mask.get_mask(), ray._length, hints); + + return report; } //////////////////////////////////////////////////////////////////// -// Function : reset_effector_iterator -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -reset_effector_iterator() { - nassertv(nScene != NULL); - - nScene->resetEffectorIterator(); -} - -//////////////////////////////////////////////////////////////////// -// Function : reset_joint_iterator -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -reset_joint_iterator() { - nassertv(nScene != NULL); - - nScene->resetJointIterator(); -} - -//////////////////////////////////////////////////////////////////// -// Function : reset_poll_for_work -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -reset_poll_for_work() { - nassertv(nScene != NULL); - - nScene->resetPollForWork(); -} - -//////////////////////////////////////////////////////////////////// -// Function : save_to_desc -// Access : Published -// Description : +// Function: PhysxScene::raycast_any_bounds +// Access: Published +// Description: Returns true if any axis aligned bounding box +// enclosing a shape is intersected by the ray. //////////////////////////////////////////////////////////////////// bool PhysxScene:: -save_to_desc(PhysxSceneDesc & desc) const { - nassertr(nScene != NULL, false); +raycast_any_bounds(const PhysxRay &ray, + PhysxShapesType shapesType, + PhysxMask mask, + PhysxGroupsMask *groups) const { - return nScene->saveToDesc(desc.nSceneDesc); + nassertr(_error_type == ET_ok, false); + + NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL; + + return _ptr->raycastAnyBounds(ray._ray, (NxShapesType)shapesType, + mask.get_mask(), ray._length, groupsPtr); } //////////////////////////////////////////////////////////////////// -// Function : set_actor_group_pair_flags -// Access : Published -// Description : +// Function: PhysxScene::raycast_closest_bounds +// Access: Published +// Description: Returns the first axis aligned bounding box +// enclosing a shape that is hit along the ray. +// If not shape is hit then an empty raycast hit +// is returned (is_empty() == true). +//////////////////////////////////////////////////////////////////// +PhysxRaycastHit PhysxScene:: +raycast_closest_bounds(const PhysxRay &ray, PhysxShapesType shapesType, PhysxMask mask, PhysxGroupsMask *groups, bool smoothNormal) const { + + NxRaycastHit hit; + + nassertr(_error_type == ET_ok, hit); + + NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL; + + NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE; + if (smoothNormal == true) { + hints |= NX_RAYCAST_NORMAL; + } + else { + hints |= NX_RAYCAST_FACE_NORMAL; + } + + _ptr->raycastClosestBounds(ray._ray, (NxShapesType)shapesType, hit, + mask.get_mask(), ray._length, hints); + + + return PhysxRaycastHit(hit); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::raycast_all_bounds +// Access: Published +// Description: Returns a PhysxRaycastReport object which can be +// used to iterate over all shapes that have been +// enclosed by axis aligned bounding boxes hit by +// the ray. +//////////////////////////////////////////////////////////////////// +PhysxRaycastReport PhysxScene:: +raycast_all_bounds(const PhysxRay &ray, + PhysxShapesType shapesType, + PhysxMask mask, + PhysxGroupsMask *groups, bool smoothNormal) const { + + PhysxRaycastReport report; + + nassertr(_error_type == ET_ok, report); + + NxGroupsMask *groupsPtr = groups ? &(groups->_mask) : NULL; + + NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE; + if (smoothNormal == true) { + hints |= NX_RAYCAST_NORMAL; + } + else { + hints |= NX_RAYCAST_FACE_NORMAL; + } + + _ptr->raycastAllBounds(ray._ray, report, (NxShapesType)shapesType, + mask.get_mask(), ray._length, hints); + + return report; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::overlap_sphere_shapes +// Access: Published +// Description: Returns the set of shapes overlapped by the +// world-space sphere. +// You can test against static and/or dynamic objects +// by adjusting 'shapeType'. +//////////////////////////////////////////////////////////////////// +PhysxOverlapReport PhysxScene:: +overlap_sphere_shapes(const LPoint3f ¢er, float radius, + PhysxShapesType shapesType, + PhysxMask mask, bool accurateCollision) const { + + PhysxOverlapReport report; + + nassertr(_error_type == ET_ok, report); + + NxSphere worldSphere(PhysxManager::point3_to_nxVec3(center), radius); + + _ptr->overlapSphereShapes(worldSphere, (NxShapesType)shapesType, 0, NULL, &report, + mask.get_mask(), NULL, accurateCollision); + + return report; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::overlap_capsule_shapes +// Access: Published +// Description: Returns the set of shapes overlapped by the +// world-space capsule. +// You can test against static and/or dynamic objects +// by adjusting 'shapeType'. +//////////////////////////////////////////////////////////////////// +PhysxOverlapReport PhysxScene:: +overlap_capsule_shapes(const LPoint3f &p0, const LPoint3f &p1, float radius, + PhysxShapesType shapesType, + PhysxMask mask, bool accurateCollision) const { + + PhysxOverlapReport report; + + nassertr(_error_type == ET_ok, report); + + NxSegment segment(PhysxManager::point3_to_nxVec3(p0), + PhysxManager::point3_to_nxVec3(p1)); + NxCapsule worldCapsule(segment, radius); + + _ptr->overlapCapsuleShapes(worldCapsule, (NxShapesType)shapesType, 0, NULL, &report, + mask.get_mask(), NULL, accurateCollision); + + return report; +} + + + + + + + + + + +//################################ + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::set_actor_pair_flag +// Access: Published +// Description: Sets the pair flags for the given pair of actors. +// +// Calling this on an actor that has no shape(s) has +// no effect. The two actor references must not +// reference the same actor. +// +// It is important to note that the engine stores +// pair flags per shape, even for actor pair flags. +// This means that shapes should be created before +// actor pair flags are set, otherwise the pair flags +// will be ignored. //////////////////////////////////////////////////////////////////// void PhysxScene:: -set_actor_group_pair_flags(unsigned short group1, unsigned short group2, unsigned int flags) { - nassertv(nScene != NULL); +set_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, + PhysxContactPairFlag flag, bool value) { - nScene->setActorGroupPairFlags(group1, group2, flags); + nassertv(_error_type == ET_ok); + + NxActor *ptrA = actorA.ptr(); + NxActor *ptrB = actorB.ptr(); + NxU32 flags = _ptr->getActorPairFlags(*ptrA, *ptrB); + + if (value == true) { + flags |= flag; + } + else { + flags &= ~(flag); + } + + _ptr->setActorPairFlags(*ptrA, *ptrB, flags); } //////////////////////////////////////////////////////////////////// -// Function : set_actor_pair_flags -// Access : Published -// Description : +// Function: PhysxScene::get_actor_pair_flag +// Access: Published +// Description: Retrieves a single flag for the given pair of +// actors. +// +// The two actor references must not reference the +// same actor. +//////////////////////////////////////////////////////////////////// +bool PhysxScene:: +get_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, + PhysxContactPairFlag flag) { + + nassertr(_error_type == ET_ok, false); + + NxActor *ptrA = actorA.ptr(); + NxActor *ptrB = actorB.ptr(); + NxU32 flags = _ptr->getActorPairFlags(*ptrA, *ptrB); + + return (flags && flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::set_shape_pair_flag +// Access: Published +// Description: Disables or enables contact generation for a pair +// of shapes. +// +// The two shape references must not reference the +// same shape. //////////////////////////////////////////////////////////////////// void PhysxScene:: -set_actor_pair_flags(PhysxActorNode & actor_a, PhysxActorNode & actor_b, unsigned int nx_contact_pair_flag) { - nassertv(nScene != NULL); +set_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB, bool value) { - nScene->setActorPairFlags(*(actor_a.nActor), *(actor_b.nActor), nx_contact_pair_flag); + nassertv(_error_type == ET_ok); + + NxShape *ptrA = shapeA.ptr(); + NxShape *ptrB = shapeB.ptr(); + NxU32 flags = _ptr->getShapePairFlags(*ptrA, *ptrB); + + if (value == true) { + flags |= NX_IGNORE_PAIR; + } + else { + flags &= ~(NX_IGNORE_PAIR); + } + + _ptr->setShapePairFlags(*ptrA, *ptrB, flags); } //////////////////////////////////////////////////////////////////// -// Function : set_filter_bool -// Access : Published -// Description : +// Function: PhysxScene::get_shape_pair_flag +// Access: Published +// Description: Returns /true/ if contact generation between a pair +// of shapes is enabled, and /false/ if contact +// generation is disables. +// +// The two shape references must not reference the +// same shape. +//////////////////////////////////////////////////////////////////// +bool PhysxScene:: +get_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB) { + + nassertr(_error_type == ET_ok, false); + + NxShape *ptrA = shapeA.ptr(); + NxShape *ptrB = shapeB.ptr(); + NxU32 flags = _ptr->getShapePairFlags(*ptrA, *ptrB); + + return (flags && NX_IGNORE_PAIR) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::set_actor_group_pair_flag +// Access: Published +// Description: With this method one can set contact reporting +// flags between actors belonging to a pair of groups. +// +// It is possible to assign each actor to a group +// using PhysxActor::set_group(). This is a different +// set of groups from the shape groups despite the +// similar name. Here up to 0xffff different groups +// are permitted, With this method one can set +// contact reporting flags between actors belonging +// to a pair of groups. +// +// The following flags are permitted: +// - CPF_start_touch +// - CPF_end_touch +// - CPF_touch +// - CPF_start_touch_treshold +// - CPF_end_touch_treshold +// - CPF_touch_treshold +// +// Note that finer grain control of pairwise flags is +// possible using the function +// PhysxScene::set_actor_pair_flags(). //////////////////////////////////////////////////////////////////// void PhysxScene:: -set_filter_bool(bool flag) { - nassertv(nScene != NULL); +set_actor_group_pair_flag(unsigned int g1, unsigned int g2, + PhysxContactPairFlag flag, bool value) { - nScene->setFilterBool(flag); + nassertv(_error_type == ET_ok); + + NxU32 flags = _ptr->getActorGroupPairFlags(g1, g2); + if (value == true) { + flags |= flag; + } + else { + flags &= ~(flag); + } + _ptr->setActorGroupPairFlags(g1, g2, flags); } //////////////////////////////////////////////////////////////////// -// Function : set_filter_ops -// Access : Published -// Description : +// Function: PhysxScene::get_actor_group_pair_flag +// Access: Published +// Description: Retrieves a single flag set with +// PhysxScene::set_actor_group_pair_flag() +//////////////////////////////////////////////////////////////////// +bool PhysxScene:: +get_actor_group_pair_flag(unsigned int g1, unsigned int g2, + PhysxContactPairFlag flag) { + + nassertr(_error_type == ET_ok, false); + NxU32 flags = _ptr->getActorGroupPairFlags(g1, g2); + return (flags && flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::set_filter_ops +// Access: Published +// Description: Setups filtering operations. //////////////////////////////////////////////////////////////////// void PhysxScene:: set_filter_ops(PhysxFilterOp op0, PhysxFilterOp op1, PhysxFilterOp op2) { - nassertv(nScene != NULL); - nScene->setFilterOps((NxFilterOp)op0, (NxFilterOp)op1, (NxFilterOp)op2); + nassertv(_error_type == ET_ok); + _ptr->setFilterOps((NxFilterOp)op0, (NxFilterOp)op1, (NxFilterOp)op2); } //////////////////////////////////////////////////////////////////// -// Function : set_gravity -// Access : Published -// Description : +// Function: PhysxScene::set_filter_bool +// Access: Published +// Description: Setups filtering's boolean value. //////////////////////////////////////////////////////////////////// void PhysxScene:: -set_gravity(const LVecBase3f & vec) { - nassertv(nScene != NULL); +set_filter_bool(bool flag) { - nScene->setGravity(PhysxManager::lVecBase3_to_nxVec3(vec)); + nassertv(_error_type == ET_ok); + _ptr->setFilterBool(flag); } //////////////////////////////////////////////////////////////////// -// Function : set_group_collision_flag -// Access : Published -// Description : +// Function: PhysxScene::set_filter_constant0 +// Access: Published +// Description: Setups filtering's K0 value. //////////////////////////////////////////////////////////////////// void PhysxScene:: -set_group_collision_flag(unsigned short group1, unsigned short group2, bool enable) { - nassertv(nScene != NULL); +set_filter_constant0(const PhysxGroupsMask &mask) { - nScene->setGroupCollisionFlag(group1, group2, enable); + nassertv(_error_type == ET_ok); + _ptr->setFilterConstant0(mask.get_mask()); } //////////////////////////////////////////////////////////////////// -// Function : set_max_cpu_for_load_balancing -// Access : Published -// Description : +// Function: PhysxScene::set_filter_constant1 +// Access: Published +// Description: Setups filtering's K1 value. //////////////////////////////////////////////////////////////////// void PhysxScene:: -set_max_cpu_for_load_balancing(float cpu_fraction) { - nassertv(nScene != NULL); +set_filter_constant1(const PhysxGroupsMask &mask) { - nScene->setMaxCPUForLoadBalancing(cpu_fraction); + nassertv(_error_type == ET_ok); + _ptr->setFilterConstant1(mask.get_mask()); } //////////////////////////////////////////////////////////////////// -// Function : set_shape_pair_flags -// Access : Published -// Description : +// Function: PhysxScene::get_filter_bool +// Access: Published +// Description: Retrieves filtering's boolean value. +//////////////////////////////////////////////////////////////////// +bool PhysxScene:: +get_filter_bool() const { + + nassertr(_error_type == ET_ok, false); + return _ptr->getFilterBool(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_filter_constant0 +// Access: Published +// Description: Gets filtering constant K0. +//////////////////////////////////////////////////////////////////// +PhysxGroupsMask PhysxScene:: +get_filter_constant0() const { + + PhysxGroupsMask mask; + + nassertr(_error_type == ET_ok, mask); + + NxGroupsMask _mask = ptr()->getFilterConstant0(); + mask.set_mask(_mask); + + return mask; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_filter_constant1 +// Access: Published +// Description: Gets filtering constant K1. +//////////////////////////////////////////////////////////////////// +PhysxGroupsMask PhysxScene:: +get_filter_constant1() const { + + PhysxGroupsMask mask; + + nassertr(_error_type == ET_ok, mask); + + NxGroupsMask _mask = ptr()->getFilterConstant1(); + mask.set_mask(_mask); + + return mask; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_filter_op0 +// Access: Published +// Description: Retrieves the op0 filtering operation. +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxFilterOp PhysxScene:: +get_filter_op0() const { + + nassertr(_error_type == ET_ok, FO_and); + + NxFilterOp op0; + NxFilterOp op1; + NxFilterOp op2; + + _ptr->getFilterOps(op0, op1, op2); + + return (PhysxFilterOp)op0; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_filter_op1 +// Access: Published +// Description: Retrieves the op1 filtering operation. +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxFilterOp PhysxScene:: +get_filter_op1() const { + + nassertr(_error_type == ET_ok, FO_and); + + NxFilterOp op0; + NxFilterOp op1; + NxFilterOp op2; + + _ptr->getFilterOps(op0, op1, op2); + + return (PhysxFilterOp)op1; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_filter_op2 +// Access: Published +// Description: Retrieves the op2 filtering operation. +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxFilterOp PhysxScene:: +get_filter_op2() const { + + nassertr(_error_type == ET_ok, FO_and); + + NxFilterOp op0; + NxFilterOp op1; + NxFilterOp op2; + + _ptr->getFilterOps(op0, op1, op2); + + return (PhysxFilterOp)op2; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::set_group_collision_flag +// Access: Published +// Description: Specifies if collision should be performed by a +// pair of shape groups. +// +// It is possible to assign each shape to a collision +// groups using PhysxShape::set_group(). With this +// method one can set whether collisions should be +// detected between shapes belonging to a given pair +// of groups. Initially all pairs are enabled. +// +// Fluids can be assigned to collision groups as well. +// +// Collision groups are integers between 0 and 31. //////////////////////////////////////////////////////////////////// void PhysxScene:: -set_shape_pair_flags(PhysxShape & shape_a, PhysxShape & shape_b, unsigned int nx_contact_pair_flag) { - nassertv(nScene != NULL); +set_group_collision_flag(unsigned int g1, unsigned int g2, bool enable) { - nScene->setShapePairFlags(*(shape_a.nShape), *(shape_b.nShape), nx_contact_pair_flag); + nassertv(_error_type == ET_ok); + nassertv(g1 >= 0 && g1 < 32); + nassertv(g2 >= 0 && g2 < 32); + + _ptr->setGroupCollisionFlag((NxCollisionGroup)g1, (NxCollisionGroup)g2, enable); } //////////////////////////////////////////////////////////////////// -// Function : set_timing -// Access : Published -// Description : +// Function: PhysxScene::get_group_collision_flag +// Access: Published +// Description: Determines if collision detection is performed +// between a pair of groups. Collision groups are +// integers between 0 and 31. +//////////////////////////////////////////////////////////////////// +bool PhysxScene:: +get_group_collision_flag(unsigned int g1, unsigned int g2) { + + nassertr(_error_type == ET_ok, false); + nassertr(g1 >= 0 && g1 < 32, false); + nassertr(g2 >= 0 && g2 < 32, false); + + return _ptr->getGroupCollisionFlag((NxCollisionGroup)g1, (NxCollisionGroup)g2); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::get_flag +// Access: Published +// Description: Return the specified scene flag flag. +//////////////////////////////////////////////////////////////////// +bool PhysxScene:: +get_flag(PhysxSceneFlag flag) const { + + nassertr(_error_type == ET_ok, false); + return (_ptr->getFlags() & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::is_hardware_scene +// Access: Published +// Description: Returns TRUE if the the scene is simulated in +// hardware. FALSE if the scene is simulated in +// software. +//////////////////////////////////////////////////////////////////// +bool PhysxScene:: +is_hardware_scene() const { + + nassertr(_error_type == ET_ok, false); + return (_ptr->getSimType() & NX_SIMULATION_HW) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxScene::set_dominance_group_pair +// Access: Published +// Description: Specifies the dominance behavior of constraints +// between two actors with two certain dominance +// groups. +// +// It is possible to assign each actor to a dominance +// groups using PhysxActor::set_dominance_group(). +// +// With dominance groups one can have all constraints +// (contacts and joints) created between actors act in +// one direction only. This is useful if you want to +// make sure that the movement of the rider of a +// vehicle or the pony tail of a character doesn't +// influence the object it is attached to, while +// keeping the motion of both inherently physical. +// +// Whenever a constraint (i.e. joint or contact) +// between two actors (a0, a1) needs to be solved, the +// groups (g0, g1) of both actors are retrieved. Then +// the constraint dominance setting for this group +// pair is retrieved. +// +// In the constraint, PhysxConstraintDominance::get_0() +// becomes the dominance setting for a0, and +// PhysxConstraintDominance::get_1() becomes the +// dominance setting for a1. A dominance setting of +// 1.0f, the default, will permit the actor to be +// pushed or pulled by the other actor. A dominance +// setting of 0.0f will however prevent the actor to +// be pushed or pulled by the other actor. Thus, a +// PhysxConstraintDominance of (1.0f, 0.0f) makes the +// interaction one-way. +// +// The dominance matrix is initialised by default such +// that: +// - if g1 == g2, then (1.0f, 1.0f) is returned +// - if g1 < g2, then (0.0f, 1.0f) is returned +// - if g1 > g2, then (1.0f, 0.0f) is returned +// +// In other words, actors in higher groups can be +// pushed around by actors in lower groups by default. +// +// These settings should cover most applications, and +// in fact not overriding these settings may likely +// result in higher performance. +// +// Dominance settings are currently specified as +// floats 0.0f or 1.0f because in the future PhysX may +// permit arbitrary fractional settings to express +// 'partly-one-way' interactions. //////////////////////////////////////////////////////////////////// void PhysxScene:: -set_timing(float max_timestep, unsigned int max_iter, PhysxTimeStepMethod method) { - nassertv(nScene != NULL); +set_dominance_group_pair(unsigned int g1, unsigned int g2, PhysxConstraintDominance dominance ) { - nScene->setTiming(max_timestep, max_iter, (NxTimeStepMethod)method); + nassertv(_error_type == ET_ok); + nassertv(g1 < 32); + nassertv(g2 < 32); + + NxConstraintDominance d = dominance.get_dominance(); + _ptr->setDominanceGroupPair((NxDominanceGroup)g1, (NxDominanceGroup)g2, d); } //////////////////////////////////////////////////////////////////// -// Function : shutdown_worker_threads -// Access : Published -// Description : +// Function: PhysxScene::get_dominance_group_pair +// Access: Published +// Description: Samples the dominance matrix. //////////////////////////////////////////////////////////////////// -void PhysxScene:: -shutdown_worker_threads() { - nassertv(nScene != NULL); +PhysxConstraintDominance PhysxScene:: +get_dominance_group_pair(unsigned int g1, unsigned int g2) { - nScene->shutdownWorkerThreads(); + PhysxConstraintDominance result(1.0f, 1.0f); + + nassertr(_error_type == ET_ok, result); + nassertr(g1 < 32, result); + nassertr(g2 < 32, result); + + result.set_dominance(_ptr->getDominanceGroupPair((NxDominanceGroup)g1, (NxDominanceGroup)g2)); + return result; } -//////////////////////////////////////////////////////////////////// -// Function : simulate -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -simulate(float elapsed_time) { - nassertv(nScene != NULL); - - nScene->simulate(elapsed_time); -} - -//////////////////////////////////////////////////////////////////// -// Function : unlock_queries -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxScene:: -unlock_queries() { - nassertv(nScene != NULL); - - nScene->unlockQueries(); -} - -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxScene.h b/panda/src/physx/physxScene.h index 79a74479e2..2552ed56de 100644 --- a/panda/src/physx/physxScene.h +++ b/panda/src/physx/physxScene.h @@ -1,5 +1,5 @@ // Filename: physxScene.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (14Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,136 +15,243 @@ #ifndef PHYSXSCENE_H #define PHYSXSCENE_H -#ifdef HAVE_PHYSX - #include "pandabase.h" -#include "pvector.h" +#include "lvector3.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" -#include "physxContactHandler.h" -#include "physxTriggerHandler.h" -#include "physxJointHandler.h" +#include "physxObject.h" +#include "physxObjectCollection.h" +#include "physxEnums.h" +#include "physxContactReport.h" +#include "physxControllerReport.h" +#include "physxTriggerReport.h" +#include "physxOverlapReport.h" +#include "physxMask.h" +#include "physxGroupsMask.h" -class PhysxActorNode; +#include "NoMinMax.h" +#include "NxPhysics.h" +#include "NxControllerManager.h" + +class PhysxActor; class PhysxActorDesc; +class PhysxController; +class PhysxControllerDesc; +class PhysxConstraintDominance; +class PhysxDebugGeomNode; +class PhysxForceField; +class PhysxForceFieldDesc; +class PhysxForceFieldShapeGroup; +class PhysxForceFieldShapeGroupDesc; class PhysxJoint; class PhysxJointDesc; class PhysxMaterial; class PhysxMaterialDesc; -class PhysxSceneDesc; +class PhysxOverlapReport; +class PhysxRay; +class PhysxRaycastHit; +class PhysxRaycastReport; class PhysxSceneStats2; -class PhysxShape; - -#include "NxPhysics.h" //////////////////////////////////////////////////////////////////// // Class : PhysxScene -// Description : +// Description : A scene is a collection of bodies, constraints, +// and effectors which can interact. +// +// The scene simulates the behavior of these objects +// over time. Several scenes may exist at the same +// time, but each body, constraint, or effector object +// is specific to a scene -- they may not be shared. +// +// For example, attempting to create a joint in one +// scene and then using it to attach bodies from a +// different scene results in undefined behavior. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxScene { -PUBLISHED: - void update_panda_graph(); - PT(PhysxActorNode) get_actor(unsigned int index); - void set_contact_reporting_enabled(bool enabled); - bool is_contact_reporting_enabled(); - void set_trigger_reporting_enabled(bool enabled); - bool is_trigger_reporting_enabled(); - void set_joint_reporting_enabled(bool enabled); - bool is_joint_reporting_enabled(); - void set_contact_reporting_threshold(float threshold); - float get_contact_reporting_threshold(); +class EXPCL_PANDAPHYSX PhysxScene : public PhysxObject, public PhysxEnums { - bool check_results(PhysxSimulationStatus status, bool block); - PT(PhysxActorNode) create_actor(const PhysxActorDesc & desc, const string &name=""); - PhysxJoint *create_joint(const PhysxJointDesc & desc); - PhysxMaterial *create_material(const PhysxMaterialDesc & desc); - void flush_caches(); - void flush_stream(); - unsigned int get_actor_group_pair_flags(unsigned short group1, unsigned short group2) const; - unsigned int get_actor_pair_flags(PhysxActorNode & actor_a, PhysxActorNode & actor_b) const; - unsigned int get_bound_for_island_size(PhysxActorNode & actor); - bool get_filter_bool() const; - unsigned int get_flags() const; - void get_gravity(LVecBase3f & vec); - bool get_group_collision_flag(unsigned short group1, unsigned short group2) const; - unsigned short get_highest_material_index() const; - PhysxMaterial * get_material_from_index(unsigned short mat_index); - float get_max_cpu_for_load_balancing(); - unsigned int get_nb_actor_group_pairs() const; - unsigned int get_nb_actors() const; - unsigned int get_nb_cloths() const; - unsigned int get_nb_compartments() const; - unsigned int get_nb_dynamic_shapes() const; - unsigned int get_nb_effectors() const; - unsigned int get_nb_fluids() const; - unsigned int get_nb_force_fields() const; - unsigned int get_nb_implicit_screen_meshes() const; - unsigned int get_nb_joints() const; - unsigned int get_nb_materials() const; - unsigned int get_nb_pairs() const; - unsigned int get_nb_soft_bodies() const; - unsigned int get_nb_static_shapes() const; - PhysxJoint * get_next_joint(); - unsigned int get_shape_pair_flags(PhysxShape & shape_a, PhysxShape & shape_b) const; - PhysxSimulationType get_sim_type() const; +PUBLISHED: + INLINE PhysxScene(); + INLINE ~PhysxScene(); + + void simulate(float dt); + void fetch_results(); + void set_timing_variable(); + void set_timing_fixed(float maxTimestep=1.0f/60.0f, unsigned int maxIter=8); + + PT(PhysxDebugGeomNode) get_debug_geom_node(); + + void enable_contact_reporting(bool enabled); + bool is_contact_reporting_enabled() const; + void enable_trigger_reporting(bool enabled); + bool is_trigger_reporting_enabled() const; + void enable_controller_reporting(bool enabled); + bool is_controller_reporting_enabled() const; + + void set_gravity(const LVector3f &gravity); + + LVector3f get_gravity() const; PhysxSceneStats2 get_stats2() const; - void get_timing(float & max_timestep, unsigned int & max_iter, PhysxTimeStepMethod & method, unsigned int * num_sub_steps) const; - unsigned int get_total_nb_shapes() const; - bool is_writable(); - void lock_queries(); - PhysxThreadPollResult poll_for_background_work(PhysxThreadWait wait_type); - PhysxThreadPollResult poll_for_work(PhysxThreadWait wait_type); - void release_actor(PhysxActorNode & pActor); - void release_joint(PhysxJoint & pJoint); - void release_material(PhysxMaterial & pMaterial); - void reset_effector_iterator(); - void reset_joint_iterator(); - void reset_poll_for_work(); - bool save_to_desc(PhysxSceneDesc & desc) const; - void set_actor_group_pair_flags(unsigned short group1, unsigned short group2, unsigned int flags); - void set_actor_pair_flags(PhysxActorNode & actor_a, PhysxActorNode & actor_b, unsigned int nx_contact_pair_flag); - void set_filter_bool(bool flag); + bool get_flag(PhysxSceneFlag flag) const; + bool is_hardware_scene() const; + + // Actors + unsigned int get_num_actors() const; + PT(PhysxActor) create_actor(PhysxActorDesc &desc); + PT(PhysxActor) get_actor(unsigned int idx) const; + MAKE_SEQ(get_actors, get_num_actors, get_actor); + + // Joints + unsigned int get_num_joints() const; + PT(PhysxJoint) create_joint(PhysxJointDesc &desc); + PT(PhysxJoint) get_joint(unsigned int idx) const; + MAKE_SEQ(get_joints, get_num_joints, get_joint); + + // Materials + unsigned int get_num_materials() const; + unsigned int get_hightest_material_index() const; + PT(PhysxMaterial) create_material(PhysxMaterialDesc &desc); + PT(PhysxMaterial) create_material(); + PT(PhysxMaterial) get_material(unsigned int idx) const; + PT(PhysxMaterial) get_material_from_index(unsigned int idx) const; + MAKE_SEQ(get_materials, get_num_materials, get_material); + + // Controllers + unsigned int get_num_controllers() const; + PT(PhysxController) create_controller(PhysxControllerDesc &controllerDesc); + PT(PhysxController) get_controller(unsigned int idx) const; + MAKE_SEQ(get_controllers, get_num_controllers, get_controller); + + // Force fields + unsigned int get_num_force_fields() const; + PT(PhysxForceField) create_force_field(PhysxForceFieldDesc &desc); + PT(PhysxForceField) get_force_field(unsigned int idx) const; + MAKE_SEQ(get_force_fields, get_num_force_fields, get_force_field); + + // Force field shape groups + unsigned int get_num_force_field_shape_groups() const; + PT(PhysxForceFieldShapeGroup) create_force_field_shape_group(PhysxForceFieldShapeGroupDesc &desc); + PT(PhysxForceFieldShapeGroup) get_force_field_shape_group(unsigned int idx) const; + MAKE_SEQ(get_force_field_shape_groups, get_num_force_field_shape_groups, get_force_field_shape_group); + + // Raycast queries + bool raycast_any_shape(const PhysxRay &ray, + PhysxShapesType shapesType=ST_all, + PhysxMask mask=PhysxMask::all_on(), + PhysxGroupsMask *groups=NULL) const; + + PhysxRaycastHit raycast_closest_shape(const PhysxRay &ray, + PhysxShapesType shapesType=ST_all, + PhysxMask mask=PhysxMask::all_on(), + PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const; + + PhysxRaycastReport raycast_all_shapes(const PhysxRay &ray, + PhysxShapesType shapesType=ST_all, + PhysxMask mask=PhysxMask::all_on(), + PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const; + + bool raycast_any_bounds(const PhysxRay &ray, + PhysxShapesType shapesType=ST_all, + PhysxMask mask=PhysxMask::all_on(), + PhysxGroupsMask *groups=NULL) const; + + PhysxRaycastHit raycast_closest_bounds(const PhysxRay &ray, + PhysxShapesType shapesType=ST_all, + PhysxMask mask=PhysxMask::all_on(), + PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const; + + PhysxRaycastReport raycast_all_bounds(const PhysxRay &ray, + PhysxShapesType shapesType=ST_all, + PhysxMask mask=PhysxMask::all_on(), + PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const; + + // Overlap queries + PhysxOverlapReport overlap_sphere_shapes(const LPoint3f ¢er, float radius, + PhysxShapesType shapesType=ST_all, + PhysxMask mask=PhysxMask::all_on(), bool accurateCollision=true) const; + + 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; + + // Filters + void set_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag, bool value); + void set_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB, bool value); + void set_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag, bool value); + void set_group_collision_flag(unsigned int g1, unsigned int g2, bool enable); void set_filter_ops(PhysxFilterOp op0, PhysxFilterOp op1, PhysxFilterOp op2); - void set_gravity(const LVecBase3f & vec); - void set_group_collision_flag(unsigned short group1, unsigned short group2, bool enable); - void set_max_cpu_for_load_balancing(float cpu_fraction); - void set_shape_pair_flags(PhysxShape & shape_a, PhysxShape & shape_b, unsigned int nx_contact_pair_flag); - void set_timing(float max_timestep, unsigned int max_iter, PhysxTimeStepMethod method); - void shutdown_worker_threads(); - void simulate(float elapsed_time); - void unlock_queries(); + void set_filter_bool(bool flag); + void set_filter_constant0(const PhysxGroupsMask &mask); + void set_filter_constant1(const PhysxGroupsMask &mask); + void set_dominance_group_pair(unsigned int g1, unsigned int g2, PhysxConstraintDominance dominance); + + bool get_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag); + bool get_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB); + bool get_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag); + bool get_group_collision_flag(unsigned int g1, unsigned int g2); + bool get_filter_bool() const; + PhysxGroupsMask get_filter_constant0() const; + PhysxGroupsMask get_filter_constant1() const; + PhysxFilterOp get_filter_op0() const; + PhysxFilterOp get_filter_op1() const; + PhysxFilterOp get_filter_op2() const; + PhysxConstraintDominance get_dominance_group_pair(unsigned int g1, unsigned int g2); + +//////////////////////////////////////////////////////////////////// +PUBLISHED: + void release(); + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; public: - NxScene *nScene; + INLINE NxScene *ptr() const { return _ptr; }; + INLINE NxControllerManager *cm() const { return _cm; }; + + void link(NxScene *ptr); + void unlink(); + + PhysxObjectCollection _materials; + PhysxObjectCollection _actors; + PhysxObjectCollection _joints; + PhysxObjectCollection _forcefields; + PhysxObjectCollection _ffgroups; + PhysxObjectCollection _controllers; private: - // Keep lists of all reference counted Physx objects so that they won't be - // inadvertantly destroyed before they've been released. - pvector _actors; - pvector _joints; - pvector _shapes; + NxScene *_ptr; + NxControllerManager *_cm; + PT(PhysxDebugGeomNode) _debugNode; - bool contact_reporting_enabled; - PhysxContactHandler contact_handler; - bool trigger_reporting_enabled; - PhysxTriggerHandler trigger_handler; - bool joint_reporting_enabled; - PhysxJointHandler joint_handler; + PhysxContactReport _contact_report; + PhysxControllerReport _controller_report; + PhysxTriggerReport _trigger_report; - static PStatCollector _update_pcollector; - static PStatCollector _fetch_results_pcollector; - static PStatCollector _update_transforms_pcollector; - static PStatCollector _simulate_pcollector; - static PStatCollector _flush_stream_pcollector; - static PStatCollector _contact_reporting_pcollector; - static PStatCollector _trigger_reporting_pcollector; - static PStatCollector _joint_reporting_pcollector; + static PStatCollector _pcollector_fetch_results; + static PStatCollector _pcollector_update_transforms; + static PStatCollector _pcollector_debug_renderer; + static PStatCollector _pcollector_simulate; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxObject::init_type(); + register_type(_type_handle, "PhysxScene", + PhysxObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; }; #include "physxScene.I" -#endif // HAVE_PHYSX - #endif // PHYSXSCENE_H diff --git a/panda/src/physx/physxSceneDesc.I b/panda/src/physx/physxSceneDesc.I index df4d0c9dff..fb3640dfe3 100644 --- a/panda/src/physx/physxSceneDesc.I +++ b/panda/src/physx/physxSceneDesc.I @@ -1,5 +1,5 @@ // Filename: physxSceneDesc.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (05Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,303 +12,47 @@ // //////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxSceneDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxSceneDesc:: -is_valid() const { - return nSceneDesc.isValid(); +INLINE PhysxSceneDesc:: +PhysxSceneDesc() { + } //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxSceneDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSceneDesc:: +~PhysxSceneDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. //////////////////////////////////////////////////////////////////// INLINE void PhysxSceneDesc:: set_to_default() { - nSceneDesc.setToDefault(); + + _desc.setToDefault(); } //////////////////////////////////////////////////////////////////// -// Function : get_background_thread_count -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxSceneDesc:: -get_background_thread_count() const { - return nSceneDesc.backgroundThreadCount; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_background_thread_mask -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxSceneDesc:: -get_background_thread_mask() const { - return nSceneDesc.backgroundThreadMask; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_bounds_planes -// Access : Published -// Description : +// Function: PhysxSceneDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. //////////////////////////////////////////////////////////////////// INLINE bool PhysxSceneDesc:: -get_bounds_planes() const { - return nSceneDesc.boundsPlanes != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxSceneDesc:: -get_flags() const { - return nSceneDesc.flags; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_ground_plane -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE bool PhysxSceneDesc:: -get_ground_plane() const { - return nSceneDesc.groundPlane != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_internal_thread_count -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxSceneDesc:: -get_internal_thread_count() const { - return nSceneDesc.internalThreadCount; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_max_iter -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxSceneDesc:: -get_max_iter() const { - return nSceneDesc.maxIter; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_max_timestep -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxSceneDesc:: -get_max_timestep() const { - return nSceneDesc.maxTimestep; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_sim_thread_mask -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxSceneDesc:: -get_sim_thread_mask() const { - return nSceneDesc.simThreadMask; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_sim_thread_stack_size -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxSceneDesc:: -get_sim_thread_stack_size() const { - return nSceneDesc.simThreadStackSize; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_subdivision_level -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxSceneDesc:: -get_subdivision_level() const { - return nSceneDesc.subdivisionLevel; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_thread_mask -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxSceneDesc:: -get_thread_mask() const { - return nSceneDesc.threadMask; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_up_axis -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxSceneDesc:: -get_up_axis() const { - return nSceneDesc.upAxis; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_worker_thread_stack_size -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxSceneDesc:: -get_worker_thread_stack_size() const { - return nSceneDesc.workerThreadStackSize; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_background_thread_count -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_background_thread_count(unsigned int value) { - nSceneDesc.backgroundThreadCount = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_background_thread_mask -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_background_thread_mask(unsigned int value) { - nSceneDesc.backgroundThreadMask = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_bounds_planes -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_bounds_planes(bool value) { - nSceneDesc.boundsPlanes = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_flags(unsigned int value) { - nSceneDesc.flags = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_ground_plane -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_ground_plane(bool value) { - nSceneDesc.groundPlane = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_internal_thread_count -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_internal_thread_count(unsigned int value) { - nSceneDesc.internalThreadCount = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_max_iter -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_max_iter(unsigned int value) { - nSceneDesc.maxIter = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_max_timestep -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_max_timestep(float value) { - nSceneDesc.maxTimestep = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_sim_thread_mask -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_sim_thread_mask(unsigned int value) { - nSceneDesc.simThreadMask = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_sim_thread_stack_size -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_sim_thread_stack_size(unsigned int value) { - nSceneDesc.simThreadStackSize = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_subdivision_level -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_subdivision_level(unsigned int value) { - nSceneDesc.subdivisionLevel = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_thread_mask -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_thread_mask(unsigned int value) { - nSceneDesc.threadMask = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_up_axis -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_up_axis(unsigned int value) { - nSceneDesc.upAxis = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_worker_thread_stack_size -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSceneDesc:: -set_worker_thread_stack_size(unsigned int value) { - nSceneDesc.workerThreadStackSize = value; +is_valid() const { + + return _desc.isValid(); } diff --git a/panda/src/physx/physxSceneDesc.cxx b/panda/src/physx/physxSceneDesc.cxx index e8df98bcad..48bd47a703 100644 --- a/panda/src/physx/physxSceneDesc.cxx +++ b/panda/src/physx/physxSceneDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxSceneDesc.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (05Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,183 +12,267 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxSceneDesc.h" - -#include "luse.h" +#include "physxManager.h" #include "physxBounds3.h" - //////////////////////////////////////////////////////////////////// -// Function : PhysxSceneDesc -// Access : Published -// Description : +// Function: PhysxSceneDesc::set_gravity +// Access: Published +// Description: Sets the gravity vector. //////////////////////////////////////////////////////////////////// -PhysxSceneDesc:: -PhysxSceneDesc() { +void PhysxSceneDesc:: +set_gravity(const LVector3f &gravity) { + nassertv_always(!gravity.is_nan()); + _desc.gravity = PhysxManager::vec3_to_nxVec3(gravity); } //////////////////////////////////////////////////////////////////// -// Function : get_dynamic_structure -// Access : Published -// Description : +// Function: PhysxSceneDesc::get_gravity +// Access: Published +// Description: Get the gravity vector. //////////////////////////////////////////////////////////////////// -PhysxPruningStructure PhysxSceneDesc:: -get_dynamic_structure() const { - return (PhysxPruningStructure)nSceneDesc.dynamicStructure; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_gravity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxSceneDesc:: +LVector3f PhysxSceneDesc:: get_gravity() const { - return PhysxManager::nxVec3_to_lVecBase3(nSceneDesc.gravity); + + return PhysxManager::nxVec3_to_vec3(_desc.gravity); } //////////////////////////////////////////////////////////////////// -// Function : get_max_bounds -// Access : Published -// Description : +// Function: PhysxSceneDesc::set_flag +// Access: Published +// Description: Raise or lower individual scene flags. //////////////////////////////////////////////////////////////////// -PhysxBounds3 * PhysxSceneDesc:: +void PhysxSceneDesc:: +set_flag(const PhysxSceneFlag flag, bool value) { + + if (value == true) { + _desc.flags |= flag; + } + else { + _desc.flags &= ~(flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::get_flag +// Access: Published +// Description: Returns the specified scene flag. +//////////////////////////////////////////////////////////////////// +bool PhysxSceneDesc:: +get_flag(const PhysxSceneFlag flag) const { + + return (_desc.flags & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::set_max_bounds +// Access: Published +// Description: Set the max scene bounds. +// +// If scene bounds are provided (maxBounds in the +// descriptor), the SDK takes advantage of this +// information to accelerate scene-level collision +// queries (e.g. raycasting). When using maxBounds, +// you have to make sure created objects stay within +// the scene bounds. In particular, the position of +// dynamic shapes should stay within the provided +// bounds. Otherwise the shapes outside the bounds +// will not be taken into account by all scene queries +// (raycasting, sweep tests, overlap tests, etc). They +// will nonetheless still work correctly for the main +// physics simulation. +//////////////////////////////////////////////////////////////////// +void PhysxSceneDesc:: +set_max_bounds(PhysxBounds3 &bounds) { + + _desc.maxBounds = &(bounds._bounds); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::get_max_bounds +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxBounds3 PhysxSceneDesc:: get_max_bounds() const { - throw "Not Implemented"; // return nSceneDesc.maxBounds; + + throw "Not Implemented"; + + //PhysxBounds3 value; + //value._bounds = *(_desc.maxBounds); + //return value; } //////////////////////////////////////////////////////////////////// -// Function : get_sim_thread_priority -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxThreadPriority PhysxSceneDesc:: -get_sim_thread_priority() const { - return (PhysxThreadPriority)nSceneDesc.simThreadPriority; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_sim_type -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxSimulationType PhysxSceneDesc:: -get_sim_type() const { - return (PhysxSimulationType)nSceneDesc.simType; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_static_structure -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxPruningStructure PhysxSceneDesc:: -get_static_structure() const { - return (PhysxPruningStructure)nSceneDesc.staticStructure; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_time_step_method -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxTimeStepMethod PhysxSceneDesc:: -get_time_step_method() const { - return (PhysxTimeStepMethod)nSceneDesc.timeStepMethod; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_worker_thread_priority -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxThreadPriority PhysxSceneDesc:: -get_worker_thread_priority() const { - return (PhysxThreadPriority)nSceneDesc.workerThreadPriority; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_dynamic_structure -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxSceneDesc:: -set_dynamic_structure(PhysxPruningStructure value) { - nSceneDesc.dynamicStructure = (NxPruningStructure)value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_gravity -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxSceneDesc:: -set_gravity(LVecBase3f value) { - nSceneDesc.gravity = PhysxManager::lVecBase3_to_nxVec3(value); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_max_bounds -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxSceneDesc:: -set_max_bounds(PhysxBounds3 * value) { - nSceneDesc.maxBounds = value->nBounds3; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_sim_thread_priority -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxSceneDesc:: -set_sim_thread_priority(PhysxThreadPriority value) { - nSceneDesc.simThreadPriority = (NxThreadPriority)value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_sim_type -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxSceneDesc:: -set_sim_type(PhysxSimulationType value) { - nSceneDesc.simType = (NxSimulationType)value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_static_structure -// Access : Published -// Description : +// Function: PhysxSceneDesc::set_static_structure +// Access: Published +// Description: Defines the structure used to store static +// objects. //////////////////////////////////////////////////////////////////// void PhysxSceneDesc:: set_static_structure(PhysxPruningStructure value) { - nSceneDesc.staticStructure = (NxPruningStructure)value; + + _desc.staticStructure = (NxPruningStructure)value; } //////////////////////////////////////////////////////////////////// -// Function : set_time_step_method -// Access : Published -// Description : +// Function: PhysxSceneDesc::set_dynamic_structure +// Access: Published +// Description: Defines the subdivision level for acceleration +// structures used for scene queries. +// This is only used when maxBounds are defined! //////////////////////////////////////////////////////////////////// void PhysxSceneDesc:: -set_time_step_method(PhysxTimeStepMethod value) { - nSceneDesc.timeStepMethod = (NxTimeStepMethod)value; +set_dynamic_structure(PhysxPruningStructure value) { + + _desc.dynamicStructure = (NxPruningStructure)value; } //////////////////////////////////////////////////////////////////// -// Function : set_worker_thread_priority -// Access : Published -// Description : +// Function: PhysxSceneDesc::get_static_structure +// Access: Published +// Description: Returns the structure used to store static +// objects. +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxPruningStructure PhysxSceneDesc:: +get_static_structure() const { + + return (PhysxPruningStructure)_desc.staticStructure; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::get_dynamic_structure +// Access: Published +// Description: Returns the subdivision level for acceleration +// structures used for scene queries. +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxPruningStructure PhysxSceneDesc:: +get_dynamic_structure() const { + + return (PhysxPruningStructure)_desc.dynamicStructure; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::set_subdivision_level +// Access: Published +// Description: Defines the subdivision level for acceleration +// structures used for scene queries. +// This is only used when maxBounds are defined! //////////////////////////////////////////////////////////////////// void PhysxSceneDesc:: -set_worker_thread_priority(PhysxThreadPriority value) { - nSceneDesc.workerThreadPriority = (NxThreadPriority)value; +set_subdivision_level(unsigned int value) { + + _desc.subdivisionLevel = (NxU32)value; } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::set_num_grid_cells_x +// Access: Published +// Description: Defines the number of broadphase cells along the +// grid x-axis. Must be power of two. Max is 8 at the +// moment. The broadphase type must be set to +// BPT_sap_multi for this parameter to have +// an effect. +//////////////////////////////////////////////////////////////////// +void PhysxSceneDesc:: +set_num_grid_cells_x(unsigned int value) { + + _desc.nbGridCellsX = (NxU32)value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::set_num_grid_cells_y +// Access: Published +// Description: Defines the number of broadphase cells along the +// grid y-axis. Must be power of two. Max is 8 at the +// moment. The broadphase type must be set to +// BPT_sap_multi for this parameter to have +// an effect. +//////////////////////////////////////////////////////////////////// +void PhysxSceneDesc:: +set_num_grid_cells_y(unsigned int value) { + + _desc.nbGridCellsY = (NxU32)value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::get_subdivision_level +// Access: Published +// Description: Returns the subdivision level for acceleration +// structures used for scene queries. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxSceneDesc:: +get_subdivision_level() const { + + return _desc.subdivisionLevel; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::get_num_grid_cells_x +// Access: Published +// Description: Returns the number of broadphase cells along the +// grid x-axis. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxSceneDesc:: +get_num_grid_cells_x() const { + + return _desc.nbGridCellsX; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::get_num_grid_cells_y +// Access: Published +// Description: Returns the number of broadphase cells along the +// grid y-axis. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxSceneDesc:: +get_num_grid_cells_y() const { + + return _desc.nbGridCellsY; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::set_bp_type +// Access: Published +// Description: Defines which type of broadphase to use. +// +// (1) BPT_sap_single: A sweep-and-prune (SAP) +// algorithm to find pairs of potentially colliding +// shapes. +// +// (2) BPT_sap_multi: A multi sweep-and-prune +// algorithm to find pairs of potentially colliding +// shapes. Uses a configurable 2D grid to divide the +// scene space into cells. The potentially overlapping +// shape pairs are detected in each cell and the +// information is merged together. This approach is +// usually faster than BPT_sap_single in scenarios +// with many shapes and a high creation/deletion rate +// of shapes. However, the amount of memory required +// is considerably higher depending on the number of +// grid cells used. +// The following extra parameters need to be defined: +// - PhysxSceneDesc.set_max_bounds +// - PhysxSceneDesc.set_num_grid_cells_x +// - PhysxSceneDesc.set_num_grid_cells_y +// (the scene up direction is set via config options) +//////////////////////////////////////////////////////////////////// +void PhysxSceneDesc:: +set_bp_type(PhysxBroadPhaseType value) { + + _desc.bpType = (NxBroadPhaseType)value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSceneDesc::get_bp_type +// Access: Published +// Description: Returns the type of broadphase to use. +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxBroadPhaseType PhysxSceneDesc:: +get_bp_type() const { + + return (PhysxBroadPhaseType)_desc.bpType; +} diff --git a/panda/src/physx/physxSceneDesc.h b/panda/src/physx/physxSceneDesc.h index e88a4a466c..7b67e84663 100644 --- a/panda/src/physx/physxSceneDesc.h +++ b/panda/src/physx/physxSceneDesc.h @@ -1,5 +1,5 @@ // Filename: physxSceneDesc.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (05Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,81 +15,53 @@ #ifndef PHYSXSCENEDESC_H #define PHYSXSCENEDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "lvector3.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "physxEnums.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" class PhysxBounds3; -#include "NxPhysics.h" - //////////////////////////////////////////////////////////////////// // Class : PhysxSceneDesc -// Description : +// Description : Descriptor for PhysxScene. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxSceneDesc { +class EXPCL_PANDAPHYSX PhysxSceneDesc : public PhysxEnums { + PUBLISHED: - PhysxSceneDesc(); + INLINE PhysxSceneDesc(); + INLINE ~PhysxSceneDesc(); - INLINE bool is_valid() const; INLINE void set_to_default(); + INLINE bool is_valid() const; - INLINE unsigned int get_background_thread_count() const; - INLINE unsigned int get_background_thread_mask() const; - INLINE bool get_bounds_planes() const; - PhysxPruningStructure get_dynamic_structure() const; - INLINE unsigned int get_flags() const; - LVecBase3f get_gravity() const; - INLINE bool get_ground_plane() const; - INLINE unsigned int get_internal_thread_count() const; - PhysxBounds3 * get_max_bounds() const; - INLINE unsigned int get_max_iter() const; - INLINE float get_max_timestep() const; - INLINE unsigned int get_sim_thread_mask() const; - PhysxThreadPriority get_sim_thread_priority() const; - INLINE unsigned int get_sim_thread_stack_size() const; - PhysxSimulationType get_sim_type() const; - PhysxPruningStructure get_static_structure() const; - INLINE unsigned int get_subdivision_level() const; - INLINE unsigned int get_thread_mask() const; - PhysxTimeStepMethod get_time_step_method() const; - INLINE unsigned int get_up_axis() const; - PhysxThreadPriority get_worker_thread_priority() const; - INLINE unsigned int get_worker_thread_stack_size() const; - - INLINE void set_background_thread_count( unsigned int value ); - INLINE void set_background_thread_mask( unsigned int value ); - INLINE void set_bounds_planes( bool value ); - void set_dynamic_structure(PhysxPruningStructure value); - INLINE void set_flags( unsigned int value ); - void set_gravity( LVecBase3f value ); - INLINE void set_ground_plane( bool value ); - INLINE void set_internal_thread_count( unsigned int value ); - void set_max_bounds(PhysxBounds3 * value); - INLINE void set_max_iter( unsigned int value ); - INLINE void set_max_timestep( float value ); - INLINE void set_sim_thread_mask(unsigned int value); - void set_sim_thread_priority(PhysxThreadPriority value); - INLINE void set_sim_thread_stack_size(unsigned int value); - void set_sim_type( PhysxSimulationType value ); + void set_flag(PhysxSceneFlag flag, bool value); + void set_gravity(const LVector3f &gravity); + void set_max_bounds(PhysxBounds3 &bounds); void set_static_structure(PhysxPruningStructure value); - INLINE void set_subdivision_level(unsigned int value); - INLINE void set_thread_mask( unsigned int value ); - void set_time_step_method( PhysxTimeStepMethod value ); - INLINE void set_up_axis(unsigned int value); - void set_worker_thread_priority(PhysxThreadPriority value); - INLINE void set_worker_thread_stack_size(unsigned int value); + void set_dynamic_structure(PhysxPruningStructure value); + void set_bp_type(PhysxBroadPhaseType value); + void set_subdivision_level(unsigned int value); + void set_num_grid_cells_x(unsigned int value); + void set_num_grid_cells_y(unsigned int value); + + bool get_flag(PhysxSceneFlag flag) const; + LVector3f get_gravity() const; + PhysxBounds3 get_max_bounds() const; + PhysxPruningStructure get_static_structure() const; + PhysxPruningStructure get_dynamic_structure() const; + PhysxBroadPhaseType get_bp_type() const; + unsigned int get_subdivision_level() const; + unsigned int get_num_grid_cells_x() const; + unsigned int get_num_grid_cells_y() const; public: - NxSceneDesc nSceneDesc; + NxSceneDesc _desc; }; #include "physxSceneDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXSCENEDESC_H diff --git a/panda/src/physx/physxSceneStats2.I b/panda/src/physx/physxSceneStats2.I index e2dc3565d0..2fb52af751 100644 --- a/panda/src/physx/physxSceneStats2.I +++ b/panda/src/physx/physxSceneStats2.I @@ -1,5 +1,5 @@ -// Filename: physxSceneStats2.I -// Created by: pratt (Jun 20, 2006) +// Filename: physxSceneStats2.cxx +// Created by: enn0x (20Oct09) // //////////////////////////////////////////////////////////////////// // @@ -13,58 +13,62 @@ //////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////// -// Function : get_num_stats -// Access : Published -// Description : +// Function: PhysxSceneStats2::get_num_stats +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// INLINE unsigned int PhysxSceneStats2:: get_num_stats() const { - return nSceneStats2->numStats; + + return _ptr->numStats; } //////////////////////////////////////////////////////////////////// -// Function : get_cur_value -// Access : Published -// Description : +// Function: PhysxSceneStats2::get_cur_value +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// INLINE int PhysxSceneStats2:: get_cur_value(unsigned int index) const { - nassertr(index < nSceneStats2->numStats, -1); - return nSceneStats2->stats[index].curValue; + + nassertr(index < _ptr->numStats, -1); + return _ptr->stats[index].curValue; } //////////////////////////////////////////////////////////////////// -// Function : get_max_value -// Access : Published -// Description : +// Function: PhysxSceneStats2::get_max_value +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// INLINE int PhysxSceneStats2:: get_max_value(unsigned int index) const { - nassertr(index < nSceneStats2->numStats, -1); - return nSceneStats2->stats[index].maxValue; + + nassertr(index < _ptr->numStats, -1); + return _ptr->stats[index].maxValue; } //////////////////////////////////////////////////////////////////// -// Function : get_name -// Access : Published -// Description : +// Function: PhysxSceneStats2::get_name +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// INLINE const char * PhysxSceneStats2:: get_name(unsigned int index) const { - nassertr(index < nSceneStats2->numStats, ""); - return nSceneStats2->stats[index].name; + + nassertr(index < _ptr->numStats, ""); + return _ptr->stats[index].name; } //////////////////////////////////////////////////////////////////// -// Function : get_parent -// Access : Published -// Description : +// Function: PhysxSceneStats2::get_parent +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// INLINE unsigned int PhysxSceneStats2:: get_parent(unsigned int index) const { - nassertr(index < nSceneStats2->numStats, 0); - return nSceneStats2->stats[index].parent; + + nassertr(index < _ptr->numStats, 0); + return _ptr->stats[index].parent; } diff --git a/panda/src/physx/physxSceneStats2.cxx b/panda/src/physx/physxSceneStats2.cxx index 6c9d6df11f..8459d93ae5 100644 --- a/panda/src/physx/physxSceneStats2.cxx +++ b/panda/src/physx/physxSceneStats2.cxx @@ -1,5 +1,5 @@ // Filename: physxSceneStats2.cxx -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (20Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,28 +12,26 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxSceneStats2.h" - //////////////////////////////////////////////////////////////////// -// Function : PhysxSceneStats2 -// Access : Published -// Description : +// Function: PhysxSceneStats2::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// PhysxSceneStats2:: -PhysxSceneStats2(const NxSceneStats2 *stats2) { - nSceneStats2 = stats2; +PhysxSceneStats2(const NxSceneStats2 *ptr) { + + _ptr = ptr; } //////////////////////////////////////////////////////////////////// -// Function : ~PhysxSceneStats2 -// Access : Published -// Description : +// Function: PhysxSceneStats2::Destructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// PhysxSceneStats2:: ~PhysxSceneStats2() { + } -#endif // HAVE_PHYSX diff --git a/panda/src/physx/physxSceneStats2.h b/panda/src/physx/physxSceneStats2.h index b032de66a8..8f41bfdbd9 100644 --- a/panda/src/physx/physxSceneStats2.h +++ b/panda/src/physx/physxSceneStats2.h @@ -1,5 +1,5 @@ // Filename: physxSceneStats2.h -// Created by: pratt (Jun 20, 2006) +// Created by: enn0x (20Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,14 +15,9 @@ #ifndef PHYSXSCENESTATS2_H #define PHYSXSCENESTATS2_H -#ifdef HAVE_PHYSX - #include "pandabase.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - +#include "NoMinMax.h" #include "NxPhysics.h" //////////////////////////////////////////////////////////////////// @@ -30,8 +25,9 @@ // Description : //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxSceneStats2 { + PUBLISHED: - PhysxSceneStats2(const NxSceneStats2 *stats2); + PhysxSceneStats2(const NxSceneStats2 *ptr); ~PhysxSceneStats2(); INLINE unsigned int get_num_stats() const; @@ -41,11 +37,9 @@ PUBLISHED: INLINE unsigned int get_parent(unsigned int index) const; private: - const NxSceneStats2 *nSceneStats2; + const NxSceneStats2 *_ptr; }; #include "physxSceneStats2.I" -#endif // HAVE_PHYSX - #endif // PHYSXSCENESTATS2_H diff --git a/panda/src/physx/physxSegment.I b/panda/src/physx/physxSegment.I index 25148958d8..06b0e26dc0 100644 --- a/panda/src/physx/physxSegment.I +++ b/panda/src/physx/physxSegment.I @@ -1,5 +1,5 @@ // Filename: physxSegment.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,63 +12,35 @@ // //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function : compute_direction -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSegment:: -compute_direction(LVecBase3f & dir) const { - nassertv(nSegment != NULL); - nSegment->computeDirection(PhysxManager::lVecBase3_to_nxVec3(dir)); +//////////////////////////////////////////////////////////////////// +// Function: PhysxSegment::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSegment:: +PhysxSegment() { + } //////////////////////////////////////////////////////////////////// -// Function : compute_length -// Access : Published -// Description : +// Function: PhysxSegment::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE float PhysxSegment:: -compute_length() const { - nassertr(nSegment != NULL, -1.0f); +INLINE PhysxSegment:: +PhysxSegment(const PhysxSegment &segment) { - return nSegment->computeLength(); + _segment = segment._segment; } //////////////////////////////////////////////////////////////////// -// Function : compute_point -// Access : Published -// Description : +// Function: PhysxSegment::Destructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE void PhysxSegment:: -compute_point(LVecBase3f & pt, float t) const { - nassertv(nSegment != NULL); +INLINE PhysxSegment:: +~PhysxSegment() { - nSegment->computePoint(PhysxManager::lVecBase3_to_nxVec3(pt), t); -} - -//////////////////////////////////////////////////////////////////// -// Function : compute_square_length -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxSegment:: -compute_square_length() const { - nassertr(nSegment != NULL, -1.0f); - - return nSegment->computeSquareLength(); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_origin_direction -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSegment:: -set_origin_direction(const LVecBase3f & origin, const LVecBase3f & direction) { - nassertv(nSegment != NULL); - - nSegment->setOriginDirection(PhysxManager::lVecBase3_to_nxVec3(origin), PhysxManager::lVecBase3_to_nxVec3(direction)); } diff --git a/panda/src/physx/physxSegment.cxx b/panda/src/physx/physxSegment.cxx index b1720c0322..e6f5afe2ed 100644 --- a/panda/src/physx/physxSegment.cxx +++ b/panda/src/physx/physxSegment.cxx @@ -1,5 +1,5 @@ // Filename: physxSegment.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,112 +12,148 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxSegment.h" - -#include "luse.h" - +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxSegment -// Access : Published -// Description : +// Function: PhysxSegment::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// PhysxSegment:: -PhysxSegment() { +PhysxSegment(const LPoint3f &p0, const LPoint3f &p1) { + _segment.p0 = PhysxManager::point3_to_nxVec3(p0); + _segment.p1 = PhysxManager::point3_to_nxVec3(p1); } //////////////////////////////////////////////////////////////////// -// Function : PhysxSegment -// Access : Published -// Description : +// Function: PhysxSegment::get_p0 +// Access: Published +// Description: Returns the start point of the segment. //////////////////////////////////////////////////////////////////// -PhysxSegment:: -PhysxSegment(const LVecBase3f &p0, const LVecBase3f &p1) { - -} - -//////////////////////////////////////////////////////////////////// -// Function : PhysxSegment -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxSegment:: -PhysxSegment(const PhysxSegment & seg) { - -} - -//////////////////////////////////////////////////////////////////// -// Function : ~PhysxSegment -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxSegment:: -~PhysxSegment() { - -} - -//////////////////////////////////////////////////////////////////// -// Function : get_origin -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxSegment:: -get_origin() const { - nassertr(nSegment != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nSegment->getOrigin()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_p0 -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxSegment:: +LPoint3f PhysxSegment:: get_p0() const { - nassertr(nSegment != NULL, *((LVecBase3f *)NULL)); - return PhysxManager::nxVec3_to_lVecBase3(nSegment->p0); + return PhysxManager::nxVec3_to_vec3(_segment.p0); } //////////////////////////////////////////////////////////////////// -// Function : get_p1 -// Access : Published -// Description : +// Function: PhysxSegment::set_p0 +// Access: Published +// Description: Sets the start point of the segment. //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxSegment:: +void PhysxSegment:: +set_p0(LPoint3f p) { + + nassertv_always(!p.is_nan()); + + _segment.p0 = PhysxManager::vec3_to_nxVec3(p); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSegment::get_p1 +// Access: Published +// Description: Returns the end point of the segment. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxSegment:: get_p1() const { - nassertr(nSegment != NULL, *((LVecBase3f *)NULL)); - return PhysxManager::nxVec3_to_lVecBase3(nSegment->p1); + return PhysxManager::nxVec3_to_vec3(_segment.p1); } //////////////////////////////////////////////////////////////////// -// Function : set_p0 -// Access : Published -// Description : +// Function: PhysxSegment::set_p1 +// Access: Published +// Description: Sets the end point of the segment. //////////////////////////////////////////////////////////////////// void PhysxSegment:: -set_p0(LVecBase3f value) { - nassertv(nSegment != NULL); +set_p1(LPoint3f p) { - nSegment->p0 = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv_always(!p.is_nan()); + + _segment.p1 = PhysxManager::vec3_to_nxVec3(p); } //////////////////////////////////////////////////////////////////// -// Function : set_p1 -// Access : Published -// Description : +// Function: PhysxSegment::get_origin +// Access: Published +// Description: Returns the start point of the segment. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxSegment:: +get_origin() const { + + return PhysxManager::nxVec3_to_point3(_segment.getOrigin()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSegment::compute_direction +// Access: Published +// Description: Returns the direction vector from the segment's +// start point to it's end point. //////////////////////////////////////////////////////////////////// void PhysxSegment:: -set_p1(LVecBase3f value) { - nassertv(nSegment != NULL); +compute_direction(LPoint3f &dir) const { - nSegment->p1 = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv(!dir.is_nan()); + + NxVec3 nDir = PhysxManager::point3_to_nxVec3(dir); + _segment.computeDirection(nDir); + PhysxManager::update_point3_from_nxVec3(dir, nDir); } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxSegment::compute_length +// Access: Published +// Description: Returns the distance from the segment's start point +// to it's end point. +//////////////////////////////////////////////////////////////////// +float PhysxSegment:: +compute_length() const { + + return _segment.computeLength(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSegment::compute_point +// Access: Published +// Description: Computes a point on the segment. +//////////////////////////////////////////////////////////////////// +void PhysxSegment:: +compute_point(LPoint3f &p, float t) const { + + nassertv(!p.is_nan()); + + NxVec3 nP = PhysxManager::point3_to_nxVec3(p); + _segment.computePoint(nP, t); + PhysxManager::update_point3_from_nxVec3(p, nP); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSegment::compute_square_length +// Access: Published +// Description: Returns the square distance from the segment's +// start point to it's end point. +//////////////////////////////////////////////////////////////////// +float PhysxSegment:: +compute_square_length() const { + + return _segment.computeSquareLength(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSegment::set_origin_direction +// Access: Published +// Description: Setup this segment from origin (start point) and +// direction vector. +//////////////////////////////////////////////////////////////////// +void PhysxSegment:: +set_origin_direction(const LPoint3f &origin, const LVector3f &direction) { + + nassertv_always(!origin.is_nan()); + nassertv_always(!direction.is_nan()); + + _segment.setOriginDirection(PhysxManager::point3_to_nxVec3(origin), + PhysxManager::vec3_to_nxVec3(direction)); +} diff --git a/panda/src/physx/physxSegment.h b/panda/src/physx/physxSegment.h index 453b546dbd..3cbdb9f8ca 100644 --- a/panda/src/physx/physxSegment.h +++ b/panda/src/physx/physxSegment.h @@ -1,5 +1,5 @@ // Filename: physxSegment.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,46 +15,40 @@ #ifndef PHYSXSEGMENT_H #define PHYSXSEGMENT_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "lpoint3.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -#include "NxPhysics.h" +#include "config_physx.h" //////////////////////////////////////////////////////////////////// // Class : PhysxSegment -// Description : +// Description : Represents a line segment. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxSegment { + PUBLISHED: - PhysxSegment(); - PhysxSegment(const LVecBase3f &p0, const LVecBase3f &p1); - PhysxSegment(const PhysxSegment & seg); - ~PhysxSegment(); + INLINE PhysxSegment(); + INLINE PhysxSegment(const PhysxSegment & segment); + PhysxSegment(const LPoint3f &p0, const LPoint3f &p1); + INLINE ~PhysxSegment(); - INLINE void compute_direction(LVecBase3f & dir) const; - INLINE float compute_length() const; - INLINE void compute_point(LVecBase3f & pt, float t) const; - INLINE float compute_square_length() const; - LVecBase3f get_origin() const; - INLINE void set_origin_direction(const LVecBase3f & origin, const LVecBase3f & direction); + void compute_direction(LPoint3f &dir) const; + float compute_length() const; + void compute_point(LPoint3f &p, float t) const; + float compute_square_length() const; + LPoint3f get_origin() const; + void set_origin_direction(const LPoint3f &origin, const LVector3f &direction); - LVecBase3f get_p0() const; - LVecBase3f get_p1() const; + LPoint3f get_p0() const; + LPoint3f get_p1() const; - void set_p0( LVecBase3f value ); - void set_p1( LVecBase3f value ); + void set_p0(LPoint3f p); + void set_p1(LPoint3f p); public: - NxSegment *nSegment; + NxSegment _segment; }; #include "physxSegment.I" -#endif // HAVE_PHYSX - -#endif // PHYSXSEGMENT_H +#endif // PHYSSEGMENT_H diff --git a/panda/src/physx/physxShape.I b/panda/src/physx/physxShape.I index 514dd5f19b..7ec9355945 100644 --- a/panda/src/physx/physxShape.I +++ b/panda/src/physx/physxShape.I @@ -1,5 +1,5 @@ // Filename: physxShape.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,39 +15,36 @@ //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : Returns true if the NxShape associated with this -// is not NULL. The NxShape will be NULL if the -// Actor that this shape is a part of has been -// released. +// Function: PhysxShape::Constructor +// Access: Protected +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxShape:: -is_valid() { - return nShape != NULL; +INLINE PhysxShape:: +PhysxShape() : PhysxObject() { + } //////////////////////////////////////////////////////////////////// -// Function : get_app_data -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void * PhysxShape:: -get_app_data() const { - nassertr(nShape != NULL, NULL); - - return nShape->appData; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_app_data -// Access : Published -// Description : +// Function: PhysxShape::ls +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// INLINE void PhysxShape:: -set_app_data(void * value) { - nassertv(nShape != NULL); +ls() const { - nShape->appData = value; + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxShape:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " " << get_name() + << " (at 0x" << this << ")\n"; } diff --git a/panda/src/physx/physxShape.cxx b/panda/src/physx/physxShape.cxx index 57d6d5c11b..33c301c649 100644 --- a/panda/src/physx/physxShape.cxx +++ b/panda/src/physx/physxShape.cxx @@ -1,5 +1,5 @@ // Filename: physxShape.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,414 +12,450 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxShape.h" - -#include "luse.h" -#include "physxActorNode.h" -#include "physxBounds3.h" -#include "physxBox.h" +#include "physxManager.h" +#include "physxActor.h" #include "physxBoxShape.h" -#include "physxCapsule.h" #include "physxCapsuleShape.h" #include "physxPlaneShape.h" -#include "physxSphere.h" #include "physxSphereShape.h" +#include "physxConvexShape.h" +#include "physxHeightFieldShape.h" +#include "physxTriangleMeshShape.h" +#include "physxWheelShape.h" +#include "physxGroupsMask.h" +#include "physxBounds3.h" +#include "physxSphere.h" +#include "physxBox.h" +#include "physxCapsule.h" +#include "physxRay.h" +#include "physxRaycastHit.h" TypeHandle PhysxShape::_type_handle; //////////////////////////////////////////////////////////////////// -// Function : check_overlap_aabb -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxShape:: -check_overlap_aabb(const PhysxBounds3 & world_bounds) const { - nassertr(nShape != NULL, false); - - return nShape->checkOverlapAABB(*(world_bounds.nBounds3)); -} - -//////////////////////////////////////////////////////////////////// -// Function : check_overlap_capsule -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxShape:: -check_overlap_capsule(const PhysxCapsule & world_capsule) const { - nassertr(nShape != NULL, false); - - return nShape->checkOverlapCapsule(*(world_capsule.nCapsule)); -} - -//////////////////////////////////////////////////////////////////// -// Function : check_overlap_obb -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxShape:: -check_overlap_obb(const PhysxBox & world_box) const { - nassertr(nShape != NULL, false); - - return nShape->checkOverlapOBB(*(world_box.nBox)); -} - -//////////////////////////////////////////////////////////////////// -// Function : check_overlap_sphere -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxShape:: -check_overlap_sphere(const PhysxSphere & world_sphere) const { - nassertr(nShape != NULL, false); - - return nShape->checkOverlapSphere(*(world_sphere.nSphere)); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_actor -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxActorNode & PhysxShape:: -get_actor() const { - nassertr(nShape != NULL, *((PhysxActorNode *)NULL)); - - return *((PhysxActorNode *)(nShape->getActor().userData)); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_flag -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxShape:: -get_flag(PhysxShapeFlag flag) const { - nassertr(nShape != NULL, false); - - return (bool)(nShape->getFlag((NxShapeFlag)flag)); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_global_orientation -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LMatrix3f PhysxShape:: -get_global_orientation() const { - nassertr(nShape != NULL, *((LMatrix3f *)NULL)); - - return PhysxManager::nxMat33_to_lMatrix3(nShape->getGlobalOrientation()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_global_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LMatrix4f PhysxShape:: -get_global_pose() const { - nassertr(nShape != NULL, *((LMatrix4f *)NULL)); - - return PhysxManager::nxMat34_to_lMatrix4(nShape->getGlobalPose()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_global_position -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxShape:: -get_global_position() const { - nassertr(nShape != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nShape->getGlobalPosition()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_group -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned short PhysxShape:: -get_group() const { - nassertr(nShape != NULL, -1); - - return nShape->getGroup(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_local_orientation -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LMatrix3f PhysxShape:: -get_local_orientation() const { - nassertr(nShape != NULL, *((LMatrix3f *)NULL)); - - return PhysxManager::nxMat33_to_lMatrix3(nShape->getLocalOrientation()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_local_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LMatrix4f PhysxShape:: -get_local_pose() const { - nassertr(nShape != NULL, *((LMatrix4f *)NULL)); - - return PhysxManager::nxMat34_to_lMatrix4(nShape->getLocalPose()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_local_position -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -LVecBase3f PhysxShape:: -get_local_position() const { - nassertr(nShape != NULL, *((LVecBase3f *)NULL)); - - return PhysxManager::nxVec3_to_lVecBase3(nShape->getLocalPosition()); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_material -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned short PhysxShape:: -get_material() const { - nassertr(nShape != NULL, -1); - - return nShape->getMaterial(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_name -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -const char * PhysxShape:: -get_name() const { - nassertr(nShape != NULL, NULL); - - return nShape->getName(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_skin_width -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxShape:: -get_skin_width() const { - nassertr(nShape != NULL, -1.0f); - - return nShape->getSkinWidth(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_world_bounds -// Access : Published -// Description : +// Function: PhysxShape::release +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// void PhysxShape:: -get_world_bounds(PhysxBounds3 & dest) const { - nassertv(nShape != NULL); +release() { - nShape->getWorldBounds(*(dest.nBounds3)); + nassertv(_error_type == ET_ok); + + unlink(); + ptr()->getActor().releaseShape(*ptr()); } //////////////////////////////////////////////////////////////////// -// Function : is_box -// Access : Published -// Description : +// Function: PhysxShape::factory +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// -const PhysxBoxShape * PhysxShape:: -is_box() const { - nassertr(nShape != NULL, NULL); +PT(PhysxShape) PhysxShape:: +factory(NxShapeType shapeType) { - return (PhysxBoxShape *)(nShape->isBox()->userData); + switch (shapeType) { + + case NX_SHAPE_PLANE: + return new PhysxPlaneShape(); + + case NX_SHAPE_SPHERE: + return new PhysxSphereShape(); + + case NX_SHAPE_BOX: + return new PhysxBoxShape(); + + case NX_SHAPE_CAPSULE: + return new PhysxCapsuleShape(); + + case NX_SHAPE_CONVEX: + return new PhysxConvexShape(); + + case NX_SHAPE_MESH: + return new PhysxTriangleMeshShape(); + + case NX_SHAPE_HEIGHTFIELD: + return new PhysxHeightFieldShape(); + + case NX_SHAPE_WHEEL: + return new PhysxWheelShape(); + } + + physx_cat.error() << "Unknown shape type.\n"; + return NULL; } //////////////////////////////////////////////////////////////////// -// Function : is_capsule -// Access : Published -// Description : +// Function: PhysxShape::get_actor +// Access: Published +// Description: Retrieves the actor which this shape is associated +// with. //////////////////////////////////////////////////////////////////// -const PhysxCapsuleShape * PhysxShape:: -is_capsule() const { - nassertr(nShape != NULL, NULL); +PT(PhysxActor) PhysxShape:: +get_actor() const { - return (PhysxCapsuleShape *)(nShape->isCapsule()->userData); + nassertr(_error_type == ET_ok, NULL); + return (PhysxActor *)(ptr()->getActor().userData); } //////////////////////////////////////////////////////////////////// -// Function : is_plane -// Access : Published -// Description : +// Function: PhysxShape::set_name +// Access: Published +// Description: Sets a name string for this object. The name can +// be retrieved again with get_name(). +// This is for debugging and is not used by the +// physics engine. //////////////////////////////////////////////////////////////////// -const PhysxPlaneShape * PhysxShape:: -is_plane() const { - nassertr(nShape != NULL, NULL); +void PhysxShape:: +set_name(const char *name) { - return (PhysxPlaneShape *)(nShape->isPlane()->userData); + nassertv(_error_type == ET_ok); + ptr()->setName(name); } //////////////////////////////////////////////////////////////////// -// Function : is_sphere -// Access : Published -// Description : +// Function: PhysxShape::get_name +// Access: Published +// Description: Returns the name string. //////////////////////////////////////////////////////////////////// -const PhysxSphereShape * PhysxShape:: -is_sphere() const { - nassertr(nShape != NULL, NULL); +const char *PhysxShape:: +get_name() const { - return (PhysxSphereShape *)(nShape->isSphere()->userData); + nassertr(_error_type == ET_ok, ""); + return ptr()->getName(); } //////////////////////////////////////////////////////////////////// -// Function : set_flag -// Access : Published -// Description : +// Function: PhysxShape::set_flag +// Access: Published +// Description: Sets the specified shape flag. +// +// The shape may be turned into a trigger by setting +// one or more of the TriggerFlags to true. A trigger +// shape will not collide with other shapes. Instead, +// if a shape enters the trigger's volume, a trigger +// event will be sent. Trigger events can be listened +// to by DirectObjects. +// The following trigger events can be sent: +// - physx-trigger-enter +// - physx-trigger-stay +// - physx-trigger-leave //////////////////////////////////////////////////////////////////// void PhysxShape:: set_flag(PhysxShapeFlag flag, bool value) { - nassertv(nShape != NULL); - nShape->setFlag((NxShapeFlag)flag, value); + nassertv(_error_type == ET_ok); + + ptr()->setFlag((NxShapeFlag)flag, value); } //////////////////////////////////////////////////////////////////// -// Function : set_global_orientation -// Access : Published -// Description : +// Function: PhysxShape::get_flag +// Access: Published +// Description: Returns the specified shape flag. +//////////////////////////////////////////////////////////////////// +bool PhysxShape:: +get_flag(PhysxShapeFlag flag) const { + + nassertr(_error_type == ET_ok, false); + + return (ptr()->getFlag((NxShapeFlag)flag)) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::set_skin_width +// Access: Published +// Description: Sets the skin width. +// The skin width must be non-negative. //////////////////////////////////////////////////////////////////// void PhysxShape:: -set_global_orientation(const LMatrix3f & mat) { - nassertv(nShape != NULL); +set_skin_width(float skinWidth) { - nShape->setGlobalOrientation(PhysxManager::lMatrix3_to_nxMat33(mat)); + nassertv(_error_type == ET_ok); + nassertv(skinWidth >= 0.0f); + + ptr()->setSkinWidth(skinWidth); } //////////////////////////////////////////////////////////////////// -// Function : set_global_pose -// Access : Published -// Description : +// Function: PhysxShape::get_skin_width +// Access: Published +// Description: Returns the skin width. +//////////////////////////////////////////////////////////////////// +float PhysxShape:: +get_skin_width() const { + + nassertr(_error_type == ET_ok, 0.0f); + + return ptr()->getSkinWidth(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::set_group +// Access: Published +// Description: Sets which collision group this shape is part of. +// +// Default group is 0. Maximum possible group is 31. +// Collision groups are sets of shapes which may or +// may not be set to collision detect with each other; +// this can be set using +// PhysxScene::set_group_collision_flag(). //////////////////////////////////////////////////////////////////// void PhysxShape:: -set_global_pose(const LMatrix4f & mat) { - nassertv(nShape != NULL); +set_group(unsigned short group) { - nShape->setGlobalPose(PhysxManager::lMatrix4_to_nxMat34(mat)); + nassertv(_error_type == ET_ok); + nassertv(group < 32); + + ptr()->setGroup(group); } //////////////////////////////////////////////////////////////////// -// Function : set_global_position -// Access : Published -// Description : +// Function: PhysxShape::get_group +// Access: Published +// Description: Retrieves the collision group set for this shape. +// The collision group is an integer between 0 and +// 31. +//////////////////////////////////////////////////////////////////// +unsigned short PhysxShape:: +get_group() const { + + nassertr(_error_type == ET_ok, 0); + + return ptr()->getGroup(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::set_local_pos +// Access: Published +// Description: Set the position of the shape in actor space, i.e. +// relative to the actor it is owned by. +// +// Calling this method does NOT wake the associated +// actor up automatically. +// +// Calling this method does not automatically update +// the inertia properties of the owning actor (if +// applicable); use +// PhysxActor::update_mass_from_shapes() to do this. //////////////////////////////////////////////////////////////////// void PhysxShape:: -set_global_position(const LVecBase3f & vec) { - nassertv(nShape != NULL); +set_local_pos(const LPoint3f &pos) { - nShape->setGlobalPosition(PhysxManager::lVecBase3_to_nxVec3(vec)); + nassertv(_error_type == ET_ok); + + ptr()->setLocalPosition(PhysxManager::point3_to_nxVec3(pos)); } //////////////////////////////////////////////////////////////////// -// Function : set_group -// Access : Published -// Description : +// Function: PhysxShape::get_local_pos +// Access: Published +// Description: Retrieve the position of the shape in actor space, +// i.e. relative to the actor it is owned by. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxShape:: +get_local_pos() const { + + nassertr(_error_type == ET_ok, LPoint3f::zero()); + + return PhysxManager::nxVec3_to_point3(ptr()->getLocalPosition()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::set_local_mat +// Access: Published +// Description: Set the transform of the shape in actor space, +// i.e. relative to the actor it is owned by. +// +// Calling this method does NOT wake the associated +// actor up automatically. +// +// Calling this method does not automatically update +// the inertia properties of the owning actor (if +// applicable); use +// PhysxActor::update_mass_from_shapes() to do this. //////////////////////////////////////////////////////////////////// void PhysxShape:: -set_group(unsigned short collision_group) { - nassertv(nShape != NULL); +set_local_mat(const LMatrix4f &mat) { - nShape->setGroup(collision_group); + nassertv(_error_type == ET_ok); + + ptr()->setLocalPose(PhysxManager::mat4_to_nxMat34(mat)); } //////////////////////////////////////////////////////////////////// -// Function : set_local_orientation -// Access : Published -// Description : +// Function: PhysxShape::get_local_mat +// Access: Published +// Description: Retrieve the transform of the shape in actor space, +// i.e. relative to the actor it is owned by. +//////////////////////////////////////////////////////////////////// +LMatrix4f PhysxShape:: +get_local_mat() const { + + nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat()); + + return PhysxManager::nxMat34_to_mat4(ptr()->getLocalPose()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::get_material_index +// Access: Published +// Description: Returns the material index currently assigned to +// the shape. +//////////////////////////////////////////////////////////////////// +unsigned short PhysxShape:: +get_material_index() const { + + nassertr(_error_type == ET_ok, 0); + NxMaterialIndex index = ptr()->getMaterial(); + return (unsigned int)index; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::set_material +// Access: Published +// Description: Assigns a material to the shape. //////////////////////////////////////////////////////////////////// void PhysxShape:: -set_local_orientation(const LMatrix3f & mat) { - nassertv(nShape != NULL); +set_material(const PhysxMaterial &material) { - nShape->setLocalOrientation(PhysxManager::lMatrix3_to_nxMat33(mat)); + nassertv(_error_type == ET_ok); + ptr()->setMaterial(material.ptr()->getMaterialIndex()); } //////////////////////////////////////////////////////////////////// -// Function : set_local_pose -// Access : Published -// Description : +// Function: PhysxShape::set_material_index +// Access: Published +// Description: Assigns a material index to the shape. +// +// The material index can be retrieved by calling +// PhysxMaterial::get_material_index(). If the material +// index is invalid, it will still be recorded, but +// the default material (at index 0) will effectively +// be used for simulation. //////////////////////////////////////////////////////////////////// void PhysxShape:: -set_local_pose(const LMatrix4f & mat) { - nassertv(nShape != NULL); +set_material_index(unsigned short index) { - nShape->setLocalPose(PhysxManager::lMatrix4_to_nxMat34(mat)); + nassertv(_error_type == ET_ok); + ptr()->setMaterial((NxMaterialIndex)index); } //////////////////////////////////////////////////////////////////// -// Function : set_local_position -// Access : Published -// Description : +// Function: PhysxShape::set_groups_mask +// Access: Published +// Description: Sets 128-bit mask used for collision filtering. +// Does NOT wake the associated actor up +// automatically. //////////////////////////////////////////////////////////////////// void PhysxShape:: -set_local_position(const LVecBase3f & vec) { - nassertv(nShape != NULL); +set_groups_mask(const PhysxGroupsMask &mask) { - nShape->setLocalPosition(PhysxManager::lVecBase3_to_nxVec3(vec)); + nassertv(_error_type == ET_ok); + ptr()->setGroupsMask(mask.get_mask()); } //////////////////////////////////////////////////////////////////// -// Function : set_material -// Access : Published -// Description : +// Function: PhysxShape::get_groups_mask +// Access: Published +// Description: Gets 128-bit mask used for collision filtering. //////////////////////////////////////////////////////////////////// -void PhysxShape:: -set_material(unsigned short mat_index) { - nassertv(nShape != NULL); +PhysxGroupsMask PhysxShape:: +get_groups_mask() const { - nShape->setMaterial(mat_index); + PhysxGroupsMask mask; + nassertr(_error_type == ET_ok, mask); + mask.set_mask(ptr()->getGroupsMask()); + return mask; } //////////////////////////////////////////////////////////////////// -// Function : set_name -// Access : Published -// Description : +// Function: PhysxShape::get_world_bounds +// Access: Published +// Description: Returns a world space AABB enclosing this shape. //////////////////////////////////////////////////////////////////// -void PhysxShape:: -set_name(const char * name) { - nassertv(nShape != NULL); +PhysxBounds3 PhysxShape:: +get_world_bounds() const { - // Because the PhysX engine does not store its own copy of names, - // we keep a local copy on this instance. Otherwise, it would be - // very easy for names to be declared in python and then - // invalidated when the string is reclaimed from reference - // counting. - _name_store = name; - nShape->setName(_name_store.c_str()); + PhysxBounds3 bounds; + nassertr(_error_type == ET_ok, bounds); + ptr()->getWorldBounds(bounds._bounds); + return bounds; } //////////////////////////////////////////////////////////////////// -// Function : set_skin_width -// Access : Published -// Description : +// Function: PhysxShape::check_overlap_aabb +// Access: Published +// Description: Checks whether the shape overlaps a world-space +// AABB or not. //////////////////////////////////////////////////////////////////// -void PhysxShape:: -set_skin_width(float skin_width) { - nassertv(nShape != NULL); +bool PhysxShape:: +check_overlap_aabb(const PhysxBounds3 &world_bounds) const { - nShape->setSkinWidth(skin_width); + nassertr(_error_type == ET_ok, false); + return ptr()->checkOverlapAABB(world_bounds._bounds); } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::check_overlap_capsule +// Access: Published +// Description: Checks whether the shape overlaps a world-space +// capsule or not. +//////////////////////////////////////////////////////////////////// +bool PhysxShape:: +check_overlap_capsule(const PhysxCapsule &world_capsule) const { + nassertr(_error_type == ET_ok, false); + return ptr()->checkOverlapCapsule(world_capsule._capsule); +} +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::check_overlap_obb +// Access: Published +// Description: Checks whether the shape overlaps a world-space +// OBB or not. +//////////////////////////////////////////////////////////////////// +bool PhysxShape:: +check_overlap_obb(const PhysxBox &world_box) const { + + nassertr(_error_type == ET_ok, false); + return ptr()->checkOverlapOBB(world_box._box); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::check_overlap_sphere +// Access: Published +// Description: Checks whether the shape overlaps a world-space +// sphere or not. +//////////////////////////////////////////////////////////////////// +bool PhysxShape:: +check_overlap_sphere(const PhysxSphere &world_sphere) const { + + nassertr(_error_type == ET_ok, false); + return ptr()->checkOverlapSphere(world_sphere._sphere); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::raycast +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxRaycastHit PhysxShape:: +raycast(const PhysxRay &worldRay, bool firstHit, bool smoothNormal) const { + + NxRaycastHit hit; + nassertr(_error_type == ET_ok, hit); + + NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE; + if (smoothNormal == true) { + hints |= NX_RAYCAST_NORMAL; + } + else { + hints |= NX_RAYCAST_FACE_NORMAL; + } + + ptr()->raycast(worldRay._ray, worldRay._length, hints, hit, firstHit); + return PhysxRaycastHit(hit); +} diff --git a/panda/src/physx/physxShape.h b/panda/src/physx/physxShape.h index fc826b2225..559a83b605 100644 --- a/panda/src/physx/physxShape.h +++ b/panda/src/physx/physxShape.h @@ -1,5 +1,5 @@ // Filename: physxShape.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,83 +15,88 @@ #ifndef PHYSXSHAPE_H #define PHYSXSHAPE_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "pointerTo.h" +#include "lpoint3.h" +#include "lmatrix.h" +#include "lquaternion.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -#include "typedWritableReferenceCount.h" - -class PhysxActorNode; -class PhysxBounds3; -class PhysxBox; -class PhysxBoxShape; -class PhysxCapsule; -class PhysxCapsuleShape; -class PhysxPlaneShape; -class PhysxSphere; -class PhysxSphereShape; +#include "physxObject.h" +#include "physxEnums.h" +#include "NoMinMax.h" #include "NxPhysics.h" +class PhysxActor; +class PhysxMaterial; +class PhysxGroupsMask; +class PhysxBounds3; +class PhysxSphere; +class PhysxBox; +class PhysxCapsule; +class PhysxRay; +class PhysxRaycastHit; + //////////////////////////////////////////////////////////////////// // Class : PhysxShape -// Description : +// Description : Abstract base class for shapes. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxShape : public TypedWritableReferenceCount { +class EXPCL_PANDAPHYSX PhysxShape : public PhysxObject, public PhysxEnums { + PUBLISHED: - INLINE bool is_valid(); + void release(); - bool check_overlap_aabb(const PhysxBounds3 & world_bounds) const; - bool check_overlap_capsule(const PhysxCapsule & world_capsule) const; - bool check_overlap_obb(const PhysxBox & world_box) const; - bool check_overlap_sphere(const PhysxSphere & world_sphere) const; - PhysxActorNode & get_actor() const; - bool get_flag(PhysxShapeFlag flag) const; - LMatrix3f get_global_orientation() const; - LMatrix4f get_global_pose() const; - LVecBase3f get_global_position() const; - unsigned short get_group() const; - LMatrix3f get_local_orientation() const; - LMatrix4f get_local_pose() const; - LVecBase3f get_local_position() const; - unsigned short get_material() const; - const char * get_name() const; + PT(PhysxActor) get_actor() const; + + void set_name(const char *name); + void set_flag(const PhysxShapeFlag flag, bool value); + void set_skin_width(float skinWidth); + void set_group(unsigned short group); + void set_local_pos(const LPoint3f &pos); + void set_local_mat(const LMatrix4f &mat); + void set_material(const PhysxMaterial &material); + void set_material_index(unsigned short idx); + void set_groups_mask(const PhysxGroupsMask &mask); + + const char *get_name() const; + bool get_flag(const PhysxShapeFlag flag) const; float get_skin_width() const; - void get_world_bounds(PhysxBounds3 & dest) const; - const PhysxBoxShape * is_box() const; - const PhysxCapsuleShape * is_capsule() const; - const PhysxPlaneShape * is_plane() const; - const PhysxSphereShape * is_sphere() const; - void set_flag(PhysxShapeFlag flag, bool value); - void set_global_orientation(const LMatrix3f & mat); - void set_global_pose(const LMatrix4f & mat); - void set_global_position(const LVecBase3f & vec); - void set_group(unsigned short collision_group); - void set_local_orientation(const LMatrix3f & mat); - void set_local_pose(const LMatrix4f & mat); - void set_local_position(const LVecBase3f & vec); - void set_material(unsigned short mat_index); - void set_name(const char * name); - void set_skin_width(float skin_width); + unsigned short get_group() const; + LPoint3f get_local_pos() const; + LMatrix4f get_local_mat() const; + unsigned short get_material_index() const; + PhysxGroupsMask get_groups_mask() const; + PhysxBounds3 get_world_bounds() const; - INLINE void * get_app_data() const; + bool check_overlap_aabb(const PhysxBounds3 &world_bounds) const; + bool check_overlap_capsule(const PhysxCapsule &world_capsule) const; + bool check_overlap_obb(const PhysxBox &world_box) const; + bool check_overlap_sphere(const PhysxSphere &world_sphere) const; + PhysxRaycastHit raycast(const PhysxRay &worldRay, bool firstHit, bool smoothNormal) const; - INLINE void set_app_data( void * value ); + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; public: - NxShape *nShape; + static PT(PhysxShape) factory(NxShapeType shapeType); + virtual NxShape *ptr() const = 0; + + virtual void link(NxShape *shapePtr) = 0; + virtual void unlink() = 0; + +protected: + INLINE PhysxShape(); + +//////////////////////////////////////////////////////////////////// +public: static TypeHandle get_class_type() { return _type_handle; } static void init_type() { - TypedWritableReferenceCount::init_type(); - register_type(_type_handle, "PhysxShape", - TypedWritableReferenceCount::get_class_type()); + PhysxObject::init_type(); + register_type(_type_handle, "PhysxShape", + PhysxObject::get_class_type()); } virtual TypeHandle get_type() const { return get_class_type(); @@ -103,12 +108,8 @@ public: private: static TypeHandle _type_handle; - - string _name_store; }; #include "physxShape.I" -#endif // HAVE_PHYSX - #endif // PHYSXSHAPE_H diff --git a/panda/src/physx/physxShapeDesc.I b/panda/src/physx/physxShapeDesc.I index 8845c26096..cbacdb803e 100644 --- a/panda/src/physx/physxShapeDesc.I +++ b/panda/src/physx/physxShapeDesc.I @@ -1,5 +1,5 @@ // Filename: physxShapeDesc.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (08Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,129 +12,15 @@ // //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE bool PhysxShapeDesc:: -is_valid() const { - return nShapeDesc->isValid(); -} + //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxShapeDesc::Constructor +// Access: Protected +// Description: //////////////////////////////////////////////////////////////////// -INLINE void PhysxShapeDesc:: -set_to_default() { - nShapeDesc->setToDefault(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_density -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxShapeDesc:: -get_density() const { - return nShapeDesc->density; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_mass -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxShapeDesc:: -get_mass() const { - return nShapeDesc->mass; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_name -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE const char * PhysxShapeDesc:: -get_name() const { - return nShapeDesc->name; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_shape_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE unsigned int PhysxShapeDesc:: -get_shape_flags() const { - return nShapeDesc->shapeFlags; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_skin_width -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxShapeDesc:: -get_skin_width() const { - return nShapeDesc->skinWidth; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_density -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxShapeDesc:: -set_density(float value) { - nShapeDesc->density = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_mass -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxShapeDesc:: -set_mass(float value) { - nShapeDesc->mass = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_name -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxShapeDesc:: -set_name(const char * value) { - // Because the PhysX engine does not store its own copy of names, - // we keep a local copy on this instance. Otherwise, it would be - // very easy for names to be declared in python and then - // invalidated when the string is reclaimed from reference - // counting. - _name_store = value; - nShapeDesc->name = _name_store.c_str(); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_shape_flags -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxShapeDesc:: -set_shape_flags(unsigned int value) { - nShapeDesc->shapeFlags = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_skin_width -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxShapeDesc:: -set_skin_width(float value) { - nShapeDesc->skinWidth = value; +INLINE PhysxShapeDesc:: +PhysxShapeDesc() { + } diff --git a/panda/src/physx/physxShapeDesc.cxx b/panda/src/physx/physxShapeDesc.cxx index e991a31a2f..9f8b99aef7 100644 --- a/panda/src/physx/physxShapeDesc.cxx +++ b/panda/src/physx/physxShapeDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxShapeDesc.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (08Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,92 +12,289 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxShapeDesc.h" - -#include "luse.h" - +#include "physxManager.h" +#include "physxMaterial.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxShapeDesc -// Access : protected -// Description : +// Function: PhysxShapeDesc::set_name +// Access: Published +// Description: Sets a possible debug name. //////////////////////////////////////////////////////////////////// -PhysxShapeDesc:: -PhysxShapeDesc(NxShapeDesc *subShapeDesc) { - nShapeDesc = subShapeDesc; +void PhysxShapeDesc:: +set_name(const char *name) { + + ptr()->name = name; } //////////////////////////////////////////////////////////////////// -// Function : ~PhysxShapeDesc -// Access : Published -// Description : +// Function: PhysxShapeDesc::set_trigger +// Access: Published +// Description: This shape will become a trigger shape if this +// parameter is set to TRUE. It won't take part in +// collisions, but trigger events if some other +// shape passes through it. //////////////////////////////////////////////////////////////////// -PhysxShapeDesc:: -~PhysxShapeDesc() { +void PhysxShapeDesc:: +set_trigger(bool value) { + if (value == true) { + ptr()->shapeFlags |= NX_TRIGGER_ENABLE; + } + else { + ptr()->shapeFlags &= ~(NX_TRIGGER_ENABLE); + } } //////////////////////////////////////////////////////////////////// -// Function : get_group -// Access : Published -// Description : +// Function: PhysxShapeDesc::set_local_pos +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxShapeDesc:: +set_local_pos(const LPoint3f &pos) { + + nassertv(!pos.is_nan()); + ptr()->localPose.t = PhysxManager::point3_to_nxVec3(pos); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::set_local_mat +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxShapeDesc:: +set_local_mat(const LMatrix4f &mat) { + + nassertv(!mat.is_nan()); + ptr()->localPose = PhysxManager::mat4_to_nxMat34(mat); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::set_local_hpr +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxShapeDesc:: +set_local_hpr(float h, float p, float r) { + + LQuaternionf q; + LMatrix3f rot; + NxMat34 m; + + q.set_hpr(LVector3f(h, p, r)); + q.extract_to_matrix(rot); + + ptr()->localPose.M = PhysxManager::mat3_to_nxMat33(rot); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::set_skin_width +// Access: Published +// Description: Specifies by how much shapes can interpenetrate. +// +// Two shapes will interpenetrate by the sum of their +// skin widths. This means that their graphical +// representations should be adjusted so that they +// just touch when the shapes are interpenetrating. +// +// The default skin width is the 'physx-skin-width' +// parameter. +// +// A skin width sum of zero for two bodies is not +// permitted because it will lead to an unstable +// simulation. +// +// If your simulation jitters because resting bodies +// occasionally lose contact, increasing the size of +// your collision volumes and the skin width may +// improve things. +//////////////////////////////////////////////////////////////////// +void PhysxShapeDesc:: +set_skin_width(float skinWidth) { + + nassertv(skinWidth >= 0.0f); + ptr()->skinWidth = skinWidth; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::set_shape_flag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxShapeDesc:: +set_shape_flag(const PhysxShapeFlag flag, bool value) { + + if (value == true) { + ptr()->shapeFlags |= flag; + } + else { + ptr()->shapeFlags &= ~(flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::set_mass +// Access: Published +// Description: Sets the mass of this individual shape when +// computing mass inertial properties for a rigidbody. +// When mass<=0.0 then density and volume determine +// the mass. Note that this will only be used if the +// body has a zero inertia tensor, or if you call +// PhysxActor::update_mass_from_shapes explicitly. +//////////////////////////////////////////////////////////////////// +void PhysxShapeDesc:: +set_mass(float mass) { + + ptr()->mass = mass; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::set_density +// Access: Published +// Description: Sets the density of this individual shape when +// computing mass inertial properties for a rigidbody +// (unless a valid mass >0.0 is provided). Note that +// this will only be used if the body has a zero +// inertia tensor, or if you call +// PhysxActor::update_mass_from_shapes explicitly. +//////////////////////////////////////////////////////////////////// +void PhysxShapeDesc:: +set_density(float density) { + + nassertv(density > 0.0f); + ptr()->density = density; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::set_group +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxShapeDesc:: +set_group(unsigned short group) { + + ptr()->group = group; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::get_name +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +const char *PhysxShapeDesc:: +get_name() const { + + return ptr()->name; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::get_local_pos +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxShapeDesc:: +get_local_pos() const { + + return PhysxManager::nxVec3_to_point3(ptr()->localPose.t); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::get_local_mat +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LMatrix4f PhysxShapeDesc:: +get_local_mat() const { + + return PhysxManager::nxMat34_to_mat4(ptr()->localPose); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::get_skin_width +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxShapeDesc:: +get_skin_width() const { + + return ptr()->skinWidth; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::get_shape_flag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxShapeDesc:: +get_shape_flag(const PhysxShapeFlag flag) const { + + return (ptr()->shapeFlags & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::get_mass +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxShapeDesc:: +get_mass() const { + + return ptr()->mass; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::get_density +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxShapeDesc:: +get_density() const { + + return ptr()->density; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::get_group +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// unsigned short PhysxShapeDesc:: get_group() const { - return nShapeDesc->group; + + return ptr()->group; } //////////////////////////////////////////////////////////////////// -// Function : get_local_pose -// Access : Published -// Description : +// Function: PhysxShapeDesc::set_material +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -LMatrix4f PhysxShapeDesc:: -get_local_pose() const { - return PhysxManager::nxMat34_to_lMatrix4(nShapeDesc->localPose); +void PhysxShapeDesc:: +set_material(const PhysxMaterial &material) { + + ptr()->materialIndex = material.ptr()->getMaterialIndex(); } //////////////////////////////////////////////////////////////////// -// Function : get_material_index -// Access : Published -// Description : +// Function: PhysxShapeDesc::set_material_index +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxShapeDesc:: +set_material_index(unsigned short index) { + + ptr()->materialIndex = index; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShapeDesc::get_material_index +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// unsigned short PhysxShapeDesc:: get_material_index() const { - return nShapeDesc->materialIndex; + + return ptr()->materialIndex; } -//////////////////////////////////////////////////////////////////// -// Function : set_group -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxShapeDesc:: -set_group(unsigned short value) { - nShapeDesc->group = value; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_local_pose -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxShapeDesc:: -set_local_pose(LMatrix4f value) { - nShapeDesc->localPose = PhysxManager::lMatrix4_to_nxMat34(value); -} - -//////////////////////////////////////////////////////////////////// -// Function : set_material_index -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxShapeDesc:: -set_material_index(unsigned short value) { - nShapeDesc->materialIndex = value; -} - -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxShapeDesc.h b/panda/src/physx/physxShapeDesc.h index 876679f671..2ccf8097be 100644 --- a/panda/src/physx/physxShapeDesc.h +++ b/panda/src/physx/physxShapeDesc.h @@ -1,5 +1,5 @@ // Filename: physxShapeDesc.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (08Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,57 +15,59 @@ #ifndef PHYSXSHAPEDESC_H #define PHYSXSHAPEDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "lpoint3.h" +#include "lmatrix.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "physxEnums.h" +#include "NoMinMax.h" #include "NxPhysics.h" +class PhysxMaterial; + //////////////////////////////////////////////////////////////////// // Class : PhysxShapeDesc -// Description : +// Description : Abstract base class for shape descriptors. +// Descriptors for all the different shape types are +// derived from this class. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxShapeDesc { +class EXPCL_PANDAPHYSX PhysxShapeDesc : public PhysxEnums { + PUBLISHED: - ~PhysxShapeDesc(); + virtual void set_to_default() = 0; + virtual bool is_valid() const = 0; - INLINE bool is_valid() const; - INLINE void set_to_default(); + void set_name(const char *name); + void set_trigger(bool value); + void set_local_pos(const LPoint3f &pos); + void set_local_mat(const LMatrix4f &mat); + void set_local_hpr(float h, float p, float r); + void set_skin_width(float skinWidth); + void set_shape_flag(const PhysxShapeFlag flag, bool value); + void set_mass(float mass); + void set_density(float density); + void set_group(unsigned short group); + void set_material(const PhysxMaterial &material); + void set_material_index(unsigned short index); - INLINE float get_density() const; + const char *get_name() const; + LPoint3f get_local_pos() const; + LMatrix4f get_local_mat() const; + float get_skin_width() const; + bool get_shape_flag(const PhysxShapeFlag flag) const; + float get_mass() const; + float get_density() const; unsigned short get_group() const; - LMatrix4f get_local_pose() const; - INLINE float get_mass() const; unsigned short get_material_index() const; - INLINE const char * get_name() const; - INLINE unsigned int get_shape_flags() const; - INLINE float get_skin_width() const; - - INLINE void set_density( float value ); - void set_group(unsigned short value); - void set_local_pose( LMatrix4f value ); - INLINE void set_mass( float value ); - void set_material_index(unsigned short value); - INLINE void set_name( const char * value ); - INLINE void set_shape_flags( unsigned int value ); - INLINE void set_skin_width( float value ); public: - NxShapeDesc *nShapeDesc; + virtual NxShapeDesc *ptr() const = 0; protected: - PhysxShapeDesc(NxShapeDesc *subShapeDesc); - -private: - string _name_store; + INLINE PhysxShapeDesc(); }; #include "physxShapeDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXSHAPEDESC_H diff --git a/panda/src/physx/physxSphere.I b/panda/src/physx/physxSphere.I index 87c60037d2..fa527d071b 100644 --- a/panda/src/physx/physxSphere.I +++ b/panda/src/physx/physxSphere.I @@ -1,5 +1,5 @@ // Filename: physxSphere.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,64 +12,35 @@ // //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function : contains -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE bool PhysxSphere:: -contains(const LVecBase3f & min, const LVecBase3f & max) const { - nassertr(nSphere != NULL, false); - return nSphere->Contains(PhysxManager::lVecBase3_to_nxVec3(min), PhysxManager::lVecBase3_to_nxVec3(max)); +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphere::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphere:: +PhysxSphere() { + } //////////////////////////////////////////////////////////////////// -// Function : intersect -// Access : Published -// Description : +// Function: PhysxSphere::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxSphere:: -intersect(const PhysxSphere & sphere) const { - nassertr(nSphere != NULL, false); +INLINE PhysxSphere:: +PhysxSphere(const PhysxSphere &sphere) { - return nSphere->Intersect(*(sphere.nSphere)); + _sphere = sphere._sphere; } //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxSphere::Destructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxSphere:: -is_valid() const { - nassertr(nSphere != NULL, false); +INLINE PhysxSphere:: +~PhysxSphere() { - return nSphere->IsValid(); } -//////////////////////////////////////////////////////////////////// -// Function : get_radius -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE float PhysxSphere:: -get_radius() const { - nassertr(nSphere != NULL, -1.0f); - - return nSphere->radius; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_radius -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSphere:: -set_radius(float value) { - nassertv(nSphere != NULL); - - nSphere->radius = value; -} - - diff --git a/panda/src/physx/physxSphere.cxx b/panda/src/physx/physxSphere.cxx index 691b72a1d5..7c3309fe41 100644 --- a/panda/src/physx/physxSphere.cxx +++ b/panda/src/physx/physxSphere.cxx @@ -1,5 +1,5 @@ // Filename: physxSphere.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -12,57 +12,116 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxSphere.h" - -#include "luse.h" - +#include "physxManager.h" //////////////////////////////////////////////////////////////////// -// Function : PhysxSphere -// Access : Published -// Description : +// Function: PhysxSphere::is_valid +// Access: Published +// Description: Returns TRUE if this sphere is valid. //////////////////////////////////////////////////////////////////// -PhysxSphere:: -PhysxSphere(const PhysxSphere & sphere) { +bool PhysxSphere:: +is_valid() const { + return _sphere.IsValid(); } //////////////////////////////////////////////////////////////////// -// Function : ~PhysxSphere -// Access : Published -// Description : +// Function: PhysxSphere::contains +// Access: Published +// Description: Tests if a point is contained within the sphere. //////////////////////////////////////////////////////////////////// -PhysxSphere:: -~PhysxSphere() { +bool PhysxSphere:: +contains(const LPoint3f &p) const { + nassertr(!p.is_nan(), false); + + return _sphere.Contains(PhysxManager::vec3_to_nxVec3(p)); } //////////////////////////////////////////////////////////////////// -// Function : get_center -// Access : Published -// Description : +// Function: PhysxSphere::contains +// Access: Published +// Description: Tests if a sphere is contained within the sphere. //////////////////////////////////////////////////////////////////// -LVecBase3f PhysxSphere:: +bool PhysxSphere:: +contains(const PhysxSphere &sphere) const { + + return _sphere.Contains(sphere._sphere); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphere::contains +// Access: Published +// Description: Tests if an axis aligned box is contained within +// the sphere. The axis aligned box is defined by the +// minimum corner and the maximum corner. +//////////////////////////////////////////////////////////////////// +bool PhysxSphere:: +contains(const LPoint3f &min, const LPoint3f &max) const { + + nassertr(!min.is_nan(), false); + nassertr(!max.is_nan(), false); + + return _sphere.Contains(PhysxManager::vec3_to_nxVec3(min), + PhysxManager::vec3_to_nxVec3(max)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphere::intersect +// Access: Published +// Description: Tests if the sphere intersects another sphere. +// Returns TRUE if the spheres overlap. +//////////////////////////////////////////////////////////////////// +bool PhysxSphere:: +intersect(const PhysxSphere &sphere) const { + + return _sphere.Intersect(sphere._sphere); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphere::get_center +// Access: Published +// Description: Returns the center of the sphere. +//////////////////////////////////////////////////////////////////// +LPoint3f PhysxSphere:: get_center() const { - nassertr(nSphere != NULL, *((LVecBase3f *)NULL)); - return PhysxManager::nxVec3_to_lVecBase3(nSphere->center); + return PhysxManager::nxVec3_to_vec3(_sphere.center); } //////////////////////////////////////////////////////////////////// -// Function : set_center -// Access : Published -// Description : +// Function: PhysxSphere::set_center +// Access: Published +// Description: Sets the center of the sphere. //////////////////////////////////////////////////////////////////// void PhysxSphere:: -set_center(LVecBase3f value) { - nassertv(nSphere != NULL); +set_center(LPoint3f center) { - nSphere->center = PhysxManager::lVecBase3_to_nxVec3(value); + nassertv(!center.is_nan()); + + _sphere.center = PhysxManager::vec3_to_nxVec3(center); } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphere::get_radius +// Access: Published +// Description: Returns the sphere's radius. +//////////////////////////////////////////////////////////////////// +float PhysxSphere:: +get_radius() const { + return _sphere.radius; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphere::set_radius +// Access: Published +// Description: Sets the sphere's radius. +//////////////////////////////////////////////////////////////////// +void PhysxSphere:: +set_radius(float radius) { + + _sphere.radius = radius; +} diff --git a/panda/src/physx/physxSphere.h b/panda/src/physx/physxSphere.h index 22e7547f7b..cc927d499c 100644 --- a/panda/src/physx/physxSphere.h +++ b/panda/src/physx/physxSphere.h @@ -1,5 +1,5 @@ // Filename: physxSphere.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (31Oct09) // //////////////////////////////////////////////////////////////////// // @@ -15,41 +15,39 @@ #ifndef PHYSXSPHERE_H #define PHYSXSPHERE_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "lpoint3.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -#include "NxPhysics.h" +#include "config_physx.h" //////////////////////////////////////////////////////////////////// // Class : PhysxSphere -// Description : +// Description : Represents a sphere defined by its center point +// and radius. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxSphere { + PUBLISHED: - PhysxSphere(const PhysxSphere & sphere); - ~PhysxSphere(); + INLINE PhysxSphere(); + INLINE PhysxSphere(const PhysxSphere &sphere); + INLINE ~PhysxSphere(); - INLINE bool contains(const LVecBase3f & min, const LVecBase3f & max) const; - INLINE bool intersect(const PhysxSphere & sphere) const; - INLINE bool is_valid() const; + bool contains(const LPoint3f &p) const; + bool contains(const PhysxSphere &sphere) const; + bool contains(const LPoint3f &min, const LPoint3f &max) const; + bool intersect(const PhysxSphere &sphere) const; + bool is_valid() const; - LVecBase3f get_center() const; - INLINE float get_radius() const; + LPoint3f get_center() const; + float get_radius() const; - void set_center( LVecBase3f value ); - INLINE void set_radius( float value ); + void set_center(LPoint3f value); + void set_radius(float value); public: - NxSphere *nSphere; + NxSphere _sphere; }; #include "physxSphere.I" -#endif // HAVE_PHYSX - -#endif // PHYSXSPHERE_H +#endif // PHYSSPHERE_H diff --git a/panda/src/physx/physxSphereForceFieldShape.I b/panda/src/physx/physxSphereForceFieldShape.I new file mode 100644 index 0000000000..b31ee29b69 --- /dev/null +++ b/panda/src/physx/physxSphereForceFieldShape.I @@ -0,0 +1,36 @@ +// Filename: physxSphereForceFieldShape.I +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphereForceFieldShape:: +PhysxSphereForceFieldShape() : PhysxForceFieldShape() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphereForceFieldShape:: +~PhysxSphereForceFieldShape() { + +} + diff --git a/panda/src/physx/physxSphereForceFieldShape.cxx b/panda/src/physx/physxSphereForceFieldShape.cxx new file mode 100644 index 0000000000..c4e48a3f5f --- /dev/null +++ b/panda/src/physx/physxSphereForceFieldShape.cxx @@ -0,0 +1,87 @@ +// Filename: physxSphereForceFieldShape.cxx +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxSphereForceFieldShape.h" +#include "physxSphereForceFieldShapeDesc.h" + +TypeHandle PhysxSphereForceFieldShape::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShape::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxSphereForceFieldShape:: +link(NxForceFieldShape *shapePtr) { + + _ptr = shapePtr->isSphere(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)_ptr->getShapeGroup().userData; + group->_shapes.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShape::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxSphereForceFieldShape:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)_ptr->getShapeGroup().userData; + group->_shapes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxSphereForceFieldShape::save_to_desc +// Access : Published +// Description : Saves the state of the shape object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxSphereForceFieldShape:: +save_to_desc(PhysxSphereForceFieldShapeDesc &shapeDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShape::set_radius +// Access: Published +// Description: Sets the sphere radius. +//////////////////////////////////////////////////////////////////// +void PhysxSphereForceFieldShape:: +set_radius(float radius) { + + nassertv(_error_type == ET_ok); + _ptr->setRadius(radius); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShape::get_radius +// Access: Published +// Description: Returns the radius of the sphere. +//////////////////////////////////////////////////////////////////// +float PhysxSphereForceFieldShape:: +get_radius() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getRadius(); +} + diff --git a/panda/src/physx/physxSphereForceFieldShape.h b/panda/src/physx/physxSphereForceFieldShape.h new file mode 100644 index 0000000000..d9cfa932e4 --- /dev/null +++ b/panda/src/physx/physxSphereForceFieldShape.h @@ -0,0 +1,78 @@ +// Filename: physxSphereForceFieldShape.h +// Created by: enn0x (15Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXSPHEREFORCEFIELDSHAPE_H +#define PHYSXSPHEREFORCEFIELDSHAPE_H + +#include "pandabase.h" +#include "lvector3.h" + +#include "physxForceFieldShape.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxSphereForceFieldShapeDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxSphereForceFieldShape +// Description : A spherical force field shape. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxSphereForceFieldShape : public PhysxForceFieldShape { + +PUBLISHED: + INLINE PhysxSphereForceFieldShape(); + INLINE ~PhysxSphereForceFieldShape(); + + void save_to_desc(PhysxSphereForceFieldShapeDesc &shapeDesc) const; + + void set_radius(float radius); + + float get_radius() const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxForceFieldShape *ptr() const { return (NxForceFieldShape *)_ptr; }; + + void link(NxForceFieldShape *shapePtr); + void unlink(); + +private: + NxSphereForceFieldShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxForceFieldShape::init_type(); + register_type(_type_handle, "PhysxSphereForceFieldShape", + PhysxForceFieldShape::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxSphereForceFieldShape.I" + +#endif // PHYSXSPHEREFORCEFIELDSHAPE_H diff --git a/panda/src/physx/physxSphereForceFieldShapeDesc.I b/panda/src/physx/physxSphereForceFieldShapeDesc.I new file mode 100644 index 0000000000..6242acf5fe --- /dev/null +++ b/panda/src/physx/physxSphereForceFieldShapeDesc.I @@ -0,0 +1,59 @@ +// Filename: physxSphereForceFieldShapeDesc.I +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShapeDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphereForceFieldShapeDesc:: +PhysxSphereForceFieldShapeDesc() : PhysxForceFieldShapeDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphereForceFieldShapeDesc:: +~PhysxSphereForceFieldShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxSphereForceFieldShapeDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxSphereForceFieldShapeDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxSphereForceFieldShapeDesc.cxx b/panda/src/physx/physxSphereForceFieldShapeDesc.cxx new file mode 100644 index 0000000000..c94aa556e1 --- /dev/null +++ b/panda/src/physx/physxSphereForceFieldShapeDesc.cxx @@ -0,0 +1,38 @@ +// Filename: physxSphereForceFieldShapeDesc.cxx +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxSphereForceFieldShapeDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShapeDesc::set_radius +// Access: Published +// Description: Radius of shape. Must be positive. +//////////////////////////////////////////////////////////////////// +void PhysxSphereForceFieldShapeDesc:: +set_radius(float radius) { + + _desc.radius = radius; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereForceFieldShapeDesc::get_radius +// Access: Published +// Description: Radius of shape. +//////////////////////////////////////////////////////////////////// +float PhysxSphereForceFieldShapeDesc:: +get_radius() const { + + return _desc.radius; +} + diff --git a/panda/src/physx/physxSphereForceFieldShapeDesc.h b/panda/src/physx/physxSphereForceFieldShapeDesc.h new file mode 100644 index 0000000000..f288c0c2f3 --- /dev/null +++ b/panda/src/physx/physxSphereForceFieldShapeDesc.h @@ -0,0 +1,49 @@ +// Filename: physxSphereForceFieldShapeDesc.h +// Created by: enn0x (06Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXSPHEREFORCEFIELDSHAPEDESC_H +#define PHYSXSPHEREFORCEFIELDSHAPEDESC_H + +#include "pandabase.h" + +#include "physxForceFieldShapeDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxSphereForceFieldShapeDesc +// Description : A descriptor for a sphere force field shape. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxSphereForceFieldShapeDesc : public PhysxForceFieldShapeDesc { + +PUBLISHED: + INLINE PhysxSphereForceFieldShapeDesc(); + INLINE ~PhysxSphereForceFieldShapeDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_radius(float radius); + + float get_radius() const; + +public: + NxForceFieldShapeDesc *ptr() const { return (NxForceFieldShapeDesc *)&_desc; }; + NxSphereForceFieldShapeDesc _desc; +}; + +#include "physxSphereForceFieldShapeDesc.I" + +#endif // PHYSXSPHEREFORCEFIELDSHAPEDESC_H diff --git a/panda/src/physx/physxSphereShape.I b/panda/src/physx/physxSphereShape.I index 30bf5cfedf..d01268c3e9 100644 --- a/panda/src/physx/physxSphereShape.I +++ b/panda/src/physx/physxSphereShape.I @@ -1,5 +1,5 @@ // Filename: physxSphereShape.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,3 +12,25 @@ // //////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphereShape:: +PhysxSphereShape() : PhysxShape() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphereShape:: +~PhysxSphereShape() { + +} + diff --git a/panda/src/physx/physxSphereShape.cxx b/panda/src/physx/physxSphereShape.cxx index dbf7de0afe..afd4e2066f 100644 --- a/panda/src/physx/physxSphereShape.cxx +++ b/panda/src/physx/physxSphereShape.cxx @@ -1,5 +1,5 @@ // Filename: physxSphereShape.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,64 +12,76 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxSphereShape.h" - -#include "physxSphere.h" #include "physxSphereShapeDesc.h" TypeHandle PhysxSphereShape::_type_handle; //////////////////////////////////////////////////////////////////// -// Function : get_radius -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxSphereShape:: -get_radius() const { - nassertr(nSphereShape != NULL, -1.0f); - - return nSphereShape->getRadius(); -} - -//////////////////////////////////////////////////////////////////// -// Function : get_world_sphere -// Access : Published -// Description : +// Function: PhysxSphereShape::link +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// void PhysxSphereShape:: -get_world_sphere(PhysxSphere & world_sphere) const { - nassertv(nSphereShape != NULL); +link(NxShape *shapePtr) { - nSphereShape->getWorldSphere(*(world_sphere.nSphere)); + _ptr = shapePtr->isSphere(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.add(this); } //////////////////////////////////////////////////////////////////// -// Function : save_to_desc -// Access : Published -// Description : +// Function: PhysxSphereShape::unlink +// Access: Public +// Description: //////////////////////////////////////////////////////////////////// void PhysxSphereShape:: -save_to_desc(PhysxSphereShapeDesc & desc) const { - nassertv(nSphereShape != NULL); +unlink() { - nSphereShape->saveToDesc(desc.nSphereShapeDesc); + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.remove(this); } //////////////////////////////////////////////////////////////////// -// Function : set_radius +// Function : PhysxSphereShape::save_to_desc // Access : Published -// Description : +// Description : Saves the state of the shape object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxSphereShape:: +save_to_desc(PhysxSphereShapeDesc &shapeDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereShape::set_radius +// Access: Published +// Description: Sets the sphere radius. //////////////////////////////////////////////////////////////////// void PhysxSphereShape:: set_radius(float radius) { - nassertv(nSphereShape != NULL); - nSphereShape->setRadius(radius); + nassertv(_error_type == ET_ok); + _ptr->setRadius(radius); } -#endif // HAVE_PHYSX - +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereShape::get_radius +// Access: Published +// Description: Returns the radius of the sphere. +//////////////////////////////////////////////////////////////////// +float PhysxSphereShape:: +get_radius() const { + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getRadius(); +} diff --git a/panda/src/physx/physxSphereShape.h b/panda/src/physx/physxSphereShape.h index 6c492920f4..7857eafffb 100644 --- a/panda/src/physx/physxSphereShape.h +++ b/panda/src/physx/physxSphereShape.h @@ -1,5 +1,5 @@ // Filename: physxSphereShape.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (16Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,43 +15,62 @@ #ifndef PHYSXSPHERESHAPE_H #define PHYSXSPHERESHAPE_H -#ifdef HAVE_PHYSX - #include "pandabase.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "lvector3.h" #include "physxShape.h" -class PhysxSphere; -class PhysxSphereShapeDesc; - +#include "NoMinMax.h" #include "NxPhysics.h" +class PhysxSphereShapeDesc; + //////////////////////////////////////////////////////////////////// // Class : PhysxSphereShape -// Description : +// Description : A sphere shaped collision detection primitive. +// Each shape is owned by an actor that it is attached +// to. +// +// An instance can be created by calling the +// createShape() method of the PhysxActor object that +// should own it, with a PhysxSphereShapeDesc object +// as the parameter, or by adding the shape descriptor +// into the PhysxActorDesc class before creating the +// actor. +// +// The shape is deleted by calling release() on the +// shape itself. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxSphereShape : public PhysxShape { -PUBLISHED: - float get_radius() const; - void get_world_sphere(PhysxSphere & world_sphere) const; - void save_to_desc(PhysxSphereShapeDesc & desc) const; +PUBLISHED: + INLINE PhysxSphereShape(); + INLINE ~PhysxSphereShape(); + + void save_to_desc(PhysxSphereShapeDesc &shapeDesc) const; + void set_radius(float radius); + float get_radius() const; +//////////////////////////////////////////////////////////////////// public: - NxSphereShape *nSphereShape; + INLINE NxShape *ptr() const { return (NxShape *)_ptr; }; + void link(NxShape *shapePtr); + void unlink(); + +private: + NxSphereShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: static TypeHandle get_class_type() { return _type_handle; } static void init_type() { PhysxShape::init_type(); - register_type(_type_handle, "PhysxSphereShape", + register_type(_type_handle, "PhysxSphereShape", PhysxShape::get_class_type()); } virtual TypeHandle get_type() const { @@ -68,6 +87,4 @@ private: #include "physxSphereShape.I" -#endif // HAVE_PHYSX - #endif // PHYSXSPHERESHAPE_H diff --git a/panda/src/physx/physxSphereShapeDesc.I b/panda/src/physx/physxSphereShapeDesc.I index 3fd0eb6c31..89f5f9beee 100644 --- a/panda/src/physx/physxSphereShapeDesc.I +++ b/panda/src/physx/physxSphereShapeDesc.I @@ -1,5 +1,5 @@ // Filename: physxSphereShapeDesc.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (11Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,43 +12,48 @@ // //////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////// -// Function : is_valid -// Access : Published -// Description : +// Function: PhysxSphereShapeDesc::Constructor +// Access: Published +// Description: //////////////////////////////////////////////////////////////////// -INLINE bool PhysxSphereShapeDesc:: -is_valid() const { - return nSphereShapeDesc.isValid(); +INLINE PhysxSphereShapeDesc:: +PhysxSphereShapeDesc() : PhysxShapeDesc() { + + _desc.name = ""; } //////////////////////////////////////////////////////////////////// -// Function : set_to_default -// Access : Published -// Description : +// Function: PhysxSphereShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphereShapeDesc:: +~PhysxSphereShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. //////////////////////////////////////////////////////////////////// INLINE void PhysxSphereShapeDesc:: set_to_default() { - nSphereShapeDesc.setToDefault(); + + _desc.setToDefault(); } //////////////////////////////////////////////////////////////////// -// Function : get_radius -// Access : Published -// Description : +// Function: PhysxSphereShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. //////////////////////////////////////////////////////////////////// -INLINE float PhysxSphereShapeDesc:: -get_radius() const { - return nSphereShapeDesc.radius; -} - -//////////////////////////////////////////////////////////////////// -// Function : set_radius -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -INLINE void PhysxSphereShapeDesc:: -set_radius(float value) { - nSphereShapeDesc.radius = value; +INLINE bool PhysxSphereShapeDesc:: +is_valid() const { + + return _desc.isValid(); } diff --git a/panda/src/physx/physxSphereShapeDesc.cxx b/panda/src/physx/physxSphereShapeDesc.cxx index 33517e2199..755c29de87 100644 --- a/panda/src/physx/physxSphereShapeDesc.cxx +++ b/panda/src/physx/physxSphereShapeDesc.cxx @@ -1,5 +1,5 @@ // Filename: physxSphereShapeDesc.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (11Sep09) // //////////////////////////////////////////////////////////////////// // @@ -12,22 +12,27 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxSphereShapeDesc.h" - - //////////////////////////////////////////////////////////////////// -// Function : PhysxSphereShapeDesc -// Access : Published -// Description : +// Function: PhysxSphereShapeDesc::set_radius +// Access: Published +// Description: Radius of shape. Must be positive. //////////////////////////////////////////////////////////////////// -PhysxSphereShapeDesc:: -PhysxSphereShapeDesc() -: PhysxShapeDesc( &nSphereShapeDesc ) { +void PhysxSphereShapeDesc:: +set_radius(float radius) { + _desc.radius = radius; } -#endif // HAVE_PHYSX +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphereShapeDesc::get_radius +// Access: Published +// Description: Radius of shape. +//////////////////////////////////////////////////////////////////// +float PhysxSphereShapeDesc:: +get_radius() const { + + return _desc.radius; +} diff --git a/panda/src/physx/physxSphereShapeDesc.h b/panda/src/physx/physxSphereShapeDesc.h index 771e02f196..222c866380 100644 --- a/panda/src/physx/physxSphereShapeDesc.h +++ b/panda/src/physx/physxSphereShapeDesc.h @@ -1,5 +1,5 @@ // Filename: physxSphereShapeDesc.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (11Sep09) // //////////////////////////////////////////////////////////////////// // @@ -15,39 +15,35 @@ #ifndef PHYSXSPHERESHAPEDESC_H #define PHYSXSPHERESHAPEDESC_H -#ifdef HAVE_PHYSX - #include "pandabase.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - #include "physxShapeDesc.h" +#include "NoMinMax.h" #include "NxPhysics.h" //////////////////////////////////////////////////////////////////// // Class : PhysxSphereShapeDesc -// Description : +// Description : Descriptor class for PhysxSphereShape. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxSphereShapeDesc : public PhysxShapeDesc { + PUBLISHED: - PhysxSphereShapeDesc(); + INLINE PhysxSphereShapeDesc(); + INLINE ~PhysxSphereShapeDesc(); - INLINE bool is_valid() const; INLINE void set_to_default(); + INLINE bool is_valid() const; - INLINE float get_radius() const; + void set_radius(float radius); - INLINE void set_radius( float value ); + float get_radius() const; public: - NxSphereShapeDesc nSphereShapeDesc; + NxShapeDesc *ptr() const { return (NxShapeDesc *)&_desc; }; + NxSphereShapeDesc _desc; }; #include "physxSphereShapeDesc.I" -#endif // HAVE_PHYSX - #endif // PHYSXSPHERESHAPEDESC_H diff --git a/panda/src/physx/physxSphericalJoint.I b/panda/src/physx/physxSphericalJoint.I new file mode 100644 index 0000000000..271b869f63 --- /dev/null +++ b/panda/src/physx/physxSphericalJoint.I @@ -0,0 +1,36 @@ +// Filename: physxSphericalJoint.I +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJoint::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphericalJoint:: +PhysxSphericalJoint() : PhysxJoint() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJoint::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphericalJoint:: +~PhysxSphericalJoint() { + +} + diff --git a/panda/src/physx/physxSphericalJoint.cxx b/panda/src/physx/physxSphericalJoint.cxx new file mode 100644 index 0000000000..ba571e1506 --- /dev/null +++ b/panda/src/physx/physxSphericalJoint.cxx @@ -0,0 +1,133 @@ +// Filename: physxSphericalJoint.cxx +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxSphericalJoint.h" +#include "physxSphericalJointDesc.h" + +TypeHandle PhysxSphericalJoint::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJoint::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJoint:: +link(NxJoint *jointPtr) { + + _ptr = jointPtr->isSphericalJoint(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJoint::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJoint:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; + scene->_joints.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxSphericalJoint::save_to_desc +// Access : Published +// Description : Saves the state of the joint object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJoint:: +save_to_desc(PhysxSphericalJointDesc &jointDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxSphericalJoint::load_from_desc +// Access : Published +// Description : Loads the entire state of the joint from a +// descriptor with a single call. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJoint:: +load_from_desc(const PhysxSphericalJointDesc &jointDesc) { + + nassertv(_error_type == ET_ok); + _ptr->loadFromDesc(jointDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJoint::set_projection_mode +// Access: Published +// Description: Sets the joint projection mode. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJoint:: +set_projection_mode(PhysxProjectionMode mode) { + + nassertv(_error_type == ET_ok); + _ptr->setProjectionMode((NxJointProjectionMode)mode); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJoint::get_projection_mode +// Access: Published +// Description: Returns the current projection mode settings. +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxProjectionMode PhysxSphericalJoint:: +get_projection_mode() const { + + nassertr(_error_type == ET_ok, PM_none); + return (PhysxProjectionMode)_ptr->getProjectionMode(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJoint::set_flag +// Access: Published +// Description: Sets or clears a single SphericalJointFlag. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJoint:: +set_flag(PhysxSphericalJointFlag flag, bool value) { + + nassertv(_error_type == ET_ok); + NxU32 flags = _ptr->getFlags(); + + if (value == true) { + flags |= flag; + } + else { + flags &= ~(flag); + } + + _ptr->setFlags(flags); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJoint::get_flag +// Access: Published +// Description: Returns the value of a single SphericalJointFlag. +//////////////////////////////////////////////////////////////////// +bool PhysxSphericalJoint:: +get_flag(PhysxSphericalJointFlag flag) const { + + nassertr(_error_type == ET_ok, false); + return (_ptr->getFlags() & flag) ? true : false; +} + diff --git a/panda/src/physx/physxSphericalJoint.h b/panda/src/physx/physxSphericalJoint.h new file mode 100644 index 0000000000..a76c4b1541 --- /dev/null +++ b/panda/src/physx/physxSphericalJoint.h @@ -0,0 +1,84 @@ +// Filename: physxSphericalJoint.h +// Created by: enn0x (02Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXSPHERICALJOINT_H +#define PHYSXSPHERICALJOINT_H + +#include "pandabase.h" + +#include "physxJoint.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxSphericalJointDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxSphericalJoint +// Description : A sphere joint constrains two points on two bodies +// to coincide. This point, specified in world space +// (this guarantees that the points coincide to start +// with) is the only parameter that has to be +// specified. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxSphericalJoint : public PhysxJoint { + +PUBLISHED: + INLINE PhysxSphericalJoint(); + INLINE ~PhysxSphericalJoint(); + + void save_to_desc(PhysxSphericalJointDesc &jointDesc) const; + void load_from_desc(const PhysxSphericalJointDesc &jointDesc); + + void set_flag(PhysxSphericalJointFlag flag, bool value); + void set_projection_mode(PhysxProjectionMode mode); + + bool get_flag(PhysxSphericalJointFlag flag) const; + PhysxProjectionMode get_projection_mode() const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxJoint *ptr() const { return (NxJoint *)_ptr; }; + + void link(NxJoint *jointPtr); + void unlink(); + +private: + NxSphericalJoint *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxJoint::init_type(); + register_type(_type_handle, "PhysxSphericalJoint", + PhysxJoint::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxSphericalJoint.I" + +#endif // PHYSXSPHERICALJOINT_H diff --git a/panda/src/physx/physxSphericalJointDesc.I b/panda/src/physx/physxSphericalJointDesc.I new file mode 100644 index 0000000000..864d771e38 --- /dev/null +++ b/panda/src/physx/physxSphericalJointDesc.I @@ -0,0 +1,59 @@ +// Filename: physxSphericalJointDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphericalJointDesc:: +PhysxSphericalJointDesc() : PhysxJointDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSphericalJointDesc:: +~PhysxSphericalJointDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxSphericalJointDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxSphericalJointDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxSphericalJointDesc.cxx b/panda/src/physx/physxSphericalJointDesc.cxx new file mode 100644 index 0000000000..65a79c1a1a --- /dev/null +++ b/panda/src/physx/physxSphericalJointDesc.cxx @@ -0,0 +1,259 @@ +// Filename: physxSphericalJointDesc.cxx +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxSphericalJointDesc.h" +#include "physxManager.h" +#include "physxSpringDesc.h" +#include "physxJointLimitDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::set_projection_distance +// Access: Published +// Description: Set the distance above which to project joint. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJointDesc:: +set_projection_distance(float distance) { + + _desc.projectionDistance = distance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::set_flag +// Access: Published +// Description: Sets or clears a single SphericalJointFlag flag. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJointDesc:: +set_flag(PhysxSphericalJointFlag flag, bool value) { + + if (value == true) { + _desc.flags |= flag; + } + else { + _desc.flags &= ~(flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::set_twist_spring +// Access: Published +// Description: Sets a spring that works against twisting. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJointDesc:: +set_twist_spring(const PhysxSpringDesc &spring) { + + _desc.twistSpring = spring._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::set_swing_spring +// Access: Published +// Description: Sets a spring that works against swinging. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJointDesc:: +set_swing_spring(const PhysxSpringDesc &spring) { + + _desc.swingSpring = spring._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::set_joint_spring +// Access: Published +// Description: Sets a spring that lets the joint get pulled apart. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJointDesc:: +set_joint_spring(const PhysxSpringDesc &spring) { + + _desc.jointSpring = spring._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::set_swing_axis +// Access: Published +// Description: Set the swing limit axis defined in the joint +// space of actor 0. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJointDesc:: +set_swing_axis(const LVector3f &axis) { + + nassertv( !axis.is_nan() ); + _desc.swingAxis = PhysxManager::vec3_to_nxVec3(axis); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::set_projection_mode +// Access: Published +// Description: Use this to enable joint projection. +// Default is PM_none. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJointDesc:: +set_projection_mode(PhysxProjectionMode mode) { + + _desc.projectionMode = (NxJointProjectionMode)mode; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::set_twist_limit_low +// Access: Published +// Description: Limits rotation around twist axis. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJointDesc:: +set_twist_limit_low(const PhysxJointLimitDesc &low) { + + _desc.twistLimit.low = low._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::set_twist_limit_high +// Access: Published +// Description: Limits rotation around twist axis. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJointDesc:: +set_twist_limit_high(const PhysxJointLimitDesc &high) { + + _desc.twistLimit.high = high._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::set_swing_limit +// Access: Published +// Description: Limits swing of twist axis. +//////////////////////////////////////////////////////////////////// +void PhysxSphericalJointDesc:: +set_swing_limit(const PhysxJointLimitDesc &limit) { + + _desc.swingLimit = limit._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::get_projection_distance +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxSphericalJointDesc:: +get_projection_distance() const { + + return _desc.projectionDistance; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::get_flag +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxSphericalJointDesc:: +get_flag(PhysxSphericalJointFlag flag) const { + + return (_desc.flags & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::get_twist_spring +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxSpringDesc PhysxSphericalJointDesc:: +get_twist_spring() const { + + PhysxSpringDesc value; + value._desc = _desc.twistSpring; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::get_swing_spring +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxSpringDesc PhysxSphericalJointDesc:: +get_swing_spring() const { + + PhysxSpringDesc value; + value._desc = _desc.swingSpring; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::get_joint_spring +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxSpringDesc PhysxSphericalJointDesc:: +get_joint_spring() const { + + PhysxSpringDesc value; + value._desc = _desc.jointSpring; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::get_swing_axis +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LVector3f PhysxSphericalJointDesc:: +get_swing_axis() const { + + return PhysxManager::nxVec3_to_vec3(_desc.swingAxis); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::get_projection_mode +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxEnums::PhysxProjectionMode PhysxSphericalJointDesc:: +get_projection_mode() const { + + return (PhysxProjectionMode)_desc.projectionMode; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::get_twist_limit_low +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointLimitDesc PhysxSphericalJointDesc:: +get_twist_limit_low() const { + + PhysxJointLimitDesc value; + value._desc = _desc.twistLimit.low; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::get_twist_limit_high +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxJointLimitDesc PhysxSphericalJointDesc:: +get_twist_limit_high() const { + + PhysxJointLimitDesc value; + value._desc = _desc.twistLimit.high; + return value; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSphericalJointDesc::get_swing_limit +// Access: Published +// Description: Limits swing of twist axis. +//////////////////////////////////////////////////////////////////// +PhysxJointLimitDesc PhysxSphericalJointDesc:: +get_swing_limit() const { + + PhysxJointLimitDesc value; + value._desc = _desc.swingLimit; + return value; +} + diff --git a/panda/src/physx/physxSphericalJointDesc.h b/panda/src/physx/physxSphericalJointDesc.h new file mode 100644 index 0000000000..ba7f052e19 --- /dev/null +++ b/panda/src/physx/physxSphericalJointDesc.h @@ -0,0 +1,71 @@ +// Filename: physxSphericalJointDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXSPHERICALJOINTDESC_H +#define PHYSXSPHERICALJOINTDESC_H + +#include "pandabase.h" + +#include "physxJointDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxSpringDesc; +class PhysxJointLimitDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxSphericalJointDesc +// Description : Descriptor class for distance joint. See +// PhysxSphericalJoint. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxSphericalJointDesc : public PhysxJointDesc { + +PUBLISHED: + INLINE PhysxSphericalJointDesc(); + INLINE ~PhysxSphericalJointDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_projection_distance(float distance); + void set_flag(PhysxSphericalJointFlag flag, bool value); + void set_swing_axis(const LVector3f &axis); + void set_twist_spring(const PhysxSpringDesc &spring); + void set_swing_spring(const PhysxSpringDesc &spring); + void set_joint_spring(const PhysxSpringDesc &spring); + void set_twist_limit_low(const PhysxJointLimitDesc &low); + void set_twist_limit_high(const PhysxJointLimitDesc &high); + void set_swing_limit(const PhysxJointLimitDesc &limit); + void set_projection_mode(PhysxProjectionMode mode); + + float get_projection_distance() const; + bool get_flag(PhysxSphericalJointFlag flag) const; + LVector3f get_swing_axis() const; + PhysxSpringDesc get_twist_spring() const; + PhysxSpringDesc get_swing_spring() const; + PhysxSpringDesc get_joint_spring() const; + PhysxJointLimitDesc get_twist_limit_low() const; + PhysxJointLimitDesc get_twist_limit_high() const; + PhysxJointLimitDesc get_swing_limit() const; + PhysxProjectionMode get_projection_mode() const; + +public: + NxJointDesc *ptr() const { return (NxJointDesc *)&_desc; }; + NxSphericalJointDesc _desc; +}; + +#include "physxSphericalJointDesc.I" + +#endif // PHYSXSPHERICALJOINTDESC_H diff --git a/panda/src/physx/physxSpringDesc.I b/panda/src/physx/physxSpringDesc.I new file mode 100644 index 0000000000..26132d7117 --- /dev/null +++ b/panda/src/physx/physxSpringDesc.I @@ -0,0 +1,48 @@ +// Filename: physxSpringDesc.I +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSpringDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSpringDesc:: +PhysxSpringDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSpringDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSpringDesc:: +PhysxSpringDesc(float spring, float damper, float target) { + + _desc.spring = spring; + _desc.damper = damper; + _desc.targetValue = target; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSpringDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxSpringDesc:: +~PhysxSpringDesc() { + +} + diff --git a/panda/src/physx/physxSpringDesc.cxx b/panda/src/physx/physxSpringDesc.cxx new file mode 100644 index 0000000000..70604bba50 --- /dev/null +++ b/panda/src/physx/physxSpringDesc.cxx @@ -0,0 +1,82 @@ +// Filename: physxSpringDesc.cxx +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxSpringDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSpringDesc::set_spring +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxSpringDesc:: +set_spring(float spring) { + + _desc.spring = spring; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSpringDesc::set_damper +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxSpringDesc:: +set_damper(float damper) { + + _desc.damper = damper; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSpringDesc::set_target_value +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxSpringDesc:: +set_target_value(float targetValue) { + + _desc.targetValue = targetValue; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSpringDesc::get_spring +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxSpringDesc:: +get_spring() const { + + return _desc.spring; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSpringDesc::get_damper +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxSpringDesc:: +get_damper() const { + + return _desc.damper; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxSpringDesc::get_target_value +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxSpringDesc:: +get_target_value() const { + + return _desc.targetValue; +} + diff --git a/panda/src/physx/physxSpringDesc.h b/panda/src/physx/physxSpringDesc.h new file mode 100644 index 0000000000..f21b6231e4 --- /dev/null +++ b/panda/src/physx/physxSpringDesc.h @@ -0,0 +1,50 @@ +// Filename: physxSpringDesc.h +// Created by: enn0x (28Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXSPRINGDESC_H +#define PHYSXSPRINGDESC_H + +#include "pandabase.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxSpringDesc +// Description : Describes a joint spring. The spring is implicitly +// integrated, so even high spring and damper +// coefficients should be robust. +//////////////////////////////////////////////////////////////////// +class PhysxSpringDesc { + +PUBLISHED: + INLINE PhysxSpringDesc(); + INLINE PhysxSpringDesc(float spring, float damper=0, float targetValue=0); + INLINE ~PhysxSpringDesc(); + + void set_spring(float spring); + void set_damper(float damper); + void set_target_value(float target); + + float get_spring() const; + float get_damper() const; + float get_target_value() const; + +public: + NxSpringDesc _desc; +}; + +#include "physxSpringDesc.I" + +#endif // PHYSXSPRINGDESC_H diff --git a/panda/src/physx/physxTriangleMesh.I b/panda/src/physx/physxTriangleMesh.I new file mode 100644 index 0000000000..54f5d0a1c2 --- /dev/null +++ b/panda/src/physx/physxTriangleMesh.I @@ -0,0 +1,59 @@ +// Filename: physxTriangleMesh.I +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMesh::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxTriangleMesh:: +PhysxTriangleMesh() : PhysxObject() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMesh::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxTriangleMesh:: +~PhysxTriangleMesh() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMesh::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxTriangleMesh:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMesh::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxTriangleMesh:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " (at 0x" << this << ")\n"; +} + diff --git a/panda/src/physx/physxTriangleMesh.cxx b/panda/src/physx/physxTriangleMesh.cxx new file mode 100644 index 0000000000..a1a7000d5f --- /dev/null +++ b/panda/src/physx/physxTriangleMesh.cxx @@ -0,0 +1,76 @@ +// Filename: physxTriangleMesh.cxx +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxTriangleMesh.h" +#include "physxMeshPool.h" + +TypeHandle PhysxTriangleMesh::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMesh::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMesh:: +link(NxTriangleMesh *meshPtr) { + + // Link self + PhysxManager::get_global_ptr()->_triangle_meshes.add(this); + _ptr = meshPtr; + _error_type = ET_ok; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMesh::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMesh:: +unlink() { + + // Unlink self + _error_type = ET_released; + PhysxManager::get_global_ptr()->_triangle_meshes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMesh::release +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMesh:: +release() { + + nassertv(_error_type == ET_ok); + + unlink(); + NxGetPhysicsSDK()->releaseTriangleMesh(*_ptr); + _ptr = NULL; + + PhysxMeshPool::release_triangle_mesh(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMesh::get_reference_count +// Access: Published +// Description: Returns the reference count for shared meshes. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxTriangleMesh:: +get_reference_count() const { + + nassertr(_error_type == ET_ok, 0); + + return _ptr->getReferenceCount(); +} + diff --git a/panda/src/physx/physxTriangleMesh.h b/panda/src/physx/physxTriangleMesh.h new file mode 100644 index 0000000000..05001949f9 --- /dev/null +++ b/panda/src/physx/physxTriangleMesh.h @@ -0,0 +1,77 @@ +// Filename: physxTriangleMesh.h +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXTRIANGLEMESH_H +#define PHYSXTRIANGLEMESH_H + +#include "pandabase.h" + +#include "physxObject.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxTriangleMesh +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxTriangleMesh : public PhysxObject { + +PUBLISHED: + unsigned int get_reference_count() const; + +//////////////////////////////////////////////////////////////////// +PUBLISHED: + void release(); + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +public: + INLINE PhysxTriangleMesh(); + INLINE ~PhysxTriangleMesh(); + + INLINE NxTriangleMesh *ptr() const { return _ptr; }; + + void link(NxTriangleMesh *meshPtr); + void unlink(); + +private: + NxTriangleMesh *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxObject::init_type(); + register_type(_type_handle, "PhysxTriangleMesh", + PhysxObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxTriangleMesh.I" + +#endif // PHYSXTRIANGLEMESH_H diff --git a/panda/src/physx/physxTriangleMeshDesc.I b/panda/src/physx/physxTriangleMeshDesc.I new file mode 100644 index 0000000000..e6e98516fe --- /dev/null +++ b/panda/src/physx/physxTriangleMeshDesc.I @@ -0,0 +1,61 @@ +// Filename: physxTriangleMeshDesc.I +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshDesc::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxTriangleMeshDesc:: +PhysxTriangleMeshDesc() { + + _desc.flags = 0; + _desc.pointStrideBytes = sizeof(NxVec3); + _desc.triangleStrideBytes = 3*sizeof(NxU32); + _desc.points = NULL; + _desc.triangles = NULL; + + _vertices = NULL; + _triangles = NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshDesc::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxTriangleMeshDesc:: +~PhysxTriangleMeshDesc() { + + if (_vertices) { + delete [] _vertices; + } + + if (_triangles) { + delete [] _triangles; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxTriangleMeshDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxTriangleMeshDesc.cxx b/panda/src/physx/physxTriangleMeshDesc.cxx new file mode 100644 index 0000000000..ae01dd9580 --- /dev/null +++ b/panda/src/physx/physxTriangleMeshDesc.cxx @@ -0,0 +1,199 @@ +// Filename: physxTriangleMeshDesc.cxx +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxTriangleMeshDesc.h" +#include "physxManager.h" + +#include "nodePathCollection.h" +#include "geomNode.h" +#include "geomVertexReader.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshDesc::set_num_vertices +// Access: Published +// Description: Sets the number of vertices to be stored within +// this triangle mesh. The function allocates memory +// for the vertices, but it does not set any vertices. +// +// This method must be called before any calls to +// set_vertex are done! +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMeshDesc:: +set_num_vertices(unsigned int numVertices) { + + if (_desc.points) { + delete [] _vertices; + } + + _vertices = new NxVec3[numVertices]; + + _desc.numVertices = numVertices; + _desc.points = _vertices; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshDesc::set_vertex +// Access: Published +// Description: Sets a single vertex. You have to call the function +// set_num_vertices before you can call this function. +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMeshDesc:: +set_vertex(unsigned int idx, const LPoint3f &vert) { + + nassertv(_desc.numVertices > idx); + _vertices[idx] = PhysxManager::point3_to_nxVec3(vert); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshDesc::set_num_triangles +// Access: Published +// Description: Sets the number of triangles to be stored in this +// triangle mesh. +// +// This method must be called before any calls to +// set_triangle are done! +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMeshDesc:: +set_num_triangles(unsigned int numTriangles) { + + if (_desc.triangles) { + delete [] _triangles; + } + + _triangles = new NxU32[3 * numTriangles]; + + _desc.numTriangles = numTriangles; + _desc.triangles = _triangles; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshDesc::set_triangles +// Access: Published +// Description: Sets a single triangle, by providing the three +// indices i1, i2, i3. +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMeshDesc:: +set_triangle(unsigned int idx, unsigned int i1, unsigned int i2, unsigned int i3) { + + nassertv(_desc.numTriangles > idx); + + idx = 3 * idx; + _triangles[idx] = i1; + _triangles[idx + 1] = i2; + _triangles[idx + 2] = i3; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshDesc::get_desc +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +const NxTriangleMeshDesc &PhysxTriangleMeshDesc:: +get_desc() const { + + return _desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshDesc::set_from_node_path +// Access: Published +// Description: A convenience method to set the mesh data from +// a NodePath in a single call. The method iterates +// over the NodePath geoms and collects data for +// the triangle mesh. +// +// Do not use the following function when using this +// one: +// - set_num_vertices +// - set_vertex +// - set_num_triangles +// - set_triangle +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMeshDesc:: +set_from_node_path(const NodePath &np) { + + pvector dataVertices; + pvector dataIndices; + + // Collect data from NodePath + NodePathCollection npc = np.find_all_matches( "**/+GeomNode" ); + for (int i=0; iget_num_geoms(); j++) { + CPT(Geom) geom = gnode->get_geom(j); + + // Vertices + CPT(GeomVertexData) vdata = geom->get_vertex_data(); + GeomVertexReader reader = GeomVertexReader(vdata, InternalName::get_vertex()); + + while (!reader.is_at_end()) { + dataVertices.push_back(reader.get_data3f()); + } + + // Indices + for (int k=0; kget_num_primitives(); k++) { + + CPT(GeomPrimitive) prim = geom->get_primitive(k); + prim = prim->decompose(); + + for (int l=0; lget_num_primitives(); l++) { + + int s = prim->get_primitive_start(l); + int e = prim->get_primitive_end(l); + + for (int l=s; lget_vertex(l)); + } + } + } + } + } + + // Set descriptor members + int i; + + NxU32 numVertices = dataVertices.size(); + NxU32 numTriangles = dataIndices.size() / 3; + + _vertices = new NxVec3[numVertices]; + _triangles = new NxU32[3 * numTriangles]; + + i = 0; + pvector::const_iterator vit; + for (vit=dataVertices.begin(); vit!=dataVertices.end(); vit++) { + LPoint3f v = *vit; + + _vertices[i].x = v.get_x(); + _vertices[i].y = v.get_y(); + _vertices[i].z = v.get_z(); + i++; + } + + i = 0; + pvector::const_iterator iit; + for(iit=dataIndices.begin(); iit!=dataIndices.end(); iit++) { + NxU32 idx = *iit; + + _triangles[i] = idx; + i++; + } + + _desc.numVertices = numVertices; + _desc.points = _vertices; + _desc.numTriangles = numTriangles; + _desc.triangles = _triangles; +} + diff --git a/panda/src/physx/physxTriangleMeshDesc.h b/panda/src/physx/physxTriangleMeshDesc.h new file mode 100644 index 0000000000..f2c5d2bf1d --- /dev/null +++ b/panda/src/physx/physxTriangleMeshDesc.h @@ -0,0 +1,56 @@ +// Filename: physxTriangleMeshDesc.h +// Created by: enn0x (11Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXTRIANGLEMESHDESC_H +#define PHYSXTRIANGLEMESHDESC_H + +#include "pandabase.h" +#include "lpoint3.h" +#include "nodePath.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxTriangleMeshDesc +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxTriangleMeshDesc { + +PUBLISHED: + INLINE PhysxTriangleMeshDesc(); + INLINE ~PhysxTriangleMeshDesc(); + + INLINE bool is_valid() const; + + void set_num_vertices(unsigned int n); + void set_vertex(unsigned int idx, const LPoint3f &vert); + + void set_num_triangles(unsigned int n); + void set_triangle(unsigned int idx, unsigned int i1, unsigned int i2, unsigned int i3); + + void set_from_node_path(const NodePath &np); + +public: + const NxTriangleMeshDesc &get_desc() const; + +private: + NxVec3 *_vertices; + NxU32 *_triangles; + NxTriangleMeshDesc _desc; +}; + +#include "physxTriangleMeshDesc.I" + +#endif // PHYSXTRIANGLEMESHDESC_H diff --git a/panda/src/physx/physxTriangleMeshShape.I b/panda/src/physx/physxTriangleMeshShape.I new file mode 100644 index 0000000000..a1244f15e5 --- /dev/null +++ b/panda/src/physx/physxTriangleMeshShape.I @@ -0,0 +1,36 @@ +// Filename: physxTriangleMeshShape.I +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxTriangleMeshShape:: +PhysxTriangleMeshShape() : PhysxShape() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxTriangleMeshShape:: +~PhysxTriangleMeshShape() { + +} + diff --git a/panda/src/physx/physxTriangleMeshShape.cxx b/panda/src/physx/physxTriangleMeshShape.cxx new file mode 100644 index 0000000000..ed9a9968ce --- /dev/null +++ b/panda/src/physx/physxTriangleMeshShape.cxx @@ -0,0 +1,63 @@ +// Filename: physxTriangleMeshShape.cxx +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxTriangleMeshShape.h" +#include "physxTriangleMeshShapeDesc.h" + +TypeHandle PhysxTriangleMeshShape::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshShape::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMeshShape:: +link(NxShape *shapePtr) { + + _ptr = shapePtr->isTriangleMesh(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshShape::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMeshShape:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxTriangleMeshShape::save_to_desc +// Access : Published +// Description : Saves the state of the shape object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMeshShape:: +save_to_desc(PhysxTriangleMeshShapeDesc &shapeDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); +} + diff --git a/panda/src/physx/physxTriangleMeshShape.h b/panda/src/physx/physxTriangleMeshShape.h new file mode 100644 index 0000000000..934a1186f3 --- /dev/null +++ b/panda/src/physx/physxTriangleMeshShape.h @@ -0,0 +1,74 @@ +// Filename: physxTriangleMeshShape.h +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXTRIANGLEMESHSHAPE_H +#define PHYSXTRIANGLEMESHSHAPE_H + +#include "pandabase.h" + +#include "physxShape.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxTriangleMeshShapeDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxTriangleMeshShape +// Description : A shapes which is used to represent an instance of +// an convex mesh. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxTriangleMeshShape : public PhysxShape { + +PUBLISHED: + INLINE PhysxTriangleMeshShape(); + INLINE ~PhysxTriangleMeshShape(); + + void save_to_desc(PhysxTriangleMeshShapeDesc &shapeDesc) const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxShape *ptr() const { return (NxShape *)_ptr; }; + + void link(NxShape *shapePtr); + void unlink(); + +private: + NxTriangleMeshShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxShape::init_type(); + register_type(_type_handle, "PhysxTriangleMeshShape", + PhysxShape::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxTriangleMeshShape.I" + +#endif // PHYSXTRIANGLEMESHSHAPE_H diff --git a/panda/src/physx/physxTriangleMeshShapeDesc.I b/panda/src/physx/physxTriangleMeshShapeDesc.I new file mode 100644 index 0000000000..8d00b0cc2e --- /dev/null +++ b/panda/src/physx/physxTriangleMeshShapeDesc.I @@ -0,0 +1,59 @@ +// Filename: physxTriangleMeshShapeDesc.I +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshShapeDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxTriangleMeshShapeDesc:: +PhysxTriangleMeshShapeDesc() : PhysxShapeDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxTriangleMeshShapeDesc:: +~PhysxTriangleMeshShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxTriangleMeshShapeDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxTriangleMeshShapeDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxTriangleMeshShapeDesc.cxx b/panda/src/physx/physxTriangleMeshShapeDesc.cxx new file mode 100644 index 0000000000..48a9589d6b --- /dev/null +++ b/panda/src/physx/physxTriangleMeshShapeDesc.cxx @@ -0,0 +1,29 @@ +// Filename: physxTriangleMeshShapeDesc.cxx +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxTriangleMeshShapeDesc.h" +#include "physxTriangleMesh.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriangleMeshShapeDesc::set_mesh +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxTriangleMeshShapeDesc:: +set_mesh(PT(PhysxTriangleMesh) mesh) { + + _desc.meshData = mesh->ptr(); +} + + diff --git a/panda/src/physx/physxTriangleMeshShapeDesc.h b/panda/src/physx/physxTriangleMeshShapeDesc.h new file mode 100644 index 0000000000..6c92d2b79c --- /dev/null +++ b/panda/src/physx/physxTriangleMeshShapeDesc.h @@ -0,0 +1,49 @@ +// Filename: physxTriangleMeshShapeDesc.h +// Created by: enn0x (14Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXTRIANGLEMESHSHAPEDESC_H +#define PHYSXTRIANGLEMESHSHAPEDESC_H + +#include "pandabase.h" + +#include "physxShapeDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxTriangleMesh; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxTriangleMeshShapeDesc +// Description : Descriptor class for PhysxTriangleMeshShape. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxTriangleMeshShapeDesc : public PhysxShapeDesc { + +PUBLISHED: + INLINE PhysxTriangleMeshShapeDesc(); + INLINE ~PhysxTriangleMeshShapeDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_mesh(PT(PhysxTriangleMesh) mesh); + +public: + NxShapeDesc *ptr() const { return (NxShapeDesc *)&_desc; }; + NxTriangleMeshShapeDesc _desc; +}; + +#include "physxTriangleMeshShapeDesc.I" + +#endif // PHYSXTRIANGLEMESHSHAPEDESC_H diff --git a/panda/src/physx/physxTriggerHandler.cxx b/panda/src/physx/physxTriggerHandler.cxx deleted file mode 100644 index da81ff67c2..0000000000 --- a/panda/src/physx/physxTriggerHandler.cxx +++ /dev/null @@ -1,72 +0,0 @@ -// Filename: physxTriggerHandler.cxx -// Created by: pratt (May 16, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifdef HAVE_PHYSX - -#include "physxTriggerHandler.h" - -#include "eventParameter.h" -#include "throw_event.h" - -//////////////////////////////////////////////////////////////////// -// Function : clear_events -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxTriggerHandler:: -clear_events() { - events.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function : throw_events -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxTriggerHandler:: -throw_events() { - pvector::const_iterator events_iter; - PhysxTriggerEvent event; - string on_enter_name = "physxOnTriggerEnter"; - string on_leave_name = "physxOnTriggerLeave"; - string on_stay_name = "physxOnTriggerStay"; - for(events_iter = events.begin(); events_iter != events.end(); ++events_iter) { - event = *events_iter; - PT(PhysxShape) pTriggerShape = (PhysxShape *)event.nTriggerShape->userData; - PT(PhysxShape) pOtherShape = (PhysxShape *)event.nOtherShape->userData; - if(event.status & NX_TRIGGER_ON_ENTER) { - throw_event(on_enter_name, EventParameter(pTriggerShape), EventParameter(pOtherShape)); - } else if(event.status & NX_TRIGGER_ON_LEAVE) { - throw_event(on_leave_name, EventParameter(pTriggerShape), EventParameter(pOtherShape)); - } else if(event.status & NX_TRIGGER_ON_STAY) { - throw_event(on_stay_name, EventParameter(pTriggerShape), EventParameter(pOtherShape)); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function : onTrigger -// Access : public -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxTriggerHandler:: -onTrigger(NxShape &nTriggerShape, NxShape &nOtherShape, NxTriggerFlag status) { - PhysxTriggerEvent event; - event.nTriggerShape = &nTriggerShape; - event.nOtherShape = &nOtherShape; - event.status = status; - events.push_back(event); -} - -#endif // HAVE_PHYSX diff --git a/panda/src/physx/physxTriggerHandler.h b/panda/src/physx/physxTriggerHandler.h deleted file mode 100644 index 43969f5be5..0000000000 --- a/panda/src/physx/physxTriggerHandler.h +++ /dev/null @@ -1,57 +0,0 @@ -// Filename: physxTriggerHandler.h -// Created by: pratt (May 16, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifndef PHYSXTRIGGERHANDLER_H -#define PHYSXTRIGGERHANDLER_H - -#ifdef HAVE_PHYSX - -#include "pandabase.h" -#include "pvector.h" - -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" - -class PhysxShape; - -#include "NxPhysics.h" - -//////////////////////////////////////////////////////////////////// -// Class : PhysxTriggerHandler -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDAPHYSX PhysxTriggerHandler : public NxUserTriggerReport { -PUBLISHED: - void clear_events(); - void throw_events(); - -public: - void onTrigger(NxShape &nTriggerShape, NxShape &nOtherShape, NxTriggerFlag status); - -private: - struct PhysxTriggerEvent { - NxShape *nTriggerShape; - NxShape *nOtherShape; - NxTriggerFlag status; - }; - - pvector events; -}; - -#include "physxTriggerHandler.I" - -#endif // HAVE_PHYSX - -#endif // PHYSXTRIGGERHANDLER_H diff --git a/panda/src/physx/physxTriggerReport.I b/panda/src/physx/physxTriggerReport.I new file mode 100644 index 0000000000..d52b3989bb --- /dev/null +++ b/panda/src/physx/physxTriggerReport.I @@ -0,0 +1,36 @@ +// Filename: physxTriggerReport.I +// Created by: enn0x (19Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriggerReport::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxTriggerReport:: +PhysxTriggerReport() : NxUserTriggerReport() { + + _enabled = false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriggerReport::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxTriggerReport:: +~PhysxTriggerReport() { + +} + diff --git a/panda/src/physx/physxTriggerReport.cxx b/panda/src/physx/physxTriggerReport.cxx new file mode 100644 index 0000000000..b00483fbd1 --- /dev/null +++ b/panda/src/physx/physxTriggerReport.cxx @@ -0,0 +1,93 @@ +// Filename: physxTriggerReport.cxx +// Created by: enn0x (19Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxTriggerReport.h" + +#include "event.h" +#include "eventQueue.h" +#include "eventParameter.h" + +PStatCollector PhysxTriggerReport::_pcollector("App:PhysX:Trigger Reporting"); + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriggerReport::enable +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxTriggerReport:: +enable() { + + _enabled = true; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriggerReport::disable +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxTriggerReport:: +disable() { + + _enabled = false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriggerReport::is_enabled +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +bool PhysxTriggerReport:: +is_enabled() const { + + return _enabled; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxTriggerReport::onTrigger +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxTriggerReport:: +onTrigger(NxShape &triggerShape, NxShape &otherShape, NxTriggerFlag status) { + + if (!_enabled) { + return; + } + + _pcollector.start(); + + Event *event; + if (status & NX_TRIGGER_ON_ENTER) { + event = new Event("physx-trigger-enter"); + } + else if (status & NX_TRIGGER_ON_LEAVE) { + event = new Event("physx-trigger-leave"); + } + else if (status & NX_TRIGGER_ON_STAY) { + event = new Event("physx-trigger-stay"); + } + else { + return; + } + + PT(PhysxShape) pTriggerShape = (PhysxShape *)triggerShape.userData; + PT(PhysxShape) pOtherShape = (PhysxShape *)otherShape.userData; + event->add_parameter(EventParameter(pTriggerShape)); + event->add_parameter(EventParameter(pOtherShape)); + + EventQueue::get_global_event_queue()->queue_event(event); + + _pcollector.stop(); +} + diff --git a/panda/src/physx/physxTriggerReport.h b/panda/src/physx/physxTriggerReport.h new file mode 100644 index 0000000000..2a645f7148 --- /dev/null +++ b/panda/src/physx/physxTriggerReport.h @@ -0,0 +1,48 @@ +// Filename: physxTriggerReport.h +// Created by: enn0x (19Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXTRIGGERREPORT_H +#define PHYSXTRIGGERREPORT_H + +#include "pandabase.h" +#include "pStatCollector.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxTriggerReport +// Description : Implementation of the NxUserTriggerReport +// interface. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxTriggerReport : public NxUserTriggerReport { + +public: + INLINE PhysxTriggerReport(); + INLINE ~PhysxTriggerReport(); + + void enable(); + void disable(); + bool is_enabled() const; + + void onTrigger(NxShape &triggerShape, NxShape &otherShape, NxTriggerFlag status); + +private: + bool _enabled; + static PStatCollector _pcollector; +}; + +#include "physxTriggerReport.I" + +#endif // PHYSXTRIGGERREPORT_H diff --git a/panda/src/physx/physxUtilLib.I b/panda/src/physx/physxUtilLib.I index 7cb067ecb3..df1c0449d2 100644 --- a/panda/src/physx/physxUtilLib.I +++ b/panda/src/physx/physxUtilLib.I @@ -1,5 +1,5 @@ // Filename: physxUtilLib.I -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (01Nov09) // //////////////////////////////////////////////////////////////////// // @@ -12,3 +12,26 @@ // //////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxUtilLib:: +PhysxUtilLib() { + + _ptr = NxGetUtilLib(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxUtilLib:: +~PhysxUtilLib() { + + _ptr = NULL; +} + diff --git a/panda/src/physx/physxUtilLib.cxx b/panda/src/physx/physxUtilLib.cxx index fa98daae2c..161e84c9a8 100644 --- a/panda/src/physx/physxUtilLib.cxx +++ b/panda/src/physx/physxUtilLib.cxx @@ -1,5 +1,5 @@ // Filename: physxUtilLib.cxx -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (01Nov09) // //////////////////////////////////////////////////////////////////// // @@ -12,852 +12,1061 @@ // //////////////////////////////////////////////////////////////////// -#ifdef HAVE_PHYSX - #include "physxUtilLib.h" - -#include "luse.h" +#include "physxManager.h" #include "physxBounds3.h" #include "physxBox.h" #include "physxCapsule.h" -#include "physxJointDesc.h" #include "physxPlane.h" #include "physxRay.h" #include "physxSegment.h" #include "physxSphere.h" - //////////////////////////////////////////////////////////////////// -// Function : physx_box_box_intersect -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_box_box_intersect(const LVecBase3f & extents0, const LVecBase3f & center0, const LMatrix3f & rotation0, const LVecBase3f & extents1, const LVecBase3f & center1, const LMatrix3f & rotation1, bool full_test) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxBoxBoxIntersect(PhysxManager::lVecBase3_to_nxVec3(extents0), PhysxManager::lVecBase3_to_nxVec3(center0), PhysxManager::lMatrix3_to_nxMat33(rotation0), PhysxManager::lVecBase3_to_nxVec3(extents1), PhysxManager::lVecBase3_to_nxVec3(center1), PhysxManager::lMatrix3_to_nxMat33(rotation1), full_test); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_box_contains_point -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_box_contains_point(const PhysxBox & box, const LVecBase3f & p) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxBoxContainsPoint(*(box.nBox), PhysxManager::lVecBase3_to_nxVec3(p)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_box_vertex_to_quad -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -const unsigned int * PhysxUtilLib:: -physx_box_vertex_to_quad(unsigned int vertex_index) { - nassertr(nUtilLib != NULL, NULL); - - return nUtilLib->NxBoxVertexToQuad(vertex_index); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_build_smooth_normals -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_build_smooth_normals(unsigned int nb_tris, unsigned int nb_verts, const LVecBase3f * verts, const unsigned int * d_faces, const unsigned short * w_faces, LVecBase3f * normals, bool flip) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxBuildSmoothNormals(nb_tris, nb_verts, &PhysxManager::lVecBase3_to_nxVec3(*verts), d_faces, w_faces, &PhysxManager::lVecBase3_to_nxVec3(*normals), flip); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_compute_bounds -// Access : Published -// Description : +// Function: PhysxUtilLib::set_fpu_exceptions +// Access: Published +// Description: Set FPU precision. //////////////////////////////////////////////////////////////////// void PhysxUtilLib:: -physx_compute_bounds(LVecBase3f & min, LVecBase3f & max, unsigned int nb_verts, const LVecBase3f * verts) { - nassertv(nUtilLib != NULL); +set_fpu_exceptions(bool b) { - nUtilLib->NxComputeBounds(PhysxManager::lVecBase3_to_nxVec3(min), PhysxManager::lVecBase3_to_nxVec3(max), nb_verts, &PhysxManager::lVecBase3_to_nxVec3(*verts)); + _ptr->NxSetFPUExceptions(b); } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_box_around_capsule -// Access : Published -// Description : +// Function: PhysxUtilLib::set_fpu_precision24 +// Access: Published +// Description: Set FPU precision. //////////////////////////////////////////////////////////////////// void PhysxUtilLib:: -physx_compute_box_around_capsule(const PhysxCapsule & capsule, PhysxBox & box) { - nassertv(nUtilLib != NULL); +set_fpu_precision24() { - nUtilLib->NxComputeBoxAroundCapsule(*(capsule.nCapsule), *(box.nBox)); + _ptr->NxSetFPUPrecision24(); } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_box_density -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_box_density(const LVecBase3f & extents, float mass) { - nassertr(nUtilLib != NULL, -1.0f); - - return nUtilLib->NxComputeBoxDensity(PhysxManager::lVecBase3_to_nxVec3(extents), mass); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_compute_box_inertia_tensor -// Access : Published -// Description : +// Function: PhysxUtilLib::set_fpu_precision53 +// Access: Published +// Description: Set FPU precision. //////////////////////////////////////////////////////////////////// void PhysxUtilLib:: -physx_compute_box_inertia_tensor(LVecBase3f & diag_inertia, float mass, float xlength, float ylength, float zlength) { - nassertv(nUtilLib != NULL); +set_fpu_precision53() { - nUtilLib->NxComputeBoxInertiaTensor(PhysxManager::lVecBase3_to_nxVec3(diag_inertia), mass, xlength, ylength, zlength); + _ptr->NxSetFPUPrecision53(); } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_box_mass -// Access : Published -// Description : +// Function: PhysxUtilLib::set_fpu_precision64 +// Access: Published +// Description: Set FPU precision. //////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_box_mass(const LVecBase3f & extents, float density) { - nassertr(nUtilLib != NULL, -1.0f); +void PhysxUtilLib:: +set_fpu_precision64() { - return nUtilLib->NxComputeBoxMass(PhysxManager::lVecBase3_to_nxVec3(extents), density); + _ptr->NxSetFPUPrecision64(); } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_box_planes -// Access : Published -// Description : +// Function: PhysxUtilLib::set_fpu_rounding_chop +// Access: Published +// Description: Set FPU precision. +//////////////////////////////////////////////////////////////////// +void PhysxUtilLib:: +set_fpu_rounding_chop() { + + _ptr->NxSetFPURoundingChop(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::set_fpu_rounding_down +// Access: Published +// Description: Set FPU rounding mode. +//////////////////////////////////////////////////////////////////// +void PhysxUtilLib:: +set_fpu_rounding_down() { + + _ptr->NxSetFPURoundingDown(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::set_fpu_rounding_near +// Access: Published +// Description: Set FPU rounding mode. +//////////////////////////////////////////////////////////////////// +void PhysxUtilLib:: +set_fpu_rounding_near() { + + _ptr->NxSetFPURoundingNear(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::set_fpu_rounding_up +// Access: Published +// Description: Set FPU rounding mode. +//////////////////////////////////////////////////////////////////// +void PhysxUtilLib:: +set_fpu_rounding_up() { + + _ptr->NxSetFPURoundingUp(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::int_ceil +// Access: Published +// Description: Convert a floating point number to an integer. +//////////////////////////////////////////////////////////////////// +int PhysxUtilLib:: +int_ceil(const float &f) { + + return _ptr->NxIntCeil(f); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::int_chop +// Access: Published +// Description: Convert a floating point number to an integer. +//////////////////////////////////////////////////////////////////// +int PhysxUtilLib:: +int_chop(const float &f) { + + return _ptr->NxIntChop(f); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::int_floor +// Access: Published +// Description: Convert a floating point number to an integer. +//////////////////////////////////////////////////////////////////// +int PhysxUtilLib:: +int_floor(const float &f) { + + return _ptr->NxIntFloor(f); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::box_contains_point +// Access: Published +// Description: Test if an oriented box contains a point. +// +// \param [in] box +// \param [in] p //////////////////////////////////////////////////////////////////// bool PhysxUtilLib:: -physx_compute_box_planes(const PhysxBox & box, PhysxPlane * planes) { - nassertr(nUtilLib != NULL, false); +box_contains_point(const PhysxBox &box, const LPoint3f &p) { - return nUtilLib->NxComputeBoxPlanes(*(box.nBox), planes->nPlane); + return _ptr->NxBoxContainsPoint(box._box, PhysxManager::point3_to_nxVec3(p)); } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_box_points -// Access : Published -// Description : +// Function: PhysxUtilLib::create_box +// Access: Published +// Description: Create an oriented box from an axis aligned box +// and a transformation. +// +// \param [in] aabb +// \param [in] mat +//////////////////////////////////////////////////////////////////// +PhysxBox PhysxUtilLib:: +create_box(const PhysxBounds3 &aabb, const LMatrix4f &mat) { + + PhysxBox box; + _ptr->NxCreateBox(box._box, aabb._bounds, PhysxManager::mat4_to_nxMat34(mat)); + return box; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_box_world_edge_normal +// Access: Published +// Description: Compute and edge normals for an oriented box. This +// is an averaged normal, from the two faces sharing +// the edge. The edge index should be from 0 to 11 +// (i.e. a box has 12 edges). +// +// \param [in] box +// \param [in] edge_index +//////////////////////////////////////////////////////////////////// +LVector3f PhysxUtilLib:: +compute_box_world_edge_normal(const PhysxBox &box, unsigned int edge_index) { + + NxVec3 nNormal; + + nassertr(edge_index < 12, LVector3f::zero()); + + _ptr->NxComputeBoxWorldEdgeNormal(box._box, edge_index, nNormal); + return PhysxManager::nxVec3_to_vec3(nNormal); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_capsule_around_box +// Access: Published +// Description: Compute a capsule which encloses a box. +// +// \param [in] box +//////////////////////////////////////////////////////////////////// +PhysxCapsule PhysxUtilLib:: +compute_capsule_around_box(const PhysxBox &box) { + + PhysxCapsule capsule; + _ptr->NxComputeCapsuleAroundBox(box._box, capsule._capsule); + return capsule; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::is_box_a_inside_box_b +// Access: Published +// Description: Test if box A is inside another box B. Returns +// TRUE if box A is inside box B. +// +// \param [in] a +// \param [in] b //////////////////////////////////////////////////////////////////// bool PhysxUtilLib:: -physx_compute_box_points(const PhysxBox & box, LVecBase3f * pts) { - nassertr(nUtilLib != NULL, false); +is_box_a_inside_box_b(const PhysxBox &a, const PhysxBox &b) { - return nUtilLib->NxComputeBoxPoints(*(box.nBox), &PhysxManager::lVecBase3_to_nxVec3(*pts)); + return _ptr->NxIsBoxAInsideBoxB(a._box, b._box); } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_box_vertex_normals -// Access : Published -// Description : +// Function: PhysxUtilLib::compute_box_around_capsule +// Access: Published +// Description: Compute a box which encloses a capsule. +// +// \param [in] capsule +//////////////////////////////////////////////////////////////////// +PhysxBox PhysxUtilLib:: +compute_box_around_capsule(const PhysxCapsule &capsule) { + + PhysxBox box; + _ptr->NxComputeBoxAroundCapsule(capsule._capsule, box._box); + return box; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_distance_squared +// Access: Published +// Description: Compute the distance squared from a point to a +// ray. +// +// \param [in] ray +// \param [in] point +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_distance_squared(const PhysxRay &ray, const LPoint3f &point) { + + NxF32 t; // not used + return _ptr->NxComputeDistanceSquared(ray._ray, PhysxManager::point3_to_nxVec3(point), &t); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_square_distance +// Access: Published +// Description: Compute the distance squared from a point to a +// line segment. +// +// \param [in] seg +// \param [in] point +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_square_distance(const PhysxSegment &seg, const LPoint3f &point) { + + NxF32 t; // not used + return _ptr->NxComputeSquareDistance(seg._segment, PhysxManager::point3_to_nxVec3(point), &t); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::merge_spheres +// Access: Published +// Description: Compute an overall bounding sphere for a pair of +// spheres. +// +// \param [in] sphere0 +// \param [in] sphere1 +//////////////////////////////////////////////////////////////////// +PhysxSphere PhysxUtilLib:: +merge_spheres(const PhysxSphere &sphere0, const PhysxSphere &sphere1) { + + PhysxSphere merged; + _ptr->NxMergeSpheres(merged._sphere, sphere0._sphere, sphere1._sphere); + return merged; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::normal_to_tangents +// Access: Published +// Description: Get the tangent vectors associated with a normal. +// +// \param [in] n +// \param [out] t1 +// \param [out] t2 +//////////////////////////////////////////////////////////////////// +void PhysxUtilLib:: +normal_to_tangents(const LVector3f &n, LVector3f &t1, LVector3f &t2) { + + NxVec3 nt1; + NxVec3 nt2; + + _ptr->NxNormalToTangents(PhysxManager::vec3_to_nxVec3(n), nt1, nt2); + + t1.set_x(nt1.x); + t1.set_y(nt1.y); + t1.set_z(nt1.z); + + t2.set_x(nt2.x); + t2.set_y(nt2.y); + t2.set_z(nt2.z); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::find_rotation_matrix +// Access: Published +// Description: Computes a rotation matrix M so that: M * x = b +// (x and b are unit vectors). +// +// \param [in] x +// \param [in] b +//////////////////////////////////////////////////////////////////// +LMatrix3f PhysxUtilLib:: +find_rotation_matrix(const LVector3f &x, const LVector3f &b) { + + NxMat33 nmat; + _ptr->NxFindRotationMatrix(PhysxManager::vec3_to_nxVec3(x), + PhysxManager::vec3_to_nxVec3(b), + nmat); + return PhysxManager::nxMat33_to_mat3(nmat); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_sphere_mass +// Access: Published +// Description: Computes mass of a homogeneous sphere according +// to sphere density. +// +// \param [in] radius +// \param [in] density +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_sphere_mass(float radius, float density) { + + return _ptr->NxComputeSphereMass(radius, density); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_sphere_density +// Access: Published +// Description: Computes density of a homogeneous sphere according +// to sphere mass +// +// \param [in] radius +// \param [in] mass +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_sphere_density(float radius, float mass) { + + return _ptr->NxComputeSphereDensity(radius, mass); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_box_mass +// Access: Published +// Description: Computes mass of a homogeneous box according to +// box density. +// +// \param [in] radius +// \param [in] density +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_box_mass(const LVector3f &extents, float density) { + + return _ptr->NxComputeBoxMass(PhysxManager::vec3_to_nxVec3(extents), density); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_box_density +// Access: Published +// Description: Computes density of a homogeneous box according to +// box mass. +// +// \param [in] radius +// \param [in] mass +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_box_density(const LVector3f &extents, float mass) { + + return _ptr->NxComputeBoxDensity(PhysxManager::vec3_to_nxVec3(extents), mass); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_ellipsoid_mass +// Access: Published +// Description: Computes mass of a homogeneous ellipsoid according +// to ellipsoid density. +// +// \param [in] radius +// \param [in] density +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_ellipsoid_mass(const LVector3f &extents, float density ) { + + return _ptr->NxComputeEllipsoidMass(PhysxManager::vec3_to_nxVec3(extents), density); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_ellipsoid_density +// Access: Published +// Description: Computes density of a homogeneous ellipsoid +// according to ellipsoid mass. +// +// \param [in] radius +// \param [in] mass +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_ellipsoid_density(const LVector3f &extents, float mass) { + + return _ptr->NxComputeEllipsoidDensity(PhysxManager::vec3_to_nxVec3(extents), mass); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_cylinder_mass +// Access: Published +// Description: Computes mass of a homogeneous cylinder according +// to cylinder density. +// +// \param [in] radius +// \param [in] density +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_cylinder_mass(float radius, float length, float density) { + + return _ptr->NxComputeCylinderMass(radius, length, density); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_cylinder_density +// Access: Published +// Description: Computes density of a homogeneous cylinder +// according to cylinder mass. +// +// \param [in] radius +// \param [in] mass +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_cylinder_density(float radius, float length, float mass) { + + return _ptr->NxComputeCylinderDensity(radius, length, mass); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_cone_mass +// Access: Published +// Description: Computes mass of a homogeneous cone according to +// cone density. +// +// \param [in] radius +// \param [in] density +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_cone_mass(float radius, float length, float density) { + + return _ptr->NxComputeConeMass(radius, length, density); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_cone_density +// Access: Published +// Description: Computes density of a homogeneous cone according +// to cone mass. +// +// \param [in] radius +// \param [in] mass +//////////////////////////////////////////////////////////////////// +float PhysxUtilLib:: +compute_cone_density(float radius, float length, float mass) { + + return _ptr->NxComputeConeDensity(radius, length, mass); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_box_inertia_tensor +// Access: Published +// Description: Computes diagonalized inertia tensor for a box. +// +// \param [in] mass +// \param [in] xlength +// \param [in] ylength +// \param [in] zlength +//////////////////////////////////////////////////////////////////// +LVector3f PhysxUtilLib:: +compute_box_inertia_tensor(float mass, float xlength, float ylength, float zlength) { + + NxVec3 tensor; + _ptr->NxComputeBoxInertiaTensor(tensor, mass, xlength, ylength, zlength); + return PhysxManager::nxVec3_to_vec3(tensor); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::compute_sphere_inertia_tensor +// Access: Published +// Description: Computes diagonalized inertia tensor for a sphere. +// +// \param [in] mass +// \param [in] radius +// \param [in] hollow +//////////////////////////////////////////////////////////////////// +LVector3f PhysxUtilLib:: +compute_sphere_inertia_tensor(float mass, float radius, bool hollow) { + + NxVec3 tensor; + _ptr->NxComputeSphereInertiaTensor(tensor, mass, radius, hollow); + return PhysxManager::nxVec3_to_vec3(tensor); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxUtilLib::box_box_intersect +// Access: Published +// Description: Boolean intersection test between two OBBs. Uses +// the separating axis theorem. Disabling 'full_test' +// only performs 6 axis tests out of 15. +// +// \param [in] extents0 +// \param [in] center0 +// \param [in] rotation0 +// \param [in] extents1 +// \param [in] center1 +// \param [in] rotation1 +// \param [in] full_test //////////////////////////////////////////////////////////////////// bool PhysxUtilLib:: -physx_compute_box_vertex_normals(const PhysxBox & box, LVecBase3f * pts) { - nassertr(nUtilLib != NULL, false); +box_box_intersect(const LVector3f &extents0, const LPoint3f ¢er0, const LMatrix3f &rotation0, const LVector3f &extents1, const LPoint3f ¢er1, const LMatrix3f &rotation1, bool full_test) { - return nUtilLib->NxComputeBoxVertexNormals(*(box.nBox), &PhysxManager::lVecBase3_to_nxVec3(*pts)); + nassertr_always(!extents0.is_nan(), false); + nassertr_always(!center0.is_nan(), false); + nassertr_always(!rotation0.is_nan(), false); + nassertr_always(!extents1.is_nan(), false); + nassertr_always(!center1.is_nan(), false); + nassertr_always(!rotation1.is_nan(), false); + + return _ptr->NxBoxBoxIntersect( + PhysxManager::vec3_to_nxVec3(extents0), + PhysxManager::point3_to_nxVec3(center0), + PhysxManager::mat3_to_nxMat33(rotation0), + PhysxManager::vec3_to_nxVec3(extents1), + PhysxManager::point3_to_nxVec3(center1), + PhysxManager::mat3_to_nxMat33(rotation1), full_test); } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_box_world_edge_normal -// Access : Published -// Description : +// Function: PhysxUtilLib::tri_box_intersect +// Access: Published +// Description: Boolean intersection test between a triangle and +// a box. +// +// \param [in] vertex0 +// \param [in] vertex1 +// \param [in] vertex2 +// \param [in] center +// \param [in] extents //////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_compute_box_world_edge_normal(const PhysxBox & box, unsigned int edge_index, LVecBase3f & world_normal) { - nassertv(nUtilLib != NULL); +bool PhysxUtilLib:: +tri_box_intersect(const LPoint3f &vertex0, const LPoint3f &vertex1, const LPoint3f &vertex2, const LPoint3f ¢er, const LVector3f &extents) { - nUtilLib->NxComputeBoxWorldEdgeNormal(*(box.nBox), edge_index, PhysxManager::lVecBase3_to_nxVec3(world_normal)); + nassertr_always(!vertex0.is_nan(), false); + nassertr_always(!vertex1.is_nan(), false); + nassertr_always(!vertex2.is_nan(), false); + nassertr_always(!center.is_nan(), false); + nassertr_always(!extents.is_nan(), false); + + return _ptr->NxTriBoxIntersect( + PhysxManager::point3_to_nxVec3(vertex0), + PhysxManager::point3_to_nxVec3(vertex1), + PhysxManager::point3_to_nxVec3(vertex2), + PhysxManager::point3_to_nxVec3(center), + PhysxManager::point3_to_nxVec3(extents)); } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_capsule_around_box -// Access : Published -// Description : +// Function: PhysxUtilLib::ray_plane_intersect +// Access: Published +// Description: Ray-plane intersection test. +// +// \param [in] ray +// \param [in] plane +// \param [out] point_on_plane //////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_compute_capsule_around_box(const PhysxBox & box, PhysxCapsule & capsule) { - nassertv(nUtilLib != NULL); +bool PhysxUtilLib:: +ray_plane_intersect(const PhysxRay &ray, const PhysxPlane &plane, LPoint3f &point_on_plane) { - nUtilLib->NxComputeCapsuleAroundBox(*(box.nBox), *(capsule.nCapsule)); + NxReal dist; // not used + NxVec3 nPointOnPlane; + + bool result = _ptr->NxRayPlaneIntersect(ray._ray, plane._plane, dist, nPointOnPlane); + + PhysxManager::update_point3_from_nxVec3(point_on_plane, nPointOnPlane); + return result; } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_cone_density -// Access : Published -// Description : +// Function: PhysxUtilLib::ray_sphere_intersect +// Access: Published +// Description: Ray-sphere intersection test. Returns true if the +// ray intersects the sphere, and the impact point if +// needed. +// +// \param [in] origin +// \param [in] dir +// \param [in] length +// \param [in] center +// \param [in] radius +// \param [out] hit_pos //////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_cone_density(float radius, float length, float mass) { - nassertr(nUtilLib != NULL, -1.0f); +bool PhysxUtilLib:: +ray_sphere_intersect(const LPoint3f &origin, const LVector3f &dir, float length, const LPoint3f ¢er, float radius, LPoint3f &hit_pos) { - return nUtilLib->NxComputeConeDensity(radius, length, mass); + nassertr_always(!origin.is_nan(), false); + nassertr_always(!dir.is_nan(), false); + nassertr_always(!center.is_nan(), false); + + NxReal nHitTime; // not used + NxVec3 nPointOnPlane; + + bool result = _ptr->NxRaySphereIntersect( + PhysxManager::point3_to_nxVec3(origin), + PhysxManager::vec3_to_nxVec3(dir), + length, + PhysxManager::point3_to_nxVec3(center), + radius, + nHitTime, + nPointOnPlane); + + PhysxManager::update_point3_from_nxVec3(hit_pos, nPointOnPlane); + return result; } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_cone_mass -// Access : Published -// Description : +// Function: PhysxUtilLib::segment_box_intersect +// Access: Published +// Description: Segment-AABB intersection test. Also computes +// intersection point. +// +// \param [in] p1 +// \param [in] p2 +// \param [in] bbox_min +// \param [in] bbox_max +// \param [out] intercept //////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_cone_mass(float radius, float length, float density) { - nassertr(nUtilLib != NULL, -1.0f); +bool PhysxUtilLib:: +segment_box_intersect(const LPoint3f &p1, const LPoint3f &p2, const LPoint3f &bbox_min, const LPoint3f &bbox_max, LPoint3f &intercept) { - return nUtilLib->NxComputeConeMass(radius, length, density); + nassertr_always(!p1.is_nan(), false); + nassertr_always(!p2.is_nan(), false); + nassertr_always(!bbox_min.is_nan(), false); + nassertr_always(!bbox_max.is_nan(), false); + + NxVec3 nIntercept; + + bool result =_ptr->NxSegmentBoxIntersect( + PhysxManager::point3_to_nxVec3(p1), + PhysxManager::point3_to_nxVec3(p2), + PhysxManager::point3_to_nxVec3(bbox_min), + PhysxManager::point3_to_nxVec3(bbox_max), + nIntercept); + + PhysxManager::update_point3_from_nxVec3(intercept, nIntercept); + return result; } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_cylinder_density -// Access : Published -// Description : +// Function: PhysxUtilLib::ray_aabb_intersect +// Access: Published +// Description: Ray-AABB intersection test. Also computes +// intersection point. +// +// \param [in] min +// \param [in] max +// \param [in] origin +// \param [in] dir +// \param [out] coord //////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_cylinder_density(float radius, float length, float mass) { - nassertr(nUtilLib != NULL, -1.0f); +bool PhysxUtilLib:: +ray_aabb_intersect(const LPoint3f &min, const LPoint3f &max, const LPoint3f &origin, const LVector3f &dir, LPoint3f &coord) { - return nUtilLib->NxComputeCylinderDensity(radius, length, mass); + nassertr_always(!min.is_nan(), false); + nassertr_always(!max.is_nan(), false); + nassertr_always(!origin.is_nan(), false); + nassertr_always(!dir.is_nan(), false); + + NxVec3 nCoord; + + bool result = _ptr->NxRayAABBIntersect( + PhysxManager::point3_to_nxVec3(min), + PhysxManager::point3_to_nxVec3(max), + PhysxManager::point3_to_nxVec3(origin), + PhysxManager::vec3_to_nxVec3(dir), + nCoord); + + PhysxManager::update_point3_from_nxVec3(coord, nCoord); + return result; } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_cylinder_mass -// Access : Published -// Description : +// Function: PhysxUtilLib::segment_obb_intersect +// Access: Published +// Description: Boolean segment-OBB intersection test. Based on +// separating axis theorem. +// +// \param [in] p0 +// \param [in] p1 +// \param [in] center +// \param [in] extents +// \param [in] rot //////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_cylinder_mass(float radius, float length, float density) { - nassertr(nUtilLib != NULL, -1.0f); +bool PhysxUtilLib:: +segment_obb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot) { - return nUtilLib->NxComputeCylinderMass(radius, length, density); + nassertr_always(!p0.is_nan(), false); + nassertr_always(!p1.is_nan(), false); + nassertr_always(!center.is_nan(), false); + nassertr_always(!extents.is_nan(), false); + nassertr_always(!rot.is_nan(), false); + + return _ptr->NxSegmentOBBIntersect( + PhysxManager::point3_to_nxVec3(p0), + PhysxManager::point3_to_nxVec3(p1), + PhysxManager::point3_to_nxVec3(center), + PhysxManager::vec3_to_nxVec3(extents), + PhysxManager::mat3_to_nxMat33(rot)); } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_distance_squared -// Access : Published -// Description : +// Function: PhysxUtilLib::segment_aabb_intersect +// Access: Published +// Description: Boolean segment-AABB intersection test. Based on +// separating axis theorem. +// +// \param [in] p0 +// \param [in] p1 +// \param [in] min +// \param [in] max //////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_distance_squared(const PhysxRay & ray, const LVecBase3f & point, float * t) { - nassertr(nUtilLib != NULL, -1.0f); +bool PhysxUtilLib:: +segment_aabb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &min, const LPoint3f &max) { - return nUtilLib->NxComputeDistanceSquared(*(ray.nRay), PhysxManager::lVecBase3_to_nxVec3(point), t); + nassertr_always(!p0.is_nan(), false); + nassertr_always(!p1.is_nan(), false); + nassertr_always(!min.is_nan(), false); + nassertr_always(!max.is_nan(), false); + + return _ptr->NxSegmentAABBIntersect( + PhysxManager::point3_to_nxVec3(p0), + PhysxManager::point3_to_nxVec3(p1), + PhysxManager::point3_to_nxVec3(min), + PhysxManager::point3_to_nxVec3(max)); } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_ellipsoid_density -// Access : Published -// Description : +// Function: PhysxUtilLib::ray_obb_intersect +// Access: Published +// Description: Boolean ray-OBB intersection test. Based on +// separating axis theorem. +// +// \param [in] ray +// \param [in] center +// \param [in] extents +// \param [in] rot //////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_ellipsoid_density(const LVecBase3f & extents, float mass) { - nassertr(nUtilLib != NULL, -1.0f); +bool PhysxUtilLib:: +ray_obb_intersect(const PhysxRay &ray, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot) { - return nUtilLib->NxComputeEllipsoidDensity(PhysxManager::lVecBase3_to_nxVec3(extents), mass); + nassertr_always(!center.is_nan(), false); + nassertr_always(!extents.is_nan(), false); + nassertr_always(!rot.is_nan(), false); + + return _ptr->NxRayOBBIntersect( + ray._ray, + PhysxManager::point3_to_nxVec3(center), + PhysxManager::point3_to_nxVec3(extents), + PhysxManager::mat3_to_nxMat33(rot)); } //////////////////////////////////////////////////////////////////// -// Function : physx_compute_ellipsoid_mass -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_ellipsoid_mass(const LVecBase3f & extents, float density) { - nassertr(nUtilLib != NULL, -1.0f); - - return nUtilLib->NxComputeEllipsoidMass(PhysxManager::lVecBase3_to_nxVec3(extents), density); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_compute_sphere_density -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_sphere_density(float radius, float mass) { - nassertr(nUtilLib != NULL, -1.0f); - - return nUtilLib->NxComputeSphereDensity(radius, mass); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_compute_sphere_inertia_tensor -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_compute_sphere_inertia_tensor(LVecBase3f & diag_inertia, float mass, float radius, bool hollow) { - nassertv(nUtilLib != NULL); - - nUtilLib->NxComputeSphereInertiaTensor(PhysxManager::lVecBase3_to_nxVec3(diag_inertia), mass, radius, hollow); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_compute_sphere_mass -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_sphere_mass(float radius, float density) { - nassertr(nUtilLib != NULL, -1.0f); - - return nUtilLib->NxComputeSphereMass(radius, density); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_compute_square_distance -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -float PhysxUtilLib:: -physx_compute_square_distance(const PhysxSegment & seg, const LVecBase3f & point, float * t) { - nassertr(nUtilLib != NULL, -1.0f); - - return nUtilLib->NxComputeSquareDistance(*(seg.nSegment), PhysxManager::lVecBase3_to_nxVec3(point), t); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_crc32 -// Access : Published -// Description : +// Function: PhysxUtilLib::ray_capsule_intersect +// Access: Published +// Description: Ray-capsule intersection test. Returns number of +// intersection points (0,1 or 2) along the ray. +// +// \param [in] origin +// \param [in] dir +// \param [in] capsule //////////////////////////////////////////////////////////////////// unsigned int PhysxUtilLib:: -physx_crc32(const void * buffer, unsigned int nb_bytes) { - nassertr(nUtilLib != NULL, -1); +ray_capsule_intersect(const LPoint3f &origin, const LVector3f &dir, const PhysxCapsule &capsule) { - return nUtilLib->NxCrc32(buffer, nb_bytes); + nassertr_always(!origin.is_nan(), -1); + nassertr_always(!dir.is_nan(), -1); + + NxReal t[2] = { 0.0f, 0.0f }; // not used + + return _ptr->NxRayCapsuleIntersect( + PhysxManager::point3_to_nxVec3(origin), + PhysxManager::vec3_to_nxVec3(dir), + capsule._capsule, t); } //////////////////////////////////////////////////////////////////// -// Function : physx_create_box -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_create_box(PhysxBox & box, const PhysxBounds3 & aabb, const LMatrix4f & mat) { - nassertv(nUtilLib != NULL); - - nUtilLib->NxCreateBox(*(box.nBox), *(aabb.nBounds3), PhysxManager::lMatrix4_to_nxMat34(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_diagonalize_inertia_tensor -// Access : Published -// Description : +// Function: PhysxUtilLib::swept_spheres_intersect +// Access: Published +// Description: Sphere-sphere sweep test. Returns true if spheres +// intersect during their linear motion along +// provided velocity vectors. +// +// \param [in] sphere0 +// \param [in] velocity0 +// \param [in] sphere1 +// \param [in] velocity1 //////////////////////////////////////////////////////////////////// bool PhysxUtilLib:: -physx_diagonalize_inertia_tensor(const LMatrix3f & dense_inertia, LVecBase3f & diagonal_inertia, LMatrix3f & rotation) { - nassertr(nUtilLib != NULL, false); +swept_spheres_intersect(const PhysxSphere &sphere0, const LVector3f &velocity0, const PhysxSphere &sphere1, const LVector3f &velocity1) { - return nUtilLib->NxDiagonalizeInertiaTensor(PhysxManager::lMatrix3_to_nxMat33(dense_inertia), PhysxManager::lVecBase3_to_nxVec3(diagonal_inertia), PhysxManager::lMatrix3_to_nxMat33(rotation)); + nassertr_always(!velocity0.is_nan(), false); + nassertr_always(!velocity1.is_nan(), false); + + return _ptr->NxSweptSpheresIntersect( + sphere0._sphere, + PhysxManager::vec3_to_nxVec3(velocity0), + sphere1._sphere, + PhysxManager::vec3_to_nxVec3(velocity1)); } //////////////////////////////////////////////////////////////////// -// Function : physx_fast_compute_sphere -// Access : Published -// Description : +// Function: PhysxUtilLib::ray_tri_intersect +// Access: Published +// Description: Ray-triangle intersection test. Returns impact +// distance (t) as well as barycentric coordinates +// (u,v) of impact point. The test performs back face +// culling or not according to 'cull'. +// +// \param [in] orig +// \param [in] dir +// \param [in] vert0 +// \param [in] vert1 +// \param [in] vert2 +// \param [out] hit, with coordinates (t,u,v) +// \param [in] cull //////////////////////////////////////////////////////////////////// bool PhysxUtilLib:: -physx_fast_compute_sphere(PhysxSphere & sphere, unsigned nb_verts, const LVecBase3f * verts) { - nassertr(nUtilLib != NULL, false); +ray_tri_intersect(const LPoint3f &orig, const LVector3f &dir, const LPoint3f &vert0, const LPoint3f &vert1, const LPoint3f &vert2, LVector3f &hit, bool cull) { - return nUtilLib->NxFastComputeSphere(*(sphere.nSphere), nb_verts, &PhysxManager::lVecBase3_to_nxVec3(*verts)); + nassertr_always(!orig.is_nan(), false); + nassertr_always(!dir.is_nan(), false); + nassertr_always(!vert0.is_nan(), false); + nassertr_always(!vert1.is_nan(), false); + nassertr_always(!vert2.is_nan(), false); + + NxReal t, u, v; + + bool result = _ptr->NxRayTriIntersect( + PhysxManager::point3_to_nxVec3(orig), + PhysxManager::vec3_to_nxVec3(dir), + PhysxManager::point3_to_nxVec3(vert0), + PhysxManager::point3_to_nxVec3(vert1), + PhysxManager::point3_to_nxVec3(vert2), + t, u, v, cull); + + hit.set_x(t); + hit.set_y(u); + hit.set_z(v); + + return result; } //////////////////////////////////////////////////////////////////// -// Function : physx_find_rotation_matrix -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_find_rotation_matrix(const LVecBase3f & x, const LVecBase3f & b, LMatrix3f & m) { - nassertv(nUtilLib != NULL); - - nUtilLib->NxFindRotationMatrix(PhysxManager::lVecBase3_to_nxVec3(x), PhysxManager::lVecBase3_to_nxVec3(b), PhysxManager::lMatrix3_to_nxMat33(m)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_get_box_edges -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -const unsigned int * PhysxUtilLib:: -physx_get_box_edges() { - nassertr(nUtilLib != NULL, NULL); - - return nUtilLib->NxGetBoxEdges(); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_get_box_edges_axes -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -const int * PhysxUtilLib:: -physx_get_box_edges_axes() { - nassertr(nUtilLib != NULL, NULL); - - return nUtilLib->NxGetBoxEdgesAxes(); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_get_box_local_edge_normals -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -const LVecBase3f * PhysxUtilLib:: -physx_get_box_local_edge_normals() { - nassertr(nUtilLib != NULL, NULL); - - return &PhysxManager::nxVec3_to_lVecBase3(*nUtilLib->NxGetBoxLocalEdgeNormals()); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_get_box_quads -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -const unsigned int * PhysxUtilLib:: -physx_get_box_quads() { - nassertr(nUtilLib != NULL, NULL); - - return nUtilLib->NxGetBoxQuads(); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_get_box_triangles -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -const unsigned int * PhysxUtilLib:: -physx_get_box_triangles() { - nassertr(nUtilLib != NULL, NULL); - - return nUtilLib->NxGetBoxTriangles(); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_int_ceil -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -int PhysxUtilLib:: -physx_int_ceil(const float & f) { - return nUtilLib->NxIntCeil(f); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_int_chop -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -int PhysxUtilLib:: -physx_int_chop(const float & f) { - return nUtilLib->NxIntChop(f); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_int_floor -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -int PhysxUtilLib:: -physx_int_floor(const float & f) { - return nUtilLib->NxIntFloor(f); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_is_box_a_inside_box_b -// Access : Published -// Description : +// Function: PhysxUtilLib::sweep_box_capsule +// Access: Published +// Description: Box-vs-capsule sweep test. Sweeps a box against a +// capsule, returns true if box hit the capsule. Also +// returns contact information. +// +// \param [in] box Box +// \param [in] lss Capsule +// \param [in] dir Unit-length sweep direction +// \param [in] length Length of sweep +// \param [out] normal Normal at impact point //////////////////////////////////////////////////////////////////// bool PhysxUtilLib:: -physx_is_box_a_inside_box_b(const PhysxBox & a, const PhysxBox & b) { - nassertr(nUtilLib != NULL, false); +sweep_box_capsule(const PhysxBox &box, const PhysxCapsule &lss, const LVector3f &dir, float length, LVector3f &normal) { - return nUtilLib->NxIsBoxAInsideBoxB(*(a.nBox), *(b.nBox)); + nassertr_always(!dir.is_nan(), false); + + NxReal min_dist; // not used + NxVec3 nNormal; + + bool result = _ptr->NxSweepBoxCapsule( + box._box, lss._capsule, + PhysxManager::vec3_to_nxVec3(dir), + length, min_dist, nNormal); + + PhysxManager::update_vec3_from_nxVec3(normal, nNormal); + return result; } //////////////////////////////////////////////////////////////////// -// Function : physx_joint_desc__set_global_anchor -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_joint_desc__set_global_anchor(PhysxJointDesc & dis, const LVecBase3f & ws_anchor) { - nassertv(nUtilLib != NULL); - - nUtilLib->NxJointDesc_SetGlobalAnchor(*(dis.nJointDesc), PhysxManager::lVecBase3_to_nxVec3(ws_anchor)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_joint_desc__set_global_axis -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_joint_desc__set_global_axis(PhysxJointDesc & dis, const LVecBase3f & ws_axis) { - nassertv(nUtilLib != NULL); - - nUtilLib->NxJointDesc_SetGlobalAxis(*(dis.nJointDesc), PhysxManager::lVecBase3_to_nxVec3(ws_axis)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_merge_spheres -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_merge_spheres(PhysxSphere & merged, const PhysxSphere & sphere0, const PhysxSphere & sphere1) { - nassertv(nUtilLib != NULL); - - nUtilLib->NxMergeSpheres(*(merged.nSphere), *(sphere0.nSphere), *(sphere1.nSphere)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_normal_to_tangents -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_normal_to_tangents(const LVecBase3f & n, LVecBase3f & t1, LVecBase3f & t2) { - nassertv(nUtilLib != NULL); - - nUtilLib->NxNormalToTangents(PhysxManager::lVecBase3_to_nxVec3(n), PhysxManager::lVecBase3_to_nxVec3(t1), PhysxManager::lVecBase3_to_nxVec3(t2)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_ray_aabb_intersect -// Access : Published -// Description : +// Function: PhysxUtilLib::sweep_box_sphere +// Access: Published +// Description: Box-vs-sphere sweep test. Sweeps a box against a +// sphere, returns true if box hit the sphere. Also +// returns contact information. +// +// \param [in] box Box +// \param [in] sphere Sphere +// \param [in] dir Unit-length sweep direction +// \param [in] length Length of sweep +// \param [out] normal Normal at impact point //////////////////////////////////////////////////////////////////// bool PhysxUtilLib:: -physx_ray_aabb_intersect(const LVecBase3f & min, const LVecBase3f & max, const LVecBase3f & origin, const LVecBase3f & dir, LVecBase3f & coord) { - nassertr(nUtilLib != NULL, false); +sweep_box_sphere(const PhysxBox &box, const PhysxSphere &sphere, const LVector3f &dir, float length, LVector3f &normal) { - return nUtilLib->NxRayAABBIntersect(PhysxManager::lVecBase3_to_nxVec3(min), PhysxManager::lVecBase3_to_nxVec3(max), PhysxManager::lVecBase3_to_nxVec3(origin), PhysxManager::lVecBase3_to_nxVec3(dir), PhysxManager::lVecBase3_to_nxVec3(coord)); + nassertr_always(!dir.is_nan(), false); + + NxReal min_dist; // not used + NxVec3 nNormal; + + bool result = _ptr->NxSweepBoxSphere( + box._box, sphere._sphere, + PhysxManager::vec3_to_nxVec3(dir), + length, min_dist, nNormal); + + PhysxManager::update_vec3_from_nxVec3(normal, nNormal); + return result; } //////////////////////////////////////////////////////////////////// -// Function : physx_ray_aabb_intersect2 -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -unsigned int PhysxUtilLib:: -physx_ray_aabb_intersect2(const LVecBase3f & min, const LVecBase3f & max, const LVecBase3f & origin, const LVecBase3f & dir, LVecBase3f & coord, float & t) { - nassertr(nUtilLib != NULL, -1); - - return nUtilLib->NxRayAABBIntersect2(PhysxManager::lVecBase3_to_nxVec3(min), PhysxManager::lVecBase3_to_nxVec3(max), PhysxManager::lVecBase3_to_nxVec3(origin), PhysxManager::lVecBase3_to_nxVec3(dir), PhysxManager::lVecBase3_to_nxVec3(coord), t); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_ray_obb_intersect -// Access : Published -// Description : +// Function: PhysxUtilLib::sweep_capsule_capsule +// Access: Published +// Description: Capsule-vs-capsule sweep test. Sweeps a capsule +// against a capsule, returns true if capsule hit the +// other capsule. Also returns contact information. +// +// \param [in] lss0 +// \param [in] lss1 +// \param [in] dir Unit-length sweep direction +// \param [in] length Length of sweep +// \param [out] ip Impact point +// \param [out] normal Normal at impact point //////////////////////////////////////////////////////////////////// bool PhysxUtilLib:: -physx_ray_obb_intersect(const PhysxRay & ray, const LVecBase3f & center, const LVecBase3f & extents, const LMatrix3f & rot) { - nassertr(nUtilLib != NULL, false); +sweep_capsule_capsule(const PhysxCapsule &lss0, const PhysxCapsule &lss1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal) { - return nUtilLib->NxRayOBBIntersect(*(ray.nRay), PhysxManager::lVecBase3_to_nxVec3(center), PhysxManager::lVecBase3_to_nxVec3(extents), PhysxManager::lMatrix3_to_nxMat33(rot)); + nassertr_always(!dir.is_nan(), false); + + NxReal min_dist; // not used + NxVec3 nIp; + NxVec3 nNormal; + + bool result = _ptr->NxSweepCapsuleCapsule( + lss0._capsule, lss1._capsule, + PhysxManager::vec3_to_nxVec3(dir), + length, min_dist, nIp, nNormal); + + PhysxManager::update_point3_from_nxVec3(ip, nIp); + PhysxManager::update_vec3_from_nxVec3(normal, nNormal); + return result; } //////////////////////////////////////////////////////////////////// -// Function : physx_ray_plane_intersect -// Access : Published -// Description : +// Function: PhysxUtilLib::sweep_sphere_capsule +// Access: Published +// Description: Sphere-vs-capsule sweep test. Sweeps a sphere +// against a capsule, returns true if sphere hit the +// capsule. Also returns contact information. +// +// \param [in] sphere +// \param [in] lss +// \param [in] dir Unit-length sweep direction +// \param [in] length Length of sweep +// \param [out] ip Impact point +// \param [out] normal Normal at impact point //////////////////////////////////////////////////////////////////// bool PhysxUtilLib:: -physx_ray_plane_intersect(const PhysxRay & ray, const PhysxPlane & plane, float & dist, LVecBase3f & point_on_plane) { - nassertr(nUtilLib != NULL, false); +sweep_sphere_capsule(const PhysxSphere &sphere, const PhysxCapsule &lss, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal) { - return nUtilLib->NxRayPlaneIntersect(*(ray.nRay), *(plane.nPlane), dist, PhysxManager::lVecBase3_to_nxVec3(point_on_plane)); + nassertr_always(!dir.is_nan(), false); + + NxReal min_dist; // not used + NxVec3 nIp; + NxVec3 nNormal; + + bool result = _ptr->NxSweepSphereCapsule( + sphere._sphere, lss._capsule, + PhysxManager::vec3_to_nxVec3(dir), + length, min_dist, nIp, nNormal); + + PhysxManager::update_point3_from_nxVec3(ip, nIp); + PhysxManager::update_vec3_from_nxVec3(normal, nNormal); + return result; } //////////////////////////////////////////////////////////////////// -// Function : physx_ray_sphere_intersect -// Access : Published -// Description : +// Function: PhysxUtilLib::sweep_box_box +// Access: Published +// Description: Box-vs-box sweep test. Sweeps a box against a box, +// returns true if box hit the other box. Also returns +// contact information. +// +// \param [in] box0 +// \param [in] box1 +// \param [in] dir Unit-length sweep direction +// \param [in] length Length of sweep +// \param [out] ip Impact point +// \param [out] normal Normal at impact point //////////////////////////////////////////////////////////////////// bool PhysxUtilLib:: -physx_ray_sphere_intersect(const LVecBase3f & origin, const LVecBase3f & dir, float length, const LVecBase3f & center, float radius, float & hit_time, LVecBase3f & hit_pos) { - nassertr(nUtilLib != NULL, false); +sweep_box_box(const PhysxBox &box0, const PhysxBox &box1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal) { - return nUtilLib->NxRaySphereIntersect(PhysxManager::lVecBase3_to_nxVec3(origin), PhysxManager::lVecBase3_to_nxVec3(dir), length, PhysxManager::lVecBase3_to_nxVec3(center), radius, hit_time, PhysxManager::lVecBase3_to_nxVec3(hit_pos)); + nassertr_always(!dir.is_nan(), false); + + NxReal min_dist; // not used + NxVec3 nIp; + NxVec3 nNormal; + + bool result = _ptr->NxSweepBoxBox( + box0._box, box1._box, + PhysxManager::vec3_to_nxVec3(dir), + length, nIp, nNormal, min_dist); + + PhysxManager::update_point3_from_nxVec3(ip, nIp); + PhysxManager::update_vec3_from_nxVec3(normal, nNormal); + return result; } //////////////////////////////////////////////////////////////////// -// Function : physx_ray_tri_intersect -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_ray_tri_intersect(const LVecBase3f & orig, const LVecBase3f & dir, const LVecBase3f & vert0, const LVecBase3f & vert1, const LVecBase3f & vert2, float & t, float & u, float & v, bool cull) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxRayTriIntersect(PhysxManager::lVecBase3_to_nxVec3(orig), PhysxManager::lVecBase3_to_nxVec3(dir), PhysxManager::lVecBase3_to_nxVec3(vert0), PhysxManager::lVecBase3_to_nxVec3(vert1), PhysxManager::lVecBase3_to_nxVec3(vert2), t, u, v, cull); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_segment_aabb_intersect -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_segment_aabb_intersect(const LVecBase3f & p0, const LVecBase3f & p1, const LVecBase3f & min, const LVecBase3f & max) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxSegmentAABBIntersect(PhysxManager::lVecBase3_to_nxVec3(p0), PhysxManager::lVecBase3_to_nxVec3(p1), PhysxManager::lVecBase3_to_nxVec3(min), PhysxManager::lVecBase3_to_nxVec3(max)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_segment_box_intersect -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_segment_box_intersect(const LVecBase3f & p1, const LVecBase3f & p2, const LVecBase3f & bbox_min, const LVecBase3f & bbox_max, LVecBase3f & intercept) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxSegmentBoxIntersect(PhysxManager::lVecBase3_to_nxVec3(p1), PhysxManager::lVecBase3_to_nxVec3(p2), PhysxManager::lVecBase3_to_nxVec3(bbox_min), PhysxManager::lVecBase3_to_nxVec3(bbox_max), PhysxManager::lVecBase3_to_nxVec3(intercept)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_segment_obb_intersect -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_segment_obb_intersect(const LVecBase3f & p0, const LVecBase3f & p1, const LVecBase3f & center, const LVecBase3f & extents, const LMatrix3f & rot) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxSegmentOBBIntersect(PhysxManager::lVecBase3_to_nxVec3(p0), PhysxManager::lVecBase3_to_nxVec3(p1), PhysxManager::lVecBase3_to_nxVec3(center), PhysxManager::lVecBase3_to_nxVec3(extents), PhysxManager::lMatrix3_to_nxMat33(rot)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_segment_obb_sqr_dist -// Access : Published -// Description : +// Function: PhysxUtilLib::point_obb_sqr_dist +// Access: Published +// Description: Point-vs-OBB distance computation. Returns distance +// between a point and an OBB. +// +// \param [in] point The point +// \param [in] center OBB center +// \param [in] extents OBB extents +// \param [in] rot OBB rotation +// \param [out] params Closest point on the box, in box space //////////////////////////////////////////////////////////////////// float PhysxUtilLib:: -physx_segment_obb_sqr_dist(const PhysxSegment & segment, const LVecBase3f & c0, const LVecBase3f & e0, const LMatrix3f & r0, float * t, LVecBase3f * p) { - nassertr(nUtilLib != NULL, -1.0f); +point_obb_sqr_dist(const LPoint3f &point, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot, LPoint3f ¶ms) { - return nUtilLib->NxSegmentOBBSqrDist(*(segment.nSegment), PhysxManager::lVecBase3_to_nxVec3(c0), PhysxManager::lVecBase3_to_nxVec3(e0), PhysxManager::lMatrix3_to_nxMat33(r0), t, &PhysxManager::lVecBase3_to_nxVec3(*p)); + nassertr_always(!point.is_nan(), 0.0f); + nassertr_always(!center.is_nan(), 0.0f); + nassertr_always(!extents.is_nan(), 0.0f); + nassertr_always(!rot.is_nan(), 0.0f); + + NxVec3 nParams; + + float result = _ptr->NxPointOBBSqrDist( + PhysxManager::point3_to_nxVec3(point), + PhysxManager::point3_to_nxVec3(center), + PhysxManager::vec3_to_nxVec3(extents), + PhysxManager::mat3_to_nxMat33(rot), + &nParams); + + PhysxManager::update_point3_from_nxVec3(params, nParams); + return result; } -//////////////////////////////////////////////////////////////////// -// Function : physx_segment_plane_intersect -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_segment_plane_intersect(const LVecBase3f & v1, const LVecBase3f & v2, const PhysxPlane & plane, float & dist, LVecBase3f & point_on_plane) { - nassertv(nUtilLib != NULL); - - nUtilLib->NxSegmentPlaneIntersect(PhysxManager::lVecBase3_to_nxVec3(v1), PhysxManager::lVecBase3_to_nxVec3(v2), *(plane.nPlane), dist, PhysxManager::lVecBase3_to_nxVec3(point_on_plane)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_separating_axis -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -PhysxSepAxis PhysxUtilLib:: -physx_separating_axis(const LVecBase3f & extents0, const LVecBase3f & center0, const LMatrix3f & rotation0, const LVecBase3f & extents1, const LVecBase3f & center1, const LMatrix3f & rotation1, bool full_test) { - return (PhysxSepAxis)nUtilLib->NxSeparatingAxis(PhysxManager::lVecBase3_to_nxVec3(extents0), PhysxManager::lVecBase3_to_nxVec3(center0), PhysxManager::lMatrix3_to_nxMat33(rotation0), PhysxManager::lVecBase3_to_nxVec3(extents1), PhysxManager::lVecBase3_to_nxVec3(center1), PhysxManager::lMatrix3_to_nxMat33(rotation1), full_test); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_set_fpu_exceptions -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_set_fpu_exceptions(bool b) { - nassertv(nUtilLib != NULL); - - nUtilLib->NxSetFPUExceptions(b); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_set_fpu_precision24 -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_set_fpu_precision24() { - nassertv(nUtilLib != NULL); - - nUtilLib->NxSetFPUPrecision24(); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_set_fpu_precision53 -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_set_fpu_precision53() { - nassertv(nUtilLib != NULL); - - nUtilLib->NxSetFPUPrecision53(); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_set_fpu_precision64 -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_set_fpu_precision64() { - nassertv(nUtilLib != NULL); - - nUtilLib->NxSetFPUPrecision64(); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_set_fpu_rounding_chop -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_set_fpu_rounding_chop() { - nassertv(nUtilLib != NULL); - - nUtilLib->NxSetFPURoundingChop(); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_set_fpu_rounding_down -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_set_fpu_rounding_down() { - nassertv(nUtilLib != NULL); - - nUtilLib->NxSetFPURoundingDown(); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_set_fpu_rounding_near -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_set_fpu_rounding_near() { - nassertv(nUtilLib != NULL); - - nUtilLib->NxSetFPURoundingNear(); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_set_fpu_rounding_up -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -void PhysxUtilLib:: -physx_set_fpu_rounding_up() { - nassertv(nUtilLib != NULL); - - nUtilLib->NxSetFPURoundingUp(); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_sweep_box_box -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_sweep_box_box(const PhysxBox & box0, const PhysxBox & box1, const LVecBase3f & dir, float length, LVecBase3f & ip, LVecBase3f & normal, float & min_dist) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxSweepBoxBox(*(box0.nBox), *(box1.nBox), PhysxManager::lVecBase3_to_nxVec3(dir), length, PhysxManager::lVecBase3_to_nxVec3(ip), PhysxManager::lVecBase3_to_nxVec3(normal), min_dist); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_sweep_box_capsule -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_sweep_box_capsule(const PhysxBox & box, const PhysxCapsule & lss, const LVecBase3f & dir, float length, float & min_dist, LVecBase3f & normal) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxSweepBoxCapsule(*(box.nBox), *(lss.nCapsule), PhysxManager::lVecBase3_to_nxVec3(dir), length, min_dist, PhysxManager::lVecBase3_to_nxVec3(normal)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_sweep_box_sphere -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_sweep_box_sphere(const PhysxBox & box, const PhysxSphere & sphere, const LVecBase3f & dir, float length, float & min_dist, LVecBase3f & normal) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxSweepBoxSphere(*(box.nBox), *(sphere.nSphere), PhysxManager::lVecBase3_to_nxVec3(dir), length, min_dist, PhysxManager::lVecBase3_to_nxVec3(normal)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_sweep_capsule_capsule -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_sweep_capsule_capsule(const PhysxCapsule & lss0, const PhysxCapsule & lss1, const LVecBase3f & dir, float length, float & min_dist, LVecBase3f & ip, LVecBase3f & normal) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxSweepCapsuleCapsule(*(lss0.nCapsule), *(lss1.nCapsule), PhysxManager::lVecBase3_to_nxVec3(dir), length, min_dist, PhysxManager::lVecBase3_to_nxVec3(ip), PhysxManager::lVecBase3_to_nxVec3(normal)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_sweep_sphere_capsule -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_sweep_sphere_capsule(const PhysxSphere & sphere, const PhysxCapsule & lss, const LVecBase3f & dir, float length, float & min_dist, LVecBase3f & ip, LVecBase3f & normal) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxSweepSphereCapsule(*(sphere.nSphere), *(lss.nCapsule), PhysxManager::lVecBase3_to_nxVec3(dir), length, min_dist, PhysxManager::lVecBase3_to_nxVec3(ip), PhysxManager::lVecBase3_to_nxVec3(normal)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_swept_spheres_intersect -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_swept_spheres_intersect(const PhysxSphere & sphere0, const LVecBase3f & velocity0, const PhysxSphere & sphere1, const LVecBase3f & velocity1) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxSweptSpheresIntersect(*(sphere0.nSphere), PhysxManager::lVecBase3_to_nxVec3(velocity0), *(sphere1.nSphere), PhysxManager::lVecBase3_to_nxVec3(velocity1)); -} - -//////////////////////////////////////////////////////////////////// -// Function : physx_tri_box_intersect -// Access : Published -// Description : -//////////////////////////////////////////////////////////////////// -bool PhysxUtilLib:: -physx_tri_box_intersect(const LVecBase3f & vertex0, const LVecBase3f & vertex1, const LVecBase3f & vertex2, const LVecBase3f & center, const LVecBase3f & extents) { - nassertr(nUtilLib != NULL, false); - - return nUtilLib->NxTriBoxIntersect(PhysxManager::lVecBase3_to_nxVec3(vertex0), PhysxManager::lVecBase3_to_nxVec3(vertex1), PhysxManager::lVecBase3_to_nxVec3(vertex2), PhysxManager::lVecBase3_to_nxVec3(center), PhysxManager::lVecBase3_to_nxVec3(extents)); -} - -#endif // HAVE_PHYSX - diff --git a/panda/src/physx/physxUtilLib.h b/panda/src/physx/physxUtilLib.h index 429e50860b..7de3689a58 100644 --- a/panda/src/physx/physxUtilLib.h +++ b/panda/src/physx/physxUtilLib.h @@ -1,5 +1,5 @@ // Filename: physxUtilLib.h -// Created by: pratt (Apr 7, 2006) +// Created by: enn0x (01Nov09) // //////////////////////////////////////////////////////////////////// // @@ -15,110 +15,113 @@ #ifndef PHYSXUTILLIB_H #define PHYSXUTILLIB_H -#ifdef HAVE_PHYSX - #include "pandabase.h" +#include "lvector3.h" +#include "lpoint3.h" +#include "lmatrix.h" -#include "physx_enumerations.h" -#include "physxManager.h" -#include "luse.h" +#include "config_physx.h" class PhysxBounds3; class PhysxBox; class PhysxCapsule; -class PhysxJointDesc; class PhysxPlane; class PhysxRay; class PhysxSegment; class PhysxSphere; -#include "NxPhysics.h" - //////////////////////////////////////////////////////////////////// // Class : PhysxUtilLib -// Description : +// Description : //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSX PhysxUtilLib { + PUBLISHED: + INLINE PhysxUtilLib(); + INLINE ~PhysxUtilLib(); - bool physx_box_box_intersect(const LVecBase3f & extents0, const LVecBase3f & center0, const LMatrix3f & rotation0, const LVecBase3f & extents1, const LVecBase3f & center1, const LMatrix3f & rotation1, bool full_test); - bool physx_box_contains_point(const PhysxBox & box, const LVecBase3f & p); - const unsigned int * physx_box_vertex_to_quad(unsigned int vertex_index); - bool physx_build_smooth_normals(unsigned int nb_tris, unsigned int nb_verts, const LVecBase3f * verts, const unsigned int * d_faces, const unsigned short * w_faces, LVecBase3f * normals, bool flip); - void physx_compute_bounds(LVecBase3f & min, LVecBase3f & max, unsigned int nb_verts, const LVecBase3f * verts); - void physx_compute_box_around_capsule(const PhysxCapsule & capsule, PhysxBox & box); - float physx_compute_box_density(const LVecBase3f & extents, float mass); - void physx_compute_box_inertia_tensor(LVecBase3f & diag_inertia, float mass, float xlength, float ylength, float zlength); - float physx_compute_box_mass(const LVecBase3f & extents, float density); - bool physx_compute_box_planes(const PhysxBox & box, PhysxPlane * planes); - bool physx_compute_box_points(const PhysxBox & box, LVecBase3f * pts); - bool physx_compute_box_vertex_normals(const PhysxBox & box, LVecBase3f * pts); - void physx_compute_box_world_edge_normal(const PhysxBox & box, unsigned int edge_index, LVecBase3f & world_normal); - void physx_compute_capsule_around_box(const PhysxBox & box, PhysxCapsule & capsule); - float physx_compute_cone_density(float radius, float length, float mass); - float physx_compute_cone_mass(float radius, float length, float density); - float physx_compute_cylinder_density(float radius, float length, float mass); - float physx_compute_cylinder_mass(float radius, float length, float density); - float physx_compute_distance_squared(const PhysxRay & ray, const LVecBase3f & point, float * t); - float physx_compute_ellipsoid_density(const LVecBase3f & extents, float mass); - float physx_compute_ellipsoid_mass(const LVecBase3f & extents, float density); - float physx_compute_sphere_density(float radius, float mass); - void physx_compute_sphere_inertia_tensor(LVecBase3f & diag_inertia, float mass, float radius, bool hollow); - float physx_compute_sphere_mass(float radius, float density); - float physx_compute_square_distance(const PhysxSegment & seg, const LVecBase3f & point, float * t); - unsigned int physx_crc32(const void * buffer, unsigned int nb_bytes); - void physx_create_box(PhysxBox & box, const PhysxBounds3 & aabb, const LMatrix4f & mat); - bool physx_diagonalize_inertia_tensor(const LMatrix3f & dense_inertia, LVecBase3f & diagonal_inertia, LMatrix3f & rotation); - bool physx_fast_compute_sphere(PhysxSphere & sphere, unsigned nb_verts, const LVecBase3f * verts); - void physx_find_rotation_matrix(const LVecBase3f & x, const LVecBase3f & b, LMatrix3f & m); - const unsigned int * physx_get_box_edges(); - const int * physx_get_box_edges_axes(); - const LVecBase3f * physx_get_box_local_edge_normals(); - const unsigned int * physx_get_box_quads(); - const unsigned int * physx_get_box_triangles(); - int physx_int_ceil(const float & f); - int physx_int_chop(const float & f); - int physx_int_floor(const float & f); - bool physx_is_box_a_inside_box_b(const PhysxBox & a, const PhysxBox & b); - void physx_joint_desc__set_global_anchor(PhysxJointDesc & dis, const LVecBase3f & ws_anchor); - void physx_joint_desc__set_global_axis(PhysxJointDesc & dis, const LVecBase3f & ws_axis); - void physx_merge_spheres(PhysxSphere & merged, const PhysxSphere & sphere0, const PhysxSphere & sphere1); - void physx_normal_to_tangents(const LVecBase3f & n, LVecBase3f & t1, LVecBase3f & t2); - bool physx_ray_aabb_intersect(const LVecBase3f & min, const LVecBase3f & max, const LVecBase3f & origin, const LVecBase3f & dir, LVecBase3f & coord); - unsigned int physx_ray_aabb_intersect2(const LVecBase3f & min, const LVecBase3f & max, const LVecBase3f & origin, const LVecBase3f & dir, LVecBase3f & coord, float & t); - bool physx_ray_obb_intersect(const PhysxRay & ray, const LVecBase3f & center, const LVecBase3f & extents, const LMatrix3f & rot); - bool physx_ray_plane_intersect(const PhysxRay & ray, const PhysxPlane & plane, float & dist, LVecBase3f & point_on_plane); - bool physx_ray_sphere_intersect(const LVecBase3f & origin, const LVecBase3f & dir, float length, const LVecBase3f & center, float radius, float & hit_time, LVecBase3f & hit_pos); - bool physx_ray_tri_intersect(const LVecBase3f & orig, const LVecBase3f & dir, const LVecBase3f & vert0, const LVecBase3f & vert1, const LVecBase3f & vert2, float & t, float & u, float & v, bool cull); - bool physx_segment_aabb_intersect(const LVecBase3f & p0, const LVecBase3f & p1, const LVecBase3f & min, const LVecBase3f & max); - bool physx_segment_box_intersect(const LVecBase3f & p1, const LVecBase3f & p2, const LVecBase3f & bbox_min, const LVecBase3f & bbox_max, LVecBase3f & intercept); - bool physx_segment_obb_intersect(const LVecBase3f & p0, const LVecBase3f & p1, const LVecBase3f & center, const LVecBase3f & extents, const LMatrix3f & rot); - float physx_segment_obb_sqr_dist(const PhysxSegment & segment, const LVecBase3f & c0, const LVecBase3f & e0, const LMatrix3f & r0, float * t, LVecBase3f * p); - void physx_segment_plane_intersect(const LVecBase3f & v1, const LVecBase3f & v2, const PhysxPlane & plane, float & dist, LVecBase3f & point_on_plane); - PhysxSepAxis physx_separating_axis(const LVecBase3f & extents0, const LVecBase3f & center0, const LMatrix3f & rotation0, const LVecBase3f & extents1, const LVecBase3f & center1, const LMatrix3f & rotation1, bool full_test); - void physx_set_fpu_exceptions(bool b); - void physx_set_fpu_precision24(); - void physx_set_fpu_precision53(); - void physx_set_fpu_precision64(); - void physx_set_fpu_rounding_chop(); - void physx_set_fpu_rounding_down(); - void physx_set_fpu_rounding_near(); - void physx_set_fpu_rounding_up(); - bool physx_sweep_box_box(const PhysxBox & box0, const PhysxBox & box1, const LVecBase3f & dir, float length, LVecBase3f & ip, LVecBase3f & normal, float & min_dist); - bool physx_sweep_box_capsule(const PhysxBox & box, const PhysxCapsule & lss, const LVecBase3f & dir, float length, float & min_dist, LVecBase3f & normal); - bool physx_sweep_box_sphere(const PhysxBox & box, const PhysxSphere & sphere, const LVecBase3f & dir, float length, float & min_dist, LVecBase3f & normal); - bool physx_sweep_capsule_capsule(const PhysxCapsule & lss0, const PhysxCapsule & lss1, const LVecBase3f & dir, float length, float & min_dist, LVecBase3f & ip, LVecBase3f & normal); - bool physx_sweep_sphere_capsule(const PhysxSphere & sphere, const PhysxCapsule & lss, const LVecBase3f & dir, float length, float & min_dist, LVecBase3f & ip, LVecBase3f & normal); - bool physx_swept_spheres_intersect(const PhysxSphere & sphere0, const LVecBase3f & velocity0, const PhysxSphere & sphere1, const LVecBase3f & velocity1); - bool physx_tri_box_intersect(const LVecBase3f & vertex0, const LVecBase3f & vertex1, const LVecBase3f & vertex2, const LVecBase3f & center, const LVecBase3f & extents); - + bool box_contains_point(const PhysxBox &box, const LPoint3f &p); + PhysxBox create_box(const PhysxBounds3 &aabb, const LMatrix4f &mat); + LVector3f compute_box_world_edge_normal(const PhysxBox &box, unsigned int edge_index); + PhysxCapsule compute_capsule_around_box(const PhysxBox &box); + bool is_box_a_inside_box_b(const PhysxBox &a, const PhysxBox &b); + PhysxBox compute_box_around_capsule(const PhysxCapsule &capsule); + void set_fpu_exceptions(bool b); + void set_fpu_precision24(); + void set_fpu_precision53(); + void set_fpu_precision64(); + void set_fpu_rounding_chop(); + void set_fpu_rounding_down(); + void set_fpu_rounding_near(); + void set_fpu_rounding_up(); + int int_ceil(const float &f); + int int_chop(const float &f); + int int_floor(const float &f); + float compute_distance_squared(const PhysxRay &ray, const LPoint3f &point); + float compute_square_distance(const PhysxSegment &seg, const LPoint3f &point); + PhysxSphere merge_spheres(const PhysxSphere &sphere0, const PhysxSphere &sphere1); + void normal_to_tangents(const LVector3f &n, LVector3f &t1, LVector3f &t2); + LMatrix3f find_rotation_matrix(const LVector3f &x, const LVector3f &b); + float compute_sphere_mass(float radius, float density); + float compute_sphere_density(float radius, float mass); + float compute_box_mass(const LVector3f &extents, float density); + float compute_box_density(const LVector3f &extents, float mass); + float compute_ellipsoid_mass(const LVector3f &extents, float density); + float compute_ellipsoid_density(const LVector3f &extents, float mass); + float compute_cylinder_mass(float radius, float length, float density); + float compute_cylinder_density(float radius, float length, float mass); + float compute_cone_mass(float radius, float length, float density); + float compute_cone_density(float radius, float length, float mass); + LVector3f compute_box_inertia_tensor(float mass, float xlength, float ylength, float zlength); + LVector3f compute_sphere_inertia_tensor(float mass, float radius, bool hollow); + bool box_box_intersect(const LVector3f &extents0, const LPoint3f ¢er0, const LMatrix3f &rotation0, const LVector3f &extents1, const LPoint3f ¢er1, const LMatrix3f &rotation1, bool full_test); + bool tri_box_intersect(const LPoint3f &vertex0, const LPoint3f &vertex1, const LPoint3f &vertex2, const LPoint3f ¢er, const LVector3f &extents); + bool ray_plane_intersect(const PhysxRay &ray, const PhysxPlane &plane, LPoint3f &point_on_plane); + bool ray_sphere_intersect(const LPoint3f &origin, const LVector3f &dir, float length, const LPoint3f ¢er, float radius, LPoint3f &hit_pos); + bool segment_box_intersect(const LPoint3f &p1, const LPoint3f &p2, const LPoint3f &bbox_min, const LPoint3f &bbox_max, LPoint3f &intercept); + bool ray_aabb_intersect(const LPoint3f &min, const LPoint3f &max, const LPoint3f &origin, const LVector3f &dir, LPoint3f &coord); + bool segment_obb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot); + bool segment_aabb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &min, const LPoint3f &max); + bool ray_obb_intersect(const PhysxRay &ray, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot); + unsigned int ray_capsule_intersect(const LPoint3f &origin, const LVector3f &dir, const PhysxCapsule &capsule); + bool swept_spheres_intersect(const PhysxSphere &sphere0, const LVector3f &velocity0, const PhysxSphere &sphere1, const LVector3f &velocity1); + bool ray_tri_intersect(const LPoint3f &orig, const LVector3f &dir, const LPoint3f &vert0, const LPoint3f &vert1, const LPoint3f &vert2, LVector3f &hit, bool cull); + bool sweep_box_capsule(const PhysxBox &box, const PhysxCapsule &lss, const LVector3f &dir, float length, LVector3f &normal); + bool sweep_box_sphere(const PhysxBox &box, const PhysxSphere &sphere, const LVector3f &dir, float length, LVector3f &normal); + bool sweep_capsule_capsule(const PhysxCapsule &lss0, const PhysxCapsule &lss1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal); + bool sweep_sphere_capsule(const PhysxSphere &sphere, const PhysxCapsule &lss, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal); + bool sweep_box_box(const PhysxBox &box0, const PhysxBox &box1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal); + float point_obb_sqr_dist(const LPoint3f &point, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot, LPoint3f ¶ms); public: - NxUtilLib *nUtilLib; + NxUtilLib *_ptr; }; #include "physxUtilLib.I" -#endif // HAVE_PHYSX +#endif // PHYSUTILLIB_H -#endif // PHYSXUTILLIB_H +/* +NOT WRAPPED: +bool NxComputeBoxPlanes(const NxBox &box, NxPlane *planes) +bool NxComputeBoxPoints(const NxBox &box, NxVec3 *pts) +bool NxComputeBoxVertexNormals(const NxBox &box, NxVec3 *pts) +const NxU32 *NxGetBoxEdges() +const NxI32 *NxGetBoxEdgesAxes() +const NxU32 *NxGetBoxTriangles() +const NxVec3 *NxGetBoxLocalEdgeNormals() +const NxU32 *NxGetBoxQuads() +const NxU32 *NxBoxVertexToQuad(NxU32 vertexIndex) +NxBSphereMethod NxComputeSphere(NxSphere &sphere, unsigned nb_verts, const NxVec3 *verts) +bool NxFastComputeSphere(NxSphere &sphere, unsigned nb_verts, const NxVec3 *verts) +bool NxDiagonalizeInertiaTensor(const NxMat33 &denseInertia, NxVec3 &diagonalInertia, NxMat33 &rotation) +void NxComputeBounds(NxVec3 &min, NxVec3 &max, NxU32 nbVerts, const NxVec3 *verts) +NxU32 NxCrc32(const void *buffer, NxU32 nbBytes) +NxSepAxis NxSeparatingAxis(const NxVec3 &extents0, const NxVec3 ¢er0, const NxMat33 &rotation0, const NxVec3 &extents1, const NxVec3 ¢er1, const NxMat33 &rotation1, bool fullTest=true) +void NxSegmentPlaneIntersect(const NxVec3 &v1, const NxVec3 &v2, const NxPlane &plane, NxReal &dist, NxVec3 &pointOnPlane) +NxU32 NxRayAABBIntersect2(const NxVec3 &min, const NxVec3 &max, const NxVec3 &origin, const NxVec3 &dir, NxVec3 &coord, NxReal &t) +bool NxBuildSmoothNormals(NxU32 nbTris, NxU32 nbVerts, const NxVec3 *verts, const NxU32 *dFaces, const NxU16 *wFaces, NxVec3 *normals, bool flip=false) +bool NxSweepBoxTriangles(NxU32 nb_tris, const NxTriangle *triangles, const NxTriangle *edge_triangles, const NxU32 *edge_flags, const NxBounds3 &box, const NxVec3 &dir, float length, NxVec3 &hit, NxVec3 &normal, float &d, NxU32 &index, NxU32 *cachedIndex=NULL) +bool NxSweepCapsuleTriangles(NxU32 up_direction, NxU32 nb_tris, const NxTriangle *triangles, const NxU32 *edge_flags, const NxVec3 ¢er, const float radius, const float height, const NxVec3 &dir, float length, NxVec3 &hit, NxVec3 &normal, float &d, NxU32 &index, NxU32 *cachedIndex=NULL) +float NxSegmentOBBSqrDist(const NxSegment &segment, const NxVec3 &c0, const NxVec3 &e0, const NxMat33 &r0, float *t, NxVec3 *p) +*/ diff --git a/panda/src/physx/physxWheelShape.I b/panda/src/physx/physxWheelShape.I new file mode 100644 index 0000000000..a8f0c6bfe1 --- /dev/null +++ b/panda/src/physx/physxWheelShape.I @@ -0,0 +1,36 @@ +// Filename: physxWheelShape.I +// Created by: enn0x (09Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxWheelShape:: +PhysxWheelShape() : PhysxShape() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxWheelShape:: +~PhysxWheelShape() { + +} + diff --git a/panda/src/physx/physxWheelShape.cxx b/panda/src/physx/physxWheelShape.cxx new file mode 100644 index 0000000000..e9b7baaba1 --- /dev/null +++ b/panda/src/physx/physxWheelShape.cxx @@ -0,0 +1,316 @@ +// Filename: physxWheelShape.cxx +// Created by: enn0x (09Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxWheelShape.h" +#include "physxWheelShapeDesc.h" +#include "physxSpringDesc.h" + +TypeHandle PhysxWheelShape::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +link(NxShape *shapePtr) { + + _ptr = shapePtr->isWheel(); + _ptr->userData = this; + _error_type = ET_ok; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.add(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +unlink() { + + _ptr->userData = NULL; + _error_type = ET_released; + + PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData; + actor->_shapes.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function : PhysxWheelShape::save_to_desc +// Access : Published +// Description : Saves the state of the shape object to a +// descriptor. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +save_to_desc(PhysxWheelShapeDesc &shapeDesc) const { + + nassertv(_error_type == ET_ok); + _ptr->saveToDesc(shapeDesc._desc); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::set_radius +// Access: Published +// Description: Sets the sphere radius. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +set_radius(float radius) { + + nassertv(_error_type == ET_ok); + _ptr->setRadius(radius); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::get_radius +// Access: Published +// Description: Returns the radius of the sphere. +//////////////////////////////////////////////////////////////////// +float PhysxWheelShape:: +get_radius() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getRadius(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::set_suspension_travel +// Access: Published +// Description: Set the maximum extension distance of suspension +// along shape's -Y axis. The minimum extension is +// always 0. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +set_suspension_travel(float travel) { + + nassertv(_error_type == ET_ok); + _ptr->setSuspensionTravel(travel); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::get_suspension_travel +// Access: Published +// Description: Returns the suspension travel +//////////////////////////////////////////////////////////////////// +float PhysxWheelShape:: +get_suspension_travel() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getSuspensionTravel(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::set_inverse_wheel_mass +// Access: Published +// Description: Set the inverse mass of the wheel. Determines the +// wheel velocity that wheel torques can achieve. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +set_inverse_wheel_mass(float invMass) { + + nassertv(_error_type == ET_ok); + _ptr->setInverseWheelMass(invMass); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::get_inverse_wheel_mass +// Access: Published +// Description: Returns the inverse mass of the wheel. Determines +// the wheel velocity that wheel torques can achieve. +//////////////////////////////////////////////////////////////////// +float PhysxWheelShape:: +get_inverse_wheel_mass() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getInverseWheelMass(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::set_motor_torque +// Access: Published +// Description: Set the sum engine torque on the wheel axle. +// Positive or negative depending on direction +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +set_motor_torque(float torque) { + + nassertv(_error_type == ET_ok); + _ptr->setMotorTorque(torque); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::get_motor_torque +// Access: Published +// Description: Retrieves the sum engine torque on the wheel axle. +// Positive or negative depending on direction +//////////////////////////////////////////////////////////////////// +float PhysxWheelShape:: +get_motor_torque() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getMotorTorque(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::set_brake_torque +// Access: Published +// Description: Must be nonnegative. Very large values should lock +// wheel but should be stable. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +set_brake_torque(float torque) { + + nassertv(_error_type == ET_ok); + _ptr->setBrakeTorque(torque); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::get_brake_torque +// Access: Published +// Description: Must be nonnegative. Very large values should lock +// wheel but should be stable. +//////////////////////////////////////////////////////////////////// +float PhysxWheelShape:: +get_brake_torque() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getBrakeTorque(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::set_steer_angle +// Access: Published +// Description: Set the steering angle, around shape Y axis. +// The steering angle is measured in degrees. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +set_steer_angle(float angle) { + + nassertv(_error_type == ET_ok); + _ptr->setSteerAngle(NxMath::degToRad(-1.0f * angle)); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::get_steer_angle +// Access: Published +// Description: Retrieves the steering angle, around shape Y axis. +// The steering angle is measured in degrees. +//////////////////////////////////////////////////////////////////// +float PhysxWheelShape:: +get_steer_angle() const { + + nassertr(_error_type == ET_ok, 0.0f); + return -1.0f * NxMath::radToDeg(_ptr->getSteerAngle()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::set_steer_angle_rad +// Access: Published +// Description: Set the steering angle, around shape Y axis. +// The steering angle is measured in radians. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +set_steer_angle_rad(float angle) { + + nassertv(_error_type == ET_ok); + _ptr->setSteerAngle(-1.0f * angle); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::get_steer_angle_rad +// Access: Published +// Description: Retrieves the steering angle, around shape Y axis. +// The steering angle is measured in radians. +//////////////////////////////////////////////////////////////////// +float PhysxWheelShape:: +get_steer_angle_rad() const { + + nassertr(_error_type == ET_ok, 0.0f); + return -1.0f * _ptr->getSteerAngle(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::set_axle_speed +// Access: Published +// Description: Set the current axle rotation speed. +// Note: WSF_axle_speed_override flag must be raised +// for this to have effect! +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +set_axle_speed(float speed) { + + nassertv(_error_type == ET_ok); + _ptr->setAxleSpeed(speed); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::get_axle_speed +// Access: Published +// Description: Retrieves the current axle rotation speed. +//////////////////////////////////////////////////////////////////// +float PhysxWheelShape:: +get_axle_speed() const { + + nassertr(_error_type == ET_ok, 0.0f); + return _ptr->getAxleSpeed(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::set_wheel_flag +// Access: Published +// Description: Turns the specified wheel shape flag on or off. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +set_wheel_flag(PhysxWheelShapeFlag flag, bool value) { + + nassertv(_error_type == ET_ok); + NxU32 flags = _ptr->getWheelFlags(); + + if (value == true) { + flags |= flag; + } else { + flags &= ~(flag); + } + + _ptr->setWheelFlags(flags); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::get_wheel_flag +// Access: Published +// Description: Returns the value of the specified wheel shape +// flag. +//////////////////////////////////////////////////////////////////// +bool PhysxWheelShape:: +get_wheel_flag(PhysxWheelShapeFlag flag) const { + + nassertr(_error_type == ET_ok, false); + return (_ptr->getWheelFlags() & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShape::set_suspension +// Access: Published +// Description: Set the data intended for car wheel suspension +// effects. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShape:: +set_suspension(const PhysxSpringDesc &spring) { + + nassertv(_error_type == ET_ok); + return _ptr->setSuspension(spring._desc); +} + diff --git a/panda/src/physx/physxWheelShape.h b/panda/src/physx/physxWheelShape.h new file mode 100644 index 0000000000..9a258023b8 --- /dev/null +++ b/panda/src/physx/physxWheelShape.h @@ -0,0 +1,133 @@ +// Filename: physxWheelShape.h +// Created by: enn0x (09Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXWHEELSHAPE_H +#define PHYSXWHEELSHAPE_H + +#include "pandabase.h" + +#include "physxShape.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxWheelShapeDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxWheelShape +// Description : A special shape used for simulating a car wheel. +// The -Y axis should be directed toward the ground. +// +// A ray is cast from the shape's origin along the -Y +// axis. When the ray strikes something, and the +// distance is: +// +// - less than wheelRadius from the shape origin: +// a hard contact is created +// - between wheelRadius and (suspensionTravel + +// wheelRadius): a soft suspension contact is +// created +// - greater than (suspensionTravel + wheelRadius): +// no contact is created. +// +// Thus at the point of greatest possible suspension +// compression the wheel axle will pass through at +// the shape's origin. At the point greatest +// suspension extension the wheel axle will be a +// distance of suspensionTravel from the shape's +// origin. +// +// The suspension's targetValue is 0 for real cars, +// which means that the suspension tries to extend +// all the way. Otherwise one can specify values +// [0,1] for suspensions which have a spring to +// pull the wheel up when it is extended too far. +// 0.5 will then fall halfway along suspensionTravel. +// +// The +Z axis is the 'forward' direction of travel +// for the wheel. -Z is backwards. The wheel rolls +// forward when rotating around the positive direction +// around the X axis. +// +// A positive wheel steering angle corresponds to a +// positive rotation around the shape's Y axis. +// (Castor angles are not modeled.) +// +// The coordinate frame of the shape is rigidly fixed +// on the car. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxWheelShape : public PhysxShape { + +PUBLISHED: + INLINE PhysxWheelShape(); + INLINE ~PhysxWheelShape(); + + void save_to_desc(PhysxWheelShapeDesc &shapeDesc) const; + + void set_radius(float radius); + void set_suspension_travel(float travel); + void set_inverse_wheel_mass(float invMass); + void set_motor_torque(float torque); + void set_brake_torque(float torque); + void set_steer_angle(float angle); + void set_steer_angle_rad(float angle); + void set_axle_speed(float speed); + void set_wheel_flag(PhysxWheelShapeFlag flag, bool value); + void set_suspension(const PhysxSpringDesc &spring); + + float get_radius() const; + float get_suspension_travel() const; + float get_inverse_wheel_mass() const; + float get_motor_torque() const; + float get_brake_torque() const; + float get_steer_angle() const; + float get_steer_angle_rad() const; + float get_axle_speed() const; + bool get_wheel_flag(PhysxWheelShapeFlag flag) const; + +//////////////////////////////////////////////////////////////////// +public: + INLINE NxShape *ptr() const { return (NxShape *)_ptr; }; + + void link(NxShape *shapePtr); + void unlink(); + +private: + NxWheelShape *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxShape::init_type(); + register_type(_type_handle, "PhysxWheelShape", + PhysxShape::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxWheelShape.I" + +#endif // PHYSXWHEELSHAPE_H diff --git a/panda/src/physx/physxWheelShapeDesc.I b/panda/src/physx/physxWheelShapeDesc.I new file mode 100644 index 0000000000..8ee757a9c0 --- /dev/null +++ b/panda/src/physx/physxWheelShapeDesc.I @@ -0,0 +1,59 @@ +// Filename: physxWheelShapeDesc.I +// Created by: enn0x (09Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxWheelShapeDesc:: +PhysxWheelShapeDesc() : PhysxShapeDesc() { + + _desc.name = ""; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxWheelShapeDesc:: +~PhysxWheelShapeDesc() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::set_to_default +// Access: Published +// Description: (re)sets the structure to the default. +//////////////////////////////////////////////////////////////////// +INLINE void PhysxWheelShapeDesc:: +set_to_default() { + + _desc.setToDefault(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::is_valid +// Access: Published +// Description: Returns true if the descriptor is valid. +//////////////////////////////////////////////////////////////////// +INLINE bool PhysxWheelShapeDesc:: +is_valid() const { + + return _desc.isValid(); +} + diff --git a/panda/src/physx/physxWheelShapeDesc.cxx b/panda/src/physx/physxWheelShapeDesc.cxx new file mode 100644 index 0000000000..1a97065b5b --- /dev/null +++ b/panda/src/physx/physxWheelShapeDesc.cxx @@ -0,0 +1,202 @@ +// Filename: physxWheelShapeDesc.cxx +// Created by: enn0x (09Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxWheelShapeDesc.h" + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::set_radius +// Access: Published +// Description: Radius of shape. Must be positive. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShapeDesc:: +set_radius(float radius) { + + _desc.radius = radius; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::get_radius +// Access: Published +// Description: Radius of shape. +//////////////////////////////////////////////////////////////////// +float PhysxWheelShapeDesc:: +get_radius() const { + + return _desc.radius; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::set_suspension_travel +// Access: Published +// Description: Set the maximum extension distance of suspension +// along shape's -Y axis. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShapeDesc:: +set_suspension_travel(float suspensionTravel) { + + _desc.suspensionTravel = suspensionTravel; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::get_suspension_travel +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxWheelShapeDesc:: +get_suspension_travel() const { + + return _desc.suspensionTravel; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::set_inverse_wheel_mass +// Access: Published +// Description: Set the inverse mass of the wheel. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShapeDesc:: +set_inverse_wheel_mass(float inverseWheelMass) { + + _desc.inverseWheelMass = inverseWheelMass; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::get_inverse_wheel_mass +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxWheelShapeDesc:: +get_inverse_wheel_mass() const { + + return _desc.inverseWheelMass; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::set_motor_torque +// Access: Published +// Description: Set the sum engine torque on the wheel axle. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShapeDesc:: +set_motor_torque(float motorTorque) { + + _desc.motorTorque = motorTorque; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::get_motor_torque +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxWheelShapeDesc:: +get_motor_torque() const { + + return _desc.motorTorque; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::set_brake_torque +// Access: Published +// Description: Set the amount of torque applied for braking. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShapeDesc:: +set_brake_torque(float brakeTorque) { + + _desc.brakeTorque = brakeTorque; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::get_brake_torque +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxWheelShapeDesc:: +get_brake_torque() const { + + return _desc.brakeTorque; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::set_steer_angle +// Access: Published +// Description: Set the steering angle, around shape Y axis. +// The steering angle is measured in degrees. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShapeDesc:: +set_steer_angle(float steerAngle) { + + _desc.steerAngle = NxMath::degToRad(steerAngle); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::get_steer_angle +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float PhysxWheelShapeDesc:: +get_steer_angle() const { + + return _desc.steerAngle; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::set_wheel_flag +// Access: Published +// Description: Turn the specified wheel shape flag on or off. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShapeDesc:: +set_wheel_flag(PhysxWheelShapeFlag flag, bool value) { + + if (value == true) { + _desc.wheelFlags |= flag; + } + else { + _desc.wheelFlags &= ~(flag); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::get_wheel_flag +// Access: Published +// Description: Returns the specified wheel shape flag. +//////////////////////////////////////////////////////////////////// +bool PhysxWheelShapeDesc:: +get_wheel_flag(const PhysxWheelShapeFlag flag) const { + + return (_desc.wheelFlags & flag) ? true : false; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::set_suspension +// Access: Published +// Description: Set the data intended for car wheel suspension +// effects. +//////////////////////////////////////////////////////////////////// +void PhysxWheelShapeDesc:: +set_suspension(const PhysxSpringDesc &spring) { + + _desc.suspension = spring._desc; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxWheelShapeDesc::get_suspension +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxSpringDesc PhysxWheelShapeDesc:: +get_suspension() const { + + PhysxSpringDesc value; + value._desc = _desc.suspension; + return value; +} + diff --git a/panda/src/physx/physxWheelShapeDesc.h b/panda/src/physx/physxWheelShapeDesc.h new file mode 100644 index 0000000000..7da24b34df --- /dev/null +++ b/panda/src/physx/physxWheelShapeDesc.h @@ -0,0 +1,65 @@ +// Filename: physxWheelShapeDesc.h +// Created by: enn0x (09Nov09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXWHEELSHAPEDESC_H +#define PHYSXWHEELSHAPEDESC_H + +#include "pandabase.h" + +#include "physxShapeDesc.h" + +#include "NoMinMax.h" +#include "NxPhysics.h" + +class PhysxSpringDesc; + +//////////////////////////////////////////////////////////////////// +// Class : PhysxWheelShapeDesc +// Description : Descriptor class for PhysxWheelShape. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxWheelShapeDesc : public PhysxShapeDesc { + +PUBLISHED: + INLINE PhysxWheelShapeDesc(); + INLINE ~PhysxWheelShapeDesc(); + + INLINE void set_to_default(); + INLINE bool is_valid() const; + + void set_radius(float radius); + void set_suspension_travel(float suspensionTravel); + void set_inverse_wheel_mass(float inverseWheelMass); + void set_motor_torque(float motorTorque); + void set_brake_torque(float brakeTorque); + void set_steer_angle(float steerAngle); + void set_wheel_flag(PhysxWheelShapeFlag flag, bool value); + void set_suspension(const PhysxSpringDesc &spring); + + float get_radius() const; + float get_suspension_travel() const; + float get_inverse_wheel_mass() const; + float get_motor_torque() const; + float get_brake_torque() const; + float get_steer_angle() const; + bool get_wheel_flag(PhysxWheelShapeFlag flag) const; + PhysxSpringDesc get_suspension() const; + +public: + NxShapeDesc *ptr() const { return (NxShapeDesc *)&_desc; }; + NxWheelShapeDesc _desc; +}; + +#include "physxWheelShapeDesc.I" + +#endif // PHYSXWHEELSHAPEDESC_H diff --git a/panda/src/physx/physx_composite.cxx b/panda/src/physx/physx_composite.cxx index 031e7f4fb1..9200b6dae9 100644 --- a/panda/src/physx/physx_composite.cxx +++ b/panda/src/physx/physx_composite.cxx @@ -1,31 +1,90 @@ - #include "config_physx.cxx" +#include "physxActor.cxx" #include "physxActorDesc.cxx" -#include "physxActorNode.cxx" #include "physxBodyDesc.cxx" #include "physxBounds3.cxx" #include "physxBox.cxx" +#include "physxBoxController.cxx" +#include "physxBoxControllerDesc.cxx" +#include "physxBoxForceFieldShape.cxx" +#include "physxBoxForceFieldShapeDesc.cxx" #include "physxBoxShape.cxx" #include "physxBoxShapeDesc.cxx" #include "physxCapsule.cxx" +#include "physxCapsuleController.cxx" +#include "physxCapsuleControllerDesc.cxx" +#include "physxCapsuleForceFieldShape.cxx" +#include "physxCapsuleForceFieldShapeDesc.cxx" #include "physxCapsuleShape.cxx" #include "physxCapsuleShapeDesc.cxx" -#include "physxContactHandler.cxx" +#include "physxContactPair.cxx" +#include "physxContactPoint.cxx" +#include "physxContactReport.cxx" +#include "physxController.cxx" +#include "physxControllerDesc.cxx" +#include "physxControllerReport.cxx" +#include "physxConstraintDominance.cxx" +#include "physxConvexForceFieldShape.cxx" +#include "physxConvexForceFieldShapeDesc.cxx" +#include "physxConvexMesh.cxx" +#include "physxConvexMeshDesc.cxx" +#include "physxConvexShape.cxx" +#include "physxConvexShapeDesc.cxx" +#include "physxCylindricalJoint.cxx" +#include "physxCylindricalJointDesc.cxx" #include "physxD6Joint.cxx" #include "physxD6JointDesc.cxx" +#include "physxDebugGeomNode.cxx" +#include "physxDistanceJoint.cxx" +#include "physxDistanceJointDesc.cxx" +#include "physxEnums.cxx" +#include "physxFileStream.cxx" +#include "physxFixedJoint.cxx" +#include "physxFixedJointDesc.cxx" +#include "physxForceField.cxx" +#include "physxForceFieldDesc.cxx" +#include "physxForceFieldShape.cxx" +#include "physxForceFieldShapeDesc.cxx" +#include "physxForceFieldShapeGroup.cxx" +#include "physxForceFieldShapeGroupDesc.cxx" +#include "physxGroupsMask.cxx" +#include "physxHeightField.cxx" +#include "physxHeightFieldDesc.cxx" +#include "physxHeightFieldShape.cxx" +#include "physxHeightFieldShapeDesc.cxx" #include "physxJoint.cxx" #include "physxJointDesc.cxx" #include "physxJointDriveDesc.cxx" -#include "physxJointHandler.cxx" +#include "physxJointLimitDesc.cxx" #include "physxJointLimitSoftDesc.cxx" -#include "physxJointLimitSoftPairDesc.cxx" +#include "physxKitchen.cxx" #include "physxManager.cxx" +#include "physxMask.cxx" #include "physxMaterial.cxx" #include "physxMaterialDesc.cxx" +#include "physxMemoryReadBuffer.cxx" +#include "physxMemoryWriteBuffer.cxx" +#include "physxMeshPool.cxx" +#include "physxMotorDesc.cxx" +#include "physxObject.cxx" +#include "physxObjectCollection.cxx" +#include "physxOverlapReport.cxx" #include "physxPlane.cxx" #include "physxPlaneShape.cxx" #include "physxPlaneShapeDesc.cxx" +#include "physxPointInPlaneJoint.cxx" +#include "physxPointInPlaneJointDesc.cxx" +#include "physxPointOnLineJoint.cxx" +#include "physxPointOnLineJointDesc.cxx" +#include "physxPrismaticJoint.cxx" +#include "physxPrismaticJointDesc.cxx" +#include "physxPulleyJoint.cxx" +#include "physxPulleyJointDesc.cxx" #include "physxRay.cxx" +#include "physxRaycastHit.cxx" +#include "physxRaycastReport.cxx" +#include "physxRevoluteJoint.cxx" +#include "physxRevoluteJointDesc.cxx" #include "physxScene.cxx" #include "physxSceneDesc.cxx" #include "physxSceneStats2.cxx" @@ -33,7 +92,18 @@ #include "physxShape.cxx" #include "physxShapeDesc.cxx" #include "physxSphere.cxx" +#include "physxSphereForceFieldShape.cxx" +#include "physxSphereForceFieldShapeDesc.cxx" #include "physxSphereShape.cxx" #include "physxSphereShapeDesc.cxx" -#include "physxTriggerHandler.cxx" +#include "physxSphericalJoint.cxx" +#include "physxSphericalJointDesc.cxx" +#include "physxSpringDesc.cxx" +#include "physxTriangleMesh.cxx" +#include "physxTriangleMeshDesc.cxx" +#include "physxTriangleMeshShape.cxx" +#include "physxTriangleMeshShapeDesc.cxx" +#include "physxTriggerReport.cxx" #include "physxUtilLib.cxx" +#include "physxWheelShape.cxx" +#include "physxWheelShapeDesc.cxx" diff --git a/panda/src/physx/physx_enumerations.h b/panda/src/physx/physx_enumerations.h deleted file mode 100644 index d36311af52..0000000000 --- a/panda/src/physx/physx_enumerations.h +++ /dev/null @@ -1,826 +0,0 @@ -// Filename: physx_enumerations.h -// Created by: pratt (Apr 20, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifndef PHYSX_ENUMERATIONS_H -#define PHYSX_ENUMERATIONS_H - -#ifdef HAVE_PHYSX - -#include "NoMinMax.h" -#include "NxPhysics.h" - -enum PhysxActorDescType { - physx_adt_shapeless = NX_ADT_SHAPELESS, - physx_adt_default = NX_ADT_DEFAULT, - physx_adt_allocator = NX_ADT_ALLOCATOR, - physx_adt_list = NX_ADT_LIST, - physx_adt_pointer = NX_ADT_POINTER, -}; - -enum PhysxActorFlag { - physx_af_fluid_disable_collision = NX_AF_FLUID_DISABLE_COLLISION, - physx_af_contact_modification = NX_AF_CONTACT_MODIFICATION, - physx_af_disable_collision = NX_AF_DISABLE_COLLISION, - physx_af_disable_response = NX_AF_DISABLE_RESPONSE, - physx_af_lock_com = NX_AF_LOCK_COM, - physx_af_user_actor_pair_filtering = NX_AF_USER_ACTOR_PAIR_FILTERING, - physx_af_force_cone_friction = NX_AF_FORCE_CONE_FRICTION, -}; - -enum PhysxAssertResponse { - physx_ar_continue = NX_AR_CONTINUE, - physx_ar_ignore = NX_AR_IGNORE, - physx_ar_breakpoint = NX_AR_BREAKPOINT, -}; - -enum PhysxAxisType { - physx_axis_plus_x = NX_AXIS_PLUS_X, - physx_axis_minus_x = NX_AXIS_MINUS_X, - physx_axis_plus_y = NX_AXIS_PLUS_Y, - physx_axis_minus_y = NX_AXIS_MINUS_Y, - physx_axis_plus_z = NX_AXIS_PLUS_Z, - physx_axis_minus_z = NX_AXIS_MINUS_Z, - physx_axis_arbitrary = NX_AXIS_ARBITRARY, -}; - -enum PhysxBSphereMethod { - physx_bs_none = NX_BS_NONE, - physx_bs_gems = NX_BS_GEMS, - physx_bs_miniball = NX_BS_MINIBALL, - physx_bs_force_dword = NX_BS_FORCE_DWORD, -}; - -enum PhysxBodyFlag { - physx_bf_frozen_rot_z = NX_BF_FROZEN_ROT_Z, - physx_bf_frozen_rot_y = NX_BF_FROZEN_ROT_Y, - physx_bf_frozen_rot_x = NX_BF_FROZEN_ROT_X, - physx_bf_kinematic = NX_BF_KINEMATIC, - physx_bf_pose_sleep_test = NX_BF_POSE_SLEEP_TEST, - physx_bf_disable_gravity = NX_BF_DISABLE_GRAVITY, - physx_bf_frozen_pos_z = NX_BF_FROZEN_POS_Z, - physx_bf_frozen_pos_x = NX_BF_FROZEN_POS_X, - physx_bf_frozen_pos_y = NX_BF_FROZEN_POS_Y, - physx_bf_visualization = NX_BF_VISUALIZATION, - physx_bf_filter_sleep_vel = NX_BF_FILTER_SLEEP_VEL, - physx_bf_energy_sleep_test = NX_BF_ENERGY_SLEEP_TEST, -}; - -enum PhysxCapsuleShapeFlag { - physx_swept_shape = NX_SWEPT_SHAPE, -}; - -enum PhysxClothAttachmentFlag { - physx_cloth_attachment_tearable = NX_CLOTH_ATTACHMENT_TEARABLE, - physx_cloth_attachment_twoway = NX_CLOTH_ATTACHMENT_TWOWAY, -}; - -enum PhysxClothFlag { - physx_clf_disable_collision = NX_CLF_DISABLE_COLLISION, - physx_clf_bending_ortho = NX_CLF_BENDING_ORTHO, - physx_clf_bending = NX_CLF_BENDING, - physx_clf_pressure = NX_CLF_PRESSURE, - physx_clf_damping = NX_CLF_DAMPING, - physx_clf_fluid_collision = NX_CLF_FLUID_COLLISION, - physx_clf_triangle_collision = NX_CLF_TRIANGLE_COLLISION, - physx_clf_visualization = NX_CLF_VISUALIZATION, - physx_clf_collision_twoway = NX_CLF_COLLISION_TWOWAY, - physx_clf_hardware = NX_CLF_HARDWARE, - physx_clf_gravity = NX_CLF_GRAVITY, - physx_clf_selfcollision = NX_CLF_SELFCOLLISION, - physx_clf_tearable = NX_CLF_TEARABLE, - physx_clf_validbounds = NX_CLF_VALIDBOUNDS, - physx_clf_static = NX_CLF_STATIC, - physx_clf_comdamping = NX_CLF_COMDAMPING, -}; - -enum PhysxClothMeshFlags { - physx_cloth_mesh_tearable = NX_CLOTH_MESH_TEARABLE, -}; - -enum PhysxClothVertexAttachmentStatus { - physx_cloth_vertex_attachment_none = NX_CLOTH_VERTEX_ATTACHMENT_NONE, - physx_cloth_vertex_attachment_global = NX_CLOTH_VERTEX_ATTACHMENT_GLOBAL, - physx_cloth_vertex_attachment_shape = NX_CLOTH_VERTEX_ATTACHMENT_SHAPE, -}; - -enum PhysxClothVertexFlags { - physx_cloth_vertex_attached = NX_CLOTH_VERTEX_ATTACHED, - physx_cloth_vertex_tearable = NX_CLOTH_VERTEX_TEARABLE, -}; - -enum PhysxCombineMode { - physx_cm_multiply = NX_CM_MULTIPLY, - physx_cm_average = NX_CM_AVERAGE, - physx_cm_max = NX_CM_MAX, - physx_cm_pad_32 = NX_CM_PAD_32, - physx_cm_n_values = NX_CM_N_VALUES, - physx_cm_min = NX_CM_MIN, -}; - -enum PhysxCompartmentFlag { - physx_cf_sleep_notification = NX_CF_SLEEP_NOTIFICATION, - physx_cf_continuous_cd = NX_CF_CONTINUOUS_CD, - physx_cf_inherit_settings = NX_CF_INHERIT_SETTINGS, - physx_cf_restricted_scene = NX_CF_RESTRICTED_SCENE, -}; - -enum PhysxCompartmentType { - physx_sct_cloth = NX_SCT_CLOTH, - physx_sct_rigidbody = NX_SCT_RIGIDBODY, - physx_sct_softbody = NX_SCT_SOFTBODY, - physx_sct_fluid = NX_SCT_FLUID, -}; - -enum PhysxContactPairFlag { - physx_ignore_pair = NX_IGNORE_PAIR, - physx_notify_on_touch = NX_NOTIFY_ON_TOUCH, - physx_notify_on_end_touch = NX_NOTIFY_ON_END_TOUCH, - physx_notify_forces = NX_NOTIFY_FORCES, - physx_notify_on_slide = NX_NOTIFY_ON_SLIDE, - physx_notify_on_impact = NX_NOTIFY_ON_IMPACT, - physx_notify_contact_modification = NX_NOTIFY_CONTACT_MODIFICATION, - physx_notify_on_roll = NX_NOTIFY_ON_ROLL, - physx_notify_on_start_touch = NX_NOTIFY_ON_START_TOUCH, -}; - -enum PhysxConvexFlags { - physx_cf_use_uncompressed_normals = NX_CF_USE_UNCOMPRESSED_NORMALS, - physx_cf_flipnormals = NX_CF_FLIPNORMALS, - physx_cf_use_legacy_cooker = NX_CF_USE_LEGACY_COOKER, - physx_cf_inflate_convex = NX_CF_INFLATE_CONVEX, - physx_cf_16_bit_indices = NX_CF_16_BIT_INDICES, - physx_cf_compute_convex = NX_CF_COMPUTE_CONVEX, -}; - -enum PhysxCookingValue { - physx_cooking_convex_version_pc = NX_COOKING_CONVEX_VERSION_PC, - physx_cooking_mesh_version_pc = NX_COOKING_MESH_VERSION_PC, - physx_cooking_convex_version_xenon = NX_COOKING_CONVEX_VERSION_XENON, - physx_cooking_mesh_version_xenon = NX_COOKING_MESH_VERSION_XENON, - physx_cooking_convex_version_playstation3 = NX_COOKING_CONVEX_VERSION_PLAYSTATION3, - physx_cooking_mesh_version_playstation3 = NX_COOKING_MESH_VERSION_PLAYSTATION3, -}; - -enum PhysxD6JointDriveType { - physx_d6joint_drive_velocity = NX_D6JOINT_DRIVE_VELOCITY, - physx_d6joint_drive_position = NX_D6JOINT_DRIVE_POSITION, -}; - -enum PhysxD6JointFlag { - physx_d6joint_slerp_drive = NX_D6JOINT_SLERP_DRIVE, - physx_d6joint_gear_enabled = NX_D6JOINT_GEAR_ENABLED, -}; - -enum PhysxD6JointMotion { - physx_d6joint_motion_locked = NX_D6JOINT_MOTION_LOCKED, - physx_d6joint_motion_limited = NX_D6JOINT_MOTION_LIMITED, - physx_d6joint_motion_free = NX_D6JOINT_MOTION_FREE, -}; - -enum PhysxDebugColor { - physx_argb_white = NX_ARGB_WHITE, - physx_argb_green = NX_ARGB_GREEN, - physx_argb_red = NX_ARGB_RED, - physx_argb_yellow = NX_ARGB_YELLOW, - physx_argb_magenta = NX_ARGB_MAGENTA, - physx_argb_blue = NX_ARGB_BLUE, - physx_argb_cyan = NX_ARGB_CYAN, - physx_argb_black = NX_ARGB_BLACK, -}; - -enum PhysxDeviceCode { - physx_dc_ppu_0 = NX_DC_PPU_0, - physx_dc_ppu_1 = NX_DC_PPU_1, - physx_dc_ppu_2 = NX_DC_PPU_2, - physx_dc_ppu_3 = NX_DC_PPU_3, - physx_dc_ppu_4 = NX_DC_PPU_4, - physx_dc_ppu_5 = NX_DC_PPU_5, - physx_dc_ppu_6 = NX_DC_PPU_6, - physx_dc_ppu_7 = NX_DC_PPU_7, - physx_dc_ppu_8 = NX_DC_PPU_8, - physx_dc_cpu = NX_DC_CPU, - physx_dc_ppu_auto_assign = NX_DC_PPU_AUTO_ASSIGN, -}; - -enum PhysxDistanceJointFlag { - physx_djf_max_distance_enabled = NX_DJF_MAX_DISTANCE_ENABLED, - physx_djf_min_distance_enabled = NX_DJF_MIN_DISTANCE_ENABLED, - physx_djf_spring_enabled = NX_DJF_SPRING_ENABLED, -}; - -enum PhysxEffectorType { - physx_effector_spring_and_damper = NX_EFFECTOR_SPRING_AND_DAMPER, -}; - -enum PhysxEmitterShape { - physx_fe_ellipse = NX_FE_ELLIPSE, - physx_fe_rectangular = NX_FE_RECTANGULAR, -}; - -enum PhysxEmitterType { - physx_fe_constant_flow_rate = NX_FE_CONSTANT_FLOW_RATE, - physx_fe_constant_pressure = NX_FE_CONSTANT_PRESSURE, -}; - -enum PhysxErrorCode { - physxe_invalid_parameter = NXE_INVALID_PARAMETER, - physxe_db_warning = NXE_DB_WARNING, - physxe_out_of_memory = NXE_OUT_OF_MEMORY, - physxe_internal_error = NXE_INTERNAL_ERROR, - physxe_invalid_operation = NXE_INVALID_OPERATION, - physxe_db_info = NXE_DB_INFO, - physxe_assertion = NXE_ASSERTION, - physxe_no_error = NXE_NO_ERROR, - physxe_db_print = NXE_DB_PRINT, -}; - -enum PhysxFilterOp { - physx_filterop_and = NX_FILTEROP_AND, - physx_filterop_or = NX_FILTEROP_OR, - physx_filterop_xor = NX_FILTEROP_XOR, - physx_filterop_nand = NX_FILTEROP_NAND, - physx_filterop_nor = NX_FILTEROP_NOR, - physx_filterop_nxor = NX_FILTEROP_NXOR, - physx_filterop_swap_and = NX_FILTEROP_SWAP_AND, -}; - -enum PhysxFluidCollisionMethod { - physx_f_static = NX_F_STATIC, - physx_f_dynamic = NX_F_DYNAMIC, -}; - -enum PhysxFluidDescType { - physx_fdt_default = NX_FDT_DEFAULT, - physx_fdt_allocator = NX_FDT_ALLOCATOR, -}; - -enum PhysxFluidEmitterEventType { - physx_feet_emitter_empty = NX_FEET_EMITTER_EMPTY, -}; - -enum PhysxFluidEmitterFlag { - physx_fef_visualization = NX_FEF_VISUALIZATION, - physx_fef_add_body_velocity = NX_FEF_ADD_BODY_VELOCITY, - physx_fef_enabled = NX_FEF_ENABLED, - physx_fef_force_on_body = NX_FEF_FORCE_ON_BODY, -}; - -enum PhysxFluidEventType { - physx_fet_no_particles_left = NX_FET_NO_PARTICLES_LEFT, -}; - -enum PhysxFluidFlag { - physx_ff_visualization = NX_FF_VISUALIZATION, - physx_ff_disable_gravity = NX_FF_DISABLE_GRAVITY, - physx_ff_hardware = NX_FF_HARDWARE, - physx_ff_priority_mode = NX_FF_PRIORITY_MODE, - physx_ff_collision_twoway = NX_FF_COLLISION_TWOWAY, - physx_ff_enabled = NX_FF_ENABLED, -}; - -enum PhysxFluidSimulationMethod { - physx_f_sph = NX_F_SPH, - physx_f_mixed_mode = NX_F_MIXED_MODE, - physx_f_no_particle_interaction = NX_F_NO_PARTICLE_INTERACTION, -}; - -enum PhysxForceFieldCoordinates { - physx_ffc_cartesian = NX_FFC_CARTESIAN, - physx_ffc_spherical = NX_FFC_SPHERICAL, - physx_ffc_cylindrical = NX_FFC_CYLINDRICAL, - physx_ffc_toroidal = NX_FFC_TOROIDAL, -}; - -enum PhysxForceFieldFlags { - physx_fff_ignore_rigidbody_mass = NX_FFF_IGNORE_RIGIDBODY_MASS, - physx_fff_ignore_fluid_mass = NX_FFF_IGNORE_FLUID_MASS, - physx_fff_legacy_force = NX_FFF_LEGACY_FORCE, - physx_fff_ignore_cloth_mass = NX_FFF_IGNORE_CLOTH_MASS, - physx_fff_ignore_softbody_mass = NX_FFF_IGNORE_SOFTBODY_MASS, -}; - -enum PhysxForceFieldShapeFlags { - physx_ffs_exclude = NX_FFS_EXCLUDE, -}; - -enum PhysxForceFieldType { - physx_ff_type_force = NX_FF_TYPE_FORCE, - physx_ff_type_acceleration = NX_FF_TYPE_ACCELERATION, -}; - -enum PhysxForceMode { - physx_force = NX_FORCE, - physx_impulse = NX_IMPULSE, - physx_velocity_change = NX_VELOCITY_CHANGE, - physx_smooth_impulse = NX_SMOOTH_IMPULSE, - physx_smooth_velocity_change = NX_SMOOTH_VELOCITY_CHANGE, - physx_acceleration = NX_ACCELERATION, -}; - -enum PhysxHWVersion { - physx_hw_version_none = NX_HW_VERSION_NONE, - physx_hw_version_athena_1_0 = NX_HW_VERSION_ATHENA_1_0, -}; - -enum PhysxHeightFieldAxis { - physx_not_heightfield = NX_NOT_HEIGHTFIELD, - physx_z = NX_Z, - physx_y = NX_Y, - physx_x = NX_X, -}; - -enum PhysxHeightFieldFlags { - physx_hf_no_boundary_edges = NX_HF_NO_BOUNDARY_EDGES, -}; - -enum PhysxHeightFieldFormat { - physx_hf_s16_tm = NX_HF_S16_TM, -}; - -enum PhysxHeightFieldTessFlag { - physx_hf_0th_vertex_shared = NX_HF_0TH_VERTEX_SHARED, -}; - -enum PhysxInternalArray { - physx_array_triangles = NX_ARRAY_TRIANGLES, - physx_array_vertices = NX_ARRAY_VERTICES, - physx_array_normals = NX_ARRAY_NORMALS, - physx_array_hull_vertices = NX_ARRAY_HULL_VERTICES, - physx_array_hull_polygons = NX_ARRAY_HULL_POLYGONS, -}; - -enum PhysxInternalFormat { - physx_format_nodata = NX_FORMAT_NODATA, - physx_format_float = NX_FORMAT_FLOAT, - physx_format_byte = NX_FORMAT_BYTE, - physx_format_short = NX_FORMAT_SHORT, - physx_format_int = NX_FORMAT_INT, -}; - -enum PhysxJointFlag { - physx_jf_collision_enabled = NX_JF_COLLISION_ENABLED, - physx_jf_visualization = NX_JF_VISUALIZATION, -}; - -enum PhysxJointProjectionMode { - physx_jpm_linear_mindist = NX_JPM_LINEAR_MINDIST, - physx_jpm_point_mindist = NX_JPM_POINT_MINDIST, - physx_jpm_none = NX_JPM_NONE, -}; - -enum PhysxJointState { - physx_js_unbound = NX_JS_UNBOUND, - physx_js_simulating = NX_JS_SIMULATING, - physx_js_broken = NX_JS_BROKEN, -}; - -enum PhysxJointType { - physx_joint_prismatic = NX_JOINT_PRISMATIC, - physx_joint_revolute = NX_JOINT_REVOLUTE, - physx_joint_cylindrical = NX_JOINT_CYLINDRICAL, - physx_joint_spherical = NX_JOINT_SPHERICAL, - physx_joint_point_on_line = NX_JOINT_POINT_ON_LINE, - physx_joint_point_in_plane = NX_JOINT_POINT_IN_PLANE, - physx_joint_distance = NX_JOINT_DISTANCE, - physx_joint_pulley = NX_JOINT_PULLEY, - physx_joint_fixed = NX_JOINT_FIXED, - physx_joint_d6 = NX_JOINT_D6, - physx_joint_count = NX_JOINT_COUNT, - physx_joint_force_dword = NX_JOINT_FORCE_DWORD, -}; - -enum PhysxMaterialFlag { - physx_mf_disable_friction = NX_MF_DISABLE_FRICTION, - physx_mf_disable_strong_friction = NX_MF_DISABLE_STRONG_FRICTION, - physx_mf_anisotropic = NX_MF_ANISOTROPIC, -}; - -enum PhysxMatrixType { - physx_zero_matrix = NX_ZERO_MATRIX, - physx_identity_matrix = NX_IDENTITY_MATRIX, -}; - -enum PhysxMeshDataDirtyBufferFlags { - physx_mdf_vertices_pos_dirty = NX_MDF_VERTICES_POS_DIRTY, - physx_mdf_parent_indices_dirty = NX_MDF_PARENT_INDICES_DIRTY, - physx_mdf_vertices_normal_dirty = NX_MDF_VERTICES_NORMAL_DIRTY, - physx_mdf_indices_dirty = NX_MDF_INDICES_DIRTY, -}; - -enum PhysxMeshDataFlags { - physx_mdf_16_bit_indices = NX_MDF_16_BIT_INDICES, -}; - -enum PhysxMeshFlags { - physx_mf_16_bit_indices = NX_MF_16_BIT_INDICES, - physx_mf_flipnormals = NX_MF_FLIPNORMALS, - physx_mf_hardware_mesh = NX_MF_HARDWARE_MESH, -}; - -enum PhysxMeshPagingMode { - physx_mesh_paging_manual = NX_MESH_PAGING_MANUAL, - physx_mesh_paging_fallback = NX_MESH_PAGING_FALLBACK, - physx_mesh_paging_auto = NX_MESH_PAGING_AUTO, -}; - -enum PhysxMeshShapeFlag { - physx_mesh_double_sided = NX_MESH_DOUBLE_SIDED, - physx_mesh_smooth_sphere_collisions = NX_MESH_SMOOTH_SPHERE_COLLISIONS, -}; - -enum PhysxParameter { - physx_visualize_collision_edges = NX_VISUALIZE_COLLISION_EDGES, - physx_params_num_values = NX_PARAMS_NUM_VALUES, - physx_visualize_collision_dynamic = NX_VISUALIZE_COLLISION_DYNAMIC, - physx_visualize_contact_error = NX_VISUALIZE_CONTACT_ERROR, - physx_visualize_fluid_motion_limit = NX_VISUALIZE_FLUID_MOTION_LIMIT, - physx_visualize_cloth_workpackets = NX_VISUALIZE_CLOTH_WORKPACKETS, - physx_visualize_fluid_velocity = NX_VISUALIZE_FLUID_VELOCITY, - physx_visualize_fluid_mesh_packets = NX_VISUALIZE_FLUID_MESH_PACKETS, - physx_visualize_body_axes = NX_VISUALIZE_BODY_AXES, - physx_visualize_softbody_sleep = NX_VISUALIZE_SOFTBODY_SLEEP, - physx_visualize_softbody_attachment = NX_VISUALIZE_SOFTBODY_ATTACHMENT, - physx_visualize_cloth_collisions = NX_VISUALIZE_CLOTH_COLLISIONS, - physx_continuous_cd = NX_CONTINUOUS_CD, - physx_visualize_collision_aabbs = NX_VISUALIZE_COLLISION_AABBS, - physx_visualize_joint_world_axes = NX_VISUALIZE_JOINT_WORLD_AXES, - physx_visualize_fluid_drains = NX_VISUALIZE_FLUID_DRAINS, - physx_default_sleep_energy = NX_DEFAULT_SLEEP_ENERGY, - physx_visualize_cloth_mesh = NX_VISUALIZE_CLOTH_MESH, - physx_penalty_force = NX_PENALTY_FORCE, - physx_visualize_contact_normal = NX_VISUALIZE_CONTACT_NORMAL, - physx_implicit_sweep_cache_size = NX_IMPLICIT_SWEEP_CACHE_SIZE, - physx_visualize_softbody_tearing = NX_VISUALIZE_SOFTBODY_TEARING, - physx_visualize_collision_ccd = NX_VISUALIZE_COLLISION_CCD, - physx_bounce_threshold = NX_BOUNCE_THRESHOLD, - physx_visualize_collision_spheres = NX_VISUALIZE_COLLISION_SPHERES, - physx_visualize_collision_axes = NX_VISUALIZE_COLLISION_AXES, - physx_visualize_fluid_bounds = NX_VISUALIZE_FLUID_BOUNDS, - physx_visualize_joint_limits = NX_VISUALIZE_JOINT_LIMITS, - physx_visualize_force_fields = NX_VISUALIZE_FORCE_FIELDS, - physx_visualize_cloth_validbounds = NX_VISUALIZE_CLOTH_VALIDBOUNDS, - physx_default_sleep_lin_vel_squared = NX_DEFAULT_SLEEP_LIN_VEL_SQUARED, - physx_visualize_cloth_selfcollisions = NX_VISUALIZE_CLOTH_SELFCOLLISIONS, - physx_visualize_softbody_collisions = NX_VISUALIZE_SOFTBODY_COLLISIONS, - physx_constant_fluid_max_particles_per_step = NX_CONSTANT_FLUID_MAX_PARTICLES_PER_STEP, - physx_visualize_contact_force = NX_VISUALIZE_CONTACT_FORCE, - physx_sta_frict_scaling = NX_STA_FRICT_SCALING, - physx_default_sleep_ang_vel_squared = NX_DEFAULT_SLEEP_ANG_VEL_SQUARED, - physx_ccd_epsilon = NX_CCD_EPSILON, - physx_asynchronous_mesh_creation = NX_ASYNCHRONOUS_MESH_CREATION, - physx_visualize_world_axes = NX_VISUALIZE_WORLD_AXES, - physx_visualize_active_vertices = NX_VISUALIZE_ACTIVE_VERTICES, - physx_select_hw_algo = NX_SELECT_HW_ALGO, - physx_visualize_cloth_sleep_vertex = NX_VISUALIZE_CLOTH_SLEEP_VERTEX, - physx_visualize_cloth_attachment = NX_VISUALIZE_CLOTH_ATTACHMENT, - physx_visualize_fluid_stc_collision = NX_VISUALIZE_FLUID_STC_COLLISION, - physx_visualization_scale = NX_VISUALIZATION_SCALE, - physx_visualize_cloth_tearable_vertices = NX_VISUALIZE_CLOTH_TEARABLE_VERTICES, - physx_visualize_cloth_sleep = NX_VISUALIZE_CLOTH_SLEEP, - physx_visualize_collision_fnormals = NX_VISUALIZE_COLLISION_FNORMALS, - physx_visualize_body_mass_axes = NX_VISUALIZE_BODY_MASS_AXES, - physx_visualize_body_ang_velocity = NX_VISUALIZE_BODY_ANG_VELOCITY, - physx_visualize_fluid_packet_data = NX_VISUALIZE_FLUID_PACKET_DATA, - physx_visualize_fluid_kernel_radius = NX_VISUALIZE_FLUID_KERNEL_RADIUS, - physx_bbox_noise_level = NX_BBOX_NOISE_LEVEL, - physx_skin_width = NX_SKIN_WIDTH, - physx_visualize_body_lin_velocity = NX_VISUALIZE_BODY_LIN_VELOCITY, - physx_visualize_fluid_dyn_collision = NX_VISUALIZE_FLUID_DYN_COLLISION, - physx_visualize_actor_axes = NX_VISUALIZE_ACTOR_AXES, - physx_visualize_collision_free = NX_VISUALIZE_COLLISION_FREE, - physx_visualize_cloth_tearing = NX_VISUALIZE_CLOTH_TEARING, - physx_coll_veto_jointed = NX_COLL_VETO_JOINTED, - physx_visualize_softbody_tearable_vertices = NX_VISUALIZE_SOFTBODY_TEARABLE_VERTICES, - physx_visualize_collision_shapes = NX_VISUALIZE_COLLISION_SHAPES, - physx_trigger_trigger_callback = NX_TRIGGER_TRIGGER_CALLBACK, - physx_visualize_fluid_packets = NX_VISUALIZE_FLUID_PACKETS, - physx_visualize_contact_point = NX_VISUALIZE_CONTACT_POINT, - physx_max_angular_velocity = NX_MAX_ANGULAR_VELOCITY, - physx_dyn_frict_scaling = NX_DYN_FRICT_SCALING, - physx_visualize_softbody_validbounds = NX_VISUALIZE_SOFTBODY_VALIDBOUNDS, - physx_visualize_softbody_sleep_vertex = NX_VISUALIZE_SOFTBODY_SLEEP_VERTEX, - physx_visualize_softbody_workpackets = NX_VISUALIZE_SOFTBODY_WORKPACKETS, - physx_adaptive_force = NX_ADAPTIVE_FORCE, - physx_solver_convergence_threshold = NX_SOLVER_CONVERGENCE_THRESHOLD, - physx_visualize_fluid_position = NX_VISUALIZE_FLUID_POSITION, - physx_visualize_softbody_mesh = NX_VISUALIZE_SOFTBODY_MESH, - physx_visualize_joint_local_axes = NX_VISUALIZE_JOINT_LOCAL_AXES, - physx_visualize_body_joint_groups = NX_VISUALIZE_BODY_JOINT_GROUPS, - physx_visualize_collision_sap = NX_VISUALIZE_COLLISION_SAP, - physx_visualize_collision_static = NX_VISUALIZE_COLLISION_STATIC, - physx_visualize_fluid_emitters = NX_VISUALIZE_FLUID_EMITTERS, - physx_constant_fluid_max_packets = NX_CONSTANT_FLUID_MAX_PACKETS, - physx_visualize_collision_vnormals = NX_VISUALIZE_COLLISION_VNORMALS, - physx_params_force_dword = NX_PARAMS_FORCE_DWORD, - physx_visualize_collision_skeletons = NX_VISUALIZE_COLLISION_SKELETONS, - physx_visualize_collision_compounds = NX_VISUALIZE_COLLISION_COMPOUNDS, -}; - -enum PhysxParticleDataFlag { - physx_fp_delete = NX_FP_DELETE, -}; - -enum PhysxParticleFlag { - physx_fp_separated = NX_FP_SEPARATED, - physx_fp_motion_limit_reached = NX_FP_MOTION_LIMIT_REACHED, - physx_fp_collision_with_dynamic = NX_FP_COLLISION_WITH_DYNAMIC, - physx_fp_collision_with_static = NX_FP_COLLISION_WITH_STATIC, -}; - -enum PhysxProfileZoneName { - physx_pz_client_frame = NX_PZ_CLIENT_FRAME, - physx_pz_cpu_simulate = NX_PZ_CPU_SIMULATE, - physx_pz_ppu0_simulate = NX_PZ_PPU0_SIMULATE, - physx_pz_ppu1_simulate = NX_PZ_PPU1_SIMULATE, - physx_pz_ppu2_simulate = NX_PZ_PPU2_SIMULATE, - physx_pz_ppu3_simulate = NX_PZ_PPU3_SIMULATE, - physx_pz_total_simulation = NX_PZ_TOTAL_SIMULATION, -}; - -enum PhysxPruningStructure { - physx_pruning_none = NX_PRUNING_NONE, - physx_pruning_octree = NX_PRUNING_OCTREE, - physx_pruning_quadtree = NX_PRUNING_QUADTREE, - physx_pruning_dynamic_aabb_tree = NX_PRUNING_DYNAMIC_AABB_TREE, - physx_pruning_static_aabb_tree = NX_PRUNING_STATIC_AABB_TREE, -}; - -enum PhysxPulleyJointFlag { - physx_pjf_is_rigid = NX_PJF_IS_RIGID, - physx_pjf_motor_enabled = NX_PJF_MOTOR_ENABLED, -}; - -enum PhysxQueryFlags { - physx_query_world_space = NX_QUERY_WORLD_SPACE, - physx_query_first_contact = NX_QUERY_FIRST_CONTACT, -}; - -enum PhysxQueryReportResult { - physx_sqr_continue = NX_SQR_CONTINUE, - physx_sqr_abort_query = NX_SQR_ABORT_QUERY, - physx_sqr_abort_all_queries = NX_SQR_ABORT_ALL_QUERIES, - physx_sqr_force_dword = NX_SQR_FORCE_DWORD, -}; - -enum PhysxRaycastBit { - physx_raycast_impact = NX_RAYCAST_IMPACT, - physx_raycast_distance = NX_RAYCAST_DISTANCE, - physx_raycast_face_index = NX_RAYCAST_FACE_INDEX, - physx_raycast_shape = NX_RAYCAST_SHAPE, - physx_raycast_normal = NX_RAYCAST_NORMAL, - physx_raycast_uv = NX_RAYCAST_UV, - physx_raycast_material = NX_RAYCAST_MATERIAL, - physx_raycast_face_normal = NX_RAYCAST_FACE_NORMAL, -}; - -enum PhysxRemoteDebuggerObjectType { - physx_dbg_objecttype_contact = NX_DBG_OBJECTTYPE_CONTACT, - physx_dbg_objecttype_actor = NX_DBG_OBJECTTYPE_ACTOR, - physx_dbg_objecttype_boundingbox = NX_DBG_OBJECTTYPE_BOUNDINGBOX, - physx_dbg_objecttype_cloth = NX_DBG_OBJECTTYPE_CLOTH, - physx_dbg_objecttype_capsule = NX_DBG_OBJECTTYPE_CAPSULE, - physx_dbg_objecttype_cylinder = NX_DBG_OBJECTTYPE_CYLINDER, - physx_dbg_objecttype_plane = NX_DBG_OBJECTTYPE_PLANE, - physx_dbg_objecttype_mesh = NX_DBG_OBJECTTYPE_MESH, - physx_dbg_objecttype_box = NX_DBG_OBJECTTYPE_BOX, - physx_dbg_objecttype_fluid = NX_DBG_OBJECTTYPE_FLUID, - physx_dbg_objecttype_convex = NX_DBG_OBJECTTYPE_CONVEX, - physx_dbg_objecttype_generic = NX_DBG_OBJECTTYPE_GENERIC, - physx_dbg_objecttype_sphere = NX_DBG_OBJECTTYPE_SPHERE, - physx_dbg_objecttype_joint = NX_DBG_OBJECTTYPE_JOINT, - physx_dbg_objecttype_softbody = NX_DBG_OBJECTTYPE_SOFTBODY, - physx_dbg_objecttype_vector = NX_DBG_OBJECTTYPE_VECTOR, - physx_dbg_objecttype_wheel = NX_DBG_OBJECTTYPE_WHEEL, - physx_dbg_objecttype_camera = NX_DBG_OBJECTTYPE_CAMERA, -}; - -enum PhysxRevoluteJointFlag { - physx_rjf_motor_enabled = NX_RJF_MOTOR_ENABLED, - physx_rjf_limit_enabled = NX_RJF_LIMIT_ENABLED, - physx_rjf_spring_enabled = NX_RJF_SPRING_ENABLED, -}; - -enum PhysxSDKCreateError { - physxce_wrong_version = NXCE_WRONG_VERSION, - physxce_bundle_error = NXCE_BUNDLE_ERROR, - physxce_physx_not_found = NXCE_PHYSX_NOT_FOUND, - physxce_reset_error = NXCE_RESET_ERROR, - physxce_in_use_error = NXCE_IN_USE_ERROR, - physxce_connection_error = NXCE_CONNECTION_ERROR, - physxce_no_error = NXCE_NO_ERROR, - physxce_descriptor_invalid = NXCE_DESCRIPTOR_INVALID, -}; - -enum PhysxSDKCreationFlag { - physx_sdkf_no_hardware = NX_SDKF_NO_HARDWARE, -}; - -enum PhysxSceneFlags { - physx_sf_force_cone_friction = NX_SF_FORCE_CONE_FRICTION, - physx_sf_disable_collisions = NX_SF_DISABLE_COLLISIONS, - physx_sf_restricted_scene = NX_SF_RESTRICTED_SCENE, - physx_sf_fluid_performance_hint = NX_SF_FLUID_PERFORMANCE_HINT, - physx_sf_simulate_separate_thread = NX_SF_SIMULATE_SEPARATE_THREAD, - physx_sf_sequential_primary = NX_SF_SEQUENTIAL_PRIMARY, - physx_sf_disable_scene_mutex = NX_SF_DISABLE_SCENE_MUTEX, - physx_sf_enable_multithread = NX_SF_ENABLE_MULTITHREAD, - physx_sf_disable_sse = NX_SF_DISABLE_SSE, - physx_sf_enable_activetransforms = NX_SF_ENABLE_ACTIVETRANSFORMS, -}; - -enum PhysxSceneQueryExecuteMode { - physx_sqe_synchronous = NX_SQE_SYNCHRONOUS, - physx_sqe_asynchronous = NX_SQE_ASYNCHRONOUS, - physx_sqe_force_dword = NX_SQE_FORCE_DWORD, -}; - -enum PhysxSepAxis { - physx_sep_axis_overlap = NX_SEP_AXIS_OVERLAP, - physx_sep_axis_a0 = NX_SEP_AXIS_A0, - physx_sep_axis_a1 = NX_SEP_AXIS_A1, - physx_sep_axis_a2 = NX_SEP_AXIS_A2, - physx_sep_axis_b0 = NX_SEP_AXIS_B0, - physx_sep_axis_b1 = NX_SEP_AXIS_B1, - physx_sep_axis_b2 = NX_SEP_AXIS_B2, - physx_sep_axis_a0_cross_b0 = NX_SEP_AXIS_A0_CROSS_B0, - physx_sep_axis_a0_cross_b1 = NX_SEP_AXIS_A0_CROSS_B1, - physx_sep_axis_a0_cross_b2 = NX_SEP_AXIS_A0_CROSS_B2, - physx_sep_axis_a1_cross_b0 = NX_SEP_AXIS_A1_CROSS_B0, - physx_sep_axis_a1_cross_b1 = NX_SEP_AXIS_A1_CROSS_B1, - physx_sep_axis_a1_cross_b2 = NX_SEP_AXIS_A1_CROSS_B2, - physx_sep_axis_a2_cross_b0 = NX_SEP_AXIS_A2_CROSS_B0, - physx_sep_axis_a2_cross_b1 = NX_SEP_AXIS_A2_CROSS_B1, - physx_sep_axis_a2_cross_b2 = NX_SEP_AXIS_A2_CROSS_B2, - physx_sep_axis_force_dword = NX_SEP_AXIS_FORCE_DWORD, -}; - -enum PhysxShapeFlag { - physx_sf_disable_response = NX_SF_DISABLE_RESPONSE, - physx_sf_softbody_drain = NX_SF_SOFTBODY_DRAIN, - physx_sf_cloth_drain = NX_SF_CLOTH_DRAIN, - physx_trigger_on_enter = NX_TRIGGER_ON_ENTER, - physx_sf_point_contact_force = NX_SF_POINT_CONTACT_FORCE, - physx_sf_softbody_disable_collision = NX_SF_SOFTBODY_DISABLE_COLLISION, - physx_sf_feature_indices = NX_SF_FEATURE_INDICES, - physx_sf_cloth_twoway = NX_SF_CLOTH_TWOWAY, - physx_sf_visualization = NX_SF_VISUALIZATION, - physx_trigger_on_stay = NX_TRIGGER_ON_STAY, - physx_sf_cloth_disable_collision = NX_SF_CLOTH_DISABLE_COLLISION, - physx_sf_fluid_twoway = NX_SF_FLUID_TWOWAY, - physx_trigger_on_leave = NX_TRIGGER_ON_LEAVE, - physx_sf_disable_scene_queries = NX_SF_DISABLE_SCENE_QUERIES, - physx_sf_disable_raycasting = NX_SF_DISABLE_RAYCASTING, - physx_sf_dynamic_dynamic_ccd = NX_SF_DYNAMIC_DYNAMIC_CCD, - physx_sf_disable_collision = NX_SF_DISABLE_COLLISION, - physx_sf_softbody_twoway = NX_SF_SOFTBODY_TWOWAY, - physx_sf_fluid_disable_collision = NX_SF_FLUID_DISABLE_COLLISION, - physx_sf_fluid_drain = NX_SF_FLUID_DRAIN, -}; - -enum PhysxShapePairStreamFlags { - physx_sf_has_mats_per_point = NX_SF_HAS_MATS_PER_POINT, - physx_sf_has_features_per_point = NX_SF_HAS_FEATURES_PER_POINT, -}; - -enum PhysxShapeType { - physx_shape_plane = NX_SHAPE_PLANE, - physx_shape_sphere = NX_SHAPE_SPHERE, - physx_shape_box = NX_SHAPE_BOX, - physx_shape_capsule = NX_SHAPE_CAPSULE, - physx_shape_wheel = NX_SHAPE_WHEEL, - physx_shape_convex = NX_SHAPE_CONVEX, - physx_shape_mesh = NX_SHAPE_MESH, - physx_shape_heightfield = NX_SHAPE_HEIGHTFIELD, - physx_shape_raw_mesh = NX_SHAPE_RAW_MESH, - physx_shape_compound = NX_SHAPE_COMPOUND, - physx_shape_count = NX_SHAPE_COUNT, - physx_shape_force_dword = NX_SHAPE_FORCE_DWORD, -}; - -enum PhysxShapesType { - physx_dynamic_shapes = NX_DYNAMIC_SHAPES, - physx_static_shapes = NX_STATIC_SHAPES, -}; - -enum PhysxSimulationStatus { - physx_rigid_body_finished = NX_RIGID_BODY_FINISHED, - physx_all_finished = NX_ALL_FINISHED, - physx_primary_finished = NX_PRIMARY_FINISHED, -}; - -enum PhysxSimulationType { - physx_simulation_hw = NX_SIMULATION_HW, - physx_sty_force_dword = NX_STY_FORCE_DWORD, - physx_simulation_sw = NX_SIMULATION_SW, -}; - -enum PhysxSoftBodyAttachmentFlag { - physx_softbody_attachment_tearable = NX_SOFTBODY_ATTACHMENT_TEARABLE, - physx_softbody_attachment_twoway = NX_SOFTBODY_ATTACHMENT_TWOWAY, -}; - -enum PhysxSoftBodyFlag { - physx_sbf_visualization = NX_SBF_VISUALIZATION, - physx_sbf_fluid_collision = NX_SBF_FLUID_COLLISION, - physx_sbf_static = NX_SBF_STATIC, - physx_sbf_collision_twoway = NX_SBF_COLLISION_TWOWAY, - physx_sbf_disable_collision = NX_SBF_DISABLE_COLLISION, - physx_sbf_validbounds = NX_SBF_VALIDBOUNDS, - physx_sbf_tearable = NX_SBF_TEARABLE, - physx_sbf_volume_conservation = NX_SBF_VOLUME_CONSERVATION, - physx_sbf_selfcollision = NX_SBF_SELFCOLLISION, - physx_sbf_gravity = NX_SBF_GRAVITY, - physx_sbf_comdamping = NX_SBF_COMDAMPING, - physx_sbf_hardware = NX_SBF_HARDWARE, - physx_sbf_damping = NX_SBF_DAMPING, -}; - -enum PhysxSoftBodyMeshFlags { - physx_softbody_mesh_16_bit_indices = NX_SOFTBODY_MESH_16_BIT_INDICES, - physx_softbody_mesh_tearable = NX_SOFTBODY_MESH_TEARABLE, -}; - -enum PhysxSoftBodyVertexFlags { - physx_softbody_vertex_tearable = NX_SOFTBODY_VERTEX_TEARABLE, -}; - -enum PhysxSphericalJointFlag { - physx_sjf_swing_spring_enabled = NX_SJF_SWING_SPRING_ENABLED, - physx_sjf_joint_spring_enabled = NX_SJF_JOINT_SPRING_ENABLED, - physx_sjf_twist_limit_enabled = NX_SJF_TWIST_LIMIT_ENABLED, - physx_sjf_twist_spring_enabled = NX_SJF_TWIST_SPRING_ENABLED, - physx_sjf_swing_limit_enabled = NX_SJF_SWING_LIMIT_ENABLED, -}; - -enum PhysxStandardFences { - physx_fence_run_finished = NX_FENCE_RUN_FINISHED, - physx_num_standard_fences = NX_NUM_STANDARD_FENCES, -}; - -enum PhysxSweepFlags { - physx_sf_async = NX_SF_ASYNC, - physx_sf_debug_sm = NX_SF_DEBUG_SM, - physx_sf_dynamics = NX_SF_DYNAMICS, - physx_sf_statics = NX_SF_STATICS, - physx_sf_debug_et = NX_SF_DEBUG_ET, - physx_sf_all_hits = NX_SF_ALL_HITS, -}; - -enum PhysxThreadPollResult { - physx_thread_shutdown = NX_THREAD_SHUTDOWN, - physx_thread_force_dword = NX_THREAD_FORCE_DWORD, - physx_thread_nowork = NX_THREAD_NOWORK, - physx_thread_simulation_end = NX_THREAD_SIMULATION_END, - physx_thread_morework = NX_THREAD_MOREWORK, -}; - -enum PhysxThreadPriority { - physx_tp_above_normal = NX_TP_ABOVE_NORMAL, - physx_tp_normal = NX_TP_NORMAL, - physx_tp_high = NX_TP_HIGH, - physx_tp_low = NX_TP_LOW, - physx_tp_force_dword = NX_TP_FORCE_DWORD, - physx_tp_below_normal = NX_TP_BELOW_NORMAL, -}; - -enum PhysxThreadWait { - physx_wait_force_dword = NX_WAIT_FORCE_DWORD, - physx_wait_shutdown = NX_WAIT_SHUTDOWN, - physx_wait_simulation_end = NX_WAIT_SIMULATION_END, - physx_wait_none = NX_WAIT_NONE, -}; - -enum PhysxTimeStepMethod { - physx_timestep_fixed = NX_TIMESTEP_FIXED, - physx_timestep_variable = NX_TIMESTEP_VARIABLE, - physx_timestep_inherit = NX_TIMESTEP_INHERIT, - physx_num_timestep_methods = NX_NUM_TIMESTEP_METHODS, - physx_tsm_force_dword = NX_TSM_FORCE_DWORD, -}; - -enum PhysxTriangleFlags { - physx_boundary_edge20 = NXTF_BOUNDARY_EDGE20, - physx_double_sided = NXTF_DOUBLE_SIDED, - physx_active_edge12 = NXTF_ACTIVE_EDGE12, - physx_active_edge01 = NXTF_ACTIVE_EDGE01, - physx_boundary_edge01 = NXTF_BOUNDARY_EDGE01, - physx_boundary_edge12 = NXTF_BOUNDARY_EDGE12, - physx_active_edge20 = NXTF_ACTIVE_EDGE20, -}; - - - -#endif // HAVE_PHYSX - -#endif // PHYSX_ENUMERATIONS_H diff --git a/panda/src/physx/physx_enumerations_for_interrogate.h b/panda/src/physx/physx_enumerations_for_interrogate.h deleted file mode 100644 index bb8debadba..0000000000 --- a/panda/src/physx/physx_enumerations_for_interrogate.h +++ /dev/null @@ -1,826 +0,0 @@ -// Filename: physx_enumerations.h -// Created by: pratt (Apr 20, 2006) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifndef PHYSX_ENUMERATIONS_H -#define PHYSX_ENUMERATIONS_H - -#ifdef HAVE_PHYSX - -#include "NoMinMax.h" -#include "NxPhysics.h" - -enum PhysxActorDescType { - physx_adt_shapeless, - physx_adt_default, - physx_adt_allocator, - physx_adt_list, - physx_adt_pointer, -}; - -enum PhysxActorFlag { - physx_af_fluid_disable_collision = (1<<3), - physx_af_contact_modification = (1<<4), - physx_af_disable_collision = (1<<0), - physx_af_disable_response = (1<<1), - physx_af_lock_com = (1<<2), - physx_af_user_actor_pair_filtering = (1<<6), - physx_af_force_cone_friction = (1<<5), -}; - -enum PhysxAssertResponse { - physx_ar_continue, - physx_ar_ignore, - physx_ar_breakpoint, -}; - -enum PhysxAxisType { - physx_axis_plus_x, - physx_axis_minus_x, - physx_axis_plus_y, - physx_axis_minus_y, - physx_axis_plus_z, - physx_axis_minus_z, - physx_axis_arbitrary, -}; - -enum PhysxBSphereMethod { - physx_bs_none, - physx_bs_gems, - physx_bs_miniball, - physx_bs_force_dword = 0x7fffffff, -}; - -enum PhysxBodyFlag { - physx_bf_frozen_rot_z = (1<<6), - physx_bf_frozen_rot_y = (1<<5), - physx_bf_frozen_rot_x = (1<<4), - physx_bf_kinematic = (1<<7), - physx_bf_pose_sleep_test = (1<<9), - physx_bf_disable_gravity = (1<<0), - physx_bf_frozen_pos_z = (1<<3), - physx_bf_frozen_pos_x = (1<<1), - physx_bf_frozen_pos_y = (1<<2), - physx_bf_visualization = (1<<8), - physx_bf_filter_sleep_vel = (1<<10), - physx_bf_energy_sleep_test = (1<<11), -}; - -enum PhysxCapsuleShapeFlag { - physx_swept_shape = (1<<0), -}; - -enum PhysxClothAttachmentFlag { - physx_cloth_attachment_tearable = (1<<1), - physx_cloth_attachment_twoway = (1<<0), -}; - -enum PhysxClothFlag { - physx_clf_disable_collision = (1<<2), - physx_clf_bending_ortho = (1<<7), - physx_clf_bending = (1<<6), - physx_clf_pressure = (1<<0), - physx_clf_damping = (1<<8), - physx_clf_fluid_collision = (1<<16), - physx_clf_triangle_collision = (1<<11), - physx_clf_visualization = (1<<4), - physx_clf_collision_twoway = (1<<9), - physx_clf_hardware = (1<<13), - physx_clf_gravity = (1<<5), - physx_clf_selfcollision = (1<<3), - physx_clf_tearable = (1<<12), - physx_clf_validbounds = (1<<15), - physx_clf_static = (1<<1), - physx_clf_comdamping = (1<<14), -}; - -enum PhysxClothMeshFlags { - physx_cloth_mesh_tearable = (1<<8), -}; - -enum PhysxClothVertexAttachmentStatus { - physx_cloth_vertex_attachment_none, - physx_cloth_vertex_attachment_global, - physx_cloth_vertex_attachment_shape, -}; - -enum PhysxClothVertexFlags { - physx_cloth_vertex_attached = (1<<0), - physx_cloth_vertex_tearable = (1<<7), -}; - -enum PhysxCombineMode { - physx_cm_multiply = 2, - physx_cm_average = 0, - physx_cm_max = 3, - physx_cm_pad_32 = 0xffffffff, - physx_cm_n_values = 4, - physx_cm_min = 1, -}; - -enum PhysxCompartmentFlag { - physx_cf_sleep_notification = (1<<0), - physx_cf_continuous_cd = (1<<1), - physx_cf_inherit_settings = (1<<3), - physx_cf_restricted_scene = (1<<2), -}; - -enum PhysxCompartmentType { - physx_sct_cloth = 2, - physx_sct_rigidbody = 0, - physx_sct_softbody = 2, - physx_sct_fluid = 1, -}; - -enum PhysxContactPairFlag { - physx_ignore_pair = (1<<0), - physx_notify_on_touch = (1<<3), - physx_notify_on_end_touch = (1<<2), - physx_notify_forces = (1<<7), - physx_notify_on_slide = (1<<6), - physx_notify_on_impact = (1<<4), - physx_notify_contact_modification = (1<<16), - physx_notify_on_roll = (1<<5), - physx_notify_on_start_touch = (1<<1), -}; - -enum PhysxConvexFlags { - physx_cf_use_uncompressed_normals = (1<<5), - physx_cf_flipnormals = (1<<0), - physx_cf_use_legacy_cooker = (1<<4), - physx_cf_inflate_convex = (1<<3), - physx_cf_16_bit_indices = (1<<1), - physx_cf_compute_convex = (1<<2), -}; - -enum PhysxCookingValue { - physx_cooking_convex_version_pc, - physx_cooking_mesh_version_pc, - physx_cooking_convex_version_xenon, - physx_cooking_mesh_version_xenon, - physx_cooking_convex_version_playstation3, - physx_cooking_mesh_version_playstation3, -}; - -enum PhysxD6JointDriveType { - physx_d6joint_drive_velocity = 1<<1, - physx_d6joint_drive_position = 1<<0, -}; - -enum PhysxD6JointFlag { - physx_d6joint_slerp_drive = 1<<0, - physx_d6joint_gear_enabled = 1<<1, -}; - -enum PhysxD6JointMotion { - physx_d6joint_motion_locked, - physx_d6joint_motion_limited, - physx_d6joint_motion_free, -}; - -enum PhysxDebugColor { - physx_argb_white = 0xffffffff, - physx_argb_green = 0xff00ff00, - physx_argb_red = 0xffff0000, - physx_argb_yellow = 0xffffff00, - physx_argb_magenta = 0xffff00ff, - physx_argb_blue = 0xff0000ff, - physx_argb_cyan = 0xff00ffff, - physx_argb_black = 0xff000000, -}; - -enum PhysxDeviceCode { - physx_dc_ppu_0 = 0, - physx_dc_ppu_1 = 1, - physx_dc_ppu_2 = 2, - physx_dc_ppu_3 = 3, - physx_dc_ppu_4 = 4, - physx_dc_ppu_5 = 5, - physx_dc_ppu_6 = 6, - physx_dc_ppu_7 = 7, - physx_dc_ppu_8 = 8, - physx_dc_cpu = 0xffff0000, - physx_dc_ppu_auto_assign = 0xffff0001, -}; - -enum PhysxDistanceJointFlag { - physx_djf_max_distance_enabled = 1 << 0, - physx_djf_min_distance_enabled = 1 << 1, - physx_djf_spring_enabled = 1 << 2, -}; - -enum PhysxEffectorType { - physx_effector_spring_and_damper, -}; - -enum PhysxEmitterShape { - physx_fe_ellipse = (1<<1), - physx_fe_rectangular = (1<<0), -}; - -enum PhysxEmitterType { - physx_fe_constant_flow_rate = (1<<1), - physx_fe_constant_pressure = (1<<0), -}; - -enum PhysxErrorCode { - physxe_invalid_parameter = 1, - physxe_db_warning = 206, - physxe_out_of_memory = 3, - physxe_internal_error = 4, - physxe_invalid_operation = 2, - physxe_db_info = 205, - physxe_assertion = 107, - physxe_no_error = 0, - physxe_db_print = 208, -}; - -enum PhysxFilterOp { - physx_filterop_and, - physx_filterop_or, - physx_filterop_xor, - physx_filterop_nand, - physx_filterop_nor, - physx_filterop_nxor, - physx_filterop_swap_and, -}; - -enum PhysxFluidCollisionMethod { - physx_f_static = (1<<0), - physx_f_dynamic = (1<<1), -}; - -enum PhysxFluidDescType { - physx_fdt_default, - physx_fdt_allocator, -}; - -enum PhysxFluidEmitterEventType { - physx_feet_emitter_empty, -}; - -enum PhysxFluidEmitterFlag { - physx_fef_visualization = (1<<0), - physx_fef_add_body_velocity = (1<<3), - physx_fef_enabled = (1<<4), - physx_fef_force_on_body = (1<<2), -}; - -enum PhysxFluidEventType { - physx_fet_no_particles_left, -}; - -enum PhysxFluidFlag { - physx_ff_visualization = (1<<0), - physx_ff_disable_gravity = (1<<1), - physx_ff_hardware = (1<<4), - physx_ff_priority_mode = (1<<5), - physx_ff_collision_twoway = (1<<2), - physx_ff_enabled = (1<<3), -}; - -enum PhysxFluidSimulationMethod { - physx_f_sph = (1<<0), - physx_f_mixed_mode = (1<<2), - physx_f_no_particle_interaction = (1<<1), -}; - -enum PhysxForceFieldCoordinates { - physx_ffc_cartesian, - physx_ffc_spherical, - physx_ffc_cylindrical, - physx_ffc_toroidal, -}; - -enum PhysxForceFieldFlags { - physx_fff_ignore_rigidbody_mass = (1<<3), - physx_fff_ignore_fluid_mass = (1<<0), - physx_fff_legacy_force = (1<<4), - physx_fff_ignore_cloth_mass = (1<<1), - physx_fff_ignore_softbody_mass = (1<<2), -}; - -enum PhysxForceFieldShapeFlags { - physx_ffs_exclude = (1<<0), -}; - -enum PhysxForceFieldType { - physx_ff_type_force, - physx_ff_type_acceleration, -}; - -enum PhysxForceMode { - physx_force, - physx_impulse, - physx_velocity_change, - physx_smooth_impulse, - physx_smooth_velocity_change, - physx_acceleration, -}; - -enum PhysxHWVersion { - physx_hw_version_none = 0, - physx_hw_version_athena_1_0 = 1, -}; - -enum PhysxHeightFieldAxis { - physx_not_heightfield = 0xff, - physx_z = 2, - physx_y = 1, - physx_x = 0, -}; - -enum PhysxHeightFieldFlags { - physx_hf_no_boundary_edges = (1 << 0), -}; - -enum PhysxHeightFieldFormat { - physx_hf_s16_tm = (1 << 0), -}; - -enum PhysxHeightFieldTessFlag { - physx_hf_0th_vertex_shared = (1 << 0), -}; - -enum PhysxInternalArray { - physx_array_triangles, - physx_array_vertices, - physx_array_normals, - physx_array_hull_vertices, - physx_array_hull_polygons, -}; - -enum PhysxInternalFormat { - physx_format_nodata, - physx_format_float, - physx_format_byte, - physx_format_short, - physx_format_int, -}; - -enum PhysxJointFlag { - physx_jf_collision_enabled = (1<<0), - physx_jf_visualization = (1<<1), -}; - -enum PhysxJointProjectionMode { - physx_jpm_linear_mindist = 2, - physx_jpm_point_mindist = 1, - physx_jpm_none = 0, -}; - -enum PhysxJointState { - physx_js_unbound, - physx_js_simulating, - physx_js_broken, -}; - -enum PhysxJointType { - physx_joint_prismatic, - physx_joint_revolute, - physx_joint_cylindrical, - physx_joint_spherical, - physx_joint_point_on_line, - physx_joint_point_in_plane, - physx_joint_distance, - physx_joint_pulley, - physx_joint_fixed, - physx_joint_d6, - physx_joint_count, - physx_joint_force_dword = 0x7fffffff, -}; - -enum PhysxMaterialFlag { - physx_mf_disable_friction = 1 << 4, - physx_mf_disable_strong_friction = 1 << 5, - physx_mf_anisotropic = 1 << 0, -}; - -enum PhysxMatrixType { - physx_zero_matrix, - physx_identity_matrix, -}; - -enum PhysxMeshDataDirtyBufferFlags { - physx_mdf_vertices_pos_dirty = 1 << 0, - physx_mdf_parent_indices_dirty = 1 << 3, - physx_mdf_vertices_normal_dirty = 1 << 1, - physx_mdf_indices_dirty = 1 << 2, -}; - -enum PhysxMeshDataFlags { - physx_mdf_16_bit_indices = 1 << 0, -}; - -enum PhysxMeshFlags { - physx_mf_16_bit_indices = (1<<1), - physx_mf_flipnormals = (1<<0), - physx_mf_hardware_mesh = (1<<2), -}; - -enum PhysxMeshPagingMode { - physx_mesh_paging_manual, - physx_mesh_paging_fallback, - physx_mesh_paging_auto, -}; - -enum PhysxMeshShapeFlag { - physx_mesh_double_sided = (1<<1), - physx_mesh_smooth_sphere_collisions = (1<<0), -}; - -enum PhysxParameter { - physx_visualize_collision_edges = 44, - physx_params_num_values = 97, - physx_visualize_collision_dynamic = 48, - physx_visualize_contact_error = 35, - physx_visualize_fluid_motion_limit = 58, - physx_visualize_cloth_workpackets = 66, - physx_visualize_fluid_velocity = 54, - physx_visualize_fluid_mesh_packets = 61, - physx_visualize_body_axes = 11, - physx_visualize_softbody_sleep = 86, - physx_visualize_softbody_attachment = 89, - physx_visualize_cloth_collisions = 64, - physx_continuous_cd = 8, - physx_visualize_collision_aabbs = 38, - physx_visualize_joint_world_axes = 28, - physx_visualize_fluid_drains = 62, - physx_default_sleep_energy = 77, - physx_visualize_cloth_mesh = 63, - physx_penalty_force = 0, - physx_visualize_contact_normal = 34, - physx_implicit_sweep_cache_size = 76, - physx_visualize_softbody_tearing = 88, - physx_visualize_collision_ccd = 50, - physx_bounce_threshold = 4, - physx_visualize_collision_spheres = 45, - physx_visualize_collision_axes = 40, - physx_visualize_fluid_bounds = 56, - physx_visualize_joint_limits = 29, - physx_visualize_force_fields = 91, - physx_visualize_cloth_validbounds = 92, - physx_default_sleep_lin_vel_squared = 2, - physx_visualize_cloth_selfcollisions = 65, - physx_visualize_softbody_collisions = 84, - physx_constant_fluid_max_particles_per_step = 79, - physx_visualize_contact_force = 36, - physx_sta_frict_scaling = 6, - physx_default_sleep_ang_vel_squared = 3, - physx_ccd_epsilon = 73, - physx_asynchronous_mesh_creation = 96, - physx_visualize_world_axes = 10, - physx_visualize_active_vertices = 72, - physx_select_hw_algo = 71, - physx_visualize_cloth_sleep_vertex = 94, - physx_visualize_cloth_attachment = 82, - physx_visualize_fluid_stc_collision = 60, - physx_visualization_scale = 9, - physx_visualize_cloth_tearable_vertices = 80, - physx_visualize_cloth_sleep = 67, - physx_visualize_collision_fnormals = 43, - physx_visualize_body_mass_axes = 12, - physx_visualize_body_ang_velocity = 14, - physx_visualize_fluid_packet_data = 90, - physx_visualize_fluid_kernel_radius = 55, - physx_bbox_noise_level = 75, - physx_skin_width = 1, - physx_visualize_body_lin_velocity = 13, - physx_visualize_fluid_dyn_collision = 59, - physx_visualize_actor_axes = 37, - physx_visualize_collision_free = 49, - physx_visualize_cloth_tearing = 81, - physx_coll_veto_jointed = 69, - physx_visualize_softbody_tearable_vertices = 87, - physx_visualize_collision_shapes = 39, - physx_trigger_trigger_callback = 70, - physx_visualize_fluid_packets = 57, - physx_visualize_contact_point = 33, - physx_max_angular_velocity = 7, - physx_dyn_frict_scaling = 5, - physx_visualize_softbody_validbounds = 93, - physx_visualize_softbody_sleep_vertex = 95, - physx_visualize_softbody_workpackets = 85, - physx_adaptive_force = 68, - physx_solver_convergence_threshold = 74, - physx_visualize_fluid_position = 53, - physx_visualize_softbody_mesh = 83, - physx_visualize_joint_local_axes = 27, - physx_visualize_body_joint_groups = 22, - physx_visualize_collision_sap = 46, - physx_visualize_collision_static = 47, - physx_visualize_fluid_emitters = 52, - physx_constant_fluid_max_packets = 78, - physx_visualize_collision_vnormals = 42, - physx_params_force_dword = 0x7fffffff, - physx_visualize_collision_skeletons = 51, - physx_visualize_collision_compounds = 41, -}; - -enum PhysxParticleDataFlag { - physx_fp_delete = (1<<0), -}; - -enum PhysxParticleFlag { - physx_fp_separated = (1<<2), - physx_fp_motion_limit_reached = (1<<3), - physx_fp_collision_with_dynamic = (1<<1), - physx_fp_collision_with_static = (1<<0), -}; - -enum PhysxProfileZoneName { - physx_pz_client_frame, - physx_pz_cpu_simulate, - physx_pz_ppu0_simulate, - physx_pz_ppu1_simulate, - physx_pz_ppu2_simulate, - physx_pz_ppu3_simulate, - physx_pz_total_simulation = 0x10, -}; - -enum PhysxPruningStructure { - physx_pruning_none, - physx_pruning_octree, - physx_pruning_quadtree, - physx_pruning_dynamic_aabb_tree, - physx_pruning_static_aabb_tree, -}; - -enum PhysxPulleyJointFlag { - physx_pjf_is_rigid = 1 << 0, - physx_pjf_motor_enabled = 1 << 1, -}; - -enum PhysxQueryFlags { - physx_query_world_space = (1<<0), - physx_query_first_contact = (1<<1), -}; - -enum PhysxQueryReportResult { - physx_sqr_continue, - physx_sqr_abort_query, - physx_sqr_abort_all_queries, - physx_sqr_force_dword = 0x7fffffff, -}; - -enum PhysxRaycastBit { - physx_raycast_impact = (1<<1), - physx_raycast_distance = (1<<4), - physx_raycast_face_index = (1<<3), - physx_raycast_shape = (1<<0), - physx_raycast_normal = (1<<2), - physx_raycast_uv = (1<<5), - physx_raycast_material = (1<<7), - physx_raycast_face_normal = (1<<6), -}; - -enum PhysxRemoteDebuggerObjectType { - physx_dbg_objecttype_contact = 11, - physx_dbg_objecttype_actor = 1, - physx_dbg_objecttype_boundingbox = 12, - physx_dbg_objecttype_cloth = 15, - physx_dbg_objecttype_capsule = 5, - physx_dbg_objecttype_cylinder = 6, - physx_dbg_objecttype_plane = 2, - physx_dbg_objecttype_mesh = 8, - physx_dbg_objecttype_box = 3, - physx_dbg_objecttype_fluid = 17, - physx_dbg_objecttype_convex = 7, - physx_dbg_objecttype_generic = 0, - physx_dbg_objecttype_sphere = 4, - physx_dbg_objecttype_joint = 10, - physx_dbg_objecttype_softbody = 16, - physx_dbg_objecttype_vector = 13, - physx_dbg_objecttype_wheel = 9, - physx_dbg_objecttype_camera = 14, -}; - -enum PhysxRevoluteJointFlag { - physx_rjf_motor_enabled = 1 << 1, - physx_rjf_limit_enabled = 1 << 0, - physx_rjf_spring_enabled = 1 << 2, -}; - -enum PhysxSDKCreateError { - physxce_wrong_version = 2, - physxce_bundle_error = 7, - physxce_physx_not_found = 1, - physxce_reset_error = 5, - physxce_in_use_error = 6, - physxce_connection_error = 4, - physxce_no_error = 0, - physxce_descriptor_invalid = 3, -}; - -enum PhysxSDKCreationFlag { - physx_sdkf_no_hardware = (1<<0), -}; - -enum PhysxSceneFlags { - physx_sf_force_cone_friction = 0x80, - physx_sf_disable_collisions = 0x2, - physx_sf_restricted_scene = 0x20, - physx_sf_fluid_performance_hint = 0x80*4, - physx_sf_simulate_separate_thread = 0x4, - physx_sf_sequential_primary = 0x80*2, - physx_sf_disable_scene_mutex = 0x40, - physx_sf_enable_multithread = 0x8, - physx_sf_disable_sse = 0x1, - physx_sf_enable_activetransforms = 0x10, -}; - -enum PhysxSceneQueryExecuteMode { - physx_sqe_synchronous, - physx_sqe_asynchronous, - physx_sqe_force_dword = 0x7fffffff, -}; - -enum PhysxSepAxis { - physx_sep_axis_overlap, - physx_sep_axis_a0, - physx_sep_axis_a1, - physx_sep_axis_a2, - physx_sep_axis_b0, - physx_sep_axis_b1, - physx_sep_axis_b2, - physx_sep_axis_a0_cross_b0, - physx_sep_axis_a0_cross_b1, - physx_sep_axis_a0_cross_b2, - physx_sep_axis_a1_cross_b0, - physx_sep_axis_a1_cross_b1, - physx_sep_axis_a1_cross_b2, - physx_sep_axis_a2_cross_b0, - physx_sep_axis_a2_cross_b1, - physx_sep_axis_a2_cross_b2, - physx_sep_axis_force_dword = 0x7fffffff, -}; - -enum PhysxShapeFlag { - physx_sf_disable_response = (1<<12), - physx_sf_softbody_drain = (1<<18), - physx_sf_cloth_drain = (1<<15), - physx_trigger_on_enter = (1<<0), - physx_sf_point_contact_force = (1<<7), - physx_sf_softbody_disable_collision = (1<<19), - physx_sf_feature_indices = (1<<5), - physx_sf_cloth_twoway = (1<<17), - physx_sf_visualization = (1<<3), - physx_trigger_on_stay = (1<<2), - physx_sf_cloth_disable_collision = (1<<16), - physx_sf_fluid_twoway = (1<<11), - physx_trigger_on_leave = (1<<1), - physx_sf_disable_scene_queries = (1<<14), - physx_sf_disable_raycasting = (1<<6), - physx_sf_dynamic_dynamic_ccd = (1<<13), - physx_sf_disable_collision = (1<<4), - physx_sf_softbody_twoway = (1<<20), - physx_sf_fluid_disable_collision = (1<<10), - physx_sf_fluid_drain = (1<<8), -}; - -enum PhysxShapePairStreamFlags { - physx_sf_has_mats_per_point = (1<<0), - physx_sf_has_features_per_point = (1<<2), -}; - -enum PhysxShapeType { - physx_shape_plane, - physx_shape_sphere, - physx_shape_box, - physx_shape_capsule, - physx_shape_wheel, - physx_shape_convex, - physx_shape_mesh, - physx_shape_heightfield, - physx_shape_raw_mesh, - physx_shape_compound, - physx_shape_count, - physx_shape_force_dword = 0x7fffffff, -}; - -enum PhysxShapesType { - physx_dynamic_shapes = (1<<1), - physx_static_shapes = (1<<0), -}; - -enum PhysxSimulationStatus { - physx_rigid_body_finished = (1<<0), - physx_all_finished = (1<<0), - physx_primary_finished = (1<<1), -}; - -enum PhysxSimulationType { - physx_simulation_hw = 1, - physx_sty_force_dword = 0x7fffffff, - physx_simulation_sw = 0, -}; - -enum PhysxSoftBodyAttachmentFlag { - physx_softbody_attachment_tearable = (1<<1), - physx_softbody_attachment_twoway = (1<<0), -}; - -enum PhysxSoftBodyFlag { - physx_sbf_visualization = (1<<4), - physx_sbf_fluid_collision = (1<<13), - physx_sbf_static = (1<<1), - physx_sbf_collision_twoway = (1<<8), - physx_sbf_disable_collision = (1<<2), - physx_sbf_validbounds = (1<<12), - physx_sbf_tearable = (1<<9), - physx_sbf_volume_conservation = (1<<6), - physx_sbf_selfcollision = (1<<3), - physx_sbf_gravity = (1<<5), - physx_sbf_comdamping = (1<<11), - physx_sbf_hardware = (1<<10), - physx_sbf_damping = (1<<7), -}; - -enum PhysxSoftBodyMeshFlags { - physx_softbody_mesh_16_bit_indices = (1<<1), - physx_softbody_mesh_tearable = (1<<2), -}; - -enum PhysxSoftBodyVertexFlags { - physx_softbody_vertex_tearable = (1<<7), -}; - -enum PhysxSphericalJointFlag { - physx_sjf_swing_spring_enabled = 1 << 3, - physx_sjf_joint_spring_enabled = 1 << 4, - physx_sjf_twist_limit_enabled = 1 << 0, - physx_sjf_twist_spring_enabled = 1 << 2, - physx_sjf_swing_limit_enabled = 1 << 1, -}; - -enum PhysxStandardFences { - physx_fence_run_finished, - physx_num_standard_fences, -}; - -enum PhysxSweepFlags { - physx_sf_async = (1<<2), - physx_sf_debug_sm = (1<<5), - physx_sf_dynamics = (1<<1), - physx_sf_statics = (1<<0), - physx_sf_debug_et = (1<<6), - physx_sf_all_hits = (1<<3), -}; - -enum PhysxThreadPollResult { - physx_thread_shutdown = 3, - physx_thread_force_dword = 0x7fffffff, - physx_thread_nowork = 0, - physx_thread_simulation_end = 2, - physx_thread_morework = 1, -}; - -enum PhysxThreadPriority { - physx_tp_above_normal = 1, - physx_tp_normal = 2, - physx_tp_high = 0, - physx_tp_low = 4, - physx_tp_force_dword = 0xffFFffFF, - physx_tp_below_normal = 3, -}; - -enum PhysxThreadWait { - physx_wait_force_dword = 0x7fffffff, - physx_wait_shutdown = 2, - physx_wait_simulation_end = 1, - physx_wait_none = 0, -}; - -enum PhysxTimeStepMethod { - physx_timestep_fixed, - physx_timestep_variable, - physx_timestep_inherit, - physx_num_timestep_methods, - physx_tsm_force_dword = 0x7fffffff, -}; - -enum PhysxTriangleFlags { - physx_boundary_edge20 = (1<<6), - physx_double_sided = (1<<3), - physx_active_edge12 = (1<<1), - physx_active_edge01 = (1<<0), - physx_boundary_edge01 = (1<<4), - physx_boundary_edge12 = (1<<5), - physx_active_edge20 = (1<<2), -}; - - - -#endif // HAVE_PHYSX - -#endif // PHYSX_ENUMERATIONS_H