This is how I would do it:

struct point3d {

float x, y, z;

}

struct openglquad {

point3d pnt[4];

}

int anyinsidez( openglquad a, openglquad b ) {

int minz = a.pnt[0].z, maxz = a.pnt[0].z;

int i = 0;

for( i = 0; i < 4; i++ ) {

if( a.pnt[i].z < minz ) minz = a.pnt[i].z;

if( a.pnt[i].z > maxz ) maxz = a.pnt[i].z;

}

for( i = 0; i < 4; i++ ) {

if( ( b.pnt[i].z >= minz ) && ( b.pnt[i].z <= maxz ) ) return 1;

}

return 0;

}

int anyinsidex( openglquad a, openglquad b ) {

int minx = a.pnt[0].x, maxx = a.pnt[0].x;

int i = 0;

for( i = 0; i < 4; i++ ) {

if( a.pnt[i].x < minx ) minx = a.pnt[i].x;

if( a.pnt[i].x > maxx ) maxx = a.pnt[i].x;

}

for( i = 0; i < 4; i++ ) {

if( ( b.pnt[i].x >= minx ) && ( b.pnt[i].x <= maxx ) ) return 1;

}

return 0;

}

int anyinsidey( openglquad a, openglquad b ) {

int miny = a.pnt[0].y, maxy = a.pnt[0].y;

int i = 0;

for( i = 0; i < 4; i++ ) {

if( a.pnt[i].y < miny ) miny = a.pnt[i].y;

if( a.pnt[i].y > maxy ) maxy = a.pnt[i].y;

}

for( i = 0; i < 4; i++ ) {

if( ( b.pnt[i].y >= miny ) && ( b.pnt[i].y <= maxy ) ) return 1;

}

return 0;

}

int checkcollision( openglquad a, openglquad b ) {

if( anyinsidez( a, b ) == 1 ) {

if( anyinsizex( a, b ) == 1 ) {

if( anyinsidey( a, b ) == 1 ) return 1;

}

}

return 0;

}

It’s probably and almost definitely not perfect, but it will give you a

general idea if they are close to colliding.

Take care,

-AlexOn Sun, Jun 27, 2010 at 10:52 AM, Jonathan Dearborn wrote:

Separating Axis Theorem?

Jonny D

On Sun, Jun 27, 2010 at 7:43 AM, Jesse Palser wrote:

[1.2+OpenGL]-Collision Between Quads?

Hi,

How would I register collision between two OpenGL quads.

I would like it to work if the quads are scaled and/or rotated too.

Interested in both bounding box and pixel-perfect collision detections…

Thanks!

Jesse

16BitSoft®

Video Game Design Studio

www.16BitSoft.com

SDL mailing list

SDL at lists.libsdl.org

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list

SDL at lists.libsdl.org

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org