use of com.badlogic.gdx.math.Vector2 in project netthreads-libgdx by alistairrutherford.
the class BodyUpdateAction method act.
/**
* Action.
*
*/
@Override
public boolean act(float delta) {
// Centre body.
Vector2 pos = body.getPosition();
if (centred) {
// Adjust the actor to centre
getActor().setX((pos.x * pixelsPerMetre) - getActor().getWidth() / 2);
getActor().setY((pos.y * pixelsPerMetre) - getActor().getHeight() / 2);
} else {
getActor().setX(pos.x * pixelsPerMetre);
getActor().setY(pos.y * pixelsPerMetre);
}
float angleDeg = body.getAngle() * MathUtils.radiansToDegrees;
getActor().setRotation(angleDeg);
return false;
}
use of com.badlogic.gdx.math.Vector2 in project libgdx-inGameConsole by StrongJoshua.
the class Box2DTest method render.
@Override
public void render() {
if (Gdx.input.isTouched()) {
float x = Gdx.input.getX();
float y = Gdx.input.getY();
if (!console.hitsConsole(x, y)) {
Vector3 worldVector = c.unproject(new Vector3(x, y, 0));
createExplosion(worldVector.x, worldVector.y, 2000);
console.log(String.format("Created touch explosion at %.2f, %.2f!", worldVector.x, worldVector.y), LogLevel.SUCCESS);
}
}
if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE))
Gdx.app.exit();
world.step(1 / 60f, 6, 2);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
for (int i = 0; i < bodies.length; i++) {
Vector2 pos = bodies[i].getPosition();
sprites[i].setPosition(pos.x - sprites[i].getWidth() / 2, pos.y - sprites[i].getHeight() / 2);
sprites[i].setRotation(MathUtils.radiansToDegrees * bodies[i].getAngle());
sprites[i].draw(batch);
}
batch.end();
debugRenderer.render(world, c.combined);
console.draw();
}
use of com.badlogic.gdx.math.Vector2 in project libgdx-inGameConsole by StrongJoshua.
the class Box2DTest method createExplosion.
/**
* Creates an explosion that applies forces to the bodies relative to their
* position and the given x and y values.
*
* @param maxForce
* The maximum force to be applied to the bodies (diminishes as
* distance from touch increases).
*/
private void createExplosion(float x, float y, float maxForce) {
float force;
Vector2 touch = new Vector2(x, y);
for (int i = 0; i < bodies.length; i++) {
Body b = bodies[i];
Vector2 v = b.getPosition();
float dist = v.dst2(touch);
if (dist == 0)
force = maxForce;
else
force = MathUtils.clamp(maxForce / dist, 0, maxForce);
float angle = v.cpy().sub(touch).angle();
float xForce = force * MathUtils.cosDeg(angle);
float yForce = force * MathUtils.sinDeg(angle);
Vector3 touch3, v3, boundMin, boundMax, intersection;
touch3 = new Vector3(touch.x, touch.y, 0);
v3 = new Vector3(v.x, v.y, 0);
boundMin = new Vector3(v.x - 1, v.y - 1, 0);
boundMax = new Vector3(v.x + 1, v.y + 1, 0);
intersection = Vector3.Zero;
Intersector.intersectRayBounds(new Ray(touch3, v3), new BoundingBox(boundMin, boundMax), intersection);
b.applyForce(new Vector2(xForce, yForce), new Vector2(intersection.x, intersection.y), true);
}
}
use of com.badlogic.gdx.math.Vector2 in project nhglib by VoidZombie.
the class Main method onMouseInput.
@Override
public void onMouseInput(NhgInput input) {
Vector2 pointerVector = (Vector2) input.getInputSource().getValue();
if (pointerVector != null) {
float horizontalAxis = pointerVector.x;
float verticalAxis = pointerVector.y;
cameraNode.rotate(verticalAxis, horizontalAxis, 0);
cameraNode.applyTransforms();
}
}
use of com.badlogic.gdx.math.Vector2 in project AmazingMaze by TheVirtualMachine.
the class FishMiniGame method touchDown.
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (!paused && button == Input.Buttons.LEFT) {
Vector2 current = new Vector2(screenX, screenY);
canvas.drawDot(current);
previous = current;
leftDown = true;
return true;
}
return false;
}
Aggregations