Search in sources :

Example 96 with Vec2

use of org.jbox2d.common.Vec2 in project libgdx by libgdx.

the class WorldRayCastWrapper method drawJoint.

private void drawJoint(Joint joint) {
    Body bodyA = joint.getBodyA();
    Body bodyB = joint.getBodyB();
    Transform xf1 = bodyA.getTransform();
    Transform xf2 = bodyB.getTransform();
    Vec2 x1 = xf1.p;
    Vec2 x2 = xf2.p;
    Vec2 p1 = pool.popVec2();
    Vec2 p2 = pool.popVec2();
    joint.getAnchorA(p1);
    joint.getAnchorB(p2);
    color.set(0.5f, 0.8f, 0.8f);
    switch(joint.getType()) {
        // TODO djm write after writing joints
        case DISTANCE:
            m_debugDraw.drawSegment(p1, p2, color);
            break;
        case PULLEY:
            {
                PulleyJoint pulley = (PulleyJoint) joint;
                Vec2 s1 = pulley.getGroundAnchorA();
                Vec2 s2 = pulley.getGroundAnchorB();
                m_debugDraw.drawSegment(s1, p1, color);
                m_debugDraw.drawSegment(s2, p2, color);
                m_debugDraw.drawSegment(s1, s2, color);
            }
            break;
        case CONSTANT_VOLUME:
        case MOUSE:
            // don't draw this
            break;
        default:
            m_debugDraw.drawSegment(x1, p1, color);
            m_debugDraw.drawSegment(p1, p2, color);
            m_debugDraw.drawSegment(x2, p2, color);
    }
    pool.pushVec2(2);
}
Also used : Vec2(org.jbox2d.common.Vec2) Transform(org.jbox2d.common.Transform) PulleyJoint(org.jbox2d.dynamics.joints.PulleyJoint)

Example 97 with Vec2

use of org.jbox2d.common.Vec2 in project libgdx by libgdx.

the class Body method setMassData.

/**
   * Set the mass properties to override the mass properties of the fixtures. Note that this changes
   * the center of mass position. Note that creating or destroying fixtures can also alter the mass.
   * This function has no effect if the body isn't dynamic.
   * 
   * @param massData the mass properties.
   */
public final void setMassData(MassData massData) {
    // TODO_ERIN adjust linear velocity and torque to account for movement of center.
    assert (m_world.isLocked() == false);
    if (m_world.isLocked() == true) {
        return;
    }
    if (m_type != BodyType.DYNAMIC) {
        return;
    }
    m_invMass = 0.0f;
    m_I = 0.0f;
    m_invI = 0.0f;
    m_mass = massData.mass;
    if (m_mass <= 0.0f) {
        m_mass = 1f;
    }
    m_invMass = 1.0f / m_mass;
    if (massData.I > 0.0f && (m_flags & e_fixedRotationFlag) == 0) {
        m_I = massData.I - m_mass * Vec2.dot(massData.center, massData.center);
        assert (m_I > 0.0f);
        m_invI = 1.0f / m_I;
    }
    final Vec2 oldCenter = m_world.getPool().popVec2();
    // Move center of mass.
    oldCenter.set(m_sweep.c);
    m_sweep.localCenter.set(massData.center);
    // m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
    Transform.mulToOutUnsafe(m_xf, m_sweep.localCenter, m_sweep.c0);
    m_sweep.c.set(m_sweep.c0);
    // Update center of mass velocity.
    // m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
    final Vec2 temp = m_world.getPool().popVec2();
    temp.set(m_sweep.c).subLocal(oldCenter);
    Vec2.crossToOut(m_angularVelocity, temp, temp);
    m_linearVelocity.addLocal(temp);
    m_world.getPool().pushVec2(2);
}
Also used : Vec2(org.jbox2d.common.Vec2)

Example 98 with Vec2

use of org.jbox2d.common.Vec2 in project libgdx by libgdx.

the class Body method getLinearVelocityFromLocalPoint.

/**
   * Get the world velocity of a local point.
   * 
   * @param a point in local coordinates.
   * @return the world velocity of a point.
   */
public final Vec2 getLinearVelocityFromLocalPoint(Vec2 localPoint) {
    Vec2 out = new Vec2();
    getLinearVelocityFromLocalPointToOut(localPoint, out);
    return out;
}
Also used : Vec2(org.jbox2d.common.Vec2)

Example 99 with Vec2

use of org.jbox2d.common.Vec2 in project libgdx by libgdx.

the class Body method getLocalPoint.

/**
   * Gets a local point relative to the body's origin given a world point.
   * 
   * @param a point in world coordinates.
   * @return the corresponding local point relative to the body's origin.
   */
public final Vec2 getLocalPoint(Vec2 worldPoint) {
    Vec2 out = new Vec2();
    getLocalPointToOut(worldPoint, out);
    return out;
}
Also used : Vec2(org.jbox2d.common.Vec2)

Example 100 with Vec2

use of org.jbox2d.common.Vec2 in project libgdx by libgdx.

the class Body method getWorldPoint.

/**
   * Get the world coordinates of a point given the local coordinates.
   * 
   * @param localPoint a point on the body measured relative the the body's origin.
   * @return the same point expressed in world coordinates.
   */
public final Vec2 getWorldPoint(Vec2 localPoint) {
    Vec2 v = new Vec2();
    getWorldPointToOut(localPoint, v);
    return v;
}
Also used : Vec2(org.jbox2d.common.Vec2)

Aggregations

Vec2 (org.jbox2d.common.Vec2)185 Rot (org.jbox2d.common.Rot)36 Body (org.jbox2d.dynamics.Body)11 World (org.jbox2d.dynamics.World)9 AABB (org.jbox2d.collision.AABB)8 Mat22 (org.jbox2d.common.Mat22)7 Joint (org.jbox2d.dynamics.joints.Joint)7 PulleyJoint (org.jbox2d.dynamics.joints.PulleyJoint)7 ManifoldPoint (org.jbox2d.collision.ManifoldPoint)6 Test (org.junit.jupiter.api.Test)6 PolygonShape (org.jbox2d.collision.shapes.PolygonShape)5 Transform (org.jbox2d.common.Transform)5 Vec3 (org.jbox2d.common.Vec3)5 BodyDef (org.jbox2d.dynamics.BodyDef)5 VelocityConstraintPoint (org.jbox2d.dynamics.contacts.ContactVelocityConstraint.VelocityConstraintPoint)5 CircleShape (org.jbox2d.collision.shapes.CircleShape)4 Test (org.junit.Test)4 AffineTransform (java.awt.geom.AffineTransform)3 Shape (org.jbox2d.collision.shapes.Shape)3 Mat33 (org.jbox2d.common.Mat33)3