protected void controlRender(RenderManager rm, ViewPort vp) { BoundingVolume bv = spatial.getWorldBound(); Camera cam = vp.getCamera(); float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop()); float ratio = (FastMath.PI / (8f * atanNH)); float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio; int level; if (Math.abs(newDistance - lastDistance) <= distTolerance) { level = lastLevel; // we haven't moved relative to the model, send the old measurement back. } else if (lastDistance > newDistance && lastLevel == 0) { level = lastLevel; // we're already at the lowest setting and we just got closer to the model, no need to keep trying. } else if (lastDistance < newDistance && lastLevel == numLevels - 1) { level = lastLevel; // we're already at the highest setting and we just got further from the model, no need to keep trying. } else { lastDistance = newDistance; // estimate area of polygon via bounding volume float area = AreaUtils.calcScreenArea(bv, lastDistance, cam.getWidth()); float trisToDraw = area * trisPerPixel; level = numLevels - 1; for (int i = numLevels; --i >= 0;) { if (trisToDraw - numTris[i] < 0) { break; } level = i; } lastLevel = level; } spatial.setLodLevel(level); }
protected float getMinZ( BoundingVolume bv ) { if( bv instanceof BoundingBox ) { BoundingBox bb = (BoundingBox)bv; return bb.getCenter().z - bb.getZExtent(); } else if( bv instanceof BoundingSphere ) { BoundingSphere bs = (BoundingSphere)bv; return bs.getCenter().z - bs.getRadius(); } Vector3f offset = bv.getCenter().add(0, 0, -1000); return offset.z + bv.distanceTo(offset); // untested }
protected float getMaxZ( BoundingVolume bv ) { if( bv instanceof BoundingBox ) { BoundingBox bb = (BoundingBox)bv; return bb.getCenter().z + bb.getZExtent(); } else if( bv instanceof BoundingSphere ) { BoundingSphere bs = (BoundingSphere)bv; return bs.getCenter().z + bs.getRadius(); } else if( bv == null ) { // Apparently this can happen for empty nodes... return 0; } Vector3f offset = bv.getCenter().add(0, 0, 1000); return offset.z - bv.distanceTo(offset); }
protected void controlRender(RenderManager rm, ViewPort vp) { BoundingVolume bv = spatial.getWorldBound(); Camera cam = vp.getCamera(); float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop()); float ratio = (FastMath.PI / (8f * atanNH)); float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio; int level; if (Math.abs(newDistance - lastDistance) <= distTolerance) { level = lastLevel; // we haven't moved relative to the model, send the old measurement back. } else if (lastDistance > newDistance && lastLevel == 0) { level = lastLevel; // we're already at the lowest setting and we just got closer to the model, no need to keep trying. } else if (lastDistance < newDistance && lastLevel == numLevels - 1) { level = lastLevel; // we're already at the highest setting and we just got further from the model, no need to keep trying. } else { lastDistance = newDistance; // estimate area of polygon via bounding volume float area = AreaUtils.calcScreenArea(bv, lastDistance, cam.getWidth()); float trisToDraw = area * trisPerPixel; level = numLevels - 1; for (int i = numLevels; --i >= 0;) { if (trisToDraw - numTris[i] < 0) { break; } level = i; } lastLevel = level; } spatial.setLodLevel(level); }
protected void controlRender(RenderManager rm, ViewPort vp){ BoundingVolume bv = spatial.getWorldBound(); Camera cam = vp.getCamera(); float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop()); float ratio = (FastMath.PI / (8f * atanNH)); float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio; int level; if (Math.abs(newDistance - lastDistance) <= distTolerance) level = lastLevel; // we haven't moved relative to the model, send the old measurement back. else if (lastDistance > newDistance && lastLevel == 0) level = lastLevel; // we're already at the lowest setting and we just got closer to the model, no need to keep trying. else if (lastDistance < newDistance && lastLevel == numLevels - 1) level = lastLevel; // we're already at the highest setting and we just got further from the model, no need to keep trying. else{ lastDistance = newDistance; // estimate area of polygon via bounding volume float area = AreaUtils.calcScreenArea(bv, lastDistance, cam.getWidth()); float trisToDraw = area * trisPerPixel; level = numLevels - 1; for (int i = numLevels; --i >= 0;){ if (trisToDraw - numTris[i] < 0){ break; } level = i; } lastLevel = level; } spatial.setLodLevel(level); }