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