Question about moving shapes...
ok I have an Idea of what I need to do to make a shape, like a square move down periodically, like say if I had a square...if I wanted it to go down, I would have to translate the y coordinates.
Lets say I had this...
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f); //Makes a simple square
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
now if I wanted it to move down, somehow I would have to move the y coordinates down. So if im correct, to move this down it would be...
glVertex3f(-1.0f, 0.0f, 0.0f);
glVertex3f( 1.0f, 0.0f, 0.0f);//Moves square down 1.0 on y axis
glVertex3f( 1.0f,-2.0f, 0.0f);
glVertex3f(-1.0f,-2.0f, 0.0f);
But how do I get the "tetris" effect of constant moving?
it's much easier to use glTranslatef
with glTranslatef, you could have something like this instead:
and that will allow you to move the box back by pressing up and down, and you should be able to change that code to your liking (ie: make the zpos constantly subtracting, or only do it on special circumstances)
-jverkoey
-EDIT-
sorry, just realized you said y, not z, hehe
the code to move it down on the y-plane is just as simple:
and you can also add an x value in there to move it on the x plane.
[edited by - jverkoey on February 10, 2003 10:17:52 PM]
[edited by - jverkoey on February 10, 2003 10:18:26 PM]
with glTranslatef, you could have something like this instead:
//somewhere at the top of the filefloat zpos=0.0f;//in the DrawGLScene() function, after the clearglLoadIdentity();glTranslatef(0.0f,0.0f,zpos);glBegin(GL_QUADS); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);glEnd();if(keys[VK_UP]) zpos--;if(keys[VK_DOWN]) zpos++;
and that will allow you to move the box back by pressing up and down, and you should be able to change that code to your liking (ie: make the zpos constantly subtracting, or only do it on special circumstances)
-jverkoey
-EDIT-
sorry, just realized you said y, not z, hehe
the code to move it down on the y-plane is just as simple:
//somewhere at the top of the filefloat ypos=0.0f;//in the DrawGLScene() function, after the clearglLoadIdentity();glTranslatef(0.0f,ypos,-10.0f);glBegin(GL_QUADS); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);glEnd();if(keys[VK_UP]) ypos++;if(keys[VK_DOWN]) ypos--;
and you can also add an x value in there to move it on the x plane.
[edited by - jverkoey on February 10, 2003 10:17:52 PM]
[edited by - jverkoey on February 10, 2003 10:18:26 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement