rectangular collision
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)
{
?
}
August 09, 2001 10:40 AM
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.
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.
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
);
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
);
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?
bool isCol(int aX, int aY,int aWidth,int aHeight, int bX, int bY, int bWidth, int bHeight)
{
if ((aX+aWidth)
if ((aY+aHeight)
return true;
}
Buster, why do you use pointers and the LPRECT lprcDst variabele?
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 <a href="http://www.eldian.com/_nebuloids>Nebuloids
:-)
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 <a href="http://www.eldian.com/_nebuloids>Nebuloids
:-)
ujhkfkfk
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
:-)
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
:-)
ujhkfkfk
August 11, 2001 05:41 AM
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...
Ok... that was odd. The post above was written by me. I guess I forgot to put in my name

Tell him about the twinky...
August 11, 2001 05:45 AM
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;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement