Results 1 to 2 of 2

Thread: Rotatef and Translatef combinations

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2011

    Rotatef and Translatef combinations


    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.


  2. #2
    Member Newbie
    Join Date
    Nov 2010
    IIT Roorkee, India

    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()
    drawThePlane(); //this is code for your plane

    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
    learning to breathe

Similar Threads

  1. rotatef problems
    By AngryHippo in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-02-2010, 11:33 AM
  2. problem rotatef
    By john portella in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-19-2010, 01:07 PM
  3. Physics model combinations
    By klptzyxm in forum COLLADA
    Replies: 1
    Last Post: 05-04-2009, 10:50 PM
  4. color combinations
    By prashantgp in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-18-2003, 03:00 AM
  5. Using combinations (Alt+... and AltGr+...) for my console
    By Andreas J in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 09-29-2002, 08:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean