# Polygon Collision Detection

## 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 on other sites
http://www.flipcode.com/articles/article_basiccollisions.shtml

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

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627667
• Total Posts
2978533

• 9
• 10
• 10
• 12
• 22