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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations