Question about max distance for rendering objects

HI all.

By setting the max distance for camera the result is, from that point to farther nothing is rendered.

By the way, seems to me, object are drawn anyway, causing the system to carry that charge of work.



I've solved this by extending the Node class and, at the Draw method, making super.draw(…) only if distance from camera is less than a vaue.



Is there a native way i JMe to do that ?



Thanks in advice and sorry for my english, as usual, correction are wellcome.

Is there a native way i JMe to do that ?

No, and there is a good reason for that.

There are many steps for culling.

First, jme will parse the scenegraph, and for every object it encounters, the engine will compare the bounding volume of that object against all 6 frustum planes (including the far plane). If the bounding volume of the object is outside the view volume, then it is discarded. If the object was a node which has other objects inside, then all those objects are discarded as well, making culling very efficient.

Second, when OpenGL is told to draw geometry data, it will compare every polygon against the view volume and discard everything that will not be seen. Also OpenGL will cut polygons that are seen partially so only the visible part is drawn.

Simply checking the distance of the node against the far plane doesn't work, because:
1. The distance equation will form a section of a sphere, and that shape is different from the viewing volume - so you are discarding objects that would be seen otherwise.
2. The distance to the node is the distance to the center of the node. So  you are discarding objects that are inside the viewing volume. If the node is very large with many objects inside, you could be discarding objects right in front of the camera.

However, sometimes the distance culling can be useful. For example if you have many small objects and you don't mind them suddenly disappearing when they are far away, you could use the distance culling method.

What you are saying is that I need to give a bounding volume to objects to be culled ?



Actually, I need to see in the distance the skydome, for example, while trees in sceene must be culled in shortest distance.

With this system I can parametrize the max visible distance for every kind of objects ( trees, buildings, etc…).



So I guess I will carry on with this… t.a.l.

your sky does not have to be at a great distance from your eye… in fact, I often use a distance of 10 or so.  You just need it to draw behind everything else to make it look like it's far away.  This can be done through proper use of the ZBufferState.  (set it to not write to the buffer and have your sky draw first)