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

The following examples show how to use com.jme3.renderer.Camera#resize() . 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: OculusViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void prepareCameraSize(Camera cam, float xMult) {
    // TODO this function is identical to that in VRViewManagerOpenVR; merge the two.
    if (environment != null) {
        if (environment.getApplication() != null) {
            Vector2f size = new Vector2f();
            VRAPI vrhmd = environment.getVRHardware();

            if (vrhmd == null) {
                size.x = 1280f;
                size.y = 720f;
            } else {
                vrhmd.getRenderSize(size);
            }

            if (size.x < environment.getApplication().getContext().getSettings().getWidth()) {
                size.x = environment.getApplication().getContext().getSettings().getWidth();
            }
            if (size.y < environment.getApplication().getContext().getSettings().getHeight()) {
                size.y = environment.getApplication().getContext().getSettings().getHeight();
            }

            if (environment.isInstanceRendering()) {
                size.x *= 2f;
            }

            // other adjustments
            size.x *= xMult;
            size.x *= getResolutionMuliplier();
            size.y *= getResolutionMuliplier();

            if (cam.getWidth() != size.x || cam.getHeight() != size.y) {
                cam.resize((int) size.x, (int) size.y, false);
            }
        } 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 2
Source File: AWTFrameProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Reshape the current view port.
 *
 * @param width  the width.
 * @param height the height.
 */
protected void reshapeCurrentViewPort(int width, int height) {

	ViewPort viewPort = getViewPort();
	Camera camera = viewPort.getCamera();
	int cameraAngle = getCameraAngle();
	float aspect = (float) camera.getWidth() / camera.getHeight();

	if (isMain()) {
		getRenderManager().notifyReshape(width, height);
		camera.setFrustumPerspective(cameraAngle, aspect, 1f, 10000);
		return;
	}

	camera.resize(width, height, true);
	camera.setFrustumPerspective(cameraAngle, aspect, 1f, 10000);

	final List<SceneProcessor> processors = viewPort.getProcessors();

	boolean found = false;
	Iterator<SceneProcessor> iter = processors.iterator();
	while(!found && iter.hasNext()) {
		if (!(iter.next() instanceof AWTFrameProcessor)) {
			found = true;
		}
	}

	if (found) {

		FrameBuffer frameBuffer = new FrameBuffer(width, height, 1);
		frameBuffer.setDepthBuffer(Image.Format.Depth);
		frameBuffer.setColorBuffer(Image.Format.RGBA8);
		frameBuffer.setSrgb(true);

		viewPort.setOutputFrameBuffer(frameBuffer);
	}

	for (final SceneProcessor sceneProcessor : processors) {
		if (!sceneProcessor.isInitialized()) {
			sceneProcessor.initialize(renderManager, viewPort);
		} else {
			sceneProcessor.reshape(viewPort, width, height);
		}
	}
}
 
Example 3
Source File: LWJGLOpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Prepare the size of the given {@link Camera camera} to adapt it to the
 * underlying rendering context.
 *
 * @param cam the {@link Camera camera} to prepare.
 * @param xMult the camera width multiplier.
 */
private void prepareCameraSize(Camera cam, float xMult) {

    if (environment != null) {

        if (environment.getApplication() != null) {
            Vector2f size = new Vector2f();
            VRAPI vrhmd = environment.getVRHardware();

            if (vrhmd == null) {
                size.x = 1280f;
                size.y = 720f;
            } else {
                vrhmd.getRenderSize(size);
            }

            if (size.x < environment.getApplication().getContext().getSettings().getWidth()) {
                size.x = environment.getApplication().getContext().getSettings().getWidth();
            }
            if (size.y < environment.getApplication().getContext().getSettings().getHeight()) {
                size.y = environment.getApplication().getContext().getSettings().getHeight();
            }

            if (environment.isInstanceRendering()) {
                size.x *= 2f;
            }

            // other adjustments
            size.x *= xMult;
            size.x *= getResolutionMuliplier();
            size.y *= getResolutionMuliplier();

            if (cam.getWidth() != size.x || cam.getHeight() != size.y) {
                cam.resize((int) size.x, (int) size.y, false);
            }
        } 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 4
Source File: OpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Prepare the size of the given {@link Camera camera} to adapt it to the underlying rendering context.
 * @param cam the {@link Camera camera} to prepare.
 * @param xMult the camera width multiplier.
 */
private void prepareCameraSize(Camera cam, float xMult) {
	
	if (environment != null){
		
		if (environment.getApplication() != null){
			Vector2f size = new Vector2f();
	        VRAPI vrhmd = environment.getVRHardware();

	        if( vrhmd == null ) {
	            size.x = 1280f;
	            size.y = 720f;
	        } else {
	            vrhmd.getRenderSize(size);
	        }
	        
	        if( size.x < environment.getApplication().getContext().getSettings().getWidth() ) {
	            size.x = environment.getApplication().getContext().getSettings().getWidth();
	        }
	        if( size.y < environment.getApplication().getContext().getSettings().getHeight() ) {
	            size.y = environment.getApplication().getContext().getSettings().getHeight();
	        }
	        
	        if( environment.isInstanceRendering() ){
	        	size.x *= 2f;
	        }
	        
	        // other adjustments
	        size.x *= xMult;
	        size.x *= getResolutionMuliplier();
	        size.y *= getResolutionMuliplier();
	        
	        if( cam.getWidth() != size.x || cam.getHeight() != size.y ){
	        	cam.resize((int)size.x, (int)size.y, false);
	        }
		} 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 5
Source File: OSVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Prepare the size of the given {@link Camera camera} to adapt it to the underlying rendering context.
 * @param cam the {@link Camera camera} to prepare.
 * @param xMult the camera width multiplier.
 */
private void prepareCameraSize(Camera cam, float xMult) {
	
	if (environment != null){
		
		if (environment.getApplication() != null){
			
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
		
		Vector2f size = new Vector2f();
        VRAPI vrhmd = environment.getVRHardware();

        if( vrhmd == null ) {
            size.x = 1280f;
            size.y = 720f;
        } else {
            vrhmd.getRenderSize(size);
        }
        
        if( size.x < environment.getApplication().getContext().getSettings().getWidth() ) {
            size.x = environment.getApplication().getContext().getSettings().getWidth();
        }
        if( size.y < environment.getApplication().getContext().getSettings().getHeight() ) {
            size.y = environment.getApplication().getContext().getSettings().getHeight();
        }
        
        if( environment.isInstanceRendering() ){
        	size.x *= 2f;
        }
        
        // other adjustments
        size.x *= xMult;
        size.x *= getResolutionMuliplier();
        size.y *= getResolutionMuliplier();
        
        if( cam.getWidth() != size.x || cam.getHeight() != size.y ){
        	cam.resize((int)size.x, (int)size.y, false);
        }
	} else {
		throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
	}  
}