IntersectRect and C++

Started by
4 comments, last by Tipotas688 14 years, 2 months ago
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*
Advertisement
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)?
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
Well I just checked for different problems and s_gTexture->Width/Heigth
return weird numbers. It should return a UINT but my sprite definitely isnt 21x3 as it says :S
not sure i coud by wrong but i think sprites have size restrictions
eg they mus by a power of 2

but not sure
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??

This topic is closed to new replies.

Advertisement