Archived

This topic is now archived and is closed to further replies.

Can't loop the loop correctly!

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

Recommended Posts

Share on other sites
I think I cracked it: Answered my own question ;-P

You have to invert the LookAt axis so that you are orientated correctly through all pitch angles. Something like this:

if(pitch >= 0 && pitch < 90)
{
upy = 1.0;
}
else if(pitch >= 90 && pitch < 180)
{
upy = -1.0;
}
else if(pitch >= 180 && pitch < 270)
{
upy = -1.0;
}
else if(pitch >= 270 && pitch < 360)
{
upy = 1.0;
}

gluLookAt(eyex, eyey, eyez, centrex, centrey, centrez, upx, upy, upz);

If anyone has a more elegant solution, please let me know.

Cheers

Share on other sites
quote:
Original post by sPriTe

If anyone has a more elegant solution, please let me know.

The problem you''ve found is known as gimbal lock and the usually recommended elegant solution is quaternions.

See this
article on quaternions.

dave j

Share on other sites
quote:
Original post by dave j
quote:
Original post by sPriTe

If anyone has a more elegant solution, please let me know.

The problem you''ve found is known as gimbal lock and the usually recommended elegant solution is quaternions.

See this
article on quaternions.

dave j

Quaternions would obviously work, but I''m not convinced they''d be that elegant in this case, since the OP is already working with matrices.

I''d just store a transformation matrix for the plane and rotate it about the X Y or Z axis when the user changes the yaw, pitch or roll. To place a camera in the plane, you could then use the inverse of the plane''s matrix.

The same thing would apply if you were using a vector/quaternion representation, except you''d have to convert it to a matrix before rendering.

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631719
• Total Posts
3001886
×