Example usage for com.badlogic.gdx.math Vector2 scl

List of usage examples for com.badlogic.gdx.math Vector2 scl

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector2 scl.

Prototype

@Override
    public Vector2 scl(Vector2 v) 

Source Link

Usage

From source file:com.forerunnergames.peril.client.ui.screens.game.play.modes.classic.playmap.actors.DefaultCountry.java

License:Open Source License

public DefaultCountry(final CountryImages<CountryPrimaryImageState, CountryPrimaryImage> primaryImages,
        final CountryImages<CountrySecondaryImageState, CountrySecondaryImage> secondaryImages,
        final CountryImageData imageData, final CountryArmyText armyText, final Vector2 playMapReferenceSize) {
    Arguments.checkIsNotNull(primaryImages, "primaryImages");
    Arguments.checkIsNotNull(secondaryImages, "secondaryImages");
    Arguments.checkIsNotNull(imageData, "imageData");
    Arguments.checkIsNotNull(armyText, "armyText");
    Arguments.checkIsNotNull(playMapReferenceSize, "playMapReferenceSize");

    this.primaryImages = primaryImages;
    this.secondaryImages = secondaryImages;
    this.imageData = imageData;
    this.armyText = armyText;

    final Vector2 referenceToActualPlayMapSpaceScaling = PlayMapSettings
            .referenceToActualPlayMapScaling(playMapReferenceSize);

    final Vector2 tempPosition = new Vector2(imageData.getReferenceDestination());
    tempPosition.y = playMapReferenceSize.y - tempPosition.y;
    tempPosition.scl(referenceToActualPlayMapSpaceScaling);

    group.setName(imageData.getCountryName());
    group.setTransform(false);//from ww  w.  j  ava 2 s.  com

    for (final CountryPrimaryImage primaryImage : primaryImages.getAll()) {
        primaryImage.setVisible(false);
        primaryImage.setPosition(tempPosition);
        primaryImage.setScale(referenceToActualPlayMapSpaceScaling);
        group.addActor(primaryImage.asActor());
    }

    for (final CountrySecondaryImage countrySecondaryImage : secondaryImages.getAll()) {
        countrySecondaryImage.setVisible(false);
        countrySecondaryImage.setPosition(tempPosition);
        countrySecondaryImage.setScale(referenceToActualPlayMapSpaceScaling);
        group.addActor(countrySecondaryImage.asActor());
    }

    changePrimaryStateTo(primaryImageState);
    changeSecondaryStateTo(secondaryImageState);
}

From source file:com.github.skittishSloth.openSkies.battles.ships.PlayerShip.java

public void moveForward(final float delta) {
    velocity.setAngle(rotation + 90);/*from ww w.j av  a  2  s .  c  o m*/
    final Vector2 dv = velocity.cpy();
    dv.scl(delta);
    position.add(dv);
}

From source file:com.github.skittishSloth.openSkies.battles.ships.PlayerShip.java

public void moveBackward(final float delta) {
    velocity.setAngle(rotation + 90);//from   w  w  w.j  a  v a2 s .  c o  m
    final Vector2 dv = velocity.cpy();
    dv.scl(delta);

    position.sub(dv);
}

From source file:com.github.skittishSloth.openSkies.battles.ships.PlayerShip.java

public void bankLeft(final float delta) {
    bankVelocity.setAngle(rotation);//  www  .  java 2 s.  c om
    final Vector2 dv = bankVelocity.cpy();
    dv.scl(delta);
    position.sub(dv);
}

From source file:com.github.skittishSloth.openSkies.battles.ships.PlayerShip.java

public void bankRight(final float delta) {
    bankVelocity.setAngle(rotation);//  w w  w .j  a v  a  2  s.co m
    final Vector2 dv = bankVelocity.cpy();
    dv.scl(delta);
    position.add(dv);
}

From source file:com.github.unluckyninja.defenseofhuman.model.entity.Rope.java

License:Open Source License

public Rope(GameWorld gameWorld, Body body, Vector2 direction) {
    this.gameWorld = gameWorld;
    world = body.getWorld();//  w w  w .ja  v a 2  s.co  m
    bodyA = body;

    // ???
    Vector2 oriPosition = new Vector2(body.getPosition());
    if (direction.equals(Vector2.Zero)) {
        direction = Vector2.X;
    }
    Vector2 dir = new Vector2(direction);
    dir.nor();
    Vector2 distance = dir.scl(width / 2 * 1.25f); // ,?1/4,?

    // ?body
    bodyDef.angle = (float) Math.toRadians(dir.angle());
    bodyDef.position.set(distance.add(oriPosition));
    bodyDef.linearDamping = 0.3f;
    bodyDef.type = BodyDef.BodyType.DynamicBody;

    Body piece = body.getWorld().createBody(bodyDef);
    piece.setGravityScale(0.1f);

    // ?
    // ??,????
    fixtureDef.isSensor = true;
    fixtureDef.density = 0.001f;

    polygonShape.setAsBox(width / 2, height / 2);

    fixtureDef.shape = polygonShape;

    piece.createFixture(fixtureDef);

    // ?
    RevoluteJointDef rjDef = new RevoluteJointDef();
    rjDef.bodyA = body;
    rjDef.bodyB = piece;

    rjDef.localAnchorA.x = 0;
    rjDef.localAnchorA.y = 0;
    rjDef.localAnchorB.x = -width / 2 * 1.25f;
    rjDef.localAnchorB.y = 0;

    joints.add(body.getWorld().createJoint(rjDef));
    pieces.add(piece);

    piece.setUserData(this);

}

From source file:com.gmail.emersonmx.asteroids.util.ConverterUtil.java

License:Open Source License

public static Vector2 pixelToUnit(Vector2 value) {
    return value.scl(1 / PIXELS_PER_UNIT);
}

From source file:com.gmail.emersonmx.asteroids.util.ConverterUtil.java

License:Open Source License

public static Vector2 unitToPixel(Vector2 value) {
    return value.scl(PIXELS_PER_UNIT);
}

From source file:com.jmolina.orb.elements.LinearMagnetic.java

License:Open Source License

/**
 * Devuelve la fuerza que ejerce este elemento sobre un punto dado.
 *
 * La fuerza es cero si la proyeccin del punto sobre el eje del elemento cae fuera del segmento
 * del elemento./*w w  w. j a va 2s . co  m*/
 *
 * @param point Punto expresado en unidades del mundo
 */
@Override
public Vector2 getForce(Vector2 point) {
    Vector2 force = new Vector2(0, 0);

    if (closeRange(point)) {
        if (insideField(point)) {
            float factor = MAX_FORCE * (getThreshold() - distanceLine(point)) / getThreshold();
            force.set(Utils.normal(getSegment()));
            force.scl(factor);

            if (getPolarity() == Polarity.REPULSIVE)
                force.scl(-1);
        }
    }

    return force;
}

From source file:com.jmolina.orb.elements.RadialMagnetic.java

License:Open Source License

/**
 * Devuelve la fuerza que ejerce este elemento sobre un punto dado.
 * <p>// w  w w .ja v a2 s  .co m
 * La frmula de la atraccin est simplificada:
 * - Slo depende de la inversa de la distancia, siempre que el punto haya sobrepasado el umbral.
 * - Slo se computan los centroides (i.e. no se atrae el Orb si su centroide no cae dentro del
 * campo de actuacin).
 *
 * @param point Punto expresado en unidades del mundo
 */
@Override
public Vector2 getForce(Vector2 point) {
    Vector2 force = new Vector2(0, 0);

    if (belowThreshold(point)) {
        float factor = MAX_FORCE * (getThreshold() - distance(point)) / getThreshold();
        Vector2 direction = getPosition().sub(point).nor();
        force.set(direction).scl(factor);

        if (getPolarity() == Polarity.REPULSIVE)
            force.scl(-1);
    }

    return force;
}