@Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
        float newDistance;
        int level;
        BoundingVolume bv = spatial.getWorldBound();
        Camera cam = vp.getCamera();
        float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop());
        float ratio = (FastMath.PI / (8f * atanNH));
        newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio;


        if (Math.abs(newDistance - prevDistance) <= distanceThreshold) {
            level = prevLevel; // we haven't moved relative to the model, send the old measurement back.
        } else if (prevDistance > newDistance && prevLevel == 0) {
            level = prevLevel; // we're already at the lowest setting and we just got closer to the model, no need to keep trying.
        } else if (prevDistance < newDistance && prevLevel == numLevels - 1) {
            level = prevLevel; // we're already at the highest setting and we just got further from the model, no need to keep trying.
        } else {
            prevDistance = newDistance;
            // estimate area of polygon via bounding volume
            float area = AreaUtils.calcScreenArea(bv, prevDistance, cam.getWidth());
            float trisToDraw = area * trianglesPerPixel;
            level = numLevels - 1;
            for (int i = numLevels; --i >= 0;) {
                if (trisToDraw - numTris[i] < 0) {
                    break;
                }
                level = i;
            }
        }

        if(prevLevel!=level){
            System.out.println("This is the Level Of Detail control, currently drawing " + cylinders[level].getTriangleCount() +" triangles on the " + name);
        }

        prevLevel = level;
        ((Geometry) spatial).setMesh(cylinders[level]);
    }