The quickest way to learn how to rotate an object with quaternion within ogre3d

If you want to undestand the math behind rotating with quaternions you should google another site, I will guide you just in a practice way.
Well, let's start asking something really important: - how do you define how much are we going to rotate an object?
You might have answered:
- I want to rotate 45 degree through the y-axis
(or something like that)
Now I shall answer to you:
- well, so why don't you create a quaternion with this data?

         Quaternion quat = Quaternion(Degree(45),Vector3::UNIT_Y);
You just have to choose the angle and the axis that it will rotate around. - wow, simple like that? - yeah xD. Now you just have to choose if you're going to rotate 45 degree from the identity quaternion, or if you're going to rotate from the orientation that you have now. Let me explain it better. If you're going to rotate 45 degree from identity, and you have already rotated 45 degree, nothing will happen, however, if you choose to rotate from the orientation that you have now, your new orientation will be 90 degree from the identity quaternion. cool, eh? so, if you choose to rotate from the identity, you have actually to set a new orientation:
      	 yourSceneNode->setOrientation(quat);
and if you're going for the other option:
      	 yourSceneNode->rotate(quat);
Well, just to finish, if you want to rotate around 2 axis, you just have to use the * operator of the quaternion class:
         Quaternion quat = Quaternion(Degree(45),Vector3::UNIT_Y);
         Quaternion quat2 = Quaternion(Degree(45),Vector3::UNIT_Z);
	 quat = quat * quat2;
		
	 yourSceneNode->rotate(quat);
now we're going to rotate 45 degree around y-axis, and 45 degree around z-axis. enjoy it.

Comments

What will happened if i am going to rotate 45 degree from the identity quaternion.
Hair updos for weddings

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.