Search in sources :

Example 96 with Tuple2f

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

the class Body2D method synchronizeTransform.

public final void synchronizeTransform() {
    // m_xf.q.set(m_sweep.a);
    // 
    // // m_xf.position = m_sweep.c - Mul(m_xf.R, m_sweep.localCenter);
    // Rot.mulToOutUnsafe(m_xf.q, m_sweep.localCenter, m_xf.p);
    // m_xf.p.mulLocal(-1).addLocal(m_sweep.c);
    // 
    Rot q = this;
    q.s = (float) Math.sin(sweep.a);
    q.c = (float) Math.cos(sweep.a);
    Tuple2f v = sweep.localCenter;
    pos.x = sweep.c.x - q.c * v.x + q.s * v.y;
    pos.y = sweep.c.y - q.s * v.x - q.c * v.y;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) Rot(spacegraph.space2d.phys.common.Rot)

Example 97 with Tuple2f

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

the class AABB method set.

/**
 * Sets this object from the given object
 *
 * @param aabb the object to copy from
 */
public final void set(final AABB aabb) {
    Tuple2f v = aabb.lowerBound;
    lowerBound.x = v.x;
    lowerBound.y = v.y;
    Tuple2f v1 = aabb.upperBound;
    upperBound.x = v1.x;
    upperBound.y = v1.y;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Example 98 with Tuple2f

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

the class AABB method getExtents.

/**
 * Get the extents of the AABB (half-widths).
 *
 * @return
 */
public final Tuple2f getExtents() {
    final Tuple2f center = new v2(upperBound);
    center.subbed(lowerBound);
    center.scaled(.5f);
    return center;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) spacegraph.util.math.v2(spacegraph.util.math.v2)

Example 99 with Tuple2f

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

the class DynamicTreeFlatNodes method moveProxy.

@Override
public final boolean moveProxy(int proxyId, final AABB aabb, Tuple2f displacement) {
    assert (0 <= proxyId && proxyId < m_nodeCapacity);
    final int node = proxyId;
    assert (m_child1[node] == NULL_NODE);
    final AABB nodeAABB = m_aabb[node];
    // if (nodeAABB.contains(aabb)) {
    if (nodeAABB.lowerBound.x <= aabb.lowerBound.x && nodeAABB.lowerBound.y <= aabb.lowerBound.y && aabb.upperBound.x <= nodeAABB.upperBound.x && aabb.upperBound.y <= nodeAABB.upperBound.y) {
        return false;
    }
    removeLeaf(node);
    // Extend AABB
    final Tuple2f lowerBound = nodeAABB.lowerBound;
    final Tuple2f upperBound = nodeAABB.upperBound;
    lowerBound.x = aabb.lowerBound.x - Settings.aabbExtension;
    lowerBound.y = aabb.lowerBound.y - Settings.aabbExtension;
    upperBound.x = aabb.upperBound.x + Settings.aabbExtension;
    upperBound.y = aabb.upperBound.y + Settings.aabbExtension;
    // Predict AABB displacement.
    final float dx = displacement.x * Settings.aabbMultiplier;
    final float dy = displacement.y * Settings.aabbMultiplier;
    if (dx < 0.0f) {
        lowerBound.x += dx;
    } else {
        upperBound.x += dx;
    }
    if (dy < 0.0f) {
        lowerBound.y += dy;
    } else {
        upperBound.y += dy;
    }
    insertLeaf(proxyId);
    return true;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) AABB(spacegraph.space2d.phys.collision.AABB)

Example 100 with Tuple2f

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

the class CircleShape method raycast.

// Collision Detection in Interactive 3D Environments by Gino van den Bergen
// From Section 3.1.2
// x = s + a * r
// norm(x) = radius
@Override
public final boolean raycast(RayCastOutput output, RayCastInput input, Transform transform, int childIndex) {
    final Tuple2f inputp1 = input.p1;
    final Tuple2f inputp2 = input.p2;
    final Rot tq = transform;
    final Tuple2f tp = transform.pos;
    // Rot.mulToOutUnsafe(transform.q, m_p, position);
    // position.addLocal(transform.p);
    final float positionx = tq.c * center.x - tq.s * center.y + tp.x;
    final float positiony = tq.s * center.x + tq.c * center.y + tp.y;
    final float sx = inputp1.x - positionx;
    final float sy = inputp1.y - positiony;
    // final float b = Vec2.dot(s, s) - m_radius * m_radius;
    final float b = sx * sx + sy * sy - radius * radius;
    // Solve quadratic equation.
    final float rx = inputp2.x - inputp1.x;
    final float ry = inputp2.y - inputp1.y;
    // final float c = Vec2.dot(s, r);
    // final float rr = Vec2.dot(r, r);
    final float c = sx * rx + sy * ry;
    final float rr = rx * rx + ry * ry;
    final float sigma = c * c - rr * b;
    // Check for negative discriminant and short segment.
    if (sigma < 0.0f || rr < Settings.EPSILON) {
        return false;
    }
    // Find the point of intersection of the line with the circle.
    float a = -(c + (float) Math.sqrt(sigma));
    // Is the intersection point on the segment?
    if (0.0f <= a && a <= input.maxFraction * rr) {
        a /= rr;
        output.fraction = a;
        output.normal.x = rx * a + sx;
        output.normal.y = ry * a + sy;
        output.normal.normalize();
        return true;
    }
    return false;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) Rot(spacegraph.space2d.phys.common.Rot)

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