开发者

Check if object is visible

开发者 https://www.devze.com 2023-01-10 13:36 出处:网络
How would I che开发者_开发技巧ck if an object drawn in openGL-ES is visible?You don\'t check IN OpenGL if an object is visible.

How would I che开发者_开发技巧ck if an object drawn in openGL-ES is visible?


You don't check IN OpenGL if an object is visible.

You must have your own visibility/culling algorithms to do that. That means BSP Trees, Portals, Octree and others. Depending on the complexity of the world you can get away with an space partitioning based on an grid or something. It really depends on what you are doing.

Remember, OpenGL knowns only to Draw and to Cull.

You can do a loop on all objects in your world and tell GL to draw them all one by one. Each one will be process and discarded if not in view. Of course this is brute force and slow.

Hence the need for more encompassing algorithms for culling.

Why do you think Graphic Engines have all those million lines? :D


You could use a variant of picking. The idea of OpenGL picking is that you render a small area of the view, pushing names on a stack as you go (so you can refer what's being rendered). OpenGL will return a hit record so you know what's been rendered. It is often used to find out what's under the mouse.

So you'd do the following:

  • setup a small renderable surface (just to do visibility checks)

  • render your scene onto this renderable surface (replace your models by something simple, e.g. bounding boxes; note you don't need to render actual triangles, you could just render lines or dots instead)

  • check the hit record to see what's been rendered.

I haven't tried yet, but I think it would work; maybe not very fast, but reliable. Custom visibility/culling algorithms are typically used instead, although writing an efficient visibility/culling algorithm is difficult.

0

精彩评论

暂无评论...
验证码 换一张
取 消