use of spacegraph.space2d.phys.dynamics.BodyDef 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.BodyDef 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;
}
Aggregations