views:

103

answers:

2

Hey Guys,

I've created an openGL square like so..

            final float array1[] = new float[] {
            //Front face
            lx, ly, hz,
            lx, hy, hz,
            hx, ly, hz,
            hx, hy, hz
    };

I've also got a Ray. I'd now like to put bounding boxes around every square I draw so that I can check if they intersect. How would I go about doing this?

Thanks.

+1  A: 

OpenGL has no concept of bounding box, is just a mathematical concept related to collision detection.

So, basically, just create some box data structure, and store bounding boxes along your vertices (ideally in the same coordinate space), and do the collision check when necessary.

Matias Valdenegro
+2  A: 

You don't need to put bounding boxes around the squares. In fact, in the case of a square, the bounding box is the square.

A bounding box is simply a concept: a geometric shell within which some other (actual) geometry can conceptually exist. The idea is that it's much easier (and faster) to check against the 4 corners of a rectangle (for collision, etc.) than it is to check against each vertex of a complex polygonal object.

As for your particular problem of collision detection, you should simply project your ray onto the plane defined by each of your squares. If the point on the plane lies between all of your corners, then the ray hits the square.

TreDubZedd