added getRotation

This commit is contained in:
Otto Naderer 2022-06-05 14:08:07 +02:00
parent 298f013819
commit 44650eed0c
2 changed files with 36 additions and 21 deletions

View File

@ -1,21 +1,21 @@
/* /*
irrDynamics - Light-weight Bullet Physics wrapper for the irrlicht graphics engine irrDynamics - Light-weight Bullet Physics wrapper for the irrlicht graphics engine
Copyright (C) 2014 Otto Naderer - otto.naderer@aec.at Copyright (C) 2014 Otto Naderer - otto.naderer@aec.at
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated but is not required. appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
@ -110,7 +110,8 @@ class irrDynamics
static void applyTorque(irr::scene::ISceneNode* node, const irr::core::vector3df& 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 setDamping(irr::scene::ISceneNode* node, irr::f32 linearDamping, irr::f32 angularDamping);
static void setPosition(irr::scene::ISceneNode* node, const irr::core::vector3df& newPos); static void setPosition(irr::scene::ISceneNode* node, const irr::core::vector3df& newPos);
static void setRotation(irr::scene::ISceneNode* node, const irr::core::vector3df& newRotation); static void setRotation(irr::scene::ISceneNode* node, const irr::core::quaternion& newRotation);
static bool getRotation(irr::scene::ISceneNode* node, irr::core::quaternion&);
//! Change default gravity //! Change default gravity
/** Per default, irrDynamics is set to an earth-like gravitational force. Modify that for other planets /** Per default, irrDynamics is set to an earth-like gravitational force. Modify that for other planets
* or your space sim game. * or your space sim game.

View File

@ -456,7 +456,7 @@ void irrDynamics::setPosition(scene::ISceneNode* node, const core::vector3df& ne
iter->second->setWorldTransform(transform); iter->second->setWorldTransform(transform);
} }
void irrDynamics::setRotation(scene::ISceneNode* node, const core::vector3df& newRotation) void irrDynamics::setRotation(scene::ISceneNode* node, const core::quaternion& r)
{ {
irrDynamics* inst = getInstance(); irrDynamics* inst = getInstance();
//find the corresponding rigid body: //find the corresponding rigid body:
@ -466,15 +466,29 @@ void irrDynamics::setRotation(scene::ISceneNode* node, const core::vector3df& ne
cout << "irrdynamics: Unable to find node in list. Rotation update aborted." << endl; cout << "irrdynamics: Unable to find node in list. Rotation update aborted." << endl;
return; return;
} }
btTransform transform; // = iter->second->getWorldTransform(); auto transform= iter->second->getWorldTransform();
transform.setIdentity();
btQuaternion quat; btQuaternion quat;
quat.setEuler(core::degToRad(newRotation.Y), core::degToRad(newRotation.X), core::degToRad(newRotation.Z)); quat.setValue(r.X, r.Y, r.Z, r.W);
transform.setRotation(quat); transform.setRotation(quat);
transform.setOrigin(iter->second->getCenterOfMassPosition()); transform.setOrigin(iter->second->getCenterOfMassPosition());
iter->second->setCenterOfMassTransform(transform); iter->second->setCenterOfMassTransform(transform);
} }
bool irrDynamics::getRotation(irr::scene::ISceneNode *node, core::quaternion& rotationOut)
{
irrDynamics* inst = getInstance();
//find the corresponding rigid body:
auto iter = inst->objects.find(node);
if (iter == inst->objects.end())
{
cout << "irrdynamics: Unable to find node in list. getrotation aborted." << endl;
return false;
}
auto rot = iter->second->getWorldTransform().getRotation();
rotationOut.set(rot.x(), rot.y(), rot.z(), rot.w());
return true;
}
void irrDynamics::removeConstraints(btRigidBody* rigidBody) void irrDynamics::removeConstraints(btRigidBody* rigidBody)
{ {
const int len = rigidBody->getNumConstraintRefs(); const int len = rigidBody->getNumConstraintRefs();