Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Moving a ship and calculating direction to translate

  1. #1
    Guest

    Moving a ship and calculating direction to translate

    I am trying to move a ship across the screen using the arrow keys. But everytime I move the ship it moves in the wrong direction. I need it to move in the direction it is pointing. I beleive the problem is in the calculation of xd and yd, the coordinates that I am translating too...it seems to move up and down correcting but anyother direction it moves, it seems, the opposite direction...

    /************************************************** *********/
    void rotate(){
    if(rot > 360.0) rot -= 360.0;
    if(rot < 0.0) rot += 360.0;
    if(Left_isPressed)
    rot += 5.0;
    if(Right_isPressed)
    rot -= 5.0;
    if(Up_isPressed){
    yd += (cos((rot/180*3.14)) * speed);
    xd += (sin((rot/180*3.14)) * speed);
    }

    /*******function to draw ship********/
    glPushMatrix();
    glTranslatef(xd,yd,0.0);
    glRotatef(rot,0.0,0.0,1.0);
    glBegin(GL_LINES);
    for(i=0;i<=size;i++)
    glVertex2f(x[i],y[i]);
    glEnd();
    glPopMatrix();
    glutSwapBuffers();

  2. #2
    Junior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Chicago, IL US
    Posts
    100

    Re: Moving a ship and calculating direction to translate

    Let me first say I am not an expert.

    That being said, I think you need to have both a concept of "facing direction" and "facing movement" to implement the ship's movement properly. The ship movement is a vector (i.e. it has both magnitude and direction). These could be variables in your application's code (i.e. direction_face, direction_move).

    Also, you might want to look at:
    http://www.evl.uic.edu/aej/488/oldhw/fall2k.hw2.html

    Hope this helps.

    Good luck.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Chicago, IL US
    Posts
    100

    Re: Moving a ship and calculating direction to translate

    The "facing movement" above should read "movement direction". Sorry.

Posting Permissions

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