Page 1 of 1

Rotation, the very basics

Posted: Wed Jun 08, 2005 9:44 pm
by The Lord
Hi forum,

I've got some problems with getting quaternion-based rotation right.
What I want to do is, write a simple method like

void myObject::roll(float angle);

What it shall do is, rotate the object about its z-Axis in OBJECTSPACE.
So, if my object is currently looking at 2/1/0, this method shall rotate
it around an axis pointing to 2/1/0.

myObject-class objects have their current orientation stored in a quaternion, so actually this orientation has to be rotated.

I'm sure what I want is pretty easy, so any short hint is welcome.

cu,
The Lord

Posted: Wed Jun 08, 2005 9:50 pm
by joi
this is help

Posted: Wed Jun 08, 2005 10:19 pm
by AssiDragon
I think you want something like this:

Code: Select all

Quaternion q;
q.fromAngleAxis(how_much_to_rotate, axis_around_to_rotate);
myObjectsNode->setOrientation(myObjectsNode->getOrientation() * q);
It's from the top of my head, but it should be like that actually.

Posted: Wed Jun 15, 2005 6:14 pm
by tonyhnz
Assidragon -That looks good - I have used similar code that seems to work OK.

I would add a couple of things ..

Axis around to rotate would be Ogre::Vector3::UNIT_Z in your case.
The "how_much_to_rotate" has to be in radians. If you have it in degrees you can use Ogre::Angle(degrees) to convert it.

Posted: Thu Jun 16, 2005 10:31 am
by SuprChikn
What's wrong with just calling the roll function for nodes:

Code: Select all

myObject::roll(float degrees) { mSceneNode->roll(Radian(degrees)); }
where mSceneNode is a pointer to the scene node of your object, and degrees is a float representing the number of degrees you want to rotate about the z axis? The roll function defaults to using local space z-axis for the rotation, not world z-axis.
If you need to store the quaternion orientation for some reason, after applying the roll, update it using:

Code: Select all

mOrientation = mSceneNode->getOrientation();
Alternatively, instead of storing it, every time you need it for something else, just return it with a get function like this:

Code: Select all

myObject::getOrientation() { return mSceneNode->getOrientation(); }