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 6 of 6

Thread: moving space ship

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    118

    Cool moving space ship

    well I am going back to an asteroids like game. I am trying to get a space ship figure to rotate around a point and move up like in asteroids.
    Code :
    void Draw_Ship()
    {
    	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
     
    	glPushMatrix();
     
    	glTranslatef(5.0f, 0.0f, 0.0f);
     
    	glRotatef(angle, 0.0f, 0.0f, 1.0f);
     
    	glTranslatef(0.0f, up, 0.0f);
     
    	draw_ship();
     
    	glPopMatrix();
     
    	glPushMatrix();
     
    	glTranslatef(-5.0f, 0.0f, 0.0f);
     
    	glRotatef(angle_two, 0.0f, 0.0f, 1.0f);
     
    	draw_ship_two();
     
    	glPopMatrix();
     
    	glutSwapBuffers();
    }
    here is the main code I am working on. let me know if you need more code.

  2. #2
    Intern Contributor
    Join Date
    Dec 2016
    Location
    Ocean Shores, WA USA
    Posts
    97
    Looks like a good start.

    Jeff

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,828
    Quote Originally Posted by pbivens View Post
    well I am going back to an asteroids like game. I am trying to get a space ship figure to rotate around a point and move up like in asteroids.
    You need to accumulate transformations. At each update, transform the "forward" motion by the current rotation then add the result to the current position.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    118
    well I have worked on my code here is what I have so far.
    Code :
    void Draw_Ship()
    {
    	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
     
    	glPushMatrix();
     
    	x = cos(angle)*up;
    	y = sin(angle)*up;
     
    	glTranslatef(-x, -y, 0.0f);
     
    	glRotatef(angle, 0.0f, 0.0f, 1.0f);
     
    	glTranslatef(x, y, 0.0f);
     
    	glTranslatef(x, y, 0.0f);
     
    	draw_ship();
     
    	glPopMatrix();
     
    	glPushMatrix();
     
    	glTranslatef(-5.0f, 0.0f, 0.0f);
     
    	glRotatef(angle_two, 0.0f, 0.0f, 1.0f);
     
    	draw_ship_two();
     
    	glPopMatrix();
     
    	glutSwapBuffers();
    }

  5. #5
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    118
    I have almost solved my problem can I please get some input on my code.

  6. #6
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,397
    Please read the Forum Posting Guidelines. In particular, see #4 under Posting Guidelines and #6 under Before You Post.

Posting Permissions

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