• Create Account

# Sam Sandeep

Member Since 25 Apr 2011
Offline Last Active Feb 25 2013 10:19 PM

10 January 2013 - 03:51 AM

As Endurion pointed out just use the bool in the condition for collision.

```if(g_bBlock[4].m_bActive_three==true)
{
if(x>=3.0f && x<=5.0f && y>=3.5f && y<=4.0f)
{
ystep = -ystep;
g_bBlock[4].m_bActive_three=false;
}
}```

But trust me, there are much more efficient ways of detecting collision and removing the blocks.  The one you are using is probably the easiest but not accurate in many cases.

### In Topic: How do I rotate a rectangle with the four vertices

08 January 2013 - 06:09 AM

Equation for rotating a point around a center:
(x2,y2) = resulting rotated point
(x1,y1) = original point before rotation
(xc,yc) = center of rotation
x2 = xc+(x1-xc)*cos(angle)-(y1-yc)*sin(angle)
y2 = yc+(x1-xc)*sin(angle)+(y1-yc)*cos(angle)

Wow awesome.. it works...

Phew..  and it is so simple.. :|

### In Topic: How do I rotate a rectangle with the four vertices

08 January 2013 - 06:02 AM

Thank you so much...

I'll try it out and let you know..

### In Topic: Collision Detection HELP! openGL SDL c++, 2D top down racing game

02 January 2013 - 04:15 AM

Its the same method. compare the left side of the car coordinates to the left side of the track coordinates, and the right side of the car coordinates to the right side of the track coordinates. As i said, the best way i can think of to map out the track coordinates is using calculus to find the curve x,y.

then when the condition that the curve coordinates equals the car coordinates, set the car x coordinates equal to the curve x coordinates - 1.

thae hardest part for you is calculating the coordinates of the track. search up some calculus equations.

if car.x <= track.left

{ car.x = track.left + 1}

if car.x >= track.right

{ car.x = track.right - (car.x + car.width) - 1 }

Thanks.

I already have the co-ordinates for the track.  I've drawn the track by drawing many bezier curves from quadratic equations, where the last point of the first curve is the first point of the second curve and so on.  I have fixed distance for the width of the track, so i draw the other side as well.  So, i guess i have all the points needed to calculate the collision.

### In Topic: Collision Detection HELP! openGL SDL c++, 2D top down racing game

02 January 2013 - 03:15 AM

Ive never used openGL but if the theory is the same, you need to constantly compair the coordinates of the front, back, left, right of your cars with one another, then set up conditions when the cars are toutching to apply the collision physics.

//checks if the x coordinates of both objects are within the same range

"if (starting car1 x > starting car2 x ) and (ending car1 x < ending car 1 x) then

{

///// checks if y coordinates of both objects are in the same range

if (srarting car1 y > starting car2 y) and (ending car1 y < ending car2 y) then

{

///apply physics

}

}