Search in sources :

Example 6 with BodyDef

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;
}
Also used : PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) VisionRay(nars.rover.obj.VisionRay) Color3f(spacegraph.space2d.phys.common.Color3f) Vec2(spacegraph.space2d.phys.common.Vec2) Fixture(spacegraph.space2d.phys.dynamics.Fixture) BodyDef(spacegraph.space2d.phys.dynamics.BodyDef) Body(spacegraph.space2d.phys.dynamics.Body) JoglAbstractDraw(nars.rover.physics.gl.JoglAbstractDraw)

Example 7 with BodyDef

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;
}
Also used : PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) Fixture(spacegraph.space2d.phys.dynamics.Fixture) BodyDef(spacegraph.space2d.phys.dynamics.BodyDef) Body(spacegraph.space2d.phys.dynamics.Body)

Aggregations

BodyDef (spacegraph.space2d.phys.dynamics.BodyDef)7 PolygonShape (spacegraph.space2d.phys.collision.shapes.PolygonShape)6 Body (spacegraph.space2d.phys.dynamics.Body)4 Fixture (spacegraph.space2d.phys.dynamics.Fixture)4 Vec2 (spacegraph.space2d.phys.common.Vec2)3 CircleShape (spacegraph.space2d.phys.collision.shapes.CircleShape)2 Body2D (spacegraph.space2d.phys.dynamics.Body2D)2 ParticleGroupDef (spacegraph.space2d.phys.particle.ParticleGroupDef)2 spacegraph.util.math.v2 (spacegraph.util.math.v2)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 VisionRay (nars.rover.obj.VisionRay)1 JoglAbstractDraw (nars.rover.physics.gl.JoglAbstractDraw)1 SpaceGraph (spacegraph.SpaceGraph)1 Gridding (spacegraph.space2d.container.Gridding)1