Java Code Examples for com.jme3.renderer.Camera#getHeight()
The following examples show how to use
com.jme3.renderer.Camera#getHeight() .
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: LWJGLOpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 3
Source File: ScreenshotAppState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 4
Source File: OSVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 5
Source File: OSVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 6
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 7
Source File: SimpleWaterProcessor.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
protected void displayMap(Renderer r, Picture pic, int left) { Camera cam = vp.getCamera(); rm.setCamera(cam, true); int h = cam.getHeight(); pic.setPosition(left, h / 20f); pic.setWidth(128); pic.setHeight(128); pic.updateGeometricState(); rm.renderGeometry(pic); rm.setCamera(cam, false); }
Example 8
Source File: OpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 9
Source File: OpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 10
Source File: LWJGLOpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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(Texture2D.MinFilter.BilinearNoMipMaps); offTex.setMagFilter(Texture2D.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 11
Source File: EditorUtil.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * 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 12
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 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(); 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 13
Source File: AbstractShadowRenderer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * For debugging purposes, display depth shadow maps. */ protected void displayShadowMap(Renderer r) { Camera cam = viewPort.getCamera(); renderManager.setCamera(cam, true); int h = cam.getHeight(); for (int i = 0; i < dispPic.length; i++) { dispPic[i].setPosition((128 * i) + (150 + 64 * (i + 1)), h / 20f); dispPic[i].setWidth(128); dispPic[i].setHeight(128); dispPic[i].updateGeometricState(); renderManager.renderGeometry(dispPic[i]); } renderManager.setCamera(cam, false); }
Example 14
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 15
Source File: PopupState.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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: PssmShadowRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void displayShadowMap(Renderer r) { Camera cam = viewPort.getCamera(); renderManager.setCamera(cam, true); int h = cam.getHeight(); for (int i = 0; i < dispPic.length; i++) { dispPic[i].setPosition(64 * (i + 1) + 128 * i, h / 20f); dispPic[i].setWidth(128); dispPic[i].setHeight(128); dispPic[i].updateGeometricState(); renderManager.renderGeometry(dispPic[i]); } renderManager.setCamera(cam, false); }
Example 17
Source File: PssmShadowRenderer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected void displayShadowMap(Renderer r) { Camera cam = viewPort.getCamera(); renderManager.setCamera(cam, true); int h = cam.getHeight(); for (int i = 0; i < dispPic.length; i++) { dispPic[i].setPosition((128 * i) + (150 + 64 * (i + 1)), h / 20f); dispPic[i].setWidth(128); dispPic[i].setHeight(128); dispPic[i].updateGeometricState(); renderManager.renderGeometry(dispPic[i]); } renderManager.setCamera(cam, false); }
Example 18
Source File: OpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * 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 19
Source File: AWTFrameProcessor.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * 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 20
Source File: ViewPortDemoState.java From Lemur with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Creates an ortho viewport in the specified section of the screen. * The viewport will be scaled such that adding things to its root * scene will be in 1:1 pixel space. */ protected void createGuiViewPort( int x1, int y1, int x2, int y2, ColorRGBA bgColor ) { if( vp != null ) { disposeViewPort(); } log.info("Creating demo GUI ViewPort"); // Setup the viewport for a cloned camera Camera cam = getApplication().getCamera().clone(); float width = cam.getWidth(); float height = cam.getHeight(); cam.setViewPort(x1/width, x2/width, y1/height, y2/height); // Setup the ortho project. I've found it doesn't play // nice unless the range spans 0. We'll move its root node // so that 0,0 is the lower left corner like the regular gui bucket. float near = -1000; float far = 1000; float w = x2 - x1; float h = y2 - y1; cam.setParallelProjection(true); cam.setFrustum(near, far, -w/2, w/2, h/2, -h/2); // Create the actual viewport vp = getApplication().getRenderManager().createPostView("ViewPort Demo", cam); vp.setClearFlags(true, true, true); vp.setBackgroundColor(bgColor); // We want the transparent bucket to act exactly like the GUI // bucket with respect to back-to-front sorting. vp.getQueue().setGeometryComparator(Bucket.Transparent, new GuiComparator()); // Give it a root node that we can use to attach things. // Translate it so that 0,0 is the lower left corner. // Note: the is NOT in the Gui Bucket... but the transparent bucket. vpRoot = new Node("VP Root"); vpRoot.setQueueBucket(Bucket.Transparent); vpRoot.setLocalTranslation(-w/2, -h/2, 0); vp.attachScene(vpRoot); // Let Lemur know to do picking in this viewport getState(PickState.class).addCollisionRoot(vp, PickState.PICK_LAYER_GUI); }