# OpenGL Calculating dynamic bounding box

This topic is 1115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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!

##### Share on other sites
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.

##### Share on other sites

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.

Edited by vstrakh

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013596
×