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