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

The following examples show how to use com.jme3.renderer.Camera#getWidth() . 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: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Callback from Control.render(), do not use.
 * 
 * @param rm
 * @param vp 
 */
private void renderFromControl(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();

    if (meshType == ParticleMesh.Type.Point) {
        float C = cam.getProjectionMatrix().m00;
        C *= cam.getWidth() * 0.5f;

        // send attenuation params
        this.getMaterial().setFloat("Quadratic", C);
    }

    Matrix3f inverseRotation = Matrix3f.IDENTITY;
    TempVars vars = null;
    if (!worldSpace) {
        vars = TempVars.get();

        inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
    }
    particleMesh.updateParticleData(particles, cam, inverseRotation);
    if (!worldSpace) {
        vars.release();
    }
}
 
Example 2
Source File: ParticleEmitter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Callback from Control.render(), do not use.
 *
 * @param rm
 * @param vp
 */
private void renderFromControl(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();

    if (meshType == ParticleMesh.Type.Point) {
        float C = cam.getProjectionMatrix().m00;
        C *= cam.getWidth() * 0.5f;

        // send attenuation params
        this.getMaterial().setFloat("Quadratic", C);
    }

    Matrix3f inverseRotation = Matrix3f.IDENTITY;
    TempVars vars = null;
    if (!worldSpace) {
        vars = TempVars.get();

        inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
    }
    particleMesh.updateParticleData(particles, cam, inverseRotation);
    if (!worldSpace) {
        vars.release();
    }
}
 
Example 3
Source File: PopupState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected Geometry createBlocker( float z, ColorRGBA backgroundColor ) {
    Camera cam = getApplication().getCamera();
 
    // Get the inverse scale of whatever the current guiNode is so that
    // we can find a proper screen size
    float width = cam.getWidth() / guiNode.getLocalScale().x;
    float height = cam.getHeight() / guiNode.getLocalScale().y;
    
    Quad quad = new Quad(width, height);
    Geometry result = new Geometry("blocker", quad);
    GuiMaterial guiMat = createBlockerMaterial(backgroundColor);
    result.setMaterial(guiMat.getMaterial());
    //result.setQueueBucket(Bucket.Transparent); // no, it goes in the gui bucket.
    result.setLocalTranslation(0, 0, z);
    return result;
}
 
Example 4
Source File: MyParticleEmitter.java    From OpenRTS with MIT License 6 votes vote down vote up
/**
 * Callback from Control.render(), do not use.
 * 
 * @param rm
 * @param vp 
 */
private void renderFromControl(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();

    if (meshType == ParticleMesh.Type.Point) {
        float C = cam.getProjectionMatrix().m00;
        C *= cam.getWidth() * 0.5f;

        // send attenuation params
        this.getMaterial().setFloat("Quadratic", C);
    }

    Matrix3f inverseRotation = Matrix3f.IDENTITY;
    TempVars vars = null;
    if (!worldSpace) {
        vars = TempVars.get();

        inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
    }
    particleMesh.updateParticleData(particles, cam, inverseRotation);
    if (!worldSpace) {
        vars.release();
    }
}
 
Example 5
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 6
Source File: ShadowUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 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();

    points[0].set(viewCam.getWorldCoordinates(new Vector2f(0, 0), 0));
    points[1].set(viewCam.getWorldCoordinates(new Vector2f(0, h), 0));
    points[2].set(viewCam.getWorldCoordinates(new Vector2f(w, h), 0));
    points[3].set(viewCam.getWorldCoordinates(new Vector2f(w, 0), 0));

    points[4].set(viewCam.getWorldCoordinates(new Vector2f(0, 0), 1));
    points[5].set(viewCam.getWorldCoordinates(new Vector2f(0, h), 1));
    points[6].set(viewCam.getWorldCoordinates(new Vector2f(w, h), 1));
    points[7].set(viewCam.getWorldCoordinates(new Vector2f(w, 0), 1));
}
 
Example 7
Source File: EditorUtil.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Check visibility the position on the screen.
 *
 * @param position the position for checking.
 * @param camera   the camera of the screen.
 * @return true of we can see the position on the screen.
 */
@FromAnyThread
public static boolean isVisibleOnScreen(@NotNull Vector3f position, @NotNull Camera camera) {

    var maxHeight = camera.getHeight();
    var maxWidth = camera.getWidth();

    var isBottom = position.getY() < 0;
    var isTop = position.getY() > maxHeight;
    var isLeft = position.getX() < 0;
    var isRight = position.getX() > maxWidth;

    return !isBottom && !isLeft && !isTop && !isRight && position.getZ() < 1F;
}
 
Example 8
Source File: ScreenshotAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void postFrame(FrameBuffer out) {
    if (capture){
        capture = false;

        Camera curCamera = rm.getCurrentCamera();
        int viewX = (int) (curCamera.getViewPortLeft() * curCamera.getWidth());
        int viewY = (int) (curCamera.getViewPortBottom() * curCamera.getHeight());
        int viewWidth = (int) ((curCamera.getViewPortRight() - curCamera.getViewPortLeft()) * curCamera.getWidth());
        int viewHeight = (int) ((curCamera.getViewPortTop() - curCamera.getViewPortBottom()) * curCamera.getHeight());

        renderer.setViewPort(0, 0, width, height);
        renderer.readFrameBuffer(out, outBuf);
        renderer.setViewPort(viewX, viewY, viewWidth, viewHeight);

        File file;
        String filename;
        if (numbered) {
            shotIndex++;
            filename = shotName + shotIndex;
        } else {
            filename = shotName;
        }

        if (filePath == null) {
            file = new File(JmeSystem.getStorageFolder() + File.separator + filename + ".png").getAbsoluteFile();
        } else {
            file = new File(filePath + filename + ".png").getAbsoluteFile();
        }
        logger.log(Level.FINE, "Saving ScreenShot to: {0}", file.getAbsolutePath());

        try {
            writeImageFile(file);
        } catch (IOException ex) {
            logger.log(Level.SEVERE, "Error while saving screenshot", ex);
        }                
    }
}
 
Example 9
Source File: OSVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewPort setupViewBuffers(Camera cam, String viewName){
	
	if (environment != null){
		if (environment.getApplication() != null){
	        // create offscreen framebuffer
	        FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
	        //offBufferLeft.setSrgb(true);
	        
	        //setup framebuffer's texture
	        Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
	        offTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
	        offTex.setMagFilter(Texture.MagFilter.Bilinear);

	        //setup framebuffer to use texture
	        offBufferLeft.setDepthBuffer(Image.Format.Depth);
	        offBufferLeft.setColorTexture(offTex);        
	        
	        ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        
	        Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
	        while(spatialIter.hasNext()){
	        	viewPort.attachScene(spatialIter.next());
	        }

	        //set viewport to render to offscreen framebuffer
	        viewPort.setOutputFrameBuffer(offBufferLeft);
	        return viewPort;
		} 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 10
Source File: OSVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupFinalFullTexture(Camera cam) {
	
	if (environment != null){
		if (environment.getApplication() != null){
			// create offscreen framebuffer
	        FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
	        //offBuffer.setSrgb(true);

	        //setup framebuffer's texture
	        dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
	        dualEyeTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
	        dualEyeTex.setMagFilter(Texture.MagFilter.Bilinear);

	        logger.config("Dual eye texture "+dualEyeTex.getName()+" ("+dualEyeTex.getImage().getId()+")");
	        logger.config("               Type: "+dualEyeTex.getType());
	        logger.config("               Size: "+dualEyeTex.getImage().getWidth()+"x"+dualEyeTex.getImage().getHeight());
	        logger.config("        Image depth: "+dualEyeTex.getImage().getDepth());
	        logger.config("       Image format: "+dualEyeTex.getImage().getFormat());
	        logger.config("  Image color space: "+dualEyeTex.getImage().getColorSpace());
	        
	        //setup framebuffer to use texture
	        out.setDepthBuffer(Image.Format.Depth);
	        out.setColorTexture(dualEyeTex);       

	        ViewPort viewPort = environment.getApplication().getViewPort();
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        viewPort.setOutputFrameBuffer(out);
		} 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 11
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 12
Source File: OpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewPort setupViewBuffers(Camera cam, String viewName){
	
	if (environment != null){
		if (environment.getApplication() != null){
			// create offscreen framebuffer
	        FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
	        //offBufferLeft.setSrgb(true);
	        
	        //setup framebuffer's texture
	        Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
	        offTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
	        offTex.setMagFilter(Texture.MagFilter.Bilinear);

	        //setup framebuffer to use texture
	        offBufferLeft.setDepthBuffer(Image.Format.Depth);
	        offBufferLeft.setColorTexture(offTex);        
	        
	        ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        
	        Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
	        while(spatialIter.hasNext()){
	        	viewPort.attachScene(spatialIter.next());
	        }

	        //set viewport to render to offscreen framebuffer
	        viewPort.setOutputFrameBuffer(offBufferLeft);
	        return viewPort;
		} 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 13
Source File: OpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupFinalFullTexture(Camera cam) {
	
	if (environment != null){
		if (environment.getApplication() != null){
	        // create offscreen framebuffer
	        FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
	        //offBuffer.setSrgb(true);

	        //setup framebuffer's texture
	        dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
	        dualEyeTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
	        dualEyeTex.setMagFilter(Texture.MagFilter.Bilinear);

	        logger.config("Dual eye texture "+dualEyeTex.getName()+" ("+dualEyeTex.getImage().getId()+")");
	        logger.config("               Type: "+dualEyeTex.getType());
	        logger.config("               Size: "+dualEyeTex.getImage().getWidth()+"x"+dualEyeTex.getImage().getHeight());
	        logger.config("        Image depth: "+dualEyeTex.getImage().getDepth());
	        logger.config("       Image format: "+dualEyeTex.getImage().getFormat());
	        logger.config("  Image color space: "+dualEyeTex.getImage().getColorSpace());
	        
	        //setup framebuffer to use texture
	        out.setDepthBuffer(Image.Format.Depth);
	        out.setColorTexture(dualEyeTex);       

	        ViewPort viewPort = environment.getApplication().getViewPort();
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        viewPort.setOutputFrameBuffer(out);
		} 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 14
Source File: LWJGLOpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupFinalFullTexture(Camera cam) {

        if (environment != null) {
            if (environment.getApplication() != null) {
                // create offscreen framebuffer
                FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
                //offBuffer.setSrgb(true);

                //setup framebuffer's texture
                dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
                dualEyeTex.setMinFilter(Texture2D.MinFilter.BilinearNoMipMaps);
                dualEyeTex.setMagFilter(Texture2D.MagFilter.Bilinear);

                logger.config("Dual eye texture " + dualEyeTex.getName() + " (" + dualEyeTex.getImage().getId() + ")");
                logger.config("               Type: " + dualEyeTex.getType());
                logger.config("               Size: " + dualEyeTex.getImage().getWidth() + "x" + dualEyeTex.getImage().getHeight());
                logger.config("        Image depth: " + dualEyeTex.getImage().getDepth());
                logger.config("       Image format: " + dualEyeTex.getImage().getFormat());
                logger.config("  Image color space: " + dualEyeTex.getImage().getColorSpace());

                //setup framebuffer to use texture
                out.setDepthBuffer(Image.Format.Depth);
                out.setColorTexture(dualEyeTex);

                ViewPort viewPort = environment.getApplication().getViewPort();
                viewPort.setClearFlags(true, true, true);
                viewPort.setBackgroundColor(ColorRGBA.Black);
                viewPort.setOutputFrameBuffer(out);
            } 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 15
Source File: PopupState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Returns the size of the screen based on the app's main camera size
 *  and the current scale of the guiNode.
 */   
public Vector2f getGuiSize() {
    Camera cam = getApplication().getCamera();
    float width = cam.getWidth() / getGuiNode().getLocalScale().x;
    float height = cam.getHeight() / getGuiNode().getLocalScale().y;
    return new Vector2f(width, height);        
}
 
Example 16
Source File: PickEventSession.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected boolean viewContains( Camera cam, Vector2f cursor ) {
    float x1 = cam.getViewPortLeft();
    float x2 = cam.getViewPortRight();
    float y1 = cam.getViewPortBottom();
    float y2 = cam.getViewPortTop();
    if( x1 == 0 && x2 == 1 && y1 == 0 && y2 == 1 ) {
        // No need to clip
        return true;
    }

    // Else clip it against the viewport
    float x = cursor.x / cam.getWidth();
    float y = cursor.y / cam.getHeight();
    return !(x < x1 || x > x2 || y < y1 || y > y2);
}
 
Example 17
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 18
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.");
	}  
}
 
Example 19
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 20
Source File: HudState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void initialize( Application app ) 
{
    InputMapper inputMapper = GuiGlobals.getInstance().getInputMapper();
    inputMapper.addDelegate( MainFunctions.F_HUD, this, "toggleHud" );
    
    Camera cam = app.getCamera().clone();
    cam.setParallelProjection(true);
    size = new Vector3f( cam.getWidth(), cam.getHeight(), 0 );
    
    main = new Node( "HUD" ); 
    main.setQueueBucket(Bucket.Gui);
 
    view = app.getRenderManager().createPostView( "Hud ViewPort", cam);
    view.setEnabled(isEnabled());
    view.setClearFlags(false, true, true);
    view.attachScene( main );
 
    // Make sure our viewport is setup properly
    GuiGlobals.getInstance().setupGuiComparators(view);

    // Make sure this viewport gets mouse events
    getState(MouseAppState.class).addCollisionRoot( main, view );
 
    // Setup a basic container for standard layout... for anything
    // that cares to use it.       
    container = new Container( new BorderLayout() );
    container.setPreferredSize( new Vector3f(cam.getWidth(), cam.getHeight(), 0) );
    container.setLocalTranslation( 0, cam.getHeight(), 0 );
    main.attachChild(container);
 
    if( lit )
        {
        // Add some lighting 
        DirectionalLight light = new DirectionalLight();
        light.setDirection( new Vector3f( 1, -0.5f, -1.5f ).normalizeLocal() );
        main.addLight(light);

        AmbientLight ambient = new AmbientLight();
        ambient.setColor( ColorRGBA.Gray );
        main.addLight(ambient);
        }
    
    // Have to add an empty geometry to the HUD because JME has
    // a bug in the online versions and I'd rather not go directly to
    // source.
    Label temp = new Label("");
    getNorth().addChild(temp);        
 
 
    /*
    Just a test container... putting the real stuff somewhere else in a sec.
    Container test = new Container(new ElementId("window.container"), "glass"); 
    System.out.println( "Container layout:" + test.getLayout() );
    test.addChild(new Label("Test Title", new ElementId("window.title.label"), "glass"));
    test.addChild(new Button("Test Button 1", new ElementId("window.button"), "glass"));
    test.addChild(new Button("Test Button 2", new ElementId("window.button"), "glass"));
    test.addChild(new Button("Test Button 3", new ElementId("window.button"), "glass"));
    test.addChild(new Button("Test Button 4", new ElementId("window.button"), "glass"));
    getWest().addChild(test);
    */
    
    main.updateLogicalState(1);
    main.updateGeometricState();
}