Testing if an AABB is within the view frustrum?

help

#1

Hello all, I’m a n00b to this family of libraries so forgive me if this is asked and answered somewhere.

In a project, I need to be able to check if a given axis-aligned bounding box is visible. To this end, I have two questions:

  • How do I construct a view frustrum? I can provide a projection matrix or the relevant parameters of a perspective.
  • How do I get the relation between a frustrum and an AABB? By “relation”, I mean one of “Inside”, “Crossing”, or “Outside”.

To do this today, I’m using the collision crate because it had an obvious API. However, I’m soon going to need some of the features provided by the n* crates, so I’d like to switch over to that.

Thanks in advance,
Ulysse


#2

ncollide does not define any geometric shape dedicated to frustrums. One option is to define your frustrum as a convex polyhedra, i.e., you compute its eight vertices and use them to create a ConvexHull structure.

With that in hand, you can get the relation between a frustrum and an AABB by representing the AABB with a cuboid (you can’t use the AABB structure because intersection test between a bounding volume and a geometrical shape usually don’t make sense in practice). Then you can test if your frustrum and your cuboid intersect with a proximity test.

Note however that this proximity test will only tells you if they are separated or intersecting, i.e., no distinction between “crossing” and “outside” is done.


#3

Thanks for your reply, @sebcrozet! Your provided links and explanation are elucidating.

I think I’m going to stick with the collision crate for this particular problem, and use ncollide where it makes the most sense.