diff --git a/include/irrDynamics.h b/include/irrDynamics.h index d56d026..2abe03a 100644 --- a/include/irrDynamics.h +++ b/include/irrDynamics.h @@ -96,9 +96,18 @@ class irrDynamics * Use this method to apply such a push represented as a 3D vector. As expected, the 'longer' the vector, * the more powerful the push will be. * \param node The scene node the force should be applied to. - * \param force The force to apply, the vector represents its direction, the vector length its power.*/ + * \param force The force to apply, the vector represents its direction, the vector length its power. + * \see setDamping to continuously reduce the effect of applied forces*/ static void applyCentralForce(irr::scene::ISceneNode* node, const irr::core::vector3df& force); static void applyCentralImpulse(irr::scene::ISceneNode* node, const irr::core::vector3df& force); + //! Applies a rotational force to the object + /** Similarly to force/impule application to move an object, use this method to rotate an object. + * Set one or more axis values in the provided vector to rotate around the respective axis. As usual + * the higher the value in an axis, the more powerful the torque. + * \param node The scene node the torque should be applied to. + * \param torque The torque to apply, the vector represents the axis to rotate around, the axis value its power. + * \see setDamping to continuously reduce the effect of applied torque*/ + static void applyTorque(irr::scene::ISceneNode* node, const irr::core::vector3df& torque); static void setDamping(irr::scene::ISceneNode* node, irr::f32 linearDamping, irr::f32 angularDamping); static void setPosition(irr::scene::ISceneNode* node, const irr::core::vector3df& newPos); //! Change default gravity diff --git a/src/irrDynamics.cpp b/src/irrDynamics.cpp index 26817af..74f2db9 100644 --- a/src/irrDynamics.cpp +++ b/src/irrDynamics.cpp @@ -379,6 +379,22 @@ void irrDynamics::applyCentralImpulse(scene::ISceneNode* node, const core::vecto iter->second->activate(); } +void irrDynamics::applyTorque(scene::ISceneNode* node, const core::vector3df& torque) +{ + irrDynamics* inst = getInstance(); + //find the corresponding rigid body: + std::map::iterator iter; + iter = inst->objects.find(node); + if (iter == inst->objects.end()) + { + printf("irrdynamics: Unable to find node in list. Torque application aborted.\n"); + return; + } + + iter->second->applyTorque(btVector3(torque.X, torque.Y, torque.Z)); + iter->second->activate(); +} + btRigidBody* irrDynamics::addFloor(const core::vector3df& normal, const core::vector3df& offset) { irrDynamics* inst = getInstance();