use of spacegraph.space2d.phys.dynamics.joints.RevoluteJointDef in project narchy by automenta.
the class Spider method addArm.
public void addArm(Body base, float x, float y, float angle, int armSegments, float armLength, float armWidth) {
Body[] arm = new Body[armSegments];
Body prev = base;
double dr = getArmLength(armLength, 0) / 2.0;
for (int i = 0; i < armSegments; i++) {
float al = getArmLength(armLength, i);
float aw = getArmWidth(armWidth, i);
float ax = (float) (x + Math.cos(angle) * dr);
float ay = (float) (y + Math.sin(angle) * dr);
final Body b = arm[i] = sim.create(new Vec2(ax, ay), sim.rectangle(new Vec2(al, aw), new Vec2(), angle), // , angle, 1.0f, m);
BodyType.DYNAMIC);
float rx = (float) (x + Math.cos(angle) * (dr - al / 2.0f));
float ry = (float) (y + Math.sin(angle) * (dr - al / 2.0f));
RevoluteJointDef rv = new RevoluteJointDef();
rv.initialize(arm[i], prev, new Vec2(rx, ry));
rv.enableLimit = true;
rv.enableMotor = true;
rv.upperAngle = 1;
rv.lowerAngle = -1;
// rv.referenceAngle = angle;
sim.getWorld().createJoint(rv);
// new RevoluteJointByIndexVote(brain, j, -servoRange, servoRange, servoSteps);
//
// new QuantizedScalarInput(brain, 4) {
// @Override
// public float getValue() {
// return j.getJointAngle() / (float) (Math.PI * 2.0f);
// }
// };
// new QuantizedScalarInput(brain, velocityLevels) {
// @Override
// public float getValue() {
// final float zl = b.getLinearVelocity().len2();
// if (zl == 0) return 0;
// float xx = b.getLinearVelocity().x;
// xx *= xx;
// return xx / zl;
// }
// };
// new QuantizedScalarInput(brain, velocityLevels) {
// @Override
// public float getValue() {
// final float zl = b.getLinearVelocity().len2();
// if (zl == 0) return 0;
// float yy = b.getLinearVelocity().y;
// yy *= yy;
// return yy / zl;
// }
// };
//
// new QuantizedScalarInput(brain, orientationSteps) {
// @Override
// public float getValue() {
// return b.getAngle() / (float) (2.0 * Math.PI);
// }
// };
// new QuantizedScalarInput(brain, velocityLevels) {
// @Override
// public float getValue() {
// return b.getAngularVelocity() / (float) (2.0 * Math.PI);
// }
// };
// DEPRECATED
// brain.addInput(new RevoluteJointAngle(j));
// brain.addInput(new VelocityAxis(b, true));
// brain.addInput(new VelocityAxis(b, false));
// Orientation.newVector(brain, b, orientationSteps);
// brain.addInput(new VelocityAngular(b));
// brain.addOutput(new ColorBodyTowards(b, color, 0.95f));
// brain.addOutput(new ColorBodyTowards(b, new Color(color.r * 0.5f, color.g * 0.5f, color.b * 0.5f, color.a * 0.25f), 0.95f));
// int n = numRetinasPerSegment;
// for (float z = 0; z < n; z++) {
//
// float a = z * (float) (Math.PI * 2.0 / ((float) n));
// retinas.add(new Retina(brain, b, new Vector2(0, 0), a, (float) initialVisionDistance, retinaLevels));
// }
// TODO Retina.newVector(...)
// y -= al*0.9f;
dr += al * 0.9f;
prev = arm[i];
}
}
Aggregations