--Alan---
.
In the case of intersection test of the bounding volumes, if one of
them has zero value (it is really means it has no boundary), compiler
returns Disjoint value. Quite logically. |
|
Not really. That's a runtime decision. The only time in which the compiler could optimise that test would be if X and Y were both hardcoded values. But if they're both hardcoded values, then theres no point in having the if(x && y) statement at all.
It's a runtime decision to decide if Y needs to be evaluted if X is false. Unless you provide specific optimisations for each individual class and for each individual method a compiler cannot tell that my boundingBox is of 0 volume. No compiler has those kinds of optimisations therefore no compiler can do that.
If you don't believe me, take the code. Decompile it and see for yourself that the compiler hasn't optimised away the test (mostly because it's impossible). Be warned that you probably shouldn't decompile MS libraries, so your best bet would be to write your own sample and decompile that.
It's not enough to test
whether there is a single plane that excludes all the vertices. A box
that's tilted just outside the corner of a frustum will then be
considered "inside" even when it's "outside." |
|
Can you provide a testcase for when the code in pastebin that i linked above will fail Thinking about it geometrically, a BoundingBox can only have one or more points outside of the frustum if there is also a corner of the BoundingBox outside of the frustum. There is no way that i can imagine rotating a BoundingBox so that one of its edges would be outside of the frustrum without one of it's corners also being outside of the frustum.
Therefore the implementation above (which is under the MIT/X11 license, so you can look at the code freely) is correct in that it checks each corner of the BoundingBox to see if that corner is inside the frustum.
Checking that a specific corner (Vector3) is inside the frustum is as easy as substituting into the equation:
ax + by + cy + d (equation of a plane) and verifying that the answer is negative when you substitute in your point for X, Y, Z. If point X,Y,Z lies on the negative side of all 6 bounding planes of the frustum, that point is without a doubt inside the frustum. The reason for choosing the negative side is because the normals are pointing outwards.
There should be no need to test the major axes. Unless i'm misunderstanding something (which wouldn't be new ;) ).
Thanks.