Sign in to follow this  

Polygon Collision Detection

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

Hi! I am working on a homebrew game for the Sony PSP, and I am wondering if any one can tell me how to calculate collision based on polygon intersection instead bounding spheres or boxes. I would use them, but I am building a desert like the one in JAK III with hills and bumps everywhere. I am not conerned with rotations at the moment, but I need to know how to detect collisions with the ground so the dune buggies can go over the hills! Any ideas?

Share this post


Link to post
Share on other sites
You guys might find what I am doing for collision detections of polygons kind of funny.

bool RotatingPong::CRotatingSquare::intersects( const CRotatingSquare & o ) const
{

// The aliases of these functions do not correspond
// to their real meaning. Top left can be rotated to be bottom right, etc.

CPoint ( CRotatingSquare::* t [ 4 ] )( void ) const =
{
&CRotatingSquare::topleft,
&CRotatingSquare::topright,
&CRotatingSquare::borromleft,
&CRotatingSquare::bottomright
};

for( int i = 0; i < sizeof(t) / sizeof(t[0]) - 1; ++i )
{
CLineSegment c( (*this.*t[i])(), (*this.*t[i + 1])() );

for( int j = 0; j < sizeof(t) / sizeof(t[0]) - 1; ++j )
{
CLineSegment d( (o.*t[j])(), (o.*t[j + 1])() );

if( c.intersects(d) )
{
return true;
}
}
}

return false;
}


And then checking for the line segment intersections using the code I detailed here.

http://www.gamedev.net/community/forums/topic.asp?topic_id=428579

I think I might just finish it like this for the hell of it and do some major optimizing / reconstruction of these algorithms later.

Share this post


Link to post
Share on other sites

This topic is 4018 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.

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