Search in sources :

Example 36 with Tuple2f

use of spacegraph.util.math.Tuple2f in project narchy by automenta.

the class ParticleSystem method updateContacts.

void updateContacts(boolean exceptZombie) {
    for (int p = 0; p < m_proxyCount; p++) {
        Proxy proxy = m_proxyBuffer[p];
        int i = proxy.index;
        Tuple2f pos = m_positionBuffer.data[i];
        proxy.tag = computeTag(m_inverseDiameter * pos.x, m_inverseDiameter * pos.y);
    }
    Arrays.sort(m_proxyBuffer, 0, m_proxyCount);
    m_contactCount = 0;
    int c_index = 0;
    for (int i = 0; i < m_proxyCount; i++) {
        Proxy a = m_proxyBuffer[i];
        long rightTag = computeRelativeTag(a.tag, 1, 0);
        for (int j = i + 1; j < m_proxyCount; j++) {
            Proxy b = m_proxyBuffer[j];
            if (rightTag < b.tag) {
                break;
            }
            addContact(a.index, b.index);
        }
        long bottomLeftTag = computeRelativeTag(a.tag, -1, 1);
        for (; c_index < m_proxyCount; c_index++) {
            Proxy c = m_proxyBuffer[c_index];
            if (bottomLeftTag <= c.tag) {
                break;
            }
        }
        long bottomRightTag = computeRelativeTag(a.tag, 1, 1);
        for (int b_index = c_index; b_index < m_proxyCount; b_index++) {
            Proxy b = m_proxyBuffer[b_index];
            if (bottomRightTag < b.tag) {
                break;
            }
            addContact(a.index, b.index);
        }
    }
    if (exceptZombie) {
        int j = m_contactCount;
        for (int i = 0; i < j; i++) {
            if ((m_contactBuffer[i].flags & ParticleType.b2_zombieParticle) != 0) {
                --j;
                ParticleContact temp = m_contactBuffer[j];
                m_contactBuffer[j] = m_contactBuffer[i];
                m_contactBuffer[i] = temp;
                --i;
            }
        }
        m_contactCount = j;
    }
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Example 37 with Tuple2f

use of spacegraph.util.math.Tuple2f in project narchy by automenta.

the class DistanceJointDef method initialize.

/**
 * Initialize the bodies, anchors, and length using the world anchors.
 *  @param b1      First body
 * @param b2      Second body
 * @param anchor1 World anchor on first body
 * @param anchor2 World anchor on second body
 */
public DistanceJointDef initialize(final Body2D b1, final Body2D b2, final Tuple2f anchor1, final Tuple2f anchor2) {
    bodyA = b1;
    bodyB = b2;
    localAnchorA.set(bodyA.getLocalPoint(anchor1));
    localAnchorB.set(bodyB.getLocalPoint(anchor2));
    Tuple2f d = anchor2.sub(anchor1);
    length = d.length();
    return this;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Example 38 with Tuple2f

use of spacegraph.util.math.Tuple2f in project narchy by automenta.

the class Body2D method getLinearVelocityFromWorldPoint.

/**
 * Get the world linear velocity of a world point attached to this body.
 *
 * @param a point in world coordinates.
 * @return the world velocity of a point.
 */
public final Tuple2f getLinearVelocityFromWorldPoint(Tuple2f worldPoint) {
    Tuple2f out = new v2();
    getLinearVelocityFromWorldPointToOut(worldPoint, out);
    return out;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) spacegraph.util.math.v2(spacegraph.util.math.v2)

Example 39 with Tuple2f

use of spacegraph.util.math.Tuple2f in project narchy by automenta.

the class Body2D method resetMassData.

/**
 * This resets the mass properties to the sum of the mass properties of the fixtures. This
 * normally does not need to be called unless you called setMassData to override the mass and you
 * later want to reset the mass.
 */
public final void resetMassData() {
    // Compute mass data from shapes. Each shape has its own density.
    mass = 0.0f;
    m_massArea = 0.0f;
    m_invMass = 0.0f;
    m_I = 0.0f;
    m_invI = 0.0f;
    sweep.localCenter.set(0, 0);
    final MassData massData = pmd;
    for (Fixture f = fixtures; f != null; f = f.next) {
        if (f.density != 0.0f) {
            f.getMassData(massData);
            m_massArea += massData.mass;
        }
    }
    // Static and kinematic bodies have zero mass.
    if (type == BodyType.STATIC || type == BodyType.KINEMATIC) {
        // m_sweep.c0 = m_sweep.c = m_xf.position;
        sweep.c0.set(pos);
        sweep.c.set(pos);
        sweep.a0 = sweep.a;
        return;
    }
    assert (type == BodyType.DYNAMIC);
    // Accumulate mass over all fixtures.
    final Tuple2f localCenter = W.pool.popVec2();
    localCenter.set(0, 0);
    final Tuple2f temp = W.pool.popVec2();
    for (Fixture f = fixtures; f != null; f = f.next) {
        if (f.density == 0.0f) {
            continue;
        }
        f.getMassData(massData);
        mass += massData.mass;
        // center += massData.mass * massData.center;
        temp.set(massData.center).scaled(massData.mass);
        localCenter.added(temp);
        m_I += massData.I;
    }
    // Compute center of mass.
    if (mass > 0.0f) {
        m_invMass = 1.0f / mass;
        localCenter.scaled(m_invMass);
    } else {
        // Force all dynamic bodies to have a positive mass.
        mass = 1.0f;
        m_invMass = 1.0f;
    }
    if (m_I > 0.0f && (flags & e_fixedRotationFlag) == 0) {
        // Center the inertia about the center of mass.
        m_I -= mass * Tuple2f.dot(localCenter, localCenter);
        assert (m_I > 0.0f);
        m_invI = 1.0f / m_I;
    } else {
        m_I = 0.0f;
        m_invI = 0.0f;
    }
    Tuple2f oldCenter = W.pool.popVec2();
    // Move center of mass.
    oldCenter.set(sweep.c);
    sweep.localCenter.set(localCenter);
    // m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
    Transform.mulToOutUnsafe(this, sweep.localCenter, sweep.c0);
    sweep.c.set(sweep.c0);
    // Update center of mass velocity.
    // m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
    temp.set(sweep.c).subbed(oldCenter);
    final Tuple2f temp2 = oldCenter;
    Tuple2f.crossToOutUnsafe(velAngular, temp, temp2);
    vel.added(temp2);
    W.pool.pushVec2(3);
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) MassData(spacegraph.space2d.phys.collision.shapes.MassData) PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture)

Example 40 with Tuple2f

use of spacegraph.util.math.Tuple2f in project narchy by automenta.

the class Body2D 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) {
    if (type != BodyType.DYNAMIC) {
        return;
    }
    m_invMass = 0.0f;
    m_I = 0.0f;
    m_invI = 0.0f;
    mass = massData.mass;
    if (mass <= 0.0f) {
        mass = 1f;
    }
    m_invMass = 1.0f / mass;
    if (massData.I > 0.0f && (flags & e_fixedRotationFlag) == 0) {
        m_I = massData.I - mass * Tuple2f.dot(massData.center, massData.center);
        assert (m_I > 0.0f);
        m_invI = 1.0f / m_I;
    }
    final Tuple2f oldCenter = W.pool.popVec2();
    // Move center of mass.
    oldCenter.set(sweep.c);
    sweep.localCenter.set(massData.center);
    // m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
    Transform.mulToOutUnsafe(this, sweep.localCenter, sweep.c0);
    sweep.c.set(sweep.c0);
    // Update center of mass velocity.
    // m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
    final Tuple2f temp = W.pool.popVec2();
    temp.set(sweep.c).subbed(oldCenter);
    Tuple2f.crossToOut(velAngular, temp, temp);
    vel.added(temp);
    W.pool.pushVec2(2);
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Aggregations

Tuple2f (spacegraph.util.math.Tuple2f)154 spacegraph.util.math.v2 (spacegraph.util.math.v2)32 Rot (spacegraph.space2d.phys.common.Rot)23 AABB (spacegraph.space2d.phys.collision.AABB)7 Vec2 (spacegraph.space2d.phys.common.Vec2)6 Body2D (spacegraph.space2d.phys.dynamics.Body2D)6 ManifoldPoint (spacegraph.space2d.phys.collision.ManifoldPoint)5 VelocityConstraintPoint (spacegraph.space2d.phys.dynamics.contacts.ContactVelocityConstraint.VelocityConstraintPoint)5 PolygonShape (spacegraph.space2d.phys.collision.shapes.PolygonShape)4 Joint (spacegraph.space2d.phys.dynamics.joints.Joint)4 PolygonFixture (spacegraph.space2d.phys.fracture.PolygonFixture)4 MyList (spacegraph.space2d.phys.fracture.util.MyList)4 FasterList (jcog.list.FasterList)3 CircleShape (spacegraph.space2d.phys.collision.shapes.CircleShape)3 Shape (spacegraph.space2d.phys.collision.shapes.Shape)3 Transform (spacegraph.space2d.phys.common.Transform)3 DistanceJoint (spacegraph.space2d.phys.dynamics.joints.DistanceJoint)3 MouseJoint (spacegraph.space2d.phys.dynamics.joints.MouseJoint)3 Fragment (spacegraph.space2d.phys.fracture.Fragment)3 Polygon (spacegraph.space2d.phys.fracture.Polygon)3