Search in sources :

Example 6 with RevoluteJointDef

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];
    }
}
Also used : Vec2(spacegraph.space2d.phys.common.Vec2) Body(spacegraph.space2d.phys.dynamics.Body) RevoluteJointDef(spacegraph.space2d.phys.dynamics.joints.RevoluteJointDef)

Aggregations

RevoluteJointDef (spacegraph.space2d.phys.dynamics.joints.RevoluteJointDef)6 PolygonShape (spacegraph.space2d.phys.collision.shapes.PolygonShape)4 spacegraph.util.math.v2 (spacegraph.util.math.v2)4 RevoluteJoint (spacegraph.space2d.phys.dynamics.joints.RevoluteJoint)3 CircleShape (spacegraph.space2d.phys.collision.shapes.CircleShape)2 DistanceJointDef (spacegraph.space2d.phys.dynamics.joints.DistanceJointDef)2 Random (java.util.Random)1 Loop (jcog.exe.Loop)1 HaiQae (jcog.learn.ql.HaiQae)1 FloatRange (jcog.math.FloatRange)1 XoRoShiRo128PlusRandom (jcog.math.random.XoRoShiRo128PlusRandom)1 Tensor (jcog.math.tensor.Tensor)1 TensorLERP (jcog.math.tensor.TensorLERP)1 SpaceGraph (spacegraph.SpaceGraph)1 Gridding (spacegraph.space2d.container.Gridding)1 VERTICAL (spacegraph.space2d.container.Gridding.VERTICAL)1 EdgeShape (spacegraph.space2d.phys.collision.shapes.EdgeShape)1 Vec2 (spacegraph.space2d.phys.common.Vec2)1 Body (spacegraph.space2d.phys.dynamics.Body)1 Body2D (spacegraph.space2d.phys.dynamics.Body2D)1