I'm puzzling a bit with True Axis Physics integration by creating a scenenode animator. Problem is dat when adding a bunch of cubes to the scene their rotation looks distorted. Some rotate only over one angle and through the ground. Could this have anything to do with Gimbal Lock? Is there a way to overcome this with True Axis?
Code: Select all
// Add some cubes with some randiness...
for (int i=0; i<30;i++) {
irr::f32 r=float(rand()%20);
ISceneNode *cube = smgr->addCubeSceneNode(1+r,0,-1,irr::core::vector3df(300.0f+r,150.0f+(i*10),280.0f+r));
CSceneNodeAnimatorTA *tok = new CSceneNodeAnimatorTA(cube, r);
cube->addAnimator(tok);
tok->drop();
}Code: Select all
#include "SceneNodeAnimatorTA.h"
#define WORLD_SCALE 1.0f;
#define PI 3.1415926f
#define DEG2RAD(a) ((a)*PI/180)
#define RAD2DEG(a) ((a)*180/PI)
CSceneNodeAnimatorTA::CSceneNodeAnimatorTA(irr::scene::ISceneNode *node, irr::f32 mass, irr::s32 collissionID) {
TA::Physics& physics = TA::Physics::GetInstance();
irr::core::aabbox3df box = node->getBoundingBox();
irr::core::vector3df extent = box.getExtent()/2; // don't no why this is needed
irr::core::vector3df center = box.getCenter();
m_pDynamicObject = TA::DynamicObject::CreateNew();
TA::AABB aabb(convertIrrlichtPos(center),convertIrrlichtPos(extent));
m_pDynamicObject->InitialiseAsABox(aabb);
m_pDynamicObject->SetMass(mass);
irr::core::vector3df pos = node->getPosition();
irr::core::vector3df rot = node->getRotation();
TA::MFrame frame(convertIrrlichtPos(pos),convertIrrlichtRot(rot));
m_pDynamicObject->SetFrame(frame);
physics.AddDynamicObject(m_pDynamicObject);
m_pDynamicObject->Release();
}
void CSceneNodeAnimatorTA::animateNode(irr::scene::ISceneNode *node, irr::u32 timeMs) {
const TA::MFrame &frame = m_pDynamicObject->GetFrame();
node->setPosition(convertTAPos(frame.v3Translation));
node->setRotation(convertTARot(frame.m33Rotation));
}
TA::Vec3 CSceneNodeAnimatorTA::convertIrrlichtPos(irr::core::vector3df &pos) {
TA::Vec3 tokpos(pos.X,pos.Y,pos.Z);
return tokpos * WORLD_SCALE;
}
irr::core::vector3df CSceneNodeAnimatorTA::convertTAPos(const TA::Vec3 &p) {
return irr::core::vector3df(p.x,p.y,p.z) / WORLD_SCALE;
}
TA::Mat33 CSceneNodeAnimatorTA::convertIrrlichtRot(irr::core::vector3df &r) {
TA::EulerAngles tarot(DEG2RAD(r.X),DEG2RAD(r.Y),DEG2RAD(r.Z));
return TA::Mat33(tarot);
}
irr::core::vector3df CSceneNodeAnimatorTA::convertTARot(const TA::Mat33 &r) {
TA::EulerAngles rot((TA::Mat33&)r);
return RAD2DEG(irr::core::vector3df(rot.x,rot.y,rot.z));
}