# Thread: Rotatef and Translatef combinations

1. ## Rotatef and Translatef combinations

Hi,

I'm setting up a flying game, with the viewpoint as the aircraft. I have forward movement (translating along negative z-axis) set up automatically at X-rate per frame), there is a user joystick input which allows rotation for roll & pitch (yaw is derived from roll separately). So, it is my understanding, (which I have tested) that the following is true:
glRotatef (pitch, 1.0, 0.0,0.0) //user joystick input - (pitch in this example)
glTranslatef (0.0,0.0,x); // automatic forward motion

This results in a change in the line of sight (rotation) following by a translation along this line of sight. Basically a change in heading - which is what I want. However, the rotation axis remains fixed at the origin, rather than shifting with the translation. so if you pitch up after having pitched down the rotation occurs from a point far behind where you are current positioned.

I realise this can be solved using:
glTranslatef (0.0, 0.0, x); // automatic forward motion
glRotatef (pitch, 1.0, 0.0, 0.0); // user input

However, this (unsurprisingly) no longer changes your heading, and translation continues to occur in the same direction, NOT along the line of sight. Instead rotation just changes where you are looking as using GluLookAt would.

My issue is in how to combine these two opposing functions so that the 'plane' rotates about it's current position AND the subsequent translations move along the line of sight. Any suggestions or pointing me in the right direction would be much appreciated. I've read a great deal on this matter but copious reading nor many hours of trial and error hasn't provided a solution yet.

Thanks

2. ## Re: Rotatef and Translatef combinations

I assume that you are moving your plane in some small time interval( which is the case in most of the applications). Let's say at some given time the direction of the plane is known and you have to move the plane by a distance deltaZ along the line of sight.
may be this code will work if you want to stick to the transformation tools.

void transform()
{
glTranslatef(0, 0, deltaZ);
glRotatef(angle, 1, 0, 0);
angle= 0;
}

void display()
{
transform();
drawThePlane(); //this is code for your plane
glFlush();
}

initially angle will be zero and every time you press some button for changing the line of sight it will increase or decrease by deltaAngle(can be 5 degrees)

hope it will work

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•