So I'm trying to understand how to rotate objects using Euler Angles, which is so confusing and hard to do. I could rotate my object which is a cube using glRotate but now I want to use Quternions. The problem is that I have no idea how to implement that or how to proceed or even how to start.
Knowing that a quaternion's components are [w,x,y,z], my goal is to change these values each time and observe my object'orientation. So I found this example but I didn't understand why he multiplied by 0.5F. Quaternion::Quaternion(float fPitch, float fYaw, float fRoll)
Quaternion::Quaternion(float fPitch, float fYaw, float fRoll)
{
const float fSinPitch(sin(fPitch*0.5F));
const float fCosPitch(cos(fPitch*0.5F));
const float fSinYaw(sin(fYaw*0.5F));
const float fCosYaw(cos(fYaw*0.5F));
const float fSinRoll(sin(fRoll*0.5F));
const float fCosRoll(cos(fRoll*0.5F));
const float fCosPitchCosYaw(fCosPitch*fCosYaw);
const float fSinPitchSinYaw(fSinPitch*fSinYaw);
X = fSinRoll * fCosPitchCosYaw - fCosRoll * fSinPitchSinYaw;
Y = fCosRoll * fSinPitch * fCosYaw fSinRoll * fCosPitch * fSinYaw;
Z = fCosRoll * fCosPitch * fSinYaw - fSinRoll * fSinPitch * fCosYaw;
W = fCosRoll * fCosPitchCosYaw fSinRoll * fSinPitchSinYaw;
}
Can someone help me or provide me with an example on how to rotate an object using quaternions please ? I'm working with OpenGL and C .
CodePudding user response:
- Euler angles are mind-friendly. Quaternions aren't.
- Since you find Euler angles hard, you either have a problem with matrices or with visualization of the object's space transformation.
Try to understand what's happening first, before you implement something you don't need.
Read this tutorial first. Then, get a grasp of Euler angles and of corresponding matrix operations. I'm sure you'll be able to solve your problem without quaternions, using only glRotate.