Bullet physics, quaternion rotations.

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Bullet physics, quaternion rotations.

Post by serengeor »

I don't really understand how they work, I found some articles about them, but they were a bit tricky to understand.

What I want to know is how would I set quaternions rotation to lets say 30 degrees on x axis and 50 degrees on y axis?

I hope that there are more alive people here in irrlicht than there are in bullet's forums :roll:

PS. please avoid posting solutions that include conversions from bullet's quaternion class to irrlicht's types.
Working on game: Marrbles (Currently stopped).
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

The hard visualization would be that a rotation quaternion is a point on a unit-hypersphere :D

The easy visualization is to look at a quaternion as a unit vector in 3-dimensions with a given rotation around that vector, irrlicht provides an easy way to construct quaternions like this by using quaternion::fromAngleAxis(...), so if you can convert irrlicht quaternions to bullet quaternions I assume this method would be the easiest way to define and view quaternions in general
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Ok, so what I tried right now is:

Code: Select all

rotateRidigBody(const btScalar & angle, const btVector3 & axis, CRigidBody * body)
{
    btTransform trans=body->getCenterOfMassTransform();

    btQuaternion quat,quat2;

    quat=trans.getRotation();

    irr::core::quaternion q;
    q.fromAngleAxis(angle,utils::BtToIrrVec(axis));


    quat2.setW(q.W);
    quat2.setX(q.X);
    quat2.setY(q.Y);
    quat2.setZ(q.Z);

    quat+=quat2;

    trans.setRotation(quat);
    body->setCenterOfMassTransform(trans);
}
doesn't seam to work, maybe the addition part is whats causing problems?
if so, how can I increase my body's current rotation?

EDIT: Nevermind fixed it with a bit of google :D

here's the code if anyones interested:

Code: Select all

void rotateRidigBody(const btScalar & angle, const btVector3 & axis, CRigidBody * body)
{
    btTransform trans;
    trans=body->getWorldTransform();

    btQuaternion quat,quat2;

    quat2.setW(cos(angle*irr::core::DEGTORAD/2));
    quat2.setX(axis.getX()*sin(angle*irr::core::DEGTORAD/2));
    quat2.setY(axis.getY()*sin(angle*irr::core::DEGTORAD/2));
    quat2.setZ(axis.getZ()*sin(angle*irr::core::DEGTORAD/2));

    trans.setRotation(quat2*quat);
    body->setWorldTransform(trans);
}
Working on game: Marrbles (Currently stopped).
Post Reply