Search in sources :

Example 56 with Vector2

use of com.badlogic.gdx.math.Vector2 in project libgdx by libgdx.

the class Box2DDebugRenderer method drawJoint.

private void drawJoint(Joint joint) {
    Body bodyA = joint.getBodyA();
    Body bodyB = joint.getBodyB();
    Transform xf1 = bodyA.getTransform();
    Transform xf2 = bodyB.getTransform();
    Vector2 x1 = xf1.getPosition();
    Vector2 x2 = xf2.getPosition();
    Vector2 p1 = joint.getAnchorA();
    Vector2 p2 = joint.getAnchorB();
    if (joint.getType() == JointType.DistanceJoint) {
        drawSegment(p1, p2, JOINT_COLOR);
    } else if (joint.getType() == JointType.PulleyJoint) {
        PulleyJoint pulley = (PulleyJoint) joint;
        Vector2 s1 = pulley.getGroundAnchorA();
        Vector2 s2 = pulley.getGroundAnchorB();
        drawSegment(s1, p1, JOINT_COLOR);
        drawSegment(s2, p2, JOINT_COLOR);
        drawSegment(s1, s2, JOINT_COLOR);
    } else if (joint.getType() == JointType.MouseJoint) {
        drawSegment(joint.getAnchorA(), joint.getAnchorB(), JOINT_COLOR);
    } else {
        drawSegment(x1, p1, JOINT_COLOR);
        drawSegment(p1, p2, JOINT_COLOR);
        drawSegment(x2, p2, JOINT_COLOR);
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) PulleyJoint(com.badlogic.gdx.physics.box2d.joints.PulleyJoint)

Example 57 with Vector2

use of com.badlogic.gdx.math.Vector2 in project libgdx by libgdx.

the class Box2DDebugRenderer method drawSolidPolygon.

private void drawSolidPolygon(Vector2[] vertices, int vertexCount, Color color, boolean closed) {
    renderer.setColor(color.r, color.g, color.b, color.a);
    lv.set(vertices[0]);
    f.set(vertices[0]);
    for (int i = 1; i < vertexCount; i++) {
        Vector2 v = vertices[i];
        renderer.line(lv.x, lv.y, v.x, v.y);
        lv.set(v);
    }
    if (closed)
        renderer.line(f.x, f.y, lv.x, lv.y);
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) PulleyJoint(com.badlogic.gdx.physics.box2d.joints.PulleyJoint)

Example 58 with Vector2

use of com.badlogic.gdx.math.Vector2 in project gdx-skineditor by cobolfoo.

the class Tooltips method showTooltip.

public void showTooltip(Actor actor) {
    Vector2 v = new Vector2();
    actor.localToStageCoordinates(v);
    if (tooltip == null) {
        LabelStyle style = new LabelStyle();
        style.font = tooltipStyle.font;
        style.background = tooltipStyle.background;
        style.fontColor = tooltipStyle.fontColor;
        tooltip = new Label(tooltips.get(actor), style);
        tooltip.setStyle(style);
        tooltip.pack();
        tooltip.setPosition(v.x + 7.5f, v.y - tooltip.getPrefHeight() - 15);
        tooltip.setOriginY(tooltip.getPrefHeight());
        tooltip.setColor(1, 1, 1, 0);
        tooltip.setScale(1, 0);
        tooltip.addAction(parallel(fadeIn(0.15f), scaleTo(1, 1, 0.15f)));
    } else {
        tooltip.setText(tooltips.get(actor));
        tooltip.pack();
        tooltip.setPosition(v.x + 7.5f, v.y - tooltip.getPrefHeight() - 15);
    }
    stage.addActor(tooltip);
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle)

Example 59 with Vector2

use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.

the class ShapeUtils method calculateConvexHull.

/**
	 * Calculates the Convex Hull of a collection of points, extracted from <a href="http://www.cse.unsw.edu.au/~lambert/java/3d/ConvexHull.html">here</a>
	 * 
	 * @param points
	 *            An array with the points to be used when building the Convex Hull
	 * @param convexHullPoints
	 *            An array where the Convex Hull points will be stored.
	 */
public static void calculateConvexHull(Array<Vector2> points, Array<Vector2> convexHullPoints) {
    if (points.size <= 1)
        return;
    Vector2 p;
    Vector2 bot = points.get(0);
    for (int i = 1; i < points.size; i++) {
        Vector2 point = points.get(i);
        if (point.y < bot.y)
            bot = point;
    }
    convexHullPoints.add(bot);
    p = bot;
    do {
        int i;
        i = points.get(0) == p ? 1 : 0;
        Vector2 cand = points.get(i);
        for (i = i + 1; i < points.size; i++) {
            Vector2 point = points.get(i);
            if (point != p && area(p, cand, point) > 0)
                cand = points.get(i);
        }
        convexHullPoints.add(cand);
        p = cand;
    } while (p != bot);
}
Also used : Vector2(com.badlogic.gdx.math.Vector2)

Example 60 with Vector2

use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.

the class ShapeUtils method translateCircleShape.

/**
	 * Translates the CircleShape the specified translation.
	 * 
	 * @param circleShape
	 *            The CircleShape to be translated.
	 * @param tx
	 *            The translation in x coordinate.
	 * @param ty
	 *            The translation in y coordinate.
	 */
public static void translateCircleShape(CircleShape circleShape, float tx, float ty) {
    Vector2 position = circleShape.getPosition();
    position.add(tx, ty);
    circleShape.setPosition(position);
}
Also used : Vector2(com.badlogic.gdx.math.Vector2)

Aggregations

Vector2 (com.badlogic.gdx.math.Vector2)103 Body (com.badlogic.gdx.physics.box2d.Body)21 BodyDef (com.badlogic.gdx.physics.box2d.BodyDef)14 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)10 PolygonShape (com.badlogic.gdx.physics.box2d.PolygonShape)10 Texture (com.badlogic.gdx.graphics.Texture)7 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)7 EdgeShape (com.badlogic.gdx.physics.box2d.EdgeShape)7 Vector3 (com.badlogic.gdx.math.Vector3)6 Fixture (com.badlogic.gdx.physics.box2d.Fixture)6 World (com.badlogic.gdx.physics.box2d.World)6 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)6 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)5 CircleShape (com.badlogic.gdx.physics.box2d.CircleShape)5 Test (org.junit.Test)5 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)4 Box2DDebugRenderer (com.badlogic.gdx.physics.box2d.Box2DDebugRenderer)4 Contact (com.badlogic.gdx.physics.box2d.Contact)4 WorldManifold (com.badlogic.gdx.physics.box2d.WorldManifold)4