Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: rotating object

  1. #11
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    474
    Quote Originally Posted by pbivens View Post
    so how do I adjust the angle variable.
    Have keys for "rotate right" and "rotate left". Pressing one causes the angle to increase at a fixed rate, pressing the other causes it to decrease at a fixed rate.

  2. #12
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    26
    here is the code I am using
    Code :
    void ship_left_two()
    {
           angle+=2.5f;
    }
     
    void ship_right_two()
    {
    	angle-=2.5f;
    }
    here is the drawing code
    Code :
    void DrawShip(GLfloat position_X,GLfloat position_Y, GLfloat position_Z, GLfloat rotation,GLfloat color)
    {
    	glPushMatrix();
    	double magnitude = sqrt(position_X * position_X + position_Y * position_Y);
    	double angle = atan2(position_Y,position_X);
    	position_X = magnitude * cos(angle);
    	position_Y = magnitude * sin(angle);
    //	double acceleration = sqrt(position_X * position_X + position_Y * position_Y);
    //	double angle = atan2(position_Y,position_X);
    //	position_X = acceleration * cos(angle);
    //	position_Y = acceleration * sin(angle);
    //	position_X = speed_X;
    //	position_Y = speed_Y;
    //	glRotatef(rotation,0.0f,0.0f,1.0f);
    	glTranslatef(position_X, position_Y, position_Z);
    	glColor3f(color,0.0f,0.0f);
    	glBegin(GL_LINE_LOOP);
    	glVertex3f(0.0f,-0.25f,0.0f);
    	glVertex3f(-0.25f,-0.5f,0.0f);
    	glVertex3f(-0.5f,-0.5f,0.0f);
    	glVertex3f(0.0f,0.5f,0.0f);
    	glVertex3f(0.5f,-0.5f,0.0f);
    	glVertex3f(0.25f,-0.5f,0.0f);
    	glVertex3f(0.0f,-0.25f,0.0f);
    	glEnd();
    	glPopMatrix();
    }
    I am still a little confused

  3. #13
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    474
    Quote Originally Posted by pbivens View Post
    here is the drawing code
    Code :
    	double magnitude = sqrt(position_X * position_X + position_Y * position_Y);
    	double angle = atan2(position_Y,position_X);
    	position_X = magnitude * cos(angle);
    	position_Y = magnitude * sin(angle);
    This doesn't belong here. The drawing code in your first post was fine.

    The issue is how you obtain the position which you pass to the drawing function.

  4. #14
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    26
    now I am totally confused, please help

Posting Permissions

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