How to do 2D Image collision detection

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
bayofxyz
Posts: 5
Joined: Sun Sep 28, 2008 5:58 pm

How to do 2D Image collision detection

Post 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.
Quillraven
Posts: 62
Joined: Fri Aug 22, 2008 7:22 am

Post 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
bayofxyz
Posts: 5
Joined: Sun Sep 28, 2008 5:58 pm

Post by bayofxyz »

Oh, thank you so much now i understand it.
Post Reply