Search in sources :

Example 31 with Vec2

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

the class WheelJoint method getLocalAnchorA.

public Vector2 getLocalAnchorA() {
    Vec2 localAnchor = joint.getLocalAnchorA();
    localAnchorA.set(localAnchor.x, localAnchor.y);
    return localAnchorA;
}
Also used : Vec2(org.jbox2d.common.Vec2)

Example 32 with Vec2

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

the class DebugDraw method getWorldToScreen.

/**
   * Takes the world coordinates and returns the screen coordinates.
   * 
   * @param worldX
   * @param worldY
   */
public Vec2 getWorldToScreen(float worldX, float worldY) {
    Vec2 argScreen = new Vec2(worldX, worldY);
    viewportTransform.getWorldToScreen(argScreen, argScreen);
    return argScreen;
}
Also used : Vec2(org.jbox2d.common.Vec2)

Example 33 with Vec2

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

the class DebugDraw method getScreenToWorld.

/**
   * takes the screen coordinates (argScreen) and returns the world coordinates
   * 
   * @param argScreen
   */
public Vec2 getScreenToWorld(Vec2 argScreen) {
    Vec2 world = new Vec2();
    viewportTransform.getScreenToWorld(argScreen, world);
    return world;
}
Also used : Vec2(org.jbox2d.common.Vec2)

Example 34 with Vec2

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

the class PulleyJointDef method initialize.

/**
   * Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors.
   */
public void initialize(Body b1, Body b2, Vec2 ga1, Vec2 ga2, Vec2 anchor1, Vec2 anchor2, float r) {
    bodyA = b1;
    bodyB = b2;
    groundAnchorA = ga1;
    groundAnchorB = ga2;
    localAnchorA = bodyA.getLocalPoint(anchor1);
    localAnchorB = bodyB.getLocalPoint(anchor2);
    Vec2 d1 = anchor1.sub(ga1);
    lengthA = d1.length();
    Vec2 d2 = anchor2.sub(ga2);
    lengthB = d2.length();
    ratio = r;
    assert (ratio > Settings.EPSILON);
}
Also used : Vec2(org.jbox2d.common.Vec2)

Example 35 with Vec2

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

the class RevoluteJoint method initVelocityConstraints.

@Override
public void initVelocityConstraints(final SolverData data) {
    m_indexA = m_bodyA.m_islandIndex;
    m_indexB = m_bodyB.m_islandIndex;
    m_localCenterA.set(m_bodyA.m_sweep.localCenter);
    m_localCenterB.set(m_bodyB.m_sweep.localCenter);
    m_invMassA = m_bodyA.m_invMass;
    m_invMassB = m_bodyB.m_invMass;
    m_invIA = m_bodyA.m_invI;
    m_invIB = m_bodyB.m_invI;
    // Vec2 cA = data.positions[m_indexA].c;
    float aA = data.positions[m_indexA].a;
    Vec2 vA = data.velocities[m_indexA].v;
    float wA = data.velocities[m_indexA].w;
    // Vec2 cB = data.positions[m_indexB].c;
    float aB = data.positions[m_indexB].a;
    Vec2 vB = data.velocities[m_indexB].v;
    float wB = data.velocities[m_indexB].w;
    final Rot qA = pool.popRot();
    final Rot qB = pool.popRot();
    final Vec2 temp = pool.popVec2();
    qA.set(aA);
    qB.set(aB);
    // Compute the effective masses.
    Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), m_rA);
    Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB);
    // J = [-I -r1_skew I r2_skew]
    // [ 0 -1 0 1]
    // r_skew = [-ry; rx]
    // Matlab
    // K = [ mA+r1y^2*iA+mB+r2y^2*iB, -r1y*iA*r1x-r2y*iB*r2x, -r1y*iA-r2y*iB]
    // [ -r1y*iA*r1x-r2y*iB*r2x, mA+r1x^2*iA+mB+r2x^2*iB, r1x*iA+r2x*iB]
    // [ -r1y*iA-r2y*iB, r1x*iA+r2x*iB, iA+iB]
    float mA = m_invMassA, mB = m_invMassB;
    float iA = m_invIA, iB = m_invIB;
    boolean fixedRotation = (iA + iB == 0.0f);
    m_mass.ex.x = mA + mB + m_rA.y * m_rA.y * iA + m_rB.y * m_rB.y * iB;
    m_mass.ey.x = -m_rA.y * m_rA.x * iA - m_rB.y * m_rB.x * iB;
    m_mass.ez.x = -m_rA.y * iA - m_rB.y * iB;
    m_mass.ex.y = m_mass.ey.x;
    m_mass.ey.y = mA + mB + m_rA.x * m_rA.x * iA + m_rB.x * m_rB.x * iB;
    m_mass.ez.y = m_rA.x * iA + m_rB.x * iB;
    m_mass.ex.z = m_mass.ez.x;
    m_mass.ey.z = m_mass.ez.y;
    m_mass.ez.z = iA + iB;
    m_motorMass = iA + iB;
    if (m_motorMass > 0.0f) {
        m_motorMass = 1.0f / m_motorMass;
    }
    if (m_enableMotor == false || fixedRotation) {
        m_motorImpulse = 0.0f;
    }
    if (m_enableLimit && fixedRotation == false) {
        float jointAngle = aB - aA - m_referenceAngle;
        if (MathUtils.abs(m_upperAngle - m_lowerAngle) < 2.0f * Settings.angularSlop) {
            m_limitState = LimitState.EQUAL;
        } else if (jointAngle <= m_lowerAngle) {
            if (m_limitState != LimitState.AT_LOWER) {
                m_impulse.z = 0.0f;
            }
            m_limitState = LimitState.AT_LOWER;
        } else if (jointAngle >= m_upperAngle) {
            if (m_limitState != LimitState.AT_UPPER) {
                m_impulse.z = 0.0f;
            }
            m_limitState = LimitState.AT_UPPER;
        } else {
            m_limitState = LimitState.INACTIVE;
            m_impulse.z = 0.0f;
        }
    } else {
        m_limitState = LimitState.INACTIVE;
    }
    if (data.step.warmStarting) {
        final Vec2 P = pool.popVec2();
        // Scale impulses to support a variable time step.
        m_impulse.x *= data.step.dtRatio;
        m_impulse.y *= data.step.dtRatio;
        m_motorImpulse *= data.step.dtRatio;
        P.x = m_impulse.x;
        P.y = m_impulse.y;
        vA.x -= mA * P.x;
        vA.y -= mA * P.y;
        wA -= iA * (Vec2.cross(m_rA, P) + m_motorImpulse + m_impulse.z);
        vB.x += mB * P.x;
        vB.y += mB * P.y;
        wB += iB * (Vec2.cross(m_rB, P) + m_motorImpulse + m_impulse.z);
        pool.pushVec2(1);
    } else {
        m_impulse.setZero();
        m_motorImpulse = 0.0f;
    }
    // data.velocities[m_indexA].v.set(vA);
    data.velocities[m_indexA].w = wA;
    // data.velocities[m_indexB].v.set(vB);
    data.velocities[m_indexB].w = wB;
    pool.pushVec2(1);
    pool.pushRot(2);
}
Also used : Vec2(org.jbox2d.common.Vec2) Rot(org.jbox2d.common.Rot)

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