From c8f8b33bd90db834a346ae4a737ee8ad325ff3ca Mon Sep 17 00:00:00 2001 From: GoaLitiuM Date: Sun, 9 May 2021 15:18:04 +0300 Subject: [PATCH] Implement AddForceAtPosition for Rigidbodies --- Source/Engine/Physics/Actors/RigidBody.cpp | 8 ++++++++ Source/Engine/Physics/Actors/RigidBody.h | 24 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Physics/Actors/RigidBody.cpp b/Source/Engine/Physics/Actors/RigidBody.cpp index eecce480a..1f213f8f3 100644 --- a/Source/Engine/Physics/Actors/RigidBody.cpp +++ b/Source/Engine/Physics/Actors/RigidBody.cpp @@ -316,6 +316,14 @@ void RigidBody::AddForce(const Vector3& force, ForceMode mode) const } } +void RigidBody::AddForceAtPosition(const Vector3& force, const Vector3& position, ForceMode mode) const +{ + if (_actor && GetEnableSimulation()) + { + PxRigidBodyExt::addForceAtPos(*_actor, C2P(force), C2P(position), static_cast(mode)); + } +} + void RigidBody::AddRelativeForce(const Vector3& force, ForceMode mode) const { AddForce(Vector3::Transform(force, _transform.Orientation), mode); diff --git a/Source/Engine/Physics/Actors/RigidBody.h b/Source/Engine/Physics/Actors/RigidBody.h index 19e22e506..bfd6348df 100644 --- a/Source/Engine/Physics/Actors/RigidBody.h +++ b/Source/Engine/Physics/Actors/RigidBody.h @@ -428,7 +428,7 @@ public: /// Applies a force (or impulse) defined in the world space to the rigidbody at its center of mass. /// /// - /// This will not induce a torque + /// This will not induce any torque /// /// ForceMode determines if the force is to be conventional or impulsive. /// @@ -443,11 +443,31 @@ public: /// The mode to use when applying the force/impulse. API_FUNCTION() void AddForce(const Vector3& force, ForceMode mode = ForceMode::Force) const; + /// + /// Applies a force (or impulse) defined in the world space to the rigidbody at given position in the world space. + /// + /// + /// Also applies appropriate amount of torque + /// + /// ForceMode determines if the force is to be conventional or impulsive. + /// + /// + /// Each actor has an acceleration and a velocity change accumulator which are directly modified using the modes ForceMode::Acceleration + /// and ForceMode::VelocityChange respectively. The modes ForceMode::Force and ForceMode::Impulse also modify these same + /// accumulators and are just short hand for multiplying the vector parameter by inverse mass and then using ForceMode::Acceleration and + /// ForceMode::VelocityChange respectively. + /// + /// + /// The force/impulse to apply defined in the world space. + /// The position of the force/impulse in the world space. + /// The mode to use when applying the force/impulse. + API_FUNCTION() void AddForceAtPosition(const Vector3& force, const Vector3& position, ForceMode mode = ForceMode::Force) const; + /// /// Applies a force (or impulse) defined in the local space of the rigidbody (relative to its coordinate system) at its center of mass. /// /// - /// This will not induce a torque + /// This will not induce any torque /// /// ForceMode determines if the force is to be conventional or impulsive. ///