com.badlogic.gdx.graphics.PerspectiveCamera Java Examples
The following examples show how to use
com.badlogic.gdx.graphics.PerspectiveCamera.
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: Renderer.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
public Renderer () { try { lights = new Environment(); lights.add(new DirectionalLight().set(Color.WHITE, new Vector3(-1, -0.5f, 0).nor())); spriteBatch = new SpriteBatch(); modelBatch = new ModelBatch(); backgroundTexture = new Texture(Gdx.files.internal("data/planet.jpg"), Format.RGB565, true); backgroundTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear); font = new BitmapFont(Gdx.files.internal("data/font10.fnt"), Gdx.files.internal("data/font10.png"), false); camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); } catch (Exception ex) { ex.printStackTrace(); } }
Example #2
Source File: CarStillModel.java From uracer-kotd with Apache License 2.0 | 6 votes |
private Vector3 world2Dto3D (PerspectiveCamera camPersp, OrthographicCamera camOrtho, float posPxX, float posPxY) { float meshZ = -(camPersp.far - camPersp.position.z) + (camPersp.far * (1 - (camOrtho.zoom))); // compute position tmpvec.x = (this.positionOffsetPx.x - camPersp.position.x) + (camPersp.viewportWidth / 2) + posPxX; tmpvec.y = (this.positionOffsetPx.y + camPersp.position.y) + (camPersp.viewportHeight / 2) - posPxY; tmpvec.z = 1; tmpvec.x *= ScaleUtils.Scale; tmpvec.y *= ScaleUtils.Scale; tmpvec.x += ScaleUtils.CropX; tmpvec.y += ScaleUtils.CropY; // transform to world space camPersp.unproject(tmpvec, ScaleUtils.CropX, ScaleUtils.CropY, ScaleUtils.PlayWidth, ScaleUtils.PlayHeight); // build model matrix tmpvec.z = meshZ; return tmpvec; }
Example #3
Source File: GameWorldRenderer.java From uracer-kotd with Apache License 2.0 | 6 votes |
private void createCams () { int refW = Config.Graphics.ReferenceScreenWidth; int refH = Config.Graphics.ReferenceScreenHeight; camOrtho = new OrthographicCamera(refW, refH); halfViewport.set(camOrtho.viewportWidth / 2, camOrtho.viewportHeight / 2); // creates and setup orthographic camera camTilemap = new OrthographicCamera(refW, refH); camTilemap.zoom = 1; // creates and setup perspective camera // strategically choosen near/far planes, Blender models' 14.2 meters <=> one 256px tile // with far plane @48 camPersp = new PerspectiveCamera(47.27123f, refW, refH); camPersp.near = CamPerspPlaneNear; camPersp.far = CamPerspPlaneFar; camPersp.lookAt(0, 0, -1); camPersp.position.set(camTilemap.position.x, camTilemap.position.y, CamPerspElevation); camPersp.update(); camController = new CameraController(Config.Graphics.CameraInterpolationMode, halfViewport, world.worldSizePx, world.worldSizeTiles); }
Example #4
Source File: TypeTransformer.java From gdx-vr with Apache License 2.0 | 6 votes |
public static EyeParams transform(Viewport viewport) { int eye = viewport == VirtualReality.head.getLeftEye() ? 0 : 1; EyeParams eyeParams = new EyeParams(eye); eyeParams.getViewport().setViewport(viewport.getScreenX(), viewport.getScreenY(), MathUtils.nextPowerOfTwo(viewport.getScreenWidth()), MathUtils.nextPowerOfTwo(viewport.getScreenHeight())); float fov = ((PerspectiveCamera) viewport.getCamera()).fieldOfView; eyeParams.getFov().setLeft(fov); eyeParams.getFov().setRight(fov); eyeParams.getFov().setTop(fov); eyeParams.getFov().setBottom(fov); for (int i = 0; i < 16; i++) { eyeParams.getTransform().getEyeView()[i] = viewport.getCamera().view.val[i]; } for (int i = 0; i < 16; i++) { eyeParams.getTransform().getPerspective()[i] = viewport.getCamera().projection.val[i]; } return eyeParams; }
Example #5
Source File: Renderer.java From VuforiaLibGDX with MIT License | 6 votes |
public Renderer() { lights = new Environment(); lights.set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE)); camera = new PerspectiveCamera(60, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.near = 1.0F; camera.far = 1000.0F; //set camera into "Vuforia - style" direction camera.position.set(new Vector3(0,0,0)); camera.lookAt(new Vector3(0,0,1)); IntBuffer buffer = BufferUtils.newIntBuffer(16); Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_IMAGE_UNITS, buffer); int units = buffer.get(0); Log.d("TAG", "Max texture units: "+units); modelBatch = new ModelBatch(new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 0))); }
Example #6
Source File: RadixClient.java From Radix with MIT License | 6 votes |
private void setupOGL() { camera = new PerspectiveCamera(90, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.position.set(10f, 150f, 10f); camera.lookAt(0, 0, 0); camera.near = 0.1f; camera.far = 450f; camera.update(); hudCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); guiBatch = new SpriteBatch(); guiBatch.setProjectionMatrix(hudCamera.combined); if(android) { setupTouchControls(); } Gdx.input.setInputProcessor(new RadixInputHandler(this)); if(settingsManager.getVisualSettings().getNonContinuous().getValue()) { Gdx.graphics.setContinuousRendering(false); } sceneTheme = new SceneTheme(); sceneTheme.init(); }
Example #7
Source File: Scene.java From Mundus with Apache License 2.0 | 6 votes |
public Scene() { environment = new MundusEnvironment(); currentSelection = null; terrains = new Array<TerrainAsset>(); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(0, 1, -3); cam.lookAt(0, 1, -1); cam.near = 0.2f; cam.far = 10000; DirectionalLight dirLight = new DirectionalLight(); dirLight.color.set(1, 1, 1, 1); dirLight.intensity = 1f; dirLight.direction.set(0, -1f, 0); dirLight.direction.nor(); environment.add(dirLight); environment.getAmbientLight().intensity = 0.3f; sceneGraph = new SceneGraph(this); }
Example #8
Source File: GLTFQuickStartExample.java From gdx-gltf with Apache License 2.0 | 5 votes |
@Override public void create() { // create scene sceneAsset = new GLTFLoader().load(Gdx.files.internal("models/BoomBox/glTF/BoomBox.gltf")); scene = new Scene(sceneAsset.scene); sceneManager = new SceneManager(); sceneManager.addScene(scene); // setup camera camera = new PerspectiveCamera(60f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); float d = .02f; camera.near = d / 1000f; camera.far = d * 4; sceneManager.setCamera(camera); // setup light light = new DirectionalLightEx(); light.direction.set(1, -3, 1).nor(); light.color.set(Color.WHITE); sceneManager.environment.add(light); // setup quick IBL (image based lighting) IBLBuilder iblBuilder = IBLBuilder.createOutdoor(light); environmentCubemap = iblBuilder.buildEnvMap(1024); diffuseCubemap = iblBuilder.buildIrradianceMap(256); specularCubemap = iblBuilder.buildRadianceMap(10); iblBuilder.dispose(); brdfLUT = new Texture(Gdx.files.classpath("net/mgsx/gltf/shaders/brdfLUT.png")); sceneManager.setAmbientLight(1f); sceneManager.environment.set(new PBRTextureAttribute(PBRTextureAttribute.BRDFLUTTexture, brdfLUT)); sceneManager.environment.set(PBRCubemapAttribute.createSpecularEnv(specularCubemap)); sceneManager.environment.set(PBRCubemapAttribute.createDiffuseEnv(diffuseCubemap)); // setup skybox skybox = new SceneSkybox(environmentCubemap); sceneManager.setSkyBox(skybox); }
Example #9
Source File: Stage3d.java From Scene3d with Apache License 2.0 | 5 votes |
public Stage3d (float width, float height, PerspectiveCamera camera, Environment environment) { this.width = width; this.height = height; root = new Group3d(); root.setStage3d(this); modelBatch = new ModelBatch(); this.camera = camera; this.environment = environment; }
Example #10
Source File: Stage3d.java From Scene3d with Apache License 2.0 | 5 votes |
public Stage3d (float width, float height, PerspectiveCamera camera) { this.width = width; this.height = height; root = new Group3d(); root.setStage3d(this); modelBatch = new ModelBatch(); this.camera = camera; }
Example #11
Source File: WorldRenderer.java From Cubes with MIT License | 5 votes |
public WorldRenderer() { camera = new PerspectiveCamera(Settings.getIntegerSettingValue(Settings.GRAPHICS_FOV), Graphics.RENDER_WIDTH, Graphics.RENDER_HEIGHT) { @Override public void update(boolean b) { viewportWidth = Graphics.RENDER_WIDTH; viewportHeight = Graphics.RENDER_HEIGHT; super.update(b); } }; camera.near = 0.1f; camera.far = Math.max( 300f, Settings.getIntegerSettingValue(Settings.GRAPHICS_VIEW_DISTANCE) * SIZE_BLOCKS * 1.25f); Cubes.getClient().inputChain.cameraController = new CameraController(camera); }
Example #12
Source File: FluidSimulatorGeneric.java From fluid-simulator-v2 with Apache License 2.0 | 5 votes |
public FluidSimulatorGeneric(FluidSimulatorStarter fluidSimulatorStarter) { this.game = fluidSimulatorStarter; // LibGDX single batches cannot have a size more than 5460 batch = new SpriteBatch(IS_DESKTOP ? 5460 : ANDROID_SIZE); font = new BitmapFont(); camera = new OrthographicCamera(WORLD_WIDTH, WORLD_HEIGHT); camera.position.set(0, (WORLD_HEIGHT / 2) - 1, 0); immediateRenderer = new ImmediateModeRenderer20(SIZE*6, false, true, 0); irt = new Renderer20(SIZE*6, false, true, 1); irt2 = new ImmediateModeRenderer20(SIZE*11, false, true, 1); shapeRenderer = new ShapeRenderer(SIZE); renderer = new Box2DDebugRenderer(true, true, false, true, false, false); //3D camera3D = new PerspectiveCamera(67, WORLD_WIDTH, WORLD_HEIGHT); camera3D.position.set(0, 130f, 250f); camera3D.lookAt(0,150f,0); camera3D.near = 0.1f; camera3D.far = 500f; camera3D.update(); ModelBuilder modelBuilder = new ModelBuilder(); // model = modelBuilder.createSphere(5f, 5f, 5f, 4, 4, GL10.GL_TRIANGLES, // new Material(ColorAttribute.createDiffuse(Color.GREEN)), // Usage.Position | Usage.Normal); model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal); instance = new ModelInstance(model); modelBatch = new ModelBatch(); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f)); environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, 0, -0.8f, -0.2f)); camController = new Camera3DController(camera3D); camController.setFluidSimulator(this); world = new World(new Vector2(0, -9.8f), false); world.setContactListener(this); }
Example #13
Source File: WorldGenerator.java From Skyland with MIT License | 5 votes |
public static PerspectiveCamera generatePerspectiveCamera(float near, float far, Vector3 position, Vector3 lookat) { PerspectiveCamera camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.position.set(position); camera.lookAt(lookat); camera.near = near; camera.far = far; camera.update(); return camera; }
Example #14
Source File: ToolHandlePicker.java From Mundus with Apache License 2.0 | 5 votes |
private void renderPickableScene(ToolHandle[] handles, ModelBatch batch, PerspectiveCamera cam) { batch.begin(cam); for (ToolHandle handle : handles) { handle.renderPick(batch); } batch.end(); }
Example #15
Source File: GLTFCameraExporter.java From gdx-gltf with Apache License 2.0 | 5 votes |
private GLTFCamera export(Camera camera) { GLTFCamera glCamera = new GLTFCamera(); if(camera instanceof PerspectiveCamera){ PerspectiveCamera pcam = (PerspectiveCamera)camera; glCamera.type = "perspective"; glCamera.perspective = new GLTFPerspective(); glCamera.perspective.yfov = pcam.fieldOfView * MathUtils.degreesToRadians; // TODO not sure glCamera.perspective.znear = camera.near; glCamera.perspective.zfar = camera.far; glCamera.perspective.aspectRatio = camera.viewportWidth / camera.viewportHeight; // TODO not sure // TODO aspect ratio and fov should be recomputed... } else if(camera instanceof OrthographicCamera){ OrthographicCamera ocam = (OrthographicCamera)camera; glCamera.type = "orthographic"; glCamera.orthographic = new GLTFOrthographic(); glCamera.orthographic.znear = camera.near; glCamera.orthographic.zfar = camera.far; glCamera.orthographic.xmag = camera.viewportWidth * ocam.zoom; // TODO not sure glCamera.orthographic.ymag = camera.viewportHeight * ocam.zoom; // TODO not sure } else{ throw new GdxRuntimeException("unsupported camera type " + camera.getClass()); } return glCamera; }
Example #16
Source File: GLTFPostProcessingExample.java From gdx-gltf with Apache License 2.0 | 5 votes |
@Override public void create() { sceneManager = createSceneManager(); sceneManager.camera = camera = new PerspectiveCamera(); camera.fieldOfView = 50; camera.near = 0.01f; camera.far = 10f; camera.position.set(1, 1, 1).scl(.1f); camera.up.set(Vector3.Y); camera.lookAt(Vector3.Zero); camera.update(); // load user scene SceneAsset asset = new GLTFLoader().load(Gdx.files.internal("models/BoomBox/glTF/BoomBox.gltf")); sceneManager.addScene(new Scene(asset.scene)); cameraController = new CameraInputController(camera); cameraController.translateUnits = .1f; Gdx.input.setInputProcessor(cameraController); viewport = new FitViewport(1000, 500, camera); // post processing if(postProcessingEnabled){ fbo = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); effectShader = new ShaderProgram(Gdx.files.classpath("shaders/effect.vs.glsl"), Gdx.files.classpath("shaders/effect.fs.glsl")); batch = new SpriteBatch(); } }
Example #17
Source File: GLTFExample.java From gdx-gltf with Apache License 2.0 | 5 votes |
@Override public void create() { // create scene sceneAsset = new GLTFLoader().load(Gdx.files.internal("models/BoomBox/glTF/BoomBox.gltf")); scene = new Scene(sceneAsset.scene); sceneManager = new SceneManager(); sceneManager.addScene(scene); // setup camera camera = new PerspectiveCamera(60f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); float d = .02f; camera.near = d / 1000f; camera.far = d * 4; sceneManager.setCamera(camera); // setup IBL (image based lighting) environmentCubemap = EnvironmentUtil.createCubemap(new InternalFileHandleResolver(), "textures/environment/environment_", "_0.png", EnvironmentUtil.FACE_NAMES_FULL); diffuseCubemap = EnvironmentUtil.createCubemap(new InternalFileHandleResolver(), "textures/diffuse/diffuse_", "_0.jpg", EnvironmentUtil.FACE_NAMES_FULL); specularCubemap = EnvironmentUtil.createCubemap(new InternalFileHandleResolver(), "textures/specular/specular_", "_", ".jpg", 10, EnvironmentUtil.FACE_NAMES_FULL); brdfLUT = new Texture(Gdx.files.classpath("net/mgsx/gltf/shaders/brdfLUT.png")); sceneManager.setAmbientLight(1f); sceneManager.environment.set(new PBRTextureAttribute(PBRTextureAttribute.BRDFLUTTexture, brdfLUT)); sceneManager.environment.set(PBRCubemapAttribute.createSpecularEnv(specularCubemap)); sceneManager.environment.set(PBRCubemapAttribute.createDiffuseEnv(diffuseCubemap)); // setup skybox skybox = new SceneSkybox(environmentCubemap); sceneManager.setSkyBox(skybox); }
Example #18
Source File: GLTFInspector.java From gdx-gltf with Apache License 2.0 | 5 votes |
private void logCameras(Array<Camera> cameras) { int nPerspective = 0; int nOrtho = 0; for(Camera camera : cameras){ if(camera instanceof OrthographicCamera){ nOrtho++; }else if(camera instanceof PerspectiveCamera){ nPerspective++; } } log("Cameras", "count", cameras.size, "perspective", nPerspective, "orthographic", nOrtho); }
Example #19
Source File: RenderWidget.java From Mundus with Apache License 2.0 | 4 votes |
public void setCam(PerspectiveCamera cam) { this.cam = cam; viewport.setCamera(cam); }
Example #20
Source File: RenderWidget.java From Mundus with Apache License 2.0 | 4 votes |
public RenderWidget(PerspectiveCamera cam) { super(); this.cam = cam; viewport = new ScreenViewport(this.cam); }
Example #21
Source File: GameWorldRenderer.java From uracer-kotd with Apache License 2.0 | 4 votes |
public PerspectiveCamera getPerspectiveCamera () { return camPersp; }
Example #22
Source File: TrackTrees.java From uracer-kotd with Apache License 2.0 | 4 votes |
public void transform (PerspectiveCamera camPersp, OrthographicCamera camOrtho) { float meshZ = -(camPersp.far - camPersp.position.z) + (camPersp.far * (1 - (camOrtho.zoom))); for (int i = 0; i < models.size(); i++) { TreeStillModel m = models.get(i); Matrix4 transf = m.transformed; // compute position tmpvec.x = (m.positionOffsetPx.x - camPersp.position.x) + (camPersp.viewportWidth / 2) + m.positionPx.x; tmpvec.y = (m.positionOffsetPx.y + camPersp.position.y) + (camPersp.viewportHeight / 2) - m.positionPx.y; tmpvec.z = 1; tmpvec.x *= ScaleUtils.Scale; tmpvec.y *= ScaleUtils.Scale; tmpvec.x += ScaleUtils.CropX; tmpvec.y += ScaleUtils.CropY; // transform to world space camPersp.unproject(tmpvec, ScaleUtils.CropX, ScaleUtils.CropY, ScaleUtils.PlayWidth, ScaleUtils.PlayHeight); // build model matrix Matrix4 model = m.mtxmodel; tmpvec.z = meshZ; model.idt(); model.translate(tmpvec); model.rotate(m.iRotationAxis, m.iRotationAngle); model.scale(m.scaleAxis.x, m.scaleAxis.y, m.scaleAxis.z); // comb = (proj * view) * model (fast mul) transf.set(camPersp.combined).mul(m.mtxmodel); // transform the bounding box m.boundingBox.inf().set(m.localBoundingBox); m.boundingBox.mul(m.mtxmodel); // create an AABB out of the corners of the original // AABB transformed by the model matrix // bb.inf(); // Vector3[] corners = m.localBoundingBox.getCorners(); // for(int k = 0; k < corners.length; k++) // { // vtrans[k].x = corners[k].x; // vtrans[k].y = corners[k].y; // vtrans[k].z = corners[k].z; // vtrans[k].mul( tmpmtx ); // bb.ext(vtrans[k]); // } // // m.boundingBox.inf(); // m.boundingBox.set( bb ); } }
Example #23
Source File: Stage3d.java From Scene3d with Apache License 2.0 | 4 votes |
public PerspectiveCamera getCamera () { return camera; }
Example #24
Source File: Stage3d.java From Scene3d with Apache License 2.0 | 4 votes |
/** Sets the stage's camera. The camera must be configured properly or {@link #setViewport(float, float, boolean)} can be called * after the camera is set. {@link Stage#draw()} will call {@link Camera#update()} and use the {@link Camera#combined} matrix * for the SpriteBatch {@link SpriteBatch#setProjectionMatrix(com.badlogic.gdx.math.Matrix4) projection matrix}. */ public void setCamera (PerspectiveCamera camera) { this.camera = camera; }
Example #25
Source File: GroundChunk.java From gdx-proto with Apache License 2.0 | 4 votes |
public boolean isVisible (PerspectiveCamera cam) { return cam.frustum.sphereInFrustum(position, radius); }
Example #26
Source File: View.java From gdx-proto with Apache License 2.0 | 4 votes |
public View() { ModelManager modelManager = new ModelManager(); modelManager.init(); storeSize(); inst = this; gl = Gdx.graphics.getGL20(); float fov = 67f; camera = new PerspectiveCamera(fov, width(), height()); // camera.far affects frustrum culling, so a shorter distance can boost performance camera.far = 60f; camera.near = 0.01f; resetCamera(); initShaders(); modelBatch = new ModelBatch(shaderProvider); environ = new Environment(); basicEnviron = new Environment(); camLight = new PointLight(); float intensity = 100f; camLight.set(new Color(0.2f, 0.2f, 0.2f, 1f), 0f, 0f, 0f, intensity); ColorAttribute ambientLight = ColorAttribute.createAmbient(new Color(0.1f, 0.1f, 0.1f, 1f)); environ.set(ambientLight); ColorAttribute fog = new ColorAttribute(ColorAttribute.Fog); fog.color.set(fogColor); environ.set(fog); environ.add(camLight); dirLight = new DirectionalLight(); dirLight.set(new Color(0.3f, 0.3f, 0.35f, 1f), -0.25f, -0.75f, 0.25f); environ.add(dirLight); basicEnviron.set(ColorAttribute.createAmbient(0.3f, 0.3f, 0.3f, 1f)); if (Toggleable.profileGL()) { Profiler.enable(); } hud = new HUD(); Sky.createSkyBox( Assets.manager.get("textures/skybox/xpos.png", Texture.class), Assets.manager.get("textures/skybox/xneg.png", Texture.class), Assets.manager.get("textures/skybox/ypos.png", Texture.class), Assets.manager.get("textures/skybox/yneg.png", Texture.class), Assets.manager.get("textures/skybox/zpos.png", Texture.class), Assets.manager.get("textures/skybox/zneg.png", Texture.class) ); }
Example #27
Source File: View.java From gdx-proto with Apache License 2.0 | 4 votes |
public PerspectiveCamera getCamera() { return camera; }
Example #28
Source File: RadixClient.java From Radix with MIT License | votes |
public PerspectiveCamera getCamera() { return camera; }