LWJGL Forum

Programming => OpenGL => Topic started by: elias4444 on July 17, 2006, 19:04:01

Title: Quick method for determining if something is on screen?
Post by: elias4444 on July 17, 2006, 19:04:01
I'm working on optimizing my game, and was wondering if there was a quick/easy way to determine if an object is viewable on screen or not (to determine if it should be drawn or not). I know culling can determine if a face is forward facing or not, but is there another method for determining if something is within the viewport?
Title: Quick method for determining if something is on screen?
Post by: funsheep on July 18, 2006, 07:06:27
how about object-culling with
-(loose-)octrees
-bsp-trees
-scenegraphs
-just a list with all objects, making a frustum-culling-test against their boundingbox (the trees do the same, only with less tests)
?

regards
funsheep
Title: Quick method for determining if something is on screen?
Post by: elias4444 on July 18, 2006, 15:10:03
My main issue is just trying to come up with some sort of math that determines if something is "on-screen" or not. This isn't an orthographic game, so it gets a bit complicated. I'm at a loss as to how to determine it.  :(
Title: Quick method for determining if something is on screen?
Post by: funsheep on July 18, 2006, 17:11:35
regardless which type of rendering you use, you always have some sort of viewfrustrum. which can be a box, a frustrum of pyramid (in a usual 3D game), a 2D rectangle in a 2D game, etc. the type of your frustrum is determind by the projectionmatrix.

now you can use your frustrum culling it with the boundingbox of your objects (in 2D for example a 2D rectangle, in 3D a 3D box, or a 3D sphere).

if your frustrum intersects the boundingbox of the object, the object or a part of it is visible - "on screen".

look for some tutorials, how to compute the intersection of a frustrum and a box or whatever.

http://www.realtimerendering.com/int/ here you can find an overview over some intersection computations and where they are listed.
Title: hmmmmm...
Post by: Fool Running on July 18, 2006, 17:12:40
you need to do Frustum-culling (like funsheep said :D ) to determine if a 3D object is in the view frustum. You should be able to search Google to find examples on how to do this.

EDIT: Nevermind, Funsheep beat me :lol:
Title: Quick method for determining if something is on screen?
Post by: Rasengan on August 05, 2006, 00:53:08
Look @ here (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=44), he uses some functions that might interest you.