Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kolpo

rectangular collision

This topic is 6217 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

If I have to rectangulars how can I then know or they collish? so(a and b are rectangulars that can be of any size): bool isCol(int aX, int aY,int aWidth,int aHeight, int bX, int bY, int bWidth, int bHeight) { ? }

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Kolpo:

This is a simple logic/math problem. Just think about it. If one area is anywhere inside the other area, thewn they collide. Now, think mathematicaaly, how can you solve that?

if ((LeftSideRect1 is rightof RightSideRect2 AND
RightSideRect1 is leftof LeftSideRect2) AND ...

You need to solve these kind of problems yourself.

Share this post


Link to post
Share on other sites
BOOL IntersectRect(
LPRECT lprcDst, // pointer to structure for intersection
CONST RECT *lprcSrc1, // pointer to structure with first rectangle
CONST RECT *lprcSrc2 // pointer to structure with second rectangle
);

Share this post


Link to post
Share on other sites
oh found out that it is a very easy problem. I was wrong with trying to find out when they collish. It is a lot more easy to find out when they do NOT collish:

bool isCol(int aX, int aY,int aWidth,int aHeight, int bX, int bY, int bWidth, int bHeight)
{
if ((aX+aWidth) bX+bWidth) return false;
if ((aY+aHeight) bY+bHeight) return false;
return true;
}

Buster, why do you use pointers and the LPRECT lprcDst variabele?

Share this post


Link to post
Share on other sites
Once you have that licked....

When you check that your objects are on the screen (which is also a collision check!) build a stack of the collision positions (one for bullets, one for objects) and then after the main draw method process the stacks against each other!

Thats what I have done in Nebuloids

:-)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Could you please explain to me how finding the x value of the right side of the first rect, then multiplying that by the x value of the left side of the second rect, and then adding the width of the second rect and finding that it is a non-zero value would tell you that those two rects intercet at ANY point? This just seems totaly insane to me, like it was writen by someone that has no idea what he is doing. It''s probly just that I can''t see how this works out. An explenation would be great, as I am totaly confused here. It shouldn''t work...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
sorry teh code didn''t post correct(it didn''t post parts of it)


bool isCol(int aX, int aY,int aWidth,int aHeight, int bX, int bY, int bWidth, int bHeight)
{
if ((aX+aWidth)< bX || aX > bX+bWidth) return false;
if ((aY+aHeight)< bY || aY>bY+bHeight) return false;
return true;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!