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