Sign in to follow this  
Tipotas688

IntersectRect and C++

Recommended Posts

Hello I m using IntersectRect(RECT r1, RECT r2, RECT r3) of C++ to test my sprite's collision detection... It only works when one sprite is engulfing the other, or when is exactly in the same positioning. Is that how IntersectRect works? Should it be when one rect intersects with the other? Logic goes as follows for both RECT: RECT rect1; rect1.left = s_position->x; rect1.top = s_position->y; rect1.right = s_position->x + s_gTexture->Width; rect1.bottom = s_position->y + s_gTexture->Height; s_gTexture is a IDirect3DTexture9* s_position is a D3DXVECTOR2*

Share this post


Link to post
Share on other sites
Did you try to debug to see the 4 values in the rect1 structure during run-time?
Cannot you be adding (s_position->x + s_gTexture->Width) values with different "scales", for example 0.5f + 256 (0.5f for position and 256 for texture width)?

Share this post


Link to post
Share on other sites
RECT rc2;
RECT rc0 = {0,0,100,100};
RECT rc1 = {75,75,150,150};
IntersectRect(&rc2, &rc0, &rc1);

rc2 -> 75,75,100,100

as expected !


EDIT:

D3DXVECTOR2 shoud of course by in screen coordinates
if ist a vertex coordinate it will by some
smale value usualy betwean -1 - 1

in case its a vertex coordinate you can use the
D3DXMatrix..... functions to transform it to screen coordinates

Share this post


Link to post
Share on other sites
they must, you are right, mine is 124x117, I think what happens is that they become squarish to fit in a square powered textured quad.

Shouldn't it return at least with that squared version? Is there any other way to get the Width and Height of a sprite??

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this