Java Code Examples for com.jme3.renderer.Camera#setParallelProjection()
The following examples show how to use
com.jme3.renderer.Camera#setParallelProjection() .
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: SceneLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void parseCamera(Attributes attribs) throws SAXException { camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT); if (SAXUtil.parseString(attribs.getValue("projectionType"), "perspective").equals("parallel")){ camera.setParallelProjection(true); } float fov = SAXUtil.parseFloat(attribs.getValue("fov"), 45f); if (fov < FastMath.PI) { // XXX: Most likely, it is in radians.. fov = fov * FastMath.RAD_TO_DEG; } camera.setFrustumPerspective(fov, (float)DEFAULT_CAM_WIDTH / DEFAULT_CAM_HEIGHT, 1, 1000); cameraNode = new CameraNode(attribs.getValue("name"), camera); cameraNode.setControlDir(ControlDirection.SpatialToCamera); node.attachChild(cameraNode); node = null; }
Example 2
Source File: ShadowCamera.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Updates the camera view direction and position based on the light */ public void updateLightCamera(Camera lightCam) { if (target.getType() == Light.Type.Directional) { DirectionalLight dl = (DirectionalLight) target; lightCam.setParallelProjection(true); lightCam.setLocation(Vector3f.ZERO); lightCam.lookAtDirection(dl.getDirection(), Vector3f.UNIT_Y); lightCam.setFrustum(-1, 1, -1, 1, 1, -1); } else { PointLight pl = (PointLight) target; lightCam.setParallelProjection(false); lightCam.setLocation(pl.getPosition()); // direction will have to be calculated automatically lightCam.setFrustumPerspective(45, 1, 1, 300); } }
Example 3
Source File: CameraHelper.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * This method converts the given structure to jme camera. Should be used form blender 2.49. * * @param structure * camera structure * @return jme camera object * @throws BlenderFileException * an exception is thrown when there are problems with the * blender file */ private CameraNode toCamera249(Structure structure) throws BlenderFileException { Camera camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT); int type = ((Number) structure.getFieldValue("type")).intValue(); if (type != 0 && type != 1) { LOGGER.log(Level.WARNING, "Unknown camera type: {0}. Perspective camera is being used!", type); type = 0; } // type==0 - perspective; type==1 - orthographic; perspective is used as default camera.setParallelProjection(type == 1); float aspect = 0; float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue(); float clipend = ((Number) structure.getFieldValue("clipend")).floatValue(); if (type == 0) { aspect = ((Number) structure.getFieldValue("lens")).floatValue(); } else { aspect = ((Number) structure.getFieldValue("ortho_scale")).floatValue(); } camera.setFrustumPerspective(aspect, camera.getWidth() / camera.getHeight(), clipsta, clipend); return new CameraNode(null, camera); }
Example 4
Source File: SceneLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void parseCamera(Attributes attribs) throws SAXException { camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT); if (SAXUtil.parseString(attribs.getValue("projectionType"), "perspective").equals("parallel")){ camera.setParallelProjection(true); } float fov = SAXUtil.parseFloat(attribs.getValue("fov"), 45f); if (fov < FastMath.PI) { // XXX: Most likely, it is in radians.. fov = fov * FastMath.RAD_TO_DEG; } camera.setFrustumPerspective(fov, (float)DEFAULT_CAM_WIDTH / DEFAULT_CAM_HEIGHT, 1, 1000); cameraNode = new CameraNode(attribs.getValue("name"), camera); cameraNode.setControlDir(ControlDirection.SpatialToCamera); node.attachChild(cameraNode); node = null; }
Example 5
Source File: DirectionalLightShadowRendererVR.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void init(int nbSplits, int shadowMapSize) { nbShadowMaps = Math.max(Math.min(nbSplits, 4), 1); if (nbShadowMaps != nbSplits) { throw new IllegalArgumentException("Number of splits must be between 1 and 4. Given value : " + nbSplits); } splits = new ColorRGBA(); splitsArray = new float[nbSplits + 1]; shadowCam = new Camera(shadowMapSize, shadowMapSize); shadowCam.setParallelProjection(true); for (int i = 0; i < points.length; i++) { points[i] = new Vector3f(); } }
Example 6
Source File: LWJGLOpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private ViewPort setupMirrorBuffers(Camera cam, Texture2D tex, boolean expand) { if (environment != null) { if (environment.getApplication() != null) { Camera clonecam = cam.clone(); ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam); clonecam.setParallelProjection(true); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black); Picture pic = new Picture("fullscene"); pic.setLocalTranslation(-0.75f, -0.5f, 0f); if (expand) { pic.setLocalScale(3f, 1f, 1f); } else { pic.setLocalScale(1.5f, 1f, 1f); } pic.setQueueBucket(Bucket.Opaque); pic.setTexture(environment.getApplication().getAssetManager(), tex, false); viewPort.attachScene(pic); viewPort.setOutputFrameBuffer(null); pic.updateGeometricState(); 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 7
Source File: OpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) { if (environment != null){ if (environment.getApplication() != null){ Camera clonecam = cam.clone(); ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam); clonecam.setParallelProjection(true); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black); Picture pic = new Picture("fullscene"); pic.setLocalTranslation(-0.75f, -0.5f, 0f); if( expand ) { pic.setLocalScale(3f, 1f, 1f); } else { pic.setLocalScale(1.5f, 1f, 1f); } pic.setQueueBucket(Bucket.Opaque); pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D)tex, false); viewPort.attachScene(pic); viewPort.setOutputFrameBuffer(null); pic.updateGeometricState(); 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 8
Source File: OSVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) { if (environment != null){ if (environment.getApplication() != null){ Camera clonecam = cam.clone(); ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam); clonecam.setParallelProjection(true); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black); Picture pic = new Picture("fullscene"); pic.setLocalTranslation(-0.75f, -0.5f, 0f); if( expand ) { pic.setLocalScale(3f, 1f, 1f); } else { pic.setLocalScale(1.5f, 1f, 1f); } pic.setQueueBucket(Bucket.Opaque); pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D)tex, false); viewPort.attachScene(pic); viewPort.setOutputFrameBuffer(null); pic.updateGeometricState(); 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: WaterUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void updateReflectionCam(Camera reflectionCam, Plane plane, Camera sceneCam){ TempVars vars = TempVars.get(); //Temp vects for reflection cam orientation calculation Vector3f sceneTarget = vars.vect1; Vector3f reflectDirection = vars.vect2; Vector3f reflectUp = vars.vect3; Vector3f reflectLeft = vars.vect4; Vector3f camLoc = vars.vect5; camLoc = plane.reflect(sceneCam.getLocation(), camLoc); reflectionCam.setLocation(camLoc); reflectionCam.setFrustum(sceneCam.getFrustumNear(), sceneCam.getFrustumFar(), sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom()); reflectionCam.setParallelProjection(sceneCam.isParallelProjection()); sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getDirection(vars.vect6)); reflectDirection = plane.reflect(sceneTarget, reflectDirection); reflectDirection.subtractLocal(camLoc); sceneTarget.set(sceneCam.getLocation()).subtractLocal(sceneCam.getUp(vars.vect6)); reflectUp = plane.reflect(sceneTarget, reflectUp); reflectUp.subtractLocal(camLoc); sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getLeft(vars.vect6)); reflectLeft = plane.reflect(sceneTarget, reflectLeft); reflectLeft.subtractLocal(camLoc); reflectionCam.setAxes(reflectLeft, reflectUp, reflectDirection); vars.release(); }
Example 10
Source File: DirectionalLightShadowRenderer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void init(int nbSplits, int shadowMapSize) { nbShadowMaps = Math.max(Math.min(nbSplits, 4), 1); if (nbShadowMaps != nbSplits) { throw new IllegalArgumentException("Number of splits must be between 1 and 4. Given value : " + nbSplits); } splits = new ColorRGBA(); splitsArray = new float[nbSplits + 1]; shadowCam = new Camera(shadowMapSize, shadowMapSize); shadowCam.setParallelProjection(true); for (int i = 0; i < points.length; i++) { points[i] = new Vector3f(); } }
Example 11
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); }
Example 12
Source File: HudState.java From Lemur with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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(); }
Example 13
Source File: PssmShadowRenderer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Create a PSSM Shadow Renderer More info on the technique at <a * href="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html">http://http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html</a> * * @param manager the application asset manager * @param size the size of the rendered shadowmaps (512,1024,2048, etc...) * @param nbSplits the number of shadow maps rendered (the more shadow maps * the more quality, the less fps). * @param postShadowMat the material used for post shadows if you need to * override it */ protected PssmShadowRenderer(AssetManager manager, int size, int nbSplits, Material postShadowMat) { this.postshadowMat = postShadowMat; assetManager = manager; nbSplits = Math.max(Math.min(nbSplits, 4), 1); this.nbSplits = nbSplits; shadowMapSize = size; shadowFB = new FrameBuffer[nbSplits]; shadowMaps = new Texture2D[nbSplits]; dispPic = new Picture[nbSplits]; lightViewProjectionsMatrices = new Matrix4f[nbSplits]; splits = new ColorRGBA(); splitsArray = new float[nbSplits + 1]; //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash) dummyTex = new Texture2D(size, size, Format.RGBA8); preshadowMat = new Material(manager, "Common/MatDefs/Shadow/PreShadow.j3md"); postshadowMat.setFloat("ShadowMapSize", size); for (int i = 0; i < nbSplits; i++) { lightViewProjectionsMatrices[i] = new Matrix4f(); shadowFB[i] = new FrameBuffer(size, size, 1); shadowMaps[i] = new Texture2D(size, size, Format.Depth); shadowFB[i].setDepthTexture(shadowMaps[i]); //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash) shadowFB[i].setColorTexture(dummyTex); postshadowMat.setTexture("ShadowMap" + i, shadowMaps[i]); //quads for debuging purpose dispPic[i] = new Picture("Picture" + i); dispPic[i].setTexture(manager, shadowMaps[i], false); } setCompareMode(CompareMode.Hardware); setFilterMode(FilterMode.Bilinear); setShadowIntensity(0.7f); shadowCam = new Camera(size, size); shadowCam.setParallelProjection(true); for (int i = 0; i < points.length; i++) { points[i] = new Vector3f(); } }
Example 14
Source File: PssmShadowRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Create a PSSM Shadow Renderer * More info on the technique at <a href="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html">http://http.developer.nvidia.com/GPUGems3/gpugems3_ch10.html</a> * @param manager the application asset manager * @param size the size of the rendered shadowmaps (512,1024,2048, etc...) * @param nbSplits the number of shadow maps rendered (the more shadow maps the more quality, the less fps). */ public PssmShadowRenderer(AssetManager manager, int size, int nbSplits) { assetManager = manager; nbSplits = Math.max(Math.min(nbSplits, 4), 1); this.nbSplits = nbSplits; shadowFB = new FrameBuffer[nbSplits]; shadowMaps = new Texture2D[nbSplits]; dispPic = new Picture[nbSplits]; lightViewProjectionsMatrices = new Matrix4f[nbSplits]; splits = new ColorRGBA(); splitsArray = new float[nbSplits + 1]; //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash) dummyTex = new Texture2D(size, size, Format.RGBA8); preshadowMat = new Material(manager, "Common/MatDefs/Shadow/PreShadow.j3md"); postshadowMat = new Material(manager, "Common/MatDefs/Shadow/PostShadowPSSM.j3md"); for (int i = 0; i < nbSplits; i++) { lightViewProjectionsMatrices[i] = new Matrix4f(); shadowFB[i] = new FrameBuffer(size, size, 1); shadowMaps[i] = new Texture2D(size, size, Format.Depth); shadowFB[i].setDepthTexture(shadowMaps[i]); //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash) shadowFB[i].setColorTexture(dummyTex); postshadowMat.setTexture("ShadowMap" + i, shadowMaps[i]); //quads for debuging purpose dispPic[i] = new Picture("Picture" + i); dispPic[i].setTexture(manager, shadowMaps[i], false); } setCompareMode(CompareMode.Hardware); setFilterMode(FilterMode.Bilinear); setShadowIntensity(0.7f); shadowCam = new Camera(size, size); shadowCam.setParallelProjection(true); for (int i = 0; i < points.length; i++) { points[i] = new Vector3f(); } }
Example 15
Source File: CameraHelper.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * This method converts the given structure to jme camera. Should be used form blender 2.5+. * * @param structure * camera structure * @param sceneStructure * scene structure * @return jme camera object * @throws BlenderFileException * an exception is thrown when there are problems with the * blender file */ private CameraNode toCamera250(Structure structure, Structure sceneStructure) throws BlenderFileException { int width = DEFAULT_CAM_WIDTH; int height = DEFAULT_CAM_HEIGHT; if (sceneStructure != null) { Structure renderData = (Structure) sceneStructure.getFieldValue("r"); width = ((Number) renderData.getFieldValue("xsch")).shortValue(); height = ((Number) renderData.getFieldValue("ysch")).shortValue(); } Camera camera = new Camera(width, height); int type = ((Number) structure.getFieldValue("type")).intValue(); if (type != 0 && type != 1) { LOGGER.log(Level.WARNING, "Unknown camera type: {0}. Perspective camera is being used!", type); type = 0; } // type==0 - perspective; type==1 - orthographic; perspective is used as default camera.setParallelProjection(type == 1); float aspect = width / (float) height; float fovY; // Vertical field of view in degrees float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue(); float clipend = ((Number) structure.getFieldValue("clipend")).floatValue(); if (type == 0) { // Convert lens MM to vertical degrees in fovY, see Blender rna_Camera_angle_get() // Default sensor size prior to 2.60 was 32. float sensor = 32.0f; boolean sensorVertical = false; Number sensorFit = (Number) structure.getFieldValue("sensor_fit"); if (sensorFit != null) { // If sensor_fit is vert (2), then sensor_y is used sensorVertical = sensorFit.byteValue() == 2; String sensorName = "sensor_x"; if (sensorVertical) { sensorName = "sensor_y"; } sensor = ((Number) structure.getFieldValue(sensorName)).floatValue(); } float focalLength = ((Number) structure.getFieldValue("lens")).floatValue(); float fov = 2.0f * FastMath.atan((sensor / 2.0f) / focalLength); if (sensorVertical) { fovY = fov * FastMath.RAD_TO_DEG; } else { // Convert fov from horizontal to vertical fovY = 2.0f * FastMath.atan(FastMath.tan(fov / 2.0f) / aspect) * FastMath.RAD_TO_DEG; } } else { // This probably is not correct. fovY = ((Number) structure.getFieldValue("ortho_scale")).floatValue(); } camera.setFrustumPerspective(fovY, aspect, clipsta, clipend); return new CameraNode(null, camera); }