Sign in to follow this  
lodoss118

collision detection algorithm bounding box

Recommended Posts

hi i am using this bounding box method, but some of my sprites have different rectangle sizes (as in for example i got ryu to punch jump fireball etc) whats the best way i can modify this to say do this at 60% 80% etc BOOL PPCollision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) { BOOL returnedValue=FALSE; if ((x1+w1)>=x2) if ((y1+h1)>=y2) if (x1<=(x2+w2)) if (y1<=(y2+h2)) returnedValue = TRUE; return returnedValue; } // returns true if bounding rectangles of two sprites overlap // function inserted because of bug in DXU version BOOL PPSpriteCollision(LPDXUSPRITE _s1,LPDXUSPRITE _s2) { return PPCollision((int)(_s1->x-_s1->tw/2.0f),(int)(_s1->y-_s1->th/2.0f),(int)_s1->tw,(int)_s1->th,(int)(_s2->x-_s2->tw/2.0f),(int)(_s2->y-_s2->th/2),(int)_s2->tw,(int)_s2->th); }

Share this post


Link to post
Share on other sites
intersect rect i the devil..do not use it...this is an old algorithm i used for a arcanoid clone...

bool BaseObject::BaseToBaseCollision(BaseObject &ObjectToCheckAgainst)
{
if (this->GetTop() < ObjectToCheckAgainst.GetTop())
{
// thisBox is above otherBox
if (this->GetBottom() > ObjectToCheckAgainst.GetTop())
if (this->GetLeft() < ObjectToCheckAgainst.GetLeft())
{
if (this->GetRight() > ObjectToCheckAgainst.GetLeft())
return true;
}
else
{
if (this->GetLeft() < ObjectToCheckAgainst.GetRight() )
return true;
}
}
else
{
// otherBox is above thisBox
if (ObjectToCheckAgainst.GetBottom() > this->GetTop())
if (ObjectToCheckAgainst.GetLeft() < this->GetLeft())
{
if ( ObjectToCheckAgainst.GetRight() > this->GetLeft())
return true;
}
else
{
if ( ObjectToCheckAgainst.GetLeft() < this->GetRight() )
return true;
}
}

return false;



}


the basic concept is there...just use your objects instead...

Share this post


Link to post
Share on other sites
I guess he's saying that you'll still be using a box (of course, you need *some* kind of simplified geometry to check against), but use a box calculated by the actual object than holding it seperately. Correct me if I'm wrong.

Share this post


Link to post
Share on other sites
Intersect rect(Ive used it) doesnt always works, I sometimes joke that thats what Mortal Kombat 2 the arcade machine uses....your objects will constantly visibly collide and not register a collision...or collide, but get stuck inside one another and bounce around...like a ball in pong bouncing inside a paddle and out some random side...its evil...its easy to use...and hence..not worth the energy used to type IntersectRect....trust me...make it yourself...youll be happier with the result

Share this post


Link to post
Share on other sites
well not sure how that is different from the method i posted but the problem i am saying is that say for the firebal the reatcangle is quite big and image is in the middle so if the firbal tries to hit an object it doesn;t seem to hit the object as the fireball rectangle is really big and image is small in the middle and i don;t want to resize the image manually using a paint program :), so if the firbal hits the object it disappears but it gives the effect that it doesn;t hit the object and disappears?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Tang of the Mountain
Intersect rect(Ive used it) doesnt always works, I sometimes joke that thats what Mortal Kombat 2 the arcade machine uses....your objects will constantly visibly collide and not register a collision...or collide, but get stuck inside one another and bounce around...like a ball in pong bouncing inside a paddle and out some random side...its evil...its easy to use...and hence..not worth the energy used to type IntersectRect....trust me...make it yourself...youll be happier with the result


Tang, when you had your object bounce around did you happen to move the object outside of the object that it was causing it to collide with and change its direction... If you do not move the object outside of what it is colliding with, it would not matter what you used to check for the boundingbox collision.

I ran into the same problem with using RECTs but found the problem to being what I mentioned above and not the Interesecting detection funtion.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this