Java Code Examples for com.jme3.renderer.Camera#getFrustumNear()
The following examples show how to use
com.jme3.renderer.Camera#getFrustumNear() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShadowUtil.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Updates a points arrays with the frustum corners of the provided camera. * @param viewCam * @param points */ public static void updateFrustumPoints2(Camera viewCam, Vector3f[] points) { int w = viewCam.getWidth(); int h = viewCam.getHeight(); float n = viewCam.getFrustumNear(); float f = viewCam.getFrustumFar(); points[0].set(viewCam.getWorldCoordinates(new Vector2f(0, 0), n)); points[1].set(viewCam.getWorldCoordinates(new Vector2f(0, h), n)); points[2].set(viewCam.getWorldCoordinates(new Vector2f(w, h), n)); points[3].set(viewCam.getWorldCoordinates(new Vector2f(w, 0), n)); points[4].set(viewCam.getWorldCoordinates(new Vector2f(0, 0), f)); points[5].set(viewCam.getWorldCoordinates(new Vector2f(0, h), f)); points[6].set(viewCam.getWorldCoordinates(new Vector2f(w, h), f)); points[7].set(viewCam.getWorldCoordinates(new Vector2f(w, 0), f)); }
Example 2
Source File: PerspectiveLodCalculator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * This computes the "C" value in the geomipmapping paper. * See section "2.3.1.2 Pre-calculating d" * * @param cam * @param pixelLimit * @return */ private float getCameraConstant(Camera cam, float pixelLimit){ float n = cam.getFrustumNear(); float t = FastMath.abs(cam.getFrustumTop()); float A = n / t; float v_res = cam.getHeight(); float T = (2f * pixelLimit) / v_res; return A / T; }
Example 3
Source File: UniformBindingManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void setCamera(Camera cam, Matrix4f viewMatrix, Matrix4f projMatrix, Matrix4f viewProjMatrix) { this.viewMatrix.set(viewMatrix); this.projMatrix.set(projMatrix); this.viewProjMatrix.set(viewProjMatrix); camLoc.set(cam.getLocation()); cam.getLeft(camLeft); cam.getUp(camUp); cam.getDirection(camDir); near = cam.getFrustumNear(); far = cam.getFrustumFar(); }
Example 4
Source File: PerspectiveLodCalculator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * This computes the "C" value in the geomipmapping paper. * See section "2.3.1.2 Pre-calculating d" * * @param cam * @param pixelLimit * @return */ private float getCameraConstant(Camera cam, float pixelLimit){ float n = cam.getFrustumNear(); float t = FastMath.abs(cam.getFrustumTop()); float A = n / t; float v_res = cam.getHeight(); float T = (2f * pixelLimit) / v_res; return A / T; }
Example 5
Source File: LWJGLOpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void setupCamerasAndViews() { if (environment != null) { // get desired frustum from original camera Camera origCam = environment.getCamera(); float fFar = origCam.getFrustumFar(); float fNear = origCam.getFrustumNear(); // restore frustum on distortion scene cam, if needed if (environment.isInstanceRendering()) { leftCamera = origCam; } else if (environment.compositorAllowed() == false) { origCam.setFrustumFar(100f); origCam.setFrustumNear(1f); leftCamera = origCam.clone(); prepareCameraSize(origCam, 2f); } else { leftCamera = origCam.clone(); } getLeftCamera().setFrustumPerspective(environment.getDefaultFOV(), environment.getDefaultAspect(), fNear, fFar); prepareCameraSize(getLeftCamera(), 1f); if (environment.getVRHardware() != null) { getLeftCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionLeftEye(getLeftCamera())); } //org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_FRAMEBUFFER_SRGB); if (!environment.isInstanceRendering()) { leftViewPort = setupViewBuffers(getLeftCamera(), LEFT_VIEW_NAME); rightCamera = getLeftCamera().clone(); if (environment.getVRHardware() != null) { getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera())); } rightViewPort = setupViewBuffers(getRightCamera(), RIGHT_VIEW_NAME); } else { if (environment.getApplication() != null) { logger.severe("THIS CODE NEED CHANGES !!!"); leftViewPort = environment.getApplication().getViewPort(); //leftViewport.attachScene(app.getRootNode()); rightCamera = getLeftCamera().clone(); if (environment.getVRHardware() != null) { getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera())); } org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_CLIP_DISTANCE0); //FIXME: [jme-vr] Fix with JMonkey next release //RenderManager._VRInstancing_RightCamProjection = camRight.getViewProjectionMatrix(); setupFinalFullTexture(environment.getApplication().getViewPort().getCamera()); } else { throw new IllegalStateException("This VR environment is not attached to any application."); } } // setup gui environment.getVRGUIManager().setupGui(getLeftCamera(), getRightCamera(), getLeftViewPort(), getRightViewPort()); if (environment.getVRHardware() != null) { // call these to cache the results internally environment.getVRHardware().getHMDMatrixPoseLeftEye(); environment.getVRHardware().getHMDMatrixPoseRightEye(); } } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
Example 6
Source File: OpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void setupCamerasAndViews() { if (environment != null){ // get desired frustum from original camera Camera origCam = environment.getCamera(); float fFar = origCam.getFrustumFar(); float fNear = origCam.getFrustumNear(); // restore frustum on distortion scene cam, if needed if( environment.isInstanceRendering() ) { leftCamera = origCam; } else if( environment.compositorAllowed() == false ) { origCam.setFrustumFar(100f); origCam.setFrustumNear(1f); leftCamera = origCam.clone(); prepareCameraSize(origCam, 2f); } else { leftCamera = origCam.clone(); } getLeftCamera().setFrustumPerspective(environment.getDefaultFOV(), environment.getDefaultAspect(), fNear, fFar); prepareCameraSize(getLeftCamera(), 1f); if( environment.getVRHardware() != null ) { getLeftCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionLeftEye(getLeftCamera())); } //org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_FRAMEBUFFER_SRGB); if( !environment.isInstanceRendering()) { leftViewPort = setupViewBuffers(getLeftCamera(), LEFT_VIEW_NAME); rightCamera = getLeftCamera().clone(); if( environment.getVRHardware() != null ){ getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera())); } rightViewPort = setupViewBuffers(getRightCamera(), RIGHT_VIEW_NAME); } else { if (environment.getApplication() != null){ logger.severe("THIS CODE NEED CHANGES !!!"); leftViewPort = environment.getApplication().getViewPort(); //leftViewport.attachScene(app.getRootNode()); rightCamera = getLeftCamera().clone(); if( environment.getVRHardware() != null ){ getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera())); } org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_CLIP_DISTANCE0); //FIXME: [jme-vr] Fix with JMonkey next release //RenderManager._VRInstancing_RightCamProjection = camRight.getViewProjectionMatrix(); setupFinalFullTexture(environment.getApplication().getViewPort().getCamera()); } else { throw new IllegalStateException("This VR environment is not attached to any application."); } } // setup gui environment.getVRGUIManager().setupGui(getLeftCamera(), getRightCamera(), getLeftViewPort(), getRightViewPort()); if( environment.getVRHardware() != null ) { // call these to cache the results internally environment.getVRHardware().getHMDMatrixPoseLeftEye(); environment.getVRHardware().getHMDMatrixPoseRightEye(); } } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
Example 7
Source File: OculusViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Set up the cameras and views for each eye and the mirror display. */ private void setupCamerasAndViews() { // TODO: Use LobOVR IPD etc if (environment != null) { // get desired frustum from original camera Camera origCam = environment.getCamera(); float fFar = origCam.getFrustumFar(); float fNear = origCam.getFrustumNear(); // restore frustum on distortion scene cam, if needed if (environment.isInstanceRendering()) { leftCamera = origCam; } else { leftCamera = origCam.clone(); } OVRFovPort fp = hardware.getFovPort(); float hFov = fp.LeftTan() + fp.RightTan(); float vFov = fp.UpTan() + fp.DownTan(); getLeftCamera().setFrustumPerspective(hFov / FastMath.TWO_PI * 360, vFov / hFov, fNear, fFar); prepareCameraSize(getLeftCamera(), 1f); if (environment.getVRHardware() != null) { getLeftCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionLeftEye(getLeftCamera())); } //org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_FRAMEBUFFER_SRGB); if (!environment.isInstanceRendering()) { leftViewPort = setupViewBuffers(getLeftCamera(), LEFT_VIEW_NAME); rightCamera = getLeftCamera().clone(); if (environment.getVRHardware() != null) { getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera())); } rightViewPort = setupViewBuffers(getRightCamera(), RIGHT_VIEW_NAME); } else if (environment.getApplication() != null) { throw new UnsupportedOperationException("Not yet implemented!"); } else { throw new IllegalStateException("This VR environment is not attached to any application."); } // setup gui environment.getVRGUIManager().setupGui(getLeftCamera(), getRightCamera(), getLeftViewPort(), getRightViewPort()); } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
Example 8
Source File: OSVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void setupCamerasAndViews() { if (environment != null){ if (environment.getApplication() != null){ // get desired frustum from original camera Camera origCam = environment.getCamera(); float fFar = origCam.getFrustumFar(); float fNear = origCam.getFrustumNear(); // if we are using OSVR get the eye info here if( environment.getVRHardware() instanceof OSVR ) { ((OSVR)environment.getVRHardware()).getEyeInfo(); } // restore frustum on distortion scene cam, if needed if( environment.isInstanceRendering() ) { leftCamera = origCam; } else if( environment.compositorAllowed() == false ) { origCam.setFrustumFar(100f); origCam.setFrustumNear(1f); leftCamera = origCam.clone(); prepareCameraSize(origCam, 2f); } else { leftCamera = origCam.clone(); } leftCamera.setFrustumPerspective(environment.getDefaultFOV(), environment.getDefaultAspect(), fNear, fFar); prepareCameraSize(leftCamera, 1f); if( environment.getVRHardware() != null ) leftCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionLeftEye(leftCamera)); //org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_FRAMEBUFFER_SRGB); if( !environment.isInstanceRendering()) { leftViewPort = setupViewBuffers(leftCamera, LEFT_VIEW_NAME); rightCamera = leftCamera.clone(); if( environment.getVRHardware() != null ){ rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera)); } rightViewPort = setupViewBuffers(rightCamera, RIGHT_VIEW_NAME); } else { System.err.println("[VRViewManager] THIS CODE NEED CHANGES !!!"); leftViewPort = environment.getApplication().getViewPort(); //leftViewport.attachScene(app.getRootNode()); rightCamera = leftCamera.clone(); if( environment.getVRHardware() != null ){ rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera)); } org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_CLIP_DISTANCE0); //FIXME: [jme-vr] Fix with JMonkey next release //RenderManager._VRInstancing_RightCamProjection = camRight.getViewProjectionMatrix(); setupFinalFullTexture(environment.getApplication().getViewPort().getCamera()); } // setup gui environment.getVRGUIManager().setupGui(leftCamera, rightCamera, getLeftViewPort(), getRightViewPort()); if( environment.getVRHardware() != null ) { // call these to cache the results internally environment.getVRHardware().getHMDMatrixPoseLeftEye(); environment.getVRHardware().getHMDMatrixPoseRightEye(); } } else { throw new IllegalStateException("This VR environment is not attached to any application."); } } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
Example 9
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Updates the points array to contain the frustum corners of the given * camera. The nearOverride and farOverride variables can be used to * override the camera's near/far values with own values. * * TODO: Reduce creation of new vectors * * @param viewCam * @param nearOverride * @param farOverride */ public static void updateFrustumPoints(Camera viewCam, float nearOverride, float farOverride, float scale, Vector3f[] points) { Vector3f pos = viewCam.getLocation(); Vector3f dir = viewCam.getDirection(); Vector3f up = viewCam.getUp(); float depthHeightRatio = viewCam.getFrustumTop() / viewCam.getFrustumNear(); float near = nearOverride; float far = farOverride; float ftop = viewCam.getFrustumTop(); float fright = viewCam.getFrustumRight(); float ratio = fright / ftop; float near_height; float near_width; float far_height; float far_width; if (viewCam.isParallelProjection()) { near_height = ftop; near_width = near_height * ratio; far_height = ftop; far_width = far_height * ratio; } else { near_height = depthHeightRatio * near; near_width = near_height * ratio; far_height = depthHeightRatio * far; far_width = far_height * ratio; } Vector3f right = dir.cross(up).normalizeLocal(); Vector3f temp = new Vector3f(); temp.set(dir).multLocal(far).addLocal(pos); Vector3f farCenter = temp.clone(); temp.set(dir).multLocal(near).addLocal(pos); Vector3f nearCenter = temp.clone(); Vector3f nearUp = temp.set(up).multLocal(near_height).clone(); Vector3f farUp = temp.set(up).multLocal(far_height).clone(); Vector3f nearRight = temp.set(right).multLocal(near_width).clone(); Vector3f farRight = temp.set(right).multLocal(far_width).clone(); points[0].set(nearCenter).subtractLocal(nearUp).subtractLocal(nearRight); points[1].set(nearCenter).addLocal(nearUp).subtractLocal(nearRight); points[2].set(nearCenter).addLocal(nearUp).addLocal(nearRight); points[3].set(nearCenter).subtractLocal(nearUp).addLocal(nearRight); points[4].set(farCenter).subtractLocal(farUp).subtractLocal(farRight); points[5].set(farCenter).addLocal(farUp).subtractLocal(farRight); points[6].set(farCenter).addLocal(farUp).addLocal(farRight); points[7].set(farCenter).subtractLocal(farUp).addLocal(farRight); if (scale != 1.0f) { // find center of frustum Vector3f center = new Vector3f(); for (int i = 0; i < 8; i++) { center.addLocal(points[i]); } center.divideLocal(8f); Vector3f cDir = new Vector3f(); for (int i = 0; i < 8; i++) { cDir.set(points[i]).subtractLocal(center); cDir.multLocal(scale - 1.0f); points[i].addLocal(cDir); } } }
Example 10
Source File: ShadowUtil.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Updates the points array to contain the frustum corners of the given * camera. The nearOverride and farOverride variables can be used * to override the camera's near/far values with own values. * * TODO: Reduce creation of new vectors * * @param viewCam * @param nearOverride * @param farOverride */ public static void updateFrustumPoints(Camera viewCam, float nearOverride, float farOverride, float scale, Vector3f[] points) { Vector3f pos = viewCam.getLocation(); Vector3f dir = viewCam.getDirection(); Vector3f up = viewCam.getUp(); float depthHeightRatio = viewCam.getFrustumTop() / viewCam.getFrustumNear(); float near = nearOverride; float far = farOverride; float ftop = viewCam.getFrustumTop(); float fright = viewCam.getFrustumRight(); float ratio = fright / ftop; float near_height; float near_width; float far_height; float far_width; if (viewCam.isParallelProjection()) { near_height = ftop; near_width = near_height * ratio; far_height = ftop; far_width = far_height * ratio; } else { near_height = depthHeightRatio * near; near_width = near_height * ratio; far_height = depthHeightRatio * far; far_width = far_height * ratio; } Vector3f right = dir.cross(up).normalizeLocal(); Vector3f temp = new Vector3f(); temp.set(dir).multLocal(far).addLocal(pos); Vector3f farCenter = temp.clone(); temp.set(dir).multLocal(near).addLocal(pos); Vector3f nearCenter = temp.clone(); Vector3f nearUp = temp.set(up).multLocal(near_height).clone(); Vector3f farUp = temp.set(up).multLocal(far_height).clone(); Vector3f nearRight = temp.set(right).multLocal(near_width).clone(); Vector3f farRight = temp.set(right).multLocal(far_width).clone(); points[0].set(nearCenter).subtractLocal(nearUp).subtractLocal(nearRight); points[1].set(nearCenter).addLocal(nearUp).subtractLocal(nearRight); points[2].set(nearCenter).addLocal(nearUp).addLocal(nearRight); points[3].set(nearCenter).subtractLocal(nearUp).addLocal(nearRight); points[4].set(farCenter).subtractLocal(farUp).subtractLocal(farRight); points[5].set(farCenter).addLocal(farUp).subtractLocal(farRight); points[6].set(farCenter).addLocal(farUp).addLocal(farRight); points[7].set(farCenter).subtractLocal(farUp).addLocal(farRight); if (scale != 1.0f) { // find center of frustum Vector3f center = new Vector3f(); for (int i = 0; i < 8; i++) { center.addLocal(points[i]); } center.divideLocal(8f); Vector3f cDir = new Vector3f(); for (int i = 0; i < 8; i++) { cDir.set(points[i]).subtractLocal(center); cDir.multLocal(scale - 1.0f); points[i].addLocal(cDir); } } }