/** * 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); }
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);
public void postQueue(RenderQueue rq) { Camera sceneCam = rm.getCurrentCamera(); //update refraction cam refractionCam.setLocation(sceneCam.getLocation()); refractionCam.setRotation(sceneCam.getRotation()); refractionCam.setFrustum(sceneCam.getFrustumNear(), sceneCam.getFrustumFar(), sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom()); refractionCam.setParallelProjection(sceneCam.isParallelProjection()); //update reflection cam WaterUtils.updateReflectionCam(reflectionCam, plane, sceneCam); //Rendering reflection and refraction rm.renderViewPort(reflectionView, savedTpf); rm.renderViewPort(refractionView, savedTpf); rm.getRenderer().setFrameBuffer(vp.getOutputFrameBuffer()); rm.setCamera(sceneCam, false); }
public void onAnalog(String name, float value, float tpf) { if (cam.isParallelProjection()) { // Instead of moving closer/farther to object, we zoom in/out. if (name.equals("Size-")) { frustumSize += 5f * tpf; } else { frustumSize -= 5f * tpf; } float aspect = (float) cam.getWidth() / cam.getHeight(); cam.setFrustum(-1000, 1000, -aspect * frustumSize, aspect * frustumSize, frustumSize, -frustumSize); } }
/** * Computes the z value in projection space from the z value in view space * Note that the returned value is going non linearly from 0 to 1. * for more explanations on non linear z buffer see * http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html * @param viewZPos the z value in view space. * @return the z value in projection space. */ public float getViewToProjectionZ(float viewZPos) { float far = getFrustumFar(); float near = getFrustumNear(); float a = far / (far - near); float b = far * near / (near - far); return a + b / viewZPos; }
public void onAnalog(String name, float value, float tpf) { // Instead of moving closer/farther to object, we zoom in/out. if (name.equals("Size-")) frustumSize += 0.3f * tpf; else frustumSize -= 0.3f * tpf; float aspect = (float) cam.getWidth() / cam.getHeight(); cam.setFrustum(-1000, 1000, -aspect * frustumSize, aspect * frustumSize, frustumSize, -frustumSize); } }
public void initialize(RenderManager rm, ViewPort viewPort) { this.camera = viewPort.getCamera(); this.width = camera.getWidth(); this.height = camera.getHeight(); this.renderManager = rm; this.isInitilized = true; if (freeItems == null) { freeItems = new LinkedBlockingQueue<WorkItem>(); for (int i = 0; i < numCpus; i++) { freeItems.add(new WorkItem(width, height)); } } }
public void setupOffscreenView(){ offCamera = new Camera(width, height); offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f); offCamera.setLocation(new Vector3f(0f, 0f, -5f)); offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
@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.setDirection(direction); shadowCam.setFrustumPerspective(light.getSpotOuterAngle() * FastMath.RAD_TO_DEG * 2.0f, 1, 1f, light.getSpotRange()); shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp()); shadowCam.setLocation(light.getPosition()); shadowCam.update(); shadowCam.updateViewProjection(); }
Camera camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT); int type = ((Number) structure.getFieldValue("type")).intValue(); if (type != 0 && type != 1) { camera.setParallelProjection(type == 1); float aspect = 0; float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue(); aspect = ((Number) structure.getFieldValue("ortho_scale")).floatValue(); camera.setFrustumPerspective(aspect, camera.getWidth() / camera.getHeight(), clipsta, clipend); camera.setName(structure.getName()); return camera;
private void initView() { viewPort.setBackgroundColor(ColorRGBA.DarkGray); cam.setLocation(new Vector3f(8.569681f, 3.335546f, 5.4372444f)); cam.setRotation(new Quaternion(-0.07608022f, 0.9086564f, -0.18992864f, -0.3639813f)); flyCam.setMoveSpeed(10); }
@Override protected void initFrustumCam() { Camera viewCam = viewPort.getCamera(); frustumCam = viewCam.clone(); frustumCam.setFrustum(viewCam.getFrustumNear(), zFarOverride, viewCam.getFrustumLeft(), viewCam.getFrustumRight(), viewCam.getFrustumTop(), viewCam.getFrustumBottom()); }
/** * * @param viewCam * @return */ @Override protected boolean checkCulling(Camera viewCam) { Camera cam = viewCam; if(frustumCam != null){ cam = frustumCam; cam.setLocation(viewCam.getLocation()); cam.setRotation(viewCam.getRotation()); } TempVars vars = TempVars.get(); boolean intersects = light.intersectsFrustum(cam,vars); vars.release(); return intersects; }
/** * Creates an off camera * * @param mapSize the size * @param worldPos the position * @param axisX the x axis * @param axisY the y axis * @param axisZ tha z axis * @return */ protected Camera createOffCamera(final int mapSize, final Vector3f worldPos, final Vector3f axisX, final Vector3f axisY, final Vector3f axisZ) { final Camera offCamera = new Camera(mapSize, mapSize); offCamera.setLocation(worldPos); offCamera.setAxes(axisX, axisY, axisZ); offCamera.setFrustumPerspective(90f, 1f, 0.1f, 1000); offCamera.setLocation(position); return offCamera; }
viewCam.getFrustumNear(), viewCam.getFrustumFar(), 1.0f, points); shadowCam.setProjectionMatrix(null); shadowCam.setParallelProjection(true); shadowCam.lookAtDirection(direction, Vector3f.UNIT_Y); shadowCam.update(); shadowCam.setLocation(frustaCenter); shadowCam.update(); shadowCam.updateViewProjection();
public void setCamera(Camera cam, Matrix4f viewMatrix, Matrix4f projMatrix, Matrix4f viewProjMatrix) { this.viewMatrix.set(viewMatrix); this.projMatrix.set(projMatrix); this.viewProjMatrix.set(viewProjMatrix); camLoc.set(cam.getLocation()); cam.getLeft(camLeft); cam.getUp(camUp); cam.getDirection(camDir); near = cam.getFrustumNear(); far = cam.getFrustumFar(); }
@Override public void simpleInitApp() { viewPort.setBackgroundColor(ColorRGBA.Gray); cam.setLocation(new Vector3f(-5.6310086f, 5.0892987f, -13.000479f)); cam.setRotation(new Quaternion(0.1779095f, 0.20036356f, -0.03702727f, 0.96272093f)); cam.update(); cam.setFrustumFar(300); flyCam.setMoveSpeed(30); rootNode.setCullHint(CullHint.Never); setupLighting(); setupModel(); setupFilters(); }
public void simpleInitApp() { Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj"); DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.White); dl.setDirection(Vector3f.UNIT_XYZ.negate()); rootNode.addLight(dl); rootNode.attachChild(teaGeom); // Setup first view cam.setParallelProjection(true); float aspect = (float) cam.getWidth() / cam.getHeight(); cam.setFrustum(-1000, 1000, -aspect * frustumSize, aspect * frustumSize, frustumSize, -frustumSize); inputManager.addListener(this, "Size+", "Size-"); inputManager.addMapping("Size+", new KeyTrigger(KeyInput.KEY_W)); inputManager.addMapping("Size-", new KeyTrigger(KeyInput.KEY_S)); }
/** * Forcefully takes over Camera adding functionality and placing it behind the character * @param tpf Tickes Per Frame */ private void camTakeOver(float tpf) { cam.setLocation(player.getLocalTranslation().add(-8, 2, 0)); cam.lookAt(player.getLocalTranslation(), Vector3f.UNIT_Y); Quaternion rot = new Quaternion(); rot.fromAngleNormalAxis(camAngle, Vector3f.UNIT_Z); cam.setRotation(cam.getRotation().mult(rot)); camAngle *= FastMath.pow(.99f, fpsRate * tpf); }
@Override public void simpleInitApp() { makeTerrain(); flyCam.setMoveSpeed(50); sl = new SpotLight(); sl.setSpotRange(100); sl.setSpotOuterAngle(20 * FastMath.DEG_TO_RAD); sl.setSpotInnerAngle(15 * FastMath.DEG_TO_RAD); sl.setDirection(new Vector3f(-0.39820394f, -0.73094344f, 0.55421597f)); sl.setPosition(new Vector3f(-64.61567f, -87.615425f, -202.41328f)); rootNode.addLight(sl); AmbientLight ambLight = new AmbientLight(); ambLight.setColor(ColorRGBA.Black); rootNode.addLight(ambLight); cam.setLocation(new Vector3f(-41.219646f, 0.8363f, -171.67267f)); cam.setRotation(new Quaternion(-0.04562731f, 0.89917684f, -0.09668826f, -0.4243236f)); sl.setDirection(cam.getDirection()); sl.setPosition(cam.getLocation()); }