com.badlogic.gdx.utils.viewport.Viewport Java Examples

The following examples show how to use com.badlogic.gdx.utils.viewport.Viewport. 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: GameRenderer.java    From GdxDemo3D with Apache License 2.0 6 votes vote down vote up
public GameRenderer(Viewport viewport, Camera camera, GameEngine engine) {
	this.viewport = viewport;
	this.camera = camera;
	this.engine = engine;

	shapeRenderer = new MyShapeRenderer();
	shapeRenderer.setAutoShapeType(true);

	spriteBatch = new SpriteBatch();
	font = new BitmapFont();
	font.setColor(Color.WHITE);
	font.setUseIntegerPositions(false);
	font.getData().setScale(0.01f);
	shadowBatch = new ModelBatch(new DepthShaderProvider());

	ShaderProgram.pedantic = false;
	final String vertUber = Gdx.files.internal("shaders/uber.vert").readString();
	final String fragUber = Gdx.files.internal("shaders/uber.frag").readString();
	modelBatch = new ModelBatch(new DefaultShaderProvider(vertUber, fragUber) {
		@Override
		protected Shader createShader(final Renderable renderable) {
			return new UberShader(renderable, config);
		}
	});
}
 
Example #2
Source File: BouncingBall.java    From ud405 with MIT License 6 votes vote down vote up
public void update(float delta, Viewport viewport) {

        float secondsSinceLastKick = MathUtils.nanoToSec * (TimeUtils.nanoTime() - lastKick);

        if (secondsSinceLastKick > KICK_INTERVAL) {
            lastKick = TimeUtils.nanoTime();
            randomKick();
        }

        // Drag is proportional to the current velocity
        velocity.x -= delta * DRAG * velocity.x;
        velocity.y -= delta * DRAG * velocity.y;

        position.x += delta * velocity.x;
        position.y += delta * velocity.y;
        radius = RADIUS_FACTOR * Math.min(viewport.getWorldWidth(), viewport.getWorldHeight());

        collideWithWalls(radius, viewport.getWorldWidth(), viewport.getWorldHeight());
    }
 
Example #3
Source File: VfxWidgetGroup.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
private void performPendingResize() {
    if (!resizePending) return;

    final int width;
    final int height;

    // Size may be zero if the widget wasn't laid out yet.
    if ((int)getWidth() == 0 || (int)getHeight() == 0) {
        // If the size of the widget is not defined,
        // just resize to a small buffer to keep the memory footprint low.
        width = 16;
        height = 16;

    } else if (matchWidgetSize) {
        // Set buffer to match the size of the widget.
        width = MathUtils.floor(getWidth());
        height = MathUtils.floor(getHeight());

    } else {
        // Set buffer to match the screen pixel density.
        Viewport viewport = getStage().getViewport();
        float ppu = viewport.getScreenWidth() / viewport.getWorldWidth();
        width = MathUtils.floor(getWidth() * ppu);
        height = MathUtils.floor(getHeight() * ppu);

        rendererAdapter.updateOwnProjection();
    }

    vfxManager.resize(width, height);

    resizePending = false;
}
 
Example #4
Source File: Avalanche.java    From ud405 with MIT License 5 votes vote down vote up
public void update(float delta, Viewport viewport){
    Random random = new Random();
    if (random.nextFloat() < delta * SPAWNS_PER_SECOND){
        boulders.add(new Boulder(viewport));
    }

    for (int i = 0; i < boulders.size; i++){
        Boulder boulder = boulders.get(i);
        boulder.update(delta);
        if (boulder.isBelowScreen()){
            boulders.removeIndex(i);
        }
    }
}
 
Example #5
Source File: UIActors.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public InteractiveActor getActorAtInput(Viewport v) {

		cam.getInputUnProject(v, unprojectTmp);

		for (InteractiveActor uia : actors) {
			if (uia.canInteract() && uia.hit(unprojectTmp.x, unprojectTmp.y))
				return uia;
		}

		return null;
	}
 
Example #6
Source File: Level.java    From ud406 with MIT License 5 votes vote down vote up
public Level(Viewport viewport) {
    this.viewport = viewport;

    gigaGal = new GigaGal(Constants.DEFAULT_SPAWN_LOCATION, this);
    platforms = new Array<Platform>();
    enemies = new DelayedRemovalArray<Enemy>();
    bullets = new DelayedRemovalArray<Bullet>();
    explosions = new DelayedRemovalArray<Explosion>();
    powerups = new DelayedRemovalArray<Powerup>();
    exitPortal = new ExitPortal(Constants.EXIT_PORTAL_DEFAULT_LOCATION);
}
 
Example #7
Source File: BouncingBall.java    From ud405 with MIT License 5 votes vote down vote up
public void init(Viewport viewport) {
    position = new Vector2(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2);
    velocity = new Vector2();
    radiusMultiplier = 1;
    radius = BASE_RADIUS * radiusMultiplier;
    randomKick();
}
 
Example #8
Source File: BouncingBall.java    From ud405 with MIT License 5 votes vote down vote up
/**
 * TODO: Here's the polling action
 *
 * We've defined a base radius for the ball, and we determine the actual radius by multiplying
 * the base radius by the radius multiplier. We start the radius multiplier at 1.0, and then we
 * adjust it up or down each frame based on whether or not the Z or X keys are pressed. We also
 * have a radius growth rate constant that determines how fast the radius multiplier changes.
 *
 * Note that we also make sure the radius multiplier can't fall below a certain minimum. That
 * way we don't end up with an invisible ball with a negative radius.
 */
public void update(float delta, Viewport viewport) {

    if (Gdx.input.isKeyPressed(Keys.Z)) {
        radiusMultiplier += delta * RADIUS_GROWTH_RATE;
    }
    if (Gdx.input.isKeyPressed(Keys.X)) {
        radiusMultiplier -= delta * RADIUS_GROWTH_RATE;
        radiusMultiplier = Math.max(radiusMultiplier, MIN_RADIUS_MULTIPLIER);
    }
    radius = radiusMultiplier * BASE_RADIUS;

    float secondsSinceLastKick = MathUtils.nanoToSec * (TimeUtils.nanoTime() - lastKick);

    if (secondsSinceLastKick > KICK_INTERVAL) {
        lastKick = TimeUtils.nanoTime();
        randomKick();
    }

    velocity.x -= delta * DRAG * velocity.x;
    velocity.y -= delta * DRAG * velocity.y;

    position.x += delta * velocity.x;
    position.y += delta * velocity.y;


    collideWithWalls(radius, viewport.getWorldWidth(), viewport.getWorldHeight());
}
 
Example #9
Source File: VirtualRealityRenderer.java    From gdx-vr with Apache License 2.0 5 votes vote down vote up
private void renderEye(Viewport eye, Vector3 eyeOffset) {
	Camera camera = eye.getCamera();

	Vector3 eyePosition = camera.position;
	eyePosition.set(VirtualReality.body.position);

	Vector3 headOffset = new Vector3(0, VirtualReality.head.getEyeHeight() / 2f, 0);
	headOffset.mul(VirtualReality.body.orientation);
	eyePosition.add(headOffset);

	Quaternion eyeOrientation = new Quaternion();
	eyeOrientation.set(VirtualReality.head.getOrientation());
	eyeOrientation.mul(VirtualReality.body.orientation);

	eyeOffset.mul(eyeOrientation);
	eyePosition.add(eyeOffset);

	Vector3 eyeDirection = new Vector3(0, 0, -1);
	eyeDirection.mul(eyeOrientation);
	Vector3 eyeUp = new Vector3(0, 1, 0);
	eyeUp.mul(eyeOrientation);

	camera.position.set(eyePosition);
	camera.direction.set(eyeDirection);
	camera.up.set(eyeUp);

	camera.update(true);

	for (VirtualRealityRenderListener listener : listeners) {
		listener.render(camera);
	}
}
 
Example #10
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public Viewport getViewport() {
    return viewport;
}
 
Example #11
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public Viewport getViewport() {
    return viewport;
}
 
Example #12
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public void setViewport(Viewport viewport) {
    this.viewport = viewport;
}
 
Example #13
Source File: Player.java    From ud405 with MIT License 4 votes vote down vote up
public Player(Viewport viewport) {
    this.viewport = viewport;
    deaths = 0;
    init();
}
 
Example #14
Source File: Stage3D.java    From gdx-vr with Apache License 2.0 4 votes vote down vote up
public Stage3D(Plane plane, Viewport viewport, SpriteBatch batch) {
	super(viewport, batch);
	this.plane = plane;
}
 
Example #15
Source File: Player.java    From ud405 with MIT License 4 votes vote down vote up
public Player(Viewport viewport) {
    this.viewport = viewport;
    init();
}
 
Example #16
Source File: Player.java    From ud405 with MIT License 4 votes vote down vote up
public Player(Viewport viewport) {
    this.viewport = viewport;
    init();
}
 
Example #17
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public Level(Viewport viewport) {
    this.viewport = viewport;
    initializeDebugLevel();
}
 
Example #18
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public Viewport getViewport() {
    return viewport;
}
 
Example #19
Source File: LevelLoader.java    From ud406 with MIT License 4 votes vote down vote up
public static Level load(String levelName, Viewport viewport) {

        String path = Constants.LEVEL_DIR + File.separator + levelName + "." + Constants.LEVEL_FILE_EXTENSION;
        Level level = new Level(viewport);

        FileHandle file = Gdx.files.internal(path);
        JSONParser parser = new JSONParser();

        try {
            JSONObject rootJsonObject = (JSONObject) parser.parse(file.reader());

            JSONObject composite = (JSONObject) rootJsonObject.get(Constants.LEVEL_COMPOSITE);

            JSONArray platforms = (JSONArray) composite.get(Constants.LEVEL_9PATCHES);
            loadPlatforms(platforms, level);


        } catch (Exception ex) {
            Gdx.app.error(TAG, ex.getMessage());
            Gdx.app.error(TAG, Constants.LEVEL_ERROR_MESSAGE);
        }

        return level;
    }
 
Example #20
Source File: ScenePointer.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
private void getInputUnproject(Viewport v, Vector2 out) {
	out.set(Gdx.input.getX(), Gdx.input.getY());

	v.unproject(out);
}
 
Example #21
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public Level(Viewport viewport) {
    this.viewport = viewport;
    initializeDebugLevel();
}
 
Example #22
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public void setViewport(Viewport viewport) {
    this.viewport = viewport;
}
 
Example #23
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public Viewport getViewport() {
    return viewport;
}
 
Example #24
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public Level(Viewport viewport) {
    this.viewport = viewport;
    initializeDebugLevel();
}
 
Example #25
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public Viewport getViewport() {
    return viewport;
}
 
Example #26
Source File: BaseLayout.java    From libgdx-snippets with MIT License 4 votes vote down vote up
<T extends Actor> void resize(Stage stage, Actor actor, boolean root) {

		int parentWidth, parentHeight;

		if (root) {
			Viewport viewport = stage.getViewport();

			parentWidth = viewport.getScreenWidth();
			parentHeight = viewport.getScreenHeight();

		} else {
			Actor parent = actor.getParent();

			parentWidth = MathUtils.floor(parent.getWidth());
			parentHeight = MathUtils.floor(parent.getHeight());
		}

		int actorWidth = MathUtils.floor(actor.getWidth());
		int actorHeight = MathUtils.floor(actor.getHeight());

		/** Dynamic sizing of actor if we want percentage of parent (indicated by negative width) */
		if(width < 0){
			actorWidth = MathUtils.clamp(-width, 1, 100) * parentWidth / 100;

			actor.setWidth(actorWidth);
		}
		if(height < 0){
			actorHeight = MathUtils.clamp(-height, 1, 100) * parentHeight / 100;

			actor.setHeight(actorHeight);
		}

		int px = 0, py = 0;

		switch (anchor) {

			case Center:
				px = parentWidth / 2 - actorWidth / 2;
				py = parentHeight / 2 - actorHeight / 2;
				break;

			case Left:
				px = 0;
				py = parentHeight / 2 - actorHeight / 2;
				break;

			case Right:
				px = parentWidth - actorWidth;
				py = parentHeight / 2 - actorHeight / 2;
				break;

			case Bottom:
				px = parentWidth / 2 - actorWidth / 2;
				py = 0;
				break;

			case Top:
				px = parentWidth / 2 - actorWidth / 2;
				py = parentHeight - actorHeight;
				break;

			case BottomLeft:
				px = 0;
				py = 0;
				break;

			case BottomRight:
				px = parentWidth - actorWidth;
				py = 0;
				break;

			case TopLeft:
				px = 0;
				py = parentHeight - actorHeight;
				break;

			case TopRight:
				px = parentWidth - actorWidth;
				py = parentHeight - actorHeight;
				break;
		}

		px += x;
		py += y;

		actor.setPosition(px, py);
	}
 
Example #27
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public void setViewport(Viewport viewport) {
    this.viewport = viewport;
}
 
Example #28
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public Viewport getViewport() {
    return viewport;
}
 
Example #29
Source File: Level.java    From ud406 with MIT License 4 votes vote down vote up
public Level(Viewport viewport) {
    this.viewport = viewport;
    initializeDebugLevel();
}
 
Example #30
Source File: BouncingBall.java    From ud405 with MIT License 4 votes vote down vote up
public BouncingBall(Viewport viewport) {
    this.viewport = viewport;
    init();
}