🔒 Locked
Collision detection
Advertisement
Original Post
BOOL Collision(RECT obj1, RECT obj2)
{
RECT temp;
if (IntersectRect(&temp, &obj1, &obj2)) return TRUE;
return FALSE;
}
Thats my collision detector.
-----------------------------
A wise man once said "A person with half a clue is more dangerous than a person with or without one."
{
RECT temp;
if (IntersectRect(&temp, &obj1, &obj2)) return TRUE;
return FALSE;
}
Thats my collision detector.
-----------------------------
A wise man once said "A person with half a clue is more dangerous than a person with or without one."
actually there is some better way (thats what i think
)
i learned it from witchlord
.
the problem in your why is that u can have a pixel space between the too object andthat means its not a good collusion...
the other why is to create a circle that its origin is the object origin, then , if u want to check if the object collide some other object just check if the sum of the two objects circles radiuses is bigger that the distance between the two circles origins....
hope its help
.
u can do the same thing with if u want to check if object collide some point.
"Everything you know is wrong" - Bono
i learned it from witchlord
the problem in your why is that u can have a pixel space between the too object andthat means its not a good collusion...
the other why is to create a circle that its origin is the object origin, then , if u want to check if the object collide some other object just check if the sum of the two objects circles radiuses is bigger that the distance between the two circles origins....
hope its help
u can do the same thing with if u want to check if object collide some point.
"Everything you know is wrong" - Bono
There''s two way, i known to detect collision of 2 object.
The first one as mentionned earlier is BoundingBox, that''s great but it''s a lot of calculations compared to the second option.
The second option is BoundingSphere, where you only store the greatest distance from the origin (0,0,0) to the fartest vertex of your object.
This way, with only : "if (d < ( r1 + r2))" you can known if there a chance that those 2 object will collide.
d : distance between the center of the two object to check for collision
r1, r2 : Is the maximum radius of the 2 object (bounding sphere)
When, in the first or second method, the condition for collision return TRUE, that dont mean that those objects has collide; But instead, that those object has a chance to collide.
So when you detect a potiential collision, you must check each polygon of each object to see if they''ve really collide together.
I must say, that collision detection is a costly function. So, as always there''s some room for improvement. Instead of checking, each polygons of each object together, after detecting a potential collision, why not have a tree of bounding sphere or bounding box for each object.
So let say that we have two persons running toward each other. So when the two are coming closer, the first BoundingSphere will return true as if they where collide, but in fack they may be at 2 meters. So, when the head node of the BoundingSphere tree return true, we go a step down. So, now we have a boundingsphere for the torso, each legs, arms, ...
With this type of Collision Detection, you can achieve very, if not perfect, collision detection. At less cost, then boundingbox alone, without CollisionTree.
That was only my reflection of the Collision Detection part of an Engine. Let try it now !!
Happy Coding,
LowRad
The first one as mentionned earlier is BoundingBox, that''s great but it''s a lot of calculations compared to the second option.
The second option is BoundingSphere, where you only store the greatest distance from the origin (0,0,0) to the fartest vertex of your object.
This way, with only : "if (d < ( r1 + r2))" you can known if there a chance that those 2 object will collide.
d : distance between the center of the two object to check for collision
r1, r2 : Is the maximum radius of the 2 object (bounding sphere)
When, in the first or second method, the condition for collision return TRUE, that dont mean that those objects has collide; But instead, that those object has a chance to collide.
So when you detect a potiential collision, you must check each polygon of each object to see if they''ve really collide together.
I must say, that collision detection is a costly function. So, as always there''s some room for improvement. Instead of checking, each polygons of each object together, after detecting a potential collision, why not have a tree of bounding sphere or bounding box for each object.
So let say that we have two persons running toward each other. So when the two are coming closer, the first BoundingSphere will return true as if they where collide, but in fack they may be at 2 meters. So, when the head node of the BoundingSphere tree return true, we go a step down. So, now we have a boundingsphere for the torso, each legs, arms, ...
With this type of Collision Detection, you can achieve very, if not perfect, collision detection. At less cost, then boundingbox alone, without CollisionTree.
That was only my reflection of the Collision Detection part of an Engine. Let try it now !!
Happy Coding,
LowRad
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement