Different collision detection methods.
once again given this is a tetris type program, I was looking for a way to determine wether or not a square that is constantly dropping has reached a certain point on the opengl screen.
I made 2 lines on the open gl window that look like this...
the bottoms of the lines equal -20.0f(y axis)....
| . | //box drops from top.
and my square which is made up of
glVertex3f(-1.0f, 1.0f, 0.0f); //top left glVertex3f( 1.0f, 1.0f, 0.0f); //top right glVertex3f( 1.0f,-1.0f, 0.0f); //bottom left glVertex3f(-1.0f,-1.0f, 0.0f); //Bottom right
the box drops constantly, and what I want to do, is when it gets to a certain point...I want the box to stop right where it is.
the code that makex the box drop looks like this...
if(count>50)
{
count=0; //This counter makes the box drop down about
//a little less than every 1 second yposy--; //This is the boxes y position
}
I tried using an if, that said ....if(yposy == -20.0f)
{
yposy-=0.0;
}
but this just made the box start at -20.0f in the begginning of program. Any suggestions?
[edited by - skittlez on February 12, 2003 10:29:44 PM]
[edited by - skittlez on February 12, 2003 10:30:31 PM]
what you want to do is test if it is greater than or equal to 20k, that way if you aren''t always moving it down at 1 unit per second, then it will stop, so you''ll want to have something like this:
if(ypos<=-20)
ypos+=1.0f; //or whatever value you''re incrementing it by
that will make it so the box just stays at the bottom, however, I would suggest that you look in to using a bool variable to say whether or not to move it:
bool move=true; //put this at the top of your program
// inside of the drawglscene function, put this:
if(move==true && count>50)
{
ypos--;
count=0;
}
if(move)
count++;
if(ypos<=-20)
move=false;
and that code will effectively move, test, and stop the block once it reaches -20
bloodright.150m.com //For the latest on all of the IVGDA projects!
if(ypos<=-20)
ypos+=1.0f; //or whatever value you''re incrementing it by
that will make it so the box just stays at the bottom, however, I would suggest that you look in to using a bool variable to say whether or not to move it:
bool move=true; //put this at the top of your program
// inside of the drawglscene function, put this:
if(move==true && count>50)
{
ypos--;
count=0;
}
if(move)
count++;
if(ypos<=-20)
move=false;
and that code will effectively move, test, and stop the block once it reaches -20
bloodright.150m.com //For the latest on all of the IVGDA projects!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement