Jump to content
  • Advertisement
Sign in to follow this  
Tipotas688

IntersectRect and C++

This topic is 3054 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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)?

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
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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!