This may have been answered before, and if so, point me to the answer. Otherwise, here goes.
You have x number of objects in space, which have bounding coordinates p0 and p1. p0 and p1 are each 3 dimensional coordinates and p0 always has the lower values – whether negative or positive, and p1 always has the higher values.
Now, you have a plane, which is perfectly orthogonal to the direction of camera C, which has a position (pC) and a heading (hC). This plane can then be defined as being 90 degrees (pi/2 radians) from the camera’s yaw (sometimes called ‘heading’) and pitch and extending unto the furthest defined bounds in the space.
Because I do not permit more than 180 degrees FOV, anything which lies completely behind the camera (behind the plane of exclusion) must be excluded.
Is there a simple way to do this? For this question, I do not treat the issue of having to check against every object in the space; assume for the purpose of our question that there are always a limited number of objects – managed by partitioning the space in some fashion – so that the objects we check against are always ‘questionable’.
Also keep in mind that because these are not points but pairs of points representing 3d bounding cubes, it is not enough for a point to lie on this or that side of the plane.
I get the feeling there is a simple way to do this, but not having taken Computer Graphics I was never introduced to the math.
So here’s how to do it.
First you need to store the eight points in each bounding box in a predictable manner, for instance, each bit in an integer representing its position about the center of the box. What you can do is use 0x4 to represent EAST (+x) (zero in that bit means WEST) 0x2 to represent NORTH (zero in that bit means SOUTH) and 0x1 to represent TOP (zero in that bit means BOTTOM). Now you can universally access all points in the same position of the bounding box by specifying a position number. (all zero bit numbers are just zero. Java warns that these assignments are meaningless, but they help with readability.)
Setting up the bounding box: (do this for every bounding box)
Next, calculate the normal from your view angle. (Yaw is left/right rotation, pitch is up/down rotation)
I think the negative is right, but if everything is invisible on one side, just reverse it 🙂
Calculate the Characteristic Point, which is just the index that you’re going to check in every bounding box because it represents the point in every box that will be nearest to the plane on the invisible side:
Make sure that every bounding box is set up such that x,y,z aught are lesser than x,y,z prime (x0 = x aught, x1 = x prime)
Then collect your characteristic (‘check’) point, your set of normals (‘frustrum’), and your camera position (x,y,z) and do this with every bounding box:
This is simple linear algebra (IMO) and the logic is as follows: If the point is on the positive side of two or more of the lines representing the plane, it is visible. If it is on the negative side of tow or more of the lines representing the plane, it is invisible. You calculate the first two, and if they are different (one negative, one positive) you check the third and take that value.
It is important to note the following property when treating lines as equations:
The line is the same, but its implicit ‘facing’ is inverse.
I hope this helps someone else with this question. It was hard, but enjoyable, to figure out.
This could be made more efficient by storing the first half of CheckA, I suppose 🙂