diff options
Diffstat (limited to 'modules/bullet')
43 files changed, 2323 insertions, 2167 deletions
diff --git a/modules/bullet/SCsub b/modules/bullet/SCsub index 02d0a31a69..21bdcca18e 100644 --- a/modules/bullet/SCsub +++ b/modules/bullet/SCsub @@ -1,212 +1,210 @@ #!/usr/bin/env python -Import('env') -Import('env_modules') +Import("env") +Import("env_modules") env_bullet = env_modules.Clone() # Thirdparty source files -if env['builtin_bullet']: +if env["builtin_bullet"]: # Build only version 2 for now (as of 2.89) # Sync file list with relevant upstream CMakeLists.txt for each folder. thirdparty_dir = "#thirdparty/bullet/" bullet2_src = [ # BulletCollision - "BulletCollision/BroadphaseCollision/btAxisSweep3.cpp" - , "BulletCollision/BroadphaseCollision/btBroadphaseProxy.cpp" - , "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.cpp" - , "BulletCollision/BroadphaseCollision/btDbvt.cpp" - , "BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp" - , "BulletCollision/BroadphaseCollision/btDispatcher.cpp" - , "BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp" - , "BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp" - , "BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp" - , "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp" - , "BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp" - , "BulletCollision/CollisionDispatch/btCollisionDispatcherMt.cpp" - , "BulletCollision/CollisionDispatch/btCollisionObject.cpp" - , "BulletCollision/CollisionDispatch/btCollisionWorld.cpp" - , "BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp" - , "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp" - , "BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btGhostObject.cpp" - , "BulletCollision/CollisionDispatch/btHashedSimplePairCache.cpp" - , "BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp" - , "BulletCollision/CollisionDispatch/btManifoldResult.cpp" - , "BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp" - , "BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp" - , "BulletCollision/CollisionDispatch/btUnionFind.cpp" - , "BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp" - , "BulletCollision/CollisionShapes/btBoxShape.cpp" - , "BulletCollision/CollisionShapes/btBox2dShape.cpp" - , "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp" - , "BulletCollision/CollisionShapes/btCapsuleShape.cpp" - , "BulletCollision/CollisionShapes/btCollisionShape.cpp" - , "BulletCollision/CollisionShapes/btCompoundShape.cpp" - , "BulletCollision/CollisionShapes/btConcaveShape.cpp" - , "BulletCollision/CollisionShapes/btConeShape.cpp" - , "BulletCollision/CollisionShapes/btConvexHullShape.cpp" - , "BulletCollision/CollisionShapes/btConvexInternalShape.cpp" - , "BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp" - , "BulletCollision/CollisionShapes/btConvexPolyhedron.cpp" - , "BulletCollision/CollisionShapes/btConvexShape.cpp" - , "BulletCollision/CollisionShapes/btConvex2dShape.cpp" - , "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp" - , "BulletCollision/CollisionShapes/btCylinderShape.cpp" - , "BulletCollision/CollisionShapes/btEmptyShape.cpp" - , "BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp" - , "BulletCollision/CollisionShapes/btMiniSDF.cpp" - , "BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp" - , "BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.cpp" - , "BulletCollision/CollisionShapes/btMultiSphereShape.cpp" - , "BulletCollision/CollisionShapes/btOptimizedBvh.cpp" - , "BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp" - , "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp" - , "BulletCollision/CollisionShapes/btSdfCollisionShape.cpp" - , "BulletCollision/CollisionShapes/btShapeHull.cpp" - , "BulletCollision/CollisionShapes/btSphereShape.cpp" - , "BulletCollision/CollisionShapes/btStaticPlaneShape.cpp" - , "BulletCollision/CollisionShapes/btStridingMeshInterface.cpp" - , "BulletCollision/CollisionShapes/btTetrahedronShape.cpp" - , "BulletCollision/CollisionShapes/btTriangleBuffer.cpp" - , "BulletCollision/CollisionShapes/btTriangleCallback.cpp" - , "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp" - , "BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp" - , "BulletCollision/CollisionShapes/btTriangleMesh.cpp" - , "BulletCollision/CollisionShapes/btTriangleMeshShape.cpp" - , "BulletCollision/CollisionShapes/btUniformScalingShape.cpp" - , "BulletCollision/Gimpact/btContactProcessing.cpp" - , "BulletCollision/Gimpact/btGenericPoolAllocator.cpp" - , "BulletCollision/Gimpact/btGImpactBvh.cpp" - , "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.cpp" - , "BulletCollision/Gimpact/btGImpactQuantizedBvh.cpp" - , "BulletCollision/Gimpact/btGImpactShape.cpp" - , "BulletCollision/Gimpact/btTriangleShapeEx.cpp" - , "BulletCollision/Gimpact/gim_box_set.cpp" - , "BulletCollision/Gimpact/gim_contact.cpp" - , "BulletCollision/Gimpact/gim_memory.cpp" - , "BulletCollision/Gimpact/gim_tri_collision.cpp" - , "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp" - , "BulletCollision/NarrowPhaseCollision/btConvexCast.cpp" - , "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.cpp" - , "BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp" - , "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp" - , "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp" - , "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp" - , "BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp" - , "BulletCollision/NarrowPhaseCollision/btRaycastCallback.cpp" - , "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp" - , "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp" - , "BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp" - + "BulletCollision/BroadphaseCollision/btAxisSweep3.cpp", + "BulletCollision/BroadphaseCollision/btBroadphaseProxy.cpp", + "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.cpp", + "BulletCollision/BroadphaseCollision/btDbvt.cpp", + "BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp", + "BulletCollision/BroadphaseCollision/btDispatcher.cpp", + "BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp", + "BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp", + "BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp", + "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp", + "BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp", + "BulletCollision/CollisionDispatch/btCollisionDispatcherMt.cpp", + "BulletCollision/CollisionDispatch/btCollisionObject.cpp", + "BulletCollision/CollisionDispatch/btCollisionWorld.cpp", + "BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp", + "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp", + "BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btGhostObject.cpp", + "BulletCollision/CollisionDispatch/btHashedSimplePairCache.cpp", + "BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp", + "BulletCollision/CollisionDispatch/btManifoldResult.cpp", + "BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp", + "BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp", + "BulletCollision/CollisionDispatch/btUnionFind.cpp", + "BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp", + "BulletCollision/CollisionShapes/btBoxShape.cpp", + "BulletCollision/CollisionShapes/btBox2dShape.cpp", + "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp", + "BulletCollision/CollisionShapes/btCapsuleShape.cpp", + "BulletCollision/CollisionShapes/btCollisionShape.cpp", + "BulletCollision/CollisionShapes/btCompoundShape.cpp", + "BulletCollision/CollisionShapes/btConcaveShape.cpp", + "BulletCollision/CollisionShapes/btConeShape.cpp", + "BulletCollision/CollisionShapes/btConvexHullShape.cpp", + "BulletCollision/CollisionShapes/btConvexInternalShape.cpp", + "BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp", + "BulletCollision/CollisionShapes/btConvexPolyhedron.cpp", + "BulletCollision/CollisionShapes/btConvexShape.cpp", + "BulletCollision/CollisionShapes/btConvex2dShape.cpp", + "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp", + "BulletCollision/CollisionShapes/btCylinderShape.cpp", + "BulletCollision/CollisionShapes/btEmptyShape.cpp", + "BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp", + "BulletCollision/CollisionShapes/btMiniSDF.cpp", + "BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp", + "BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.cpp", + "BulletCollision/CollisionShapes/btMultiSphereShape.cpp", + "BulletCollision/CollisionShapes/btOptimizedBvh.cpp", + "BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp", + "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp", + "BulletCollision/CollisionShapes/btSdfCollisionShape.cpp", + "BulletCollision/CollisionShapes/btShapeHull.cpp", + "BulletCollision/CollisionShapes/btSphereShape.cpp", + "BulletCollision/CollisionShapes/btStaticPlaneShape.cpp", + "BulletCollision/CollisionShapes/btStridingMeshInterface.cpp", + "BulletCollision/CollisionShapes/btTetrahedronShape.cpp", + "BulletCollision/CollisionShapes/btTriangleBuffer.cpp", + "BulletCollision/CollisionShapes/btTriangleCallback.cpp", + "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp", + "BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp", + "BulletCollision/CollisionShapes/btTriangleMesh.cpp", + "BulletCollision/CollisionShapes/btTriangleMeshShape.cpp", + "BulletCollision/CollisionShapes/btUniformScalingShape.cpp", + "BulletCollision/Gimpact/btContactProcessing.cpp", + "BulletCollision/Gimpact/btGenericPoolAllocator.cpp", + "BulletCollision/Gimpact/btGImpactBvh.cpp", + "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.cpp", + "BulletCollision/Gimpact/btGImpactQuantizedBvh.cpp", + "BulletCollision/Gimpact/btGImpactShape.cpp", + "BulletCollision/Gimpact/btTriangleShapeEx.cpp", + "BulletCollision/Gimpact/gim_box_set.cpp", + "BulletCollision/Gimpact/gim_contact.cpp", + "BulletCollision/Gimpact/gim_memory.cpp", + "BulletCollision/Gimpact/gim_tri_collision.cpp", + "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp", + "BulletCollision/NarrowPhaseCollision/btConvexCast.cpp", + "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.cpp", + "BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp", + "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp", + "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp", + "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp", + "BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp", + "BulletCollision/NarrowPhaseCollision/btRaycastCallback.cpp", + "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp", + "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp", + "BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp", # BulletDynamics - , "BulletDynamics/Character/btKinematicCharacterController.cpp" - , "BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp" - , "BulletDynamics/ConstraintSolver/btContactConstraint.cpp" - , "BulletDynamics/ConstraintSolver/btFixedConstraint.cpp" - , "BulletDynamics/ConstraintSolver/btGearConstraint.cpp" - , "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp" - , "BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp" - , "BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.cpp" - , "BulletDynamics/ConstraintSolver/btHinge2Constraint.cpp" - , "BulletDynamics/ConstraintSolver/btHingeConstraint.cpp" - , "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.cpp" - , "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp" - , "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolverMt.cpp" - , "BulletDynamics/ConstraintSolver/btBatchedConstraints.cpp" - , "BulletDynamics/ConstraintSolver/btNNCGConstraintSolver.cpp" - , "BulletDynamics/ConstraintSolver/btSliderConstraint.cpp" - , "BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.cpp" - , "BulletDynamics/ConstraintSolver/btTypedConstraint.cpp" - , "BulletDynamics/ConstraintSolver/btUniversalConstraint.cpp" - , "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp" - , "BulletDynamics/Dynamics/btDiscreteDynamicsWorldMt.cpp" - , "BulletDynamics/Dynamics/btSimulationIslandManagerMt.cpp" - , "BulletDynamics/Dynamics/btRigidBody.cpp" - , "BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp" - #, "BulletDynamics/Dynamics/Bullet-C-API.cpp" - , "BulletDynamics/Vehicle/btRaycastVehicle.cpp" - , "BulletDynamics/Vehicle/btWheelInfo.cpp" - , "BulletDynamics/Featherstone/btMultiBody.cpp" - , "BulletDynamics/Featherstone/btMultiBodyConstraint.cpp" - , "BulletDynamics/Featherstone/btMultiBodyConstraintSolver.cpp" - , "BulletDynamics/Featherstone/btMultiBodyDynamicsWorld.cpp" - , "BulletDynamics/Featherstone/btMultiBodyFixedConstraint.cpp" - , "BulletDynamics/Featherstone/btMultiBodyGearConstraint.cpp" - , "BulletDynamics/Featherstone/btMultiBodyJointLimitConstraint.cpp" - , "BulletDynamics/Featherstone/btMultiBodyJointMotor.cpp" - , "BulletDynamics/Featherstone/btMultiBodyMLCPConstraintSolver.cpp" - , "BulletDynamics/Featherstone/btMultiBodyPoint2Point.cpp" - , "BulletDynamics/Featherstone/btMultiBodySliderConstraint.cpp" - , "BulletDynamics/Featherstone/btMultiBodySphericalJointMotor.cpp" - , "BulletDynamics/MLCPSolvers/btDantzigLCP.cpp" - , "BulletDynamics/MLCPSolvers/btMLCPSolver.cpp" - , "BulletDynamics/MLCPSolvers/btLemkeAlgorithm.cpp" - + "BulletDynamics/Character/btKinematicCharacterController.cpp", + "BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp", + "BulletDynamics/ConstraintSolver/btContactConstraint.cpp", + "BulletDynamics/ConstraintSolver/btFixedConstraint.cpp", + "BulletDynamics/ConstraintSolver/btGearConstraint.cpp", + "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp", + "BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp", + "BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.cpp", + "BulletDynamics/ConstraintSolver/btHinge2Constraint.cpp", + "BulletDynamics/ConstraintSolver/btHingeConstraint.cpp", + "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.cpp", + "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp", + "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolverMt.cpp", + "BulletDynamics/ConstraintSolver/btBatchedConstraints.cpp", + "BulletDynamics/ConstraintSolver/btNNCGConstraintSolver.cpp", + "BulletDynamics/ConstraintSolver/btSliderConstraint.cpp", + "BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.cpp", + "BulletDynamics/ConstraintSolver/btTypedConstraint.cpp", + "BulletDynamics/ConstraintSolver/btUniversalConstraint.cpp", + "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp", + "BulletDynamics/Dynamics/btDiscreteDynamicsWorldMt.cpp", + "BulletDynamics/Dynamics/btSimulationIslandManagerMt.cpp", + "BulletDynamics/Dynamics/btRigidBody.cpp", + "BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp", + # "BulletDynamics/Dynamics/Bullet-C-API.cpp", + "BulletDynamics/Vehicle/btRaycastVehicle.cpp", + "BulletDynamics/Vehicle/btWheelInfo.cpp", + "BulletDynamics/Featherstone/btMultiBody.cpp", + "BulletDynamics/Featherstone/btMultiBodyConstraint.cpp", + "BulletDynamics/Featherstone/btMultiBodyConstraintSolver.cpp", + "BulletDynamics/Featherstone/btMultiBodyDynamicsWorld.cpp", + "BulletDynamics/Featherstone/btMultiBodyFixedConstraint.cpp", + "BulletDynamics/Featherstone/btMultiBodyGearConstraint.cpp", + "BulletDynamics/Featherstone/btMultiBodyJointLimitConstraint.cpp", + "BulletDynamics/Featherstone/btMultiBodyJointMotor.cpp", + "BulletDynamics/Featherstone/btMultiBodyMLCPConstraintSolver.cpp", + "BulletDynamics/Featherstone/btMultiBodyPoint2Point.cpp", + "BulletDynamics/Featherstone/btMultiBodySliderConstraint.cpp", + "BulletDynamics/Featherstone/btMultiBodySphericalJointMotor.cpp", + "BulletDynamics/MLCPSolvers/btDantzigLCP.cpp", + "BulletDynamics/MLCPSolvers/btMLCPSolver.cpp", + "BulletDynamics/MLCPSolvers/btLemkeAlgorithm.cpp", # BulletInverseDynamics - , "BulletInverseDynamics/IDMath.cpp" - , "BulletInverseDynamics/MultiBodyTree.cpp" - , "BulletInverseDynamics/details/MultiBodyTreeInitCache.cpp" - , "BulletInverseDynamics/details/MultiBodyTreeImpl.cpp" - + "BulletInverseDynamics/IDMath.cpp", + "BulletInverseDynamics/MultiBodyTree.cpp", + "BulletInverseDynamics/details/MultiBodyTreeInitCache.cpp", + "BulletInverseDynamics/details/MultiBodyTreeImpl.cpp", # BulletSoftBody - , "BulletSoftBody/btSoftBody.cpp" - , "BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp" - , "BulletSoftBody/btSoftBodyHelpers.cpp" - , "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.cpp" - , "BulletSoftBody/btSoftRigidCollisionAlgorithm.cpp" - , "BulletSoftBody/btSoftRigidDynamicsWorld.cpp" - , "BulletSoftBody/btSoftMultiBodyDynamicsWorld.cpp" - , "BulletSoftBody/btSoftSoftCollisionAlgorithm.cpp" - , "BulletSoftBody/btDefaultSoftBodySolver.cpp" - , "BulletSoftBody/btDeformableBackwardEulerObjective.cpp" - , "BulletSoftBody/btDeformableBodySolver.cpp" - , "BulletSoftBody/btDeformableMultiBodyConstraintSolver.cpp" - , "BulletSoftBody/btDeformableContactProjection.cpp" - , "BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp" - , "BulletSoftBody/btDeformableContactConstraint.cpp" - + "BulletSoftBody/btSoftBody.cpp", + "BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp", + "BulletSoftBody/btSoftBodyHelpers.cpp", + "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.cpp", + "BulletSoftBody/btSoftRigidCollisionAlgorithm.cpp", + "BulletSoftBody/btSoftRigidDynamicsWorld.cpp", + "BulletSoftBody/btSoftMultiBodyDynamicsWorld.cpp", + "BulletSoftBody/btSoftSoftCollisionAlgorithm.cpp", + "BulletSoftBody/btDefaultSoftBodySolver.cpp", + "BulletSoftBody/btDeformableBackwardEulerObjective.cpp", + "BulletSoftBody/btDeformableBodySolver.cpp", + "BulletSoftBody/btDeformableMultiBodyConstraintSolver.cpp", + "BulletSoftBody/btDeformableContactProjection.cpp", + "BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp", + "BulletSoftBody/btDeformableContactConstraint.cpp", + "BulletSoftBody/poly34.cpp", # clew - , "clew/clew.c" - + "clew/clew.c", # LinearMath - , "LinearMath/btAlignedAllocator.cpp" - , "LinearMath/btConvexHull.cpp" - , "LinearMath/btConvexHullComputer.cpp" - , "LinearMath/btGeometryUtil.cpp" - , "LinearMath/btPolarDecomposition.cpp" - , "LinearMath/btQuickprof.cpp" - , "LinearMath/btSerializer.cpp" - , "LinearMath/btSerializer64.cpp" - , "LinearMath/btThreads.cpp" - , "LinearMath/btVector3.cpp" - , "LinearMath/TaskScheduler/btTaskScheduler.cpp" - , "LinearMath/TaskScheduler/btThreadSupportPosix.cpp" - , "LinearMath/TaskScheduler/btThreadSupportWin32.cpp" + "LinearMath/btAlignedAllocator.cpp", + "LinearMath/btConvexHull.cpp", + "LinearMath/btConvexHullComputer.cpp", + "LinearMath/btGeometryUtil.cpp", + "LinearMath/btPolarDecomposition.cpp", + "LinearMath/btQuickprof.cpp", + "LinearMath/btSerializer.cpp", + "LinearMath/btSerializer64.cpp", + "LinearMath/btThreads.cpp", + "LinearMath/btVector3.cpp", + "LinearMath/TaskScheduler/btTaskScheduler.cpp", + "LinearMath/TaskScheduler/btThreadSupportPosix.cpp", + "LinearMath/TaskScheduler/btThreadSupportWin32.cpp", ] thirdparty_sources = [thirdparty_dir + file for file in bullet2_src] # Treat Bullet headers as system headers to avoid raising warnings. Not supported on MSVC. if not env.msvc: - env_bullet.Append(CPPFLAGS=['-isystem', Dir(thirdparty_dir).path]) + env_bullet.Append(CPPFLAGS=["-isystem", Dir(thirdparty_dir).path]) else: env_bullet.Prepend(CPPPATH=[thirdparty_dir]) - # if env['target'] == "debug" or env['target'] == "release_debug": - # env_bullet.Append(CPPDEFINES=['BT_DEBUG']) + if env["target"] == "debug" or env["target"] == "release_debug": + env_bullet.Append(CPPDEFINES=["DEBUG"]) + + env_bullet.Append(CPPDEFINES=["BT_USE_OLD_DAMPING_METHOD"]) env_thirdparty = env_bullet.Clone() env_thirdparty.disable_warnings() diff --git a/modules/bullet/area_bullet.cpp b/modules/bullet/area_bullet.cpp index 79ada54f0f..b35019bea3 100644 --- a/modules/bullet/area_bullet.cpp +++ b/modules/bullet/area_bullet.cpp @@ -44,19 +44,7 @@ */ AreaBullet::AreaBullet() : - RigidCollisionObjectBullet(CollisionObjectBullet::TYPE_AREA), - monitorable(true), - spOv_mode(PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED), - spOv_gravityPoint(false), - spOv_gravityPointDistanceScale(0), - spOv_gravityPointAttenuation(1), - spOv_gravityVec(0, -1, 0), - spOv_gravityMag(10), - spOv_linearDump(0.1), - spOv_angularDump(1), - spOv_priority(0), - isScratched(false) { - + RigidCollisionObjectBullet(CollisionObjectBullet::TYPE_AREA) { btGhost = bulletnew(btGhostObject); reload_shapes(); setupBulletCollisionObject(btGhost); @@ -64,33 +52,33 @@ AreaBullet::AreaBullet() : /// In order to use collision objects as trigger, you have to disable the collision response. set_collision_enabled(false); - for (int i = 0; i < 5; ++i) + for (int i = 0; i < 5; ++i) { call_event_res_ptr[i] = &call_event_res[i]; + } } AreaBullet::~AreaBullet() { // signal are handled by godot, so just clear without notify - for (int i = overlappingObjects.size() - 1; 0 <= i; --i) + for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { overlappingObjects[i].object->on_exit_area(this); + } } void AreaBullet::dispatch_callbacks() { - if (!isScratched) - return; - isScratched = false; + RigidCollisionObjectBullet::dispatch_callbacks(); // Reverse order because I've to remove EXIT objects for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { - OverlappingObjectData &otherObj = overlappingObjects.write[i]; + OverlappingObjectData &otherObj = overlappingObjects[i]; switch (otherObj.state) { case OVERLAP_STATE_ENTER: otherObj.state = OVERLAP_STATE_INSIDE; - call_event(otherObj.object, PhysicsServer::AREA_BODY_ADDED); + call_event(otherObj.object, PhysicsServer3D::AREA_BODY_ADDED); otherObj.object->on_enter_area(this); break; case OVERLAP_STATE_EXIT: - call_event(otherObj.object, PhysicsServer::AREA_BODY_REMOVED); + call_event(otherObj.object, PhysicsServer3D::AREA_BODY_REMOVED); otherObj.object->on_exit_area(this); overlappingObjects.remove(i); // Remove after callback break; @@ -101,13 +89,12 @@ void AreaBullet::dispatch_callbacks() { } } -void AreaBullet::call_event(CollisionObjectBullet *p_otherObject, PhysicsServer::AreaBodyStatus p_status) { - +void AreaBullet::call_event(CollisionObjectBullet *p_otherObject, PhysicsServer3D::AreaBodyStatus p_status) { InOutEventCallback &event = eventsCallbacks[static_cast<int>(p_otherObject->getType())]; Object *areaGodoObject = ObjectDB::get_instance(event.event_callback_id); if (!areaGodoObject) { - event.event_callback_id = 0; + event.event_callback_id = ObjectID(); return; } @@ -117,20 +104,21 @@ void AreaBullet::call_event(CollisionObjectBullet *p_otherObject, PhysicsServer: call_event_res[3] = 0; // other_body_shape ID call_event_res[4] = 0; // self_shape ID - Variant::CallError outResp; + Callable::CallError outResp; areaGodoObject->call(event.event_callback_method, (const Variant **)call_event_res_ptr, 5, outResp); } void AreaBullet::scratch() { - if (isScratched) - return; - isScratched = true; + if (space != nullptr) { + space->add_to_pre_flush_queue(this); + } } void AreaBullet::clear_overlaps(bool p_notify) { for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { - if (p_notify) - call_event(overlappingObjects[i].object, PhysicsServer::AREA_BODY_REMOVED); + if (p_notify) { + call_event(overlappingObjects[i].object, PhysicsServer3D::AREA_BODY_REMOVED); + } overlappingObjects[i].object->on_exit_area(this); } overlappingObjects.clear(); @@ -139,8 +127,9 @@ void AreaBullet::clear_overlaps(bool p_notify) { void AreaBullet::remove_overlap(CollisionObjectBullet *p_object, bool p_notify) { for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { if (overlappingObjects[i].object == p_object) { - if (p_notify) - call_event(overlappingObjects[i].object, PhysicsServer::AREA_BODY_REMOVED); + if (p_notify) { + call_event(overlappingObjects[i].object, PhysicsServer3D::AREA_BODY_REMOVED); + } overlappingObjects[i].object->on_exit_area(this); overlappingObjects.remove(i); break; @@ -167,11 +156,11 @@ bool AreaBullet::is_monitoring() const { } void AreaBullet::main_shape_changed() { - CRASH_COND(!get_main_shape()) + CRASH_COND(!get_main_shape()); btGhost->setCollisionShape(get_main_shape()); } -void AreaBullet::reload_body() { +void AreaBullet::do_reload_body() { if (space) { space->remove_area(this); space->add_area(this); @@ -180,21 +169,25 @@ void AreaBullet::reload_body() { void AreaBullet::set_space(SpaceBullet *p_space) { // Clear the old space if there is one + if (space) { - isScratched = false; + clear_overlaps(false); // Remove this object form the physics world + space->unregister_collision_object(this); space->remove_area(this); } space = p_space; if (space) { - space->add_area(this); + space->register_collision_object(this); + reload_body(); + scratch(); } } -void AreaBullet::on_collision_filters_change() { +void AreaBullet::do_reload_collision_filters() { if (space) { space->reload_collision_filters(this); } @@ -208,67 +201,67 @@ void AreaBullet::add_overlap(CollisionObjectBullet *p_otherObject) { void AreaBullet::put_overlap_as_exit(int p_index) { scratch(); - overlappingObjects.write[p_index].state = OVERLAP_STATE_EXIT; + overlappingObjects[p_index].state = OVERLAP_STATE_EXIT; } void AreaBullet::put_overlap_as_inside(int p_index) { // This check is required to be sure this body was inside if (OVERLAP_STATE_DIRTY == overlappingObjects[p_index].state) { - overlappingObjects.write[p_index].state = OVERLAP_STATE_INSIDE; + overlappingObjects[p_index].state = OVERLAP_STATE_INSIDE; } } -void AreaBullet::set_param(PhysicsServer::AreaParameter p_param, const Variant &p_value) { +void AreaBullet::set_param(PhysicsServer3D::AreaParameter p_param, const Variant &p_value) { switch (p_param) { - case PhysicsServer::AREA_PARAM_GRAVITY: + case PhysicsServer3D::AREA_PARAM_GRAVITY: set_spOv_gravityMag(p_value); break; - case PhysicsServer::AREA_PARAM_GRAVITY_VECTOR: + case PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR: set_spOv_gravityVec(p_value); break; - case PhysicsServer::AREA_PARAM_LINEAR_DAMP: + case PhysicsServer3D::AREA_PARAM_LINEAR_DAMP: set_spOv_linearDump(p_value); break; - case PhysicsServer::AREA_PARAM_ANGULAR_DAMP: + case PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP: set_spOv_angularDump(p_value); break; - case PhysicsServer::AREA_PARAM_PRIORITY: + case PhysicsServer3D::AREA_PARAM_PRIORITY: set_spOv_priority(p_value); break; - case PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT: + case PhysicsServer3D::AREA_PARAM_GRAVITY_IS_POINT: set_spOv_gravityPoint(p_value); break; - case PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE: + case PhysicsServer3D::AREA_PARAM_GRAVITY_DISTANCE_SCALE: set_spOv_gravityPointDistanceScale(p_value); break; - case PhysicsServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: + case PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_ATTENUATION: set_spOv_gravityPointAttenuation(p_value); break; default: - WARN_PRINTS("Area doesn't support this parameter in the Bullet backend: " + itos(p_param)); + WARN_PRINT("Area doesn't support this parameter in the Bullet backend: " + itos(p_param)); } } -Variant AreaBullet::get_param(PhysicsServer::AreaParameter p_param) const { +Variant AreaBullet::get_param(PhysicsServer3D::AreaParameter p_param) const { switch (p_param) { - case PhysicsServer::AREA_PARAM_GRAVITY: + case PhysicsServer3D::AREA_PARAM_GRAVITY: return spOv_gravityMag; - case PhysicsServer::AREA_PARAM_GRAVITY_VECTOR: + case PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR: return spOv_gravityVec; - case PhysicsServer::AREA_PARAM_LINEAR_DAMP: + case PhysicsServer3D::AREA_PARAM_LINEAR_DAMP: return spOv_linearDump; - case PhysicsServer::AREA_PARAM_ANGULAR_DAMP: + case PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP: return spOv_angularDump; - case PhysicsServer::AREA_PARAM_PRIORITY: + case PhysicsServer3D::AREA_PARAM_PRIORITY: return spOv_priority; - case PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT: + case PhysicsServer3D::AREA_PARAM_GRAVITY_IS_POINT: return spOv_gravityPoint; - case PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE: + case PhysicsServer3D::AREA_PARAM_GRAVITY_DISTANCE_SCALE: return spOv_gravityPointDistanceScale; - case PhysicsServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: + case PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_ATTENUATION: return spOv_gravityPointAttenuation; default: - WARN_PRINTS("Area doesn't support this parameter in the Bullet backend: " + itos(p_param)); + WARN_PRINT("Area doesn't support this parameter in the Bullet backend: " + itos(p_param)); return Variant(); } } @@ -279,7 +272,7 @@ void AreaBullet::set_event_callback(Type p_callbackObjectType, ObjectID p_id, co ev.event_callback_method = p_method; /// Set if monitoring - if (eventsCallbacks[0].event_callback_id || eventsCallbacks[1].event_callback_id) { + if (eventsCallbacks[0].event_callback_id.is_valid() || eventsCallbacks[1].event_callback_id.is_valid()) { set_godot_object_flags(get_godot_object_flags() | GOF_IS_MONITORING_AREA); } else { set_godot_object_flags(get_godot_object_flags() & (~GOF_IS_MONITORING_AREA)); @@ -287,7 +280,7 @@ void AreaBullet::set_event_callback(Type p_callbackObjectType, ObjectID p_id, co } bool AreaBullet::has_event_callback(Type p_callbackObjectType) { - return eventsCallbacks[static_cast<int>(p_callbackObjectType)].event_callback_id; + return eventsCallbacks[static_cast<int>(p_callbackObjectType)].event_callback_id.is_valid(); } void AreaBullet::on_enter_area(AreaBullet *p_area) { diff --git a/modules/bullet/area_bullet.h b/modules/bullet/area_bullet.h index f770c63bcc..51fbc1f71d 100644 --- a/modules/bullet/area_bullet.h +++ b/modules/bullet/area_bullet.h @@ -32,8 +32,8 @@ #define AREABULLET_H #include "collision_object_bullet.h" -#include "core/vector.h" -#include "servers/physics_server.h" +#include "core/local_vector.h" +#include "servers/physics_server_3d.h" #include "space_bullet.h" /** @@ -50,8 +50,7 @@ public: ObjectID event_callback_id; StringName event_callback_method; - InOutEventCallback() : - event_callback_id(0) {} + InOutEventCallback() {} }; enum OverlapState { @@ -62,12 +61,10 @@ public: }; struct OverlappingObjectData { - CollisionObjectBullet *object; - OverlapState state; + CollisionObjectBullet *object = nullptr; + OverlapState state = OVERLAP_STATE_ENTER; - OverlappingObjectData() : - object(NULL), - state(OVERLAP_STATE_ENTER) {} + OverlappingObjectData() {} OverlappingObjectData(CollisionObjectBullet *p_object, OverlapState p_state) : object(p_object), state(p_state) {} @@ -86,20 +83,18 @@ private: Variant *call_event_res_ptr[5]; btGhostObject *btGhost; - Vector<OverlappingObjectData> overlappingObjects; - bool monitorable; - - PhysicsServer::AreaSpaceOverrideMode spOv_mode; - bool spOv_gravityPoint; - real_t spOv_gravityPointDistanceScale; - real_t spOv_gravityPointAttenuation; - Vector3 spOv_gravityVec; - real_t spOv_gravityMag; - real_t spOv_linearDump; - real_t spOv_angularDump; - int spOv_priority; - - bool isScratched; + LocalVector<OverlappingObjectData> overlappingObjects; + bool monitorable = true; + + PhysicsServer3D::AreaSpaceOverrideMode spOv_mode = PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED; + bool spOv_gravityPoint = false; + real_t spOv_gravityPointDistanceScale = 0; + real_t spOv_gravityPointAttenuation = 1; + Vector3 spOv_gravityVec = Vector3(0, -1, 0); + real_t spOv_gravityMag = 10; + real_t spOv_linearDump = 0.1; + real_t spOv_angularDump = 0.1; + int spOv_priority = 0; InOutEventCallback eventsCallbacks[2]; @@ -115,8 +110,8 @@ public: bool is_monitoring() const; - _FORCE_INLINE_ void set_spOv_mode(PhysicsServer::AreaSpaceOverrideMode p_mode) { spOv_mode = p_mode; } - _FORCE_INLINE_ PhysicsServer::AreaSpaceOverrideMode get_spOv_mode() { return spOv_mode; } + _FORCE_INLINE_ void set_spOv_mode(PhysicsServer3D::AreaSpaceOverrideMode p_mode) { spOv_mode = p_mode; } + _FORCE_INLINE_ PhysicsServer3D::AreaSpaceOverrideMode get_spOv_mode() { return spOv_mode; } _FORCE_INLINE_ void set_spOv_gravityPoint(bool p_isGP) { spOv_gravityPoint = p_isGP; } _FORCE_INLINE_ bool is_spOv_gravityPoint() { return spOv_gravityPoint; } @@ -142,12 +137,12 @@ public: _FORCE_INLINE_ void set_spOv_priority(int p_priority) { spOv_priority = p_priority; } _FORCE_INLINE_ int get_spOv_priority() { return spOv_priority; } - virtual void main_shape_changed(); - virtual void reload_body(); - virtual void set_space(SpaceBullet *p_space); + virtual void main_shape_changed() override; + virtual void do_reload_body() override; + virtual void set_space(SpaceBullet *p_space) override; - virtual void dispatch_callbacks(); - void call_event(CollisionObjectBullet *p_otherObject, PhysicsServer::AreaBodyStatus p_status); + virtual void dispatch_callbacks() override; + void call_event(CollisionObjectBullet *p_otherObject, PhysicsServer3D::AreaBodyStatus p_status); void set_on_state_change(ObjectID p_id, const StringName &p_method, const Variant &p_udata = Variant()); void scratch(); @@ -155,22 +150,22 @@ public: // Dispatch the callbacks and removes from overlapping list void remove_overlap(CollisionObjectBullet *p_object, bool p_notify); - virtual void on_collision_filters_change(); - virtual void on_collision_checker_start() {} - virtual void on_collision_checker_end() { isTransformChanged = false; } + virtual void do_reload_collision_filters() override; + virtual void on_collision_checker_start() override {} + virtual void on_collision_checker_end() override { isTransformChanged = false; } void add_overlap(CollisionObjectBullet *p_otherObject); void put_overlap_as_exit(int p_index); void put_overlap_as_inside(int p_index); - void set_param(PhysicsServer::AreaParameter p_param, const Variant &p_value); - Variant get_param(PhysicsServer::AreaParameter p_param) const; + void set_param(PhysicsServer3D::AreaParameter p_param, const Variant &p_value); + Variant get_param(PhysicsServer3D::AreaParameter p_param) const; void set_event_callback(Type p_callbackObjectType, ObjectID p_id, const StringName &p_method); bool has_event_callback(Type p_callbackObjectType); - virtual void on_enter_area(AreaBullet *p_area); - virtual void on_exit_area(AreaBullet *p_area); + virtual void on_enter_area(AreaBullet *p_area) override; + virtual void on_exit_area(AreaBullet *p_area) override; }; #endif diff --git a/modules/bullet/btRayShape.cpp b/modules/bullet/btRayShape.cpp index 4071723a3e..a754ca6a89 100644 --- a/modules/bullet/btRayShape.cpp +++ b/modules/bullet/btRayShape.cpp @@ -43,13 +43,13 @@ btRayShape::btRayShape(btScalar length) : m_shapeAxis(0, 0, 1) { m_shapeType = CUSTOM_CONVEX_SHAPE_TYPE; setLength(length); + slipsOnSlope = false; } btRayShape::~btRayShape() { } void btRayShape::setLength(btScalar p_length) { - m_length = p_length; reload_cache(); } @@ -60,7 +60,6 @@ void btRayShape::setMargin(btScalar margin) { } void btRayShape::setSlipsOnSlope(bool p_slipsOnSlope) { - slipsOnSlope = p_slipsOnSlope; } @@ -69,10 +68,11 @@ btVector3 btRayShape::localGetSupportingVertex(const btVector3 &vec) const { } btVector3 btRayShape::localGetSupportingVertexWithoutMargin(const btVector3 &vec) const { - if (vec.z() > 0) + if (vec.z() > 0) { return m_shapeAxis * m_cacheScaledLength; - else + } else { return btVector3(0, 0, 0); + } } void btRayShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const { @@ -100,7 +100,6 @@ void btRayShape::getPreferredPenetrationDirection(int index, btVector3 &penetrat } void btRayShape::reload_cache() { - m_cacheScaledLength = m_length * m_localScaling[2]; m_cacheSupportPoint.setIdentity(); diff --git a/modules/bullet/btRayShape.h b/modules/bullet/btRayShape.h index df6dd93d57..d9ecde81e6 100644 --- a/modules/bullet/btRayShape.h +++ b/modules/bullet/btRayShape.h @@ -42,7 +42,6 @@ /// Ray shape around z axis ATTRIBUTE_ALIGNED16(class) btRayShape : public btConvexInternalShape { - btScalar m_length; bool slipsOnSlope; /// The default axis is the z diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index 6662e130c8..8f64c11867 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -57,10 +57,10 @@ // <--------------- Joint creation asserts /// Assert the body is assigned to a space -#define JointAssertSpace(body, bIndex, ret) \ - if (!body->get_space()) { \ - ERR_PRINTS("Before create a joint the Body" + String(bIndex) + " must be added to a space!"); \ - return ret; \ +#define JointAssertSpace(body, bIndex, ret) \ + if (!body->get_space()) { \ + ERR_PRINT("Before create a joint the Body" + String(bIndex) + " must be added to a space!"); \ + return ret; \ } /// Assert the two bodies of joint are in the same space @@ -74,51 +74,41 @@ body->get_space()->add_constraint(joint, joint->is_disabled_collisions_between_bodies()); // <--------------- Joint creation asserts -void BulletPhysicsServer::_bind_methods() { - //ClassDB::bind_method(D_METHOD("DoTest"), &BulletPhysicsServer::DoTest); +void BulletPhysicsServer3D::_bind_methods() { + //ClassDB::bind_method(D_METHOD("DoTest"), &BulletPhysicsServer3D::DoTest); } -BulletPhysicsServer::BulletPhysicsServer() : - PhysicsServer(), - active(true), - active_spaces_count(0) {} +BulletPhysicsServer3D::BulletPhysicsServer3D() : + PhysicsServer3D() {} -BulletPhysicsServer::~BulletPhysicsServer() {} +BulletPhysicsServer3D::~BulletPhysicsServer3D() {} -RID BulletPhysicsServer::shape_create(ShapeType p_shape) { - ShapeBullet *shape = NULL; +RID BulletPhysicsServer3D::shape_create(ShapeType p_shape) { + ShapeBullet *shape = nullptr; switch (p_shape) { case SHAPE_PLANE: { - shape = bulletnew(PlaneShapeBullet); } break; case SHAPE_SPHERE: { - shape = bulletnew(SphereShapeBullet); } break; case SHAPE_BOX: { - shape = bulletnew(BoxShapeBullet); } break; case SHAPE_CAPSULE: { - shape = bulletnew(CapsuleShapeBullet); } break; case SHAPE_CYLINDER: { - shape = bulletnew(CylinderShapeBullet); } break; case SHAPE_CONVEX_POLYGON: { - shape = bulletnew(ConvexPolygonShapeBullet); } break; case SHAPE_CONCAVE_POLYGON: { - shape = bulletnew(ConcavePolygonShapeBullet); } break; case SHAPE_HEIGHTMAP: { - shape = bulletnew(HeightMapShapeBullet); } break; case SHAPE_RAY: { @@ -133,53 +123,52 @@ RID BulletPhysicsServer::shape_create(ShapeType p_shape) { CreateThenReturnRID(shape_owner, shape) } -void BulletPhysicsServer::shape_set_data(RID p_shape, const Variant &p_data) { - ShapeBullet *shape = shape_owner.get(p_shape); +void BulletPhysicsServer3D::shape_set_data(RID p_shape, const Variant &p_data) { + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); shape->set_data(p_data); } -void BulletPhysicsServer::shape_set_custom_solver_bias(RID p_shape, real_t p_bias) { +void BulletPhysicsServer3D::shape_set_custom_solver_bias(RID p_shape, real_t p_bias) { //WARN_PRINT("Bias not supported by Bullet physics engine"); } -PhysicsServer::ShapeType BulletPhysicsServer::shape_get_type(RID p_shape) const { - ShapeBullet *shape = shape_owner.get(p_shape); - ERR_FAIL_COND_V(!shape, PhysicsServer::SHAPE_CUSTOM); +PhysicsServer3D::ShapeType BulletPhysicsServer3D::shape_get_type(RID p_shape) const { + ShapeBullet *shape = shape_owner.getornull(p_shape); + ERR_FAIL_COND_V(!shape, PhysicsServer3D::SHAPE_CUSTOM); return shape->get_type(); } -Variant BulletPhysicsServer::shape_get_data(RID p_shape) const { - ShapeBullet *shape = shape_owner.get(p_shape); +Variant BulletPhysicsServer3D::shape_get_data(RID p_shape) const { + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, Variant()); return shape->get_data(); } -void BulletPhysicsServer::shape_set_margin(RID p_shape, real_t p_margin) { - ShapeBullet *shape = shape_owner.get(p_shape); +void BulletPhysicsServer3D::shape_set_margin(RID p_shape, real_t p_margin) { + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); shape->set_margin(p_margin); } -real_t BulletPhysicsServer::shape_get_margin(RID p_shape) const { - ShapeBullet *shape = shape_owner.get(p_shape); +real_t BulletPhysicsServer3D::shape_get_margin(RID p_shape) const { + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, 0.0); return shape->get_margin(); } -real_t BulletPhysicsServer::shape_get_custom_solver_bias(RID p_shape) const { +real_t BulletPhysicsServer3D::shape_get_custom_solver_bias(RID p_shape) const { //WARN_PRINT("Bias not supported by Bullet physics engine"); return 0.; } -RID BulletPhysicsServer::space_create() { +RID BulletPhysicsServer3D::space_create() { SpaceBullet *space = bulletnew(SpaceBullet); CreateThenReturnRID(space_owner, space); } -void BulletPhysicsServer::space_set_active(RID p_space, bool p_active) { - - SpaceBullet *space = space_owner.get(p_space); +void BulletPhysicsServer3D::space_set_active(RID p_space, bool p_active) { + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); if (space_is_active(p_space) == p_active) { @@ -195,345 +184,347 @@ void BulletPhysicsServer::space_set_active(RID p_space, bool p_active) { } } -bool BulletPhysicsServer::space_is_active(RID p_space) const { - SpaceBullet *space = space_owner.get(p_space); +bool BulletPhysicsServer3D::space_is_active(RID p_space) const { + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, false); return -1 != active_spaces.find(space); } -void BulletPhysicsServer::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) { - SpaceBullet *space = space_owner.get(p_space); +void BulletPhysicsServer3D::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) { + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); space->set_param(p_param, p_value); } -real_t BulletPhysicsServer::space_get_param(RID p_space, SpaceParameter p_param) const { - SpaceBullet *space = space_owner.get(p_space); +real_t BulletPhysicsServer3D::space_get_param(RID p_space, SpaceParameter p_param) const { + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, 0); return space->get_param(p_param); } -PhysicsDirectSpaceState *BulletPhysicsServer::space_get_direct_state(RID p_space) { - SpaceBullet *space = space_owner.get(p_space); - ERR_FAIL_COND_V(!space, NULL); +PhysicsDirectSpaceState3D *BulletPhysicsServer3D::space_get_direct_state(RID p_space) { + SpaceBullet *space = space_owner.getornull(p_space); + ERR_FAIL_COND_V(!space, nullptr); return space->get_direct_state(); } -void BulletPhysicsServer::space_set_debug_contacts(RID p_space, int p_max_contacts) { - SpaceBullet *space = space_owner.get(p_space); +void BulletPhysicsServer3D::space_set_debug_contacts(RID p_space, int p_max_contacts) { + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); space->set_debug_contacts(p_max_contacts); } -Vector<Vector3> BulletPhysicsServer::space_get_contacts(RID p_space) const { - SpaceBullet *space = space_owner.get(p_space); +Vector<Vector3> BulletPhysicsServer3D::space_get_contacts(RID p_space) const { + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, Vector<Vector3>()); return space->get_debug_contacts(); } -int BulletPhysicsServer::space_get_contact_count(RID p_space) const { - SpaceBullet *space = space_owner.get(p_space); +int BulletPhysicsServer3D::space_get_contact_count(RID p_space) const { + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, 0); return space->get_debug_contact_count(); } -RID BulletPhysicsServer::area_create() { +RID BulletPhysicsServer3D::area_create() { AreaBullet *area = bulletnew(AreaBullet); area->set_collision_layer(1); area->set_collision_mask(1); CreateThenReturnRID(area_owner, area) } -void BulletPhysicsServer::area_set_space(RID p_area, RID p_space) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_space(RID p_area, RID p_space) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - SpaceBullet *space = NULL; + SpaceBullet *space = nullptr; if (p_space.is_valid()) { - space = space_owner.get(p_space); + space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); } area->set_space(space); } -RID BulletPhysicsServer::area_get_space(RID p_area) const { - AreaBullet *area = area_owner.get(p_area); +RID BulletPhysicsServer3D::area_get_space(RID p_area) const { + AreaBullet *area = area_owner.getornull(p_area); return area->get_space()->get_self(); } -void BulletPhysicsServer::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_spOv_mode(p_mode); } -PhysicsServer::AreaSpaceOverrideMode BulletPhysicsServer::area_get_space_override_mode(RID p_area) const { - AreaBullet *area = area_owner.get(p_area); - ERR_FAIL_COND_V(!area, PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED); +PhysicsServer3D::AreaSpaceOverrideMode BulletPhysicsServer3D::area_get_space_override_mode(RID p_area) const { + AreaBullet *area = area_owner.getornull(p_area); + ERR_FAIL_COND_V(!area, PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED); return area->get_spOv_mode(); } -void BulletPhysicsServer::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform, bool p_disabled) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform, bool p_disabled) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); area->add_shape(shape, p_transform, p_disabled); } -void BulletPhysicsServer::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); area->set_shape(p_shape_idx, shape); } -void BulletPhysicsServer::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_shape_transform(p_shape_idx, p_transform); } -int BulletPhysicsServer::area_get_shape_count(RID p_area) const { - AreaBullet *area = area_owner.get(p_area); +int BulletPhysicsServer3D::area_get_shape_count(RID p_area) const { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, 0); return area->get_shape_count(); } -RID BulletPhysicsServer::area_get_shape(RID p_area, int p_shape_idx) const { - AreaBullet *area = area_owner.get(p_area); +RID BulletPhysicsServer3D::area_get_shape(RID p_area, int p_shape_idx) const { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, RID()); return area->get_shape(p_shape_idx)->get_self(); } -Transform BulletPhysicsServer::area_get_shape_transform(RID p_area, int p_shape_idx) const { - AreaBullet *area = area_owner.get(p_area); +Transform BulletPhysicsServer3D::area_get_shape_transform(RID p_area, int p_shape_idx) const { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Transform()); return area->get_shape_transform(p_shape_idx); } -void BulletPhysicsServer::area_remove_shape(RID p_area, int p_shape_idx) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_remove_shape(RID p_area, int p_shape_idx) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); return area->remove_shape_full(p_shape_idx); } -void BulletPhysicsServer::area_clear_shapes(RID p_area) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_clear_shapes(RID p_area) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - for (int i = area->get_shape_count(); 0 < i; --i) + for (int i = area->get_shape_count(); 0 < i; --i) { area->remove_shape_full(0); + } } -void BulletPhysicsServer::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_shape_disabled(p_shape_idx, p_disabled); } -void BulletPhysicsServer::area_attach_object_instance_id(RID p_area, ObjectID p_id) { +void BulletPhysicsServer3D::area_attach_object_instance_id(RID p_area, ObjectID p_id) { if (space_owner.owns(p_area)) { return; } - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_instance_id(p_id); } -ObjectID BulletPhysicsServer::area_get_object_instance_id(RID p_area) const { +ObjectID BulletPhysicsServer3D::area_get_object_instance_id(RID p_area) const { if (space_owner.owns(p_area)) { - return 0; + return ObjectID(); } - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, ObjectID()); return area->get_instance_id(); } -void BulletPhysicsServer::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) { +void BulletPhysicsServer3D::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) { if (space_owner.owns(p_area)) { - SpaceBullet *space = space_owner.get(p_area); + SpaceBullet *space = space_owner.getornull(p_area); if (space) { space->set_param(p_param, p_value); } } else { - - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_param(p_param, p_value); } } -Variant BulletPhysicsServer::area_get_param(RID p_area, AreaParameter p_param) const { +Variant BulletPhysicsServer3D::area_get_param(RID p_area, AreaParameter p_param) const { if (space_owner.owns(p_area)) { - SpaceBullet *space = space_owner.get(p_area); + SpaceBullet *space = space_owner.getornull(p_area); return space->get_param(p_param); } else { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Variant()); return area->get_param(p_param); } } -void BulletPhysicsServer::area_set_transform(RID p_area, const Transform &p_transform) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_transform(RID p_area, const Transform &p_transform) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_transform(p_transform); } -Transform BulletPhysicsServer::area_get_transform(RID p_area) const { - AreaBullet *area = area_owner.get(p_area); +Transform BulletPhysicsServer3D::area_get_transform(RID p_area) const { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Transform()); return area->get_transform(); } -void BulletPhysicsServer::area_set_collision_mask(RID p_area, uint32_t p_mask) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_collision_mask(RID p_area, uint32_t p_mask) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_collision_mask(p_mask); } -void BulletPhysicsServer::area_set_collision_layer(RID p_area, uint32_t p_layer) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_collision_layer(RID p_area, uint32_t p_layer) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_collision_layer(p_layer); } -void BulletPhysicsServer::area_set_monitorable(RID p_area, bool p_monitorable) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_monitorable(RID p_area, bool p_monitorable) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_monitorable(p_monitorable); } -void BulletPhysicsServer::area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - area->set_event_callback(CollisionObjectBullet::TYPE_RIGID_BODY, p_receiver ? p_receiver->get_instance_id() : 0, p_method); + area->set_event_callback(CollisionObjectBullet::TYPE_RIGID_BODY, p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method); } -void BulletPhysicsServer::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - area->set_event_callback(CollisionObjectBullet::TYPE_AREA, p_receiver ? p_receiver->get_instance_id() : 0, p_method); + area->set_event_callback(CollisionObjectBullet::TYPE_AREA, p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method); } -void BulletPhysicsServer::area_set_ray_pickable(RID p_area, bool p_enable) { - AreaBullet *area = area_owner.get(p_area); +void BulletPhysicsServer3D::area_set_ray_pickable(RID p_area, bool p_enable) { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_ray_pickable(p_enable); } -bool BulletPhysicsServer::area_is_ray_pickable(RID p_area) const { - AreaBullet *area = area_owner.get(p_area); +bool BulletPhysicsServer3D::area_is_ray_pickable(RID p_area) const { + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, false); return area->is_ray_pickable(); } -RID BulletPhysicsServer::body_create(BodyMode p_mode, bool p_init_sleeping) { +RID BulletPhysicsServer3D::body_create(BodyMode p_mode, bool p_init_sleeping) { RigidBodyBullet *body = bulletnew(RigidBodyBullet); body->set_mode(p_mode); body->set_collision_layer(1); body->set_collision_mask(1); - if (p_init_sleeping) + if (p_init_sleeping) { body->set_state(BODY_STATE_SLEEPING, p_init_sleeping); + } CreateThenReturnRID(rigid_body_owner, body); } -void BulletPhysicsServer::body_set_space(RID p_body, RID p_space) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_space(RID p_body, RID p_space) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - SpaceBullet *space = NULL; + SpaceBullet *space = nullptr; if (p_space.is_valid()) { - space = space_owner.get(p_space); + space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); } - if (body->get_space() == space) + if (body->get_space() == space) { return; //pointles + } body->set_space(space); } -RID BulletPhysicsServer::body_get_space(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +RID BulletPhysicsServer3D::body_get_space(RID p_body) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, RID()); SpaceBullet *space = body->get_space(); - if (!space) + if (!space) { return RID(); + } return space->get_self(); } -void BulletPhysicsServer::body_set_mode(RID p_body, PhysicsServer::BodyMode p_mode) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_mode(RID p_body, PhysicsServer3D::BodyMode p_mode) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_mode(p_mode); } -PhysicsServer::BodyMode BulletPhysicsServer::body_get_mode(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +PhysicsServer3D::BodyMode BulletPhysicsServer3D::body_get_mode(RID p_body) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, BODY_MODE_STATIC); return body->get_mode(); } -void BulletPhysicsServer::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform, bool p_disabled) { - - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform, bool p_disabled) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); body->add_shape(shape, p_transform, p_disabled); } -void BulletPhysicsServer::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); body->set_shape(p_shape_idx, shape); } -void BulletPhysicsServer::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_shape_transform(p_shape_idx, p_transform); } -int BulletPhysicsServer::body_get_shape_count(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +int BulletPhysicsServer3D::body_get_shape_count(RID p_body) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_shape_count(); } -RID BulletPhysicsServer::body_get_shape(RID p_body, int p_shape_idx) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +RID BulletPhysicsServer3D::body_get_shape(RID p_body, int p_shape_idx) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, RID()); ShapeBullet *shape = body->get_shape(p_shape_idx); @@ -542,219 +533,217 @@ RID BulletPhysicsServer::body_get_shape(RID p_body, int p_shape_idx) const { return shape->get_self(); } -Transform BulletPhysicsServer::body_get_shape_transform(RID p_body, int p_shape_idx) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +Transform BulletPhysicsServer3D::body_get_shape_transform(RID p_body, int p_shape_idx) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Transform()); return body->get_shape_transform(p_shape_idx); } -void BulletPhysicsServer::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_shape_disabled(p_shape_idx, p_disabled); } -void BulletPhysicsServer::body_remove_shape(RID p_body, int p_shape_idx) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_remove_shape(RID p_body, int p_shape_idx) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->remove_shape_full(p_shape_idx); } -void BulletPhysicsServer::body_clear_shapes(RID p_body) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_clear_shapes(RID p_body) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->remove_all_shapes(); } -void BulletPhysicsServer::body_attach_object_instance_id(RID p_body, uint32_t p_id) { - CollisionObjectBullet *body = get_collisin_object(p_body); +void BulletPhysicsServer3D::body_attach_object_instance_id(RID p_body, ObjectID p_id) { + CollisionObjectBullet *body = get_collision_object(p_body); ERR_FAIL_COND(!body); body->set_instance_id(p_id); } -uint32_t BulletPhysicsServer::body_get_object_instance_id(RID p_body) const { - CollisionObjectBullet *body = get_collisin_object(p_body); - ERR_FAIL_COND_V(!body, 0); +ObjectID BulletPhysicsServer3D::body_get_object_instance_id(RID p_body) const { + CollisionObjectBullet *body = get_collision_object(p_body); + ERR_FAIL_COND_V(!body, ObjectID()); return body->get_instance_id(); } -void BulletPhysicsServer::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_continuous_collision_detection(p_enable); } -bool BulletPhysicsServer::body_is_continuous_collision_detection_enabled(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +bool BulletPhysicsServer3D::body_is_continuous_collision_detection_enabled(RID p_body) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->is_continuous_collision_detection_enabled(); } -void BulletPhysicsServer::body_set_collision_layer(RID p_body, uint32_t p_layer) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_collision_layer(RID p_body, uint32_t p_layer) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_layer(p_layer); } -uint32_t BulletPhysicsServer::body_get_collision_layer(RID p_body) const { - const RigidBodyBullet *body = rigid_body_owner.get(p_body); +uint32_t BulletPhysicsServer3D::body_get_collision_layer(RID p_body) const { + const RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_layer(); } -void BulletPhysicsServer::body_set_collision_mask(RID p_body, uint32_t p_mask) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_collision_mask(RID p_body, uint32_t p_mask) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_mask(p_mask); } -uint32_t BulletPhysicsServer::body_get_collision_mask(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +uint32_t BulletPhysicsServer3D::body_get_collision_mask(RID p_body) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_mask(); } -void BulletPhysicsServer::body_set_user_flags(RID p_body, uint32_t p_flags) { +void BulletPhysicsServer3D::body_set_user_flags(RID p_body, uint32_t p_flags) { // This function si not currently supported } -uint32_t BulletPhysicsServer::body_get_user_flags(RID p_body) const { +uint32_t BulletPhysicsServer3D::body_get_user_flags(RID p_body) const { // This function si not currently supported return 0; } -void BulletPhysicsServer::body_set_param(RID p_body, BodyParameter p_param, float p_value) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_param(RID p_body, BodyParameter p_param, float p_value) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_param(p_param, p_value); } -float BulletPhysicsServer::body_get_param(RID p_body, BodyParameter p_param) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +float BulletPhysicsServer3D::body_get_param(RID p_body, BodyParameter p_param) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_param(p_param); } -void BulletPhysicsServer::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); if (body->get_kinematic_utilities()) { - body->get_kinematic_utilities()->setSafeMargin(p_margin); } } -real_t BulletPhysicsServer::body_get_kinematic_safe_margin(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +real_t BulletPhysicsServer3D::body_get_kinematic_safe_margin(RID p_body) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); if (body->get_kinematic_utilities()) { - return body->get_kinematic_utilities()->safe_margin; } return 0; } -void BulletPhysicsServer::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_state(p_state, p_variant); } -Variant BulletPhysicsServer::body_get_state(RID p_body, BodyState p_state) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +Variant BulletPhysicsServer3D::body_get_state(RID p_body, BodyState p_state) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Variant()); return body->get_state(p_state); } -void BulletPhysicsServer::body_set_applied_force(RID p_body, const Vector3 &p_force) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_applied_force(RID p_body, const Vector3 &p_force) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_applied_force(p_force); } -Vector3 BulletPhysicsServer::body_get_applied_force(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +Vector3 BulletPhysicsServer3D::body_get_applied_force(RID p_body) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Vector3()); return body->get_applied_force(); } -void BulletPhysicsServer::body_set_applied_torque(RID p_body, const Vector3 &p_torque) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_applied_torque(RID p_body, const Vector3 &p_torque) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_applied_torque(p_torque); } -Vector3 BulletPhysicsServer::body_get_applied_torque(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +Vector3 BulletPhysicsServer3D::body_get_applied_torque(RID p_body) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Vector3()); return body->get_applied_torque(); } -void BulletPhysicsServer::body_add_central_force(RID p_body, const Vector3 &p_force) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_add_central_force(RID p_body, const Vector3 &p_force) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->apply_central_force(p_force); } -void BulletPhysicsServer::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_pos) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - body->apply_force(p_force, p_pos); + body->apply_force(p_force, p_position); } -void BulletPhysicsServer::body_add_torque(RID p_body, const Vector3 &p_torque) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_add_torque(RID p_body, const Vector3 &p_torque) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->apply_torque(p_torque); } -void BulletPhysicsServer::body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->apply_central_impulse(p_impulse); } -void BulletPhysicsServer::body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - body->apply_impulse(p_pos, p_impulse); + body->apply_impulse(p_impulse, p_position); } -void BulletPhysicsServer::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->apply_torque_impulse(p_impulse); } -void BulletPhysicsServer::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); Vector3 v = body->get_linear_velocity(); @@ -764,254 +753,257 @@ void BulletPhysicsServer::body_set_axis_velocity(RID p_body, const Vector3 &p_ax body->set_linear_velocity(v); } -void BulletPhysicsServer::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_axis_lock(p_axis, p_lock); } -bool BulletPhysicsServer::body_is_axis_locked(RID p_body, BodyAxis p_axis) const { - const RigidBodyBullet *body = rigid_body_owner.get(p_body); +bool BulletPhysicsServer3D::body_is_axis_locked(RID p_body, BodyAxis p_axis) const { + const RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->is_axis_locked(p_axis); } -void BulletPhysicsServer::body_add_collision_exception(RID p_body, RID p_body_b) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_add_collision_exception(RID p_body, RID p_body_b) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - RigidBodyBullet *other_body = rigid_body_owner.get(p_body_b); + RigidBodyBullet *other_body = rigid_body_owner.getornull(p_body_b); ERR_FAIL_COND(!other_body); body->add_collision_exception(other_body); } -void BulletPhysicsServer::body_remove_collision_exception(RID p_body, RID p_body_b) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_remove_collision_exception(RID p_body, RID p_body_b) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - RigidBodyBullet *other_body = rigid_body_owner.get(p_body_b); + RigidBodyBullet *other_body = rigid_body_owner.getornull(p_body_b); ERR_FAIL_COND(!other_body); body->remove_collision_exception(other_body); } -void BulletPhysicsServer::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); for (int i = 0; i < body->get_exceptions().size(); i++) { p_exceptions->push_back(body->get_exceptions()[i]); } } -void BulletPhysicsServer::body_set_max_contacts_reported(RID p_body, int p_contacts) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_max_contacts_reported(RID p_body, int p_contacts) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_max_collisions_detection(p_contacts); } -int BulletPhysicsServer::body_get_max_contacts_reported(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +int BulletPhysicsServer3D::body_get_max_contacts_reported(RID p_body) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_max_collisions_detection(); } -void BulletPhysicsServer::body_set_contacts_reported_depth_threshold(RID p_body, float p_threshold) { +void BulletPhysicsServer3D::body_set_contacts_reported_depth_threshold(RID p_body, float p_threshold) { // Not supported by bullet and even Godot } -float BulletPhysicsServer::body_get_contacts_reported_depth_threshold(RID p_body) const { +float BulletPhysicsServer3D::body_get_contacts_reported_depth_threshold(RID p_body) const { // Not supported by bullet and even Godot return 0.; } -void BulletPhysicsServer::body_set_omit_force_integration(RID p_body, bool p_omit) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_omit_force_integration(RID p_body, bool p_omit) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_omit_forces_integration(p_omit); } -bool BulletPhysicsServer::body_is_omitting_force_integration(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +bool BulletPhysicsServer3D::body_is_omitting_force_integration(RID p_body) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->get_omit_forces_integration(); } -void BulletPhysicsServer::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(0), p_method, p_udata); + body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method, p_udata); } -void BulletPhysicsServer::body_set_ray_pickable(RID p_body, bool p_enable) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +void BulletPhysicsServer3D::body_set_ray_pickable(RID p_body, bool p_enable) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_ray_pickable(p_enable); } -bool BulletPhysicsServer::body_is_ray_pickable(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +bool BulletPhysicsServer3D::body_is_ray_pickable(RID p_body) const { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->is_ray_pickable(); } -PhysicsDirectBodyState *BulletPhysicsServer::body_get_direct_state(RID p_body) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); - ERR_FAIL_COND_V(!body, NULL); - return BulletPhysicsDirectBodyState::get_singleton(body); +PhysicsDirectBodyState3D *BulletPhysicsServer3D::body_get_direct_state(RID p_body) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + ERR_FAIL_COND_V(!body, nullptr); + return BulletPhysicsDirectBodyState3D::get_singleton(body); } -bool BulletPhysicsServer::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result, bool p_exclude_raycast_shapes) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +bool BulletPhysicsServer3D::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result, bool p_exclude_raycast_shapes) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); ERR_FAIL_COND_V(!body->get_space(), false); return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, r_result, p_exclude_raycast_shapes); } -int BulletPhysicsServer::body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); +int BulletPhysicsServer3D::body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); ERR_FAIL_COND_V(!body->get_space(), 0); return body->get_space()->test_ray_separation(body, p_transform, p_infinite_inertia, r_recover_motion, r_results, p_result_max, p_margin); } -RID BulletPhysicsServer::soft_body_create(bool p_init_sleeping) { +RID BulletPhysicsServer3D::soft_body_create(bool p_init_sleeping) { SoftBodyBullet *body = bulletnew(SoftBodyBullet); body->set_collision_layer(1); body->set_collision_mask(1); - if (p_init_sleeping) + if (p_init_sleeping) { body->set_activation_state(false); + } CreateThenReturnRID(soft_body_owner, body); } -void BulletPhysicsServer::soft_body_update_visual_server(RID p_body, class SoftBodyVisualServerHandler *p_visual_server_handler) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_update_rendering_server(RID p_body, class SoftBodyRenderingServerHandler *p_rendering_server_handler) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - body->update_visual_server(p_visual_server_handler); + body->update_rendering_server(p_rendering_server_handler); } -void BulletPhysicsServer::soft_body_set_space(RID p_body, RID p_space) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_space(RID p_body, RID p_space) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - SpaceBullet *space = NULL; + SpaceBullet *space = nullptr; if (p_space.is_valid()) { - space = space_owner.get(p_space); + space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); } - if (body->get_space() == space) + if (body->get_space() == space) { return; //pointles + } body->set_space(space); } -RID BulletPhysicsServer::soft_body_get_space(RID p_body) const { - SoftBodyBullet *body = soft_body_owner.get(p_body); +RID BulletPhysicsServer3D::soft_body_get_space(RID p_body) const { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, RID()); SpaceBullet *space = body->get_space(); - if (!space) + if (!space) { return RID(); + } return space->get_self(); } -void BulletPhysicsServer::soft_body_set_mesh(RID p_body, const REF &p_mesh) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_mesh(RID p_body, const REF &p_mesh) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_soft_mesh(p_mesh); } -void BulletPhysicsServer::soft_body_set_collision_layer(RID p_body, uint32_t p_layer) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_collision_layer(RID p_body, uint32_t p_layer) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_layer(p_layer); } -uint32_t BulletPhysicsServer::soft_body_get_collision_layer(RID p_body) const { - const SoftBodyBullet *body = soft_body_owner.get(p_body); +uint32_t BulletPhysicsServer3D::soft_body_get_collision_layer(RID p_body) const { + const SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_layer(); } -void BulletPhysicsServer::soft_body_set_collision_mask(RID p_body, uint32_t p_mask) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_collision_mask(RID p_body, uint32_t p_mask) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_mask(p_mask); } -uint32_t BulletPhysicsServer::soft_body_get_collision_mask(RID p_body) const { - const SoftBodyBullet *body = soft_body_owner.get(p_body); +uint32_t BulletPhysicsServer3D::soft_body_get_collision_mask(RID p_body) const { + const SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_mask(); } -void BulletPhysicsServer::soft_body_add_collision_exception(RID p_body, RID p_body_b) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_add_collision_exception(RID p_body, RID p_body_b) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - CollisionObjectBullet *other_body = rigid_body_owner.get(p_body_b); + CollisionObjectBullet *other_body = rigid_body_owner.getornull(p_body_b); if (!other_body) { - other_body = soft_body_owner.get(p_body_b); + other_body = soft_body_owner.getornull(p_body_b); } ERR_FAIL_COND(!other_body); body->add_collision_exception(other_body); } -void BulletPhysicsServer::soft_body_remove_collision_exception(RID p_body, RID p_body_b) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_remove_collision_exception(RID p_body, RID p_body_b) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - CollisionObjectBullet *other_body = rigid_body_owner.get(p_body_b); + CollisionObjectBullet *other_body = rigid_body_owner.getornull(p_body_b); if (!other_body) { - other_body = soft_body_owner.get(p_body_b); + other_body = soft_body_owner.getornull(p_body_b); } ERR_FAIL_COND(!other_body); body->remove_collision_exception(other_body); } -void BulletPhysicsServer::soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); for (int i = 0; i < body->get_exceptions().size(); i++) { p_exceptions->push_back(body->get_exceptions()[i]); } } -void BulletPhysicsServer::soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) { +void BulletPhysicsServer3D::soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) { // FIXME: Must be implemented. WARN_PRINT("soft_body_state is not implemented yet in Bullet backend."); } -Variant BulletPhysicsServer::soft_body_get_state(RID p_body, BodyState p_state) const { +Variant BulletPhysicsServer3D::soft_body_get_state(RID p_body, BodyState p_state) const { // FIXME: Must be implemented. WARN_PRINT("soft_body_state is not implemented yet in Bullet backend."); return Variant(); } -void BulletPhysicsServer::soft_body_set_transform(RID p_body, const Transform &p_transform) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_transform(RID p_body, const Transform &p_transform) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_soft_transform(p_transform); } -Vector3 BulletPhysicsServer::soft_body_get_vertex_position(RID p_body, int vertex_index) const { - const SoftBodyBullet *body = soft_body_owner.get(p_body); +Vector3 BulletPhysicsServer3D::soft_body_get_vertex_position(RID p_body, int vertex_index) const { + const SoftBodyBullet *body = soft_body_owner.getornull(p_body); Vector3 pos; ERR_FAIL_COND_V(!body, pos); @@ -1019,204 +1011,204 @@ Vector3 BulletPhysicsServer::soft_body_get_vertex_position(RID p_body, int verte return pos; } -void BulletPhysicsServer::soft_body_set_ray_pickable(RID p_body, bool p_enable) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_ray_pickable(RID p_body, bool p_enable) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_ray_pickable(p_enable); } -bool BulletPhysicsServer::soft_body_is_ray_pickable(RID p_body) const { - SoftBodyBullet *body = soft_body_owner.get(p_body); +bool BulletPhysicsServer3D::soft_body_is_ray_pickable(RID p_body) const { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->is_ray_pickable(); } -void BulletPhysicsServer::soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_simulation_precision(p_simulation_precision); } -int BulletPhysicsServer::soft_body_get_simulation_precision(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +int BulletPhysicsServer3D::soft_body_get_simulation_precision(RID p_body) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_simulation_precision(); } -void BulletPhysicsServer::soft_body_set_total_mass(RID p_body, real_t p_total_mass) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_total_mass(RID p_body, real_t p_total_mass) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_total_mass(p_total_mass); } -real_t BulletPhysicsServer::soft_body_get_total_mass(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +real_t BulletPhysicsServer3D::soft_body_get_total_mass(RID p_body) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_total_mass(); } -void BulletPhysicsServer::soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_linear_stiffness(p_stiffness); } -real_t BulletPhysicsServer::soft_body_get_linear_stiffness(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +real_t BulletPhysicsServer3D::soft_body_get_linear_stiffness(RID p_body) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_linear_stiffness(); } -void BulletPhysicsServer::soft_body_set_areaAngular_stiffness(RID p_body, real_t p_stiffness) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_areaAngular_stiffness(RID p_body, real_t p_stiffness) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_areaAngular_stiffness(p_stiffness); } -real_t BulletPhysicsServer::soft_body_get_areaAngular_stiffness(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +real_t BulletPhysicsServer3D::soft_body_get_areaAngular_stiffness(RID p_body) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_areaAngular_stiffness(); } -void BulletPhysicsServer::soft_body_set_volume_stiffness(RID p_body, real_t p_stiffness) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_volume_stiffness(RID p_body, real_t p_stiffness) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_volume_stiffness(p_stiffness); } -real_t BulletPhysicsServer::soft_body_get_volume_stiffness(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +real_t BulletPhysicsServer3D::soft_body_get_volume_stiffness(RID p_body) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_volume_stiffness(); } -void BulletPhysicsServer::soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_pressure_coefficient(p_pressure_coefficient); } -real_t BulletPhysicsServer::soft_body_get_pressure_coefficient(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +real_t BulletPhysicsServer3D::soft_body_get_pressure_coefficient(RID p_body) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_pressure_coefficient(); } -void BulletPhysicsServer::soft_body_set_pose_matching_coefficient(RID p_body, real_t p_pose_matching_coefficient) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_pose_matching_coefficient(RID p_body, real_t p_pose_matching_coefficient) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); return body->set_pose_matching_coefficient(p_pose_matching_coefficient); } -real_t BulletPhysicsServer::soft_body_get_pose_matching_coefficient(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +real_t BulletPhysicsServer3D::soft_body_get_pose_matching_coefficient(RID p_body) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_pose_matching_coefficient(); } -void BulletPhysicsServer::soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_damping_coefficient(p_damping_coefficient); } -real_t BulletPhysicsServer::soft_body_get_damping_coefficient(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +real_t BulletPhysicsServer3D::soft_body_get_damping_coefficient(RID p_body) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_damping_coefficient(); } -void BulletPhysicsServer::soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_drag_coefficient(p_drag_coefficient); } -real_t BulletPhysicsServer::soft_body_get_drag_coefficient(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +real_t BulletPhysicsServer3D::soft_body_get_drag_coefficient(RID p_body) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_drag_coefficient(); } -void BulletPhysicsServer::soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_node_position(p_point_index, p_global_position); } -Vector3 BulletPhysicsServer::soft_body_get_point_global_position(RID p_body, int p_point_index) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +Vector3 BulletPhysicsServer3D::soft_body_get_point_global_position(RID p_body, int p_point_index) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Vector3(0., 0., 0.)); Vector3 pos; body->get_node_position(p_point_index, pos); return pos; } -Vector3 BulletPhysicsServer::soft_body_get_point_offset(RID p_body, int p_point_index) const { - SoftBodyBullet *body = soft_body_owner.get(p_body); +Vector3 BulletPhysicsServer3D::soft_body_get_point_offset(RID p_body, int p_point_index) const { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Vector3()); Vector3 res; body->get_node_offset(p_point_index, res); return res; } -void BulletPhysicsServer::soft_body_remove_all_pinned_points(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_remove_all_pinned_points(RID p_body) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->reset_all_node_mass(); } -void BulletPhysicsServer::soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +void BulletPhysicsServer3D::soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_node_mass(p_point_index, p_pin ? 0 : 1); } -bool BulletPhysicsServer::soft_body_is_point_pinned(RID p_body, int p_point_index) { - SoftBodyBullet *body = soft_body_owner.get(p_body); +bool BulletPhysicsServer3D::soft_body_is_point_pinned(RID p_body, int p_point_index) { + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_node_mass(p_point_index); } -PhysicsServer::JointType BulletPhysicsServer::joint_get_type(RID p_joint) const { - JointBullet *joint = joint_owner.get(p_joint); +PhysicsServer3D::JointType BulletPhysicsServer3D::joint_get_type(RID p_joint) const { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, JOINT_PIN); return joint->get_type(); } -void BulletPhysicsServer::joint_set_solver_priority(RID p_joint, int p_priority) { +void BulletPhysicsServer3D::joint_set_solver_priority(RID p_joint, int p_priority) { // Joint priority not supported by bullet } -int BulletPhysicsServer::joint_get_solver_priority(RID p_joint) const { +int BulletPhysicsServer3D::joint_get_solver_priority(RID p_joint) const { // Joint priority not supported by bullet return 0; } -void BulletPhysicsServer::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) { - JointBullet *joint = joint_owner.get(p_joint); +void BulletPhysicsServer3D::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); joint->disable_collisions_between_bodies(p_disable); } -bool BulletPhysicsServer::joint_is_disabled_collisions_between_bodies(RID p_joint) const { - JointBullet *joint(joint_owner.get(p_joint)); +bool BulletPhysicsServer3D::joint_is_disabled_collisions_between_bodies(RID p_joint) const { + JointBullet *joint(joint_owner.getornull(p_joint)); ERR_FAIL_COND_V(!joint, false); return joint->is_disabled_collisions_between_bodies(); } -RID BulletPhysicsServer::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); +RID BulletPhysicsServer3D::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) { + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); - RigidBodyBullet *body_B = NULL; + RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1229,62 +1221,62 @@ RID BulletPhysicsServer::joint_create_pin(RID p_body_A, const Vector3 &p_local_A CreateThenReturnRID(joint_owner, joint); } -void BulletPhysicsServer::pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value) { - JointBullet *joint = joint_owner.get(p_joint); +void BulletPhysicsServer3D::pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); pin_joint->set_param(p_param, p_value); } -float BulletPhysicsServer::pin_joint_get_param(RID p_joint, PinJointParam p_param) const { - JointBullet *joint = joint_owner.get(p_joint); +float BulletPhysicsServer3D::pin_joint_get_param(RID p_joint, PinJointParam p_param) const { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, 0); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); return pin_joint->get_param(p_param); } -void BulletPhysicsServer::pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) { - JointBullet *joint = joint_owner.get(p_joint); +void BulletPhysicsServer3D::pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); pin_joint->setPivotInA(p_A); } -Vector3 BulletPhysicsServer::pin_joint_get_local_a(RID p_joint) const { - JointBullet *joint = joint_owner.get(p_joint); +Vector3 BulletPhysicsServer3D::pin_joint_get_local_a(RID p_joint) const { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, Vector3()); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3()); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); return pin_joint->getPivotInA(); } -void BulletPhysicsServer::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) { - JointBullet *joint = joint_owner.get(p_joint); +void BulletPhysicsServer3D::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); pin_joint->setPivotInB(p_B); } -Vector3 BulletPhysicsServer::pin_joint_get_local_b(RID p_joint) const { - JointBullet *joint = joint_owner.get(p_joint); +Vector3 BulletPhysicsServer3D::pin_joint_get_local_b(RID p_joint) const { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, Vector3()); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3()); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); return pin_joint->getPivotInB(); } -RID BulletPhysicsServer::joint_create_hinge(RID p_body_A, const Transform &p_hinge_A, RID p_body_B, const Transform &p_hinge_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); +RID BulletPhysicsServer3D::joint_create_hinge(RID p_body_A, const Transform &p_hinge_A, RID p_body_B, const Transform &p_hinge_B) { + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); - RigidBodyBullet *body_B = NULL; + RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1297,14 +1289,14 @@ RID BulletPhysicsServer::joint_create_hinge(RID p_body_A, const Transform &p_hin CreateThenReturnRID(joint_owner, joint); } -RID BulletPhysicsServer::joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); +RID BulletPhysicsServer3D::joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) { + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); - RigidBodyBullet *body_B = NULL; + RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1317,46 +1309,46 @@ RID BulletPhysicsServer::joint_create_hinge_simple(RID p_body_A, const Vector3 & CreateThenReturnRID(joint_owner, joint); } -void BulletPhysicsServer::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, float p_value) { - JointBullet *joint = joint_owner.get(p_joint); +void BulletPhysicsServer3D::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, float p_value) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_HINGE); HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint); hinge_joint->set_param(p_param, p_value); } -float BulletPhysicsServer::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const { - JointBullet *joint = joint_owner.get(p_joint); +float BulletPhysicsServer3D::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, 0); HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint); return hinge_joint->get_param(p_param); } -void BulletPhysicsServer::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) { - JointBullet *joint = joint_owner.get(p_joint); +void BulletPhysicsServer3D::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_HINGE); HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint); hinge_joint->set_flag(p_flag, p_value); } -bool BulletPhysicsServer::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const { - JointBullet *joint = joint_owner.get(p_joint); +bool BulletPhysicsServer3D::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, false); ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, false); HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint); return hinge_joint->get_flag(p_flag); } -RID BulletPhysicsServer::joint_create_slider(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); +RID BulletPhysicsServer3D::joint_create_slider(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); - RigidBodyBullet *body_B = NULL; + RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1369,30 +1361,30 @@ RID BulletPhysicsServer::joint_create_slider(RID p_body_A, const Transform &p_lo CreateThenReturnRID(joint_owner, joint); } -void BulletPhysicsServer::slider_joint_set_param(RID p_joint, SliderJointParam p_param, float p_value) { - JointBullet *joint = joint_owner.get(p_joint); +void BulletPhysicsServer3D::slider_joint_set_param(RID p_joint, SliderJointParam p_param, float p_value) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_SLIDER); SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint); slider_joint->set_param(p_param, p_value); } -float BulletPhysicsServer::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const { - JointBullet *joint = joint_owner.get(p_joint); +float BulletPhysicsServer3D::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_SLIDER, 0); SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint); return slider_joint->get_param(p_param); } -RID BulletPhysicsServer::joint_create_cone_twist(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); +RID BulletPhysicsServer3D::joint_create_cone_twist(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); - RigidBodyBullet *body_B = NULL; + RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1403,30 +1395,30 @@ RID BulletPhysicsServer::joint_create_cone_twist(RID p_body_A, const Transform & CreateThenReturnRID(joint_owner, joint); } -void BulletPhysicsServer::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, float p_value) { - JointBullet *joint = joint_owner.get(p_joint); +void BulletPhysicsServer3D::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, float p_value) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_CONE_TWIST); ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint); coneTwist_joint->set_param(p_param, p_value); } -float BulletPhysicsServer::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const { - JointBullet *joint = joint_owner.get(p_joint); +float BulletPhysicsServer3D::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0.); ERR_FAIL_COND_V(joint->get_type() != JOINT_CONE_TWIST, 0.); ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint); return coneTwist_joint->get_param(p_param); } -RID BulletPhysicsServer::joint_create_generic_6dof(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); +RID BulletPhysicsServer3D::joint_create_generic_6dof(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); - RigidBodyBullet *body_B = NULL; + RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1439,58 +1431,57 @@ RID BulletPhysicsServer::joint_create_generic_6dof(RID p_body_A, const Transform CreateThenReturnRID(joint_owner, joint); } -void BulletPhysicsServer::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, float p_value) { - JointBullet *joint = joint_owner.get(p_joint); +void BulletPhysicsServer3D::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, float p_value) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_6DOF); Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint); generic_6dof_joint->set_param(p_axis, p_param, p_value); } -float BulletPhysicsServer::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) { - JointBullet *joint = joint_owner.get(p_joint); +float BulletPhysicsServer3D::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0); Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint); return generic_6dof_joint->get_param(p_axis, p_param); } -void BulletPhysicsServer::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) { - JointBullet *joint = joint_owner.get(p_joint); +void BulletPhysicsServer3D::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_6DOF); Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint); generic_6dof_joint->set_flag(p_axis, p_flag, p_enable); } -bool BulletPhysicsServer::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) { - JointBullet *joint = joint_owner.get(p_joint); +bool BulletPhysicsServer3D::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, false); ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, false); Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint); return generic_6dof_joint->get_flag(p_axis, p_flag); } -void BulletPhysicsServer::generic_6dof_joint_set_precision(RID p_joint, int p_precision) { - JointBullet *joint = joint_owner.get(p_joint); +void BulletPhysicsServer3D::generic_6dof_joint_set_precision(RID p_joint, int p_precision) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_6DOF); Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint); generic_6dof_joint->set_precision(p_precision); } -int BulletPhysicsServer::generic_6dof_joint_get_precision(RID p_joint) { - JointBullet *joint = joint_owner.get(p_joint); +int BulletPhysicsServer3D::generic_6dof_joint_get_precision(RID p_joint) { + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0); Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint); return generic_6dof_joint->get_precision(); } -void BulletPhysicsServer::free(RID p_rid) { +void BulletPhysicsServer3D::free(RID p_rid) { if (shape_owner.owns(p_rid)) { - - ShapeBullet *shape = shape_owner.get(p_rid); + ShapeBullet *shape = shape_owner.getornull(p_rid); // Notify the shape is configured for (Map<ShapeOwnerBullet *, int>::Element *element = shape->get_owners().front(); element; element = element->next()) { @@ -1500,10 +1491,9 @@ void BulletPhysicsServer::free(RID p_rid) { shape_owner.free(p_rid); bulletdelete(shape); } else if (rigid_body_owner.owns(p_rid)) { + RigidBodyBullet *body = rigid_body_owner.getornull(p_rid); - RigidBodyBullet *body = rigid_body_owner.get(p_rid); - - body->set_space(NULL); + body->set_space(nullptr); body->remove_all_shapes(true, true); @@ -1511,19 +1501,17 @@ void BulletPhysicsServer::free(RID p_rid) { bulletdelete(body); } else if (soft_body_owner.owns(p_rid)) { + SoftBodyBullet *body = soft_body_owner.getornull(p_rid); - SoftBodyBullet *body = soft_body_owner.get(p_rid); - - body->set_space(NULL); + body->set_space(nullptr); soft_body_owner.free(p_rid); bulletdelete(body); } else if (area_owner.owns(p_rid)) { + AreaBullet *area = area_owner.getornull(p_rid); - AreaBullet *area = area_owner.get(p_rid); - - area->set_space(NULL); + area->set_space(nullptr); area->remove_all_shapes(true, true); @@ -1531,15 +1519,13 @@ void BulletPhysicsServer::free(RID p_rid) { bulletdelete(area); } else if (joint_owner.owns(p_rid)) { - - JointBullet *joint = joint_owner.get(p_rid); + JointBullet *joint = joint_owner.getornull(p_rid); joint->destroy_internal_constraint(); joint_owner.free(p_rid); bulletdelete(joint); } else if (space_owner.owns(p_rid)) { - - SpaceBullet *space = space_owner.get(p_rid); + SpaceBullet *space = space_owner.getornull(p_rid); space->remove_all_collision_objects(); @@ -1547,42 +1533,58 @@ void BulletPhysicsServer::free(RID p_rid) { space_owner.free(p_rid); bulletdelete(space); } else { - ERR_FAIL_MSG("Invalid ID."); } } -void BulletPhysicsServer::init() { - BulletPhysicsDirectBodyState::initSingleton(); +void BulletPhysicsServer3D::init() { + BulletPhysicsDirectBodyState3D::initSingleton(); } -void BulletPhysicsServer::step(float p_deltaTime) { - if (!active) +void BulletPhysicsServer3D::step(float p_deltaTime) { + if (!active) { return; + } - BulletPhysicsDirectBodyState::singleton_setDeltaTime(p_deltaTime); + BulletPhysicsDirectBodyState3D::singleton_setDeltaTime(p_deltaTime); for (int i = 0; i < active_spaces_count; ++i) { - active_spaces[i]->step(p_deltaTime); } } -void BulletPhysicsServer::sync() { +void BulletPhysicsServer3D::sync() { } -void BulletPhysicsServer::flush_queries() { +void BulletPhysicsServer3D::flush_queries() { + if (!active) { + return; + } + + for (int i = 0; i < active_spaces_count; ++i) { + active_spaces[i]->flush_queries(); + } } -void BulletPhysicsServer::finish() { - BulletPhysicsDirectBodyState::destroySingleton(); +void BulletPhysicsServer3D::finish() { + BulletPhysicsDirectBodyState3D::destroySingleton(); } -int BulletPhysicsServer::get_process_info(ProcessInfo p_info) { +int BulletPhysicsServer3D::get_process_info(ProcessInfo p_info) { return 0; } -CollisionObjectBullet *BulletPhysicsServer::get_collisin_object(RID p_object) const { +SpaceBullet *BulletPhysicsServer3D::get_space(RID p_rid) const { + ERR_FAIL_COND_V_MSG(space_owner.owns(p_rid) == false, nullptr, "The RID is not valid."); + return space_owner.getornull(p_rid); +} + +ShapeBullet *BulletPhysicsServer3D::get_shape(RID p_rid) const { + ERR_FAIL_COND_V_MSG(shape_owner.owns(p_rid) == false, nullptr, "The RID is not valid."); + return shape_owner.getornull(p_rid); +} + +CollisionObjectBullet *BulletPhysicsServer3D::get_collision_object(RID p_object) const { if (rigid_body_owner.owns(p_object)) { return rigid_body_owner.getornull(p_object); } @@ -1592,15 +1594,20 @@ CollisionObjectBullet *BulletPhysicsServer::get_collisin_object(RID p_object) co if (soft_body_owner.owns(p_object)) { return soft_body_owner.getornull(p_object); } - return NULL; + ERR_FAIL_V_MSG(nullptr, "The RID is no valid."); } -RigidCollisionObjectBullet *BulletPhysicsServer::get_rigid_collisin_object(RID p_object) const { +RigidCollisionObjectBullet *BulletPhysicsServer3D::get_rigid_collision_object(RID p_object) const { if (rigid_body_owner.owns(p_object)) { return rigid_body_owner.getornull(p_object); } if (area_owner.owns(p_object)) { return area_owner.getornull(p_object); } - return NULL; + ERR_FAIL_V_MSG(nullptr, "The RID is no valid."); +} + +JointBullet *BulletPhysicsServer3D::get_joint(RID p_rid) const { + ERR_FAIL_COND_V_MSG(joint_owner.owns(p_rid) == false, nullptr, "The RID is not valid."); + return joint_owner.getornull(p_rid); } diff --git a/modules/bullet/bullet_physics_server.h b/modules/bullet/bullet_physics_server.h index 4a3b4a2edc..eb95120f74 100644 --- a/modules/bullet/bullet_physics_server.h +++ b/modules/bullet/bullet_physics_server.h @@ -33,9 +33,10 @@ #include "area_bullet.h" #include "core/rid.h" +#include "core/rid_owner.h" #include "joint_bullet.h" #include "rigid_body_bullet.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" #include "shape_bullet.h" #include "soft_body_bullet.h" #include "space_bullet.h" @@ -44,78 +45,78 @@ @author AndreaCatania */ -class BulletPhysicsServer : public PhysicsServer { - GDCLASS(BulletPhysicsServer, PhysicsServer); +class BulletPhysicsServer3D : public PhysicsServer3D { + GDCLASS(BulletPhysicsServer3D, PhysicsServer3D); friend class BulletPhysicsDirectSpaceState; - bool active; - char active_spaces_count; - Vector<SpaceBullet *> active_spaces; + bool active = true; + char active_spaces_count = 0; + LocalVector<SpaceBullet *> active_spaces; - mutable RID_Owner<SpaceBullet> space_owner; - mutable RID_Owner<ShapeBullet> shape_owner; - mutable RID_Owner<AreaBullet> area_owner; - mutable RID_Owner<RigidBodyBullet> rigid_body_owner; - mutable RID_Owner<SoftBodyBullet> soft_body_owner; - mutable RID_Owner<JointBullet> joint_owner; + mutable RID_PtrOwner<SpaceBullet> space_owner; + mutable RID_PtrOwner<ShapeBullet> shape_owner; + mutable RID_PtrOwner<AreaBullet> area_owner; + mutable RID_PtrOwner<RigidBodyBullet> rigid_body_owner; + mutable RID_PtrOwner<SoftBodyBullet> soft_body_owner; + mutable RID_PtrOwner<JointBullet> joint_owner; protected: static void _bind_methods(); public: - BulletPhysicsServer(); - ~BulletPhysicsServer(); + BulletPhysicsServer3D(); + ~BulletPhysicsServer3D(); - _FORCE_INLINE_ RID_Owner<SpaceBullet> *get_space_owner() { + _FORCE_INLINE_ RID_PtrOwner<SpaceBullet> *get_space_owner() { return &space_owner; } - _FORCE_INLINE_ RID_Owner<ShapeBullet> *get_shape_owner() { + _FORCE_INLINE_ RID_PtrOwner<ShapeBullet> *get_shape_owner() { return &shape_owner; } - _FORCE_INLINE_ RID_Owner<AreaBullet> *get_area_owner() { + _FORCE_INLINE_ RID_PtrOwner<AreaBullet> *get_area_owner() { return &area_owner; } - _FORCE_INLINE_ RID_Owner<RigidBodyBullet> *get_rigid_body_owner() { + _FORCE_INLINE_ RID_PtrOwner<RigidBodyBullet> *get_rigid_body_owner() { return &rigid_body_owner; } - _FORCE_INLINE_ RID_Owner<SoftBodyBullet> *get_soft_body_owner() { + _FORCE_INLINE_ RID_PtrOwner<SoftBodyBullet> *get_soft_body_owner() { return &soft_body_owner; } - _FORCE_INLINE_ RID_Owner<JointBullet> *get_joint_owner() { + _FORCE_INLINE_ RID_PtrOwner<JointBullet> *get_joint_owner() { return &joint_owner; } /* SHAPE API */ - virtual RID shape_create(ShapeType p_shape); - virtual void shape_set_data(RID p_shape, const Variant &p_data); - virtual ShapeType shape_get_type(RID p_shape) const; - virtual Variant shape_get_data(RID p_shape) const; + virtual RID shape_create(ShapeType p_shape) override; + virtual void shape_set_data(RID p_shape, const Variant &p_data) override; + virtual ShapeType shape_get_type(RID p_shape) const override; + virtual Variant shape_get_data(RID p_shape) const override; - virtual void shape_set_margin(RID p_shape, real_t p_margin); - virtual real_t shape_get_margin(RID p_shape) const; + virtual void shape_set_margin(RID p_shape, real_t p_margin) override; + virtual real_t shape_get_margin(RID p_shape) const override; /// Not supported - virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias); + virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) override; /// Not supported - virtual real_t shape_get_custom_solver_bias(RID p_shape) const; + virtual real_t shape_get_custom_solver_bias(RID p_shape) const override; /* SPACE API */ - virtual RID space_create(); - virtual void space_set_active(RID p_space, bool p_active); - virtual bool space_is_active(RID p_space) const; + virtual RID space_create() override; + virtual void space_set_active(RID p_space, bool p_active) override; + virtual bool space_is_active(RID p_space) const override; /// Not supported - virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value); + virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) override; /// Not supported - virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const; + virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const override; - virtual PhysicsDirectSpaceState *space_get_direct_state(RID p_space); + virtual PhysicsDirectSpaceState3D *space_get_direct_state(RID p_space) override; - virtual void space_set_debug_contacts(RID p_space, int p_max_contacts); - virtual Vector<Vector3> space_get_contacts(RID p_space) const; - virtual int space_get_contact_count(RID p_space) const; + virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) override; + virtual Vector<Vector3> space_get_contacts(RID p_space) const override; + virtual int space_get_contact_count(RID p_space) const override; /* AREA API */ @@ -124,291 +125,291 @@ public: /// The API area_set_param is a bit hacky, and allow Godot to set some parameters on Bullet's world, a different use print a warning to console. /// All other APIs returns a warning message if used - virtual RID area_create(); + virtual RID area_create() override; - virtual void area_set_space(RID p_area, RID p_space); + virtual void area_set_space(RID p_area, RID p_space) override; - virtual RID area_get_space(RID p_area) const; + virtual RID area_get_space(RID p_area) const override; - virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode); - virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const; + virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) override; + virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const override; - virtual void area_add_shape(RID p_area, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false); - virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape); - virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform); - virtual int area_get_shape_count(RID p_area) const; - virtual RID area_get_shape(RID p_area, int p_shape_idx) const; - virtual Transform area_get_shape_transform(RID p_area, int p_shape_idx) const; - virtual void area_remove_shape(RID p_area, int p_shape_idx); - virtual void area_clear_shapes(RID p_area); - virtual void area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled); - virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id); - virtual ObjectID area_get_object_instance_id(RID p_area) const; + virtual void area_add_shape(RID p_area, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false) override; + virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) override; + virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) override; + virtual int area_get_shape_count(RID p_area) const override; + virtual RID area_get_shape(RID p_area, int p_shape_idx) const override; + virtual Transform area_get_shape_transform(RID p_area, int p_shape_idx) const override; + virtual void area_remove_shape(RID p_area, int p_shape_idx) override; + virtual void area_clear_shapes(RID p_area) override; + virtual void area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) override; + virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id) override; + virtual ObjectID area_get_object_instance_id(RID p_area) const override; /// If you pass as p_area the SpaceBullet you can set some parameters as specified below /// AREA_PARAM_GRAVITY /// AREA_PARAM_GRAVITY_VECTOR /// Otherwise you can set area parameters - virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value); - virtual Variant area_get_param(RID p_area, AreaParameter p_param) const; + virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) override; + virtual Variant area_get_param(RID p_area, AreaParameter p_param) const override; - virtual void area_set_transform(RID p_area, const Transform &p_transform); - virtual Transform area_get_transform(RID p_area) const; + virtual void area_set_transform(RID p_area, const Transform &p_transform) override; + virtual Transform area_get_transform(RID p_area) const override; - virtual void area_set_collision_mask(RID p_area, uint32_t p_mask); - virtual void area_set_collision_layer(RID p_area, uint32_t p_layer); + virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) override; + virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) override; - virtual void area_set_monitorable(RID p_area, bool p_monitorable); - virtual void area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method); - virtual void area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method); - virtual void area_set_ray_pickable(RID p_area, bool p_enable); - virtual bool area_is_ray_pickable(RID p_area) const; + virtual void area_set_monitorable(RID p_area, bool p_monitorable) override; + virtual void area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) override; + virtual void area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) override; + virtual void area_set_ray_pickable(RID p_area, bool p_enable) override; + virtual bool area_is_ray_pickable(RID p_area) const override; /* RIGID BODY API */ - virtual RID body_create(BodyMode p_mode = BODY_MODE_RIGID, bool p_init_sleeping = false); + virtual RID body_create(BodyMode p_mode = BODY_MODE_RIGID, bool p_init_sleeping = false) override; - virtual void body_set_space(RID p_body, RID p_space); - virtual RID body_get_space(RID p_body) const; + virtual void body_set_space(RID p_body, RID p_space) override; + virtual RID body_get_space(RID p_body) const override; - virtual void body_set_mode(RID p_body, BodyMode p_mode); - virtual BodyMode body_get_mode(RID p_body) const; + virtual void body_set_mode(RID p_body, BodyMode p_mode) override; + virtual BodyMode body_get_mode(RID p_body) const override; - virtual void body_add_shape(RID p_body, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false); + virtual void body_add_shape(RID p_body, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false) override; // Not supported, Please remove and add new shape - virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape); - virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform); + virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) override; + virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) override; - virtual int body_get_shape_count(RID p_body) const; - virtual RID body_get_shape(RID p_body, int p_shape_idx) const; - virtual Transform body_get_shape_transform(RID p_body, int p_shape_idx) const; + virtual int body_get_shape_count(RID p_body) const override; + virtual RID body_get_shape(RID p_body, int p_shape_idx) const override; + virtual Transform body_get_shape_transform(RID p_body, int p_shape_idx) const override; - virtual void body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled); + virtual void body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) override; - virtual void body_remove_shape(RID p_body, int p_shape_idx); - virtual void body_clear_shapes(RID p_body); + virtual void body_remove_shape(RID p_body, int p_shape_idx) override; + virtual void body_clear_shapes(RID p_body) override; // Used for Rigid and Soft Bodies - virtual void body_attach_object_instance_id(RID p_body, uint32_t p_id); - virtual uint32_t body_get_object_instance_id(RID p_body) const; + virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id) override; + virtual ObjectID body_get_object_instance_id(RID p_body) const override; - virtual void body_set_enable_continuous_collision_detection(RID p_body, bool p_enable); - virtual bool body_is_continuous_collision_detection_enabled(RID p_body) const; + virtual void body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) override; + virtual bool body_is_continuous_collision_detection_enabled(RID p_body) const override; - virtual void body_set_collision_layer(RID p_body, uint32_t p_layer); - virtual uint32_t body_get_collision_layer(RID p_body) const; + virtual void body_set_collision_layer(RID p_body, uint32_t p_layer) override; + virtual uint32_t body_get_collision_layer(RID p_body) const override; - virtual void body_set_collision_mask(RID p_body, uint32_t p_mask); - virtual uint32_t body_get_collision_mask(RID p_body) const; + virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) override; + virtual uint32_t body_get_collision_mask(RID p_body) const override; /// This is not supported by physics server - virtual void body_set_user_flags(RID p_body, uint32_t p_flags); + virtual void body_set_user_flags(RID p_body, uint32_t p_flags) override; /// This is not supported by physics server - virtual uint32_t body_get_user_flags(RID p_body) const; + virtual uint32_t body_get_user_flags(RID p_body) const override; - virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value); - virtual float body_get_param(RID p_body, BodyParameter p_param) const; + virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value) override; + virtual float body_get_param(RID p_body, BodyParameter p_param) const override; - virtual void body_set_kinematic_safe_margin(RID p_body, real_t p_margin); - virtual real_t body_get_kinematic_safe_margin(RID p_body) const; + virtual void body_set_kinematic_safe_margin(RID p_body, real_t p_margin) override; + virtual real_t body_get_kinematic_safe_margin(RID p_body) const override; - virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant); - virtual Variant body_get_state(RID p_body, BodyState p_state) const; + virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) override; + virtual Variant body_get_state(RID p_body, BodyState p_state) const override; - virtual void body_set_applied_force(RID p_body, const Vector3 &p_force); - virtual Vector3 body_get_applied_force(RID p_body) const; + virtual void body_set_applied_force(RID p_body, const Vector3 &p_force) override; + virtual Vector3 body_get_applied_force(RID p_body) const override; - virtual void body_set_applied_torque(RID p_body, const Vector3 &p_torque); - virtual Vector3 body_get_applied_torque(RID p_body) const; + virtual void body_set_applied_torque(RID p_body, const Vector3 &p_torque) override; + virtual Vector3 body_get_applied_torque(RID p_body) const override; - virtual void body_add_central_force(RID p_body, const Vector3 &p_force); - virtual void body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_pos); - virtual void body_add_torque(RID p_body, const Vector3 &p_torque); + virtual void body_add_central_force(RID p_body, const Vector3 &p_force) override; + virtual void body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3()) override; + virtual void body_add_torque(RID p_body, const Vector3 &p_torque) override; - virtual void body_apply_central_impulse(RID p_body, const Vector3 &p_impulse); - virtual void body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse); - virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse); - virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity); + virtual void body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) override; + virtual void body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) override; + virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) override; + virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) override; - virtual void body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock); - virtual bool body_is_axis_locked(RID p_body, BodyAxis p_axis) const; + virtual void body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) override; + virtual bool body_is_axis_locked(RID p_body, BodyAxis p_axis) const override; - virtual void body_add_collision_exception(RID p_body, RID p_body_b); - virtual void body_remove_collision_exception(RID p_body, RID p_body_b); - virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions); + virtual void body_add_collision_exception(RID p_body, RID p_body_b) override; + virtual void body_remove_collision_exception(RID p_body, RID p_body_b) override; + virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) override; - virtual void body_set_max_contacts_reported(RID p_body, int p_contacts); - virtual int body_get_max_contacts_reported(RID p_body) const; + virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) override; + virtual int body_get_max_contacts_reported(RID p_body) const override; - virtual void body_set_contacts_reported_depth_threshold(RID p_body, float p_threshold); - virtual float body_get_contacts_reported_depth_threshold(RID p_body) const; + virtual void body_set_contacts_reported_depth_threshold(RID p_body, float p_threshold) override; + virtual float body_get_contacts_reported_depth_threshold(RID p_body) const override; - virtual void body_set_omit_force_integration(RID p_body, bool p_omit); - virtual bool body_is_omitting_force_integration(RID p_body) const; + virtual void body_set_omit_force_integration(RID p_body, bool p_omit) override; + virtual bool body_is_omitting_force_integration(RID p_body) const override; - virtual void body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata = Variant()); + virtual void body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata = Variant()) override; - virtual void body_set_ray_pickable(RID p_body, bool p_enable); - virtual bool body_is_ray_pickable(RID p_body) const; + virtual void body_set_ray_pickable(RID p_body, bool p_enable) override; + virtual bool body_is_ray_pickable(RID p_body) const override; // this function only works on physics process, errors and returns null otherwise - virtual PhysicsDirectBodyState *body_get_direct_state(RID p_body); + virtual PhysicsDirectBodyState3D *body_get_direct_state(RID p_body) override; - virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true); - virtual int body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001); + virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) override; + virtual int body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001) override; /* SOFT BODY API */ - virtual RID soft_body_create(bool p_init_sleeping = false); + virtual RID soft_body_create(bool p_init_sleeping = false) override; - virtual void soft_body_update_visual_server(RID p_body, class SoftBodyVisualServerHandler *p_visual_server_handler); + virtual void soft_body_update_rendering_server(RID p_body, class SoftBodyRenderingServerHandler *p_rendering_server_handler) override; - virtual void soft_body_set_space(RID p_body, RID p_space); - virtual RID soft_body_get_space(RID p_body) const; + virtual void soft_body_set_space(RID p_body, RID p_space) override; + virtual RID soft_body_get_space(RID p_body) const override; - virtual void soft_body_set_mesh(RID p_body, const REF &p_mesh); + virtual void soft_body_set_mesh(RID p_body, const REF &p_mesh) override; - virtual void soft_body_set_collision_layer(RID p_body, uint32_t p_layer); - virtual uint32_t soft_body_get_collision_layer(RID p_body) const; + virtual void soft_body_set_collision_layer(RID p_body, uint32_t p_layer) override; + virtual uint32_t soft_body_get_collision_layer(RID p_body) const override; - virtual void soft_body_set_collision_mask(RID p_body, uint32_t p_mask); - virtual uint32_t soft_body_get_collision_mask(RID p_body) const; + virtual void soft_body_set_collision_mask(RID p_body, uint32_t p_mask) override; + virtual uint32_t soft_body_get_collision_mask(RID p_body) const override; - virtual void soft_body_add_collision_exception(RID p_body, RID p_body_b); - virtual void soft_body_remove_collision_exception(RID p_body, RID p_body_b); - virtual void soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions); + virtual void soft_body_add_collision_exception(RID p_body, RID p_body_b) override; + virtual void soft_body_remove_collision_exception(RID p_body, RID p_body_b) override; + virtual void soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) override; - virtual void soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant); - virtual Variant soft_body_get_state(RID p_body, BodyState p_state) const; + virtual void soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) override; + virtual Variant soft_body_get_state(RID p_body, BodyState p_state) const override; /// Special function. This function has bad performance - virtual void soft_body_set_transform(RID p_body, const Transform &p_transform); - virtual Vector3 soft_body_get_vertex_position(RID p_body, int vertex_index) const; + virtual void soft_body_set_transform(RID p_body, const Transform &p_transform) override; + virtual Vector3 soft_body_get_vertex_position(RID p_body, int vertex_index) const override; - virtual void soft_body_set_ray_pickable(RID p_body, bool p_enable); - virtual bool soft_body_is_ray_pickable(RID p_body) const; + virtual void soft_body_set_ray_pickable(RID p_body, bool p_enable) override; + virtual bool soft_body_is_ray_pickable(RID p_body) const override; - virtual void soft_body_set_simulation_precision(RID p_body, int p_simulation_precision); - virtual int soft_body_get_simulation_precision(RID p_body); + virtual void soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) override; + virtual int soft_body_get_simulation_precision(RID p_body) override; - virtual void soft_body_set_total_mass(RID p_body, real_t p_total_mass); - virtual real_t soft_body_get_total_mass(RID p_body); + virtual void soft_body_set_total_mass(RID p_body, real_t p_total_mass) override; + virtual real_t soft_body_get_total_mass(RID p_body) override; - virtual void soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness); - virtual real_t soft_body_get_linear_stiffness(RID p_body); + virtual void soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) override; + virtual real_t soft_body_get_linear_stiffness(RID p_body) override; - virtual void soft_body_set_areaAngular_stiffness(RID p_body, real_t p_stiffness); - virtual real_t soft_body_get_areaAngular_stiffness(RID p_body); + virtual void soft_body_set_areaAngular_stiffness(RID p_body, real_t p_stiffness) override; + virtual real_t soft_body_get_areaAngular_stiffness(RID p_body) override; - virtual void soft_body_set_volume_stiffness(RID p_body, real_t p_stiffness); - virtual real_t soft_body_get_volume_stiffness(RID p_body); + virtual void soft_body_set_volume_stiffness(RID p_body, real_t p_stiffness) override; + virtual real_t soft_body_get_volume_stiffness(RID p_body) override; - virtual void soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient); - virtual real_t soft_body_get_pressure_coefficient(RID p_body); + virtual void soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) override; + virtual real_t soft_body_get_pressure_coefficient(RID p_body) override; - virtual void soft_body_set_pose_matching_coefficient(RID p_body, real_t p_pose_matching_coefficient); - virtual real_t soft_body_get_pose_matching_coefficient(RID p_body); + virtual void soft_body_set_pose_matching_coefficient(RID p_body, real_t p_pose_matching_coefficient) override; + virtual real_t soft_body_get_pose_matching_coefficient(RID p_body) override; - virtual void soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient); - virtual real_t soft_body_get_damping_coefficient(RID p_body); + virtual void soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) override; + virtual real_t soft_body_get_damping_coefficient(RID p_body) override; - virtual void soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient); - virtual real_t soft_body_get_drag_coefficient(RID p_body); + virtual void soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) override; + virtual real_t soft_body_get_drag_coefficient(RID p_body) override; - virtual void soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position); - virtual Vector3 soft_body_get_point_global_position(RID p_body, int p_point_index); + virtual void soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) override; + virtual Vector3 soft_body_get_point_global_position(RID p_body, int p_point_index) override; - virtual Vector3 soft_body_get_point_offset(RID p_body, int p_point_index) const; + virtual Vector3 soft_body_get_point_offset(RID p_body, int p_point_index) const override; - virtual void soft_body_remove_all_pinned_points(RID p_body); - virtual void soft_body_pin_point(RID p_body, int p_point_index, bool p_pin); - virtual bool soft_body_is_point_pinned(RID p_body, int p_point_index); + virtual void soft_body_remove_all_pinned_points(RID p_body) override; + virtual void soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) override; + virtual bool soft_body_is_point_pinned(RID p_body, int p_point_index) override; /* JOINT API */ - virtual JointType joint_get_type(RID p_joint) const; + virtual JointType joint_get_type(RID p_joint) const override; - virtual void joint_set_solver_priority(RID p_joint, int p_priority); - virtual int joint_get_solver_priority(RID p_joint) const; + virtual void joint_set_solver_priority(RID p_joint, int p_priority) override; + virtual int joint_get_solver_priority(RID p_joint) const override; - virtual void joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable); - virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const; + virtual void joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) override; + virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const override; - virtual RID joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B); + virtual RID joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) override; - virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value); - virtual float pin_joint_get_param(RID p_joint, PinJointParam p_param) const; + virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value) override; + virtual float pin_joint_get_param(RID p_joint, PinJointParam p_param) const override; - virtual void pin_joint_set_local_a(RID p_joint, const Vector3 &p_A); - virtual Vector3 pin_joint_get_local_a(RID p_joint) const; + virtual void pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) override; + virtual Vector3 pin_joint_get_local_a(RID p_joint) const override; - virtual void pin_joint_set_local_b(RID p_joint, const Vector3 &p_B); - virtual Vector3 pin_joint_get_local_b(RID p_joint) const; + virtual void pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) override; + virtual Vector3 pin_joint_get_local_b(RID p_joint) const override; - virtual RID joint_create_hinge(RID p_body_A, const Transform &p_hinge_A, RID p_body_B, const Transform &p_hinge_B); - virtual RID joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B); + virtual RID joint_create_hinge(RID p_body_A, const Transform &p_hinge_A, RID p_body_B, const Transform &p_hinge_B) override; + virtual RID joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) override; - virtual void hinge_joint_set_param(RID p_joint, HingeJointParam p_param, float p_value); - virtual float hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const; + virtual void hinge_joint_set_param(RID p_joint, HingeJointParam p_param, float p_value) override; + virtual float hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const override; - virtual void hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value); - virtual bool hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const; + virtual void hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) override; + virtual bool hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const override; /// Reference frame is A - virtual RID joint_create_slider(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B); + virtual RID joint_create_slider(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) override; - virtual void slider_joint_set_param(RID p_joint, SliderJointParam p_param, float p_value); - virtual float slider_joint_get_param(RID p_joint, SliderJointParam p_param) const; + virtual void slider_joint_set_param(RID p_joint, SliderJointParam p_param, float p_value) override; + virtual float slider_joint_get_param(RID p_joint, SliderJointParam p_param) const override; /// Reference frame is A - virtual RID joint_create_cone_twist(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B); + virtual RID joint_create_cone_twist(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) override; - virtual void cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, float p_value); - virtual float cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const; + virtual void cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, float p_value) override; + virtual float cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const override; /// Reference frame is A - virtual RID joint_create_generic_6dof(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B); + virtual RID joint_create_generic_6dof(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) override; - virtual void generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, float p_value); - virtual float generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param); + virtual void generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, float p_value) override; + virtual float generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) override; - virtual void generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable); - virtual bool generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag); + virtual void generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) override; + virtual bool generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) override; - virtual void generic_6dof_joint_set_precision(RID p_joint, int precision); - virtual int generic_6dof_joint_get_precision(RID p_joint); + virtual void generic_6dof_joint_set_precision(RID p_joint, int precision) override; + virtual int generic_6dof_joint_get_precision(RID p_joint) override; /* MISC */ - virtual void free(RID p_rid); + virtual void free(RID p_rid) override; - virtual void set_active(bool p_active) { + virtual void set_active(bool p_active) override { active = p_active; } static bool singleton_isActive() { - return static_cast<BulletPhysicsServer *>(get_singleton())->active; + return static_cast<BulletPhysicsServer3D *>(get_singleton())->active; } bool isActive() { return active; } - virtual void init(); - virtual void step(float p_deltaTime); - virtual void sync(); - virtual void flush_queries(); - virtual void finish(); + virtual void init() override; + virtual void step(float p_deltaTime) override; + virtual void sync() override; + virtual void flush_queries() override; + virtual void finish() override; - virtual bool is_flushing_queries() const { return false; } + virtual bool is_flushing_queries() const override { return false; } - virtual int get_process_info(ProcessInfo p_info); + virtual int get_process_info(ProcessInfo p_info) override; - CollisionObjectBullet *get_collisin_object(RID p_object) const; - RigidCollisionObjectBullet *get_rigid_collisin_object(RID p_object) const; - - /// Internal APIs -public: + SpaceBullet *get_space(RID p_rid) const; + ShapeBullet *get_shape(RID p_rid) const; + CollisionObjectBullet *get_collision_object(RID p_object) const; + RigidCollisionObjectBullet *get_rigid_collision_object(RID p_object) const; + JointBullet *get_joint(RID p_rid) const; }; #endif diff --git a/modules/bullet/bullet_types_converter.cpp b/modules/bullet/bullet_types_converter.cpp index c9493d8892..7ecad9b78a 100644 --- a/modules/bullet/bullet_types_converter.cpp +++ b/modules/bullet/bullet_types_converter.cpp @@ -95,12 +95,61 @@ void G_TO_B(Transform const &inVal, btTransform &outVal) { } void UNSCALE_BT_BASIS(btTransform &scaledBasis) { - btMatrix3x3 &m(scaledBasis.getBasis()); - btVector3 column0(m[0][0], m[1][0], m[2][0]); - btVector3 column1(m[0][1], m[1][1], m[2][1]); - btVector3 column2(m[0][2], m[1][2], m[2][2]); + btMatrix3x3 &basis(scaledBasis.getBasis()); + btVector3 column0 = basis.getColumn(0); + btVector3 column1 = basis.getColumn(1); + btVector3 column2 = basis.getColumn(2); + + // Check for zero scaling. + if (btFuzzyZero(column0[0])) { + if (btFuzzyZero(column1[1])) { + if (btFuzzyZero(column2[2])) { + // All dimensions are fuzzy zero. Create a default basis. + column0 = btVector3(1, 0, 0); + column1 = btVector3(0, 1, 0); + column2 = btVector3(0, 0, 1); + } else { // Column 2 scale not fuzzy zero. + // Create two vectors orthogonal to row 2. + // Ensure that a default basis is created if row 2 = <0, 0, 1> + column1 = btVector3(0, column2[2], -column2[1]); + column0 = column1.cross(column2); + } + } else { // Column 1 scale not fuzzy zero. + if (btFuzzyZero(column2[2])) { + // Create two vectors othogonal to column 1. + // Ensure that a default basis is created if column 1 = <0, 1, 0> + column0 = btVector3(column1[1], -column1[0], 0); + column2 = column0.cross(column1); + } else { // Column 1 and column 2 scales not fuzzy zero. + // Create column 0 orthogonal to column 1 and column 2. + column0 = column1.cross(column2); + } + } + } else { // Column 0 scale not fuzzy zero. + if (btFuzzyZero(column1[1])) { + if (btFuzzyZero(column2[2])) { + // Create two vectors orthogonal to column 0. + // Ensure that a default basis is created if column 0 = <1, 0, 0> + column2 = btVector3(-column0[2], 0, column0[0]); + column1 = column2.cross(column0); + } else { // Column 0 and column 2 scales not fuzzy zero. + // Create column 1 orthogonal to column 0 and column 2. + column1 = column2.cross(column0); + } + } else { // Column 0 and column 1 scales not fuzzy zero. + if (btFuzzyZero(column2[2])) { + // Create column 2 orthogonal to column 0 and column 1. + column2 = column0.cross(column1); + } + } + } + + // Normalize column0.normalize(); column1.normalize(); column2.normalize(); - m.setValue(column0[0], column1[0], column2[0], column0[1], column1[1], column2[1], column0[2], column1[2], column2[2]); + + basis.setValue(column0[0], column1[0], column2[0], + column0[1], column1[1], column2[1], + column0[2], column1[2], column2[2]); } diff --git a/modules/bullet/bullet_utilities.h b/modules/bullet/bullet_utilities.h index 968cb38ba2..a5e33d9829 100644 --- a/modules/bullet/bullet_utilities.h +++ b/modules/bullet/bullet_utilities.h @@ -41,6 +41,6 @@ #define bulletdelete(cl) \ { \ delete cl; \ - cl = NULL; \ + cl = nullptr; \ } #endif diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp index c916c65d2b..660e9afc5e 100644 --- a/modules/bullet/collision_object_bullet.cpp +++ b/modules/bullet/collision_object_bullet.cpp @@ -60,7 +60,7 @@ void CollisionObjectBullet::ShapeWrapper::set_transform(const btTransform &p_tra } btTransform CollisionObjectBullet::ShapeWrapper::get_adjusted_transform() const { - if (shape->get_type() == PhysicsServer::SHAPE_HEIGHTMAP) { + if (shape->get_type() == PhysicsServer3D::SHAPE_HEIGHTMAP) { const HeightMapShapeBullet *hm_shape = (const HeightMapShapeBullet *)shape; // should be safe to cast now btTransform adjusted_transform; @@ -79,28 +79,25 @@ btTransform CollisionObjectBullet::ShapeWrapper::get_adjusted_transform() const } void CollisionObjectBullet::ShapeWrapper::claim_bt_shape(const btVector3 &body_scale) { - if (!bt_shape) { - if (active) + if (bt_shape == nullptr) { + if (active) { bt_shape = shape->create_bt_shape(scale * body_scale); - else + } else { bt_shape = ShapeBullet::create_shape_empty(); + } + } +} + +void CollisionObjectBullet::ShapeWrapper::release_bt_shape() { + if (bt_shape != nullptr) { + shape->destroy_bt_shape(bt_shape); + bt_shape = nullptr; } } CollisionObjectBullet::CollisionObjectBullet(Type p_type) : RIDBullet(), - type(p_type), - instance_id(0), - collisionLayer(0), - collisionMask(0), - collisionsEnabled(true), - m_isStatic(false), - ray_pickable(false), - bt_collision_object(NULL), - body_scale(1., 1., 1.), - force_shape_reset(false), - space(NULL), - isTransformChanged(false) {} + type(p_type) {} CollisionObjectBullet::~CollisionObjectBullet() { // Remove all overlapping, notify is not required since godot take care of it @@ -147,24 +144,43 @@ void CollisionObjectBullet::setupBulletCollisionObject(btCollisionObject *p_coll void CollisionObjectBullet::add_collision_exception(const CollisionObjectBullet *p_ignoreCollisionObject) { exceptions.insert(p_ignoreCollisionObject->get_self()); - if (!bt_collision_object) + if (!bt_collision_object) { return; + } bt_collision_object->setIgnoreCollisionCheck(p_ignoreCollisionObject->bt_collision_object, true); - if (space) + if (space) { space->get_broadphase()->getOverlappingPairCache()->cleanProxyFromPairs(bt_collision_object->getBroadphaseHandle(), space->get_dispatcher()); + } } void CollisionObjectBullet::remove_collision_exception(const CollisionObjectBullet *p_ignoreCollisionObject) { exceptions.erase(p_ignoreCollisionObject->get_self()); bt_collision_object->setIgnoreCollisionCheck(p_ignoreCollisionObject->bt_collision_object, false); - if (space) + if (space) { space->get_broadphase()->getOverlappingPairCache()->cleanProxyFromPairs(bt_collision_object->getBroadphaseHandle(), space->get_dispatcher()); + } } bool CollisionObjectBullet::has_collision_exception(const CollisionObjectBullet *p_otherCollisionObject) const { return !bt_collision_object->checkCollideWith(p_otherCollisionObject->bt_collision_object); } +void CollisionObjectBullet::reload_body() { + needs_body_reload = true; +} + +void CollisionObjectBullet::dispatch_callbacks() {} + +void CollisionObjectBullet::pre_process() { + if (needs_body_reload) { + do_reload_body(); + } else if (needs_collision_filters_reload) { + do_reload_collision_filters(); + } + needs_body_reload = false; + needs_collision_filters_reload = false; +} + void CollisionObjectBullet::set_collision_enabled(bool p_enabled) { collisionsEnabled = p_enabled; if (collisionsEnabled) { @@ -195,7 +211,6 @@ int CollisionObjectBullet::get_godot_object_flags() const { } void CollisionObjectBullet::set_transform(const Transform &p_global_transform) { - set_body_scale(p_global_transform.basis.get_scale_abs()); btTransform bt_transform; @@ -225,11 +240,6 @@ void CollisionObjectBullet::notify_transform_changed() { isTransformChanged = true; } -RigidCollisionObjectBullet::RigidCollisionObjectBullet(Type p_type) : - CollisionObjectBullet(p_type), - mainShape(NULL) { -} - RigidCollisionObjectBullet::~RigidCollisionObjectBullet() { remove_all_shapes(true, true); if (mainShape && mainShape->isCompound()) { @@ -244,7 +254,7 @@ void RigidCollisionObjectBullet::add_shape(ShapeBullet *p_shape, const Transform } void RigidCollisionObjectBullet::set_shape(int p_index, ShapeBullet *p_shape) { - ShapeWrapper &shp = shapes.write[p_index]; + ShapeWrapper &shp = shapes[p_index]; shp.shape->remove_owner(this); p_shape->add_owner(this); shp.shape = p_shape; @@ -266,8 +276,9 @@ btCollisionShape *RigidCollisionObjectBullet::get_bt_shape(int p_index) const { int RigidCollisionObjectBullet::find_shape(ShapeBullet *p_shape) const { const int size = shapes.size(); for (int i = 0; i < size; ++i) { - if (shapes[i].shape == p_shape) + if (shapes[i].shape == p_shape) { return i; + } } return -1; } @@ -297,14 +308,15 @@ void RigidCollisionObjectBullet::remove_all_shapes(bool p_permanentlyFromThisBod internal_shape_destroy(i, p_permanentlyFromThisBody); } shapes.clear(); - if (!p_force_not_reload) + if (!p_force_not_reload) { reload_shapes(); + } } void RigidCollisionObjectBullet::set_shape_transform(int p_index, const Transform &p_transform) { ERR_FAIL_INDEX(p_index, get_shape_count()); - shapes.write[p_index].set_transform(p_transform); + shapes[p_index].set_transform(p_transform); shape_changed(p_index); } @@ -319,9 +331,10 @@ Transform RigidCollisionObjectBullet::get_shape_transform(int p_index) const { } void RigidCollisionObjectBullet::set_shape_disabled(int p_index, bool p_disabled) { - if (shapes[p_index].active != p_disabled) + if (shapes[p_index].active != p_disabled) { return; - shapes.write[p_index].active = !p_disabled; + } + shapes[p_index].active = !p_disabled; shape_changed(p_index); } @@ -329,59 +342,67 @@ bool RigidCollisionObjectBullet::is_shape_disabled(int p_index) { return !shapes[p_index].active; } +void RigidCollisionObjectBullet::pre_process() { + if (need_shape_reload) { + do_reload_shapes(); + need_shape_reload = false; + } + CollisionObjectBullet::pre_process(); +} + void RigidCollisionObjectBullet::shape_changed(int p_shape_index) { - ShapeWrapper &shp = shapes.write[p_shape_index]; + ShapeWrapper &shp = shapes[p_shape_index]; if (shp.bt_shape == mainShape) { - mainShape = NULL; + mainShape = nullptr; } - bulletdelete(shp.bt_shape); + shp.release_bt_shape(); reload_shapes(); } void RigidCollisionObjectBullet::reload_shapes() { + need_shape_reload = true; +} +void RigidCollisionObjectBullet::do_reload_shapes() { if (mainShape && mainShape->isCompound()) { // Destroy compound bulletdelete(mainShape); } - mainShape = NULL; + mainShape = nullptr; - ShapeWrapper *shpWrapper; const int shape_count = shapes.size(); - // Reset shape if required + // Reset all shapes if required if (force_shape_reset) { for (int i(0); i < shape_count; ++i) { - shpWrapper = &shapes.write[i]; - bulletdelete(shpWrapper->bt_shape); + shapes[i].release_bt_shape(); } force_shape_reset = false; } const btVector3 body_scale(get_bt_body_scale()); - // Try to optimize by not using compound if (1 == shape_count) { - shpWrapper = &shapes.write[0]; - btTransform transform = shpWrapper->get_adjusted_transform(); + // Is it possible to optimize by not using compound? + btTransform transform = shapes[0].get_adjusted_transform(); if (transform.getOrigin().isZero() && transform.getBasis() == transform.getBasis().getIdentity()) { - shpWrapper->claim_bt_shape(body_scale); - mainShape = shpWrapper->bt_shape; + shapes[0].claim_bt_shape(body_scale); + mainShape = shapes[0].bt_shape; main_shape_changed(); + // Nothing more to do return; } } - // Optimization not possible use a compound shape + // Optimization not possible use a compound shape. btCompoundShape *compoundShape = bulletnew(btCompoundShape(enableDynamicAabbTree, shape_count)); for (int i(0); i < shape_count; ++i) { - shpWrapper = &shapes.write[i]; - shpWrapper->claim_bt_shape(body_scale); - btTransform scaled_shape_transform(shpWrapper->get_adjusted_transform()); + shapes[i].claim_bt_shape(body_scale); + btTransform scaled_shape_transform(shapes[i].get_adjusted_transform()); scaled_shape_transform.getOrigin() *= body_scale; - compoundShape->addChildShape(scaled_shape_transform, shpWrapper->bt_shape); + compoundShape->addChildShape(scaled_shape_transform, shapes[i].bt_shape); } compoundShape->recalculateLocalAabb(); @@ -395,10 +416,10 @@ void RigidCollisionObjectBullet::body_scale_changed() { } void RigidCollisionObjectBullet::internal_shape_destroy(int p_index, bool p_permanentlyFromThisBody) { - ShapeWrapper &shp = shapes.write[p_index]; + ShapeWrapper &shp = shapes[p_index]; shp.shape->remove_owner(this, p_permanentlyFromThisBody); if (shp.bt_shape == mainShape) { - mainShape = NULL; + mainShape = nullptr; } - bulletdelete(shp.bt_shape); + shp.release_bt_shape(); } diff --git a/modules/bullet/collision_object_bullet.h b/modules/bullet/collision_object_bullet.h index 42ba4aa907..920d80af23 100644 --- a/modules/bullet/collision_object_bullet.h +++ b/modules/bullet/collision_object_bullet.h @@ -31,6 +31,7 @@ #ifndef COLLISION_OBJECT_BULLET_H #define COLLISION_OBJECT_BULLET_H +#include "core/local_vector.h" #include "core/math/transform.h" #include "core/math/vector3.h" #include "core/object.h" @@ -69,27 +70,23 @@ public: }; struct ShapeWrapper { - ShapeBullet *shape; - btCollisionShape *bt_shape; + ShapeBullet *shape = nullptr; btTransform transform; btVector3 scale; - bool active; + bool active = true; + btCollisionShape *bt_shape = nullptr; - ShapeWrapper() : - shape(NULL), - bt_shape(NULL), - active(true) {} + public: + ShapeWrapper() {} ShapeWrapper(ShapeBullet *p_shape, const btTransform &p_transform, bool p_active) : shape(p_shape), - bt_shape(NULL), active(p_active) { set_transform(p_transform); } ShapeWrapper(ShapeBullet *p_shape, const Transform &p_transform, bool p_active) : shape(p_shape), - bt_shape(NULL), active(p_active) { set_transform(p_transform); } @@ -112,28 +109,36 @@ public: btTransform get_adjusted_transform() const; void claim_bt_shape(const btVector3 &body_scale); + void release_bt_shape(); }; protected: Type type; ObjectID instance_id; - uint32_t collisionLayer; - uint32_t collisionMask; - bool collisionsEnabled; - bool m_isStatic; - bool ray_pickable; - btCollisionObject *bt_collision_object; - Vector3 body_scale; - bool force_shape_reset; - SpaceBullet *space; + uint32_t collisionLayer = 0; + uint32_t collisionMask = 0; + bool collisionsEnabled = true; + bool m_isStatic = false; + bool ray_pickable = false; + btCollisionObject *bt_collision_object = nullptr; + Vector3 body_scale = Vector3(1, 1, 1); + bool force_shape_reset = false; + SpaceBullet *space = nullptr; VSet<RID> exceptions; + bool needs_body_reload = true; + bool needs_collision_filters_reload = true; + /// This array is used to know all areas where this Object is overlapped in /// New area is added when overlap with new area (AreaBullet::addOverlap), then is removed when it exit (CollisionObjectBullet::onExitArea) /// This array is used mainly to know which area hold the pointer of this object - Vector<AreaBullet *> areasOverlapped; - bool isTransformChanged; + LocalVector<AreaBullet *> areasOverlapped; + bool isTransformChanged = false; + +public: + bool is_in_world = false; + bool is_in_flush_queue = false; public: CollisionObjectBullet(Type p_type); @@ -169,7 +174,7 @@ public: _FORCE_INLINE_ void set_collision_layer(uint32_t p_layer) { if (collisionLayer != p_layer) { collisionLayer = p_layer; - on_collision_filters_change(); + needs_collision_filters_reload = true; } } _FORCE_INLINE_ uint32_t get_collision_layer() const { return collisionLayer; } @@ -177,25 +182,32 @@ public: _FORCE_INLINE_ void set_collision_mask(uint32_t p_mask) { if (collisionMask != p_mask) { collisionMask = p_mask; - on_collision_filters_change(); + needs_collision_filters_reload = true; } } _FORCE_INLINE_ uint32_t get_collision_mask() const { return collisionMask; } - virtual void on_collision_filters_change() = 0; + virtual void do_reload_collision_filters() = 0; _FORCE_INLINE_ bool test_collision_mask(CollisionObjectBullet *p_other) const { return collisionLayer & p_other->collisionMask || p_other->collisionLayer & collisionMask; } - virtual void reload_body() = 0; + bool need_reload_body() const { + return needs_body_reload; + } + + void reload_body(); + + virtual void do_reload_body() = 0; virtual void set_space(SpaceBullet *p_space) = 0; _FORCE_INLINE_ SpaceBullet *get_space() const { return space; } virtual void on_collision_checker_start() = 0; virtual void on_collision_checker_end() = 0; - virtual void dispatch_callbacks() = 0; + virtual void dispatch_callbacks(); + virtual void pre_process(); void set_collision_enabled(bool p_enabled); bool is_collisions_response_enabled(); @@ -218,14 +230,16 @@ public: class RigidCollisionObjectBullet : public CollisionObjectBullet, public ShapeOwnerBullet { protected: - btCollisionShape *mainShape; - Vector<ShapeWrapper> shapes; + btCollisionShape *mainShape = nullptr; + LocalVector<ShapeWrapper> shapes; + bool need_shape_reload = true; public: - RigidCollisionObjectBullet(Type p_type); + RigidCollisionObjectBullet(Type p_type) : + CollisionObjectBullet(p_type) {} ~RigidCollisionObjectBullet(); - _FORCE_INLINE_ const Vector<ShapeWrapper> &get_shapes_wrappers() const { return shapes; } + _FORCE_INLINE_ const LocalVector<ShapeWrapper> &get_shapes_wrappers() const { return shapes; } _FORCE_INLINE_ btCollisionShape *get_main_shape() const { return mainShape; } @@ -236,9 +250,9 @@ public: ShapeBullet *get_shape(int p_index) const; btCollisionShape *get_bt_shape(int p_index) const; - int find_shape(ShapeBullet *p_shape) const; + virtual int find_shape(ShapeBullet *p_shape) const override; - virtual void remove_shape_full(ShapeBullet *p_shape); + virtual void remove_shape_full(ShapeBullet *p_shape) override; void remove_shape_full(int p_index); void remove_all_shapes(bool p_permanentlyFromThisBody = false, bool p_force_not_reload = false); @@ -250,11 +264,15 @@ public: void set_shape_disabled(int p_index, bool p_disabled); bool is_shape_disabled(int p_index); - virtual void shape_changed(int p_shape_index); - virtual void reload_shapes(); + virtual void pre_process() override; + + virtual void shape_changed(int p_shape_index) override; + virtual void reload_shapes() override; + bool need_reload_shapes() const { return need_shape_reload; } + virtual void do_reload_shapes(); virtual void main_shape_changed() = 0; - virtual void body_scale_changed(); + virtual void body_scale_changed() override; private: void internal_shape_destroy(int p_index, bool p_permanentlyFromThisBody = false); diff --git a/modules/bullet/cone_twist_joint_bullet.cpp b/modules/bullet/cone_twist_joint_bullet.cpp index afeafcc356..b4735fa9e9 100644 --- a/modules/bullet/cone_twist_joint_bullet.cpp +++ b/modules/bullet/cone_twist_joint_bullet.cpp @@ -42,7 +42,6 @@ ConeTwistJointBullet::ConeTwistJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &rbAFrame, const Transform &rbBFrame) : JointBullet() { - Transform scaled_AFrame(rbAFrame.scaled(rbA->get_body_scale())); scaled_AFrame.basis.rotref_posscale_decomposition(scaled_AFrame.basis); @@ -50,7 +49,6 @@ ConeTwistJointBullet::ConeTwistJointBullet(RigidBodyBullet *rbA, RigidBodyBullet G_TO_B(scaled_AFrame, btFrameA); if (rbB) { - Transform scaled_BFrame(rbBFrame.scaled(rbB->get_body_scale())); scaled_BFrame.basis.rotref_posscale_decomposition(scaled_BFrame.basis); @@ -64,44 +62,46 @@ ConeTwistJointBullet::ConeTwistJointBullet(RigidBodyBullet *rbA, RigidBodyBullet setup(coneConstraint); } -void ConeTwistJointBullet::set_param(PhysicsServer::ConeTwistJointParam p_param, real_t p_value) { +void ConeTwistJointBullet::set_param(PhysicsServer3D::ConeTwistJointParam p_param, real_t p_value) { switch (p_param) { - case PhysicsServer::CONE_TWIST_JOINT_SWING_SPAN: + case PhysicsServer3D::CONE_TWIST_JOINT_SWING_SPAN: coneConstraint->setLimit(5, p_value); coneConstraint->setLimit(4, p_value); break; - case PhysicsServer::CONE_TWIST_JOINT_TWIST_SPAN: + case PhysicsServer3D::CONE_TWIST_JOINT_TWIST_SPAN: coneConstraint->setLimit(3, p_value); break; - case PhysicsServer::CONE_TWIST_JOINT_BIAS: + case PhysicsServer3D::CONE_TWIST_JOINT_BIAS: coneConstraint->setLimit(coneConstraint->getSwingSpan1(), coneConstraint->getSwingSpan2(), coneConstraint->getTwistSpan(), coneConstraint->getLimitSoftness(), p_value, coneConstraint->getRelaxationFactor()); break; - case PhysicsServer::CONE_TWIST_JOINT_SOFTNESS: + case PhysicsServer3D::CONE_TWIST_JOINT_SOFTNESS: coneConstraint->setLimit(coneConstraint->getSwingSpan1(), coneConstraint->getSwingSpan2(), coneConstraint->getTwistSpan(), p_value, coneConstraint->getBiasFactor(), coneConstraint->getRelaxationFactor()); break; - case PhysicsServer::CONE_TWIST_JOINT_RELAXATION: + case PhysicsServer3D::CONE_TWIST_JOINT_RELAXATION: coneConstraint->setLimit(coneConstraint->getSwingSpan1(), coneConstraint->getSwingSpan2(), coneConstraint->getTwistSpan(), coneConstraint->getLimitSoftness(), coneConstraint->getBiasFactor(), p_value); break; - default: - WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated."); + case PhysicsServer3D::CONE_TWIST_MAX: + // Internal size value, nothing to do. break; } } -real_t ConeTwistJointBullet::get_param(PhysicsServer::ConeTwistJointParam p_param) const { +real_t ConeTwistJointBullet::get_param(PhysicsServer3D::ConeTwistJointParam p_param) const { switch (p_param) { - case PhysicsServer::CONE_TWIST_JOINT_SWING_SPAN: + case PhysicsServer3D::CONE_TWIST_JOINT_SWING_SPAN: return coneConstraint->getSwingSpan1(); - case PhysicsServer::CONE_TWIST_JOINT_TWIST_SPAN: + case PhysicsServer3D::CONE_TWIST_JOINT_TWIST_SPAN: return coneConstraint->getTwistSpan(); - case PhysicsServer::CONE_TWIST_JOINT_BIAS: + case PhysicsServer3D::CONE_TWIST_JOINT_BIAS: return coneConstraint->getBiasFactor(); - case PhysicsServer::CONE_TWIST_JOINT_SOFTNESS: + case PhysicsServer3D::CONE_TWIST_JOINT_SOFTNESS: return coneConstraint->getLimitSoftness(); - case PhysicsServer::CONE_TWIST_JOINT_RELAXATION: + case PhysicsServer3D::CONE_TWIST_JOINT_RELAXATION: return coneConstraint->getRelaxationFactor(); - default: - WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated."); + case PhysicsServer3D::CONE_TWIST_MAX: + // Internal size value, nothing to do. return 0; } + // Compiler doesn't seem to notice that all code paths are fulfilled... + return 0; } diff --git a/modules/bullet/cone_twist_joint_bullet.h b/modules/bullet/cone_twist_joint_bullet.h index 134706f8bb..ed4baa9d1b 100644 --- a/modules/bullet/cone_twist_joint_bullet.h +++ b/modules/bullet/cone_twist_joint_bullet.h @@ -45,9 +45,9 @@ class ConeTwistJointBullet : public JointBullet { public: ConeTwistJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &rbAFrame, const Transform &rbBFrame); - virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_CONE_TWIST; } + virtual PhysicsServer3D::JointType get_type() const { return PhysicsServer3D::JOINT_CONE_TWIST; } - void set_param(PhysicsServer::ConeTwistJointParam p_param, real_t p_value); - real_t get_param(PhysicsServer::ConeTwistJointParam p_param) const; + void set_param(PhysicsServer3D::ConeTwistJointParam p_param, real_t p_value); + real_t get_param(PhysicsServer3D::ConeTwistJointParam p_param) const; }; #endif diff --git a/modules/bullet/config.py b/modules/bullet/config.py index 92dbcf5cb0..d22f9454ed 100644 --- a/modules/bullet/config.py +++ b/modules/bullet/config.py @@ -1,14 +1,6 @@ def can_build(env, platform): return True + def configure(env): pass - -def get_doc_classes(): - return [ - "BulletPhysicsDirectBodyState", - "BulletPhysicsServer", - ] - -def get_doc_path(): - return "doc_classes" diff --git a/modules/bullet/constraint_bullet.cpp b/modules/bullet/constraint_bullet.cpp index 7e90e2b488..c47a23e75f 100644 --- a/modules/bullet/constraint_bullet.cpp +++ b/modules/bullet/constraint_bullet.cpp @@ -37,10 +37,7 @@ @author AndreaCatania */ -ConstraintBullet::ConstraintBullet() : - space(NULL), - constraint(NULL), - disabled_collisions_between_bodies(true) {} +ConstraintBullet::ConstraintBullet() {} void ConstraintBullet::setup(btTypedConstraint *p_constraint) { constraint = p_constraint; diff --git a/modules/bullet/constraint_bullet.h b/modules/bullet/constraint_bullet.h index 89ad150257..538808be51 100644 --- a/modules/bullet/constraint_bullet.h +++ b/modules/bullet/constraint_bullet.h @@ -45,11 +45,10 @@ class SpaceBullet; class btTypedConstraint; class ConstraintBullet : public RIDBullet { - protected: - SpaceBullet *space; - btTypedConstraint *constraint; - bool disabled_collisions_between_bodies; + SpaceBullet *space = nullptr; + btTypedConstraint *constraint = nullptr; + bool disabled_collisions_between_bodies = true; public: ConstraintBullet(); @@ -64,7 +63,7 @@ public: public: virtual ~ConstraintBullet() { bulletdelete(constraint); - constraint = NULL; + constraint = nullptr; } _FORCE_INLINE_ btTypedConstraint *get_bt_constraint() { return constraint; } diff --git a/modules/bullet/doc_classes/BulletPhysicsDirectBodyState.xml b/modules/bullet/doc_classes/BulletPhysicsDirectBodyState.xml deleted file mode 100644 index 5ea1b810a1..0000000000 --- a/modules/bullet/doc_classes/BulletPhysicsDirectBodyState.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="BulletPhysicsDirectBodyState" inherits="PhysicsDirectBodyState" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> - <methods> - </methods> - <constants> - </constants> -</class> diff --git a/modules/bullet/doc_classes/BulletPhysicsServer.xml b/modules/bullet/doc_classes/BulletPhysicsServer.xml deleted file mode 100644 index af8fb3c02c..0000000000 --- a/modules/bullet/doc_classes/BulletPhysicsServer.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="BulletPhysicsServer" inherits="PhysicsServer" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> - <methods> - </methods> - <constants> - </constants> -</class> diff --git a/modules/bullet/generic_6dof_joint_bullet.cpp b/modules/bullet/generic_6dof_joint_bullet.cpp index 86bedd6c45..56a66dba45 100644 --- a/modules/bullet/generic_6dof_joint_bullet.cpp +++ b/modules/bullet/generic_6dof_joint_bullet.cpp @@ -42,6 +42,11 @@ Generic6DOFJointBullet::Generic6DOFJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB) : JointBullet() { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < PhysicsServer3D::G6DOF_JOINT_FLAG_MAX; j++) { + flags[i][j] = false; + } + } Transform scaled_AFrame(frameInA.scaled(rbA->get_body_scale())); @@ -118,147 +123,153 @@ void Generic6DOFJointBullet::set_angular_upper_limit(const Vector3 &angularUpper sixDOFConstraint->setAngularUpperLimit(btVec); } -void Generic6DOFJointBullet::set_param(Vector3::Axis p_axis, PhysicsServer::G6DOFJointAxisParam p_param, real_t p_value) { +void Generic6DOFJointBullet::set_param(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param, real_t p_value) { ERR_FAIL_INDEX(p_axis, 3); switch (p_param) { - case PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT: limits_lower[0][p_axis] = p_value; - set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, flags[p_axis][PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT]); // Reload bullet parameter + set_flag(p_axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, flags[p_axis][PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT]); // Reload bullet parameter break; - case PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT: limits_upper[0][p_axis] = p_value; - set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, flags[p_axis][PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT]); // Reload bullet parameter + set_flag(p_axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, flags[p_axis][PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT]); // Reload bullet parameter break; - case PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY: sixDOFConstraint->getTranslationalLimitMotor()->m_targetVelocity.m_floats[p_axis] = p_value; break; - case PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT: sixDOFConstraint->getTranslationalLimitMotor()->m_maxMotorForce.m_floats[p_axis] = p_value; break; - case PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_DAMPING: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING: sixDOFConstraint->getTranslationalLimitMotor()->m_springDamping.m_floats[p_axis] = p_value; break; - case PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS: sixDOFConstraint->getTranslationalLimitMotor()->m_springStiffness.m_floats[p_axis] = p_value; break; - case PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT: sixDOFConstraint->getTranslationalLimitMotor()->m_equilibriumPoint.m_floats[p_axis] = p_value; break; - case PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT: limits_lower[1][p_axis] = p_value; - set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, flags[p_axis][PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT]); // Reload bullet parameter + set_flag(p_axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, flags[p_axis][PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT]); // Reload bullet parameter break; - case PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT: limits_upper[1][p_axis] = p_value; - set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, flags[p_axis][PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT]); // Reload bullet parameter + set_flag(p_axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, flags[p_axis][PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT]); // Reload bullet parameter break; - case PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION: sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_bounce = p_value; break; - case PhysicsServer::G6DOF_JOINT_ANGULAR_ERP: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP: sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_stopERP = p_value; break; - case PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY: sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_targetVelocity = p_value; break; - case PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT: sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_maxMotorForce = p_value; break; - case PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS: sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_springStiffness = p_value; break; - case PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_DAMPING: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING: sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_springDamping = p_value; break; - case PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT: sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_equilibriumPoint = p_value; break; + case PhysicsServer3D::G6DOF_JOINT_MAX: + // Internal size value, nothing to do. + break; default: WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated."); break; } } -real_t Generic6DOFJointBullet::get_param(Vector3::Axis p_axis, PhysicsServer::G6DOFJointAxisParam p_param) const { +real_t Generic6DOFJointBullet::get_param(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param) const { ERR_FAIL_INDEX_V(p_axis, 3, 0.); switch (p_param) { - case PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT: return limits_lower[0][p_axis]; - case PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT: return limits_upper[0][p_axis]; - case PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY: return sixDOFConstraint->getTranslationalLimitMotor()->m_targetVelocity.m_floats[p_axis]; - case PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT: return sixDOFConstraint->getTranslationalLimitMotor()->m_maxMotorForce.m_floats[p_axis]; - case PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_DAMPING: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING: return sixDOFConstraint->getTranslationalLimitMotor()->m_springDamping.m_floats[p_axis]; - case PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS: return sixDOFConstraint->getTranslationalLimitMotor()->m_springStiffness.m_floats[p_axis]; - case PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT: + case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT: return sixDOFConstraint->getTranslationalLimitMotor()->m_equilibriumPoint.m_floats[p_axis]; - case PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT: return limits_lower[1][p_axis]; - case PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT: return limits_upper[1][p_axis]; - case PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION: return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_bounce; - case PhysicsServer::G6DOF_JOINT_ANGULAR_ERP: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP: return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_stopERP; - case PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY: return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_targetVelocity; - case PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT: return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_maxMotorForce; - case PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS: return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_springStiffness; - case PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_DAMPING: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING: return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_springDamping; - case PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT: + case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT: return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_equilibriumPoint; + case PhysicsServer3D::G6DOF_JOINT_MAX: + // Internal size value, nothing to do. + return 0; default: WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated."); return 0; } } -void Generic6DOFJointBullet::set_flag(Vector3::Axis p_axis, PhysicsServer::G6DOFJointAxisFlag p_flag, bool p_value) { +void Generic6DOFJointBullet::set_flag(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag, bool p_value) { ERR_FAIL_INDEX(p_axis, 3); flags[p_axis][p_flag] = p_value; switch (p_flag) { - case PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT: if (flags[p_axis][p_flag]) { sixDOFConstraint->setLimit(p_axis, limits_lower[0][p_axis], limits_upper[0][p_axis]); } else { sixDOFConstraint->setLimit(p_axis, 0, -1); // Free } break; - case PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT: + case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT: if (flags[p_axis][p_flag]) { sixDOFConstraint->setLimit(p_axis + 3, limits_lower[1][p_axis], limits_upper[1][p_axis]); } else { sixDOFConstraint->setLimit(p_axis + 3, 0, -1); // Free } break; - case PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_MOTOR: - sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_enableMotor = flags[p_axis][p_flag]; - break; - case PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR: - sixDOFConstraint->getTranslationalLimitMotor()->m_enableMotor[p_axis] = flags[p_axis][p_flag]; + case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING: + sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_enableSpring = p_value; break; - case PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING: + case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING: sixDOFConstraint->getTranslationalLimitMotor()->m_enableSpring[p_axis] = p_value; break; - case PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING: - sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_enableSpring = p_value; + case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_MOTOR: + sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_enableMotor = flags[p_axis][p_flag]; break; - default: - WARN_DEPRECATED_MSG("The flag " + itos(p_flag) + " is deprecated."); + case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR: + sixDOFConstraint->getTranslationalLimitMotor()->m_enableMotor[p_axis] = flags[p_axis][p_flag]; + break; + case PhysicsServer3D::G6DOF_JOINT_FLAG_MAX: + // Internal size value, nothing to do. break; } } -bool Generic6DOFJointBullet::get_flag(Vector3::Axis p_axis, PhysicsServer::G6DOFJointAxisFlag p_flag) const { +bool Generic6DOFJointBullet::get_flag(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag) const { ERR_FAIL_INDEX_V(p_axis, 3, false); return flags[p_axis][p_flag]; } diff --git a/modules/bullet/generic_6dof_joint_bullet.h b/modules/bullet/generic_6dof_joint_bullet.h index 75c8005811..316708bb11 100644 --- a/modules/bullet/generic_6dof_joint_bullet.h +++ b/modules/bullet/generic_6dof_joint_bullet.h @@ -45,12 +45,12 @@ class Generic6DOFJointBullet : public JointBullet { // First is linear second is angular Vector3 limits_lower[2]; Vector3 limits_upper[2]; - bool flags[3][PhysicsServer::G6DOF_JOINT_FLAG_MAX]; + bool flags[3][PhysicsServer3D::G6DOF_JOINT_FLAG_MAX]; public: Generic6DOFJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB); - virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_6DOF; } + virtual PhysicsServer3D::JointType get_type() const { return PhysicsServer3D::JOINT_6DOF; } Transform getFrameOffsetA() const; Transform getFrameOffsetB() const; @@ -63,11 +63,11 @@ public: void set_angular_lower_limit(const Vector3 &angularLower); void set_angular_upper_limit(const Vector3 &angularUpper); - void set_param(Vector3::Axis p_axis, PhysicsServer::G6DOFJointAxisParam p_param, real_t p_value); - real_t get_param(Vector3::Axis p_axis, PhysicsServer::G6DOFJointAxisParam p_param) const; + void set_param(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param, real_t p_value); + real_t get_param(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param) const; - void set_flag(Vector3::Axis p_axis, PhysicsServer::G6DOFJointAxisFlag p_flag, bool p_value); - bool get_flag(Vector3::Axis p_axis, PhysicsServer::G6DOFJointAxisFlag p_flag) const; + void set_flag(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag, bool p_value); + bool get_flag(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag) const; void set_precision(int p_precision); int get_precision() const; diff --git a/modules/bullet/godot_collision_configuration.cpp b/modules/bullet/godot_collision_configuration.cpp index f3e3a01a52..ec7a1dbd9a 100644 --- a/modules/bullet/godot_collision_configuration.cpp +++ b/modules/bullet/godot_collision_configuration.cpp @@ -41,8 +41,7 @@ GodotCollisionConfiguration::GodotCollisionConfiguration(const btDiscreteDynamicsWorld *world, const btDefaultCollisionConstructionInfo &constructionInfo) : btDefaultCollisionConfiguration(constructionInfo) { - - void *mem = NULL; + void *mem = nullptr; mem = btAlignedAlloc(sizeof(GodotRayWorldAlgorithm::CreateFunc), 16); m_rayWorldCF = new (mem) GodotRayWorldAlgorithm::CreateFunc(world); @@ -60,45 +59,34 @@ GodotCollisionConfiguration::~GodotCollisionConfiguration() { } btCollisionAlgorithmCreateFunc *GodotCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1) { - if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0 && CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - // This collision is not supported return m_emptyCreateFunc; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0) { - return m_rayWorldCF; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - return m_swappedRayWorldCF; } else { - return btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(proxyType0, proxyType1); } } btCollisionAlgorithmCreateFunc *GodotCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1) { - if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0 && CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - // This collision is not supported return m_emptyCreateFunc; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0) { - return m_rayWorldCF; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - return m_swappedRayWorldCF; } else { - return btDefaultCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(proxyType0, proxyType1); } } GodotSoftCollisionConfiguration::GodotSoftCollisionConfiguration(const btDiscreteDynamicsWorld *world, const btDefaultCollisionConstructionInfo &constructionInfo) : btSoftBodyRigidBodyCollisionConfiguration(constructionInfo) { - - void *mem = NULL; + void *mem = nullptr; mem = btAlignedAlloc(sizeof(GodotRayWorldAlgorithm::CreateFunc), 16); m_rayWorldCF = new (mem) GodotRayWorldAlgorithm::CreateFunc(world); @@ -116,37 +104,27 @@ GodotSoftCollisionConfiguration::~GodotSoftCollisionConfiguration() { } btCollisionAlgorithmCreateFunc *GodotSoftCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1) { - if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0 && CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - // This collision is not supported return m_emptyCreateFunc; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0) { - return m_rayWorldCF; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - return m_swappedRayWorldCF; } else { - return btSoftBodyRigidBodyCollisionConfiguration::getCollisionAlgorithmCreateFunc(proxyType0, proxyType1); } } btCollisionAlgorithmCreateFunc *GodotSoftCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1) { - if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0 && CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - // This collision is not supported return m_emptyCreateFunc; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0) { - return m_rayWorldCF; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - return m_swappedRayWorldCF; } else { - return btSoftBodyRigidBodyCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(proxyType0, proxyType1); } } diff --git a/modules/bullet/godot_motion_state.h b/modules/bullet/godot_motion_state.h index e2c1b10e94..90d1614a77 100644 --- a/modules/bullet/godot_motion_state.h +++ b/modules/bullet/godot_motion_state.h @@ -46,7 +46,6 @@ class RigidBodyBullet; /// DOC: /// http://www.bulletphysics.org/mediawiki-1.5.8/index.php/MotionStates#What.27s_a_MotionState.3F class GodotMotionState : public btMotionState { - /// This data is used to store the new world position for kinematic body btTransform bodyKinematicWorldTransf; /// This data is used to store last world position diff --git a/modules/bullet/godot_ray_world_algorithm.cpp b/modules/bullet/godot_ray_world_algorithm.cpp index 2ef277cf5b..a84f3511ba 100644 --- a/modules/bullet/godot_ray_world_algorithm.cpp +++ b/modules/bullet/godot_ray_world_algorithm.cpp @@ -52,7 +52,6 @@ GodotRayWorldAlgorithm::GodotRayWorldAlgorithm(const btDiscreteDynamicsWorld *wo btActivatingCollisionAlgorithm(ci, body0Wrap, body1Wrap), m_world(world), m_manifoldPtr(mf), - m_ownManifold(false), m_isSwapped(isSwapped) {} GodotRayWorldAlgorithm::~GodotRayWorldAlgorithm() { @@ -62,7 +61,6 @@ GodotRayWorldAlgorithm::~GodotRayWorldAlgorithm() { } void GodotRayWorldAlgorithm::processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut) { - if (!m_manifoldPtr) { if (m_isSwapped) { m_manifoldPtr = m_dispatcher->getNewManifold(body1Wrap->getCollisionObject(), body0Wrap->getCollisionObject()); @@ -80,13 +78,11 @@ void GodotRayWorldAlgorithm::processCollision(const btCollisionObjectWrapper *bo const btCollisionObjectWrapper *other_co_wrapper; if (m_isSwapped) { - ray_shape = static_cast<const btRayShape *>(body1Wrap->getCollisionShape()); ray_transform = body1Wrap->getWorldTransform(); other_co_wrapper = body0Wrap; } else { - ray_shape = static_cast<const btRayShape *>(body0Wrap->getCollisionShape()); ray_transform = body0Wrap->getWorldTransform(); @@ -100,15 +96,15 @@ void GodotRayWorldAlgorithm::processCollision(const btCollisionObjectWrapper *bo m_world->rayTestSingleInternal(ray_transform, to, other_co_wrapper, btResult); if (btResult.hasHit()) { - btScalar depth(ray_shape->getScaledLength() * (btResult.m_closestHitFraction - 1)); - if (depth > -RAY_PENETRATION_DEPTH_EPSILON) + if (depth > -RAY_PENETRATION_DEPTH_EPSILON) { depth = 0.0; + } - if (ray_shape->getSlipsOnSlope()) + if (ray_shape->getSlipsOnSlope()) { resultOut->addContactPoint(btResult.m_hitNormalWorld, btResult.m_hitPointWorld, depth); - else { + } else { resultOut->addContactPoint((ray_transform.getOrigin() - to.getOrigin()).normalize(), btResult.m_hitPointWorld, depth); } } diff --git a/modules/bullet/godot_ray_world_algorithm.h b/modules/bullet/godot_ray_world_algorithm.h index 2cdea6c133..9786732d40 100644 --- a/modules/bullet/godot_ray_world_algorithm.h +++ b/modules/bullet/godot_ray_world_algorithm.h @@ -42,10 +42,9 @@ class btDiscreteDynamicsWorld; class GodotRayWorldAlgorithm : public btActivatingCollisionAlgorithm { - const btDiscreteDynamicsWorld *m_world; btPersistentManifold *m_manifoldPtr; - bool m_ownManifold; + bool m_ownManifold = false; bool m_isSwapped; public: @@ -57,11 +56,11 @@ public: virtual void getAllContactManifolds(btManifoldArray &manifoldArray) { ///should we use m_ownManifold to avoid adding duplicates? - if (m_manifoldPtr && m_ownManifold) + if (m_manifoldPtr && m_ownManifold) { manifoldArray.push_back(m_manifoldPtr); + } } struct CreateFunc : public btCollisionAlgorithmCreateFunc { - const btDiscreteDynamicsWorld *m_world; CreateFunc(const btDiscreteDynamicsWorld *world); @@ -72,7 +71,6 @@ public: }; struct SwappedCreateFunc : public btCollisionAlgorithmCreateFunc { - const btDiscreteDynamicsWorld *m_world; SwappedCreateFunc(const btDiscreteDynamicsWorld *world); diff --git a/modules/bullet/godot_result_callbacks.cpp b/modules/bullet/godot_result_callbacks.cpp index 6e54d10abf..f82648d6ff 100644 --- a/modules/bullet/godot_result_callbacks.cpp +++ b/modules/bullet/godot_result_callbacks.cpp @@ -62,11 +62,13 @@ bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) co CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { - if (!collide_with_areas) + if (!collide_with_areas) { return false; + } } else { - if (!collide_with_bodies) + if (!collide_with_bodies) { return false; + } } if (m_pickRay && !gObj->is_ray_pickable()) { @@ -84,8 +86,9 @@ bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) co } bool GodotAllConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { - if (count >= m_resultMax) + if (count >= m_resultMax) { return false; + } const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); if (needs) { @@ -102,17 +105,18 @@ bool GodotAllConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) con } btScalar GodotAllConvexResultCallback::addSingleResult(btCollisionWorld::LocalConvexResult &convexResult, bool normalInWorldSpace) { - if (count >= m_resultMax) + if (count >= m_resultMax) { return 1; // not used by bullet + } CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(convexResult.m_hitCollisionObject->getUserPointer()); - PhysicsDirectSpaceState::ShapeResult &result = m_results[count]; + PhysicsDirectSpaceState3D::ShapeResult &result = m_results[count]; result.shape = convexResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID result.rid = gObj->get_self(); result.collider_id = gObj->get_instance_id(); - result.collider = 0 == result.collider_id ? NULL : ObjectDB::get_instance(result.collider_id); + result.collider = result.collider_id.is_null() ? nullptr : ObjectDB::get_instance(result.collider_id); ++count; return 1; // not used by bullet @@ -126,16 +130,18 @@ bool GodotKinClosestConvexResultCallback::needsCollision(btBroadphaseProxy *prox if (gObj == m_self_object) { return false; } else { - // A kinematic body can't be stopped by a rigid body since the mass of kinematic body is infinite - if (m_infinite_inertia && !btObj->isStaticOrKinematicObject()) + if (m_infinite_inertia && !btObj->isStaticOrKinematicObject()) { return false; + } - if (gObj->getType() == CollisionObjectBullet::TYPE_AREA) + if (gObj->getType() == CollisionObjectBullet::TYPE_AREA) { return false; + } - if (m_self_object->has_collision_exception(gObj) || gObj->has_collision_exception(m_self_object)) + if (m_self_object->has_collision_exception(gObj) || gObj->has_collision_exception(m_self_object)) { return false; + } } return true; } else { @@ -150,11 +156,13 @@ bool GodotClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { - if (!collide_with_areas) + if (!collide_with_areas) { return false; + } } else { - if (!collide_with_bodies) + if (!collide_with_bodies) { return false; + } } if (m_exclude->has(gObj->get_self())) { @@ -167,16 +175,18 @@ bool GodotClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) } btScalar GodotClosestConvexResultCallback::addSingleResult(btCollisionWorld::LocalConvexResult &convexResult, bool normalInWorldSpace) { - if (convexResult.m_localShapeInfo) + if (convexResult.m_localShapeInfo) { m_shapeId = convexResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID - else + } else { m_shapeId = 0; + } return btCollisionWorld::ClosestConvexResultCallback::addSingleResult(convexResult, normalInWorldSpace); } bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { - if (m_count >= m_resultMax) + if (m_count >= m_resultMax) { return false; + } const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); if (needs) { @@ -184,11 +194,13 @@ bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) co CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { - if (!collide_with_areas) + if (!collide_with_areas) { return false; + } } else { - if (!collide_with_bodies) + if (!collide_with_bodies) { return false; + } } if (m_exclude->has(gObj->get_self())) { @@ -201,13 +213,12 @@ bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) co } btScalar GodotAllContactResultCallback::addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) { - - if (m_count >= m_resultMax) + if (m_count >= m_resultMax) { return cp.getDistance(); + } if (cp.getDistance() <= 0) { - - PhysicsDirectSpaceState::ShapeResult &result = m_results[m_count]; + PhysicsDirectSpaceState3D::ShapeResult &result = m_results[m_count]; // Penetrated CollisionObjectBullet *colObj; @@ -220,7 +231,7 @@ btScalar GodotAllContactResultCallback::addSingleResult(btManifoldPoint &cp, con } result.collider_id = colObj->get_instance_id(); - result.collider = 0 == result.collider_id ? NULL : ObjectDB::get_instance(result.collider_id); + result.collider = result.collider_id.is_null() ? nullptr : ObjectDB::get_instance(result.collider_id); result.rid = colObj->get_self(); ++m_count; } @@ -229,8 +240,9 @@ btScalar GodotAllContactResultCallback::addSingleResult(btManifoldPoint &cp, con } bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { - if (m_count >= m_resultMax) + if (m_count >= m_resultMax) { return false; + } const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); if (needs) { @@ -238,11 +250,13 @@ bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *pr CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { - if (!collide_with_areas) + if (!collide_with_areas) { return false; + } } else { - if (!collide_with_bodies) + if (!collide_with_bodies) { return false; + } } if (m_exclude->has(gObj->get_self())) { @@ -255,8 +269,9 @@ bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *pr } btScalar GodotContactPairContactResultCallback::addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) { - if (m_count >= m_resultMax) + if (m_count >= m_resultMax) { return 1; // not used by bullet + } if (m_self_object == colObj0Wrap->getCollisionObject()) { B_TO_G(cp.m_localPointA, m_results[m_count * 2 + 0]); // Local contact @@ -278,11 +293,13 @@ bool GodotRestInfoContactResultCallback::needsCollision(btBroadphaseProxy *proxy CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { - if (!collide_with_areas) + if (!collide_with_areas) { return false; + } } else { - if (!collide_with_bodies) + if (!collide_with_bodies) { return false; + } } if (m_exclude->has(gObj->get_self())) { @@ -295,7 +312,6 @@ bool GodotRestInfoContactResultCallback::needsCollision(btBroadphaseProxy *proxy } btScalar GodotRestInfoContactResultCallback::addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) { - if (cp.getDistance() <= m_min_distance) { m_min_distance = cp.getDistance(); @@ -325,7 +341,6 @@ btScalar GodotRestInfoContactResultCallback::addSingleResult(btManifoldPoint &cp } void GodotDeepPenetrationContactResultCallback::addContactPoint(const btVector3 &normalOnBInWorld, const btVector3 &pointInWorldOnB, btScalar depth) { - if (m_penetration_distance > depth) { // Has penetration? const bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject(); diff --git a/modules/bullet/godot_result_callbacks.h b/modules/bullet/godot_result_callbacks.h index 4f634ed6f0..1325542973 100644 --- a/modules/bullet/godot_result_callbacks.h +++ b/modules/bullet/godot_result_callbacks.h @@ -31,7 +31,7 @@ #ifndef GODOT_RESULT_CALLBACKS_H #define GODOT_RESULT_CALLBACKS_H -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" #include <BulletCollision/BroadphaseCollision/btBroadphaseProxy.h> #include <btBulletDynamicsCommon.h> @@ -56,8 +56,8 @@ struct GodotFilterCallback : public btOverlapFilterCallback { /// It performs an additional check allow exclusions. struct GodotClosestRayResultCallback : public btCollisionWorld::ClosestRayResultCallback { const Set<RID> *m_exclude; - bool m_pickRay; - int m_shapeId; + bool m_pickRay = false; + int m_shapeId = 0; bool collide_with_bodies; bool collide_with_areas; @@ -66,18 +66,17 @@ public: GodotClosestRayResultCallback(const btVector3 &rayFromWorld, const btVector3 &rayToWorld, const Set<RID> *p_exclude, bool p_collide_with_bodies, bool p_collide_with_areas) : btCollisionWorld::ClosestRayResultCallback(rayFromWorld, rayToWorld), m_exclude(p_exclude), - m_pickRay(false), - m_shapeId(0), collide_with_bodies(p_collide_with_bodies), collide_with_areas(p_collide_with_areas) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult &rayResult, bool normalInWorldSpace) { - if (rayResult.m_localShapeInfo) + if (rayResult.m_localShapeInfo) { m_shapeId = rayResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID - else + } else { m_shapeId = 0; + } return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace); } }; @@ -85,16 +84,15 @@ public: // store all colliding object struct GodotAllConvexResultCallback : public btCollisionWorld::ConvexResultCallback { public: - PhysicsDirectSpaceState::ShapeResult *m_results; + PhysicsDirectSpaceState3D::ShapeResult *m_results; int m_resultMax; const Set<RID> *m_exclude; - int count; + int count = 0; - GodotAllConvexResultCallback(PhysicsDirectSpaceState::ShapeResult *p_results, int p_resultMax, const Set<RID> *p_exclude) : + GodotAllConvexResultCallback(PhysicsDirectSpaceState3D::ShapeResult *p_results, int p_resultMax, const Set<RID> *p_exclude) : m_results(p_results), m_resultMax(p_resultMax), - m_exclude(p_exclude), - count(0) {} + m_exclude(p_exclude) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; @@ -117,7 +115,7 @@ public: struct GodotClosestConvexResultCallback : public btCollisionWorld::ClosestConvexResultCallback { public: const Set<RID> *m_exclude; - int m_shapeId; + int m_shapeId = 0; bool collide_with_bodies; bool collide_with_areas; @@ -125,7 +123,6 @@ public: GodotClosestConvexResultCallback(const btVector3 &convexFromWorld, const btVector3 &convexToWorld, const Set<RID> *p_exclude, bool p_collide_with_bodies, bool p_collide_with_areas) : btCollisionWorld::ClosestConvexResultCallback(convexFromWorld, convexToWorld), m_exclude(p_exclude), - m_shapeId(0), collide_with_bodies(p_collide_with_bodies), collide_with_areas(p_collide_with_areas) {} @@ -137,20 +134,19 @@ public: struct GodotAllContactResultCallback : public btCollisionWorld::ContactResultCallback { public: const btCollisionObject *m_self_object; - PhysicsDirectSpaceState::ShapeResult *m_results; + PhysicsDirectSpaceState3D::ShapeResult *m_results; int m_resultMax; const Set<RID> *m_exclude; - int m_count; + int m_count = 0; bool collide_with_bodies; bool collide_with_areas; - GodotAllContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState::ShapeResult *p_results, int p_resultMax, const Set<RID> *p_exclude, bool p_collide_with_bodies, bool p_collide_with_areas) : + GodotAllContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState3D::ShapeResult *p_results, int p_resultMax, const Set<RID> *p_exclude, bool p_collide_with_bodies, bool p_collide_with_areas) : m_self_object(p_self_object), m_results(p_results), m_resultMax(p_resultMax), m_exclude(p_exclude), - m_count(0), collide_with_bodies(p_collide_with_bodies), collide_with_areas(p_collide_with_areas) {} @@ -166,7 +162,7 @@ public: Vector3 *m_results; int m_resultMax; const Set<RID> *m_exclude; - int m_count; + int m_count = 0; bool collide_with_bodies; bool collide_with_areas; @@ -176,7 +172,6 @@ public: m_results(p_results), m_resultMax(p_resultMax), m_exclude(p_exclude), - m_count(0), collide_with_bodies(p_collide_with_bodies), collide_with_areas(p_collide_with_areas) {} @@ -188,21 +183,19 @@ public: struct GodotRestInfoContactResultCallback : public btCollisionWorld::ContactResultCallback { public: const btCollisionObject *m_self_object; - PhysicsDirectSpaceState::ShapeRestInfo *m_result; + PhysicsDirectSpaceState3D::ShapeRestInfo *m_result; const Set<RID> *m_exclude; - bool m_collided; - real_t m_min_distance; + bool m_collided = false; + real_t m_min_distance = 0; const btCollisionObject *m_rest_info_collision_object; btVector3 m_rest_info_bt_point; bool collide_with_bodies; bool collide_with_areas; - GodotRestInfoContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState::ShapeRestInfo *p_result, const Set<RID> *p_exclude, bool p_collide_with_bodies, bool p_collide_with_areas) : + GodotRestInfoContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState3D::ShapeRestInfo *p_result, const Set<RID> *p_exclude, bool p_collide_with_bodies, bool p_collide_with_areas) : m_self_object(p_self_object), m_result(p_result), m_exclude(p_exclude), - m_collided(false), - m_min_distance(0), collide_with_bodies(p_collide_with_bodies), collide_with_areas(p_collide_with_areas) {} @@ -214,13 +207,11 @@ public: struct GodotDeepPenetrationContactResultCallback : public btManifoldResult { btVector3 m_pointNormalWorld; btVector3 m_pointWorld; - btScalar m_penetration_distance; - int m_other_compound_shape_index; + btScalar m_penetration_distance = 0; + int m_other_compound_shape_index = 0; GodotDeepPenetrationContactResultCallback(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap) : - btManifoldResult(body0Wrap, body1Wrap), - m_penetration_distance(0), - m_other_compound_shape_index(0) {} + btManifoldResult(body0Wrap, body1Wrap) {} void reset() { m_penetration_distance = 0; diff --git a/modules/bullet/hinge_joint_bullet.cpp b/modules/bullet/hinge_joint_bullet.cpp index 49e67bfbc1..2338277565 100644 --- a/modules/bullet/hinge_joint_bullet.cpp +++ b/modules/bullet/hinge_joint_bullet.cpp @@ -42,7 +42,6 @@ HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameA, const Transform &frameB) : JointBullet() { - Transform scaled_AFrame(frameA.scaled(rbA->get_body_scale())); scaled_AFrame.basis.rotref_posscale_decomposition(scaled_AFrame.basis); @@ -50,7 +49,6 @@ HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, c G_TO_B(scaled_AFrame, btFrameA); if (rbB) { - Transform scaled_BFrame(frameB.scaled(rbB->get_body_scale())); scaled_BFrame.basis.rotref_posscale_decomposition(scaled_BFrame.basis); @@ -59,7 +57,6 @@ HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, c hingeConstraint = bulletnew(btHingeConstraint(*rbA->get_bt_rigid_body(), *rbB->get_bt_rigid_body(), btFrameA, btFrameB)); } else { - hingeConstraint = bulletnew(btHingeConstraint(*rbA->get_bt_rigid_body(), btFrameA)); } @@ -68,7 +65,6 @@ HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, c HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Vector3 &pivotInA, const Vector3 &pivotInB, const Vector3 &axisInA, const Vector3 &axisInB) : JointBullet() { - btVector3 btPivotA; btVector3 btAxisA; G_TO_B(pivotInA * rbA->get_body_scale(), btPivotA); @@ -82,7 +78,6 @@ HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, c hingeConstraint = bulletnew(btHingeConstraint(*rbA->get_bt_rigid_body(), *rbB->get_bt_rigid_body(), btPivotA, btPivotB, btAxisA, btAxisB)); } else { - hingeConstraint = bulletnew(btHingeConstraint(*rbA->get_bt_rigid_body(), btPivotA, btAxisA)); } @@ -93,79 +88,85 @@ real_t HingeJointBullet::get_hinge_angle() { return hingeConstraint->getHingeAngle(); } -void HingeJointBullet::set_param(PhysicsServer::HingeJointParam p_param, real_t p_value) { +void HingeJointBullet::set_param(PhysicsServer3D::HingeJointParam p_param, real_t p_value) { switch (p_param) { - case PhysicsServer::HINGE_JOINT_LIMIT_UPPER: + case PhysicsServer3D::HINGE_JOINT_BIAS: + WARN_DEPRECATED_MSG("The HingeJoint3D parameter \"bias\" is deprecated."); + break; + case PhysicsServer3D::HINGE_JOINT_LIMIT_UPPER: hingeConstraint->setLimit(hingeConstraint->getLowerLimit(), p_value, hingeConstraint->getLimitSoftness(), hingeConstraint->getLimitBiasFactor(), hingeConstraint->getLimitRelaxationFactor()); break; - case PhysicsServer::HINGE_JOINT_LIMIT_LOWER: + case PhysicsServer3D::HINGE_JOINT_LIMIT_LOWER: hingeConstraint->setLimit(p_value, hingeConstraint->getUpperLimit(), hingeConstraint->getLimitSoftness(), hingeConstraint->getLimitBiasFactor(), hingeConstraint->getLimitRelaxationFactor()); break; - case PhysicsServer::HINGE_JOINT_LIMIT_BIAS: + case PhysicsServer3D::HINGE_JOINT_LIMIT_BIAS: hingeConstraint->setLimit(hingeConstraint->getLowerLimit(), hingeConstraint->getUpperLimit(), hingeConstraint->getLimitSoftness(), p_value, hingeConstraint->getLimitRelaxationFactor()); break; - case PhysicsServer::HINGE_JOINT_LIMIT_SOFTNESS: + case PhysicsServer3D::HINGE_JOINT_LIMIT_SOFTNESS: hingeConstraint->setLimit(hingeConstraint->getLowerLimit(), hingeConstraint->getUpperLimit(), p_value, hingeConstraint->getLimitBiasFactor(), hingeConstraint->getLimitRelaxationFactor()); break; - case PhysicsServer::HINGE_JOINT_LIMIT_RELAXATION: + case PhysicsServer3D::HINGE_JOINT_LIMIT_RELAXATION: hingeConstraint->setLimit(hingeConstraint->getLowerLimit(), hingeConstraint->getUpperLimit(), hingeConstraint->getLimitSoftness(), hingeConstraint->getLimitBiasFactor(), p_value); break; - case PhysicsServer::HINGE_JOINT_MOTOR_TARGET_VELOCITY: + case PhysicsServer3D::HINGE_JOINT_MOTOR_TARGET_VELOCITY: hingeConstraint->setMotorTargetVelocity(p_value); break; - case PhysicsServer::HINGE_JOINT_MOTOR_MAX_IMPULSE: + case PhysicsServer3D::HINGE_JOINT_MOTOR_MAX_IMPULSE: hingeConstraint->setMaxMotorImpulse(p_value); break; - default: - WARN_DEPRECATED_MSG("The HingeJoint parameter " + itos(p_param) + " is deprecated."); + case PhysicsServer3D::HINGE_JOINT_MAX: + // Internal size value, nothing to do. break; } } -real_t HingeJointBullet::get_param(PhysicsServer::HingeJointParam p_param) const { +real_t HingeJointBullet::get_param(PhysicsServer3D::HingeJointParam p_param) const { switch (p_param) { - case PhysicsServer::HINGE_JOINT_BIAS: + case PhysicsServer3D::HINGE_JOINT_BIAS: + WARN_DEPRECATED_MSG("The HingeJoint3D parameter \"bias\" is deprecated."); return 0; - break; - case PhysicsServer::HINGE_JOINT_LIMIT_UPPER: + case PhysicsServer3D::HINGE_JOINT_LIMIT_UPPER: return hingeConstraint->getUpperLimit(); - case PhysicsServer::HINGE_JOINT_LIMIT_LOWER: + case PhysicsServer3D::HINGE_JOINT_LIMIT_LOWER: return hingeConstraint->getLowerLimit(); - case PhysicsServer::HINGE_JOINT_LIMIT_BIAS: + case PhysicsServer3D::HINGE_JOINT_LIMIT_BIAS: return hingeConstraint->getLimitBiasFactor(); - case PhysicsServer::HINGE_JOINT_LIMIT_SOFTNESS: + case PhysicsServer3D::HINGE_JOINT_LIMIT_SOFTNESS: return hingeConstraint->getLimitSoftness(); - case PhysicsServer::HINGE_JOINT_LIMIT_RELAXATION: + case PhysicsServer3D::HINGE_JOINT_LIMIT_RELAXATION: return hingeConstraint->getLimitRelaxationFactor(); - case PhysicsServer::HINGE_JOINT_MOTOR_TARGET_VELOCITY: + case PhysicsServer3D::HINGE_JOINT_MOTOR_TARGET_VELOCITY: return hingeConstraint->getMotorTargetVelocity(); - case PhysicsServer::HINGE_JOINT_MOTOR_MAX_IMPULSE: + case PhysicsServer3D::HINGE_JOINT_MOTOR_MAX_IMPULSE: return hingeConstraint->getMaxMotorImpulse(); - default: - WARN_DEPRECATED_MSG("The HingeJoint parameter " + itos(p_param) + " is deprecated."); + case PhysicsServer3D::HINGE_JOINT_MAX: + // Internal size value, nothing to do. return 0; } + // Compiler doesn't seem to notice that all code paths are fulfilled... + return 0; } -void HingeJointBullet::set_flag(PhysicsServer::HingeJointFlag p_flag, bool p_value) { +void HingeJointBullet::set_flag(PhysicsServer3D::HingeJointFlag p_flag, bool p_value) { switch (p_flag) { - case PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT: + case PhysicsServer3D::HINGE_JOINT_FLAG_USE_LIMIT: if (!p_value) { hingeConstraint->setLimit(-Math_PI, Math_PI); } break; - case PhysicsServer::HINGE_JOINT_FLAG_ENABLE_MOTOR: + case PhysicsServer3D::HINGE_JOINT_FLAG_ENABLE_MOTOR: hingeConstraint->enableMotor(p_value); break; - case PhysicsServer::HINGE_JOINT_FLAG_MAX: break; // Can't happen, but silences warning + case PhysicsServer3D::HINGE_JOINT_FLAG_MAX: + break; // Can't happen, but silences warning } } -bool HingeJointBullet::get_flag(PhysicsServer::HingeJointFlag p_flag) const { +bool HingeJointBullet::get_flag(PhysicsServer3D::HingeJointFlag p_flag) const { switch (p_flag) { - case PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT: + case PhysicsServer3D::HINGE_JOINT_FLAG_USE_LIMIT: return true; - case PhysicsServer::HINGE_JOINT_FLAG_ENABLE_MOTOR: + case PhysicsServer3D::HINGE_JOINT_FLAG_ENABLE_MOTOR: return hingeConstraint->getEnableAngularMotor(); default: return false; diff --git a/modules/bullet/hinge_joint_bullet.h b/modules/bullet/hinge_joint_bullet.h index d1061fe52f..120c40e5c0 100644 --- a/modules/bullet/hinge_joint_bullet.h +++ b/modules/bullet/hinge_joint_bullet.h @@ -44,14 +44,14 @@ public: HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameA, const Transform &frameB); HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Vector3 &pivotInA, const Vector3 &pivotInB, const Vector3 &axisInA, const Vector3 &axisInB); - virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_HINGE; } + virtual PhysicsServer3D::JointType get_type() const { return PhysicsServer3D::JOINT_HINGE; } real_t get_hinge_angle(); - void set_param(PhysicsServer::HingeJointParam p_param, real_t p_value); - real_t get_param(PhysicsServer::HingeJointParam p_param) const; + void set_param(PhysicsServer3D::HingeJointParam p_param, real_t p_value); + real_t get_param(PhysicsServer3D::HingeJointParam p_param) const; - void set_flag(PhysicsServer::HingeJointFlag p_flag, bool p_value); - bool get_flag(PhysicsServer::HingeJointFlag p_flag) const; + void set_flag(PhysicsServer3D::HingeJointFlag p_flag, bool p_value); + bool get_flag(PhysicsServer3D::HingeJointFlag p_flag) const; }; #endif diff --git a/modules/bullet/joint_bullet.h b/modules/bullet/joint_bullet.h index c840eb8f14..c70cea817e 100644 --- a/modules/bullet/joint_bullet.h +++ b/modules/bullet/joint_bullet.h @@ -32,7 +32,7 @@ #define JOINT_BULLET_H #include "constraint_bullet.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" /** @author AndreaCatania @@ -42,11 +42,10 @@ class RigidBodyBullet; class btTypedConstraint; class JointBullet : public ConstraintBullet { - public: JointBullet(); virtual ~JointBullet(); - virtual PhysicsServer::JointType get_type() const = 0; + virtual PhysicsServer3D::JointType get_type() const = 0; }; #endif diff --git a/modules/bullet/pin_joint_bullet.cpp b/modules/bullet/pin_joint_bullet.cpp index 1c2e5e65cc..1cfbc65c78 100644 --- a/modules/bullet/pin_joint_bullet.cpp +++ b/modules/bullet/pin_joint_bullet.cpp @@ -42,7 +42,6 @@ PinJointBullet::PinJointBullet(RigidBodyBullet *p_body_a, const Vector3 &p_pos_a, RigidBodyBullet *p_body_b, const Vector3 &p_pos_b) : JointBullet() { if (p_body_b) { - btVector3 btPivotA; btVector3 btPivotB; G_TO_B(p_pos_a * p_body_a->get_body_scale(), btPivotA); @@ -62,32 +61,31 @@ PinJointBullet::PinJointBullet(RigidBodyBullet *p_body_a, const Vector3 &p_pos_a PinJointBullet::~PinJointBullet() {} -void PinJointBullet::set_param(PhysicsServer::PinJointParam p_param, real_t p_value) { +void PinJointBullet::set_param(PhysicsServer3D::PinJointParam p_param, real_t p_value) { switch (p_param) { - case PhysicsServer::PIN_JOINT_BIAS: + case PhysicsServer3D::PIN_JOINT_BIAS: p2pConstraint->m_setting.m_tau = p_value; break; - case PhysicsServer::PIN_JOINT_DAMPING: + case PhysicsServer3D::PIN_JOINT_DAMPING: p2pConstraint->m_setting.m_damping = p_value; break; - case PhysicsServer::PIN_JOINT_IMPULSE_CLAMP: + case PhysicsServer3D::PIN_JOINT_IMPULSE_CLAMP: p2pConstraint->m_setting.m_impulseClamp = p_value; break; } } -real_t PinJointBullet::get_param(PhysicsServer::PinJointParam p_param) const { +real_t PinJointBullet::get_param(PhysicsServer3D::PinJointParam p_param) const { switch (p_param) { - case PhysicsServer::PIN_JOINT_BIAS: + case PhysicsServer3D::PIN_JOINT_BIAS: return p2pConstraint->m_setting.m_tau; - case PhysicsServer::PIN_JOINT_DAMPING: + case PhysicsServer3D::PIN_JOINT_DAMPING: return p2pConstraint->m_setting.m_damping; - case PhysicsServer::PIN_JOINT_IMPULSE_CLAMP: + case PhysicsServer3D::PIN_JOINT_IMPULSE_CLAMP: return p2pConstraint->m_setting.m_impulseClamp; - default: - WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated."); - return 0; } + // Compiler doesn't seem to notice that all code paths are fulfilled... + return 0; } void PinJointBullet::setPivotInA(const Vector3 &p_pos) { diff --git a/modules/bullet/pin_joint_bullet.h b/modules/bullet/pin_joint_bullet.h index d6e7a945b5..e7d05f34d4 100644 --- a/modules/bullet/pin_joint_bullet.h +++ b/modules/bullet/pin_joint_bullet.h @@ -46,10 +46,10 @@ public: PinJointBullet(RigidBodyBullet *p_body_a, const Vector3 &p_pos_a, RigidBodyBullet *p_body_b, const Vector3 &p_pos_b); ~PinJointBullet(); - virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_PIN; } + virtual PhysicsServer3D::JointType get_type() const { return PhysicsServer3D::JOINT_PIN; } - void set_param(PhysicsServer::PinJointParam p_param, real_t p_value); - real_t get_param(PhysicsServer::PinJointParam p_param) const; + void set_param(PhysicsServer3D::PinJointParam p_param, real_t p_value); + real_t get_param(PhysicsServer3D::PinJointParam p_param) const; void setPivotInA(const Vector3 &p_pos); void setPivotInB(const Vector3 &p_pos); diff --git a/modules/bullet/register_types.cpp b/modules/bullet/register_types.cpp index 7819b67cad..009d0dff63 100644 --- a/modules/bullet/register_types.cpp +++ b/modules/bullet/register_types.cpp @@ -39,15 +39,15 @@ */ #ifndef _3D_DISABLED -PhysicsServer *_createBulletPhysicsCallback() { - return memnew(BulletPhysicsServer); +PhysicsServer3D *_createBulletPhysicsCallback() { + return memnew(BulletPhysicsServer3D); } #endif void register_bullet_types() { #ifndef _3D_DISABLED - PhysicsServerManager::register_server("Bullet", &_createBulletPhysicsCallback); - PhysicsServerManager::set_default_server("Bullet", 1); + PhysicsServer3DManager::register_server("Bullet", &_createBulletPhysicsCallback); + PhysicsServer3DManager::set_default_server("Bullet", 1); GLOBAL_DEF("physics/3d/active_soft_world", true); ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/active_soft_world", PropertyInfo(Variant::BOOL, "physics/3d/active_soft_world")); diff --git a/modules/bullet/rid_bullet.h b/modules/bullet/rid_bullet.h index 28bcedb01a..3551ca05f9 100644 --- a/modules/bullet/rid_bullet.h +++ b/modules/bullet/rid_bullet.h @@ -37,17 +37,17 @@ @author AndreaCatania */ -class BulletPhysicsServer; +class BulletPhysicsServer3D; -class RIDBullet : public RID_Data { +class RIDBullet { RID self; - BulletPhysicsServer *physicsServer; + BulletPhysicsServer3D *physicsServer; public: _FORCE_INLINE_ void set_self(const RID &p_self) { self = p_self; } _FORCE_INLINE_ RID get_self() const { return self; } - _FORCE_INLINE_ void _set_physics_server(BulletPhysicsServer *p_physicsServer) { physicsServer = p_physicsServer; } - _FORCE_INLINE_ BulletPhysicsServer *get_physics_server() const { return physicsServer; } + _FORCE_INLINE_ void _set_physics_server(BulletPhysicsServer3D *p_physicsServer) { physicsServer = p_physicsServer; } + _FORCE_INLINE_ BulletPhysicsServer3D *get_physics_server() const { return physicsServer; } }; #endif diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index 16a8cf8ede..f517eecf64 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -48,142 +48,140 @@ @author AndreaCatania */ -BulletPhysicsDirectBodyState *BulletPhysicsDirectBodyState::singleton = NULL; +BulletPhysicsDirectBodyState3D *BulletPhysicsDirectBodyState3D::singleton = nullptr; -Vector3 BulletPhysicsDirectBodyState::get_total_gravity() const { - Vector3 gVec; - B_TO_G(body->btBody->getGravity(), gVec); - return gVec; +Vector3 BulletPhysicsDirectBodyState3D::get_total_gravity() const { + return body->total_gravity; } -float BulletPhysicsDirectBodyState::get_total_angular_damp() const { +float BulletPhysicsDirectBodyState3D::get_total_angular_damp() const { return body->btBody->getAngularDamping(); } -float BulletPhysicsDirectBodyState::get_total_linear_damp() const { +float BulletPhysicsDirectBodyState3D::get_total_linear_damp() const { return body->btBody->getLinearDamping(); } -Vector3 BulletPhysicsDirectBodyState::get_center_of_mass() const { +Vector3 BulletPhysicsDirectBodyState3D::get_center_of_mass() const { Vector3 gVec; B_TO_G(body->btBody->getCenterOfMassPosition(), gVec); return gVec; } -Basis BulletPhysicsDirectBodyState::get_principal_inertia_axes() const { +Basis BulletPhysicsDirectBodyState3D::get_principal_inertia_axes() const { return Basis(); } -float BulletPhysicsDirectBodyState::get_inverse_mass() const { +float BulletPhysicsDirectBodyState3D::get_inverse_mass() const { return body->btBody->getInvMass(); } -Vector3 BulletPhysicsDirectBodyState::get_inverse_inertia() const { +Vector3 BulletPhysicsDirectBodyState3D::get_inverse_inertia() const { Vector3 gVec; B_TO_G(body->btBody->getInvInertiaDiagLocal(), gVec); return gVec; } -Basis BulletPhysicsDirectBodyState::get_inverse_inertia_tensor() const { +Basis BulletPhysicsDirectBodyState3D::get_inverse_inertia_tensor() const { Basis gInertia; B_TO_G(body->btBody->getInvInertiaTensorWorld(), gInertia); return gInertia; } -void BulletPhysicsDirectBodyState::set_linear_velocity(const Vector3 &p_velocity) { +void BulletPhysicsDirectBodyState3D::set_linear_velocity(const Vector3 &p_velocity) { body->set_linear_velocity(p_velocity); } -Vector3 BulletPhysicsDirectBodyState::get_linear_velocity() const { +Vector3 BulletPhysicsDirectBodyState3D::get_linear_velocity() const { return body->get_linear_velocity(); } -void BulletPhysicsDirectBodyState::set_angular_velocity(const Vector3 &p_velocity) { +void BulletPhysicsDirectBodyState3D::set_angular_velocity(const Vector3 &p_velocity) { body->set_angular_velocity(p_velocity); } -Vector3 BulletPhysicsDirectBodyState::get_angular_velocity() const { +Vector3 BulletPhysicsDirectBodyState3D::get_angular_velocity() const { return body->get_angular_velocity(); } -void BulletPhysicsDirectBodyState::set_transform(const Transform &p_transform) { +void BulletPhysicsDirectBodyState3D::set_transform(const Transform &p_transform) { body->set_transform(p_transform); } -Transform BulletPhysicsDirectBodyState::get_transform() const { +Transform BulletPhysicsDirectBodyState3D::get_transform() const { return body->get_transform(); } -void BulletPhysicsDirectBodyState::add_central_force(const Vector3 &p_force) { +void BulletPhysicsDirectBodyState3D::add_central_force(const Vector3 &p_force) { body->apply_central_force(p_force); } -void BulletPhysicsDirectBodyState::add_force(const Vector3 &p_force, const Vector3 &p_pos) { - body->apply_force(p_force, p_pos); +void BulletPhysicsDirectBodyState3D::add_force(const Vector3 &p_force, const Vector3 &p_position) { + body->apply_force(p_force, p_position); } -void BulletPhysicsDirectBodyState::add_torque(const Vector3 &p_torque) { +void BulletPhysicsDirectBodyState3D::add_torque(const Vector3 &p_torque) { body->apply_torque(p_torque); } -void BulletPhysicsDirectBodyState::apply_central_impulse(const Vector3 &p_impulse) { +void BulletPhysicsDirectBodyState3D::apply_central_impulse(const Vector3 &p_impulse) { body->apply_central_impulse(p_impulse); } -void BulletPhysicsDirectBodyState::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) { - body->apply_impulse(p_pos, p_impulse); +void BulletPhysicsDirectBodyState3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) { + body->apply_impulse(p_impulse, p_position); } -void BulletPhysicsDirectBodyState::apply_torque_impulse(const Vector3 &p_impulse) { +void BulletPhysicsDirectBodyState3D::apply_torque_impulse(const Vector3 &p_impulse) { body->apply_torque_impulse(p_impulse); } -void BulletPhysicsDirectBodyState::set_sleep_state(bool p_enable) { - body->set_activation_state(p_enable); +void BulletPhysicsDirectBodyState3D::set_sleep_state(bool p_sleep) { + body->set_activation_state(!p_sleep); } -bool BulletPhysicsDirectBodyState::is_sleeping() const { +bool BulletPhysicsDirectBodyState3D::is_sleeping() const { return !body->is_active(); } -int BulletPhysicsDirectBodyState::get_contact_count() const { +int BulletPhysicsDirectBodyState3D::get_contact_count() const { return body->collisionsCount; } -Vector3 BulletPhysicsDirectBodyState::get_contact_local_position(int p_contact_idx) const { +Vector3 BulletPhysicsDirectBodyState3D::get_contact_local_position(int p_contact_idx) const { return body->collisions[p_contact_idx].hitLocalLocation; } -Vector3 BulletPhysicsDirectBodyState::get_contact_local_normal(int p_contact_idx) const { +Vector3 BulletPhysicsDirectBodyState3D::get_contact_local_normal(int p_contact_idx) const { return body->collisions[p_contact_idx].hitNormal; } -float BulletPhysicsDirectBodyState::get_contact_impulse(int p_contact_idx) const { +float BulletPhysicsDirectBodyState3D::get_contact_impulse(int p_contact_idx) const { return body->collisions[p_contact_idx].appliedImpulse; } -int BulletPhysicsDirectBodyState::get_contact_local_shape(int p_contact_idx) const { +int BulletPhysicsDirectBodyState3D::get_contact_local_shape(int p_contact_idx) const { return body->collisions[p_contact_idx].local_shape; } -RID BulletPhysicsDirectBodyState::get_contact_collider(int p_contact_idx) const { +RID BulletPhysicsDirectBodyState3D::get_contact_collider(int p_contact_idx) const { return body->collisions[p_contact_idx].otherObject->get_self(); } -Vector3 BulletPhysicsDirectBodyState::get_contact_collider_position(int p_contact_idx) const { +Vector3 BulletPhysicsDirectBodyState3D::get_contact_collider_position(int p_contact_idx) const { return body->collisions[p_contact_idx].hitWorldLocation; } -ObjectID BulletPhysicsDirectBodyState::get_contact_collider_id(int p_contact_idx) const { +ObjectID BulletPhysicsDirectBodyState3D::get_contact_collider_id(int p_contact_idx) const { return body->collisions[p_contact_idx].otherObject->get_instance_id(); } -int BulletPhysicsDirectBodyState::get_contact_collider_shape(int p_contact_idx) const { +int BulletPhysicsDirectBodyState3D::get_contact_collider_shape(int p_contact_idx) const { return body->collisions[p_contact_idx].other_object_shape; } -Vector3 BulletPhysicsDirectBodyState::get_contact_collider_velocity_at_position(int p_contact_idx) const { - RigidBodyBullet::CollisionData &colDat = body->collisions.write[p_contact_idx]; +Vector3 BulletPhysicsDirectBodyState3D::get_contact_collider_velocity_at_position(int p_contact_idx) const { + RigidBodyBullet::CollisionData &colDat = body->collisions[p_contact_idx]; btVector3 hitLocation; G_TO_B(colDat.hitLocalLocation, hitLocation); @@ -194,7 +192,7 @@ Vector3 BulletPhysicsDirectBodyState::get_contact_collider_velocity_at_position( return velocityAtPoint; } -PhysicsDirectSpaceState *BulletPhysicsDirectBodyState::get_space_state() { +PhysicsDirectSpaceState3D *BulletPhysicsDirectBodyState3D::get_space_state() { return body->get_space()->get_direct_state(); } @@ -213,7 +211,7 @@ void RigidBodyBullet::KinematicUtilities::setSafeMargin(btScalar p_margin) { } void RigidBodyBullet::KinematicUtilities::copyAllOwnerShapes() { - const Vector<CollisionObjectBullet::ShapeWrapper> &shapes_wrappers(owner->get_shapes_wrappers()); + const LocalVector<CollisionObjectBullet::ShapeWrapper> &shapes_wrappers(owner->get_shapes_wrappers()); const int shapes_count = shapes_wrappers.size(); just_delete_shapes(shapes_count); @@ -228,20 +226,20 @@ void RigidBodyBullet::KinematicUtilities::copyAllOwnerShapes() { continue; } - shapes.write[i].transform = shape_wrapper->transform; - shapes.write[i].transform.getOrigin() *= owner_scale; + shapes[i].transform = shape_wrapper->transform; + shapes[i].transform.getOrigin() *= owner_scale; switch (shape_wrapper->shape->get_type()) { - case PhysicsServer::SHAPE_SPHERE: - case PhysicsServer::SHAPE_BOX: - case PhysicsServer::SHAPE_CAPSULE: - case PhysicsServer::SHAPE_CYLINDER: - case PhysicsServer::SHAPE_CONVEX_POLYGON: - case PhysicsServer::SHAPE_RAY: { - shapes.write[i].shape = static_cast<btConvexShape *>(shape_wrapper->shape->create_bt_shape(owner_scale * shape_wrapper->scale, safe_margin)); + case PhysicsServer3D::SHAPE_SPHERE: + case PhysicsServer3D::SHAPE_BOX: + case PhysicsServer3D::SHAPE_CAPSULE: + case PhysicsServer3D::SHAPE_CYLINDER: + case PhysicsServer3D::SHAPE_CONVEX_POLYGON: + case PhysicsServer3D::SHAPE_RAY: { + shapes[i].shape = static_cast<btConvexShape *>(shape_wrapper->shape->internal_create_bt_shape(owner_scale * shape_wrapper->scale, safe_margin)); } break; default: - WARN_PRINT("This shape is not supported to be kinematic!"); - shapes.write[i].shape = NULL; + WARN_PRINT("This shape is not supported for kinematic collision."); + shapes[i].shape = nullptr; } } } @@ -249,49 +247,30 @@ void RigidBodyBullet::KinematicUtilities::copyAllOwnerShapes() { void RigidBodyBullet::KinematicUtilities::just_delete_shapes(int new_size) { for (int i = shapes.size() - 1; 0 <= i; --i) { if (shapes[i].shape) { - bulletdelete(shapes.write[i].shape); + bulletdelete(shapes[i].shape); } } shapes.resize(new_size); } RigidBodyBullet::RigidBodyBullet() : - RigidCollisionObjectBullet(CollisionObjectBullet::TYPE_RIGID_BODY), - kinematic_utilities(NULL), - locked_axis(0), - mass(1), - gravity_scale(1), - linearDamp(0), - angularDamp(0), - can_sleep(true), - omit_forces_integration(false), - can_integrate_forces(false), - maxCollisionsDetection(0), - collisionsCount(0), - prev_collision_count(0), - maxAreasWhereIam(10), - areaWhereIamCount(0), - countGravityPointSpaces(0), - isScratchedSpaceOverrideModificator(false), - previousActiveState(true), - force_integration_callback(NULL) { - + RigidCollisionObjectBullet(CollisionObjectBullet::TYPE_RIGID_BODY) { godotMotionState = bulletnew(GodotMotionState(this)); // Initial properties const btVector3 localInertia(0, 0, 0); - btRigidBody::btRigidBodyConstructionInfo cInfo(mass, godotMotionState, NULL, localInertia); + btRigidBody::btRigidBodyConstructionInfo cInfo(mass, godotMotionState, nullptr, localInertia); btBody = bulletnew(btRigidBody(cInfo)); reload_shapes(); setupBulletCollisionObject(btBody); - set_mode(PhysicsServer::BODY_MODE_RIGID); + set_mode(PhysicsServer3D::BODY_MODE_RIGID); reload_axis_lock(); areasWhereIam.resize(maxAreasWhereIam); - for (int i = areasWhereIam.size() - 1; 0 <= i; --i) { - areasWhereIam.write[i] = NULL; + for (uint32_t i = 0; i < areasWhereIam.size(); i += 1) { + areasWhereIam[i] = nullptr; } btBody->setSleepingThresholds(0.2, 0.2); @@ -302,8 +281,9 @@ RigidBodyBullet::RigidBodyBullet() : RigidBodyBullet::~RigidBodyBullet() { bulletdelete(godotMotionState); - if (force_integration_callback) + if (force_integration_callback) { memdelete(force_integration_callback); + } destroy_kinematic_utilities(); } @@ -315,21 +295,22 @@ void RigidBodyBullet::init_kinematic_utilities() { void RigidBodyBullet::destroy_kinematic_utilities() { if (kinematic_utilities) { memdelete(kinematic_utilities); - kinematic_utilities = NULL; + kinematic_utilities = nullptr; } } void RigidBodyBullet::main_shape_changed() { - CRASH_COND(!get_main_shape()) + CRASH_COND(!get_main_shape()); btBody->setCollisionShape(get_main_shape()); set_continuous_collision_detection(is_continuous_collision_detection_enabled()); // Reset } -void RigidBodyBullet::reload_body() { +void RigidBodyBullet::do_reload_body() { if (space) { space->remove_rigid_body(this); - if (get_main_shape()) + if (get_main_shape()) { space->add_rigid_body(this); + } } } @@ -337,65 +318,72 @@ void RigidBodyBullet::set_space(SpaceBullet *p_space) { // Clear the old space if there is one if (space) { can_integrate_forces = false; + isScratchedSpaceOverrideModificator = false; // Remove all eventual constraints assert_no_constraints(); // Remove this object form the physics world + space->unregister_collision_object(this); space->remove_rigid_body(this); } space = p_space; if (space) { - space->add_rigid_body(this); + space->register_collision_object(this); + reload_body(); + space->add_to_flush_queue(this); } } void RigidBodyBullet::dispatch_callbacks() { + RigidCollisionObjectBullet::dispatch_callbacks(); + /// The check isFirstTransformChanged is necessary in order to call integrated forces only when the first transform is sent if ((btBody->isKinematicObject() || btBody->isActive() || previousActiveState != btBody->isActive()) && force_integration_callback && can_integrate_forces) { - - if (omit_forces_integration) - btBody->clearForces(); - - BulletPhysicsDirectBodyState *bodyDirect = BulletPhysicsDirectBodyState::get_singleton(this); + BulletPhysicsDirectBodyState3D *bodyDirect = BulletPhysicsDirectBodyState3D::get_singleton(this); Variant variantBodyDirect = bodyDirect; Object *obj = ObjectDB::get_instance(force_integration_callback->id); if (!obj) { // Remove integration callback - set_force_integration_callback(0, StringName()); + set_force_integration_callback(ObjectID(), StringName()); } else { const Variant *vp[2] = { &variantBodyDirect, &force_integration_callback->udata }; - Variant::CallError responseCallError; + Callable::CallError responseCallError; int argc = (force_integration_callback->udata.get_type() == Variant::NIL) ? 1 : 2; obj->call(force_integration_callback->method, vp, argc, responseCallError); } } + previousActiveState = btBody->isActive(); +} + +void RigidBodyBullet::pre_process() { + RigidCollisionObjectBullet::pre_process(); + if (isScratchedSpaceOverrideModificator || 0 < countGravityPointSpaces) { isScratchedSpaceOverrideModificator = false; reload_space_override_modificator(); } - /// Lock axis - btBody->setLinearVelocity(btBody->getLinearVelocity() * btBody->getLinearFactor()); - btBody->setAngularVelocity(btBody->getAngularVelocity() * btBody->getAngularFactor()); - - previousActiveState = btBody->isActive(); + if (is_active()) { + /// Lock axis + btBody->setLinearVelocity(btBody->getLinearVelocity() * btBody->getLinearFactor()); + btBody->setAngularVelocity(btBody->getAngularVelocity() * btBody->getAngularFactor()); + } } void RigidBodyBullet::set_force_integration_callback(ObjectID p_id, const StringName &p_method, const Variant &p_udata) { - if (force_integration_callback) { memdelete(force_integration_callback); - force_integration_callback = NULL; + force_integration_callback = nullptr; } - if (p_id != 0) { + if (p_id.is_valid()) { force_integration_callback = memnew(ForceIntegrationCallback); force_integration_callback->id = p_id; force_integration_callback->method = p_method; @@ -407,7 +395,7 @@ void RigidBodyBullet::scratch_space_override_modificator() { isScratchedSpaceOverrideModificator = true; } -void RigidBodyBullet::on_collision_filters_change() { +void RigidBodyBullet::do_reload_collision_filters() { if (space) { space->reload_collision_filters(this); } @@ -416,28 +404,27 @@ void RigidBodyBullet::on_collision_filters_change() { } void RigidBodyBullet::on_collision_checker_start() { - prev_collision_count = collisionsCount; collisionsCount = 0; // Swap array - Vector<RigidBodyBullet *> *s = prev_collision_traces; - prev_collision_traces = curr_collision_traces; - curr_collision_traces = s; + SWAP(prev_collision_traces, curr_collision_traces); } void RigidBodyBullet::on_collision_checker_end() { // Always true if active and not a static or kinematic body isTransformChanged = btBody->isActive() && !btBody->isStaticOrKinematicObject(); + if (isTransformChanged && space != nullptr) { + space->add_to_flush_queue(this); + } } bool RigidBodyBullet::add_collision_object(RigidBodyBullet *p_otherObject, const Vector3 &p_hitWorldLocation, const Vector3 &p_hitLocalLocation, const Vector3 &p_hitNormal, const float &p_appliedImpulse, int p_other_shape_index, int p_local_shape_index) { - if (collisionsCount >= maxCollisionsDetection) { return false; } - CollisionData &cd = collisions.write[collisionsCount]; + CollisionData &cd = collisions[collisionsCount]; cd.hitLocalLocation = p_hitLocalLocation; cd.otherObject = p_otherObject; cd.hitWorldLocation = p_hitWorldLocation; @@ -446,7 +433,7 @@ bool RigidBodyBullet::add_collision_object(RigidBodyBullet *p_otherObject, const cd.other_object_shape = p_other_shape_index; cd.local_shape = p_local_shape_index; - curr_collision_traces->write[collisionsCount] = p_otherObject; + (*curr_collision_traces)[collisionsCount] = p_otherObject; ++collisionsCount; return true; @@ -454,8 +441,9 @@ bool RigidBodyBullet::add_collision_object(RigidBodyBullet *p_otherObject, const bool RigidBodyBullet::was_colliding(RigidBodyBullet *p_other_object) { for (int i = prev_collision_count - 1; 0 <= i; --i) { - if ((*prev_collision_traces)[i] == p_other_object) + if ((*prev_collision_traces)[i] == p_other_object) { return true; + } } return false; } @@ -464,11 +452,6 @@ void RigidBodyBullet::assert_no_constraints() { if (btBody->getNumConstraintRefs()) { WARN_PRINT("A body with a joints is destroyed. Please check the implementation in order to destroy the joint before the body."); } - /*for(int i = btBody->getNumConstraintRefs()-1; 0<=i; --i){ - btTypedConstraint* btConst = btBody->getConstraintRef(i); - JointBullet* joint = static_cast<JointBullet*>( btConst->getUserConstraintPtr() ); - space->removeConstraint(joint); - }*/ } void RigidBodyBullet::set_activation_state(bool p_active) { @@ -485,87 +468,91 @@ bool RigidBodyBullet::is_active() const { void RigidBodyBullet::set_omit_forces_integration(bool p_omit) { omit_forces_integration = p_omit; + scratch_space_override_modificator(); } -void RigidBodyBullet::set_param(PhysicsServer::BodyParameter p_param, real_t p_value) { +void RigidBodyBullet::set_param(PhysicsServer3D::BodyParameter p_param, real_t p_value) { switch (p_param) { - case PhysicsServer::BODY_PARAM_BOUNCE: + case PhysicsServer3D::BODY_PARAM_BOUNCE: btBody->setRestitution(p_value); break; - case PhysicsServer::BODY_PARAM_FRICTION: + case PhysicsServer3D::BODY_PARAM_FRICTION: btBody->setFriction(p_value); break; - case PhysicsServer::BODY_PARAM_MASS: { + case PhysicsServer3D::BODY_PARAM_MASS: { ERR_FAIL_COND(p_value < 0); mass = p_value; _internal_set_mass(p_value); break; } - case PhysicsServer::BODY_PARAM_LINEAR_DAMP: + case PhysicsServer3D::BODY_PARAM_LINEAR_DAMP: linearDamp = p_value; - btBody->setDamping(linearDamp, angularDamp); + // Mark for updating total linear damping. + scratch_space_override_modificator(); break; - case PhysicsServer::BODY_PARAM_ANGULAR_DAMP: + case PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP: angularDamp = p_value; - btBody->setDamping(linearDamp, angularDamp); + // Mark for updating total angular damping. + scratch_space_override_modificator(); break; - case PhysicsServer::BODY_PARAM_GRAVITY_SCALE: + case PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE: gravity_scale = p_value; - /// The Bullet gravity will be is set by reload_space_override_modificator + // The Bullet gravity will be is set by reload_space_override_modificator. + // Mark for updating total gravity scale. scratch_space_override_modificator(); break; default: - WARN_PRINTS("Parameter " + itos(p_param) + " not supported by bullet. Value: " + itos(p_value)); + WARN_PRINT("Parameter " + itos(p_param) + " not supported by bullet. Value: " + itos(p_value)); } } -real_t RigidBodyBullet::get_param(PhysicsServer::BodyParameter p_param) const { +real_t RigidBodyBullet::get_param(PhysicsServer3D::BodyParameter p_param) const { switch (p_param) { - case PhysicsServer::BODY_PARAM_BOUNCE: + case PhysicsServer3D::BODY_PARAM_BOUNCE: return btBody->getRestitution(); - case PhysicsServer::BODY_PARAM_FRICTION: + case PhysicsServer3D::BODY_PARAM_FRICTION: return btBody->getFriction(); - case PhysicsServer::BODY_PARAM_MASS: { + case PhysicsServer3D::BODY_PARAM_MASS: { const btScalar invMass = btBody->getInvMass(); return 0 == invMass ? 0 : 1 / invMass; } - case PhysicsServer::BODY_PARAM_LINEAR_DAMP: + case PhysicsServer3D::BODY_PARAM_LINEAR_DAMP: return linearDamp; - case PhysicsServer::BODY_PARAM_ANGULAR_DAMP: + case PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP: return angularDamp; - case PhysicsServer::BODY_PARAM_GRAVITY_SCALE: + case PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE: return gravity_scale; default: - WARN_PRINTS("Parameter " + itos(p_param) + " not supported by bullet"); + WARN_PRINT("Parameter " + itos(p_param) + " not supported by bullet"); return 0; } } -void RigidBodyBullet::set_mode(PhysicsServer::BodyMode p_mode) { +void RigidBodyBullet::set_mode(PhysicsServer3D::BodyMode p_mode) { // This is necessary to block force_integration untile next move can_integrate_forces = false; destroy_kinematic_utilities(); // The mode change is relevant to its mass switch (p_mode) { - case PhysicsServer::BODY_MODE_KINEMATIC: - mode = PhysicsServer::BODY_MODE_KINEMATIC; + case PhysicsServer3D::BODY_MODE_KINEMATIC: + mode = PhysicsServer3D::BODY_MODE_KINEMATIC; reload_axis_lock(); _internal_set_mass(0); init_kinematic_utilities(); break; - case PhysicsServer::BODY_MODE_STATIC: - mode = PhysicsServer::BODY_MODE_STATIC; + case PhysicsServer3D::BODY_MODE_STATIC: + mode = PhysicsServer3D::BODY_MODE_STATIC; reload_axis_lock(); _internal_set_mass(0); break; - case PhysicsServer::BODY_MODE_RIGID: - mode = PhysicsServer::BODY_MODE_RIGID; + case PhysicsServer3D::BODY_MODE_RIGID: + mode = PhysicsServer3D::BODY_MODE_RIGID; reload_axis_lock(); _internal_set_mass(0 == mass ? 1 : mass); scratch_space_override_modificator(); break; - case PhysicsServer::BODY_MODE_CHARACTER: - mode = PhysicsServer::BODY_MODE_CHARACTER; + case PhysicsServer3D::BODY_MODE_CHARACTER: + mode = PhysicsServer3D::BODY_MODE_CHARACTER; reload_axis_lock(); _internal_set_mass(0 == mass ? 1 : mass); scratch_space_override_modificator(); @@ -575,26 +562,26 @@ void RigidBodyBullet::set_mode(PhysicsServer::BodyMode p_mode) { btBody->setAngularVelocity(btVector3(0, 0, 0)); btBody->setLinearVelocity(btVector3(0, 0, 0)); } -PhysicsServer::BodyMode RigidBodyBullet::get_mode() const { + +PhysicsServer3D::BodyMode RigidBodyBullet::get_mode() const { return mode; } -void RigidBodyBullet::set_state(PhysicsServer::BodyState p_state, const Variant &p_variant) { - +void RigidBodyBullet::set_state(PhysicsServer3D::BodyState p_state, const Variant &p_variant) { switch (p_state) { - case PhysicsServer::BODY_STATE_TRANSFORM: + case PhysicsServer3D::BODY_STATE_TRANSFORM: set_transform(p_variant); break; - case PhysicsServer::BODY_STATE_LINEAR_VELOCITY: + case PhysicsServer3D::BODY_STATE_LINEAR_VELOCITY: set_linear_velocity(p_variant); break; - case PhysicsServer::BODY_STATE_ANGULAR_VELOCITY: + case PhysicsServer3D::BODY_STATE_ANGULAR_VELOCITY: set_angular_velocity(p_variant); break; - case PhysicsServer::BODY_STATE_SLEEPING: + case PhysicsServer3D::BODY_STATE_SLEEPING: set_activation_state(!bool(p_variant)); break; - case PhysicsServer::BODY_STATE_CAN_SLEEP: + case PhysicsServer3D::BODY_STATE_CAN_SLEEP: can_sleep = bool(p_variant); if (!can_sleep) { // Can't sleep @@ -606,81 +593,88 @@ void RigidBodyBullet::set_state(PhysicsServer::BodyState p_state, const Variant } } -Variant RigidBodyBullet::get_state(PhysicsServer::BodyState p_state) const { +Variant RigidBodyBullet::get_state(PhysicsServer3D::BodyState p_state) const { switch (p_state) { - case PhysicsServer::BODY_STATE_TRANSFORM: + case PhysicsServer3D::BODY_STATE_TRANSFORM: return get_transform(); - case PhysicsServer::BODY_STATE_LINEAR_VELOCITY: + case PhysicsServer3D::BODY_STATE_LINEAR_VELOCITY: return get_linear_velocity(); - case PhysicsServer::BODY_STATE_ANGULAR_VELOCITY: + case PhysicsServer3D::BODY_STATE_ANGULAR_VELOCITY: return get_angular_velocity(); - case PhysicsServer::BODY_STATE_SLEEPING: + case PhysicsServer3D::BODY_STATE_SLEEPING: return !is_active(); - case PhysicsServer::BODY_STATE_CAN_SLEEP: + case PhysicsServer3D::BODY_STATE_CAN_SLEEP: return can_sleep; default: - WARN_PRINTS("This state " + itos(p_state) + " is not supported by Bullet"); + WARN_PRINT("This state " + itos(p_state) + " is not supported by Bullet"); return Variant(); } } void RigidBodyBullet::apply_central_impulse(const Vector3 &p_impulse) { - btVector3 btImpu; - G_TO_B(p_impulse, btImpu); - if (Vector3() != p_impulse) + btVector3 btImpulse; + G_TO_B(p_impulse, btImpulse); + if (Vector3() != p_impulse) { btBody->activate(); - btBody->applyCentralImpulse(btImpu); + } + btBody->applyCentralImpulse(btImpulse); } -void RigidBodyBullet::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) { - btVector3 btImpu; - btVector3 btPos; - G_TO_B(p_impulse, btImpu); - G_TO_B(p_pos, btPos); - if (Vector3() != p_impulse) +void RigidBodyBullet::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) { + btVector3 btImpulse; + btVector3 btPosition; + G_TO_B(p_impulse, btImpulse); + G_TO_B(p_position, btPosition); + if (Vector3() != p_impulse) { btBody->activate(); - btBody->applyImpulse(btImpu, btPos); + } + btBody->applyImpulse(btImpulse, btPosition); } void RigidBodyBullet::apply_torque_impulse(const Vector3 &p_impulse) { btVector3 btImp; G_TO_B(p_impulse, btImp); - if (Vector3() != p_impulse) + if (Vector3() != p_impulse) { btBody->activate(); + } btBody->applyTorqueImpulse(btImp); } -void RigidBodyBullet::apply_force(const Vector3 &p_force, const Vector3 &p_pos) { +void RigidBodyBullet::apply_force(const Vector3 &p_force, const Vector3 &p_position) { btVector3 btForce; - btVector3 btPos; + btVector3 btPosition; G_TO_B(p_force, btForce); - G_TO_B(p_pos, btPos); - if (Vector3() != p_force) + G_TO_B(p_position, btPosition); + if (Vector3() != p_force) { btBody->activate(); - btBody->applyForce(btForce, btPos); + } + btBody->applyForce(btForce, btPosition); } void RigidBodyBullet::apply_central_force(const Vector3 &p_force) { btVector3 btForce; G_TO_B(p_force, btForce); - if (Vector3() != p_force) + if (Vector3() != p_force) { btBody->activate(); + } btBody->applyCentralForce(btForce); } void RigidBodyBullet::apply_torque(const Vector3 &p_torque) { btVector3 btTorq; G_TO_B(p_torque, btTorq); - if (Vector3() != p_torque) + if (Vector3() != p_torque) { btBody->activate(); + } btBody->applyTorque(btTorq); } void RigidBodyBullet::set_applied_force(const Vector3 &p_force) { btVector3 btVec = btBody->getTotalTorque(); - if (Vector3() != p_force) + if (Vector3() != p_force) { btBody->activate(); + } btBody->clearForces(); btBody->applyTorque(btVec); @@ -698,8 +692,9 @@ Vector3 RigidBodyBullet::get_applied_force() const { void RigidBodyBullet::set_applied_torque(const Vector3 &p_torque) { btVector3 btVec = btBody->getTotalForce(); - if (Vector3() != p_torque) + if (Vector3() != p_torque) { btBody->activate(); + } btBody->clearForces(); btBody->applyCentralForce(btVec); @@ -714,7 +709,7 @@ Vector3 RigidBodyBullet::get_applied_torque() const { return gTotTorq; } -void RigidBodyBullet::set_axis_lock(PhysicsServer::BodyAxis p_axis, bool lock) { +void RigidBodyBullet::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool lock) { if (lock) { locked_axis |= p_axis; } else { @@ -724,18 +719,17 @@ void RigidBodyBullet::set_axis_lock(PhysicsServer::BodyAxis p_axis, bool lock) { reload_axis_lock(); } -bool RigidBodyBullet::is_axis_locked(PhysicsServer::BodyAxis p_axis) const { +bool RigidBodyBullet::is_axis_locked(PhysicsServer3D::BodyAxis p_axis) const { return locked_axis & p_axis; } void RigidBodyBullet::reload_axis_lock() { - - btBody->setLinearFactor(btVector3(float(!is_axis_locked(PhysicsServer::BODY_AXIS_LINEAR_X)), float(!is_axis_locked(PhysicsServer::BODY_AXIS_LINEAR_Y)), float(!is_axis_locked(PhysicsServer::BODY_AXIS_LINEAR_Z)))); - if (PhysicsServer::BODY_MODE_CHARACTER == mode) { + btBody->setLinearFactor(btVector3(float(!is_axis_locked(PhysicsServer3D::BODY_AXIS_LINEAR_X)), float(!is_axis_locked(PhysicsServer3D::BODY_AXIS_LINEAR_Y)), float(!is_axis_locked(PhysicsServer3D::BODY_AXIS_LINEAR_Z)))); + if (PhysicsServer3D::BODY_MODE_CHARACTER == mode) { /// When character angular is always locked btBody->setAngularFactor(btVector3(0., 0., 0.)); } else { - btBody->setAngularFactor(btVector3(float(!is_axis_locked(PhysicsServer::BODY_AXIS_ANGULAR_X)), float(!is_axis_locked(PhysicsServer::BODY_AXIS_ANGULAR_Y)), float(!is_axis_locked(PhysicsServer::BODY_AXIS_ANGULAR_Z)))); + btBody->setAngularFactor(btVector3(float(!is_axis_locked(PhysicsServer3D::BODY_AXIS_ANGULAR_X)), float(!is_axis_locked(PhysicsServer3D::BODY_AXIS_ANGULAR_Y)), float(!is_axis_locked(PhysicsServer3D::BODY_AXIS_ANGULAR_Z)))); } } @@ -768,8 +762,9 @@ bool RigidBodyBullet::is_continuous_collision_detection_enabled() const { void RigidBodyBullet::set_linear_velocity(const Vector3 &p_velocity) { btVector3 btVec; G_TO_B(p_velocity, btVec); - if (Vector3() != p_velocity) + if (Vector3() != p_velocity) { btBody->activate(); + } btBody->setLinearVelocity(btVec); } @@ -782,8 +777,9 @@ Vector3 RigidBodyBullet::get_linear_velocity() const { void RigidBodyBullet::set_angular_velocity(const Vector3 &p_velocity) { btVector3 btVec; G_TO_B(p_velocity, btVec); - if (Vector3() != p_velocity) + if (Vector3() != p_velocity) { btBody->activate(); + } btBody->setAngularVelocity(btVec); } @@ -794,9 +790,10 @@ Vector3 RigidBodyBullet::get_angular_velocity() const { } void RigidBodyBullet::set_transform__bullet(const btTransform &p_global_transform) { - if (mode == PhysicsServer::BODY_MODE_KINEMATIC) { - if (space && space->get_delta_time() != 0) + if (mode == PhysicsServer3D::BODY_MODE_KINEMATIC) { + if (space && space->get_delta_time() != 0) { btBody->setLinearVelocity((p_global_transform.getOrigin() - btBody->getWorldTransform().getOrigin()) / space->get_delta_time()); + } // The kinematic use MotionState class godotMotionState->moveBody(p_global_transform); } else { @@ -808,16 +805,14 @@ void RigidBodyBullet::set_transform__bullet(const btTransform &p_global_transfor const btTransform &RigidBodyBullet::get_transform__bullet() const { if (is_static()) { - return RigidCollisionObjectBullet::get_transform__bullet(); } else { - return godotMotionState->getCurrentWorldTransform(); } } -void RigidBodyBullet::reload_shapes() { - RigidCollisionObjectBullet::reload_shapes(); +void RigidBodyBullet::do_reload_shapes() { + RigidCollisionObjectBullet::do_reload_shapes(); const btScalar invMass = btBody->getInvMass(); const btScalar mass = invMass == 0 ? 0 : 1 / invMass; @@ -827,8 +822,9 @@ void RigidBodyBullet::reload_shapes() { // shapes incorrectly do not set the vector in calculateLocalIntertia. // Arbitrary zero is preferable to undefined behaviour. btVector3 inertia(0, 0, 0); - if (EMPTY_SHAPE_PROXYTYPE != mainShape->getShapeType()) // Necessary to avoid assertion of the empty shape + if (EMPTY_SHAPE_PROXYTYPE != mainShape->getShapeType()) { // Necessary to avoid assertion of the empty shape mainShape->calculateLocalInertia(mass, inertia); + } btBody->setMassProps(mass, inertia); } btBody->updateInertiaTensor(); @@ -846,23 +842,22 @@ void RigidBodyBullet::on_enter_area(AreaBullet *p_area) { return; } for (int i = 0; i < areaWhereIamCount; ++i) { - - if (NULL == areasWhereIam[i]) { + if (nullptr == areasWhereIam[i]) { // This area has the highest priority - areasWhereIam.write[i] = p_area; + areasWhereIam[i] = p_area; break; } else { if (areasWhereIam[i]->get_spOv_priority() > p_area->get_spOv_priority()) { // The position was found, just shift all elements - for (int j = i; j < areaWhereIamCount; ++j) { - areasWhereIam.write[j + 1] = areasWhereIam[j]; + for (int j = areaWhereIamCount; j > i; j--) { + areasWhereIam[j] = areasWhereIam[j - 1]; } - areasWhereIam.write[i] = p_area; + areasWhereIam[i] = p_area; break; } } } - if (PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED != p_area->get_spOv_mode()) { + if (PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED != p_area->get_spOv_mode()) { scratch_space_override_modificator(); } @@ -881,7 +876,7 @@ void RigidBodyBullet::on_exit_area(AreaBullet *p_area) { if (p_area == areasWhereIam[i]) { // The area was found, just shift down all elements for (int j = i; j < areaWhereIamCount; ++j) { - areasWhereIam.write[j] = areasWhereIam[j + 1]; + areasWhereIam[j] = areasWhereIam[j + 1]; } wasTheAreaFound = true; break; @@ -894,51 +889,43 @@ void RigidBodyBullet::on_exit_area(AreaBullet *p_area) { } --areaWhereIamCount; - areasWhereIam.write[areaWhereIamCount] = NULL; // Even if this is not required, I clear the last element to be safe - if (PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED != p_area->get_spOv_mode()) { + areasWhereIam[areaWhereIamCount] = nullptr; // Even if this is not required, I clear the last element to be safe + if (PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED != p_area->get_spOv_mode()) { scratch_space_override_modificator(); } } } void RigidBodyBullet::reload_space_override_modificator() { - - // Make sure that kinematic bodies have their total gravity calculated - if (!is_active() && PhysicsServer::BODY_MODE_KINEMATIC != mode) + if (mode == PhysicsServer3D::BODY_MODE_STATIC) { return; + } - Vector3 newGravity(space->get_gravity_direction() * space->get_gravity_magnitude()); - real_t newLinearDamp(linearDamp); - real_t newAngularDamp(angularDamp); - - AreaBullet *currentArea; - // Variable used to calculate new gravity for gravity point areas, it is pointed by currentGravity pointer - Vector3 support_gravity(0, 0, 0); - - int countCombined(0); - for (int i = areaWhereIamCount - 1; 0 <= i; --i) { + Vector3 newGravity; + real_t newLinearDamp = MAX(0.0, linearDamp); + real_t newAngularDamp = MAX(0.0, angularDamp); - currentArea = areasWhereIam[i]; + bool stopped = false; + for (int i = 0; i < areaWhereIamCount && !stopped; i += 1) { + AreaBullet *currentArea = areasWhereIam[i]; - if (!currentArea || PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED == currentArea->get_spOv_mode()) { + if (!currentArea || PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED == currentArea->get_spOv_mode()) { continue; } + Vector3 support_gravity; + /// Here is calculated the gravity if (currentArea->is_spOv_gravityPoint()) { - /// It calculates the direction of new gravity support_gravity = currentArea->get_transform().xform(currentArea->get_spOv_gravityVec()) - get_transform().get_origin(); - real_t distanceMag = support_gravity.length(); + + const real_t distanceMag = support_gravity.length(); // Normalized in this way to avoid the double call of function "length()" if (distanceMag == 0) { - support_gravity.x = 0; - support_gravity.y = 0; - support_gravity.z = 0; + support_gravity = Vector3(); } else { - support_gravity.x /= distanceMag; - support_gravity.y /= distanceMag; - support_gravity.z /= distanceMag; + support_gravity /= distanceMag; } /// Here is calculated the final gravity @@ -954,58 +941,63 @@ void RigidBodyBullet::reload_space_override_modificator() { } switch (currentArea->get_spOv_mode()) { - case PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED: + case PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED: /// This area does not affect gravity/damp. These are generally areas /// that exist only to detect collisions, and objects entering or exiting them. break; - case PhysicsServer::AREA_SPACE_OVERRIDE_COMBINE: + case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE: /// This area adds its gravity/damp values to whatever has been /// calculated so far. This way, many overlapping areas can combine /// their physics to make interesting newGravity += support_gravity; newLinearDamp += currentArea->get_spOv_linearDamp(); newAngularDamp += currentArea->get_spOv_angularDamp(); - ++countCombined; break; - case PhysicsServer::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: + case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: /// This area adds its gravity/damp values to whatever has been calculated /// so far. Then stops taking into account the rest of the areas, even the /// default one. newGravity += support_gravity; newLinearDamp += currentArea->get_spOv_linearDamp(); newAngularDamp += currentArea->get_spOv_angularDamp(); - ++countCombined; - goto endAreasCycle; - case PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE: + stopped = true; + break; + case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE: /// This area replaces any gravity/damp, even the default one, and /// stops taking into account the rest of the areas. newGravity = support_gravity; newLinearDamp = currentArea->get_spOv_linearDamp(); newAngularDamp = currentArea->get_spOv_angularDamp(); - countCombined = 1; - goto endAreasCycle; - case PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: + stopped = true; + break; + case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: /// This area replaces any gravity/damp calculated so far, but keeps /// calculating the rest of the areas, down to the default one. newGravity = support_gravity; newLinearDamp = currentArea->get_spOv_linearDamp(); newAngularDamp = currentArea->get_spOv_angularDamp(); - countCombined = 1; break; } } -endAreasCycle: - if (1 < countCombined) { - newGravity /= countCombined; - newLinearDamp /= countCombined; - newAngularDamp /= countCombined; + // Add default gravity and damping from space. + if (!stopped) { + newGravity += space->get_gravity_direction() * space->get_gravity_magnitude(); + newLinearDamp += space->get_linear_damp(); + newAngularDamp += space->get_angular_damp(); } - btVector3 newBtGravity; - G_TO_B(newGravity * gravity_scale, newBtGravity); + total_gravity = newGravity; + + if (omit_forces_integration) { + // Custom behaviour. + btBody->setGravity(btVector3(0, 0, 0)); + } else { + btVector3 newBtGravity; + G_TO_B(newGravity * gravity_scale, newBtGravity); + btBody->setGravity(newBtGravity); + } - btBody->setGravity(newBtGravity); btBody->setDamping(newLinearDamp, newAngularDamp); } @@ -1022,7 +1014,6 @@ void RigidBodyBullet::notify_transform_changed() { } void RigidBodyBullet::_internal_set_mass(real_t p_mass) { - btVector3 localInertia(0, 0, 0); int clearedCurrentFlags = btBody->getCollisionFlags(); @@ -1031,19 +1022,18 @@ void RigidBodyBullet::_internal_set_mass(real_t p_mass) { // Rigidbody is dynamic if and only if mass is non Zero, otherwise static const bool isDynamic = p_mass != 0.f; if (isDynamic) { - - if (PhysicsServer::BODY_MODE_RIGID != mode && PhysicsServer::BODY_MODE_CHARACTER != mode) + if (PhysicsServer3D::BODY_MODE_RIGID != mode && PhysicsServer3D::BODY_MODE_CHARACTER != mode) { return; + } m_isStatic = false; - if (mainShape) + if (mainShape) { mainShape->calculateLocalInertia(p_mass, localInertia); + } - if (PhysicsServer::BODY_MODE_RIGID == mode) { - + if (PhysicsServer3D::BODY_MODE_RIGID == mode) { btBody->setCollisionFlags(clearedCurrentFlags); // Just set the flags without Kin and Static } else { - btBody->setCollisionFlags(clearedCurrentFlags | btCollisionObject::CF_CHARACTER_OBJECT); } @@ -1053,16 +1043,14 @@ void RigidBodyBullet::_internal_set_mass(real_t p_mass) { btBody->forceActivationState(DISABLE_DEACTIVATION); // DISABLE_DEACTIVATION 4 } } else { - - if (PhysicsServer::BODY_MODE_STATIC != mode && PhysicsServer::BODY_MODE_KINEMATIC != mode) + if (PhysicsServer3D::BODY_MODE_STATIC != mode && PhysicsServer3D::BODY_MODE_KINEMATIC != mode) { return; + } m_isStatic = true; - if (PhysicsServer::BODY_MODE_STATIC == mode) { - + if (PhysicsServer3D::BODY_MODE_STATIC == mode) { btBody->setCollisionFlags(clearedCurrentFlags | btCollisionObject::CF_STATIC_OBJECT); } else { - btBody->setCollisionFlags(clearedCurrentFlags | btCollisionObject::CF_KINEMATIC_OBJECT); set_transform__bullet(btBody->getWorldTransform()); // Set current Transform using kinematic method } diff --git a/modules/bullet/rigid_body_bullet.h b/modules/bullet/rigid_body_bullet.h index ca599f7a77..047645677b 100644 --- a/modules/bullet/rigid_body_bullet.h +++ b/modules/bullet/rigid_body_bullet.h @@ -45,37 +45,37 @@ class AreaBullet; class SpaceBullet; class btRigidBody; class GodotMotionState; -class BulletPhysicsDirectBodyState; +class BulletPhysicsDirectBodyState3D; /// This class could be used in multi thread with few changes but currently /// is set to be only in one single thread. /// /// In the system there is only one object at a time that manage all bodies and is -/// created by BulletPhysicsServer and is held by the "singleton" variable of this class +/// created by BulletPhysicsServer3D and is held by the "singleton" variable of this class /// Each time something require it, the body must be set again. -class BulletPhysicsDirectBodyState : public PhysicsDirectBodyState { - GDCLASS(BulletPhysicsDirectBodyState, PhysicsDirectBodyState); +class BulletPhysicsDirectBodyState3D : public PhysicsDirectBodyState3D { + GDCLASS(BulletPhysicsDirectBodyState3D, PhysicsDirectBodyState3D); - static BulletPhysicsDirectBodyState *singleton; + static BulletPhysicsDirectBodyState3D *singleton; public: /// This class avoid the creation of more object of this class static void initSingleton() { if (!singleton) { - singleton = memnew(BulletPhysicsDirectBodyState); + singleton = memnew(BulletPhysicsDirectBodyState3D); } } static void destroySingleton() { memdelete(singleton); - singleton = NULL; + singleton = nullptr; } static void singleton_setDeltaTime(real_t p_deltaTime) { singleton->deltaTime = p_deltaTime; } - static BulletPhysicsDirectBodyState *get_singleton(RigidBodyBullet *p_body) { + static BulletPhysicsDirectBodyState3D *get_singleton(RigidBodyBullet *p_body) { singleton->body = p_body; return singleton; } @@ -85,64 +85,63 @@ public: real_t deltaTime; private: - BulletPhysicsDirectBodyState() {} + BulletPhysicsDirectBodyState3D() {} public: - virtual Vector3 get_total_gravity() const; - virtual float get_total_angular_damp() const; - virtual float get_total_linear_damp() const; + virtual Vector3 get_total_gravity() const override; + virtual float get_total_angular_damp() const override; + virtual float get_total_linear_damp() const override; - virtual Vector3 get_center_of_mass() const; - virtual Basis get_principal_inertia_axes() const; + virtual Vector3 get_center_of_mass() const override; + virtual Basis get_principal_inertia_axes() const override; // get the mass - virtual float get_inverse_mass() const; + virtual float get_inverse_mass() const override; // get density of this body space - virtual Vector3 get_inverse_inertia() const; + virtual Vector3 get_inverse_inertia() const override; // get density of this body space - virtual Basis get_inverse_inertia_tensor() const; + virtual Basis get_inverse_inertia_tensor() const override; - virtual void set_linear_velocity(const Vector3 &p_velocity); - virtual Vector3 get_linear_velocity() const; + virtual void set_linear_velocity(const Vector3 &p_velocity) override; + virtual Vector3 get_linear_velocity() const override; - virtual void set_angular_velocity(const Vector3 &p_velocity); - virtual Vector3 get_angular_velocity() const; + virtual void set_angular_velocity(const Vector3 &p_velocity) override; + virtual Vector3 get_angular_velocity() const override; - virtual void set_transform(const Transform &p_transform); - virtual Transform get_transform() const; + virtual void set_transform(const Transform &p_transform) override; + virtual Transform get_transform() const override; - virtual void add_central_force(const Vector3 &p_force); - virtual void add_force(const Vector3 &p_force, const Vector3 &p_pos); - virtual void add_torque(const Vector3 &p_torque); - virtual void apply_central_impulse(const Vector3 &p_impulse); - virtual void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse); - virtual void apply_torque_impulse(const Vector3 &p_impulse); + virtual void add_central_force(const Vector3 &p_force) override; + virtual void add_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()) override; + virtual void add_torque(const Vector3 &p_torque) override; + virtual void apply_central_impulse(const Vector3 &p_impulse) override; + virtual void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) override; + virtual void apply_torque_impulse(const Vector3 &p_impulse) override; - virtual void set_sleep_state(bool p_enable); - virtual bool is_sleeping() const; + virtual void set_sleep_state(bool p_sleep) override; + virtual bool is_sleeping() const override; - virtual int get_contact_count() const; + virtual int get_contact_count() const override; - virtual Vector3 get_contact_local_position(int p_contact_idx) const; - virtual Vector3 get_contact_local_normal(int p_contact_idx) const; - virtual float get_contact_impulse(int p_contact_idx) const; - virtual int get_contact_local_shape(int p_contact_idx) const; + virtual Vector3 get_contact_local_position(int p_contact_idx) const override; + virtual Vector3 get_contact_local_normal(int p_contact_idx) const override; + virtual float get_contact_impulse(int p_contact_idx) const override; + virtual int get_contact_local_shape(int p_contact_idx) const override; - virtual RID get_contact_collider(int p_contact_idx) const; - virtual Vector3 get_contact_collider_position(int p_contact_idx) const; - virtual ObjectID get_contact_collider_id(int p_contact_idx) const; - virtual int get_contact_collider_shape(int p_contact_idx) const; - virtual Vector3 get_contact_collider_velocity_at_position(int p_contact_idx) const; + virtual RID get_contact_collider(int p_contact_idx) const override; + virtual Vector3 get_contact_collider_position(int p_contact_idx) const override; + virtual ObjectID get_contact_collider_id(int p_contact_idx) const override; + virtual int get_contact_collider_shape(int p_contact_idx) const override; + virtual Vector3 get_contact_collider_velocity_at_position(int p_contact_idx) const override; - virtual real_t get_step() const { return deltaTime; } - virtual void integrate_forces() { + virtual real_t get_step() const override { return deltaTime; } + virtual void integrate_forces() override { // Skip the execution of this function } - virtual PhysicsDirectSpaceState *get_space_state(); + virtual PhysicsDirectSpaceState3D *get_space_state() override; }; class RigidBodyBullet : public RigidCollisionObjectBullet { - public: struct CollisionData { RigidBodyBullet *otherObject; @@ -162,18 +161,17 @@ public: /// Used to hold shapes struct KinematicShape { - class btConvexShape *shape; + class btConvexShape *shape = nullptr; btTransform transform; - KinematicShape() : - shape(NULL) {} + KinematicShape() {} bool is_active() const { return shape; } }; struct KinematicUtilities { RigidBodyBullet *owner; btScalar safe_margin; - Vector<KinematicShape> shapes; + LocalVector<KinematicShape> shapes; KinematicUtilities(RigidBodyBullet *p_owner); ~KinematicUtilities(); @@ -187,45 +185,46 @@ public: }; private: - friend class BulletPhysicsDirectBodyState; + friend class BulletPhysicsDirectBodyState3D; // This is required only for Kinematic movement - KinematicUtilities *kinematic_utilities; + KinematicUtilities *kinematic_utilities = nullptr; - PhysicsServer::BodyMode mode; + PhysicsServer3D::BodyMode mode; GodotMotionState *godotMotionState; btRigidBody *btBody; - uint16_t locked_axis; - real_t mass; - real_t gravity_scale; - real_t linearDamp; - real_t angularDamp; - bool can_sleep; - bool omit_forces_integration; - bool can_integrate_forces; - - Vector<CollisionData> collisions; - Vector<RigidBodyBullet *> collision_traces_1; - Vector<RigidBodyBullet *> collision_traces_2; - Vector<RigidBodyBullet *> *prev_collision_traces; - Vector<RigidBodyBullet *> *curr_collision_traces; + Vector3 total_gravity; + uint16_t locked_axis = 0; + real_t mass = 1; + real_t gravity_scale = 1; + real_t linearDamp = 0; + real_t angularDamp = 0; + bool can_sleep = true; + bool omit_forces_integration = false; + bool can_integrate_forces = false; + + LocalVector<CollisionData> collisions; + LocalVector<RigidBodyBullet *> collision_traces_1; + LocalVector<RigidBodyBullet *> collision_traces_2; + LocalVector<RigidBodyBullet *> *prev_collision_traces; + LocalVector<RigidBodyBullet *> *curr_collision_traces; // these parameters are used to avoid vector resize - int maxCollisionsDetection; - int collisionsCount; - int prev_collision_count; + uint32_t maxCollisionsDetection = 0; + uint32_t collisionsCount = 0; + uint32_t prev_collision_count = 0; - Vector<AreaBullet *> areasWhereIam; + LocalVector<AreaBullet *> areasWhereIam; // these parameters are used to avoid vector resize - int maxAreasWhereIam; - int areaWhereIamCount; + int maxAreasWhereIam = 10; + int areaWhereIamCount = 0; // Used to know if the area is used as gravity point - int countGravityPointSpaces; - bool isScratchedSpaceOverrideModificator; + int countGravityPointSpaces = 0; + bool isScratchedSpaceOverrideModificator = false; - bool previousActiveState; // Last check state + bool previousActiveState = true; // Last check state - ForceIntegrationCallback *force_integration_callback; + ForceIntegrationCallback *force_integration_callback = nullptr; public: RigidBodyBullet(); @@ -237,22 +236,20 @@ public: _FORCE_INLINE_ btRigidBody *get_bt_rigid_body() { return btBody; } - virtual void main_shape_changed(); - virtual void reload_body(); - virtual void set_space(SpaceBullet *p_space); + virtual void main_shape_changed() override; + virtual void do_reload_body() override; + virtual void set_space(SpaceBullet *p_space) override; - virtual void dispatch_callbacks(); + virtual void dispatch_callbacks() override; + virtual void pre_process() override; void set_force_integration_callback(ObjectID p_id, const StringName &p_method, const Variant &p_udata = Variant()); void scratch_space_override_modificator(); - virtual void on_collision_filters_change(); - virtual void on_collision_checker_start(); - virtual void on_collision_checker_end(); - - void set_max_collisions_detection(int p_maxCollisionsDetection) { - - ERR_FAIL_COND(0 > p_maxCollisionsDetection); + virtual void do_reload_collision_filters() override; + virtual void on_collision_checker_start() override; + virtual void on_collision_checker_end() override; + void set_max_collisions_detection(uint32_t p_maxCollisionsDetection) { maxCollisionsDetection = p_maxCollisionsDetection; collisions.resize(p_maxCollisionsDetection); @@ -278,21 +275,21 @@ public: void set_omit_forces_integration(bool p_omit); _FORCE_INLINE_ bool get_omit_forces_integration() const { return omit_forces_integration; } - void set_param(PhysicsServer::BodyParameter p_param, real_t); - real_t get_param(PhysicsServer::BodyParameter p_param) const; + void set_param(PhysicsServer3D::BodyParameter p_param, real_t); + real_t get_param(PhysicsServer3D::BodyParameter p_param) const; - void set_mode(PhysicsServer::BodyMode p_mode); - PhysicsServer::BodyMode get_mode() const; + void set_mode(PhysicsServer3D::BodyMode p_mode); + PhysicsServer3D::BodyMode get_mode() const; - void set_state(PhysicsServer::BodyState p_state, const Variant &p_variant); - Variant get_state(PhysicsServer::BodyState p_state) const; + void set_state(PhysicsServer3D::BodyState p_state, const Variant &p_variant); + Variant get_state(PhysicsServer3D::BodyState p_state) const; - void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse); void apply_central_impulse(const Vector3 &p_impulse); + void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3()); void apply_torque_impulse(const Vector3 &p_impulse); - void apply_force(const Vector3 &p_force, const Vector3 &p_pos); void apply_central_force(const Vector3 &p_force); + void apply_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()); void apply_torque(const Vector3 &p_torque); void set_applied_force(const Vector3 &p_force); @@ -300,8 +297,8 @@ public: void set_applied_torque(const Vector3 &p_torque); Vector3 get_applied_torque() const; - void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool lock); - bool is_axis_locked(PhysicsServer::BodyAxis p_axis) const; + void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool lock); + bool is_axis_locked(PhysicsServer3D::BodyAxis p_axis) const; void reload_axis_lock(); /// Doc: @@ -315,19 +312,19 @@ public: void set_angular_velocity(const Vector3 &p_velocity); Vector3 get_angular_velocity() const; - virtual void set_transform__bullet(const btTransform &p_global_transform); - virtual const btTransform &get_transform__bullet() const; + virtual void set_transform__bullet(const btTransform &p_global_transform) override; + virtual const btTransform &get_transform__bullet() const override; - virtual void reload_shapes(); + virtual void do_reload_shapes() override; - virtual void on_enter_area(AreaBullet *p_area); - virtual void on_exit_area(AreaBullet *p_area); + virtual void on_enter_area(AreaBullet *p_area) override; + virtual void on_exit_area(AreaBullet *p_area) override; void reload_space_override_modificator(); /// Kinematic void reload_kinematic_shapes(); - virtual void notify_transform_changed(); + virtual void notify_transform_changed() override; private: void _internal_set_mass(real_t p_mass); diff --git a/modules/bullet/shape_bullet.cpp b/modules/bullet/shape_bullet.cpp index f46db09e4a..74d6e073b3 100644 --- a/modules/bullet/shape_bullet.cpp +++ b/modules/bullet/shape_bullet.cpp @@ -46,10 +46,15 @@ @author AndreaCatania */ -ShapeBullet::ShapeBullet() : - margin(0.04) {} +ShapeBullet::ShapeBullet() { +} -ShapeBullet::~ShapeBullet() {} +ShapeBullet::~ShapeBullet() { + if (default_shape != nullptr) { + bulletdelete(default_shape); + default_shape = nullptr; + } +} btCollisionShape *ShapeBullet::create_bt_shape(const Vector3 &p_implicit_scale, real_t p_extra_edge) { btVector3 s; @@ -57,6 +62,22 @@ btCollisionShape *ShapeBullet::create_bt_shape(const Vector3 &p_implicit_scale, return create_bt_shape(s, p_extra_edge); } +btCollisionShape *ShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { + if (p_extra_edge == 0.0 && (p_implicit_scale - btVector3(1, 1, 1)).length2() <= CMP_EPSILON) { + return default_shape; + } + + return internal_create_bt_shape(p_implicit_scale, p_extra_edge); +} + +void ShapeBullet::destroy_bt_shape(btCollisionShape *p_shape) const { + if (p_shape != default_shape && p_shape != old_default_shape) { + if (likely(p_shape != nullptr)) { + bulletdelete(p_shape); + } + } +} + btCollisionShape *ShapeBullet::prepare(btCollisionShape *p_btShape) const { p_btShape->setUserPointer(const_cast<ShapeBullet *>(this)); p_btShape->setMargin(margin); @@ -64,10 +85,21 @@ btCollisionShape *ShapeBullet::prepare(btCollisionShape *p_btShape) const { } void ShapeBullet::notifyShapeChanged() { + // Store the old shape ptr so to not lose the reference pointer. + old_default_shape = default_shape; + // Create the new default shape with the new data. + default_shape = internal_create_bt_shape(btVector3(1, 1, 1)); + for (Map<ShapeOwnerBullet *, int>::Element *E = owners.front(); E; E = E->next()) { ShapeOwnerBullet *owner = static_cast<ShapeOwnerBullet *>(E->key()); owner->shape_changed(owner->find_shape(this)); } + + if (old_default_shape) { + // At this point now one has the old default shape; just delete it. + bulletdelete(old_default_shape); + old_default_shape = nullptr; + } } void ShapeBullet::add_owner(ShapeOwnerBullet *p_owner) { @@ -81,7 +113,9 @@ void ShapeBullet::add_owner(ShapeOwnerBullet *p_owner) { void ShapeBullet::remove_owner(ShapeOwnerBullet *p_owner, bool p_permanentlyFromThisBody) { Map<ShapeOwnerBullet *, int>::Element *E = owners.find(p_owner); - if (!E) return; + if (!E) { + return; + } E->get()--; if (p_permanentlyFromThisBody || 0 >= E->get()) { owners.erase(E); @@ -89,7 +123,6 @@ void ShapeBullet::remove_owner(ShapeOwnerBullet *p_owner, bool p_permanentlyFrom } bool ShapeBullet::is_owner(ShapeOwnerBullet *p_owner) const { - return owners.has(p_owner); } @@ -122,8 +155,8 @@ btBoxShape *ShapeBullet::create_shape_box(const btVector3 &boxHalfExtents) { return bulletnew(btBoxShape(boxHalfExtents)); } -btCapsuleShapeZ *ShapeBullet::create_shape_capsule(btScalar radius, btScalar height) { - return bulletnew(btCapsuleShapeZ(radius, height)); +btCapsuleShape *ShapeBullet::create_shape_capsule(btScalar radius, btScalar height) { + return bulletnew(btCapsuleShape(radius, height)); } btCylinderShape *ShapeBullet::create_shape_cylinder(btScalar radius, btScalar height) { @@ -138,21 +171,22 @@ btScaledBvhTriangleMeshShape *ShapeBullet::create_shape_concave(btBvhTriangleMes if (p_mesh_shape) { return bulletnew(btScaledBvhTriangleMeshShape(p_mesh_shape, p_local_scaling)); } else { - return NULL; + return nullptr; } } -btHeightfieldTerrainShape *ShapeBullet::create_shape_height_field(PoolVector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height) { +btHeightfieldTerrainShape *ShapeBullet::create_shape_height_field(Vector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height) { const btScalar ignoredHeightScale(1); const int YAxis = 1; // 0=X, 1=Y, 2=Z const bool flipQuadEdges = false; - const void *heightsPtr = p_heights.read().ptr(); + const void *heightsPtr = p_heights.ptr(); btHeightfieldTerrainShape *heightfield = bulletnew(btHeightfieldTerrainShape(p_width, p_depth, heightsPtr, ignoredHeightScale, p_min_height, p_max_height, YAxis, PHY_FLOAT, flipQuadEdges)); - // The shape can be created without params when you do PhysicsServer.shape_create(PhysicsServer.SHAPE_HEIGHTMAP) - if (heightsPtr) + // The shape can be created without params when you do PhysicsServer3D.shape_create(PhysicsServer3D.SHAPE_HEIGHTMAP) + if (heightsPtr) { heightfield->buildAccelerator(16); + } return heightfield; } @@ -176,8 +210,8 @@ Variant PlaneShapeBullet::get_data() const { return plane; } -PhysicsServer::ShapeType PlaneShapeBullet::get_type() const { - return PhysicsServer::SHAPE_PLANE; +PhysicsServer3D::ShapeType PlaneShapeBullet::get_type() const { + return PhysicsServer3D::SHAPE_PLANE; } void PlaneShapeBullet::setup(const Plane &p_plane) { @@ -185,7 +219,7 @@ void PlaneShapeBullet::setup(const Plane &p_plane) { notifyShapeChanged(); } -btCollisionShape *PlaneShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *PlaneShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { btVector3 btPlaneNormal; G_TO_B(plane.normal, btPlaneNormal); return prepare(PlaneShapeBullet::create_shape_plane(btPlaneNormal, plane.d)); @@ -204,8 +238,8 @@ Variant SphereShapeBullet::get_data() const { return radius; } -PhysicsServer::ShapeType SphereShapeBullet::get_type() const { - return PhysicsServer::SHAPE_SPHERE; +PhysicsServer3D::ShapeType SphereShapeBullet::get_type() const { + return PhysicsServer3D::SHAPE_SPHERE; } void SphereShapeBullet::setup(real_t p_radius) { @@ -213,7 +247,7 @@ void SphereShapeBullet::setup(real_t p_radius) { notifyShapeChanged(); } -btCollisionShape *SphereShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *SphereShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { return prepare(ShapeBullet::create_shape_sphere(radius * p_implicit_scale[0] + p_extra_edge)); } @@ -231,8 +265,8 @@ Variant BoxShapeBullet::get_data() const { return g_half_extents; } -PhysicsServer::ShapeType BoxShapeBullet::get_type() const { - return PhysicsServer::SHAPE_BOX; +PhysicsServer3D::ShapeType BoxShapeBullet::get_type() const { + return PhysicsServer3D::SHAPE_BOX; } void BoxShapeBullet::setup(const Vector3 &p_half_extents) { @@ -240,7 +274,7 @@ void BoxShapeBullet::setup(const Vector3 &p_half_extents) { notifyShapeChanged(); } -btCollisionShape *BoxShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *BoxShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { return prepare(ShapeBullet::create_shape_box((half_extents * p_implicit_scale) + btVector3(p_extra_edge, p_extra_edge, p_extra_edge))); } @@ -263,8 +297,8 @@ Variant CapsuleShapeBullet::get_data() const { return d; } -PhysicsServer::ShapeType CapsuleShapeBullet::get_type() const { - return PhysicsServer::SHAPE_CAPSULE; +PhysicsServer3D::ShapeType CapsuleShapeBullet::get_type() const { + return PhysicsServer3D::SHAPE_CAPSULE; } void CapsuleShapeBullet::setup(real_t p_height, real_t p_radius) { @@ -273,8 +307,8 @@ void CapsuleShapeBullet::setup(real_t p_height, real_t p_radius) { notifyShapeChanged(); } -btCollisionShape *CapsuleShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { - return prepare(ShapeBullet::create_shape_capsule(radius * p_implicit_scale[0] + p_extra_edge, height * p_implicit_scale[1] + p_extra_edge)); +btCollisionShape *CapsuleShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { + return prepare(ShapeBullet::create_shape_capsule(radius * p_implicit_scale[0] + p_extra_edge, height * p_implicit_scale[1])); } /* Cylinder */ @@ -296,8 +330,8 @@ Variant CylinderShapeBullet::get_data() const { return d; } -PhysicsServer::ShapeType CylinderShapeBullet::get_type() const { - return PhysicsServer::SHAPE_CYLINDER; +PhysicsServer3D::ShapeType CylinderShapeBullet::get_type() const { + return PhysicsServer3D::SHAPE_CYLINDER; } void CylinderShapeBullet::setup(real_t p_height, real_t p_radius) { @@ -306,7 +340,7 @@ void CylinderShapeBullet::setup(real_t p_height, real_t p_radius) { notifyShapeChanged(); } -btCollisionShape *CylinderShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { +btCollisionShape *CylinderShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { return prepare(ShapeBullet::create_shape_cylinder(radius * p_implicit_scale[0] + p_margin, height * p_implicit_scale[1] + p_margin)); } @@ -334,8 +368,8 @@ Variant ConvexPolygonShapeBullet::get_data() const { return out_vertices; } -PhysicsServer::ShapeType ConvexPolygonShapeBullet::get_type() const { - return PhysicsServer::SHAPE_CONVEX_POLYGON; +PhysicsServer3D::ShapeType ConvexPolygonShapeBullet::get_type() const { + return PhysicsServer3D::SHAPE_CONVEX_POLYGON; } void ConvexPolygonShapeBullet::setup(const Vector<Vector3> &p_vertices) { @@ -348,10 +382,11 @@ void ConvexPolygonShapeBullet::setup(const Vector<Vector3> &p_vertices) { notifyShapeChanged(); } -btCollisionShape *ConvexPolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { - if (!vertices.size()) +btCollisionShape *ConvexPolygonShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { + if (!vertices.size()) { // This is necessary since 0 vertices return prepare(ShapeBullet::create_shape_empty()); + } btCollisionShape *cs(ShapeBullet::create_shape_convex(vertices)); cs->setLocalScaling(p_implicit_scale); prepare(cs); @@ -361,8 +396,7 @@ btCollisionShape *ConvexPolygonShapeBullet::create_bt_shape(const btVector3 &p_i /* Concave polygon */ ConcavePolygonShapeBullet::ConcavePolygonShapeBullet() : - ShapeBullet(), - meshShape(NULL) {} + ShapeBullet() {} ConcavePolygonShapeBullet::~ConcavePolygonShapeBullet() { if (meshShape) { @@ -370,7 +404,7 @@ ConcavePolygonShapeBullet::~ConcavePolygonShapeBullet() { delete meshShape->getTriangleInfoMap(); bulletdelete(meshShape); } - faces = PoolVector<Vector3>(); + faces = Vector<Vector3>(); } void ConcavePolygonShapeBullet::set_data(const Variant &p_data) { @@ -381,11 +415,11 @@ Variant ConcavePolygonShapeBullet::get_data() const { return faces; } -PhysicsServer::ShapeType ConcavePolygonShapeBullet::get_type() const { - return PhysicsServer::SHAPE_CONCAVE_POLYGON; +PhysicsServer3D::ShapeType ConcavePolygonShapeBullet::get_type() const { + return PhysicsServer3D::SHAPE_CONCAVE_POLYGON; } -void ConcavePolygonShapeBullet::setup(PoolVector<Vector3> p_faces) { +void ConcavePolygonShapeBullet::setup(Vector<Vector3> p_faces) { faces = p_faces; if (meshShape) { /// Clear previous created shape @@ -395,14 +429,13 @@ void ConcavePolygonShapeBullet::setup(PoolVector<Vector3> p_faces) { } int src_face_count = faces.size(); if (0 < src_face_count) { - // It counts the faces and assert the array contains the correct number of vertices. ERR_FAIL_COND(src_face_count % 3); btTriangleMesh *shapeInterface = bulletnew(btTriangleMesh); src_face_count /= 3; - PoolVector<Vector3>::Read r = p_faces.read(); - const Vector3 *facesr = r.ptr(); + const Vector3 *r = p_faces.ptr(); + const Vector3 *facesr = r; btVector3 supVec_0; btVector3 supVec_1; @@ -425,17 +458,18 @@ void ConcavePolygonShapeBullet::setup(PoolVector<Vector3> p_faces) { btGenerateInternalEdgeInfo(meshShape, triangleInfoMap); } } else { - meshShape = NULL; + meshShape = nullptr; ERR_PRINT("The faces count are 0, the mesh shape cannot be created"); } notifyShapeChanged(); } -btCollisionShape *ConcavePolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *ConcavePolygonShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { btCollisionShape *cs = ShapeBullet::create_shape_concave(meshShape); - if (!cs) - // This is necessary since if 0 faces the creation of concave return NULL + if (!cs) { + // This is necessary since if 0 faces the creation of concave return null cs = ShapeBullet::create_shape_empty(); + } cs->setLocalScaling(p_implicit_scale); prepare(cs); cs->setMargin(0); @@ -458,23 +492,28 @@ void HeightMapShapeBullet::set_data(const Variant &p_data) { real_t l_max_height = 0.0; // If specified, min and max height will be used as precomputed values - if (d.has("min_height")) + if (d.has("min_height")) { l_min_height = d["min_height"]; - if (d.has("max_height")) + } + if (d.has("max_height")) { l_max_height = d["max_height"]; + } ERR_FAIL_COND(l_min_height > l_max_height); int l_width = d["width"]; int l_depth = d["depth"]; + ERR_FAIL_COND_MSG(l_width < 2, "Map width must be at least 2."); + ERR_FAIL_COND_MSG(l_depth < 2, "Map depth must be at least 2."); + // TODO This code will need adjustments if real_t is set to `double`, // because that precision is unnecessary for a heightmap and Bullet doesn't support it... - PoolVector<real_t> l_heights; + Vector<real_t> l_heights; Variant l_heights_v = d["heights"]; - if (l_heights_v.get_type() == Variant::POOL_REAL_ARRAY) { + if (l_heights_v.get_type() == Variant::PACKED_FLOAT32_ARRAY) { // Ready-to-use heights can be passed l_heights = l_heights_v; @@ -491,13 +530,13 @@ void HeightMapShapeBullet::set_data(const Variant &p_data) { // We could convert here automatically but it's better to not be intrusive and let the caller do it if necessary. ERR_FAIL_COND(l_image->get_format() != Image::FORMAT_RF); - PoolByteArray im_data = l_image->get_data(); + PackedByteArray im_data = l_image->get_data(); l_heights.resize(l_image->get_width() * l_image->get_height()); - PoolRealArray::Write w = l_heights.write(); - PoolByteArray::Read r = im_data.read(); - float *rp = (float *)r.ptr(); + real_t *w = l_heights.ptrw(); + const uint8_t *r = im_data.ptr(); + float *rp = (float *)r; // At this point, `rp` could be used directly for Bullet, but I don't know how safe it would be. for (int i = 0; i < l_heights.size(); ++i) { @@ -505,7 +544,7 @@ void HeightMapShapeBullet::set_data(const Variant &p_data) { } } else { - ERR_FAIL_MSG("Expected PoolRealArray or float Image."); + ERR_FAIL_MSG("Expected PackedFloat32Array or float Image."); } ERR_FAIL_COND(l_width <= 0); @@ -514,8 +553,7 @@ void HeightMapShapeBullet::set_data(const Variant &p_data) { // Compute min and max heights if not specified. if (!d.has("min_height") && !d.has("max_height")) { - - PoolVector<real_t>::Read r = l_heights.read(); + const real_t *r = l_heights.ptr(); int heights_size = l_heights.size(); for (int i = 0; i < heights_size; ++i) { @@ -536,11 +574,11 @@ Variant HeightMapShapeBullet::get_data() const { ERR_FAIL_V(Variant()); } -PhysicsServer::ShapeType HeightMapShapeBullet::get_type() const { - return PhysicsServer::SHAPE_HEIGHTMAP; +PhysicsServer3D::ShapeType HeightMapShapeBullet::get_type() const { + return PhysicsServer3D::SHAPE_HEIGHTMAP; } -void HeightMapShapeBullet::setup(PoolVector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height) { +void HeightMapShapeBullet::setup(Vector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height) { // TODO cell size must be tweaked using localScaling, which is a shared property for all Bullet shapes // If this array is resized outside of here, it should be preserved due to CoW @@ -553,7 +591,7 @@ void HeightMapShapeBullet::setup(PoolVector<real_t> &p_heights, int p_width, int notifyShapeChanged(); } -btCollisionShape *HeightMapShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *HeightMapShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { btCollisionShape *cs(ShapeBullet::create_shape_height_field(heights, width, depth, min_height, max_height)); cs->setLocalScaling(p_implicit_scale); prepare(cs); @@ -562,26 +600,22 @@ btCollisionShape *HeightMapShapeBullet::create_bt_shape(const btVector3 &p_impli /* Ray shape */ RayShapeBullet::RayShapeBullet() : - ShapeBullet(), - length(1), - slips_on_slope(false) {} + ShapeBullet() {} void RayShapeBullet::set_data(const Variant &p_data) { - Dictionary d = p_data; setup(d["length"], d["slips_on_slope"]); } Variant RayShapeBullet::get_data() const { - Dictionary d; d["length"] = length; d["slips_on_slope"] = slips_on_slope; return d; } -PhysicsServer::ShapeType RayShapeBullet::get_type() const { - return PhysicsServer::SHAPE_RAY; +PhysicsServer3D::ShapeType RayShapeBullet::get_type() const { + return PhysicsServer3D::SHAPE_RAY; } void RayShapeBullet::setup(real_t p_length, bool p_slips_on_slope) { @@ -590,6 +624,6 @@ void RayShapeBullet::setup(real_t p_length, bool p_slips_on_slope) { notifyShapeChanged(); } -btCollisionShape *RayShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *RayShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { return prepare(ShapeBullet::create_shape_ray(length * p_implicit_scale[1] + p_extra_edge, slips_on_slope)); } diff --git a/modules/bullet/shape_bullet.h b/modules/bullet/shape_bullet.h index 8d3512cab4..6ca4d36a23 100644 --- a/modules/bullet/shape_bullet.h +++ b/modules/bullet/shape_bullet.h @@ -31,10 +31,10 @@ #ifndef SHAPE_BULLET_H #define SHAPE_BULLET_H -#include "core/math/geometry.h" +#include "core/math/geometry_3d.h" #include "core/variant.h" #include "rid_bullet.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" #include <LinearMath/btAlignedObjectArray.h> #include <LinearMath/btScalar.h> @@ -50,9 +50,12 @@ class ShapeOwnerBullet; class btBvhTriangleMeshShape; class ShapeBullet : public RIDBullet { - Map<ShapeOwnerBullet *, int> owners; - real_t margin; + real_t margin = 0.04; + + // Contains the default shape. + btCollisionShape *default_shape = nullptr; + btCollisionShape *old_default_shape = nullptr; protected: /// return self @@ -64,7 +67,11 @@ public: virtual ~ShapeBullet(); btCollisionShape *create_bt_shape(const Vector3 &p_implicit_scale, real_t p_extra_edge = 0); - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0) = 0; + btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + + void destroy_bt_shape(btCollisionShape *p_shape) const; + + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0) = 0; void add_owner(ShapeOwnerBullet *p_owner); void remove_owner(ShapeOwnerBullet *p_owner, bool p_permanentlyFromThisBody = false); @@ -78,24 +85,23 @@ public: virtual void set_data(const Variant &p_data) = 0; virtual Variant get_data() const = 0; - virtual PhysicsServer::ShapeType get_type() const = 0; + virtual PhysicsServer3D::ShapeType get_type() const = 0; public: static class btEmptyShape *create_shape_empty(); static class btStaticPlaneShape *create_shape_plane(const btVector3 &planeNormal, btScalar planeConstant); static class btSphereShape *create_shape_sphere(btScalar radius); static class btBoxShape *create_shape_box(const btVector3 &boxHalfExtents); - static class btCapsuleShapeZ *create_shape_capsule(btScalar radius, btScalar height); + static class btCapsuleShape *create_shape_capsule(btScalar radius, btScalar height); static class btCylinderShape *create_shape_cylinder(btScalar radius, btScalar height); /// IMPORTANT: Remember to delete the shape interface by calling: delete my_shape->getMeshInterface(); static class btConvexPointCloudShape *create_shape_convex(btAlignedObjectArray<btVector3> &p_vertices, const btVector3 &p_local_scaling = btVector3(1, 1, 1)); static class btScaledBvhTriangleMeshShape *create_shape_concave(btBvhTriangleMeshShape *p_mesh_shape, const btVector3 &p_local_scaling = btVector3(1, 1, 1)); - static class btHeightfieldTerrainShape *create_shape_height_field(PoolVector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height); + static class btHeightfieldTerrainShape *create_shape_height_field(Vector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height); static class btRayShape *create_shape_ray(real_t p_length, bool p_slips_on_slope); }; class PlaneShapeBullet : public ShapeBullet { - Plane plane; public: @@ -103,15 +109,14 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; - virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual PhysicsServer3D::ShapeType get_type() const; + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(const Plane &p_plane); }; class SphereShapeBullet : public ShapeBullet { - real_t radius; public: @@ -120,15 +125,14 @@ public: _FORCE_INLINE_ real_t get_radius() { return radius; } virtual void set_data(const Variant &p_data); virtual Variant get_data() const; - virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual PhysicsServer3D::ShapeType get_type() const; + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(real_t p_radius); }; class BoxShapeBullet : public ShapeBullet { - btVector3 half_extents; public: @@ -137,15 +141,14 @@ public: _FORCE_INLINE_ const btVector3 &get_half_extents() { return half_extents; } virtual void set_data(const Variant &p_data); virtual Variant get_data() const; - virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual PhysicsServer3D::ShapeType get_type() const; + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(const Vector3 &p_half_extents); }; class CapsuleShapeBullet : public ShapeBullet { - real_t height; real_t radius; @@ -156,15 +159,14 @@ public: _FORCE_INLINE_ real_t get_radius() { return radius; } virtual void set_data(const Variant &p_data); virtual Variant get_data() const; - virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual PhysicsServer3D::ShapeType get_type() const; + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(real_t p_height, real_t p_radius); }; class CylinderShapeBullet : public ShapeBullet { - real_t height; real_t radius; @@ -175,15 +177,14 @@ public: _FORCE_INLINE_ real_t get_radius() { return radius; } virtual void set_data(const Variant &p_data); virtual Variant get_data() const; - virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); + virtual PhysicsServer3D::ShapeType get_type() const; + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); private: void setup(real_t p_height, real_t p_radius); }; class ConvexPolygonShapeBullet : public ShapeBullet { - public: btAlignedObjectArray<btVector3> vertices; @@ -192,35 +193,34 @@ public: virtual void set_data(const Variant &p_data); void get_vertices(Vector<Vector3> &out_vertices); virtual Variant get_data() const; - virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual PhysicsServer3D::ShapeType get_type() const; + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(const Vector<Vector3> &p_vertices); }; class ConcavePolygonShapeBullet : public ShapeBullet { - class btBvhTriangleMeshShape *meshShape; + class btBvhTriangleMeshShape *meshShape = nullptr; public: - PoolVector<Vector3> faces; + Vector<Vector3> faces; ConcavePolygonShapeBullet(); virtual ~ConcavePolygonShapeBullet(); virtual void set_data(const Variant &p_data); virtual Variant get_data() const; - virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual PhysicsServer3D::ShapeType get_type() const; + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: - void setup(PoolVector<Vector3> p_faces); + void setup(Vector<Vector3> p_faces); }; class HeightMapShapeBullet : public ShapeBullet { - public: - PoolVector<real_t> heights; + Vector<real_t> heights; int width; int depth; real_t min_height; @@ -230,25 +230,24 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; - virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual PhysicsServer3D::ShapeType get_type() const; + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: - void setup(PoolVector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height); + void setup(Vector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height); }; class RayShapeBullet : public ShapeBullet { - public: - real_t length; - bool slips_on_slope; + real_t length = 1; + bool slips_on_slope = false; RayShapeBullet(); virtual void set_data(const Variant &p_data); virtual Variant get_data() const; - virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual PhysicsServer3D::ShapeType get_type() const; + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(real_t p_length, bool p_slips_on_slope); diff --git a/modules/bullet/slider_joint_bullet.cpp b/modules/bullet/slider_joint_bullet.cpp index d9ebb9d580..6d5d95d07a 100644 --- a/modules/bullet/slider_joint_bullet.cpp +++ b/modules/bullet/slider_joint_bullet.cpp @@ -42,7 +42,6 @@ SliderJointBullet::SliderJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB) : JointBullet() { - Transform scaled_AFrame(frameInA.scaled(rbA->get_body_scale())); scaled_AFrame.basis.rotref_posscale_decomposition(scaled_AFrame.basis); @@ -50,7 +49,6 @@ SliderJointBullet::SliderJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, G_TO_B(scaled_AFrame, btFrameA); if (rbB) { - Transform scaled_BFrame(frameInB.scaled(rbB->get_body_scale())); scaled_BFrame.basis.rotref_posscale_decomposition(scaled_BFrame.basis); @@ -121,6 +119,7 @@ real_t SliderJointBullet::getLowerLinLimit() const { void SliderJointBullet::setLowerLinLimit(real_t lowerLimit) { sliderConstraint->setLowerLinLimit(lowerLimit); } + real_t SliderJointBullet::getUpperLinLimit() const { return sliderConstraint->getUpperLinLimit(); } @@ -342,58 +341,125 @@ real_t SliderJointBullet::getLinearPos() { ; } -void SliderJointBullet::set_param(PhysicsServer::SliderJointParam p_param, real_t p_value) { +void SliderJointBullet::set_param(PhysicsServer3D::SliderJointParam p_param, real_t p_value) { switch (p_param) { - case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER: setUpperLinLimit(p_value); break; - case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER: setLowerLinLimit(p_value); break; - case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS: setSoftnessLimLin(p_value); break; - case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION: setRestitutionLimLin(p_value); break; - case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING: setDampingLimLin(p_value); break; - case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS: setSoftnessDirLin(p_value); break; - case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION: setRestitutionDirLin(p_value); break; - case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_DAMPING: setDampingDirLin(p_value); break; - case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS: setSoftnessOrthoLin(p_value); break; - case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION: setRestitutionOrthoLin(p_value); break; - case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING: setDampingOrthoLin(p_value); break; - case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER: setUpperAngLimit(p_value); break; - case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER: setLowerAngLimit(p_value); break; - case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS: setSoftnessLimAng(p_value); break; - case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION: setRestitutionLimAng(p_value); break; - case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING: setDampingLimAng(p_value); break; - case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS: setSoftnessDirAng(p_value); break; - case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION: setRestitutionDirAng(p_value); break; - case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_DAMPING: setDampingDirAng(p_value); break; - case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS: setSoftnessOrthoAng(p_value); break; - case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION: setRestitutionOrthoAng(p_value); break; - case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING: setDampingOrthoAng(p_value); break; - case PhysicsServer::SLIDER_JOINT_MAX: break; // Can't happen, but silences warning + case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER: + setUpperLinLimit(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER: + setLowerLinLimit(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS: + setSoftnessLimLin(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION: + setRestitutionLimLin(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING: + setDampingLimLin(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS: + setSoftnessDirLin(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION: + setRestitutionDirLin(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_DAMPING: + setDampingDirLin(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS: + setSoftnessOrthoLin(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION: + setRestitutionOrthoLin(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING: + setDampingOrthoLin(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER: + setUpperAngLimit(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER: + setLowerAngLimit(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS: + setSoftnessLimAng(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION: + setRestitutionLimAng(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING: + setDampingLimAng(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS: + setSoftnessDirAng(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION: + setRestitutionDirAng(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_DAMPING: + setDampingDirAng(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS: + setSoftnessOrthoAng(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION: + setRestitutionOrthoAng(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING: + setDampingOrthoAng(p_value); + break; + case PhysicsServer3D::SLIDER_JOINT_MAX: + break; // Can't happen, but silences warning } } -real_t SliderJointBullet::get_param(PhysicsServer::SliderJointParam p_param) const { +real_t SliderJointBullet::get_param(PhysicsServer3D::SliderJointParam p_param) const { switch (p_param) { - case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER: return getUpperLinLimit(); - case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER: return getLowerLinLimit(); - case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS: return getSoftnessLimLin(); - case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION: return getRestitutionLimLin(); - case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING: return getDampingLimLin(); - case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS: return getSoftnessDirLin(); - case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION: return getRestitutionDirLin(); - case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_DAMPING: return getDampingDirLin(); - case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS: return getSoftnessOrthoLin(); - case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION: return getRestitutionOrthoLin(); - case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING: return getDampingOrthoLin(); - case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER: return getUpperAngLimit(); - case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER: return getLowerAngLimit(); - case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS: return getSoftnessLimAng(); - case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION: return getRestitutionLimAng(); - case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING: return getDampingLimAng(); - case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS: return getSoftnessDirAng(); - case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION: return getRestitutionDirAng(); - case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_DAMPING: return getDampingDirAng(); - case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS: return getSoftnessOrthoAng(); - case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION: return getRestitutionOrthoAng(); - case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING: return getDampingOrthoAng(); + case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER: + return getUpperLinLimit(); + case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER: + return getLowerLinLimit(); + case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS: + return getSoftnessLimLin(); + case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION: + return getRestitutionLimLin(); + case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING: + return getDampingLimLin(); + case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS: + return getSoftnessDirLin(); + case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION: + return getRestitutionDirLin(); + case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_DAMPING: + return getDampingDirLin(); + case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS: + return getSoftnessOrthoLin(); + case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION: + return getRestitutionOrthoLin(); + case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING: + return getDampingOrthoLin(); + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER: + return getUpperAngLimit(); + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER: + return getLowerAngLimit(); + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS: + return getSoftnessLimAng(); + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION: + return getRestitutionLimAng(); + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING: + return getDampingLimAng(); + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS: + return getSoftnessDirAng(); + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION: + return getRestitutionDirAng(); + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_DAMPING: + return getDampingDirAng(); + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS: + return getSoftnessOrthoAng(); + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION: + return getRestitutionOrthoAng(); + case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING: + return getDampingOrthoAng(); default: return 0; } diff --git a/modules/bullet/slider_joint_bullet.h b/modules/bullet/slider_joint_bullet.h index d98a1b8c95..6410b952ed 100644 --- a/modules/bullet/slider_joint_bullet.h +++ b/modules/bullet/slider_joint_bullet.h @@ -46,7 +46,7 @@ public: /// Reference frame is A SliderJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB); - virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_SLIDER; } + virtual PhysicsServer3D::JointType get_type() const { return PhysicsServer3D::JOINT_SLIDER; } const RigidBodyBullet *getRigidBodyA() const; const RigidBodyBullet *getRigidBodyB() const; @@ -115,7 +115,7 @@ public: real_t getMaxAngMotorForce(); real_t getLinearPos(); - void set_param(PhysicsServer::SliderJointParam p_param, real_t p_value); - real_t get_param(PhysicsServer::SliderJointParam p_param) const; + void set_param(PhysicsServer3D::SliderJointParam p_param, real_t p_value); + real_t get_param(PhysicsServer3D::SliderJointParam p_param) const; }; #endif diff --git a/modules/bullet/soft_body_bullet.cpp b/modules/bullet/soft_body_bullet.cpp index f4c0ffa6eb..ee48b3c5f0 100644 --- a/modules/bullet/soft_body_bullet.cpp +++ b/modules/bullet/soft_body_bullet.cpp @@ -32,27 +32,16 @@ #include "bullet_types_converter.h" #include "bullet_utilities.h" -#include "scene/3d/soft_body.h" +#include "scene/3d/soft_body_3d.h" #include "space_bullet.h" SoftBodyBullet::SoftBodyBullet() : - CollisionObjectBullet(CollisionObjectBullet::TYPE_SOFT_BODY), - bt_soft_body(NULL), - isScratched(false), - simulation_precision(5), - total_mass(1.), - linear_stiffness(0.5), - areaAngular_stiffness(0.5), - volume_stiffness(0.5), - pressure_coefficient(0.), - pose_matching_coefficient(0.), - damping_coefficient(0.01), - drag_coefficient(0.) {} + CollisionObjectBullet(CollisionObjectBullet::TYPE_SOFT_BODY) {} SoftBodyBullet::~SoftBodyBullet() { } -void SoftBodyBullet::reload_body() { +void SoftBodyBullet::do_reload_body() { if (space) { space->remove_soft_body(this); space->add_soft_body(this); @@ -62,13 +51,15 @@ void SoftBodyBullet::reload_body() { void SoftBodyBullet::set_space(SpaceBullet *p_space) { if (space) { isScratched = false; + space->unregister_collision_object(this); space->remove_soft_body(this); } space = p_space; if (space) { - space->add_soft_body(this); + space->register_collision_object(this); + reload_body(); } } @@ -76,9 +67,10 @@ void SoftBodyBullet::on_enter_area(AreaBullet *p_area) {} void SoftBodyBullet::on_exit_area(AreaBullet *p_area) {} -void SoftBodyBullet::update_visual_server(SoftBodyVisualServerHandler *p_visual_server_handler) { - if (!bt_soft_body) +void SoftBodyBullet::update_rendering_server(SoftBodyRenderingServerHandler *p_rendering_server_handler) { + if (!bt_soft_body) { return; + } /// Update visual server vertices const btSoftBody::tNodeArray &nodes(bt_soft_body->m_nodes); @@ -96,8 +88,8 @@ void SoftBodyBullet::update_visual_server(SoftBodyVisualServerHandler *p_visual_ const int vs_indices_size(vs_indices->size()); for (int x = 0; x < vs_indices_size; ++x) { - p_visual_server_handler->set_vertex((*vs_indices)[x], vertex_position); - p_visual_server_handler->set_normal((*vs_indices)[x], vertex_normal); + p_rendering_server_handler->set_vertex((*vs_indices)[x], vertex_position); + p_rendering_server_handler->set_normal((*vs_indices)[x], vertex_normal); } } @@ -112,31 +104,30 @@ void SoftBodyBullet::update_visual_server(SoftBodyVisualServerHandler *p_visual_ B_TO_G(aabb_min, aabb.position); B_TO_G(size, aabb.size); - p_visual_server_handler->set_aabb(aabb); + p_rendering_server_handler->set_aabb(aabb); } void SoftBodyBullet::set_soft_mesh(const Ref<Mesh> &p_mesh) { - - if (p_mesh.is_null()) + if (p_mesh.is_null()) { soft_mesh.unref(); - else + } else { soft_mesh = p_mesh; + } if (soft_mesh.is_null()) { - destroy_soft_body(); return; } Array arrays = soft_mesh->surface_get_arrays(0); - ERR_FAIL_COND(!(soft_mesh->surface_get_format(0) & VS::ARRAY_FORMAT_INDEX)); - set_trimesh_body_shape(arrays[VS::ARRAY_INDEX], arrays[VS::ARRAY_VERTEX]); + ERR_FAIL_COND(!(soft_mesh->surface_get_format(0) & RS::ARRAY_FORMAT_INDEX)); + set_trimesh_body_shape(arrays[RS::ARRAY_INDEX], arrays[RS::ARRAY_VERTEX]); } void SoftBodyBullet::destroy_soft_body() { - - if (!bt_soft_body) + if (!bt_soft_body) { return; + } if (space) { /// Remove from world before deletion @@ -144,7 +135,7 @@ void SoftBodyBullet::destroy_soft_body() { } destroyBulletCollisionObject(); - bt_soft_body = NULL; + bt_soft_body = nullptr; } void SoftBodyBullet::set_soft_transform(const Transform &p_transform) { @@ -153,8 +144,9 @@ void SoftBodyBullet::set_soft_transform(const Transform &p_transform) { } void SoftBodyBullet::move_all_nodes(const Transform &p_transform) { - if (!bt_soft_body) + if (!bt_soft_body) { return; + } btTransform bt_transf; G_TO_B(p_transform, bt_transf); bt_soft_body->transform(bt_transf); @@ -168,6 +160,7 @@ void SoftBodyBullet::set_node_position(int p_node_index, const Vector3 &p_global void SoftBodyBullet::set_node_position(int p_node_index, const btVector3 &p_global_position) { if (bt_soft_body) { + bt_soft_body->m_nodes[p_node_index].m_q = bt_soft_body->m_nodes[p_node_index].m_x; bt_soft_body->m_nodes[p_node_index].m_x = p_global_position; } } @@ -179,11 +172,12 @@ void SoftBodyBullet::get_node_position(int p_node_index, Vector3 &r_position) co } void SoftBodyBullet::get_node_offset(int p_node_index, Vector3 &r_offset) const { - if (soft_mesh.is_null()) + if (soft_mesh.is_null()) { return; + } Array arrays = soft_mesh->surface_get_arrays(0); - PoolVector<Vector3> vertices(arrays[VS::ARRAY_VERTEX]); + Vector<Vector3> vertices(arrays[RS::ARRAY_VERTEX]); if (0 <= p_node_index && vertices.size() > p_node_index) { r_offset = vertices[p_node_index]; @@ -225,15 +219,15 @@ void SoftBodyBullet::reset_all_node_mass() { } void SoftBodyBullet::reset_all_node_positions() { - if (soft_mesh.is_null()) + if (soft_mesh.is_null()) { return; + } Array arrays = soft_mesh->surface_get_arrays(0); - PoolVector<Vector3> vs_vertices(arrays[VS::ARRAY_VERTEX]); - PoolVector<Vector3>::Read vs_vertices_read = vs_vertices.read(); + Vector<Vector3> vs_vertices(arrays[RS::ARRAY_VERTEX]); + const Vector3 *vs_vertices_read = vs_vertices.ptr(); for (int vertex_index = bt_soft_body->m_nodes.size() - 1; 0 <= vertex_index; --vertex_index) { - G_TO_B(vs_vertices_read[indices_table[vertex_index][0]], bt_soft_body->m_nodes[vertex_index].m_x); bt_soft_body->m_nodes[vertex_index].m_q = bt_soft_body->m_nodes[vertex_index].m_x; @@ -319,7 +313,7 @@ void SoftBodyBullet::set_drag_coefficient(real_t p_val) { } } -void SoftBodyBullet::set_trimesh_body_shape(PoolVector<int> p_indices, PoolVector<Vector3> p_vertices) { +void SoftBodyBullet::set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector3> p_vertices) { /// Assert the current soft body is destroyed destroy_soft_body(); @@ -338,10 +332,9 @@ void SoftBodyBullet::set_trimesh_body_shape(PoolVector<int> p_indices, PoolVecto const int vs_vertices_size(p_vertices.size()); - PoolVector<Vector3>::Read p_vertices_read = p_vertices.read(); + const Vector3 *p_vertices_read = p_vertices.ptr(); for (int vs_vertex_index = 0; vs_vertex_index < vs_vertices_size; ++vs_vertex_index) { - Map<Vector3, int>::Element *e = unique_vertices.find(p_vertices_read[vs_vertex_index]); int vertex_id; if (e) { @@ -353,40 +346,40 @@ void SoftBodyBullet::set_trimesh_body_shape(PoolVector<int> p_indices, PoolVecto indices_table.push_back(Vector<int>()); } - indices_table.write[vertex_id].push_back(vs_vertex_index); + indices_table[vertex_id].push_back(vs_vertex_index); vs_indices_to_physics_table.push_back(vertex_id); } } const int indices_map_size(indices_table.size()); - Vector<btScalar> bt_vertices; + LocalVector<btScalar> bt_vertices; { // Parse vertices to bullet bt_vertices.resize(indices_map_size * 3); - PoolVector<Vector3>::Read p_vertices_read = p_vertices.read(); + const Vector3 *p_vertices_read = p_vertices.ptr(); for (int i = 0; i < indices_map_size; ++i) { - bt_vertices.write[3 * i + 0] = p_vertices_read[indices_table[i][0]].x; - bt_vertices.write[3 * i + 1] = p_vertices_read[indices_table[i][0]].y; - bt_vertices.write[3 * i + 2] = p_vertices_read[indices_table[i][0]].z; + bt_vertices[3 * i + 0] = p_vertices_read[indices_table[i][0]].x; + bt_vertices[3 * i + 1] = p_vertices_read[indices_table[i][0]].y; + bt_vertices[3 * i + 2] = p_vertices_read[indices_table[i][0]].z; } } - Vector<int> bt_triangles; + LocalVector<int> bt_triangles; const int triangles_size(p_indices.size() / 3); { // Parse indices bt_triangles.resize(triangles_size * 3); - PoolVector<int>::Read p_indices_read = p_indices.read(); + const int *p_indices_read = p_indices.ptr(); for (int i = 0; i < triangles_size; ++i) { - bt_triangles.write[3 * i + 0] = vs_indices_to_physics_table[p_indices_read[3 * i + 2]]; - bt_triangles.write[3 * i + 1] = vs_indices_to_physics_table[p_indices_read[3 * i + 1]]; - bt_triangles.write[3 * i + 2] = vs_indices_to_physics_table[p_indices_read[3 * i + 0]]; + bt_triangles[3 * i + 0] = vs_indices_to_physics_table[p_indices_read[3 * i + 2]]; + bt_triangles[3 * i + 1] = vs_indices_to_physics_table[p_indices_read[3 * i + 1]]; + bt_triangles[3 * i + 2] = vs_indices_to_physics_table[p_indices_read[3 * i + 0]]; } } @@ -397,13 +390,13 @@ void SoftBodyBullet::set_trimesh_body_shape(PoolVector<int> p_indices, PoolVecto } void SoftBodyBullet::setup_soft_body() { - - if (!bt_soft_body) + if (!bt_soft_body) { return; + } // Soft body setup setupBulletCollisionObject(bt_soft_body); - bt_soft_body->m_worldInfo = NULL; // Remove fake world info + bt_soft_body->m_worldInfo = nullptr; // Remove fake world info bt_soft_body->getCollisionShape()->setMargin(0.01); bt_soft_body->setCollisionFlags(bt_soft_body->getCollisionFlags() & (~(btCollisionObject::CF_KINEMATIC_OBJECT | btCollisionObject::CF_STATIC_OBJECT))); diff --git a/modules/bullet/soft_body_bullet.h b/modules/bullet/soft_body_bullet.h index b98116b073..229204b539 100644 --- a/modules/bullet/soft_body_bullet.h +++ b/modules/bullet/soft_body_bullet.h @@ -32,7 +32,6 @@ #define SOFT_BODY_BULLET_H #include "collision_object_bullet.h" -#include "scene/resources/material.h" // TODO remove this please #ifdef None /// This is required to remove the macro None defined by x11 compiler because this word "None" is used internally by Bullet @@ -43,7 +42,7 @@ #include "BulletSoftBody/btSoftBodyHelpers.h" #include "collision_object_bullet.h" #include "scene/resources/mesh.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" #ifdef x11_None /// This is required to re add the macro None defined by x11 compiler @@ -56,25 +55,24 @@ */ class SoftBodyBullet : public CollisionObjectBullet { - private: - btSoftBody *bt_soft_body; - Vector<Vector<int> > indices_table; + btSoftBody *bt_soft_body = nullptr; + LocalVector<Vector<int>> indices_table; btSoftBody::Material *mat0; // This is just a copy of pointer managed by btSoftBody - bool isScratched; + bool isScratched = false; Ref<Mesh> soft_mesh; - int simulation_precision; - real_t total_mass; - real_t linear_stiffness; // [0,1] - real_t areaAngular_stiffness; // [0,1] - real_t volume_stiffness; // [0,1] - real_t pressure_coefficient; // [-inf,+inf] - real_t pose_matching_coefficient; // [0,1] - real_t damping_coefficient; // [0,1] - real_t drag_coefficient; // [0,1] - Vector<int> pinned_nodes; + int simulation_precision = 5; + real_t total_mass = 1.; + real_t linear_stiffness = 0.5; // [0,1] + real_t areaAngular_stiffness = 0.5; // [0,1] + real_t volume_stiffness = 0.5; // [0,1] + real_t pressure_coefficient = 0.; // [-inf,+inf] + real_t pose_matching_coefficient = 0.; // [0,1] + real_t damping_coefficient = 0.01; // [0,1] + real_t drag_coefficient = 0.; // [0,1] + LocalVector<int> pinned_nodes; // Other property to add //btScalar kVC; // Volume conversation coefficient [0,+inf] @@ -88,19 +86,18 @@ public: SoftBodyBullet(); ~SoftBodyBullet(); - virtual void reload_body(); - virtual void set_space(SpaceBullet *p_space); + virtual void do_reload_body() override; + virtual void set_space(SpaceBullet *p_space) override; - virtual void dispatch_callbacks() {} - virtual void on_collision_filters_change() {} - virtual void on_collision_checker_start() {} - virtual void on_collision_checker_end() {} - virtual void on_enter_area(AreaBullet *p_area); - virtual void on_exit_area(AreaBullet *p_area); + virtual void do_reload_collision_filters() override {} + virtual void on_collision_checker_start() override {} + virtual void on_collision_checker_end() override {} + virtual void on_enter_area(AreaBullet *p_area) override; + virtual void on_exit_area(AreaBullet *p_area) override; _FORCE_INLINE_ btSoftBody *get_bt_soft_body() const { return bt_soft_body; } - void update_visual_server(class SoftBodyVisualServerHandler *p_visual_server_handler); + void update_rendering_server(class SoftBodyRenderingServerHandler *p_rendering_server_handler); void set_soft_mesh(const Ref<Mesh> &p_mesh); void destroy_soft_body(); @@ -152,7 +149,7 @@ public: _FORCE_INLINE_ real_t get_drag_coefficient() const { return drag_coefficient; } private: - void set_trimesh_body_shape(PoolVector<int> p_indices, PoolVector<Vector3> p_vertices); + void set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector3> p_vertices); void setup_soft_body(); void pin_node(int p_node_index); diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index 0f50d31611..d0515e7c97 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -39,7 +39,7 @@ #include "godot_collision_configuration.h" #include "godot_collision_dispatcher.h" #include "rigid_body_bullet.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" #include "soft_body_bullet.h" #include <BulletCollision/BroadphaseCollision/btBroadphaseProxy.h> @@ -59,13 +59,13 @@ */ BulletPhysicsDirectSpaceState::BulletPhysicsDirectSpaceState(SpaceBullet *p_space) : - PhysicsDirectSpaceState(), + PhysicsDirectSpaceState3D(), space(p_space) {} int BulletPhysicsDirectSpaceState::intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - - if (p_result_max <= 0) + if (p_result_max <= 0) { return 0; + } btVector3 bt_point; G_TO_B(p_point, bt_point); @@ -86,7 +86,6 @@ int BulletPhysicsDirectSpaceState::intersect_point(const Vector3 &p_point, Shape } bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_pick_ray) { - btVector3 btVec_from; btVector3 btVec_to; @@ -108,9 +107,9 @@ bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const V r_result.shape = btResult.m_shapeId; r_result.rid = gObj->get_self(); r_result.collider_id = gObj->get_instance_id(); - r_result.collider = 0 == r_result.collider_id ? NULL : ObjectDB::get_instance(r_result.collider_id); + r_result.collider = r_result.collider_id.is_null() ? nullptr : ObjectDB::get_instance(r_result.collider_id); } else { - WARN_PRINTS("The raycast performed has hit a collision object that is not part of Godot scene, please check it."); + WARN_PRINT("The raycast performed has hit a collision object that is not part of Godot scene, please check it."); } return true; } else { @@ -119,15 +118,17 @@ bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const V } int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - if (p_result_max <= 0) + if (p_result_max <= 0) { return 0; + } - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); + ERR_FAIL_COND_V(!shape, 0); btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale_abs(), p_margin); if (!btShape->isConvex()) { - bulletdelete(btShape); - ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); + shape->destroy_bt_shape(btShape); + ERR_PRINT("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); return 0; } btConvexShape *btConvex = static_cast<btConvexShape *>(btShape); @@ -146,25 +147,28 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra btQuery.m_closestDistanceThreshold = 0; space->dynamicsWorld->contactTest(&collision_object, btQuery); - bulletdelete(btConvex); + shape->destroy_bt_shape(btShape); return btQuery.m_count; } bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &r_closest_safe, float &r_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, ShapeRestInfo *r_info) { - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); + r_closest_safe = 0.0f; + r_closest_unsafe = 0.0f; + btVector3 bt_motion; + G_TO_B(p_motion, bt_motion); + + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); + ERR_FAIL_COND_V(!shape, false); btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale(), p_margin); if (!btShape->isConvex()) { - bulletdelete(btShape); - ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); + shape->destroy_bt_shape(btShape); + ERR_PRINT("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); return false; } btConvexShape *bt_convex_shape = static_cast<btConvexShape *>(btShape); - btVector3 bt_motion; - G_TO_B(p_motion, bt_motion); - btTransform bt_xform_from; G_TO_B(p_xform, bt_xform_from); UNSCALE_BT_BASIS(bt_xform_from); @@ -172,15 +176,17 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf btTransform bt_xform_to(bt_xform_from); bt_xform_to.getOrigin() += bt_motion; + if ((bt_xform_to.getOrigin() - bt_xform_from.getOrigin()).fuzzyZero()) { + shape->destroy_bt_shape(btShape); + return false; + } + GodotClosestConvexResultCallback btResult(bt_xform_from.getOrigin(), bt_xform_to.getOrigin(), &p_exclude, p_collide_with_bodies, p_collide_with_areas); btResult.m_collisionFilterGroup = 0; btResult.m_collisionFilterMask = p_collision_mask; space->dynamicsWorld->convexSweepTest(bt_convex_shape, bt_xform_from, bt_xform_to, btResult, space->dynamicsWorld->getDispatchInfo().m_allowedCcdPenetration); - r_closest_unsafe = 1.0; - r_closest_safe = 1.0; - if (btResult.hasHit()) { const btScalar l = bt_motion.length(); r_closest_unsafe = btResult.m_closestHitFraction; @@ -196,24 +202,29 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf r_info->collider_id = collision_object->get_instance_id(); r_info->shape = btResult.m_shapeId; } + } else { + r_closest_safe = 1.0f; + r_closest_unsafe = 1.0f; } - bulletdelete(bt_convex_shape); + shape->destroy_bt_shape(btShape); return true; // Mean success } /// Returns the list of contacts pairs in this order: Local contact, other body contact bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - if (p_result_max <= 0) - return 0; + if (p_result_max <= 0) { + return false; + } - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); + ERR_FAIL_COND_V(!shape, false); btCollisionShape *btShape = shape->create_bt_shape(p_shape_xform.basis.get_scale_abs(), p_margin); if (!btShape->isConvex()) { - bulletdelete(btShape); - ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); - return 0; + shape->destroy_bt_shape(btShape); + ERR_PRINT("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); + return false; } btConvexShape *btConvex = static_cast<btConvexShape *>(btShape); @@ -232,20 +243,20 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform & space->dynamicsWorld->contactTest(&collision_object, btQuery); r_result_count = btQuery.m_count; - bulletdelete(btConvex); + shape->destroy_bt_shape(btShape); return btQuery.m_count; } bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); + ERR_FAIL_COND_V(!shape, false); btCollisionShape *btShape = shape->create_bt_shape(p_shape_xform.basis.get_scale_abs(), p_margin); if (!btShape->isConvex()) { - bulletdelete(btShape); - ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); - return 0; + shape->destroy_bt_shape(btShape); + ERR_PRINT("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); + return false; } btConvexShape *btConvex = static_cast<btConvexShape *>(btShape); @@ -263,7 +274,7 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh btQuery.m_closestDistanceThreshold = 0; space->dynamicsWorld->contactTest(&collision_object, btQuery); - bulletdelete(btConvex); + shape->destroy_bt_shape(btShape); if (btQuery.m_collided) { if (btCollisionObject::CO_RIGID_BODY == btQuery.m_rest_info_collision_object->getInternalType()) { @@ -276,8 +287,7 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh } Vector3 BulletPhysicsDirectSpaceState::get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const { - - RigidCollisionObjectBullet *rigid_object = space->get_physics_server()->get_rigid_collisin_object(p_object); + RigidCollisionObjectBullet *rigid_object = space->get_physics_server()->get_rigid_collision_object(p_object); ERR_FAIL_COND_V(!rigid_object, Vector3()); btVector3 out_closest_point(0, 0, 0); @@ -309,7 +319,7 @@ Vector3 BulletPhysicsDirectSpaceState::get_closest_point_to_object_volume(RID p_ btPointCollector result; btGjkPairDetector gjk_pair_detector(&point_shape, convex_shape, space->gjk_simplex_solver, space->gjk_epa_pen_solver); - gjk_pair_detector.getClosestPoints(input, result, 0); + gjk_pair_detector.getClosestPoints(input, result, nullptr); if (out_distance > result.m_distance) { out_distance = result.m_distance; @@ -320,31 +330,16 @@ Vector3 BulletPhysicsDirectSpaceState::get_closest_point_to_object_volume(RID p_ } if (shapes_found) { - Vector3 out; B_TO_G(out_closest_point, out); return out; } else { - // no shapes found, use distance to origin. return rigid_object->get_transform().get_origin(); } } -SpaceBullet::SpaceBullet() : - broadphase(NULL), - collisionConfiguration(NULL), - dispatcher(NULL), - solver(NULL), - dynamicsWorld(NULL), - soft_body_world_info(NULL), - ghostPairCallback(NULL), - godotFilterCallback(NULL), - gravityDirection(0, -1, 0), - gravityMagnitude(10), - contactDebugCount(0), - delta_time(0.) { - +SpaceBullet::SpaceBullet() { create_empty_world(GLOBAL_DEF("physics/3d/active_soft_world", true)); direct_access = memnew(BulletPhysicsDirectSpaceState(this)); } @@ -354,112 +349,162 @@ SpaceBullet::~SpaceBullet() { destroy_world(); } +void SpaceBullet::add_to_pre_flush_queue(CollisionObjectBullet *p_co) { + if (p_co->is_in_flush_queue == false) { + p_co->is_in_flush_queue = true; + queue_pre_flush.push_back(p_co); + } +} + +void SpaceBullet::add_to_flush_queue(CollisionObjectBullet *p_co) { + if (p_co->is_in_flush_queue == false) { + p_co->is_in_flush_queue = true; + queue_flush.push_back(p_co); + } +} + +void SpaceBullet::remove_from_any_queue(CollisionObjectBullet *p_co) { + if (p_co->is_in_flush_queue) { + p_co->is_in_flush_queue = false; + queue_pre_flush.erase(p_co); + queue_flush.erase(p_co); + } +} + void SpaceBullet::flush_queries() { - const btCollisionObjectArray &colObjArray = dynamicsWorld->getCollisionObjectArray(); - for (int i = colObjArray.size() - 1; 0 <= i; --i) { - static_cast<CollisionObjectBullet *>(colObjArray[i]->getUserPointer())->dispatch_callbacks(); + for (uint32_t i = 0; i < queue_pre_flush.size(); i += 1) { + queue_pre_flush[i]->dispatch_callbacks(); + queue_pre_flush[i]->is_in_flush_queue = false; + } + for (uint32_t i = 0; i < queue_flush.size(); i += 1) { + queue_flush[i]->dispatch_callbacks(); + queue_flush[i]->is_in_flush_queue = false; } + queue_pre_flush.clear(); + queue_flush.clear(); } void SpaceBullet::step(real_t p_delta_time) { + for (uint32_t i = 0; i < collision_objects.size(); i += 1) { + collision_objects[i]->pre_process(); + } + delta_time = p_delta_time; dynamicsWorld->stepSimulation(p_delta_time, 0, 0); } -void SpaceBullet::set_param(PhysicsServer::AreaParameter p_param, const Variant &p_value) { +void SpaceBullet::set_param(PhysicsServer3D::AreaParameter p_param, const Variant &p_value) { assert(dynamicsWorld); switch (p_param) { - case PhysicsServer::AREA_PARAM_GRAVITY: + case PhysicsServer3D::AREA_PARAM_GRAVITY: gravityMagnitude = p_value; update_gravity(); break; - case PhysicsServer::AREA_PARAM_GRAVITY_VECTOR: + case PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR: gravityDirection = p_value; update_gravity(); break; - case PhysicsServer::AREA_PARAM_LINEAR_DAMP: - case PhysicsServer::AREA_PARAM_ANGULAR_DAMP: - break; // No damp - case PhysicsServer::AREA_PARAM_PRIORITY: + case PhysicsServer3D::AREA_PARAM_LINEAR_DAMP: + linear_damp = p_value; + break; + case PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP: + angular_damp = p_value; + break; + case PhysicsServer3D::AREA_PARAM_PRIORITY: // Priority is always 0, the lower break; - case PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT: - case PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE: - case PhysicsServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: + case PhysicsServer3D::AREA_PARAM_GRAVITY_IS_POINT: + case PhysicsServer3D::AREA_PARAM_GRAVITY_DISTANCE_SCALE: + case PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_ATTENUATION: break; default: - WARN_PRINTS("This set parameter (" + itos(p_param) + ") is ignored, the SpaceBullet doesn't support it."); + WARN_PRINT("This set parameter (" + itos(p_param) + ") is ignored, the SpaceBullet doesn't support it."); break; } } -Variant SpaceBullet::get_param(PhysicsServer::AreaParameter p_param) { +Variant SpaceBullet::get_param(PhysicsServer3D::AreaParameter p_param) { switch (p_param) { - case PhysicsServer::AREA_PARAM_GRAVITY: + case PhysicsServer3D::AREA_PARAM_GRAVITY: return gravityMagnitude; - case PhysicsServer::AREA_PARAM_GRAVITY_VECTOR: + case PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR: return gravityDirection; - case PhysicsServer::AREA_PARAM_LINEAR_DAMP: - case PhysicsServer::AREA_PARAM_ANGULAR_DAMP: - return 0; // No damp - case PhysicsServer::AREA_PARAM_PRIORITY: + case PhysicsServer3D::AREA_PARAM_LINEAR_DAMP: + return linear_damp; + case PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP: + return angular_damp; + case PhysicsServer3D::AREA_PARAM_PRIORITY: return 0; // Priority is always 0, the lower - case PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT: + case PhysicsServer3D::AREA_PARAM_GRAVITY_IS_POINT: return false; - case PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE: + case PhysicsServer3D::AREA_PARAM_GRAVITY_DISTANCE_SCALE: return 0; - case PhysicsServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: + case PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_ATTENUATION: return 0; default: - WARN_PRINTS("This get parameter (" + itos(p_param) + ") is ignored, the SpaceBullet doesn't support it."); + WARN_PRINT("This get parameter (" + itos(p_param) + ") is ignored, the SpaceBullet doesn't support it."); return Variant(); } } -void SpaceBullet::set_param(PhysicsServer::SpaceParameter p_param, real_t p_value) { +void SpaceBullet::set_param(PhysicsServer3D::SpaceParameter p_param, real_t p_value) { switch (p_param) { - case PhysicsServer::SPACE_PARAM_CONTACT_RECYCLE_RADIUS: - case PhysicsServer::SPACE_PARAM_CONTACT_MAX_SEPARATION: - case PhysicsServer::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION: - case PhysicsServer::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD: - case PhysicsServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD: - case PhysicsServer::SPACE_PARAM_BODY_TIME_TO_SLEEP: - case PhysicsServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO: - case PhysicsServer::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: + case PhysicsServer3D::SPACE_PARAM_CONTACT_RECYCLE_RADIUS: + case PhysicsServer3D::SPACE_PARAM_CONTACT_MAX_SEPARATION: + case PhysicsServer3D::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION: + case PhysicsServer3D::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD: + case PhysicsServer3D::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD: + case PhysicsServer3D::SPACE_PARAM_BODY_TIME_TO_SLEEP: + case PhysicsServer3D::SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO: + case PhysicsServer3D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: default: - WARN_PRINTS("This set parameter (" + itos(p_param) + ") is ignored, the SpaceBullet doesn't support it."); + WARN_PRINT("This set parameter (" + itos(p_param) + ") is ignored, the SpaceBullet doesn't support it."); break; } } -real_t SpaceBullet::get_param(PhysicsServer::SpaceParameter p_param) { +real_t SpaceBullet::get_param(PhysicsServer3D::SpaceParameter p_param) { switch (p_param) { - case PhysicsServer::SPACE_PARAM_CONTACT_RECYCLE_RADIUS: - case PhysicsServer::SPACE_PARAM_CONTACT_MAX_SEPARATION: - case PhysicsServer::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION: - case PhysicsServer::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD: - case PhysicsServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD: - case PhysicsServer::SPACE_PARAM_BODY_TIME_TO_SLEEP: - case PhysicsServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO: - case PhysicsServer::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: + case PhysicsServer3D::SPACE_PARAM_CONTACT_RECYCLE_RADIUS: + case PhysicsServer3D::SPACE_PARAM_CONTACT_MAX_SEPARATION: + case PhysicsServer3D::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION: + case PhysicsServer3D::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD: + case PhysicsServer3D::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD: + case PhysicsServer3D::SPACE_PARAM_BODY_TIME_TO_SLEEP: + case PhysicsServer3D::SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO: + case PhysicsServer3D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: default: - WARN_PRINTS("The SpaceBullet doesn't support this get parameter (" + itos(p_param) + "), 0 is returned."); + WARN_PRINT("The SpaceBullet doesn't support this get parameter (" + itos(p_param) + "), 0 is returned."); return 0.f; } } void SpaceBullet::add_area(AreaBullet *p_area) { +#ifdef TOOLS_ENABLED + // This never happen, and there is no way for the user to trigger it. + // If in future a bug is introduced into this bullet integration and this + // function is called twice, the crash will notify the developer that will + // fix it even before do the eventual PR. + CRASH_COND(p_area->is_in_world); +#endif areas.push_back(p_area); dynamicsWorld->addCollisionObject(p_area->get_bt_ghost(), p_area->get_collision_layer(), p_area->get_collision_mask()); + p_area->is_in_world = true; } void SpaceBullet::remove_area(AreaBullet *p_area) { - areas.erase(p_area); - dynamicsWorld->removeCollisionObject(p_area->get_bt_ghost()); + if (p_area->is_in_world) { + areas.erase(p_area); + dynamicsWorld->removeCollisionObject(p_area->get_bt_ghost()); + p_area->is_in_world = false; + } } void SpaceBullet::reload_collision_filters(AreaBullet *p_area) { + if (p_area->is_in_world == false) { + return; + } btGhostObject *ghost_object = p_area->get_bt_ghost(); btBroadphaseProxy *ghost_proxy = ghost_object->getBroadphaseHandle(); @@ -469,24 +514,47 @@ void SpaceBullet::reload_collision_filters(AreaBullet *p_area) { dynamicsWorld->refreshBroadphaseProxy(ghost_object); } +void SpaceBullet::register_collision_object(CollisionObjectBullet *p_object) { + collision_objects.push_back(p_object); +} + +void SpaceBullet::unregister_collision_object(CollisionObjectBullet *p_object) { + remove_from_any_queue(p_object); + collision_objects.erase(p_object); +} + void SpaceBullet::add_rigid_body(RigidBodyBullet *p_body) { +#ifdef TOOLS_ENABLED + // This never happen, and there is no way for the user to trigger it. + // If in future a bug is introduced into this bullet integration and this + // function is called twice, the crash will notify the developer that will + // fix it even before do the eventual PR. + CRASH_COND(p_body->is_in_world); +#endif if (p_body->is_static()) { dynamicsWorld->addCollisionObject(p_body->get_bt_rigid_body(), p_body->get_collision_layer(), p_body->get_collision_mask()); } else { dynamicsWorld->addRigidBody(p_body->get_bt_rigid_body(), p_body->get_collision_layer(), p_body->get_collision_mask()); p_body->scratch_space_override_modificator(); } + p_body->is_in_world = true; } void SpaceBullet::remove_rigid_body(RigidBodyBullet *p_body) { - if (p_body->is_static()) { - dynamicsWorld->removeCollisionObject(p_body->get_bt_rigid_body()); - } else { - dynamicsWorld->removeRigidBody(p_body->get_bt_rigid_body()); + if (p_body->is_in_world) { + if (p_body->is_static()) { + dynamicsWorld->removeCollisionObject(p_body->get_bt_rigid_body()); + } else { + dynamicsWorld->removeRigidBody(p_body->get_bt_rigid_body()); + } + p_body->is_in_world = false; } } void SpaceBullet::reload_collision_filters(RigidBodyBullet *p_body) { + if (p_body->is_in_world == false) { + return; + } btRigidBody *rigid_body = p_body->get_bt_rigid_body(); btBroadphaseProxy *body_proxy = rigid_body->getBroadphaseProxy(); @@ -511,7 +579,7 @@ void SpaceBullet::remove_soft_body(SoftBodyBullet *p_body) { if (is_using_soft_world()) { if (p_body->get_bt_soft_body()) { static_cast<btSoftRigidDynamicsWorld *>(dynamicsWorld)->removeSoftBody(p_body->get_bt_soft_body()); - p_body->get_bt_soft_body()->m_worldInfo = NULL; + p_body->get_bt_soft_body()->m_worldInfo = nullptr; } } } @@ -539,16 +607,11 @@ void SpaceBullet::remove_all_collision_objects() { for (int i = dynamicsWorld->getNumCollisionObjects() - 1; 0 <= i; --i) { btCollisionObject *btObj = dynamicsWorld->getCollisionObjectArray()[i]; CollisionObjectBullet *colObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); - colObj->set_space(NULL); + colObj->set_space(nullptr); } } -void onBulletPreTickCallback(btDynamicsWorld *p_dynamicsWorld, btScalar timeStep) { - static_cast<SpaceBullet *>(p_dynamicsWorld->getWorldUserInfo())->flush_queries(); -} - void onBulletTickCallback(btDynamicsWorld *p_dynamicsWorld, btScalar timeStep) { - const btCollisionObjectArray &colObjArray = p_dynamicsWorld->getCollisionObjectArray(); // Notify all Collision objects the collision checker is started @@ -570,17 +633,14 @@ BulletPhysicsDirectSpaceState *SpaceBullet::get_direct_state() { } btScalar calculateGodotCombinedRestitution(const btCollisionObject *body0, const btCollisionObject *body1) { - return CLAMP(body0->getRestitution() + body1->getRestitution(), 0, 1); } btScalar calculateGodotCombinedFriction(const btCollisionObject *body0, const btCollisionObject *body1) { - return ABS(MIN(body0->getFriction(), body1->getFriction())); } void SpaceBullet::create_empty_world(bool p_create_soft_world) { - gjk_epa_pen_solver = bulletnew(btGjkEpaPenetrationDepthSolver); gjk_simplex_solver = bulletnew(btVoronoiSimplexSolver); @@ -618,7 +678,6 @@ void SpaceBullet::create_empty_world(bool p_create_soft_world) { dynamicsWorld->setWorldUserInfo(this); - dynamicsWorld->setInternalTickCallback(onBulletPreTickCallback, this, true); dynamicsWorld->setInternalTickCallback(onBulletTickCallback, this, false); dynamicsWorld->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(ghostPairCallback); // Setup ghost check dynamicsWorld->getPairCache()->setOverlapFilterCallback(godotFilterCallback); @@ -633,11 +692,10 @@ void SpaceBullet::create_empty_world(bool p_create_soft_world) { } void SpaceBullet::destroy_world() { - /// The world elements (like: Collision Objects, Constraints, Shapes) are managed by godot - dynamicsWorld->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(NULL); - dynamicsWorld->getPairCache()->setOverlapFilterCallback(NULL); + dynamicsWorld->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(nullptr); + dynamicsWorld->getPairCache()->setOverlapFilterCallback(nullptr); bulletdelete(ghostPairCallback); bulletdelete(godotFilterCallback); @@ -645,7 +703,7 @@ void SpaceBullet::destroy_world() { // Deallocate world dynamicsWorld->~btDiscreteDynamicsWorld(); free(dynamicsWorld); - dynamicsWorld = NULL; + dynamicsWorld = nullptr; bulletdelete(solver); bulletdelete(broadphase); @@ -657,7 +715,6 @@ void SpaceBullet::destroy_world() { } void SpaceBullet::check_ghost_overlaps() { - /// Algorithm support variables btCollisionShape *other_body_shape; btConvexShape *area_shape; @@ -671,12 +728,13 @@ void SpaceBullet::check_ghost_overlaps() { btVector3 area_scale(area->get_bt_body_scale()); - if (!area->is_monitoring()) + if (!area->is_monitoring()) { continue; + } /// 1. Reset all states for (i = area->overlappingObjects.size() - 1; 0 <= i; --i) { - AreaBullet::OverlappingObjectData &otherObj = area->overlappingObjects.write[i]; + AreaBullet::OverlappingObjectData &otherObj = area->overlappingObjects[i]; // This check prevent the overwrite of ENTER state // if this function is called more times before dispatchCallbacks if (otherObj.state != AreaBullet::OVERLAP_STATE_ENTER) { @@ -690,7 +748,6 @@ void SpaceBullet::check_ghost_overlaps() { // For each overlapping for (i = ghostOverlaps.size() - 1; 0 <= i; --i) { - bool hasOverlap = false; btCollisionObject *overlapped_bt_co = ghostOverlaps[i]; RigidCollisionObjectBullet *otherObject = static_cast<RigidCollisionObjectBullet *>(overlapped_bt_co->getUserPointer()); @@ -702,15 +759,18 @@ void SpaceBullet::check_ghost_overlaps() { } if (overlapped_bt_co->getUserIndex() == CollisionObjectBullet::TYPE_AREA) { - if (!static_cast<AreaBullet *>(overlapped_bt_co->getUserPointer())->is_monitorable()) + if (!static_cast<AreaBullet *>(overlapped_bt_co->getUserPointer())->is_monitorable()) { continue; - } else if (overlapped_bt_co->getUserIndex() != CollisionObjectBullet::TYPE_RIGID_BODY) + } + } else if (overlapped_bt_co->getUserIndex() != CollisionObjectBullet::TYPE_RIGID_BODY) { continue; + } // For each area shape for (y = area->get_shape_count() - 1; 0 <= y; --y) { - if (!area->get_bt_shape(y)->isConvex()) + if (!area->get_bt_shape(y)->isConvex()) { continue; + } btTransform area_shape_treansform(area->get_bt_shape_transform(y)); area_shape_treansform.getOrigin() *= area_scale; @@ -723,12 +783,8 @@ void SpaceBullet::check_ghost_overlaps() { // For each other object shape for (z = otherObject->get_shape_count() - 1; 0 <= z; --z) { - other_body_shape = static_cast<btCollisionShape *>(otherObject->get_bt_shape(z)); - if (other_body_shape->isConcave()) - continue; - btTransform other_shape_transform(otherObject->get_bt_shape_transform(z)); other_shape_transform.getOrigin() *= other_body_scale; @@ -737,14 +793,13 @@ void SpaceBullet::check_ghost_overlaps() { other_shape_transform; if (other_body_shape->isConvex()) { - btPointCollector result; btGjkPairDetector gjk_pair_detector( area_shape, static_cast<btConvexShape *>(other_body_shape), gjk_simplex_solver, gjk_epa_pen_solver); - gjk_pair_detector.getClosestPoints(gjk_input, result, 0); + gjk_pair_detector.getClosestPoints(gjk_input, result, nullptr); if (0 >= result.m_distance) { hasOverlap = true; @@ -752,14 +807,14 @@ void SpaceBullet::check_ghost_overlaps() { } } else { + btCollisionObjectWrapper obA(nullptr, area_shape, area->get_bt_ghost(), gjk_input.m_transformA, -1, y); + btCollisionObjectWrapper obB(nullptr, other_body_shape, otherObject->get_bt_collision_object(), gjk_input.m_transformB, -1, z); - btCollisionObjectWrapper obA(NULL, area_shape, area->get_bt_ghost(), gjk_input.m_transformA, -1, y); - btCollisionObjectWrapper obB(NULL, other_body_shape, otherObject->get_bt_collision_object(), gjk_input.m_transformB, -1, z); - - btCollisionAlgorithm *algorithm = dispatcher->findAlgorithm(&obA, &obB, NULL, BT_CONTACT_POINT_ALGORITHMS); + btCollisionAlgorithm *algorithm = dispatcher->findAlgorithm(&obA, &obB, nullptr, BT_CONTACT_POINT_ALGORITHMS); - if (!algorithm) + if (!algorithm) { continue; + } GodotDeepPenetrationContactResultCallback contactPointResult(&obA, &obB); algorithm->processCollision(&obA, &obB, dynamicsWorld->getDispatchInfo(), &contactPointResult); @@ -777,8 +832,9 @@ void SpaceBullet::check_ghost_overlaps() { } // ~For each area shape collision_found: - if (!hasOverlap) + if (!hasOverlap) { continue; + } indexOverlap = area->find_overlapping_object(otherObject); if (-1 == indexOverlap) { @@ -835,7 +891,6 @@ void SpaceBullet::check_body_collision() { pt.getDistance() <= 0.0 || bodyA->was_colliding(bodyB) || bodyB->was_colliding(bodyA)) { - Vector3 collisionWorldPosition; Vector3 collisionLocalPosition; Vector3 normalOnB; @@ -888,41 +943,40 @@ void SpaceBullet::update_gravity() { #include "scene/3d/immediate_geometry.h" -static ImmediateGeometry *motionVec(NULL); -static ImmediateGeometry *normalLine(NULL); -static Ref<SpatialMaterial> red_mat; -static Ref<SpatialMaterial> blue_mat; +static ImmediateGeometry3D *motionVec(nullptr); +static ImmediateGeometry3D *normalLine(nullptr); +static Ref<StandardMaterial3D> red_mat; +static Ref<StandardMaterial3D> blue_mat; #endif -bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer::MotionResult *r_result, bool p_exclude_raycast_shapes) { - +bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult *r_result, bool p_exclude_raycast_shapes) { #if debug_test_motion /// Yes I know this is not good, but I've used it as fast debugging hack. /// I'm leaving it here just for speedup the other eventual debugs if (!normalLine) { - motionVec = memnew(ImmediateGeometry); - normalLine = memnew(ImmediateGeometry); + motionVec = memnew(ImmediateGeometry3D); + normalLine = memnew(ImmediateGeometry3D); SceneTree::get_singleton()->get_current_scene()->add_child(motionVec); SceneTree::get_singleton()->get_current_scene()->add_child(normalLine); motionVec->set_as_toplevel(true); normalLine->set_as_toplevel(true); - red_mat = Ref<SpatialMaterial>(memnew(SpatialMaterial)); - red_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + red_mat = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); + red_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); red_mat->set_line_width(20.0); - red_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - red_mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - red_mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + red_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + red_mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + red_mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); red_mat->set_albedo(Color(1, 0, 0, 1)); motionVec->set_material_override(red_mat); - blue_mat = Ref<SpatialMaterial>(memnew(SpatialMaterial)); - blue_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + blue_mat = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); + blue_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); blue_mat->set_line_width(20.0); - blue_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - blue_mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - blue_mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + blue_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + blue_mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + blue_mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); blue_mat->set_albedo(Color(0, 0, 1, 1)); normalLine->set_material_override(blue_mat); } @@ -954,13 +1008,13 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f Vector3 sup_line; B_TO_G(body_safe_position.getOrigin(), sup_line); motionVec->clear(); - motionVec->begin(Mesh::PRIMITIVE_LINES, NULL); + motionVec->begin(Mesh::PRIMITIVE_LINES, nullptr); motionVec->add_vertex(sup_line); motionVec->add_vertex(sup_line + p_motion * 10); motionVec->end(); #endif - for (int shIndex = 0; shIndex < shape_count && !motion.fuzzyZero(); ++shIndex) { + for (int shIndex = 0; shIndex < shape_count; ++shIndex) { if (p_body->is_shape_disabled(shIndex)) { continue; } @@ -982,6 +1036,11 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f btTransform shape_world_to(shape_world_from); shape_world_to.getOrigin() += motion; + if ((shape_world_to.getOrigin() - shape_world_from.getOrigin()).fuzzyZero()) { + motion = btVector3(0, 0, 0); + break; + } + GodotKinClosestConvexResultCallback btResult(shape_world_from.getOrigin(), shape_world_to.getOrigin(), p_body, p_infinite_inertia); btResult.m_collisionFilterGroup = p_body->get_collision_layer(); btResult.m_collisionFilterMask = p_body->get_collision_mask(); @@ -1012,7 +1071,6 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f B_TO_G(motion + initial_recover_motion + __rec, r_result->motion); if (has_penetration) { - const btRigidBody *btRigid = static_cast<const btRigidBody *>(r_recover_result.other_collision_object); CollisionObjectBullet *collisionObject = static_cast<CollisionObjectBullet *>(btRigid->getUserPointer()); @@ -1031,7 +1089,7 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f Vector3 sup_line2; B_TO_G(motion, sup_line2); normalLine->clear(); - normalLine->begin(Mesh::PRIMITIVE_LINES, NULL); + normalLine->begin(Mesh::PRIMITIVE_LINES, nullptr); normalLine->add_vertex(r_result->collision_point); normalLine->add_vertex(r_result->collision_point + r_result->collision_normal * 10); normalLine->end(); @@ -1045,8 +1103,7 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f return has_penetration; } -int SpaceBullet::test_ray_separation(RigidBodyBullet *p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, PhysicsServer::SeparationResult *r_results, int p_result_max, float p_margin) { - +int SpaceBullet::test_ray_separation(RigidBodyBullet *p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, PhysicsServer3D::SeparationResult *r_results, int p_result_max, float p_margin) { btTransform body_transform; G_TO_B(p_transform, body_transform); UNSCALE_BT_BASIS(body_transform); @@ -1057,7 +1114,7 @@ int SpaceBullet::test_ray_separation(RigidBodyBullet *p_body, const Transform &p int rays_found_this_round = 0; for (int t(RECOVERING_MOVEMENT_CYCLES); 0 < t; --t) { - PhysicsServer::SeparationResult *next_results = &r_results[rays_found]; + PhysicsServer3D::SeparationResult *next_results = &r_results[rays_found]; rays_found_this_round = recover_from_penetration_ray(p_body, body_transform, RECOVERING_MOVEMENT_SCALE, p_infinite_inertia, p_result_max - rays_found, recover_motion, next_results); rays_found += rays_found_this_round; @@ -1111,14 +1168,12 @@ public: self_collision_object(p_self_collision_object), collision_layer(p_collision_layer), collision_mask(p_collision_mask) { - bounds = btDbvtVolume::FromMM(p_aabb_min, p_aabb_max); } virtual ~RecoverPenetrationBroadPhaseCallback() {} virtual bool process(const btBroadphaseProxy *proxy) { - btCollisionObject *co = static_cast<btCollisionObject *>(proxy->m_clientObject); if (co->getInternalType() <= btCollisionObject::CO_RIGID_BODY) { if (self_collision_object != proxy->m_clientObject && GodotFilterCallback::test_collision_filters(collision_layer, collision_mask, proxy->m_collisionFilterGroup, proxy->m_collisionFilterMask)) { @@ -1127,7 +1182,7 @@ public: if (cs->getNumChildShapes() > 1) { const btDbvt *tree = cs->getDynamicAabbTree(); - ERR_FAIL_COND_V(tree == NULL, true); + ERR_FAIL_COND_V(tree == nullptr, true); // Transform bounds into compound shape local space const btTransform other_in_compound_space = co->getWorldTransform().inverse(); @@ -1162,13 +1217,11 @@ public: }; bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, bool p_infinite_inertia, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result) { - // Calculate the cumulative AABB of all shapes of the kinematic body btVector3 aabb_min, aabb_max; bool shapes_found = false; for (int kinIndex = p_body->get_kinematic_utilities()->shapes.size() - 1; 0 <= kinIndex; --kinIndex) { - const RigidBodyBullet::KinematicShape &kin_shape(p_body->get_kinematic_utilities()->shapes[kinIndex]); if (!kin_shape.is_active()) { continue; @@ -1213,7 +1266,6 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran // Perform narrowphase per shape for (int kinIndex = p_body->get_kinematic_utilities()->shapes.size() - 1; 0 <= kinIndex; --kinIndex) { - const RigidBodyBullet::KinematicShape &kin_shape(p_body->get_kinematic_utilities()->shapes[kinIndex]); if (!kin_shape.is_active()) { continue; @@ -1232,8 +1284,9 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran if (p_infinite_inertia && !otherObject->isStaticOrKinematicObject()) { otherObject->activate(); // Force activation of hitten rigid, soft body continue; - } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) + } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) { continue; + } if (otherObject->getCollisionShape()->isCompound()) { const btCompoundShape *cs = static_cast<const btCompoundShape *>(otherObject->getCollisionShape()); @@ -1242,23 +1295,19 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran if (cs->getChildShape(shape_idx)->isConvex()) { if (RFP_convex_convex_test(kin_shape.shape, static_cast<const btConvexShape *>(cs->getChildShape(shape_idx)), otherObject, kinIndex, shape_idx, shape_transform, otherObject->getWorldTransform() * cs->getChildTransform(shape_idx), p_recover_movement_scale, r_delta_recover_movement, r_recover_result)) { - penetration = true; } } else { if (RFP_convex_world_test(kin_shape.shape, cs->getChildShape(shape_idx), p_body->get_bt_collision_object(), otherObject, kinIndex, shape_idx, shape_transform, otherObject->getWorldTransform() * cs->getChildTransform(shape_idx), p_recover_movement_scale, r_delta_recover_movement, r_recover_result)) { - penetration = true; } } } else if (otherObject->getCollisionShape()->isConvex()) { /// Execute GJK test against object shape if (RFP_convex_convex_test(kin_shape.shape, static_cast<const btConvexShape *>(otherObject->getCollisionShape()), otherObject, kinIndex, 0, shape_transform, otherObject->getWorldTransform(), p_recover_movement_scale, r_delta_recover_movement, r_recover_result)) { - penetration = true; } } else { if (RFP_convex_world_test(kin_shape.shape, otherObject->getCollisionShape(), p_body->get_bt_collision_object(), otherObject, kinIndex, 0, shape_transform, otherObject->getWorldTransform(), p_recover_movement_scale, r_delta_recover_movement, r_recover_result)) { - penetration = true; } } @@ -1269,7 +1318,6 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran } bool SpaceBullet::RFP_convex_convex_test(const btConvexShape *p_shapeA, const btConvexShape *p_shapeB, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_recover_movement_scale, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result) { - // Initialize GJK input btGjkPairDetector::ClosestPointInput gjk_input; gjk_input.m_transformA = p_transformA; @@ -1278,7 +1326,7 @@ bool SpaceBullet::RFP_convex_convex_test(const btConvexShape *p_shapeA, const bt // Perform GJK test btPointCollector result; btGjkPairDetector gjk_pair_detector(p_shapeA, p_shapeB, gjk_simplex_solver, gjk_epa_pen_solver); - gjk_pair_detector.getClosestPoints(gjk_input, result, 0); + gjk_pair_detector.getClosestPoints(gjk_input, result, nullptr); if (0 > result.m_distance) { // Has penetration r_delta_recover_movement += result.m_normalOnBInWorld * (result.m_distance * -1 * p_recover_movement_scale); @@ -1300,15 +1348,14 @@ bool SpaceBullet::RFP_convex_convex_test(const btConvexShape *p_shapeA, const bt } bool SpaceBullet::RFP_convex_world_test(const btConvexShape *p_shapeA, const btCollisionShape *p_shapeB, btCollisionObject *p_objectA, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_recover_movement_scale, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result) { - /// Contact test btTransform tA(p_transformA); - btCollisionObjectWrapper obA(NULL, p_shapeA, p_objectA, tA, -1, p_shapeId_A); - btCollisionObjectWrapper obB(NULL, p_shapeB, p_objectB, p_transformB, -1, p_shapeId_B); + btCollisionObjectWrapper obA(nullptr, p_shapeA, p_objectA, tA, -1, p_shapeId_A); + btCollisionObjectWrapper obB(nullptr, p_shapeB, p_objectB, p_transformB, -1, p_shapeId_B); - btCollisionAlgorithm *algorithm = dispatcher->findAlgorithm(&obA, &obB, NULL, BT_CONTACT_POINT_ALGORITHMS); + btCollisionAlgorithm *algorithm = dispatcher->findAlgorithm(&obA, &obB, nullptr, BT_CONTACT_POINT_ALGORITHMS); if (algorithm) { GodotDeepPenetrationContactResultCallback contactPointResult(&obA, &obB); //discrete collision detection query @@ -1336,8 +1383,7 @@ bool SpaceBullet::RFP_convex_world_test(const btConvexShape *p_shapeA, const btC return false; } -int SpaceBullet::add_separation_result(PhysicsServer::SeparationResult *r_result, const SpaceBullet::RecoverResult &p_recover_result, int p_shape_id, const btCollisionObject *p_other_object) const { - +int SpaceBullet::add_separation_result(PhysicsServer3D::SeparationResult *r_result, const SpaceBullet::RecoverResult &p_recover_result, int p_shape_id, const btCollisionObject *p_other_object) const { // optimize results (ignore non-colliding) if (p_recover_result.penetration_distance < 0.0) { const btRigidBody *btRigid = static_cast<const btRigidBody *>(p_other_object); @@ -1358,14 +1404,12 @@ int SpaceBullet::add_separation_result(PhysicsServer::SeparationResult *r_result } } -int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, bool p_infinite_inertia, int p_result_max, btVector3 &r_delta_recover_movement, PhysicsServer::SeparationResult *r_results) { - +int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, bool p_infinite_inertia, int p_result_max, btVector3 &r_delta_recover_movement, PhysicsServer3D::SeparationResult *r_results) { // Calculate the cumulative AABB of all shapes of the kinematic body btVector3 aabb_min, aabb_max; bool shapes_found = false; for (int kinIndex = p_body->get_kinematic_utilities()->shapes.size() - 1; 0 <= kinIndex; --kinIndex) { - const RigidBodyBullet::KinematicShape &kin_shape(p_body->get_kinematic_utilities()->shapes[kinIndex]); if (!kin_shape.is_active()) { continue; @@ -1409,7 +1453,6 @@ int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btT // Perform narrowphase per shape for (int kinIndex = p_body->get_kinematic_utilities()->shapes.size() - 1; 0 <= kinIndex; --kinIndex) { - if (ray_count >= p_result_max) { break; } @@ -1431,8 +1474,9 @@ int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btT if (p_infinite_inertia && !otherObject->isStaticOrKinematicObject()) { otherObject->activate(); // Force activation of hitten rigid, soft body continue; - } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) + } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) { continue; + } if (otherObject->getCollisionShape()->isCompound()) { const btCompoundShape *cs = static_cast<const btCompoundShape *>(otherObject->getCollisionShape()); @@ -1441,14 +1485,11 @@ int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btT RecoverResult recover_result; if (RFP_convex_world_test(kin_shape.shape, cs->getChildShape(shape_idx), p_body->get_bt_collision_object(), otherObject, kinIndex, shape_idx, shape_transform, otherObject->getWorldTransform() * cs->getChildTransform(shape_idx), p_recover_movement_scale, r_delta_recover_movement, &recover_result)) { - ray_count = add_separation_result(&r_results[ray_count], recover_result, kinIndex, otherObject); } } else { - RecoverResult recover_result; if (RFP_convex_world_test(kin_shape.shape, otherObject->getCollisionShape(), p_body->get_bt_collision_object(), otherObject, kinIndex, 0, shape_transform, otherObject->getWorldTransform(), p_recover_movement_scale, r_delta_recover_movement, &recover_result)) { - ray_count = add_separation_result(&r_results[ray_count], recover_result, kinIndex, otherObject); } } diff --git a/modules/bullet/space_bullet.h b/modules/bullet/space_bullet.h index 32372f1630..897f902fe1 100644 --- a/modules/bullet/space_bullet.h +++ b/modules/bullet/space_bullet.h @@ -31,11 +31,11 @@ #ifndef SPACE_BULLET_H #define SPACE_BULLET_H +#include "core/local_vector.h" #include "core/variant.h" -#include "core/vector.h" #include "godot_result_callbacks.h" #include "rid_bullet.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" #include <BulletCollision/BroadphaseCollision/btBroadphaseProxy.h> #include <BulletCollision/BroadphaseCollision/btOverlappingPairCache.h> @@ -67,8 +67,8 @@ class btGjkEpaPenetrationDepthSolver; extern ContactAddedCallback gContactAddedCallback; -class BulletPhysicsDirectSpaceState : public PhysicsDirectSpaceState { - GDCLASS(BulletPhysicsDirectSpaceState, PhysicsDirectSpaceState); +class BulletPhysicsDirectSpaceState : public PhysicsDirectSpaceState3D { + GDCLASS(BulletPhysicsDirectSpaceState, PhysicsDirectSpaceState3D); private: SpaceBullet *space; @@ -76,75 +76,90 @@ private: public: BulletPhysicsDirectSpaceState(SpaceBullet *p_space); - virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_ray = false); - virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &r_closest_safe, float &r_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = NULL); + virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override; + virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_ray = false) override; + virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override; + virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &r_closest_safe, float &r_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = nullptr) override; /// Returns the list of contacts pairs in this order: Local contact, other body contact - virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const; + virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override; + virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override; + virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const override; }; class SpaceBullet : public RIDBullet { - friend class AreaBullet; friend void onBulletTickCallback(btDynamicsWorld *world, btScalar timeStep); friend class BulletPhysicsDirectSpaceState; - btBroadphaseInterface *broadphase; - btDefaultCollisionConfiguration *collisionConfiguration; - btCollisionDispatcher *dispatcher; - btConstraintSolver *solver; - btDiscreteDynamicsWorld *dynamicsWorld; - btSoftBodyWorldInfo *soft_body_world_info; - btGhostPairCallback *ghostPairCallback; - GodotFilterCallback *godotFilterCallback; + btBroadphaseInterface *broadphase = nullptr; + btDefaultCollisionConfiguration *collisionConfiguration = nullptr; + btCollisionDispatcher *dispatcher = nullptr; + btConstraintSolver *solver = nullptr; + btDiscreteDynamicsWorld *dynamicsWorld = nullptr; + btSoftBodyWorldInfo *soft_body_world_info = nullptr; + btGhostPairCallback *ghostPairCallback = nullptr; + GodotFilterCallback *godotFilterCallback = nullptr; btGjkEpaPenetrationDepthSolver *gjk_epa_pen_solver; btVoronoiSimplexSolver *gjk_simplex_solver; BulletPhysicsDirectSpaceState *direct_access; - Vector3 gravityDirection; - real_t gravityMagnitude; + Vector3 gravityDirection = Vector3(0, -1, 0); + real_t gravityMagnitude = 10; + + real_t linear_damp = 0.0; + real_t angular_damp = 0.0; - Vector<AreaBullet *> areas; + LocalVector<CollisionObjectBullet *> queue_pre_flush; + LocalVector<CollisionObjectBullet *> queue_flush; + LocalVector<CollisionObjectBullet *> collision_objects; + LocalVector<AreaBullet *> areas; - Vector<Vector3> contactDebug; - int contactDebugCount; - real_t delta_time; + LocalVector<Vector3> contactDebug; + uint32_t contactDebugCount = 0; + real_t delta_time = 0.; public: SpaceBullet(); virtual ~SpaceBullet(); + void add_to_flush_queue(CollisionObjectBullet *p_co); + void add_to_pre_flush_queue(CollisionObjectBullet *p_co); + void remove_from_any_queue(CollisionObjectBullet *p_co); + void flush_queries(); real_t get_delta_time() { return delta_time; } void step(real_t p_delta_time); - _FORCE_INLINE_ btBroadphaseInterface *get_broadphase() { return broadphase; } - _FORCE_INLINE_ btCollisionDispatcher *get_dispatcher() { return dispatcher; } - _FORCE_INLINE_ btSoftBodyWorldInfo *get_soft_body_world_info() { return soft_body_world_info; } + _FORCE_INLINE_ btBroadphaseInterface *get_broadphase() const { return broadphase; } + _FORCE_INLINE_ btDefaultCollisionConfiguration *get_collision_configuration() const { return collisionConfiguration; } + _FORCE_INLINE_ btCollisionDispatcher *get_dispatcher() const { return dispatcher; } + _FORCE_INLINE_ btConstraintSolver *get_solver() const { return solver; } + _FORCE_INLINE_ btDiscreteDynamicsWorld *get_dynamic_world() const { return dynamicsWorld; } + _FORCE_INLINE_ btSoftBodyWorldInfo *get_soft_body_world_info() const { return soft_body_world_info; } _FORCE_INLINE_ bool is_using_soft_world() { return soft_body_world_info; } /// Used to set some parameters to Bullet world /// @param p_param: /// AREA_PARAM_GRAVITY to set the gravity magnitude of entire world /// AREA_PARAM_GRAVITY_VECTOR to set the gravity direction of entire world - void set_param(PhysicsServer::AreaParameter p_param, const Variant &p_value); + void set_param(PhysicsServer3D::AreaParameter p_param, const Variant &p_value); /// Used to get some parameters to Bullet world /// @param p_param: /// AREA_PARAM_GRAVITY to get the gravity magnitude of entire world /// AREA_PARAM_GRAVITY_VECTOR to get the gravity direction of entire world - Variant get_param(PhysicsServer::AreaParameter p_param); + Variant get_param(PhysicsServer3D::AreaParameter p_param); - void set_param(PhysicsServer::SpaceParameter p_param, real_t p_value); - real_t get_param(PhysicsServer::SpaceParameter p_param); + void set_param(PhysicsServer3D::SpaceParameter p_param, real_t p_value); + real_t get_param(PhysicsServer3D::SpaceParameter p_param); void add_area(AreaBullet *p_area); void remove_area(AreaBullet *p_area); void reload_collision_filters(AreaBullet *p_area); + void register_collision_object(CollisionObjectBullet *p_object); + void unregister_collision_object(CollisionObjectBullet *p_object); + void add_rigid_body(RigidBodyBullet *p_body); void remove_rigid_body(RigidBodyBullet *p_body); void reload_collision_filters(RigidBodyBullet *p_body); @@ -167,7 +182,9 @@ public: contactDebugCount = 0; } _FORCE_INLINE_ void add_debug_contact(const Vector3 &p_contact) { - if (contactDebugCount < contactDebug.size()) contactDebug.write[contactDebugCount++] = p_contact; + if (contactDebugCount < contactDebug.size()) { + contactDebug[contactDebugCount++] = p_contact; + } } _FORCE_INLINE_ Vector<Vector3> get_debug_contacts() { return contactDebug; } _FORCE_INLINE_ int get_debug_contact_count() { return contactDebugCount; } @@ -177,8 +194,11 @@ public: void update_gravity(); - bool test_body_motion(RigidBodyBullet *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer::MotionResult *r_result, bool p_exclude_raycast_shapes); - int test_ray_separation(RigidBodyBullet *p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, PhysicsServer::SeparationResult *r_results, int p_result_max, float p_margin); + real_t get_linear_damp() const { return linear_damp; } + real_t get_angular_damp() const { return angular_damp; } + + bool test_body_motion(RigidBodyBullet *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult *r_result, bool p_exclude_raycast_shapes); + int test_ray_separation(RigidBodyBullet *p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, PhysicsServer3D::SeparationResult *r_results, int p_result_max, float p_margin); private: void create_empty_world(bool p_create_soft_world); @@ -187,33 +207,26 @@ private: void check_body_collision(); struct RecoverResult { - bool hasPenetration; - btVector3 normal; - btVector3 pointWorld; - btScalar penetration_distance; // Negative mean penetration - int other_compound_shape_index; - const btCollisionObject *other_collision_object; - int local_shape_most_recovered; - - RecoverResult() : - hasPenetration(false), - normal(0, 0, 0), - pointWorld(0, 0, 0), - penetration_distance(1e20), - other_compound_shape_index(0), - other_collision_object(NULL), - local_shape_most_recovered(0) {} + bool hasPenetration = false; + btVector3 normal = btVector3(0, 0, 0); + btVector3 pointWorld = btVector3(0, 0, 0); + btScalar penetration_distance = 1e20; // Negative mean penetration + int other_compound_shape_index = 0; + const btCollisionObject *other_collision_object = nullptr; + int local_shape_most_recovered = 0; + + RecoverResult() {} }; - bool recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, bool p_infinite_inertia, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result = NULL); + bool recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, bool p_infinite_inertia, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result = nullptr); /// This is an API that recover a kinematic object from penetration /// This allow only Convex Convex test and it always use GJK algorithm, With this API we don't benefit of Bullet special accelerated functions - bool RFP_convex_convex_test(const btConvexShape *p_shapeA, const btConvexShape *p_shapeB, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_recover_movement_scale, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result = NULL); + bool RFP_convex_convex_test(const btConvexShape *p_shapeA, const btConvexShape *p_shapeB, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_recover_movement_scale, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result = nullptr); /// This is an API that recover a kinematic object from penetration /// Using this we leave Bullet to select the best algorithm, For example GJK in case we have Convex Convex, or a Bullet accelerated algorithm - bool RFP_convex_world_test(const btConvexShape *p_shapeA, const btCollisionShape *p_shapeB, btCollisionObject *p_objectA, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_recover_movement_scale, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result = NULL); + bool RFP_convex_world_test(const btConvexShape *p_shapeA, const btCollisionShape *p_shapeB, btCollisionObject *p_objectA, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_recover_movement_scale, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result = nullptr); - int add_separation_result(PhysicsServer::SeparationResult *r_results, const SpaceBullet::RecoverResult &p_recover_result, int p_shape_id, const btCollisionObject *p_other_object) const; - int recover_from_penetration_ray(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, bool p_infinite_inertia, int p_result_max, btVector3 &r_delta_recover_movement, PhysicsServer::SeparationResult *r_results); + int add_separation_result(PhysicsServer3D::SeparationResult *r_results, const SpaceBullet::RecoverResult &p_recover_result, int p_shape_id, const btCollisionObject *p_other_object) const; + int recover_from_penetration_ray(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, bool p_infinite_inertia, int p_result_max, btVector3 &r_delta_recover_movement, PhysicsServer3D::SeparationResult *r_results); }; #endif |