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
Rotation, the very basics
-
- Gnoblar
- Posts: 5
- Joined: Mon May 16, 2005 4:03 pm
- Contact:
-
- Greenskin
- Posts: 145
- Joined: Wed Apr 28, 2004 12:10 pm
- Location: Hungary
- Contact:
I think you want something like this:
It's from the top of my head, but it should be like that actually.
Code: Select all
Quaternion q;
q.fromAngleAxis(how_much_to_rotate, axis_around_to_rotate);
myObjectsNode->setOrientation(myObjectsNode->getOrientation() * q);
Hope is the first step on the road to disappointment.
-
- Greenskin
- Posts: 101
- Joined: Fri Feb 25, 2005 3:54 am
- Location: Florida
- 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:
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:
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::roll(float degrees) { mSceneNode->roll(Radian(degrees)); }
If you need to store the quaternion orientation for some reason, after applying the roll, update it using:
Code: Select all
mOrientation = mSceneNode->getOrientation();
Code: Select all
myObject::getOrientation() { return mSceneNode->getOrientation(); }