[SOLVED] {lwjgl} Recreate the "intersects" for Rectangle collision

Hello,
i’ve spend the last night reading examples from the lwjgl wiki, and getting started wasn’t so hard like i thought ;D
soooo i decided to make a simple pong and actually it was very easy to do, and now am trying to make a “Brick Breaker” game, and to make it happens, i need a collision detection method, for now i just want to recreate the Java2D intersects method,
and here is the way am doing it, it still doesn’t work :stuck_out_tongue:

calculate the distance between the 2 rectangle


float dx = x - x2;  
float dy = y - y2; 
double dxy = Math.sqrt((dx * dx) + (dy * dy)); 

the white line represent the distance

http://s14.postimg.org/xqhltp9z5/Capture.png

after that, i thought that if the length of that line is less than the rectangle width, then there is a collision,
i tried it, it works, but only when the collision is from the sides and the rectangle have the same width .
so i thought maybe i’ll need the sum of the 2 rectangles diagonals


double diago1 = Math.sqrt(w*w+h*h);
double diago2 = Math.sqrt(w2*w2+h2*h2);
double diagSum = diago1/2 + diago2/2 ;

and the result was better than the previous one but still didn’t work,
sooooo guys :persecutioncomplex:
any help ::slight_smile: ??

You could try a simple AABB collision method :slight_smile:
Maybe this can help you out: http://www.java-gaming.org/index.php?topic=28059.0
Just google AABB collision detection theres sure to be numerous results

I posted a AABB method a couple of days back. Hope it helps.

Seems to be the same technique as mine (the link wreed12345 posted) except you do this:

if(a - b < 0)

Where I do this:

if(a < b)

Doesn’t make much of a difference though. Just noticed a little optimisation.

thanx a lot, your answers solved the problem

Yeah, it´s the same idea. But since I also wrote some stuff about how to deal with a collision I thought it was worth the extra post. :slight_smile:

You´re welcome! Feel free to press the “appreciate” buttons… :slight_smile: