Search in sources :

Example 91 with Tuple2f

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

the class PolygonShape method raycast.

@Override
public final boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) {
    final float xfqc = xf.c;
    final float xfqs = xf.s;
    final Tuple2f xfp = xf.pos;
    float tempx, tempy;
    // b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
    // b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
    tempx = input.p1.x - xfp.x;
    tempy = input.p1.y - xfp.y;
    final float p1x = xfqc * tempx + xfqs * tempy;
    final float p1y = -xfqs * tempx + xfqc * tempy;
    tempx = input.p2.x - xfp.x;
    tempy = input.p2.y - xfp.y;
    final float p2x = xfqc * tempx + xfqs * tempy;
    final float p2y = -xfqs * tempx + xfqc * tempy;
    final float dx = p2x - p1x;
    final float dy = p2y - p1y;
    float lower = 0, upper = input.maxFraction;
    int index = -1;
    for (int i = 0; i < vertices; ++i) {
        Tuple2f normal = normals[i];
        Tuple2f vertex = this.vertex[i];
        // p = p1 + a * d
        // dot(normal, p - v) = 0
        // dot(normal, p1 - v) + a * dot(normal, d) = 0
        float tempxn = vertex.x - p1x;
        float tempyn = vertex.y - p1y;
        final float numerator = normal.x * tempxn + normal.y * tempyn;
        final float denominator = normal.x * dx + normal.y * dy;
        if (denominator == 0.0f) {
            if (numerator < 0.0f) {
                return false;
            }
        } else {
            // numerator.
            if (denominator < 0.0f && numerator < lower * denominator) {
                // Increase lower.
                // The segment enters this half-space.
                lower = numerator / denominator;
                index = i;
            } else if (denominator > 0.0f && numerator < upper * denominator) {
                // Decrease upper.
                // The segment exits this half-space.
                upper = numerator / denominator;
            }
        }
        if (upper < lower) {
            return false;
        }
    }
    assert (0.0f <= lower && lower <= input.maxFraction);
    if (index >= 0) {
        output.fraction = lower;
        // normal = Mul(xf.R, m_normals[index]);
        Tuple2f normal = normals[index];
        Tuple2f out = output.normal;
        out.x = xfqc * normal.x - xfqs * normal.y;
        out.y = xfqs * normal.x + xfqc * normal.y;
        return true;
    }
    return false;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Example 92 with Tuple2f

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

the class MathUtils method clamp.

public static final Tuple2f clamp(final Tuple2f a, final Tuple2f low, final Tuple2f high) {
    final Tuple2f min = new Vec2();
    min.x = a.x < high.x ? a.x : high.x;
    min.y = a.y < high.y ? a.y : high.y;
    min.x = low.x > min.x ? low.x : min.x;
    min.y = low.y > min.y ? low.y : min.y;
    return min;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Example 93 with Tuple2f

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

the class DebugDraw method getWorldToScreen.

/**
 * takes the world coordinate (argWorld) and returns the screen coordinates.
 *
 * @param argWorld
 */
public Tuple2f getWorldToScreen(Tuple2f argWorld) {
    Tuple2f screen = new Vec2();
    viewportTransform.getWorldToScreen(argWorld, screen);
    return screen;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) Vec2(spacegraph.space2d.phys.common.Vec2)

Example 94 with Tuple2f

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

the class DebugDraw method getScreenToWorld.

/**
 * takes the screen coordinates (argScreen) and returns the world coordinates
 *
 * @param argScreen
 */
public Tuple2f getScreenToWorld(Tuple2f argScreen) {
    Tuple2f world = new Vec2();
    viewportTransform.getScreenToWorld(argScreen, world);
    return world;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) Vec2(spacegraph.space2d.phys.common.Vec2)

Example 95 with Tuple2f

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

the class Body2D method getLinearVelocityFromLocalPoint.

/**
 * Get the world velocity of a local point.
 *
 * @param a point in local coordinates.
 * @return the world velocity of a point.
 */
public final Tuple2f getLinearVelocityFromLocalPoint(Tuple2f localPoint) {
    Tuple2f out = new v2();
    getLinearVelocityFromLocalPointToOut(localPoint, out);
    return out;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) spacegraph.util.math.v2(spacegraph.util.math.v2)

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