From 3830ef2f85d3c4202644397d498d70907de45914 Mon Sep 17 00:00:00 2001 From: enn0x Date: Fri, 31 May 2013 15:13:19 +0000 Subject: [PATCH] Bullet: getTotalForce/Torque exposed --- panda/src/bullet/bulletRigidBodyNode.cxx | 57 +++++++++++++++++++++++- panda/src/bullet/bulletRigidBodyNode.h | 6 +++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/panda/src/bullet/bulletRigidBodyNode.cxx b/panda/src/bullet/bulletRigidBodyNode.cxx index c871dbb1ce..37326b2cc9 100644 --- a/panda/src/bullet/bulletRigidBodyNode.cxx +++ b/panda/src/bullet/bulletRigidBodyNode.cxx @@ -122,11 +122,22 @@ PN_stdfloat BulletRigidBodyNode:: get_mass() const { btScalar inv_mass = _rigid->getInvMass(); - btScalar mass = inv_mass == btScalar(0.0) ? btScalar(0.0) : btScalar(1.0) / inv_mass; + btScalar mass = (inv_mass == btScalar(0.0)) ? btScalar(0.0) : btScalar(1.0) / inv_mass; return mass; } +//////////////////////////////////////////////////////////////////// +// Function: BulletRigidBodyNode::get_inv_mass +// Access: Published +// Description: Returns the inverse mass of a rigid body. +//////////////////////////////////////////////////////////////////// +PN_stdfloat BulletRigidBodyNode:: +get_inv_mass() const { + + return (PN_stdfloat)_rigid->getInvMass(); +} + //////////////////////////////////////////////////////////////////// // Function: BulletRigidBodyNode::set_inertia // Access: Published @@ -177,6 +188,28 @@ get_inertia() const { return inertia; } +//////////////////////////////////////////////////////////////////// +// Function: BulletRigidBodyNode::get_inv_inertia_diag_local +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LVector3 BulletRigidBodyNode:: +get_inv_inertia_diag_local() const { + + return btVector3_to_LVector3(_rigid->getInvInertiaDiagLocal()); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletRigidBodyNode::get_inv_inertia_tensor_world +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LMatrix3 BulletRigidBodyNode:: +get_inv_inertia_tensor_world() const { + + return btMatrix3x3_to_LMatrix3(_rigid->getInvInertiaTensorWorld()); +} + //////////////////////////////////////////////////////////////////// // Function: BulletRigidBodyNode::apply_force // Access: Published @@ -479,6 +512,28 @@ set_angular_factor(const LVector3 &factor) { _rigid->setAngularFactor(LVecBase3_to_btVector3(factor)); } +//////////////////////////////////////////////////////////////////// +// Function: BulletRigidBodyNode::get_total_force +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LVector3 BulletRigidBodyNode:: +get_total_force() const { + + return btVector3_to_LVector3(_rigid->getTotalForce()); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletRigidBodyNode::get_total_torque +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LVector3 BulletRigidBodyNode:: +get_total_torque() const { + + return btVector3_to_LVector3(_rigid->getTotalTorque()); +} + //////////////////////////////////////////////////////////////////// // Function: BulletRigidBodyNode::MotionState::Constructor // Access: Public diff --git a/panda/src/bullet/bulletRigidBodyNode.h b/panda/src/bullet/bulletRigidBodyNode.h index e553bbe3d9..3689c5735f 100644 --- a/panda/src/bullet/bulletRigidBodyNode.h +++ b/panda/src/bullet/bulletRigidBodyNode.h @@ -39,8 +39,11 @@ PUBLISHED: // Mass & inertia void set_mass(PN_stdfloat mass); PN_stdfloat get_mass() const; + PN_stdfloat get_inv_mass() const; void set_inertia(const LVecBase3 &inertia); LVector3 get_inertia() const; + LVector3 get_inv_inertia_diag_local() const; + LMatrix3 get_inv_inertia_tensor_world() const; // Velocity LVector3 get_linear_velocity() const; @@ -63,6 +66,9 @@ PUBLISHED: void apply_torque(const LVector3 &torque); void apply_torque_impulse(const LVector3 &torque); + LVector3 get_total_force() const; + LVector3 get_total_torque() const; + // Deactivation thresholds PN_stdfloat get_linear_sleep_threshold() const; PN_stdfloat get_angular_sleep_threshold() const;