Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From quaternions to OpenGL rotations

I have an object which I want to rotate via keys. The object should yaw, pitch and roll. After trying a lot, I figured out that glRotate has its limitations and it won't be possible to implement something like that with that function.

I've researched a bit and found out about quaternion-based rotation. It would be also possible to rotate via a rotation matrix, but almost everyone describes the quaternions as the best ever.

I have read about the quaternions and understood them fairly well, but how to implement them in my OpenGL program is still a mystery. Does anyone know a small example? Not how to implement the quaternion class but how to use it. I don't get how to put the things together.

like image 974
buddy Avatar asked Oct 29 '11 10:10

buddy


People also ask

Does OpenGL use quaternions?

Both OpenGL and Direct3D give you ways to specify rotations as matrices, so a quaternion-to-matrix conversion routine is useful.

How are quaternions used in rotations?

Unit quaternions, known as versors, provide a convenient mathematical notation for representing spatial orientations and rotations of elements in three dimensional space. Specifically, they encode information about an axis-angle rotation about an arbitrary axis.

How do you convert quaternions to angles?

eul = quat2eul( quat ) converts a quaternion rotation, quat , to the corresponding Euler angles, eul . The default order for Euler angle rotations is "ZYX" . eul = quat2eul( quat , sequence ) converts a quaternion into Euler angles. The Euler angles are specified in the axis rotation sequence, sequence .


1 Answers

You can easily build rotation matrices out of unit quaternions.

Given a unit quaternion a + bi + cj + dk, you can build the following 3x3 matrix:

The matrix

Add the last line and column taken from the identity 4x4 matrix, glMultMatrix and you're done :)

like image 198
R. Martinho Fernandes Avatar answered Nov 04 '22 03:11

R. Martinho Fernandes