use of spacegraph.space2d.phys.dynamics.Body in project narchy by automenta.
the class SwingDraw method draw.
public void draw(World w) {
graphics = panel.getDBGraphics();
// for (LayerDraw l : layers) l.drawGround(this, w);
int flags = getFlags();
if ((flags & DebugDraw.e_shapeBit) != 0) {
for (Body b = w.getBodyList(); b != null; b = b.getNext()) {
drawBody(b);
}
// drawParticleSystem(m_particleSystem);
}
if ((flags & DebugDraw.e_jointBit) != 0) {
for (Joint j = w.getJointList(); j != null; j = j.getNext()) {
drawJoint(j);
}
}
// if ((flags & DebugDraw.e_pairBit) != 0) {
// color.set(0.3f, 0.9f, 0.9f);
// for (Contact c = m_contactManager.m_contactList; c != null; c = c.getNext()) {
// Fixture fixtureA = c.getFixtureA();
// Fixture fixtureB = c.getFixtureB();
// fixtureA.getAABB(c.getChildIndexA()).getCenterToOut(cA);
// fixtureB.getAABB(c.getChildIndexB()).getCenterToOut(cB);
// drawSegment(cA, cB, color);
// }
// }
//
// if ((flags & DebugDraw.e_aabbBit) != 0) {
// color.set(0.9f, 0.3f, 0.9f);
//
// for (Body b = m_bodyList; b != null; b = b.getNext()) {
// if (b.isActive() == false) {
// continue;
// }
//
// for (Fixture f = b.getFixtureList(); f != null; f = f.getNext()) {
// for (int i = 0; i < f.m_proxyCount; ++i) {
// FixtureProxy proxy = f.m_proxies[i];
// AABB aabb = m_contactManager.m_broadPhase.getFatAABB(proxy.proxyId);
// if (aabb != null) {
// Vec2[] vs = avs.get(4);
// vs[0].set(aabb.lowerBound.x, aabb.lowerBound.y);
// vs[1].set(aabb.upperBound.x, aabb.lowerBound.y);
// vs[2].set(aabb.upperBound.x, aabb.upperBound.y);
// vs[3].set(aabb.lowerBound.x, aabb.upperBound.y);
// drawPolygon(vs, 4, color);
// }
// }
// }
// }
// }
//
// if ((flags & DebugDraw.e_centerOfMassBit) != 0) {
// for (Body b = m_bodyList; b != null; b = b.getNext()) {
// xf.set(b.getTransform());
// xf.p.set(b.getWorldCenter());
// drawTransform(xf);
// }
// }
//
// if ((flags & DebugDraw.e_dynamicTreeBit) != 0) {
// m_contactManager.m_broadPhase.drawTree(m_debugDraw);
// }
// for (LayerDraw l : layers) l.drawSky(this, w);
// flush();
}
use of spacegraph.space2d.phys.dynamics.Body in project narchy by automenta.
the class SwingDraw method drawJoint.
private void drawJoint(Joint joint) {
Body bodyA = joint.getBodyA();
Body bodyB = joint.getBodyB();
Transform xf1 = bodyA.getTransform();
Transform xf2 = bodyB.getTransform();
Vec2 x1 = xf1.p;
Vec2 x2 = xf2.p;
joint.getAnchorA(p1);
joint.getAnchorB(p2);
color.set(0.5f, 0.8f, 0.8f);
switch(joint.getType()) {
// TODO djm write after writing joints
case DISTANCE:
drawSegment(p1, p2, color);
break;
case PULLEY:
{
PulleyJoint pulley = (PulleyJoint) joint;
Vec2 s1 = pulley.getGroundAnchorA();
Vec2 s2 = pulley.getGroundAnchorB();
drawSegment(s1, p1, color);
drawSegment(s2, p2, color);
drawSegment(s1, s2, color);
}
break;
case CONSTANT_VOLUME:
case MOUSE:
// don't draw this
break;
default:
drawSegment(x1, p1, color);
drawSegment(p1, p2, color);
drawSegment(x2, p2, color);
}
// pool.pushVec2(2);
}
use of spacegraph.space2d.phys.dynamics.Body in project narchy by automenta.
the class CarefulRover 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.5f, 0), 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);
initSensors(torso);
initMotors(torso);
return torso;
}
use of spacegraph.space2d.phys.dynamics.Body in project narchy by automenta.
the class Spider method init.
@Override
public void init(Sim p) {
this.sim = p;
// ix, iy, 1.0f, m);
Body base = sim.create(new Vec2(ix, iy), sim.circle(torsoRadius), BodyType.DYNAMIC);
float da = (float) ((Math.PI * 2.0) / arms);
float a = 0;
for (int i = 0; i < arms; i++) {
float ax = (float) (ix + (Math.cos(a) * torsoRadius));
float ay = (float) (iy + (Math.sin(a) * torsoRadius));
addArm(base, ax, ay, a, armSegments, armLength, armWidth);
a += da;
}
// //base's eyes
// int n = numRetinasPerSegment;
// for (float z = 0; z < n; z++) {
//
// float ba = z * (float) (Math.PI * 2.0 / ((float) n));
// retinas.add(new Retina(brain, base, new Vector2(0, 0), ba, (float) initialVisionDistance, retinaLevels));
//
// brain.addOutput(new Thruster(base, ba));
// }
//
//
// brainWiring.wireBrain(brain);
//
// new BrainReport(brain);
}
use of spacegraph.space2d.phys.dynamics.Body in project narchy by automenta.
the class ReactorWorld method fireDebris.
/**
* fuel rod components mixed with plutonium ash mutated into a supernatural buckyball atomic compound
*/
protected void fireDebris(float w, float h) {
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(0.0f, 4.0f);
PolygonShape box = new PolygonShape();
box.setAsBox(w, h);
Body m_body = p.getWorld().createBody(bd);
m_body.createFixture(box, 1.0f);
box.setAsBox(0.25f, 0.25f);
// m_x = RandomFloat(-1.0f, 1.0f);
float m_x = -0.06530577f;
bd.position.set(m_x, 10.0f);
bd.bullet = true;
Body m_bullet = p.getWorld().createBody(bd);
m_bullet.createFixture(box, 100.0f);
m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f));
m_body.setTransform(new Vec2(0.0f, 4.0f), 0.0f);
m_body.setLinearVelocity(new Vec2());
m_body.setAngularVelocity(0.0f);
m_x = MathUtils.randomFloat(-1.0f, 1.0f);
m_bullet.setTransform(new Vec2(m_x, 10.0f), 0.0f);
m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f));
m_bullet.setAngularVelocity(0.0f);
}
Aggregations