jaymystro

03-31-2006, 06:05 AM

Hi,

I have set up my collisions like so:

//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:

if ((dx1 < x2) && (dy1 < y2))

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 seems 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

I have set up my collisions like so:

//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:

if ((dx1 < x2) && (dy1 < y2))

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 seems 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