Jump to content
  • Advertisement
Sign in to follow this  
snufkin

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!