Skip to content

Commit

Permalink
Documented that you should prefer BodyInterface over Body when manipu…
Browse files Browse the repository at this point in the history
…lating velocity

See discussion #191
  • Loading branch information
jrouwe committed Sep 15, 2024
1 parent f95ad21 commit b0980e5
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions Jolt/Physics/Body/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,23 @@ class alignas(JPH_RVECTOR_ALIGNMENT) JPH_EXPORT_GCC_BUG_WORKAROUND Body : public
/// Get world space linear velocity of the center of mass (unit: m/s)
inline Vec3 GetLinearVelocity() const { return !IsStatic()? mMotionProperties->GetLinearVelocity() : Vec3::sZero(); }

/// Set world space linear velocity of the center of mass (unit: m/s)
/// Set world space linear velocity of the center of mass (unit: m/s).
/// If you want the body to wake up when it is sleeping, use BodyInterface::SetLinearVelocity instead.
void SetLinearVelocity(Vec3Arg inLinearVelocity) { JPH_ASSERT(!IsStatic()); mMotionProperties->SetLinearVelocity(inLinearVelocity); }

/// Set world space linear velocity of the center of mass, will make sure the value is clamped against the maximum linear velocity
/// Set world space linear velocity of the center of mass, will make sure the value is clamped against the maximum linear velocity.
/// If you want the body to wake up when it is sleeping, use BodyInterface::SetLinearVelocity instead.
void SetLinearVelocityClamped(Vec3Arg inLinearVelocity) { JPH_ASSERT(!IsStatic()); mMotionProperties->SetLinearVelocityClamped(inLinearVelocity); }

/// Get world space angular velocity of the center of mass (unit: rad/s)
inline Vec3 GetAngularVelocity() const { return !IsStatic()? mMotionProperties->GetAngularVelocity() : Vec3::sZero(); }

/// Set world space angular velocity of the center of mass (unit: rad/s)
/// Set world space angular velocity of the center of mass (unit: rad/s).
/// If you want the body to wake up when it is sleeping, use BodyInterface::SetAngularVelocity instead.
void SetAngularVelocity(Vec3Arg inAngularVelocity) { JPH_ASSERT(!IsStatic()); mMotionProperties->SetAngularVelocity(inAngularVelocity); }

/// Set world space angular velocity of the center of mass, will make sure the value is clamped against the maximum angular velocity
/// Set world space angular velocity of the center of mass, will make sure the value is clamped against the maximum angular velocity.
/// If you want the body to wake up when it is sleeping, use BodyInterface::SetAngularVelocity instead.
void SetAngularVelocityClamped(Vec3Arg inAngularVelocity) { JPH_ASSERT(!IsStatic()); mMotionProperties->SetAngularVelocityClamped(inAngularVelocity); }

/// Velocity of point inPoint (in center of mass space, e.g. on the surface of the body) of the body (unit: m/s)
Expand All @@ -164,13 +168,16 @@ class alignas(JPH_RVECTOR_ALIGNMENT) JPH_EXPORT_GCC_BUG_WORKAROUND Body : public
/// Velocity of point inPoint (in world space, e.g. on the surface of the body) of the body (unit: m/s)
inline Vec3 GetPointVelocity(RVec3Arg inPoint) const { JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess, BodyAccess::EAccess::Read)); return GetPointVelocityCOM(Vec3(inPoint - mPosition)); }

/// Add force (unit: N) at center of mass for the next time step, will be reset after the next call to PhysicsSystem::Update
/// Add force (unit: N) at center of mass for the next time step, will be reset after the next call to PhysicsSystem::Update.
/// If you want the body to wake up when it is sleeping, use BodyInterface::AddForce instead.
inline void AddForce(Vec3Arg inForce) { JPH_ASSERT(IsDynamic()); (Vec3::sLoadFloat3Unsafe(mMotionProperties->mForce) + inForce).StoreFloat3(&mMotionProperties->mForce); }

/// Add force (unit: N) at inPosition for the next time step, will be reset after the next call to PhysicsSystem::Update
/// Add force (unit: N) at inPosition for the next time step, will be reset after the next call to PhysicsSystem::Update.
/// If you want the body to wake up when it is sleeping, use BodyInterface::AddForce instead.
inline void AddForce(Vec3Arg inForce, RVec3Arg inPosition);

/// Add torque (unit: N m) for the next time step, will be reset after the next call to PhysicsSystem::Update
/// Add torque (unit: N m) for the next time step, will be reset after the next call to PhysicsSystem::Update.
/// If you want the body to wake up when it is sleeping, use BodyInterface::AddTorque instead.
inline void AddTorque(Vec3Arg inTorque) { JPH_ASSERT(IsDynamic()); (Vec3::sLoadFloat3Unsafe(mMotionProperties->mTorque) + inTorque).StoreFloat3(&mMotionProperties->mTorque); }

// Get the total amount of force applied to the center of mass this time step (through AddForce calls). Note that it will reset to zero after PhysicsSystem::Update.
Expand All @@ -191,19 +198,24 @@ class alignas(JPH_RVECTOR_ALIGNMENT) JPH_EXPORT_GCC_BUG_WORKAROUND Body : public
/// Get inverse inertia tensor in world space
inline Mat44 GetInverseInertia() const;

/// Add impulse to center of mass (unit: kg m/s)
/// Add impulse to center of mass (unit: kg m/s).
/// If you want the body to wake up when it is sleeping, use BodyInterface::AddImpulse instead.
inline void AddImpulse(Vec3Arg inImpulse);

/// Add impulse to point in world space (unit: kg m/s)
/// Add impulse to point in world space (unit: kg m/s).
/// If you want the body to wake up when it is sleeping, use BodyInterface::AddImpulse instead.
inline void AddImpulse(Vec3Arg inImpulse, RVec3Arg inPosition);

/// Add angular impulse in world space (unit: N m s)
/// Add angular impulse in world space (unit: N m s).
/// If you want the body to wake up when it is sleeping, use BodyInterface::AddAngularImpulse instead.
inline void AddAngularImpulse(Vec3Arg inAngularImpulse);

/// Set velocity of body such that it will be positioned at inTargetPosition/Rotation in inDeltaTime seconds.
/// If you want the body to wake up when it is sleeping, use BodyInterface::MoveKinematic instead.
void MoveKinematic(RVec3Arg inTargetPosition, QuatArg inTargetRotation, float inDeltaTime);

/// Applies an impulse to the body that simulates fluid buoyancy and drag
/// Applies an impulse to the body that simulates fluid buoyancy and drag.
/// If you want the body to wake up when it is sleeping, use BodyInterface::ApplyBuoyancyImpulse instead.
/// @param inSurfacePosition Position of the fluid surface in world space
/// @param inSurfaceNormal Normal of the fluid surface (should point up)
/// @param inBuoyancy The buoyancy factor for the body. 1 = neutral body, < 1 sinks, > 1 floats. Note that we don't use the fluid density since it is harder to configure than a simple number between [0, 2]
Expand Down Expand Up @@ -283,7 +295,7 @@ class alignas(JPH_RVECTOR_ALIGNMENT) JPH_EXPORT_GCC_BUG_WORKAROUND Body : public
inline void AddPositionStep(Vec3Arg inLinearVelocityTimesDeltaTime) { JPH_ASSERT(IsRigidBody()); JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess, BodyAccess::EAccess::ReadWrite)); mPosition += mMotionProperties->LockTranslation(inLinearVelocityTimesDeltaTime); JPH_ASSERT(!mPosition.IsNaN()); }
inline void SubPositionStep(Vec3Arg inLinearVelocityTimesDeltaTime) { JPH_ASSERT(IsRigidBody()); JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess, BodyAccess::EAccess::ReadWrite)); mPosition -= mMotionProperties->LockTranslation(inLinearVelocityTimesDeltaTime); JPH_ASSERT(!mPosition.IsNaN()); }

/// Update rotation using an Euler step (using during position integrate & constraint solving)
/// Update rotation using an Euler step (used during position integrate & constraint solving)
inline void AddRotationStep(Vec3Arg inAngularVelocityTimesDeltaTime);
inline void SubRotationStep(Vec3Arg inAngularVelocityTimesDeltaTime);

Expand Down

0 comments on commit b0980e5

Please sign in to comment.