PDA

View Full Version : Rolling using gluLookAt().



TolTol
11-14-2002, 07:38 AM
Hi all,

Does anyone know of a way to make the camera roll using gluLookAt. Is there some way of doing it with the last three parameters? The reason I ask is because I need to replicate an aeroplane rolling, ie. turning left and right.

Cheers http://www.opengl.org/discussion_boards/ubb/smile.gif

nexusone
11-14-2002, 09:00 AM
Have not tried it out, but the code should look something like this:

need to have the view change over time and space movied.

int start_roll_angle = 0;
int end_roll_angle = 360;
int roll_angle;


x3 = cos(roll_angle); // note need to convert degrees to randians for cos/sin function
y3 = sin(roll_angle);
glLookAt(x1,y1,z1, x2,y2,z2, x3,y3,0.0)
roll_angle += rate_of_roll; //
if (roll_angle > end_roll_angle) roll_angle = start_roll_angle; // reset if greater then 360

Of course you will need to a routine to update your display and move your object through your world. And add something to control if to roll right or left.



Originally posted by TolTol:
Hi all,

Does anyone know of a way to make the camera roll using gluLookAt. Is there some way of doing it with the last three parameters? The reason I ask is because I need to replicate an aeroplane rolling, ie. turning left and right.

Cheers http://www.opengl.org/discussion_boards/ubb/smile.gif

TolTol
11-14-2002, 11:51 AM
nexusone, it doesn't work when the axis going from the planes nose to its tail is Parallel to the X axis, otherwise it works fine, thanks.
I take it that it doesn't work because the code is not changing the z coordinate, ie, the last parameter in gluLookAt().

Any ideas on how to rectify this problem would be appreciated. http://www.opengl.org/discussion_boards/ubb/wink.gif

jpummill
11-14-2002, 12:21 PM
I am not very strong in math "yet" but I think this has something to do with using normal rotate functions and losing your point of reference.

The term that I have heard over and over is gimbal lock. Try searching google for "gimbal lock" and you will come up with lots of articles on what it means and ways to work around it.

Be aware that the general solution seems to be by using matrix math.

Good luck,
jpummill