kkMorp

07-30-2003, 10:12 AM

I'm a complete newbie to this, but using my mathematical knowledge from school I wrote a few classes (Matrices, Points, et cetera) to start off with.

Then, reading about Euler angles and how they are susceptable to Gimbal lock I created, mainly by copy-and-paste, a Quaternion class.

I managed to draw a pyramid on screen, but when it comes to rotating it (I was meant to be rotating the camera, but it turns out to rotate the object. Another of my many woes) around its Y:

If I use code like this:

camera.position = Point3D ( 0, 0, -10 );

// Below is a Quaternion

camera.rotation.set_eulers ( 0, 0, 0 );

camera.update_matrix ();

while ( 1 )

{

Engine::begin_frame ();

camera.matrix.rotate_y ( 0.05f );

camera.apply ();

pyramid.draw ();

Engine::end_frame ();

}

The thing slowly gets flatter and flatter as if its X was being scaled.

If I use code like this, which I would like to use eventually:

camera.position = Point3D ( 0, 0, -10 );

// Below is a Quaternion

camera.rotation.set_eulers ( 0, 0, 0 );

camera.update_matrix ();

Quaternion update;

update.set_eulers ( 0, 0.05f, 0 );

while ( 1 )

{

Engine::begin_frame ();

camera.rotation = camera.rotation * update;

camera.update_matrix ();

camera.apply ();

pyramid.draw ();

Engine::end_frame ();

}

The thing rotates fine but the X tends towards completely flat at PI/2.

Rotating about different angles have similar distortions, but documenting them all would take forever. If needed I could just post a link to my code.

Can anyone help?

[This message has been edited by kkMorp (edited 07-30-2003).]

[This message has been edited by kkMorp (edited 07-30-2003).]

Then, reading about Euler angles and how they are susceptable to Gimbal lock I created, mainly by copy-and-paste, a Quaternion class.

I managed to draw a pyramid on screen, but when it comes to rotating it (I was meant to be rotating the camera, but it turns out to rotate the object. Another of my many woes) around its Y:

If I use code like this:

camera.position = Point3D ( 0, 0, -10 );

// Below is a Quaternion

camera.rotation.set_eulers ( 0, 0, 0 );

camera.update_matrix ();

while ( 1 )

{

Engine::begin_frame ();

camera.matrix.rotate_y ( 0.05f );

camera.apply ();

pyramid.draw ();

Engine::end_frame ();

}

The thing slowly gets flatter and flatter as if its X was being scaled.

If I use code like this, which I would like to use eventually:

camera.position = Point3D ( 0, 0, -10 );

// Below is a Quaternion

camera.rotation.set_eulers ( 0, 0, 0 );

camera.update_matrix ();

Quaternion update;

update.set_eulers ( 0, 0.05f, 0 );

while ( 1 )

{

Engine::begin_frame ();

camera.rotation = camera.rotation * update;

camera.update_matrix ();

camera.apply ();

pyramid.draw ();

Engine::end_frame ();

}

The thing rotates fine but the X tends towards completely flat at PI/2.

Rotating about different angles have similar distortions, but documenting them all would take forever. If needed I could just post a link to my code.

Can anyone help?

[This message has been edited by kkMorp (edited 07-30-2003).]

[This message has been edited by kkMorp (edited 07-30-2003).]