/** * Converts a point from Cartesian coordinates (using positive Z as up) to * Spherical and stores the results in the store var. (Radius, Azimuth, * Polar) */ public static Vector3f cartesianZToSpherical(Vector3f cartCoords, Vector3f store) { if (store == null) { store = new Vector3f(); } float x = cartCoords.x; if (x == 0) { x = FastMath.FLT_EPSILON; } store.x = FastMath.sqrt((x * x) + (cartCoords.y * cartCoords.y) + (cartCoords.z * cartCoords.z)); store.z = FastMath.atan(cartCoords.z / x); if (x < 0) { store.z += FastMath.PI; } store.y = FastMath.asin(cartCoords.y / store.x); return store; }
/** * Converts a point from Cartesian coordinates (using positive Y as up) to * Spherical and stores the results in the store var. (Radius, Azimuth, * Polar) */ public static Vector3f cartesianToSpherical(Vector3f cartCoords, Vector3f store) { if (store == null) { store = new Vector3f(); } float x = cartCoords.x; if (x == 0) { x = FastMath.FLT_EPSILON; } store.x = FastMath.sqrt((x * x) + (cartCoords.y * cartCoords.y) + (cartCoords.z * cartCoords.z)); store.y = FastMath.atan(cartCoords.z / x); if (x < 0) { store.y += FastMath.PI; } store.z = FastMath.asin(cartCoords.y / store.x); return store; }
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); }
/** * Zoom the camera by the specified amount. * * @param value zoom amount */ protected void zoomCamera(float value){ // derive fovY value float h = cam.getFrustumTop(); float w = cam.getFrustumRight(); float aspect = w / h; float near = cam.getFrustumNear(); float fovY = FastMath.atan(h / near) / (FastMath.DEG_TO_RAD * .5f); float newFovY = fovY + value * 0.1f * zoomSpeed; if (newFovY > 0f) { // Don't let the FOV go zero or negative. fovY = newFovY; } h = FastMath.tan( fovY * FastMath.DEG_TO_RAD * .5f) * near; w = h * aspect; cam.setFrustumTop(h); cam.setFrustumBottom(-h); cam.setFrustumLeft(-w); cam.setFrustumRight(w); }
/** * Converts a point from Cartesian coordinates (using positive Y as up) to * Spherical and stores the results in the store var. (Radius, Azimuth, * Polar) */ public static Vector3f cartesianToSpherical(Vector3f cartCoords, Vector3f store) { if (store == null) { store = new Vector3f(); } float x = cartCoords.x; if (x == 0) { x = FastMath.FLT_EPSILON; } store.x = FastMath.sqrt((x * x) + (cartCoords.y * cartCoords.y) + (cartCoords.z * cartCoords.z)); store.y = FastMath.atan(cartCoords.z / x); if (x < 0) { store.y += FastMath.PI; } store.z = FastMath.asin(cartCoords.y / store.x); return store; }
/** * Converts a point from Cartesian coordinates (using positive Y as up) to * Spherical and stores the results in the store var. (Radius, Azimuth, * Polar) */ public static Vector3f cartesianToSpherical(Vector3f cartCoords, Vector3f store) { if (store == null) { store = new Vector3f(); } float x = cartCoords.x; if (x == 0) { x = FastMath.FLT_EPSILON; } store.x = FastMath.sqrt((x * x) + (cartCoords.y * cartCoords.y) + (cartCoords.z * cartCoords.z)); store.y = FastMath.atan(cartCoords.z / x); if (x < 0) { store.y += FastMath.PI; } store.z = FastMath.asin(cartCoords.y / store.x); return store; }
/** * Converts a point from Cartesian coordinates (using positive Z as up) to * Spherical and stores the results in the store var. (Radius, Azimuth, * Polar) */ public static Vector3f cartesianZToSpherical(Vector3f cartCoords, Vector3f store) { if (store == null) { store = new Vector3f(); } float x = cartCoords.x; if (x == 0) { x = FastMath.FLT_EPSILON; } store.x = FastMath.sqrt((x * x) + (cartCoords.y * cartCoords.y) + (cartCoords.z * cartCoords.z)); store.z = FastMath.atan(cartCoords.z / x); if (x < 0) { store.z += FastMath.PI; } store.y = FastMath.asin(cartCoords.y / store.x); return store; }
/** * Converts a point from Cartesian coordinates (using positive Z as up) to * Spherical and stores the results in the store var. (Radius, Azimuth, * Polar) */ public static Vector3f cartesianZToSpherical(Vector3f cartCoords, Vector3f store) { if (store == null) { store = new Vector3f(); } float x = cartCoords.x; if (x == 0) { x = FastMath.FLT_EPSILON; } store.x = FastMath.sqrt((x * x) + (cartCoords.y * cartCoords.y) + (cartCoords.z * cartCoords.z)); store.z = FastMath.atan(cartCoords.z / x); if (x < 0) { store.z += FastMath.PI; } store.y = FastMath.asin(cartCoords.y / store.x); return store; }
protected void zoomCamera(float value){ // derive fovY value float h = cam.getFrustumTop(); float w = cam.getFrustumRight(); float aspect = w / h; float near = cam.getFrustumNear(); float fovY = FastMath.atan(h / near) / (FastMath.DEG_TO_RAD * .5f); fovY += value * 0.1f; h = FastMath.tan( fovY * FastMath.DEG_TO_RAD * .5f) * near; w = h * aspect; cam.setFrustumTop(h); cam.setFrustumBottom(-h); cam.setFrustumLeft(-w); cam.setFrustumRight(w); }
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); }
/** * Zoom the camera by the specified amount. * * @param value zoom amount */ protected void zoomCamera(float value){ // derive fovY value float h = cam.getFrustumTop(); float w = cam.getFrustumRight(); float aspect = w / h; float near = cam.getFrustumNear(); float fovY = FastMath.atan(h / near) / (FastMath.DEG_TO_RAD * .5f); float newFovY = fovY + value * 0.1f * zoomSpeed; if (newFovY > 0f) { // Don't let the FOV go zero or negative. fovY = newFovY; } h = FastMath.tan( fovY * FastMath.DEG_TO_RAD * .5f) * near; w = h * aspect; cam.setFrustumTop(h); cam.setFrustumBottom(-h); cam.setFrustumLeft(-w); cam.setFrustumRight(w); }