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

Separating Axis Theorem?

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

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

This is how I would do it:

struct point3d {
float x, y, z;
}

point3d pnt[4];
}

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 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 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;
}

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:

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

Here is something that looks useful:
http://jgt.akpeters.com/papers/GuigueDevillers03/triangle_triangle_intersection.html

The function

int tri_tri_overlap_test_2d(double p1[2], double q1[2], double r1[2],
double p2[2], double q2[2], double r2[2]);

could be applied multiple times to cover arbitrary 2D polygons including
–AndreasOn 6/27/10 7:43 AM, Jesse Palser wrote:

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

Found one more algorithm - /triangle-box overlap test (in 3D)/
http://jgt.akpeters.com/papers/AkenineMoller01/tribox.htmlOn 6/27/10 12:53 PM, Andreas Schiffler wrote:

Here is something that looks useful:
http://jgt.akpeters.com/papers/GuigueDevillers03/triangle_triangle_intersection.html

The function
int tri_tri_overlap_test_2d(double p1[2], double q1[2], double r1[2],
double p2[2], double q2[2], double r2[2]);

could be applied multiple times to cover arbitrary 2D polygons
–Andreas

On 6/27/10 7:43 AM, Jesse Palser wrote:

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

Something like what a geometry text book might tell you:

A quad is a finite expanse of plane.

Any two non-parallel planes will intersect, assuming they are not the
same plane

The intersection of two different planes is called a line.

So if this line intersects both quads, then both quads intersect each other

You MUST purchase a geometry book if you wish to move forward on your
own although many software will do the work for youOn Sun, Jun 27, 2010 at 10:43 AM, Jesse Palser wrote:

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