com.badlogic.gdx.graphics.Camera Java Examples

The following examples show how to use com.badlogic.gdx.graphics.Camera. 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: RendererSystem.java    From Entitas-Java with MIT License 6 votes vote down vote up
public RendererSystem(Entitas entitas, Camera cam, Batch batch, World world) {
    this.physics = world;
    this.cam = cam;
    this.batch = batch;
    this.entitas = entitas;
    _groupTextureView = entitas.game.getGroup(GameMatcher.TextureView());
    this.debugShapeRenderer = new ShapeRenderer();
    this.debugRenderer = new Box2DDebugRenderer(DRAW_BOX2D_BODIES, DRAW_BOX2D_JOINTS, DRAW_BOX2D_ABBs,
            DRAW_BOX2D_INACTIVE_BODIES, DRAW_BOX2D_VELOCITIES, DRAW_BOX2D_CONTACTS);
    debugRenderer.setDrawAABBs(DRAW_BOX2D_ABBs);
    debugRenderer.setDrawBodies(DRAW_BOX2D_BODIES);
    debugRenderer.setDrawContacts(DRAW_BOX2D_CONTACTS);
    debugRenderer.setDrawInactiveBodies(DRAW_BOX2D_INACTIVE_BODIES);
    debugRenderer.setDrawJoints(DRAW_BOX2D_JOINTS);
    debugRenderer.setDrawVelocities(DRAW_BOX2D_VELOCITIES);
    this.inputs = entitas.input.getGroup(InputMatcher.Input());
}
 
Example #2
Source File: SplashState.java    From Entitas-Java with MIT License 6 votes vote down vote up
@Override
public void initialize() {
    // Input
    Camera camera = engine.getManager(BaseSceneManager.class).getDefaultCamera();
    Batch batch = engine.getManager(BaseSceneManager.class).getBatch();
    BitmapFont font = engine.getManager(BaseGUIManager.class).getDefaultFont();
    systems.add(new DelaySystem(context.core))
            .add(new RendererSystem(context.core, engine.sr, camera, batch, font));

    Texture texture = assetsManager.getTexture(splash);

    context.core.createEntity()
            .addTextureView("Pong", new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()), new Vector2(),
                    0, Pong.SCREEN_HEIGHT, Pong.SCREEN_WIDTH)
            .addDelay(3);
}
 
Example #3
Source File: CameraShake.java    From xibalba with MIT License 6 votes vote down vote up
/**
 * Called each frame to handle the shaking.
 *
 * @param delta    Time since last frame
 * @param camera   Camera to shake
 * @param position Position to snap back to afterwards
 */
public void update(float delta, Camera camera, Vector2 position) {
  if (currentTime <= time) {
    currentPower = power * ((time - currentTime) / time);
    float posX = (random.nextFloat() - 0.5f) * 2 * currentPower;
    float posY = (random.nextFloat() - 0.5f) * 2 * currentPower;

    camera.translate(-posX, -posY, 0);

    currentTime += delta;
  } else {
    time = 0;
    currentTime = 0;

    camera.position.set(
        position.x * Main.SPRITE_WIDTH,
        position.y * Main.SPRITE_HEIGHT, 0
    );
  }
}
 
Example #4
Source File: MatchOneState.java    From Entitas-Java with MIT License 5 votes vote down vote up
@Override
public void initialize() {
    entitas = new Entitas();
    EntityIndexExtension.addEntityIndices(entitas);
    // Input
    World physics = engine.getManager(BasePhysicsManager.class).getPhysics();
    BodyBuilder bodyBuilder = engine.getManager(BasePhysicsManager.class).getBodyBuilder();
    Camera camera = engine.getManager(BaseSceneManager.class).getDefaultCamera();
    Batch batch = engine.getManager(BaseSceneManager.class).getBatch();

    EmitInputSystem emitInputSystem = new EmitInputSystem(entitas.input, physics, camera );
    systems
            .add(new ProcessInputSystem(entitas))
            // Update
            .add(new GameBoardSystem(entitas.game))
            .add(new FallSystem(entitas.game))
            .add(new FillSystem(entitas.game))
            .add(new ScoreSystem(entitas))
            // Render
            .add(new RemoveViewSystem(entitas.game, physics))
            .add(new AddViewSystem(entitas.game, assetsManager, bodyBuilder ))
            .add(new AnimatePositionSystem(entitas.game))
            // Destroy
            .add(new DestroySystem(entitas.game))
            .add(new RendererSystem(entitas, camera, batch, physics))
    ;
}
 
Example #5
Source File: Scene.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public Camera getCamera(String name) {
	for(Entry<Node, Camera> e : cameras){
		if(name.equals(e.key.id)){
			return e.value;
		}
	}
	return null;
}
 
Example #6
Source File: GameRenderer.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if a model is visible using camera frustum culling and model layer visibility.
 *
 * @param camera
 * @param gameModel
 * @return
 */
private boolean isVisible(final Camera camera, final GameModel gameModel) {
	if (!gameModel.visibleOnLayers.intersects(engine.getVisibleLayers())) {
		return false;
	}
	gameModel.modelInstance.transform.getTranslation(tmp);
	tmp.add(gameModel.center);
	return camera.frustum.sphereInFrustum(tmp, gameModel.boundingBoxRadius);
}
 
Example #7
Source File: DesktopController.java    From Cubes with MIT License 5 votes vote down vote up
public static boolean handleClick(ClickType type) {
  Player player = Cubes.getClient().player;
  ItemStack itemStack = player.getInventory().selectedItemStack();
  Camera camera = Cubes.getClient().renderer.worldRenderer.camera;
  BlockIntersection blockIntersection = BlockIntersection.getBlockIntersection(camera.position, camera.direction, Cubes.getClient().world);
  if (blockIntersection != null) {
    BlockReference r = blockIntersection.getBlockReference();
    Block b = Cubes.getClient().world.getBlock(r.blockX, r.blockY, r.blockZ);
    if (b.onButtonPress(type, player, r.blockX, r.blockY, r.blockZ)) return true;
  }
  return itemStack != null && itemStack.item.onButtonPress(type, itemStack, player, player.getInventory().hotbarSelected);
}
 
Example #8
Source File: SceneSkybox.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
@Override
public void update(Camera camera, float delta){
	// scale skybox to camera range.
	float s = camera.far * (float)Math.sqrt(2.0);
	box.worldTransform.setToScaling(s, s, s);
	box.worldTransform.setTranslation(camera.position);
}
 
Example #9
Source File: NavMeshDebugDrawer.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
public void drawNavMesh(MyShapeRenderer shapeRenderer,
						SpriteBatch spriteBatch,
						NavMesh navMesh,
						GameCharacter character,
						Bits visibleLayers,
						Camera camera,
						BitmapFont font) {

	this.visibleLayers = visibleLayers;
	this.shapeRenderer = shapeRenderer;
	this.navMesh = navMesh;

	if (shapeRenderer.isDrawing()) {
		shapeRenderer.end();
	}

	Gdx.gl.glEnable(GL20.GL_BLEND);
	Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
	shapeRenderer.begin(MyShapeRenderer.ShapeType.Line);
	drawNavMeshTriangles();
	if (character != null && character.steerer instanceof FollowPathSteerer) {
		FollowPathSteerer fpSteerer = (FollowPathSteerer)character.steerer;
		drawPathTriangles(fpSteerer.navMeshGraphPath, character.getCurrentTriangle());
		if (fpSteerer.navMeshPointPath.getSize() > 0) {
			drawPathPoints(fpSteerer.navMeshPointPath);
		}
		drawClosestPointDebug(character);
	}
	shapeRenderer.end();
	Gdx.gl.glDisable(GL20.GL_BLEND);

	drawNavMeshIndices(spriteBatch, camera, font);
}
 
Example #10
Source File: GLTFDemoUI.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public void setCameras(ObjectMap<Node, Camera> cameras) {
	Array<String> cameraNames = new Array<String>();
	cameraNames.add("");
	for(Entry<Node, Camera> e : cameras){
		cameraNames.add(e.key.id);
	}
	cameraSelector.setItems();
	cameraSelector.setItems(cameraNames);
}
 
Example #11
Source File: GLTFCameraExporter.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public void export(ObjectMap<Node, Camera> cameras) {
	for(Entry<Node, Camera> entry : cameras){
		int nodeID = base.nodeMapping.indexOf(entry.key, true);
		if(nodeID < 0) throw new GdxRuntimeException("node not found");
		GLTFNode glNode = base.root.nodes.get(nodeID);
		if(base.root.cameras == null){
			base.root.cameras = new Array<GLTFCamera>();
		}
		glNode.camera = base.root.cameras.size;
		base.root.cameras.add(export(entry.value));
	}
}
 
Example #12
Source File: GLTFCameraExporter.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
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 #13
Source File: PauseMenuUI.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void initVariables(Camera camera) {
	stage = new Stage(new ScreenViewport(camera));
	menuTable = new Table();
	menuTable.setDebug(false);
	menuTable.setFillParent(true);
	this.setVisible(false);
}
 
Example #14
Source File: CameraController.java    From Skyland with MIT License 5 votes vote down vote up
public CameraController(Camera camera, float minZoom, float maxZoom, float minRotationY, float maxRotationY) {
    super(camera);
    this.minZoom = minZoom;
    this.maxZoom = maxZoom;
    this.minRotationY = minRotationY / 10;
    this.maxRotationY = maxRotationY / 10;
    this.pinchZoomFactor *= 2;
}
 
Example #15
Source File: EmitInputSystem.java    From Entitas-Java with MIT License 5 votes vote down vote up
public EmitInputSystem(InputContext context, World world, Camera cam) {
    this.context = context;
    this.inputs = context.getGroup(InputMatcher.Input());
    this.world = world;
    this.cam = cam;
    Gdx.input.setInputProcessor(this);
}
 
Example #16
Source File: CameraActuator.java    From Entitas-Java with MIT License 5 votes vote down vote up
public CameraActuator(Camera camera, short height, float damping, float minDistanceX, float minDistanceY, String followTagEntity) {
    this.actuator = (indexOwner) -> {
        Set<GameEntity> followEntities = Indexed.getTagEntities(followTagEntity);
        for (GameEntity followEntity : followEntities) {
            RigidBody rc = followEntity.getRigidBody();
            Transform transform = rc.body.getTransform();
            Vector3 position = camera.position;
            position.x += (transform.getPosition().x + minDistanceX - position.x) * damping;
            position.y += (transform.getPosition().y + minDistanceY - position.y) * height;
        }
    };

}
 
Example #17
Source File: PongState.java    From Entitas-Java with MIT License 5 votes vote down vote up
@Override
public void initialize() {
    // Input
    Camera camera = engine.getManager(BaseSceneManager.class).getDefaultCamera();
    Batch batch = engine.getManager(BaseSceneManager.class).getBatch();
    BitmapFont font = engine.getManager(BaseGUIManager.class).getDefaultFont();
    context.core.createEntity()
            .addBall(false)
            .addView(new Circle(0, 0, 8))
            .addMotion(MathUtils.clamp(1, 230, 300), 300);

    context.core.createEntity()
            .addPlayer(Player.ID.PLAYER1)
            .addScore("Player 1: ", 180, 470)
            .addView(new Rectangle(-350, 0, Pong.PLAYER_WIDTH, Pong.PLAYER_HEIGHT))
            .addMotion(0, 0);

    context.core.createEntity()
            .addPlayer(Player.ID.PLAYER2)
            .addScore("Player 2: ", 480, 470)
            .addView(new Rectangle(350, 0, Pong.PLAYER_WIDTH, Pong.PLAYER_HEIGHT))
            .addMotion(0, 0);

    systems.add(new InputSystem(context.core))
            .add(new ContactSystem(context.core))
            .add(new BoundsSystem(context.core))
            .add(new MoveSystem(context.core))
            .add(new RendererSystem(context.core, engine.sr, camera, batch, font));
}
 
Example #18
Source File: VirtualScreenViewport.java    From libgdx-snippets with MIT License 5 votes vote down vote up
/**
 * Does not call {@link com.badlogic.gdx.graphics.glutils.HdpiUtils#glViewport(int, int, int, int)}.
 */
@Override
public void apply(boolean centerCamera) {
	Camera camera = getCamera();
	camera.viewportWidth = getWorldWidth();
	camera.viewportHeight = getWorldHeight();
	if (centerCamera) {
		camera.position.set(getWorldWidth() / 2, getWorldHeight() / 2, 0);
	}
	camera.update();
}
 
Example #19
Source File: TerrainShader.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public void begin(Camera camera, RenderContext context) {
    this.context = context;
    context.begin();
    context.setCullFace(GL20.GL_BACK);

    this.context.setDepthTest(GL20.GL_LEQUAL, 0f, 1f);
    this.context.setDepthMask(true);

    program.begin();

    set(UNIFORM_PROJ_VIEW_MATRIX, camera.combined);
    set(UNIFORM_CAM_POS, camera.position);
}
 
Example #20
Source File: PlayerBattleHUD.java    From Norii with Apache License 2.0 5 votes vote down vote up
public PlayerBattleHUD(Camera camera, Entity[] sortedUnits) {
	initVariables(camera, sortedUnits);
	createTileHoverParticle();
	createBottomMenu(sortedUnits);
	createPortraits(sortedUnits);
	createHPBars(sortedUnits);
	createActionUIs(sortedUnits);
	createStatusUIs(sortedUnits);
}
 
Example #21
Source File: CubesShaderProvider.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public void begin(ShaderProgram program, Camera camera, RenderContext context) {
  TextureAttribute textureAttribute = AmbientOcclusion.getTextureAttribute();

  ao_unit = context.textureBinder.bind(textureAttribute.textureDescription);
  program.setUniformi(u_aoTexture, ao_unit);
  program.setUniformf(u_aoUVTransform, textureAttribute.offsetU, textureAttribute.offsetV, textureAttribute.scaleU, textureAttribute.scaleV);
  program.setUniformf(u_aoStrength, AmbientOcclusion.getStrength().strength);
}
 
Example #22
Source File: RayCastListener.java    From Skyland with MIT License 4 votes vote down vote up
public RayCastListener(BulletWorld world, Camera camera) {
    this.world = world;
    this.camera = camera;
}
 
Example #23
Source File: ChaseCam.java    From ud406 with MIT License 4 votes vote down vote up
public ChaseCam(Camera camera, GigaGal target) {
    this.camera = camera;
    this.target = target;
    following = true;
}
 
Example #24
Source File: ChaseCam.java    From ud406 with MIT License 4 votes vote down vote up
public ChaseCam(Camera camera, GigaGal target) {
    this.camera = camera;
    this.target = target;
    following = true;
}
 
Example #25
Source File: ChaseCam.java    From ud406 with MIT License 4 votes vote down vote up
public ChaseCam(Camera camera, GigaGal target) {
    this.camera = camera;
    this.target = target;
    following = true;
}
 
Example #26
Source File: ChaseCam.java    From ud406 with MIT License 4 votes vote down vote up
public ChaseCam(Camera camera, GigaGal target) {
    this.camera = camera;
    this.target = target;
    following = true;
}
 
Example #27
Source File: ChaseCam.java    From ud406 with MIT License 4 votes vote down vote up
public ChaseCam(Camera camera, GigaGal target) {
    this.camera = camera;
    this.target = target;
    following = true;
}
 
Example #28
Source File: ChaseCam.java    From ud406 with MIT License 4 votes vote down vote up
public ChaseCam(Camera camera, GigaGal target) {
    this.camera = camera;
    this.target = target;
    following = true;
}
 
Example #29
Source File: InterruptibleHierarchicalTiledAStarTest.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
public Camera getCamera () {
	return container.stage.getViewport().getCamera();
}
 
Example #30
Source File: ChaseCam.java    From ud406 with MIT License 4 votes vote down vote up
public ChaseCam(Camera camera, GigaGal target) {
    this.camera = camera;
    this.target = target;
    following = true;
}