Java Code Examples for com.jme3.renderer.ViewPort#getCamera()
The following examples show how to use
com.jme3.renderer.ViewPort#getCamera() .
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: DefaultDraggable.java From Lemur with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Creates a 3D draggable that will move the specified spatial relative to * its current translation in a plane relative to the current viewport camera. */ public DefaultDraggable( ViewPort view, Spatial spatial, Vector2f start ) { Camera cam = view.getCamera(); Vector3f origin = spatial.getWorldTranslation(); Vector3f screenPos = cam.getScreenCoordinates(origin); Vector2f xScreen = new Vector2f(screenPos.x + 1, screenPos.y); Vector2f yScreen = new Vector2f(screenPos.x, screenPos.y + 1); // Find the world location for one pixel right and one pixel up // in the plane of our object. Vector3f xWorld = cam.getWorldCoordinates(xScreen, screenPos.z); Vector3f yWorld = cam.getWorldCoordinates(yScreen, screenPos.z); this.start = start.clone(); this.spatial = spatial; this.origin = origin.clone(); this.xAxis = xWorld.subtractLocal(origin); this.yAxis = yWorld.subtractLocal(origin); this.currentLocation = start.clone(); }
Example 2
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 3
Source File: ParticleEmitter.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Callback from Control.render(), do not use. * * @param rm * @param vp */ private void renderFromControl(RenderManager rm, ViewPort vp) { Camera cam = vp.getCamera(); if (meshType == ParticleMesh.Type.Point) { float C = cam.getProjectionMatrix().m00; C *= cam.getWidth() * 0.5f; // send attenuation params this.getMaterial().setFloat("Quadratic", C); } Matrix3f inverseRotation = Matrix3f.IDENTITY; TempVars vars = null; if (!worldSpace) { vars = TempVars.get(); inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal(); } particleMesh.updateParticleData(particles, cam, inverseRotation); if (!worldSpace) { vars.release(); } }
Example 4
Source File: MyParticleEmitter.java From OpenRTS with MIT License | 6 votes |
/** * Callback from Control.render(), do not use. * * @param rm * @param vp */ private void renderFromControl(RenderManager rm, ViewPort vp) { Camera cam = vp.getCamera(); if (meshType == ParticleMesh.Type.Point) { float C = cam.getProjectionMatrix().m00; C *= cam.getWidth() * 0.5f; // send attenuation params this.getMaterial().setFloat("Quadratic", C); } Matrix3f inverseRotation = Matrix3f.IDENTITY; TempVars vars = null; if (!worldSpace) { vars = TempVars.get(); inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal(); } particleMesh.updateParticleData(particles, cam, inverseRotation); if (!worldSpace) { vars.release(); } }
Example 5
Source File: ParticleEmitter.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Callback from Control.render(), do not use. * * @param rm * @param vp */ private void renderFromControl(RenderManager rm, ViewPort vp) { Camera cam = vp.getCamera(); if (meshType == ParticleMesh.Type.Point) { float C = cam.getProjectionMatrix().m00; C *= cam.getWidth() * 0.5f; // send attenuation params this.getMaterial().setFloat("Quadratic", C); } Matrix3f inverseRotation = Matrix3f.IDENTITY; TempVars vars = null; if (!worldSpace) { vars = TempVars.get(); inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal(); } particleMesh.updateParticleData(particles, cam, inverseRotation); if (!worldSpace) { vars.release(); } }
Example 6
Source File: TerrainLodControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void controlRender(final RenderManager rm, final ViewPort vp) { if (!isUseRenderCamera()) { return; } else if (camera == vp.getCamera()) { return; } camera = vp.getCamera(); previousCameraLocation.set(camera.getLocation()); }
Example 7
Source File: VideoRecorderAppState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override 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)); } } }
Example 8
Source File: VideoRecorderAppState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void initialize(RenderManager rm, ViewPort viewPort) { logger.log(Level.INFO, "initialize in VideoProcessor"); 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)); } } }
Example 9
Source File: LodControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void controlRender(RenderManager rm, ViewPort vp) { BoundingVolume bv = spatial.getWorldBound(); Camera cam = vp.getCamera(); float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop()); float ratio = (FastMath.PI / (8f * atanNH)); float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio; int level; if (Math.abs(newDistance - lastDistance) <= distTolerance) { level = lastLevel; // we haven't moved relative to the model, send the old measurement back. } else if (lastDistance > newDistance && lastLevel == 0) { level = lastLevel; // we're already at the lowest setting and we just got closer to the model, no need to keep trying. } else if (lastDistance < newDistance && lastLevel == numLevels - 1) { level = lastLevel; // we're already at the highest setting and we just got further from the model, no need to keep trying. } else { lastDistance = newDistance; // estimate area of polygon via bounding volume float area = AreaUtils.calcScreenArea(bv, lastDistance, cam.getWidth()); float trisToDraw = area * trisPerPixel; level = numLevels - 1; for (int i = numLevels; --i >= 0;) { if (trisToDraw - numTris[i] < 0) { break; } level = i; } lastLevel = level; } spatial.setLodLevel(level); }
Example 10
Source File: LodControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
protected void controlRender(RenderManager rm, ViewPort vp){ BoundingVolume bv = spatial.getWorldBound(); Camera cam = vp.getCamera(); float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop()); float ratio = (FastMath.PI / (8f * atanNH)); float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio; int level; if (Math.abs(newDistance - lastDistance) <= distTolerance) level = lastLevel; // we haven't moved relative to the model, send the old measurement back. else if (lastDistance > newDistance && lastLevel == 0) level = lastLevel; // we're already at the lowest setting and we just got closer to the model, no need to keep trying. else if (lastDistance < newDistance && lastLevel == numLevels - 1) level = lastLevel; // we're already at the highest setting and we just got further from the model, no need to keep trying. else{ lastDistance = newDistance; // estimate area of polygon via bounding volume float area = AreaUtils.calcScreenArea(bv, lastDistance, cam.getWidth()); float trisToDraw = area * trisPerPixel; level = numLevels - 1; for (int i = numLevels; --i >= 0;){ if (trisToDraw - numTris[i] < 0){ break; } level = i; } lastLevel = level; } spatial.setLodLevel(level); }
Example 11
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 12
Source File: BillboardControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected void controlRender(RenderManager rm, ViewPort vp) { Camera cam = vp.getCamera(); rotateBillboard(cam); }
Example 13
Source File: BillboardControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override protected void controlRender(RenderManager rm, ViewPort vp) { Camera cam = vp.getCamera(); rotateBillboard(cam); }