Java Code Examples for com.jme3.renderer.Camera#setFrustumPerspective()
The following examples show how to use
com.jme3.renderer.Camera#setFrustumPerspective() .
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: Application.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Creates the camera to use for rendering. Default values are perspective * projection with 45° field of view, with near and far values 1 and 1000 * units respectively. */ private void initCamera(){ cam = new Camera(settings.getWidth(), settings.getHeight()); cam.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f); cam.setLocation(new Vector3f(0f, 0f, 10f)); cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y); renderManager = new RenderManager(renderer); //Remy - 09/14/2010 setted the timer in the renderManager renderManager.setTimer(timer); viewPort = renderManager.createMainView("Default", cam); viewPort.setClearFlags(true, true, true); // Create a new cam for the gui Camera guiCam = new Camera(settings.getWidth(), settings.getHeight()); guiViewPort = renderManager.createPostView("Gui Default", guiCam); guiViewPort.setClearFlags(false, false, false); }
Example 2
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 3
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 4
Source File: VRApplication.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Creates the camera to use for rendering. Default values are perspective * projection with 45° field of view, with near and far values 1 and 1000 * units respectively. */ private void initCamera(){ cam = new Camera(settings.getWidth(), settings.getHeight()); cam.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f); cam.setLocation(new Vector3f(0f, 0f, 10f)); cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y); renderManager = new RenderManager(renderer); //Remy - 09/14/2010 setted the timer in the renderManager renderManager.setTimer(timer); viewPort = renderManager.createMainView("Default", cam); viewPort.setClearFlags(true, true, true); // Create a new cam for the gui Camera guiCam = new Camera(settings.getWidth(), settings.getHeight()); guiViewPort = renderManager.createPostView("Gui Default", guiCam); guiViewPort.setClearFlags(false, false, false); }
Example 5
Source File: LegacyApplication.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Creates the camera to use for rendering. Default values are perspective * projection with 45° field of view, with near and far values 1 and 1000 * units respectively. */ private void initCamera(){ cam = new Camera(settings.getWidth(), settings.getHeight()); cam.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f); cam.setLocation(new Vector3f(0f, 0f, 10f)); cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y); renderManager = new RenderManager(renderer); //Remy - 09/14/2010 setted the timer in the renderManager renderManager.setTimer(timer); if (prof != null) { renderManager.setAppProfiler(prof); } viewPort = renderManager.createMainView("Default", cam); viewPort.setClearFlags(true, true, true); // Create a new cam for the gui Camera guiCam = new Camera(settings.getWidth(), settings.getHeight()); guiViewPort = renderManager.createPostView("Gui Default", guiCam); guiViewPort.setClearFlags(false, false, false); }
Example 6
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 7
Source File: LightFilterTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Before public void setUp() { filter = new DefaultLightFilter(); cam = new Camera(512, 512); cam.setFrustumPerspective(45, 1, 1, 1000); cam.setLocation(Vector3f.ZERO); cam.lookAtDirection(Vector3f.UNIT_Z, Vector3f.UNIT_Y); filter.setCamera(cam); Box box = new Box(1, 1, 1); geom = new Geometry("geom", box); geom.setLocalTranslation(0, 0, 10); geom.updateGeometricState(); list = new LightList(geom); }
Example 8
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 9
Source File: GroundCameraManager.java From OpenRTS with MIT License | 5 votes |
public GroundCameraManager(Camera cam) { super(cam); pos = new Point3D(1, 1, 0); rotation = new Quaternion().fromAngles((float)AngleUtil.RIGHT, 0, (float)AngleUtil.FLAT); cam.setFrustumPerspective(45, (float)cam.getWidth()/cam.getHeight(), 0.01f, 1000); applyRotationToCam(); setMappings(); }
Example 10
Source File: TestRenderToTexture.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public Texture setupOffscreenView(){ Camera offCamera = new Camera(512, 512); offView = renderManager.createPreView("Offscreen View", offCamera); offView.setClearFlags(true, true, true); offView.setBackgroundColor(ColorRGBA.DarkGray); // create offscreen framebuffer FrameBuffer offBuffer = new FrameBuffer(512, 512, 1); //setup framebuffer's cam offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f); offCamera.setLocation(new Vector3f(0f, 0f, -5f)); offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y); //setup framebuffer's texture Texture2D offTex = new Texture2D(512, 512, Format.RGBA8); offTex.setMinFilter(Texture.MinFilter.Trilinear); offTex.setMagFilter(Texture.MagFilter.Bilinear); //setup framebuffer to use texture offBuffer.setDepthBuffer(Format.Depth); offBuffer.setColorTexture(offTex); //set viewport to render to offscreen framebuffer offView.setOutputFrameBuffer(offBuffer); // setup framebuffer's scene Box boxMesh = new Box(Vector3f.ZERO, 1,1,1); Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m"); offBox = new Geometry("box", boxMesh); offBox.setMaterial(material); // attach the scene to the viewport to be rendered offView.attachScene(offBox); return offTex; }
Example 11
Source File: TestRenderToTexture.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Texture setupOffscreenView(){ Camera offCamera = new Camera(512, 512); offView = renderManager.createPreView("Offscreen View", offCamera); offView.setClearFlags(true, true, true); offView.setBackgroundColor(ColorRGBA.DarkGray); // create offscreen framebuffer FrameBuffer offBuffer = new FrameBuffer(512, 512, 1); //setup framebuffer's cam offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f); offCamera.setLocation(new Vector3f(0f, 0f, -5f)); offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y); //setup framebuffer's texture Texture2D offTex = new Texture2D(512, 512, Format.RGBA8); offTex.setMinFilter(Texture.MinFilter.Trilinear); offTex.setMagFilter(Texture.MagFilter.Bilinear); //setup framebuffer to use texture offBuffer.setDepthBuffer(Format.Depth); offBuffer.setColorTexture(offTex); //set viewport to render to offscreen framebuffer offView.setOutputFrameBuffer(offBuffer); // setup framebuffer's scene Box boxMesh = new Box(1, 1, 1); Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m"); offBox = new Geometry("box", boxMesh); offBox.setMaterial(material); // attach the scene to the viewport to be rendered offView.attachScene(offBox); return offTex; }
Example 12
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 13
Source File: ShadowUtil.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Updates the shadow camera to properly contain the given * points (which contain the eye camera frustum corners) * * @param occluders * @param lightCam * @param points */ public static void updateShadowCamera(Camera shadowCam, Vector3f[] points) { boolean ortho = shadowCam.isParallelProjection(); shadowCam.setProjectionMatrix(null); if (ortho) { shadowCam.setFrustum(-1, 1, -1, 1, 1, -1); } else { shadowCam.setFrustumPerspective(45, 1, 1, 150); } Matrix4f viewProjMatrix = shadowCam.getViewProjectionMatrix(); Matrix4f projMatrix = shadowCam.getProjectionMatrix(); BoundingBox splitBB = computeBoundForPoints(points, viewProjMatrix); Vector3f splitMin = splitBB.getMin(null); Vector3f splitMax = splitBB.getMax(null); // splitMin.z = 0; // Create the crop matrix. float scaleX, scaleY, scaleZ; float offsetX, offsetY, offsetZ; scaleX = 2.0f / (splitMax.x - splitMin.x); scaleY = 2.0f / (splitMax.y - splitMin.y); offsetX = -0.5f * (splitMax.x + splitMin.x) * scaleX; offsetY = -0.5f * (splitMax.y + splitMin.y) * scaleY; scaleZ = 1.0f / (splitMax.z - splitMin.z); offsetZ = -splitMin.z * scaleZ; Matrix4f cropMatrix = new Matrix4f(scaleX, 0f, 0f, offsetX, 0f, scaleY, 0f, offsetY, 0f, 0f, scaleZ, offsetZ, 0f, 0f, 0f, 1f); Matrix4f result = new Matrix4f(); result.set(cropMatrix); result.multLocal(projMatrix); shadowCam.setProjectionMatrix(result); }
Example 14
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); }
Example 15
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Updates the shadow camera to properly contain the given points (which * contain the eye camera frustum corners) * * @param shadowCam * @param points */ public static void updateShadowCamera(Camera shadowCam, Vector3f[] points) { boolean ortho = shadowCam.isParallelProjection(); shadowCam.setProjectionMatrix(null); if (ortho) { shadowCam.setFrustum(-1, 1, -1, 1, 1, -1); } else { shadowCam.setFrustumPerspective(45, 1, 1, 150); } Matrix4f viewProjMatrix = shadowCam.getViewProjectionMatrix(); Matrix4f projMatrix = shadowCam.getProjectionMatrix(); BoundingBox splitBB = computeBoundForPoints(points, viewProjMatrix); TempVars vars = TempVars.get(); Vector3f splitMin = splitBB.getMin(vars.vect1); Vector3f splitMax = splitBB.getMax(vars.vect2); // splitMin.z = 0; // Create the crop matrix. float scaleX, scaleY, scaleZ; float offsetX, offsetY, offsetZ; scaleX = 2.0f / (splitMax.x - splitMin.x); scaleY = 2.0f / (splitMax.y - splitMin.y); offsetX = -0.5f * (splitMax.x + splitMin.x) * scaleX; offsetY = -0.5f * (splitMax.y + splitMin.y) * scaleY; scaleZ = 1.0f / (splitMax.z - splitMin.z); offsetZ = -splitMin.z * scaleZ; Matrix4f cropMatrix = vars.tempMat4; cropMatrix.set(scaleX, 0f, 0f, offsetX, 0f, scaleY, 0f, offsetY, 0f, 0f, scaleZ, offsetZ, 0f, 0f, 0f, 1f); Matrix4f result = new Matrix4f(); result.set(cropMatrix); result.multLocal(projMatrix); vars.release(); shadowCam.setProjectionMatrix(result); }
Example 16
Source File: TestRenderToMemory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void setupOffscreenView(){ offCamera = new Camera(width, height); // create a pre-view. a view that is rendered before the main view offView = renderManager.createPreView("Offscreen View", offCamera); offView.setBackgroundColor(ColorRGBA.DarkGray); offView.setClearFlags(true, true, true); // this will let us know when the scene has been rendered to the // frame buffer offView.addProcessor(this); // create offscreen framebuffer offBuffer = new FrameBuffer(width, height, 1); //setup framebuffer's cam offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f); offCamera.setLocation(new Vector3f(0f, 0f, -5f)); offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y); //setup framebuffer's texture // offTex = new Texture2D(width, height, Format.RGBA8); //setup framebuffer to use renderbuffer // this is faster for gpu -> cpu copies offBuffer.setDepthBuffer(Format.Depth); offBuffer.setColorBuffer(Format.RGBA8); // offBuffer.setColorTexture(offTex); //set viewport to render to offscreen framebuffer offView.setOutputFrameBuffer(offBuffer); // setup framebuffer's scene Box boxMesh = new Box(Vector3f.ZERO, 1,1,1); Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m"); offBox = new Geometry("box", boxMesh); offBox.setMaterial(material); // attach the scene to the viewport to be rendered offView.attachScene(offBox); }
Example 17
Source File: TestRenderToCubemap.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public Texture setupOffscreenView(){ Camera offCamera = new Camera(512, 512); offView = renderManager.createPreView("Offscreen View", offCamera); offView.setClearFlags(true, true, true); offView.setBackgroundColor(ColorRGBA.DarkGray); // create offscreen framebuffer FrameBuffer offBuffer = new FrameBuffer(512, 512, 1); //setup framebuffer's cam offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f); offCamera.setLocation(new Vector3f(0f, 0f, -5f)); offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y); //setup framebuffer's texture TextureCubeMap offTex = new TextureCubeMap(512, 512, Format.RGBA8); offTex.setMinFilter(Texture.MinFilter.Trilinear); offTex.setMagFilter(Texture.MagFilter.Bilinear); //setup framebuffer to use texture offBuffer.setDepthBuffer(Format.Depth); offBuffer.setMultiTarget(true); offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeX); offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveX); offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeY); offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveY); offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeZ); offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveZ); //set viewport to render to offscreen framebuffer offView.setOutputFrameBuffer(offBuffer); // setup framebuffer's scene Box boxMesh = new Box( 1,1,1); Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m"); offBox = new Geometry("box", boxMesh); offBox.setMaterial(material); // attach the scene to the viewport to be rendered offView.attachScene(offBox); return offTex; }
Example 18
Source File: TestRenderToMemory.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void setupOffscreenView(){ offCamera = new Camera(width, height); // create a pre-view. a view that is rendered before the main view offView = renderManager.createPreView("Offscreen View", offCamera); offView.setBackgroundColor(ColorRGBA.DarkGray); offView.setClearFlags(true, true, true); // this will let us know when the scene has been rendered to the // frame buffer offView.addProcessor(this); // create offscreen framebuffer offBuffer = new FrameBuffer(width, height, 1); //setup framebuffer's cam offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f); offCamera.setLocation(new Vector3f(0f, 0f, -5f)); offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y); //setup framebuffer's texture // offTex = new Texture2D(width, height, Format.RGBA8); //setup framebuffer to use renderbuffer // this is faster for gpu -> cpu copies offBuffer.setDepthBuffer(Format.Depth); offBuffer.setColorBuffer(Format.RGBA8); // offBuffer.setColorTexture(offTex); //set viewport to render to offscreen framebuffer offView.setOutputFrameBuffer(offBuffer); // setup framebuffer's scene Box boxMesh = new Box(1, 1, 1); Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m"); offBox = new Geometry("box", boxMesh); offBox.setMaterial(material); // attach the scene to the viewport to be rendered offView.attachScene(offBox); }