Skip to content

Commit

Permalink
PhysicsRigidBody: add totalAppliedForce() and totalAppliedTorque()
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jun 23, 2024
1 parent 4da1691 commit df1cc0d
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,44 @@ public void setPhysicsRotationDp(Quatd orientation) {
Quaternion quaternion = orientation.toQuaternion();
reposition(location, quaternion);
}

/**
* Return the total force applied to the body.
*
* @param storeResult storage for the result (modified if not null)
* @return the total force (either storeResult or a new vector, mass times
* physics-space units per second squared in physics-space coordinates)
*/
public Vector3f totalAppliedForce(Vector3f storeResult) {
Vector3f result = (storeResult == null) ? new Vector3f() : storeResult;

MemorySession arena = PhysicsSpace.getArena();
FVec3 fvec3 = FVec3.of(arena);
joltBody.getAccumulatedForce(fvec3);
result.set(fvec3.getX(), fvec3.getY(), fvec3.getZ());

return result;
}

/**
* Return the total torque applied to the body (excluding contact forces and
* damping).
*
* @param storeResult storage for the result (modified if not null)
* @return the total torque (either storeResult or a new vector, mass times
* physics-space units squared per second squared in physics-space
* coordinates)
*/
public Vector3f totalAppliedTorque(Vector3f storeResult) {
Vector3f result = (storeResult == null) ? new Vector3f() : storeResult;

MemorySession arena = PhysicsSpace.getArena();
FVec3 fvec3 = FVec3.of(arena);
joltBody.getAccumulatedTorque(fvec3);
result.set(fvec3.getX(), fvec3.getY(), fvec3.getZ());

return result;
}
// *************************************************************************
// PhysicsBody methods

Expand Down

0 comments on commit df1cc0d

Please sign in to comment.