use of spacegraph.space2d.phys.dynamics.Fixture in project narchy by automenta.
the class Rover method newTorso.
@Override
protected Body newTorso() {
PolygonShape shape = new PolygonShape();
Vec2[] vertices = { new Vec2(3.0f, 0.0f), new Vec2(-1.0f, +2.0f), new Vec2(-1.0f, -2.0f) };
shape.set(vertices, vertices.length);
// shape.m_centroid.set(bodyDef.position);
BodyDef bd = new BodyDef();
bd.linearDamping = (linearDamping);
bd.angularDamping = (angularDamping);
bd.type = BodyType.DYNAMIC;
bd.position.set(0, 0);
Body torso = getWorld().createBody(bd);
Fixture f = torso.createFixture(shape, mass);
f.setRestitution(restitution);
f.setFriction(friction);
// for (int i = -pixels / 2; i <= pixels / 2; i++) {
for (int i = 0; i < retinaPixels; i++) {
final int ii = i;
final float angle = /*MathUtils.PI / 2f*/
aStep * i;
final boolean eats = ((angle < mouthArc / 2f) || (angle > (Math.PI * 2f) - mouthArc / 2f));
// System.out.println(i + " " + angle + " " + eats);
VisionRay v = new VisionRay(this, torso, /*eats ?*/
mouthPoint, /*: new Vec2(0,0)*/
angle, aStep, retinaRaysPerPixel, L, distanceResolution) {
@Override
public void onTouch(Body touched, float di) {
if (touched == null)
return;
if (touched.getUserData() instanceof Sim.Edible) {
if (eats) {
if (di <= biteDistanceThreshold)
eat(touched);
/*} else if (di <= tasteDistanceThreshold) {
//taste(touched, di );
}*/
}
}
}
};
v.sparkColor = new Color3f(0.5f, 0.4f, 0.4f);
v.normalColor = new Color3f(0.4f, 0.4f, 0.4f);
((JoglAbstractDraw) draw).addLayer(v);
senses.add(v);
}
return torso;
}
use of spacegraph.space2d.phys.dynamics.Fixture in project narchy by automenta.
the class RoverWorld method addBlock.
public Body addBlock(float x, float y, float w, float h, float a, float mass) {
PolygonShape shape = new PolygonShape();
shape.setAsBox(w, h);
BodyDef bd = new BodyDef();
if (mass != 0) {
bd.linearDamping = (0.95f);
bd.angularDamping = (0.8f);
bd.type = BodyType.DYNAMIC;
} else {
bd.type = BodyType.STATIC;
}
bd.position.set(x, y);
Body body = p.getWorld().createBody(bd);
Fixture fd = body.createFixture(shape, mass);
fd.setRestitution(1f);
return body;
}
use of spacegraph.space2d.phys.dynamics.Fixture in project narchy by automenta.
the class PositionSolverManifold method init.
public final void init(ContactSolverDef def) {
// System.out.println("Initializing contact solver");
m_step = def.step;
m_count = def.count;
if (m_positionConstraints.length < m_count) {
ContactPositionConstraint[] old = m_positionConstraints;
m_positionConstraints = new ContactPositionConstraint[MathUtils.max(old.length * 2, m_count)];
System.arraycopy(old, 0, m_positionConstraints, 0, old.length);
for (int i = old.length; i < m_positionConstraints.length; i++) {
m_positionConstraints[i] = new ContactPositionConstraint();
}
}
if (m_velocityConstraints.length < m_count) {
ContactVelocityConstraint[] old = m_velocityConstraints;
m_velocityConstraints = new ContactVelocityConstraint[MathUtils.max(old.length * 2, m_count)];
System.arraycopy(old, 0, m_velocityConstraints, 0, old.length);
for (int i = old.length; i < m_velocityConstraints.length; i++) {
m_velocityConstraints[i] = new ContactVelocityConstraint();
}
}
m_positions = def.positions;
m_velocities = def.velocities;
m_contacts = def.contacts;
for (int i = 0; i < m_count; ++i) {
// System.out.println("contacts: " + m_count);
final Contact contact = m_contacts[i];
final Fixture fixtureA = contact.aFixture;
final Fixture fixtureB = contact.bFixture;
final Shape shapeA = fixtureA.shape();
final Shape shapeB = fixtureB.shape();
final float radiusA = shapeA.radius;
final float radiusB = shapeB.radius;
final Body2D bodyA = fixtureA.getBody();
final Body2D bodyB = fixtureB.getBody();
final Manifold manifold = contact.getManifold();
int pointCount = manifold.pointCount;
assert (pointCount > 0);
ContactVelocityConstraint vc = m_velocityConstraints[i];
vc.friction = contact.m_friction;
vc.restitution = contact.m_restitution;
vc.tangentSpeed = contact.m_tangentSpeed;
vc.indexA = bodyA.island;
vc.indexB = bodyB.island;
vc.invMassA = bodyA.m_invMass;
vc.invMassB = bodyB.m_invMass;
vc.invIA = bodyA.m_invI;
vc.invIB = bodyB.m_invI;
vc.contactIndex = i;
vc.pointCount = pointCount;
vc.K.setZero();
vc.normalMass.setZero();
ContactPositionConstraint pc = m_positionConstraints[i];
pc.indexA = bodyA.island;
pc.indexB = bodyB.island;
pc.invMassA = bodyA.m_invMass;
pc.invMassB = bodyB.m_invMass;
pc.localCenterA.set(bodyA.sweep.localCenter);
pc.localCenterB.set(bodyB.sweep.localCenter);
pc.invIA = bodyA.m_invI;
pc.invIB = bodyB.m_invI;
pc.localNormal.set(manifold.localNormal);
pc.localPoint.set(manifold.localPoint);
pc.pointCount = pointCount;
pc.radiusA = radiusA;
pc.radiusB = radiusB;
pc.type = manifold.type;
// System.out.println("contact point count: " + pointCount);
for (int j = 0; j < pointCount; j++) {
ManifoldPoint cp = manifold.points[j];
VelocityConstraintPoint vcp = vc.points[j];
if (m_step.warmStarting) {
// assert(cp.normalImpulse == 0);
// System.out.println("contact normal impulse: " + cp.normalImpulse);
vcp.normalImpulse = m_step.dtRatio * cp.normalImpulse;
vcp.tangentImpulse = m_step.dtRatio * cp.tangentImpulse;
} else {
vcp.normalImpulse = 0;
vcp.tangentImpulse = 0;
}
vcp.rA.setZero();
vcp.rB.setZero();
vcp.normalMass = 0;
vcp.tangentMass = 0;
vcp.velocityBias = 0;
pc.localPoints[j].x = cp.localPoint.x;
pc.localPoints[j].y = cp.localPoint.y;
}
}
}
Aggregations