PDA

View Full Version : rotating primitives



phil67rpg
03-10-2012, 09:25 PM
well I have drawn 2 space ships on the screen.I can get one of them to move and rotate.I cant get the second one to rotate of move however.here is the code I am working on.


void DrawShip()
{
glPushMatrix();
glColor3f(0.0f,1.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();
}

void DrawAlien()
{
glPushMatrix();
glLoadIdentity();
glTranslatef(2.0f,0.0f,0.0f);
glColor3f(1.0f,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();
}

void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
DrawShip();
DrawAlien();
glutSwapBuffers();
}

void ShipLeft()
{
glRotatef(m,0.0f,0.0f,1.0f);
m+=0.1f;
}

void ShipRight()
{

}

void ShipUp()
{

}

void ShipDown()
{

}

void ShipBullet()
{

}

void AlienUp()
{
glTranslatef(0.0f,i,0.0f);
i+=0.1f;
}

void AlienDown()
{
glTranslatef(0.0f,j,0.0f);
j-=0.1f;
}

void AlienLeft()
{
glRotatef(k,0.0f,0.0f,1.0f);
k+=0.1f;
}

void AlienRight()
{
glRotatef(l,0.0f,0.0f,1.0f);
l-=0.1f;
}

menzel
03-11-2012, 06:04 AM
You didn't tell us where the *Left *Right etc. functions are called (if they are called). Drawing of the ship depends on the current ModelView matrix, drawing of the alien does not as it sets the matrix to the identity explicitly - maybe that difference is your error.