Calculating dynamic bounding box

Started by
1 comment, last by vstrakh 8 years, 4 months ago
Hello! I'm writing a game for Android using OpenGL ES 3.0, but can't figure out how to calculate a proper bounding box for my objects. The "main menu" consists of a couple of three-dimensional cubes. To find out what cube the user presses, I calculate a ray and check if any of the cubes intersect the ray using their bounding box (a sphere, represented by the cubes' positions and radiuses). However, now I want to switch from cubes to three-dimensional rectangles. Since I can't use a sphere to properly represent the rectangle, I need a new way to calculate the intersection of the ray and the (potential) rectangle. To add to my problem even more, the rectangles are rotating, making the width varying, so I can't use a static bounding box either. What I'm thinking of doing is transforming the vertices on the CPU every time the user touches the screen. Then when I have the same vertices as OpenGL is drawing, I calculate the triangles and their corresponding normals and test each and every triangle to see if anyone intersects the ray. Am I thinking properly, or is there an even simpler solution? I know that this intersection testing is heavy on the resources, but since I only have three rectangles on screen at the same time, I just have to check 36 triangles whenever the user touches the screen. Thanks!
Advertisement
PS. Sorry for the unformatted text. When I posted this thread the newlines were there, but when I posted the it they disappear. I'm unable to edit my post too.

or is there an even simpler solution?

There is. Instead of transforming cube verts and testing agains triangles, test against convex hull. Cube is already convex, and getting its planes is trivial. If you have more complex shapes, you can calculate its convex hulls offline (maybe apply some decimation too) and load along with meshes.


the rectangles are rotating, making the width varying, so I can't use a static bounding box either

Transform picking ray with inverse matrix of object's trasformation, then test new ray against untransformed cube/hull as before.

This topic is closed to new replies.

Advertisement