Jump to content
  • Advertisement
Sign in to follow this  

Translation and Collision problem

This topic is 4557 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!