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

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

Introduction

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

Prototype

@Override
    public float dot(Vector2 v) 

Source Link

Usage

From source file:com.agateau.pixelwheels.utils.Box2DUtils.java

License:Open Source License

@SuppressWarnings("unused")
public static Vector2 getForwardVelocity(Body body) {
    Vector2 currentRightNormal = body.getWorldVector(FORWARD_VECTOR);
    float v = currentRightNormal.dot(body.getLinearVelocity());
    return currentRightNormal.scl(v);
}

From source file:com.agateau.pixelwheels.utils.Box2DUtils.java

License:Open Source License

public static Vector2 getLateralVelocity(Body body) {
    Vector2 currentRightNormal = body.getWorldVector(LATERAL_VECTOR);
    float v = currentRightNormal.dot(body.getLinearVelocity());
    return currentRightNormal.scl(v);
}

From source file:com.dongbat.invasion.system.EnemyMovementSystem.java

@Override
protected void process(Entity entity) {
    Delay delay = delayMapper.get(entity);
    if (delay != null && delay.getDuration() > 0) {
        long timePassed = TimeUtil.getGameTimeSince(delay.getStartTime());
        if (timePassed <= delay.getDuration()) {
            return;
        }// w  w w .jav  a2 s.  c  o m
    }

    //    Vector2 prevVelocity = PhysicsUtil.getVelocity(entity).cpy();
    Vector2 position = PhysicsUtil.getPosition(entity);
    EnemyMovement movement = EntityUtil.getComponent(entity, EnemyMovement.class);
    PhysicsUtil.setVelocity(entity, new Vector2());
    Vector2 intent = movement.getIntent().cpy();
    Vector2 travel;
    MovementUtil.moveEnemyTo(entity, intent);
    // TODO check free enemy
    intent.y = position.y;
    // TODO free movement unit use moveTo
    Vector2 distance = intent.cpy().sub(position);
    travel = PhysicsUtil.getVelocity(entity).cpy().scl(world.delta);
    if (travel.dot(distance) > 0 && travel.len2() - distance.len2() > 0) {
        PhysicsUtil.setPosition(entity, intent);
        PhysicsUtil.setVelocity(entity, new Vector2());
    }

    if (TimeUtil.getGameTimeSince(movement.getStartDrag()) >= movement.getDragDuration()) {
        movement.setDraggedTo(null);
    }

    if (movement.getDraggedTo() == null) {
        return;
    }

    float max = movement.getDraggedTo().cpy().sub(movement.getDraggedFrom()).len2();
    float actual = position.cpy().sub(movement.getDraggedFrom()).len2();
    if (actual >= max) {
        return;
    }

    Vector2 drag = movement.getDraggedTo().cpy().sub(position);
    float dragLen2 = drag.len2();
    if (dragLen2 > movement.getDragForce() * movement.getDragForce()) {
        drag.nor().scl(movement.getDragForce());
    }
    PhysicsUtil.applyImpulseOnEnemy(entity, drag);

    // TODO fix this similar to above
    travel = PhysicsUtil.getVelocity(entity).cpy().scl(world.delta);
    if (travel.sub(drag).len2() <= Constants.GAME.EPSILON_SQUARED) {
        PhysicsUtil.setPosition(entity, movement.getDraggedTo());
        PhysicsUtil.applyImpulseOnEnemy(entity, drag.scl(-1));
    }
}

From source file:com.kotcrab.vis.editor.module.physicseditor.util.PolygonUtils.java

License:Apache License

private static float distanceSquared(Vector2 a, Vector2 b) {
    Vector2 c = a.cpy().sub(b);
    return c.dot(c);
}

From source file:com.nuliy.example.Car.java

public void KillOrthoVelocity(Body body) {
    Vector2 localP = new Vector2(0, 0);
    Vector2 velocity = body.getLinearVelocityFromLocalPoint(localP);

    float r = body.getTransform().getRotation();
    Vector2 sideways = new Vector2((float) -Math.sin(r), (float) Math.cos(r));
    sideways.scl(velocity.dot(sideways));

    body.setLinearVelocity(sideways);//from  w ww .ja  va2 s .c  om
}

From source file:MeshBoneUtil.CreatureManager.java

License:Open Source License

public String ProcessContactBone(Vector2 pt_in, float radius, MeshBone bone_in) {
    String ret_name = "";
    Vector3 diff_vec = bone_in.getWorldEndPt().cpy().sub(bone_in.getWorldStartPt());

    Vector2 cur_vec = new Vector2(diff_vec.x, diff_vec.y);
    float cur_length = (float) cur_vec.len();

    Vector2 unit_vec = cur_vec.cpy();
    unit_vec.nor();//from  w w  w. j a v a2 s .c  o m

    Vector2 norm_vec = new Vector2(unit_vec.y, unit_vec.x);

    Vector2 src_pt = new Vector2(bone_in.getWorldStartPt().x, bone_in.getWorldStartPt().y);
    Vector2 rel_vec = pt_in.cpy().sub(src_pt);
    float proj = (float) rel_vec.dot(unit_vec);

    if ((proj >= 0) && (proj <= cur_length)) {
        float norm_proj = (float) rel_vec.dot(norm_vec);
        if (norm_proj <= radius) {
            return bone_in.getKey();
        }
    }

    Vector<MeshBone> cur_children = bone_in.getChildren();
    for (MeshBone cur_child : cur_children) {
        ret_name = ProcessContactBone(pt_in, radius, cur_child);
        if (!(ret_name.equals(""))) {
            break;
        }
    }

    return ret_name;
}

From source file:se.anyro.snr.GameThread.java

License:Apache License

@Override
public void beginContact(Contact contact) {

    Vector2 ballSpeed = mBall.getSpeed();
    if (ballSpeed.len2() > 25) {
        Vector2 normal = contact.GetWorldManifold().getNormal();
        float collisionSpeed = Math.abs(normal.dot(ballSpeed));
        if (collisionSpeed > 10)
            SwipeNRoll.sVibrator.vibrate((long) collisionSpeed);
    }/*  ww  w.  ja  v  a  2s  . com*/

    Body body1 = (Body) contact.getFixtureA().getBody().getUserData();
    if (body1 == null)
        return;

    Body body2 = (Body) contact.getFixtureB().getBody().getUserData();
    if (body2 == null)
        return;

    if (body1.isCollider()) {
        mCollision = new Collision(body2, body1);
    } else if (body2.isCollider()) {
        mCollision = new Collision(body1, body2);
    }
}