Search in sources :

Example 31 with Tuple2f

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

the class ParticleSystem method solveViscous.

void solveViscous(final TimeStep step) {
    float viscousStrength = m_viscousStrength;
    for (int k = 0; k < m_bodyContactCount; k++) {
        final ParticleBodyContact contact = m_bodyContactBuffer[k];
        int a = contact.index;
        if ((m_flagsBuffer.data[a] & ParticleType.b2_viscousParticle) != 0) {
            Body2D b = contact.body;
            float w = contact.weight;
            float m = contact.mass;
            Tuple2f p = m_positionBuffer.data[a];
            final Tuple2f va = m_velocityBuffer.data[a];
            final float tempX = p.x - b.sweep.c.x;
            final float tempY = p.y - b.sweep.c.y;
            final float vx = -b.velAngular * tempY + b.vel.x - va.x;
            final float vy = b.velAngular * tempX + b.vel.y - va.y;
            final Tuple2f f = tempVec;
            final float pInvMass = getParticleInvMass();
            f.x = viscousStrength * m * w * vx;
            f.y = viscousStrength * m * w * vy;
            va.x += pInvMass * f.x;
            va.y += pInvMass * f.y;
            f.x = -f.x;
            f.y = -f.y;
            b.applyLinearImpulse(f, p, true);
        }
    }
    for (int k = 0; k < m_contactCount; k++) {
        final ParticleContact contact = m_contactBuffer[k];
        if ((contact.flags & ParticleType.b2_viscousParticle) != 0) {
            int a = contact.indexA;
            int b = contact.indexB;
            float w = contact.weight;
            final Tuple2f va = m_velocityBuffer.data[a];
            final Tuple2f vb = m_velocityBuffer.data[b];
            final float vx = vb.x - va.x;
            final float vy = vb.y - va.y;
            final float fx = viscousStrength * w * vx;
            final float fy = viscousStrength * w * vy;
            va.x += fx;
            va.y += fy;
            vb.x -= fx;
            vb.y -= fy;
        }
    }
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) Body2D(spacegraph.space2d.phys.dynamics.Body2D)

Example 32 with Tuple2f

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

the class ParticleSystem method addContact.

public void addContact(int a, int b) {
    assert (a != b);
    Tuple2f pa = m_positionBuffer.data[a];
    Tuple2f pb = m_positionBuffer.data[b];
    float dx = pb.x - pa.x;
    float dy = pb.y - pa.y;
    float d2 = dx * dx + dy * dy;
    // assert(d2 != 0);
    if (d2 < m_squaredDiameter) {
        if (m_contactCount >= m_contactCapacity) {
            int oldCapacity = m_contactCapacity;
            int newCapacity = m_contactCount != 0 ? 2 * m_contactCount : Settings.minParticleBufferCapacity;
            m_contactBuffer = BufferUtils.reallocateBuffer(ParticleContact.class, m_contactBuffer, oldCapacity, newCapacity);
            m_contactCapacity = newCapacity;
        }
        float invD = d2 != 0 ? (float) Math.sqrt(1 / d2) : Float.MAX_VALUE;
        ParticleContact contact = m_contactBuffer[m_contactCount];
        contact.indexA = a;
        contact.indexB = b;
        contact.flags = m_flagsBuffer.data[a] | m_flagsBuffer.data[b];
        contact.weight = 1 - d2 * invD * m_inverseDiameter;
        contact.normal.x = invD * dx;
        contact.normal.y = invD * dy;
        m_contactCount++;
    }
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Example 33 with Tuple2f

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

the class ParticleSystem method solveWall.

public void solveWall(TimeStep step) {
    for (int i = 0; i < m_count; i++) {
        if ((m_flagsBuffer.data[i] & ParticleType.b2_wallParticle) != 0) {
            final Tuple2f r = m_velocityBuffer.data[i];
            r.x = 0.0f;
            r.y = 0.0f;
        }
    }
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Example 34 with Tuple2f

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

the class ParticleSystem method solveElastic.

void solveElastic(final TimeStep step) {
    float elasticStrength = step.inv_dt * m_elasticStrength;
    for (int k = 0; k < m_triadCount; k++) {
        final Triad triad = m_triadBuffer[k];
        if ((triad.flags & ParticleType.b2_elasticParticle) != 0) {
            int a = triad.indexA;
            int b = triad.indexB;
            int c = triad.indexC;
            final Tuple2f oa = triad.pa;
            final Tuple2f ob = triad.pb;
            final Tuple2f oc = triad.pc;
            final Tuple2f pa = m_positionBuffer.data[a];
            final Tuple2f pb = m_positionBuffer.data[b];
            final Tuple2f pc = m_positionBuffer.data[c];
            final float px = 1f / 3 * (pa.x + pb.x + pc.x);
            final float py = 1f / 3 * (pa.y + pb.y + pc.y);
            float rs = Tuple2f.cross(oa, pa) + Tuple2f.cross(ob, pb) + Tuple2f.cross(oc, pc);
            float rc = Tuple2f.dot(oa, pa) + Tuple2f.dot(ob, pb) + Tuple2f.dot(oc, pc);
            float r2 = rs * rs + rc * rc;
            float invR = r2 == 0 ? Float.MAX_VALUE : (float) Math.sqrt(1f / r2);
            rs *= invR;
            rc *= invR;
            final float strength = elasticStrength * triad.strength;
            final float roax = rc * oa.x - rs * oa.y;
            final float roay = rs * oa.x + rc * oa.y;
            final float robx = rc * ob.x - rs * ob.y;
            final float roby = rs * ob.x + rc * ob.y;
            final float rocx = rc * oc.x - rs * oc.y;
            final float rocy = rs * oc.x + rc * oc.y;
            final Tuple2f va = m_velocityBuffer.data[a];
            final Tuple2f vb = m_velocityBuffer.data[b];
            final Tuple2f vc = m_velocityBuffer.data[c];
            va.x += strength * (roax - (pa.x - px));
            va.y += strength * (roay - (pa.y - py));
            vb.x += strength * (robx - (pb.x - px));
            vb.y += strength * (roby - (pb.y - py));
            vc.x += strength * (rocx - (pc.x - px));
            vc.y += strength * (rocy - (pc.y - py));
        }
    }
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Example 35 with Tuple2f

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

the class ParticleSystem method solveSpring.

void solveSpring(final TimeStep step) {
    float springStrength = step.inv_dt * m_springStrength;
    for (int k = 0; k < m_pairCount; k++) {
        final Pair pair = m_pairBuffer[k];
        if ((pair.flags & ParticleType.b2_springParticle) != 0) {
            int a = pair.indexA;
            int b = pair.indexB;
            final Tuple2f pa = m_positionBuffer.data[a];
            final Tuple2f pb = m_positionBuffer.data[b];
            final float dx = pb.x - pa.x;
            final float dy = pb.y - pa.y;
            float r0 = pair.distance;
            float r1 = (float) Math.sqrt(dx * dx + dy * dy);
            if (r1 == 0)
                r1 = Float.MAX_VALUE;
            float strength = springStrength * pair.strength;
            final float fx = strength * (r0 - r1) / r1 * dx;
            final float fy = strength * (r0 - r1) / r1 * dy;
            final Tuple2f va = m_velocityBuffer.data[a];
            final Tuple2f vb = m_velocityBuffer.data[b];
            va.x -= fx;
            va.y -= fy;
            vb.x += fx;
            vb.y += fy;
        }
    }
}
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