Skip to content

Commit

Permalink
--add access to com correction vector; cleanup outdated comments (#2333)
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner65 authored Mar 5, 2024
1 parent 498cae1 commit ad6903c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/esp/bindings/PhysicsObjectBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ void declareRigidBaseWrapper(py::module& m,
". To change the values, use the object's "
"'intertia_diagonal' property.")
.c_str())
.def_property_readonly(
"com_correction", &RigidBaseWrapper::getCOMCorrection,
("Get the COM correction vector for this " + objType +
". This tracks the local change in translation from the original "
"frame to center the COM locally.")
.c_str())
.def_property("linear_damping", &RigidBaseWrapper::getLinearDamping,
&RigidBaseWrapper::setLinearDamping,
("Get or set this " + objType +
Expand Down
5 changes: 3 additions & 2 deletions src/esp/physics/PhysicsObjectBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,16 @@ class PhysicsObjectBase : public Magnum::SceneGraph::AbstractFeature3D {

/**
* @brief Reverses the COM correction transformation for objects that require
* it. Currently a simple passthrough for stages and Articulated Objects.
* it. Currently a simple passthrough for stages and articulated objects.
*/
virtual Magnum::Vector3 getUncorrectedTranslation() const {
return getTranslation();
}

/** @brief Accessed internally. Get an appropriately cast copy of the @ref
* metadata::attributes::SceneObjectInstanceAttributes used to place the
* object within the scene, updated to have the c.
* object within the scene, updated to have the current transformation and
* status of the object.
* @return A copy of the initialization template used to create this object
* instance or nullptr if no template exists.
*/
Expand Down
35 changes: 22 additions & 13 deletions src/esp/physics/RigidObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

/** @file
* @brief Class @ref esp::physics::RigidObject, enum @ref
* esp::physics::MotionType, enum @ref esp::physics::RigidObjectType, struct
* @ref VelocityControl
* esp::physics::MotionType, struct @ref esp::physics::VelocityControl
*/

#include <Corrade/Containers/Optional.h>
Expand Down Expand Up @@ -162,27 +161,37 @@ class RigidObject : public RigidBase {

/**
* @brief Reverses the COM correction transformation for objects that require
* it. Currently a simple passthrough for stages and Articulated Objects.
* it.
*/
Magnum::Vector3 getUncorrectedTranslation() const override {
auto translation = getTranslation();
auto rotation = getRotation();
if (isCOMCorrected_) {
auto rotation = getRotation();
translation += rotation.transformVector(visualNode_->translation());
}
return translation;
}

/**
* @brief Set the @ref MotionType of the object. If the object is @ref
* ObjectType::SCENE it can only be @ref esp::physics::MotionType::STATIC. If
* the object is
* @ref ObjectType::OBJECT is can also be set to @ref
* esp::physics::MotionType::KINEMATIC. Only if a dervied @ref PhysicsManager
* implementing dynamics is in use can the object be set to @ref
* esp::physics::MotionType::DYNAMIC.
* @param mt The desirved @ref MotionType.
* @return true if successfully set, false otherwise.
* @brief Retrieves the COM correction translation for objects that require
* it.
*/
Magnum::Vector3 getCOMCorrection() const {
if (isCOMCorrected_) {
return visualNode_->translation();
}
return Magnum::Vector3();
} // getCOMCorrection

/**
* @brief Set the @ref MotionType of the object. If the construct is a @ref
* physics::RigidStage, it can only be @ref
* physics::MotionType::STATIC. If the object is
* @ref physics::RigidObject it can also be set to @ref
* physics::MotionType::KINEMATIC. Only if a dervied @ref
* physics::PhysicsManager implementing dynamics is in use can the object
* be set to @ref physics::MotionType::DYNAMIC.
* @param mt The desired @ref MotionType.
*/
void setMotionType(MotionType mt) override;

Expand Down
5 changes: 2 additions & 3 deletions src/esp/physics/bullet/BulletRigidObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ namespace physics {

/**
* @brief An individual rigid object instance implementing an interface with
* Bullet physics to enable dynamic objects. See @ref btRigidBody for @ref
* esp::physics::RigidObjectType::OBJECT.
* Bullet physics to enable dynamic objects. See @ref btRigidBody.
*
* Utilizes Magnum::BulletIntegration::MotionState to synchronize SceneNode
* state with internal btRigidBody states
Expand Down Expand Up @@ -482,7 +481,7 @@ class BulletRigidObject : public BulletBase,
*/
Magnum::Range3D getCollisionShapeAabb() const override;

/** @brief Object data: All components of a @ref esp::physics::RigidObjectType::OBJECT are
/** @brief Object data: All @ref BulletRigidObject components are
* wrapped into one @ref btRigidBody.
*/
std::unique_ptr<btRigidBody> bObjectRigidBody_;
Expand Down
7 changes: 7 additions & 0 deletions src/esp/physics/objectWrappers/ManagedRigidBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class AbstractManagedRigidBase
}
} // setCOM

Magnum::Vector3 getCOMCorrection() const {
if (auto sp = this->getObjectReference()) {
return sp->getCOMCorrection();
}
return Magnum::Vector3();
} // getCOMCorrection

double getFrictionCoefficient() const {
if (auto sp = this->getObjectReference()) {
return sp->getFrictionCoefficient();
Expand Down

0 comments on commit ad6903c

Please sign in to comment.