#### Archived

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

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

## 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 on other sites
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 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 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 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
• 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 on other sites
A good article http://www.gamasutra.com/features/19991018/Gomez_1.htm

##### Share on other sites
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 on other sites
Ok... that was odd. The post above was written by me. I guess I forgot to put in my name

##### Share on other sites
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;}

1. 1
2. 2
3. 3
4. 4
frob
14
5. 5

• 16
• 13
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632168
• Total Posts
3004543

×