Java Code Examples for com.jme3.renderer.Camera#getFrustumFar()

The following examples show how to use com.jme3.renderer.Camera#getFrustumFar() . 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: SpotLightShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void updateShadowCams(Camera viewCam) {

    if (light == null) {
        logger.warning("The light can't be null for a " + getClass().getName());
        return;
    }

    float zFar = zFarOverride;
    if (zFar == 0) {
        zFar = viewCam.getFrustumFar();
    }

    //We prevent computing the frustum points and splits with zeroed or negative near clip value
    float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f);
    ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points);
    //shadowCam.setDirection(direction);

    shadowCam.setFrustumPerspective(light.getSpotOuterAngle() * FastMath.RAD_TO_DEG * 2.0f, 1, 1f, light.getSpotRange());
    shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp());
    shadowCam.setLocation(light.getPosition());

    shadowCam.update();
    shadowCam.updateViewProjection();
}
 
Example 2
Source File: ShadowUtil.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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 3
Source File: DirectionalLightShadowRendererVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void updateShadowCams(Camera viewCam) {

    float zFar = zFarOverride;
    if (zFar == 0) {
        zFar = viewCam.getFrustumFar();
    }

    //We prevent computing the frustum points and splits with zeroed or negative near clip value
    float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f);
    ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points);

    //shadowCam.setDirection(direction);
    shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp());
    shadowCam.update();
    shadowCam.updateViewProjection();

    PssmShadowUtil.updateFrustumSplits(splitsArray, frustumNear, zFar, lambda);

    // in parallel projection shadow position goe from 0 to 1
    if(viewCam.isParallelProjection()){
        for (int i = 0; i < nbShadowMaps; i++) {
            splitsArray[i] = splitsArray[i]/(zFar- frustumNear);
        }
    }

    switch (splitsArray.length) {
        case 5:
            splits.a = splitsArray[4];
        case 4:
            splits.b = splitsArray[3];
        case 3:
            splits.g = splitsArray[2];
        case 2:
        case 1:
            splits.r = splitsArray[1];
            break;
    }

}
 
Example 4
Source File: UniformBindingManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 5
Source File: LWJGLOpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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 vote down vote up
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 vote down vote up
/**
 * 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 vote down vote up
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: DirectionalLightShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void updateShadowCams(Camera viewCam) {

    if (light == null) {
        logger.warning("The light can't be null for a " + getClass().getName());
        return;
    }

    float zFar = zFarOverride;
    if (zFar == 0) {
        zFar = viewCam.getFrustumFar();
    }

    //We prevent computing the frustum points and splits with zeroed or negative near clip value
    float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f);
    ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points);

    shadowCam.setFrustumFar(zFar);
    shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp());
    shadowCam.update();
    shadowCam.updateViewProjection();

    PssmShadowUtil.updateFrustumSplits(splitsArray, frustumNear, zFar, lambda);

    // in parallel projection shadow position goe from 0 to 1
    if(viewCam.isParallelProjection()){
        for (int i = 0; i < nbShadowMaps; i++) {
            splitsArray[i] = splitsArray[i]/(zFar- frustumNear);
        }
    }

    switch (splitsArray.length) {
        case 5:
            splits.a = splitsArray[4];
        case 4:
            splits.b = splitsArray[3];
        case 3:
            splits.g = splitsArray[2];
        case 2:
        case 1:
            splits.r = splitsArray[1];
            break;
    }

}