Code: Select all
btQuaternion q;
EulerXYZToQuaternion(node->getRotation(), q); //I got this function in other's Bullet wrapper
q.normalize();
btTransform transform;
transform.setIdentity();
core::vector3df pos = node->getPosition();
transform.setOrigin(btVector3(pos.X, pos.Y, pos.Z));
transform.setRotation(q); //I'm wondering about this, did I set it right?
rigidbody->setWorldTransform(transform);
Code: Select all
SIMD_FORCE_INLINE void EulerXYZToQuaternion(const irr::core::vector3df& euler, btQuaternion &quat)
{
btScalar _heading=euler.Z*0.5;
btScalar _attitude=euler.Y*0.5;
btScalar _bank=euler.X*0.5;
btScalar c1 = cos(_heading);
btScalar s1 = sin(_heading);
btScalar c2 = cos(_attitude);
btScalar s2 = sin(_attitude);
btScalar c3 = cos(_bank);
btScalar s3 = sin(_bank);
double c1c2 = c1*c2;
double s1s2 = s1*s2;
//w
quat.setW((btScalar) (c1c2*c3 + s1s2*s3));
//x
quat.setX((btScalar) (c1c2*s3 - s1s2*c3));
//y
quat.setY((btScalar) (c1*s2*c3 + s1*c2*s3));
//z
quat.setZ((btScalar) (s1*c2*c3 - c1*s2*s3));
}