Sign in to follow this  

Translation and Collision problem

Recommended Posts

Hi, The problem with my very basic colision system is that when the glTranslate matrix is used, the vertex points dont seem to be translating to their new locations. I tested this by assigning a variable to one of the verticies, and then incrementing the vertex, when it reached a certain point on the screen (representing a pixel location), I triggered a response. This method works but is stupidly slow. I need help gettting this to work. Below is some of my code which is supposed to create a sort of bounding box around one of the object. I have set up my collisions like so: code: //Object 1 coordinates x1 = 0; //Top left x y1 = 100; //Top left y x2 = 100; //Bottom right x y2 = 0; //Bottom right y //Object 2 coordinates dx1 = 0; //same layout as above.. dy1 = 300; dx2 = 100; dy2 = 200; //Object 1 glBegin(GL_QUADS); glVertex2i(0,0); glVertex2i(x2,y2); glVertex2i(100,100); glVertex2i(x1,y1); glEnd(); //Object 2 glTranslatef(0.0f, Translate, 0.0f); glBegin(GL_QUADS); glVertex2i(0,200); glVertex2i(dx2,dy2); glVertex2i(100,300); glVertex2i(dx1,dy1); glEnd(); Now, this draws two squares with the top left and bottom right corners set as variables. When I press a key I increment the 'Translate' variable which moves my square down towards the other one. My question is, how come when I begin translating, the coordinate variables dont change but the object moves. My collision test is very simple: code: if ((dx1 < x2) && (dy1 < y2)) //supposed to be a square region Collided! It works if i set up each point in each square with a variable, then increment each one with a keypress. But this means 18 variables and 18 input parameters in the function, which is wasteful. I know its been posted before but ive not seen any actual code posted. Please can some one clarify for me. Thanks a lot

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this