well I am working on an asteroids game, well I am able to rotate my space ship to the left but I want to reset my rotational axis when I move a second space ship. here is my code I am working on.
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"][color="#000000"] RenderSceneLeft()[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glMatrixMode(GL_MODELVIEW);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glRotatef(1.0f,0.0f,0.0f,1.0f);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glPushMatrix();[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glColor3f(0.0f,1.0f,0.0f);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glBegin(GL_LINE_LOOP);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.0f,-0.25f,0.0f);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(-0.25f,-0.5f,0.0f);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(-0.5f,-0.5f,0.0f);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.0f,0.5f,0.0f);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.5f,-0.5f,0.0f);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.25f,-0.5f,0.0f);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.0f,-0.25f,0.0f);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glEnd();[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glPopMatrix();[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glutSwapBuffers();[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]I think my answer is how I am using the push and pop matrix functions.[/font][/font]
resetting rotational axis
Push the matrix before you rotate (glRotatef modifies the current matrix), then pop it to restore it to the state it was in when you pushed it.
(Its a stack, so a push copies the current matrix and puts the copy at the top of the stack, a pop removes the top matrix from the stack and makes it the currently active one).
(You could also use glLoadIdentiy to reset the matrix completely)
(Its a stack, so a push copies the current matrix and puts the copy at the top of the stack, a pop removes the top matrix from the stack and makes it the currently active one).
(You could also use glLoadIdentiy to reset the matrix completely)
well when I move one ship the other one disappers, the same thing happens with the second ship
rotate the first ship then use [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
glLoadIdentity() then rotate the second ship.
[/font][font="helvetica, arial, verdana, tahoma, sans-serif"][size="2"][color="#282828"]make sure you apply any translation after you rotate it[/font]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement