Search in sources :

Example 6 with Fixture

use of spacegraph.space2d.phys.dynamics.Fixture 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 Fixture

use of spacegraph.space2d.phys.dynamics.Fixture 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)

Example 8 with Fixture

use of spacegraph.space2d.phys.dynamics.Fixture in project narchy by automenta.

the class PositionSolverManifold method init.

public final void init(ContactSolverDef def) {
    // System.out.println("Initializing contact solver");
    m_step = def.step;
    m_count = def.count;
    if (m_positionConstraints.length < m_count) {
        ContactPositionConstraint[] old = m_positionConstraints;
        m_positionConstraints = new ContactPositionConstraint[MathUtils.max(old.length * 2, m_count)];
        System.arraycopy(old, 0, m_positionConstraints, 0, old.length);
        for (int i = old.length; i < m_positionConstraints.length; i++) {
            m_positionConstraints[i] = new ContactPositionConstraint();
        }
    }
    if (m_velocityConstraints.length < m_count) {
        ContactVelocityConstraint[] old = m_velocityConstraints;
        m_velocityConstraints = new ContactVelocityConstraint[MathUtils.max(old.length * 2, m_count)];
        System.arraycopy(old, 0, m_velocityConstraints, 0, old.length);
        for (int i = old.length; i < m_velocityConstraints.length; i++) {
            m_velocityConstraints[i] = new ContactVelocityConstraint();
        }
    }
    m_positions = def.positions;
    m_velocities = def.velocities;
    m_contacts = def.contacts;
    for (int i = 0; i < m_count; ++i) {
        // System.out.println("contacts: " + m_count);
        final Contact contact = m_contacts[i];
        final Fixture fixtureA = contact.aFixture;
        final Fixture fixtureB = contact.bFixture;
        final Shape shapeA = fixtureA.shape();
        final Shape shapeB = fixtureB.shape();
        final float radiusA = shapeA.radius;
        final float radiusB = shapeB.radius;
        final Body2D bodyA = fixtureA.getBody();
        final Body2D bodyB = fixtureB.getBody();
        final Manifold manifold = contact.getManifold();
        int pointCount = manifold.pointCount;
        assert (pointCount > 0);
        ContactVelocityConstraint vc = m_velocityConstraints[i];
        vc.friction = contact.m_friction;
        vc.restitution = contact.m_restitution;
        vc.tangentSpeed = contact.m_tangentSpeed;
        vc.indexA = bodyA.island;
        vc.indexB = bodyB.island;
        vc.invMassA = bodyA.m_invMass;
        vc.invMassB = bodyB.m_invMass;
        vc.invIA = bodyA.m_invI;
        vc.invIB = bodyB.m_invI;
        vc.contactIndex = i;
        vc.pointCount = pointCount;
        vc.K.setZero();
        vc.normalMass.setZero();
        ContactPositionConstraint pc = m_positionConstraints[i];
        pc.indexA = bodyA.island;
        pc.indexB = bodyB.island;
        pc.invMassA = bodyA.m_invMass;
        pc.invMassB = bodyB.m_invMass;
        pc.localCenterA.set(bodyA.sweep.localCenter);
        pc.localCenterB.set(bodyB.sweep.localCenter);
        pc.invIA = bodyA.m_invI;
        pc.invIB = bodyB.m_invI;
        pc.localNormal.set(manifold.localNormal);
        pc.localPoint.set(manifold.localPoint);
        pc.pointCount = pointCount;
        pc.radiusA = radiusA;
        pc.radiusB = radiusB;
        pc.type = manifold.type;
        // System.out.println("contact point count: " + pointCount);
        for (int j = 0; j < pointCount; j++) {
            ManifoldPoint cp = manifold.points[j];
            VelocityConstraintPoint vcp = vc.points[j];
            if (m_step.warmStarting) {
                // assert(cp.normalImpulse == 0);
                // System.out.println("contact normal impulse: " + cp.normalImpulse);
                vcp.normalImpulse = m_step.dtRatio * cp.normalImpulse;
                vcp.tangentImpulse = m_step.dtRatio * cp.tangentImpulse;
            } else {
                vcp.normalImpulse = 0;
                vcp.tangentImpulse = 0;
            }
            vcp.rA.setZero();
            vcp.rB.setZero();
            vcp.normalMass = 0;
            vcp.tangentMass = 0;
            vcp.velocityBias = 0;
            pc.localPoints[j].x = cp.localPoint.x;
            pc.localPoints[j].y = cp.localPoint.y;
        }
    }
}
Also used : Shape(spacegraph.space2d.phys.collision.shapes.Shape) ManifoldPoint(spacegraph.space2d.phys.collision.ManifoldPoint) ManifoldPoint(spacegraph.space2d.phys.collision.ManifoldPoint) VelocityConstraintPoint(spacegraph.space2d.phys.dynamics.contacts.ContactVelocityConstraint.VelocityConstraintPoint) WorldManifold(spacegraph.space2d.phys.collision.WorldManifold) Manifold(spacegraph.space2d.phys.collision.Manifold) VelocityConstraintPoint(spacegraph.space2d.phys.dynamics.contacts.ContactVelocityConstraint.VelocityConstraintPoint) Fixture(spacegraph.space2d.phys.dynamics.Fixture) Body2D(spacegraph.space2d.phys.dynamics.Body2D)

Aggregations

Fixture (spacegraph.space2d.phys.dynamics.Fixture)8 PolygonShape (spacegraph.space2d.phys.collision.shapes.PolygonShape)4 Body (spacegraph.space2d.phys.dynamics.Body)4 BodyDef (spacegraph.space2d.phys.dynamics.BodyDef)4 Vec2 (spacegraph.space2d.phys.common.Vec2)3 Body2D (spacegraph.space2d.phys.dynamics.Body2D)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 VERTICAL (spacegraph.space2d.container.Gridding.VERTICAL)1 QueryCallback (spacegraph.space2d.phys.callbacks.QueryCallback)1 AABB (spacegraph.space2d.phys.collision.AABB)1