Page 1 of 1

How to do 2D Image collision detection

Posted: Sun Nov 08, 2009 11:18 am
by bayofxyz
Hi, I'm new on Irrlicht, I read all the tutorials and examples, but I don't know how to check that images are collision.

I know only how to use draw2DImage() and how to use event to control image movement.

I want to know it because I use this function to create GUI and I use this function to change my cursor icon(hide default icon before) so I want to check that images are collision.

Posted: Sun Nov 08, 2009 2:22 pm
by Quillraven
2d = rect = normal rect collision?

a rect has an x,y coordinate and a width,height of the rect.

to check if 2 rects collide in any way:

Code: Select all

if( rect1.x >= rect2.x && rect1.x <= rect2.x + rect2.width
    && rect1.y >= rect2.y && rect2.y <= rect2.y + rect2.height )
you just check if one corner of rect1 is inside of rect2

Posted: Sun Nov 08, 2009 2:45 pm
by bayofxyz
Oh, thank you so much now i understand it.