Java Code Examples for com.jme3.renderer.Camera#isParallelProjection()
The following examples show how to use
com.jme3.renderer.Camera#isParallelProjection() .
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: GuiGlobals.java From Lemur with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Deprecated public Vector3f getScreenCoordinates( Spatial relativeTo, Vector3f pos ) { ViewPort vp = getCollisionViewPort(relativeTo); if( vp == null ) { throw new RuntimeException("Could not find viewport for:" + relativeTo); } // Calculate the world position relative to the spatial pos = relativeTo.localToWorld(pos, null); Camera cam = vp.getCamera(); if( cam.isParallelProjection() ) { return pos.clone(); } return cam.getScreenCoordinates(pos); }
Example 2
Source File: AbstractCursorEvent.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Vector3f getRelativeViewCoordinates( Spatial relativeTo, Vector3f pos ) { // Calculate the world position relative to the spatial pos = relativeTo.localToWorld(pos, null); Camera cam = view.getCamera(); if( cam.isParallelProjection() ) { return pos.clone(); } return cam.getScreenCoordinates(pos); }
Example 3
Source File: DirectionalLightShadowRendererVR.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void updateShadowCams(Camera viewCam) { float zFar = zFarOverride; if (zFar == 0) { zFar = viewCam.getFrustumFar(); } //We prevent computing the frustum points and splits with zeroed or negative near clip value float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f); ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points); //shadowCam.setDirection(direction); shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp()); shadowCam.update(); shadowCam.updateViewProjection(); PssmShadowUtil.updateFrustumSplits(splitsArray, frustumNear, zFar, lambda); // in parallel projection shadow position goe from 0 to 1 if(viewCam.isParallelProjection()){ for (int i = 0; i < nbShadowMaps; i++) { splitsArray[i] = splitsArray[i]/(zFar- frustumNear); } } switch (splitsArray.length) { case 5: splits.a = splitsArray[4]; case 4: splits.b = splitsArray[3]; case 3: splits.g = splitsArray[2]; case 2: case 1: splits.r = splitsArray[1]; break; } }
Example 4
Source File: DirectionalLightShadowRenderer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected void updateShadowCams(Camera viewCam) { if (light == null) { logger.warning("The light can't be null for a " + getClass().getName()); return; } float zFar = zFarOverride; if (zFar == 0) { zFar = viewCam.getFrustumFar(); } //We prevent computing the frustum points and splits with zeroed or negative near clip value float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f); ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points); shadowCam.setFrustumFar(zFar); shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp()); shadowCam.update(); shadowCam.updateViewProjection(); PssmShadowUtil.updateFrustumSplits(splitsArray, frustumNear, zFar, lambda); // in parallel projection shadow position goe from 0 to 1 if(viewCam.isParallelProjection()){ for (int i = 0; i < nbShadowMaps; i++) { splitsArray[i] = splitsArray[i]/(zFar- frustumNear); } } switch (splitsArray.length) { case 5: splits.a = splitsArray[4]; case 4: splits.b = splitsArray[3]; case 3: splits.g = splitsArray[2]; case 2: case 1: splits.r = splitsArray[1]; break; } }
Example 5
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Updates the points array to contain the frustum corners of the given * camera. The nearOverride and farOverride variables can be used to * override the camera's near/far values with own values. * * TODO: Reduce creation of new vectors * * @param viewCam * @param nearOverride * @param farOverride */ public static void updateFrustumPoints(Camera viewCam, float nearOverride, float farOverride, float scale, Vector3f[] points) { Vector3f pos = viewCam.getLocation(); Vector3f dir = viewCam.getDirection(); Vector3f up = viewCam.getUp(); float depthHeightRatio = viewCam.getFrustumTop() / viewCam.getFrustumNear(); float near = nearOverride; float far = farOverride; float ftop = viewCam.getFrustumTop(); float fright = viewCam.getFrustumRight(); float ratio = fright / ftop; float near_height; float near_width; float far_height; float far_width; if (viewCam.isParallelProjection()) { near_height = ftop; near_width = near_height * ratio; far_height = ftop; far_width = far_height * ratio; } else { near_height = depthHeightRatio * near; near_width = near_height * ratio; far_height = depthHeightRatio * far; far_width = far_height * ratio; } Vector3f right = dir.cross(up).normalizeLocal(); Vector3f temp = new Vector3f(); temp.set(dir).multLocal(far).addLocal(pos); Vector3f farCenter = temp.clone(); temp.set(dir).multLocal(near).addLocal(pos); Vector3f nearCenter = temp.clone(); Vector3f nearUp = temp.set(up).multLocal(near_height).clone(); Vector3f farUp = temp.set(up).multLocal(far_height).clone(); Vector3f nearRight = temp.set(right).multLocal(near_width).clone(); Vector3f farRight = temp.set(right).multLocal(far_width).clone(); points[0].set(nearCenter).subtractLocal(nearUp).subtractLocal(nearRight); points[1].set(nearCenter).addLocal(nearUp).subtractLocal(nearRight); points[2].set(nearCenter).addLocal(nearUp).addLocal(nearRight); points[3].set(nearCenter).subtractLocal(nearUp).addLocal(nearRight); points[4].set(farCenter).subtractLocal(farUp).subtractLocal(farRight); points[5].set(farCenter).addLocal(farUp).subtractLocal(farRight); points[6].set(farCenter).addLocal(farUp).addLocal(farRight); points[7].set(farCenter).subtractLocal(farUp).addLocal(farRight); if (scale != 1.0f) { // find center of frustum Vector3f center = new Vector3f(); for (int i = 0; i < 8; i++) { center.addLocal(points[i]); } center.divideLocal(8f); Vector3f cDir = new Vector3f(); for (int i = 0; i < 8; i++) { cDir.set(points[i]).subtractLocal(center); cDir.multLocal(scale - 1.0f); points[i].addLocal(cDir); } } }
Example 6
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 7
Source File: ShadowUtil.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Updates the points array to contain the frustum corners of the given * camera. The nearOverride and farOverride variables can be used * to override the camera's near/far values with own values. * * TODO: Reduce creation of new vectors * * @param viewCam * @param nearOverride * @param farOverride */ public static void updateFrustumPoints(Camera viewCam, float nearOverride, float farOverride, float scale, Vector3f[] points) { Vector3f pos = viewCam.getLocation(); Vector3f dir = viewCam.getDirection(); Vector3f up = viewCam.getUp(); float depthHeightRatio = viewCam.getFrustumTop() / viewCam.getFrustumNear(); float near = nearOverride; float far = farOverride; float ftop = viewCam.getFrustumTop(); float fright = viewCam.getFrustumRight(); float ratio = fright / ftop; float near_height; float near_width; float far_height; float far_width; if (viewCam.isParallelProjection()) { near_height = ftop; near_width = near_height * ratio; far_height = ftop; far_width = far_height * ratio; } else { near_height = depthHeightRatio * near; near_width = near_height * ratio; far_height = depthHeightRatio * far; far_width = far_height * ratio; } Vector3f right = dir.cross(up).normalizeLocal(); Vector3f temp = new Vector3f(); temp.set(dir).multLocal(far).addLocal(pos); Vector3f farCenter = temp.clone(); temp.set(dir).multLocal(near).addLocal(pos); Vector3f nearCenter = temp.clone(); Vector3f nearUp = temp.set(up).multLocal(near_height).clone(); Vector3f farUp = temp.set(up).multLocal(far_height).clone(); Vector3f nearRight = temp.set(right).multLocal(near_width).clone(); Vector3f farRight = temp.set(right).multLocal(far_width).clone(); points[0].set(nearCenter).subtractLocal(nearUp).subtractLocal(nearRight); points[1].set(nearCenter).addLocal(nearUp).subtractLocal(nearRight); points[2].set(nearCenter).addLocal(nearUp).addLocal(nearRight); points[3].set(nearCenter).subtractLocal(nearUp).addLocal(nearRight); points[4].set(farCenter).subtractLocal(farUp).subtractLocal(farRight); points[5].set(farCenter).addLocal(farUp).subtractLocal(farRight); points[6].set(farCenter).addLocal(farUp).addLocal(farRight); points[7].set(farCenter).subtractLocal(farUp).addLocal(farRight); if (scale != 1.0f) { // find center of frustum Vector3f center = new Vector3f(); for (int i = 0; i < 8; i++) { center.addLocal(points[i]); } center.divideLocal(8f); Vector3f cDir = new Vector3f(); for (int i = 0; i < 8; i++) { cDir.set(points[i]).subtractLocal(center); cDir.multLocal(scale - 1.0f); points[i].addLocal(cDir); } } }
Example 8
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); }