Jump to content
  • Advertisement
Sign in to follow this  

rotation with quaterion

This topic is 3175 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I make my quaternion from an axis angle giving it the Y axis it rotate around fine.. but if give it the X axis it rotates kinda on an angle.. its not moving around the x axis.. First: setting up the rotations, angleToAddX/Y is the angle that it should be rotated around calculated from the position of the mouse curser
		Math::Quaternionf rotX;
		Math::Quaternionf rotY;

		rotX.fromAngleAxis(angleToAddX, Math::Vector3f(0.0f,1.0f,0.0f));
		rotY.fromAngleAxis(angleToAddY, Math::Vector3f(1.0f,0.0f,0.0f));


then if I do; listElement.state.orientation = listElement.state.orientation * rotY; it rotates fine around the Y axis.. but if I do; listElement.state.orientation = rotX * listElement.state.orientation; it rotates around some other axis.. looks like its on a 45 degree from x,y,z.. what I realy want is to set the orientation so it rotates around the X axis and the Y axis at the same time using thoese two rotations.. [Edited by - Nanook on November 8, 2009 7:02:23 AM]

Share this post

Link to post
Share on other sites
This is the fromAngleAxis function by the way..

void fromAngleAxis(const qType rfAngle, const Math::Vector3<qType>& rkAxis)
// assert: axis[] is unit length
// The quaternion representing the rotation is
// q = cos(A/2)+sin(A/2)*(x*i+y*j+z*k)

qType fHalfAngle = 0.5*rfAngle;
qType fSin = sin(fHalfAngle);
w = cos(fHalfAngle);
x = fSin*rkAxis.x;
y = fSin*rkAxis.y;
z = fSin*rkAxis.z;

Share this post

Link to post
Share on other sites
I have found the following to work: Store the yaw and pitch separately and increase / decrease them as needed. Then rebuild the quaternion:

transform.resetOrientation(); // calls orientation.setIdentity();
transform.rotate(yaw, 0.0f, 1.0f, 0.0f);
transform.rotate(pitch, 1.0f, 0.0f, 0.0f);

public void rotate(float angle, Vector3f axis) {
Quaternion rot = new Quaternion();


Vector4f a1 = new Vector4f(axis.x, axis.y, axis.z,
angle * Constants.DEG2RAD);

orientation = Quaternion.mul(orientation, rot, null);


Share this post

Link to post
Share on other sites
Original post by Nanook
Hmm.. I dont have Vector4f class.. Aren't you doing the same thing as I am though?

The Vector4f is just storing a 4f vector, it's nothing magical - you already have a function for getting quaternion from axis-angle.

Err forget the whole storing pitch and yaw. I was looking at the camera class. Quaternion multiplication is not commutative though - try post-multiplying rotX instead of premultiplying. Other than that yes I think it's the same. These rotations occur in the local coordinate space of your object though - the axis change once your object rotates. Particularly once you rotate around the y-axis, your object's x-axis is no longer aligned with the world's x-axis. To always rotate in the same manner with respect to the world axis, you'll have to resort to keeping track of pitch and yaw and rebuilding the quaternion.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!