use of spacegraph.space2d.phys.common.Transform in project narchy by automenta.
the class PolygonShape method setAsBox.
public final PolygonShape setAsBox(float x1, float y1, float x2, float y2) {
vertices = 4;
vertex[0].set(x1, y1);
vertex[1].set(x2, y1);
vertex[2].set(x2, y2);
vertex[3].set(x1, y2);
normals[0].set(0.0f, -1.0f);
normals[1].set(1.0f, 0.0f);
normals[2].set(0.0f, 1.0f);
normals[3].set(-1.0f, 0.0f);
v2 center = new v2((x1 + x2) / 2, (y1 + y2) / 2);
centroid.set(center);
final Transform xf = poolt1;
xf.pos.set(center);
xf.set(0);
// Transform vertices and normals.
for (int i = 0; i < vertices; ++i) {
Transform.mulToOut(xf, vertex[i], vertex[i]);
Rot.mulToOut(xf, normals[i], normals[i]);
}
return this;
}
use of spacegraph.space2d.phys.common.Transform in project narchy by automenta.
the class Contact method update.
public void update(ContactListener listener) {
oldManifold.set(m_manifold);
// Re-enable this contact.
m_flags |= ENABLED_FLAG;
boolean touching = false;
boolean wasTouching = (m_flags & TOUCHING_FLAG) == TOUCHING_FLAG;
boolean sensorA = aFixture.isSensor();
boolean sensorB = bFixture.isSensor();
boolean sensor = sensorA || sensorB;
Body2D bodyA = aFixture.getBody();
Body2D bodyB = bFixture.getBody();
Transform xfA = bodyA;
Transform xfB = bodyB;
if (sensor) {
Shape shapeA = aFixture.shape();
Shape shapeB = bFixture.shape();
touching = pool.getCollision().testOverlap(shapeA, aIndex, shapeB, bIndex, xfA, xfB);
// Sensors don't generate manifolds.
m_manifold.pointCount = 0;
} else {
evaluate(m_manifold, xfA, xfB);
touching = m_manifold.pointCount > 0;
// stored impulses to warm start the solver.
for (int i = 0; i < m_manifold.pointCount; ++i) {
ManifoldPoint mp2 = m_manifold.points[i];
mp2.normalImpulse = 0.0f;
mp2.tangentImpulse = 0.0f;
ContactID id2 = mp2.id;
for (int j = 0; j < oldManifold.pointCount; ++j) {
ManifoldPoint mp1 = oldManifold.points[j];
if (mp1.id.isEqual(id2)) {
mp2.normalImpulse = mp1.normalImpulse;
mp2.tangentImpulse = mp1.tangentImpulse;
break;
}
}
}
if (touching != wasTouching) {
bodyA.setAwake(true);
bodyB.setAwake(true);
}
}
if (touching) {
m_flags |= TOUCHING_FLAG;
} else {
m_flags &= ~TOUCHING_FLAG;
}
if (!sensor && touching) {
m_angularVelocity_bodyA = aFixture.body.velAngular;
m_linearVelocity_bodyA.set(aFixture.body.vel);
m_angularVelocity_bodyB = bFixture.body.velAngular;
m_linearVelocity_bodyB.set(bFixture.body.vel);
}
if (listener == null) {
return;
}
if (!wasTouching && touching) {
if (!listener.beginContact(this))
touching = false;
}
if (wasTouching && !touching) {
listener.endContact(this);
}
if (!sensor && touching) {
listener.preSolve(this, oldManifold);
}
}
use of spacegraph.space2d.phys.common.Transform in project narchy by automenta.
the class Body2D method synchronizeFixtures.
protected void synchronizeFixtures() {
final Transform xf1 = pxf;
// xf1.position = m_sweep.c0 - Mul(xf1.R, m_sweep.localCenter);
// xf1.q.set(m_sweep.a0);
// Rot.mulToOutUnsafe(xf1.q, m_sweep.localCenter, xf1.p);
// xf1.p.mulLocal(-1).addLocal(m_sweep.c0);
// inlined:
Rot r = xf1;
r.s = (float) Math.sin(sweep.a0);
r.c = (float) Math.cos(sweep.a0);
xf1.pos.x = sweep.c0.x - r.c * sweep.localCenter.x + r.s * sweep.localCenter.y;
xf1.pos.y = sweep.c0.y - r.s * sweep.localCenter.x - r.c * sweep.localCenter.y;
for (Fixture f = fixtures; f != null; f = f.next) {
f.synchronize(W.contactManager.broadPhase, xf1, this);
}
}
use of spacegraph.space2d.phys.common.Transform in project narchy by automenta.
the class Glass method focee.
@Override
public Tuple2f[] focee(Tuple2f startPoint, Tuple2f vektor) {
Transform t = new Transform();
t.set(startPoint, 0);
int allCount = count * levels;
Tuple2f[] va = new Tuple2f[allCount];
for (int l = 0; l < levels; l++) {
for (int c = 0; c < count; c++) {
int i = l * count + c;
// uhol pod ktorym sa nachadza dany bod
double u = r.nextDouble() * Math.PI * 2;
double deficit = (r.nextDouble() - 0.5) * m_shattering / 20;
double r = (l + 1) * m_shattering + deficit;
double x = Math.sin(u) * r;
double y = Math.cos(u) * r;
Tuple2f v = new v2((float) x, (float) y);
va[i] = Transform.mul(t, v);
}
}
return va;
}
use of spacegraph.space2d.phys.common.Transform in project narchy by automenta.
the class Collision method collidePolygons.
/**
* Compute the collision manifold between two polygons.
*
* @param manifold
* @param polygon1
* @param xf1
* @param polygon2
* @param xf2
*/
public final void collidePolygons(Manifold manifold, final PolygonShape polyA, final Transform xfA, final PolygonShape polyB, final Transform xfB) {
// Find edge normal of max separation on A - return if separating axis is found
// Find edge normal of max separation on B - return if separation axis is found
// Choose reference edge as min(minA, minB)
// Find incident edge
// Clip
// The normal points from 1 to 2
manifold.pointCount = 0;
float totalRadius = polyA.radius + polyB.radius;
findMaxSeparation(results1, polyA, xfA, polyB, xfB);
if (results1.separation > totalRadius) {
return;
}
findMaxSeparation(results2, polyB, xfB, polyA, xfA);
if (results2.separation > totalRadius) {
return;
}
// reference polygon
final PolygonShape poly1;
// incident polygon
final PolygonShape poly2;
Transform xf1, xf2;
// reference edge
int edge1;
boolean flip;
final float k_tol = 0.1f * Settings.linearSlop;
if (results2.separation > results1.separation + k_tol) {
poly1 = polyB;
poly2 = polyA;
xf1 = xfB;
xf2 = xfA;
edge1 = results2.edgeIndex;
manifold.type = ManifoldType.FACE_B;
flip = true;
} else {
poly1 = polyA;
poly2 = polyB;
xf1 = xfA;
xf2 = xfB;
edge1 = results1.edgeIndex;
manifold.type = ManifoldType.FACE_A;
flip = false;
}
final Rot xf1q = xf1;
findIncidentEdge(incidentEdge, poly1, xf1, edge1, poly2, xf2);
int count1 = poly1.vertices;
final Tuple2f[] vertices1 = poly1.vertex;
final int iv1 = edge1;
final int iv2 = edge1 + 1 < count1 ? edge1 + 1 : 0;
v11.set(vertices1[iv1]);
v12.set(vertices1[iv2]);
localTangent.x = v12.x - v11.x;
localTangent.y = v12.y - v11.y;
localTangent.normalize();
// Vec2 localNormal = Vec2.cross(dv, 1.0f);
localNormal.x = 1f * localTangent.y;
localNormal.y = -1f * localTangent.x;
// Vec2 planePoint = 0.5f * (v11+ v12);
planePoint.x = (v11.x + v12.x) * .5f;
planePoint.y = (v11.y + v12.y) * .5f;
// Rot.mulToOutUnsafe(xf1.q, localTangent, tangent);
tangent.x = xf1q.c * localTangent.x - xf1q.s * localTangent.y;
tangent.y = xf1q.s * localTangent.x + xf1q.c * localTangent.y;
// Vec2.crossToOutUnsafe(tangent, 1f, normal);
final float normalx = 1f * tangent.y;
final float normaly = -1f * tangent.x;
Transform.mulToOut(xf1, v11, v11);
Transform.mulToOut(xf1, v12, v12);
// v11 = Mul(xf1, v11);
// v12 = Mul(xf1, v12);
// Face offset
// float frontOffset = Vec2.dot(normal, v11);
float frontOffset = normalx * v11.x + normaly * v11.y;
// Side offsets, extended by polytope skin thickness.
// float sideOffset1 = -Vec2.dot(tangent, v11) + totalRadius;
// float sideOffset2 = Vec2.dot(tangent, v12) + totalRadius;
float sideOffset1 = -(tangent.x * v11.x + tangent.y * v11.y) + totalRadius;
float sideOffset2 = tangent.x * v12.x + tangent.y * v12.y + totalRadius;
// Clip incident edge against extruded edge1 side edges.
// ClipVertex clipPoints1[2];
// ClipVertex clipPoints2[2];
int np;
// Clip to box side 1
// np = ClipSegmentToLine(clipPoints1, incidentEdge, -sideNormal, sideOffset1);
tangent.negated();
np = clipSegmentToLine(clipPoints1, incidentEdge, tangent, sideOffset1, iv1);
tangent.negated();
if (np < 2) {
return;
}
// Clip to negative box side 1
np = clipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2, iv2);
if (np < 2) {
return;
}
// Now clipPoints2 contains the clipped points.
manifold.localNormal.set(localNormal);
manifold.localPoint.set(planePoint);
int pointCount = 0;
for (int i = 0; i < Settings.maxManifoldPoints; ++i) {
// float separation = Vec2.dot(normal, clipPoints2[i].v) - frontOffset;
float separation = normalx * clipPoints2[i].v.x + normaly * clipPoints2[i].v.y - frontOffset;
if (separation <= totalRadius) {
ManifoldPoint cp = manifold.points[pointCount];
// cp.m_localPoint = MulT(xf2, clipPoints2[i].v);
Tuple2f out = cp.localPoint;
final float px = clipPoints2[i].v.x - xf2.pos.x;
final float py = clipPoints2[i].v.y - xf2.pos.y;
out.x = (xf2.c * px + xf2.s * py);
out.y = (-xf2.s * px + xf2.c * py);
cp.id.set(clipPoints2[i].id);
if (flip) {
// Swap features
cp.id.flip();
}
++pointCount;
}
}
manifold.pointCount = pointCount;
}
Aggregations