Search in sources :

Example 66 with Tuple2f

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

the class CircleShape method computeAABB.

@Override
public final void computeAABB(final AABB aabb, final Transform transform, int childIndex) {
    final Rot tq = transform;
    final Tuple2f tp = transform.pos;
    final float px = tq.c * center.x - tq.s * center.y + tp.x;
    final float py = tq.s * center.x + tq.c * center.y + tp.y;
    aabb.lowerBound.x = px - radius;
    aabb.lowerBound.y = py - radius;
    aabb.upperBound.x = px + radius;
    aabb.upperBound.y = py + radius;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) Rot(spacegraph.space2d.phys.common.Rot)

Example 67 with Tuple2f

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

the class CircleShape method testPoint.

@Override
public final boolean testPoint(final Transform transform, final Tuple2f p) {
    // Rot.mulToOutUnsafe(transform.q, m_p, center);
    // center.addLocal(transform.p);
    // 
    // final Vec2 d = center.subLocal(p).negateLocal();
    // return Vec2.dot(d, d) <= m_radius * m_radius;
    final Rot q = transform;
    final Tuple2f tp = transform.pos;
    float centerx = -(q.c * center.x - q.s * center.y + tp.x - p.x);
    float centery = -(q.s * center.x + q.c * center.y + tp.y - p.y);
    return centerx * centerx + centery * centery <= radius * radius;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) Rot(spacegraph.space2d.phys.common.Rot)

Example 68 with Tuple2f

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

the class Mat33 method solve22.

/**
 * Solve A * x = b, where b is a column vector. This is more efficient than computing the inverse
 * in one-shot cases.
 *
 * @param b
 * @return
 */
public final Tuple2f solve22(Tuple2f b) {
    Tuple2f x = new Vec2();
    solve22ToOut(b, x);
    return x;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Example 69 with Tuple2f

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

the class PhyWall method drawBody.

private void drawBody(Body2D body, GL2 gl) {
    if (body.data() instanceof PhyWindow.WallBody) {
        // its rendered already via its Surface
        return;
    }
    if (body instanceof Consumer) {
        // HACK make better custom enderer interface
        ((Consumer) body).accept(gl);
        return;
    }
    // boolean active = body.isActive();
    boolean awake = body.isAwake();
    gl.glColor4f(0.5f, 0.5f, 0.5f, awake ? 0.75f : 0.65f);
    // List<PolygonFixture> generalPolygons = new FasterList<>();
    for (Fixture f = body.fixtures; f != null; f = f.next) {
        PolygonFixture pg = f.polygon;
        if (pg != null) {
        // generalPolygons.add(pg);
        } else {
            Shape shape = f.shape();
            switch(shape.m_type) {
                case POLYGON:
                    Draw.poly(body, gl, (PolygonShape) shape);
                    break;
                case CIRCLE:
                    CircleShape circle = (CircleShape) shape;
                    float r = circle.radius;
                    v2 v = new v2();
                    body.getWorldPointToOut(circle.center, v);
                    // Point p = getPoint(v);
                    // int wr = (int) (r * zoom);
                    // g.fillOval(p.x - wr, p.y - wr, wr * 2, wr * 2);
                    Draw.circle(gl, v, true, r, 9);
                    break;
                case EDGE:
                    EdgeShape edge = (EdgeShape) shape;
                    Tuple2f p1 = edge.m_vertex1;
                    Tuple2f p2 = edge.m_vertex2;
                    gl.glLineWidth(4f);
                    Draw.line(gl, p1.x, p1.y, p2.x, p2.y);
                    break;
            }
        }
    }
// if (generalPolygons.size() != 0) {
// PolygonFixture[] polygonArray = generalPolygons.toArray(new PolygonFixture[generalPolygons.size()]);
// for (PolygonFixture poly : polygonArray) {
// int n = poly.size();
// int x[] = new int[n];
// int y[] = new int[n];
// for (int i = 0; i < n; ++i) {
// body.getWorldPointToOut(poly.get(i), v);
// Point p = getPoint(v);
// x[i] = p.x;
// y[i] = p.y;
// }
// g.fillPolygon(x, y, n);
// }
}
Also used : EdgeShape(spacegraph.space2d.phys.collision.shapes.EdgeShape) PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) CircleShape(spacegraph.space2d.phys.collision.shapes.CircleShape) Shape(spacegraph.space2d.phys.collision.shapes.Shape) EdgeShape(spacegraph.space2d.phys.collision.shapes.EdgeShape) Tuple2f(spacegraph.util.math.Tuple2f) Consumer(java.util.function.Consumer) CircleShape(spacegraph.space2d.phys.collision.shapes.CircleShape) PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture) PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture) spacegraph.util.math.v2(spacegraph.util.math.v2)

Example 70 with Tuple2f

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

the class SingletonVD method quicksort.

/**
 * @param low
 * @param high
 */
private void quicksort(final int low, final int high) {
    int i = low, j = high;
    // Get the pivot element from the middle of the list
    double pivot = comparer[low + ((high - low) >> 1)];
    while (i <= j) {
        while (comparer[i] < pivot) {
            i++;
        }
        while (comparer[j] > pivot) {
            j--;
        }
        if (i <= j) {
            double temp = comparer[i];
            comparer[i] = comparer[j];
            comparer[j] = temp;
            Tuple2f v = ar[i];
            ar[i] = ar[j];
            ar[j] = v;
            i++;
            j--;
        }
    }
    if (low < j) {
        quicksort(low, j);
    }
    if (i < high) {
        quicksort(i, high);
    }
}
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