Rotation, the very basics

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
The Lord
Gnoblar
Posts: 5
Joined: Mon May 16, 2005 4:03 pm
Contact:

Rotation, the very basics

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

joi
Gnome
Posts: 327
Joined: Tue Feb 22, 2005 8:11 pm
Location: brazil
this is help
maya 7.0, vs 2005, ogre 1.2

AssiDragon
Greenskin
Posts: 145
Joined: Wed Apr 28, 2004 12:10 pm
Location: Hungary
Contact:
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.
Hope is the first step on the road to disappointment.

tonyhnz
Greenskin
Posts: 101
Joined: Fri Feb 25, 2005 3:54 am
Location: Florida
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.

SuprChikn
Bugbear
Posts: 863
Joined: Tue Apr 19, 2005 6:10 am
Location: Melbourne, Aus
Contact:
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(); }``