Search in sources :

Example 16 with Vec2

use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.

the class EnvironmentScriptingAccessor method physics2dCreateBodyWithShape.

public Physics2dBody physics2dCreateBodyWithShape(boolean fixed, ArrayRealVector position, List verticesPoints, float linearDamping, float angularDamping, float mass, float restitution, float friction) {
    PolygonShape shape = new PolygonShape();
    Vec2[] vertices = convertVerticesFromArrayRealVectorGenericList(verticesPoints);
    shape.set(vertices, vertices.length);
    // shape.m_centroid.set(bodyDef.position);
    BodyDef bodyDefinition = new BodyDef();
    bodyDefinition.linearDamping = linearDamping;
    bodyDefinition.angularDamping = angularDamping;
    if (fixed) {
        bodyDefinition.type = BodyType.STATIC;
    } else {
        bodyDefinition.type = BodyType.DYNAMIC;
    }
    bodyDefinition.position.set((float) position.getDataRef()[0], (float) position.getDataRef()[1]);
    Body body = environment.physicsWorld2d.createBody(bodyDefinition);
    Fixture fixture = body.createFixture(shape, mass);
    fixture.setRestitution(restitution);
    fixture.setFriction(friction);
    return new Physics2dBody(body);
}
Also used : PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) Physics2dBody(ptrman.difficultyEnvironment.physics.Physics2dBody) Vec2(spacegraph.space2d.phys.common.Vec2) Physics2dBody(ptrman.difficultyEnvironment.physics.Physics2dBody)

Example 17 with Vec2

use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.

the class EnvironmentScriptingAccessor method physics2dNearestRaycast.

public ArrayRealVector physics2dNearestRaycast(ArrayRealVector a, ArrayRealVector direction, float distance) {
    MyRaycastCallback rayCastCallback = new MyRaycastCallback();
    final ArrayRealVector b = a.add(direction.mapMultiply(distance));
    environment.physicsWorld2d.raycast(rayCastCallback, new Vec2((float) a.getDataRef()[0], (float) a.getDataRef()[1]), new Vec2((float) b.getDataRef()[0], (float) b.getDataRef()[1]));
    return rayCastCallback.nearestPoint;
}
Also used : Vec2(spacegraph.space2d.phys.common.Vec2) ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector)

Example 18 with Vec2

use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.

the class EnvironmentScriptingAccessor method convertVerticesFromArrayRealVectorGenericList.

private static Vec2[] convertVerticesFromArrayRealVectorGenericList(List verticesPoints) {
    Vec2[] vectorArray = new Vec2[verticesPoints.size()];
    for (int i = 0; i < verticesPoints.size(); i++) {
        if (!(verticesPoints.get(i) instanceof ArrayRealVector)) {
            throw new RuntimeException("element is a RealVector");
        }
        ArrayRealVector realVector = (ArrayRealVector) verticesPoints.get(i);
        vectorArray[i] = new Vec2((float) realVector.getDataRef()[0], (float) realVector.getDataRef()[1]);
    }
    return vectorArray;
}
Also used : Vec2(spacegraph.space2d.phys.common.Vec2) ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector)

Example 19 with Vec2

use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.

the class EnvironmentScriptingAccessor method physics2dCreateBody.

public Physics2dBody physics2dCreateBody(boolean fixed, String shapeType, ArrayRealVector position, ArrayRealVector size, float radius, float density, float friction) {
    BodyDef bodyDefinition = new BodyDef();
    bodyDefinition.position.set(new Vec2((float) position.getDataRef()[0], (float) position.getDataRef()[1]));
    if (fixed) {
        bodyDefinition.type = BodyType.STATIC;
    } else {
        bodyDefinition.type = BodyType.DYNAMIC;
    }
    Body body = environment.physicsWorld2d.createBody(bodyDefinition);
    PolygonShape polygonShape = new PolygonShape();
    if (shapeType.equals("BOX")) {
        polygonShape.setAsBox((float) size.getDataRef()[0] * 0.5f, (float) size.getDataRef()[1] * 0.5f);
    } else {
        throw new InternalError();
    }
    if (fixed) {
        body.createFixture(polygonShape, 0.0f);
    } else {
        FixtureDef fixture = new FixtureDef();
        fixture.shape = polygonShape;
        fixture.density = density;
        fixture.friction = friction;
        body.createFixture(fixture);
    }
    return new Physics2dBody(body);
}
Also used : PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) Physics2dBody(ptrman.difficultyEnvironment.physics.Physics2dBody) Vec2(spacegraph.space2d.phys.common.Vec2) Physics2dBody(ptrman.difficultyEnvironment.physics.Physics2dBody)

Example 20 with Vec2

use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.

the class Box2DTests method drawJoint.

private void drawJoint(Joint joint) {
    g.setColor(Color.GREEN);
    Tuple2f v1 = new Vec2();
    Tuple2f v2 = new Vec2();
    switch(joint.getType()) {
        case DISTANCE:
            DistanceJoint dj = (DistanceJoint) joint;
            v1 = joint.getBodyA().getWorldPoint(dj.getLocalAnchorA());
            v2 = joint.getBodyB().getWorldPoint(dj.getLocalAnchorB());
            break;
        case MOUSE:
            MouseJoint localMj = (MouseJoint) joint;
            localMj.getAnchorA(v1);
            localMj.getAnchorB(v2);
            break;
    }
    Point p1 = getPoint(v1);
    Point p2 = getPoint(v2);
    g.drawLine(p1.x, p1.y, p2.x, p2.y);
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) DistanceJoint(spacegraph.space2d.phys.dynamics.joints.DistanceJoint) Vec2(spacegraph.space2d.phys.common.Vec2) MouseJoint(spacegraph.space2d.phys.dynamics.joints.MouseJoint)

Aggregations

Vec2 (spacegraph.space2d.phys.common.Vec2)41 Body (spacegraph.space2d.phys.dynamics.Body)9 PolygonShape (spacegraph.space2d.phys.collision.shapes.PolygonShape)6 Tuple2f (spacegraph.util.math.Tuple2f)6 MouseJoint (spacegraph.space2d.phys.dynamics.joints.MouseJoint)4 JoglAbstractDraw (nars.rover.physics.gl.JoglAbstractDraw)3 ArrayRealVector (org.apache.commons.math3.linear.ArrayRealVector)3 Color3f (spacegraph.space2d.phys.common.Color3f)3 BodyDef (spacegraph.space2d.phys.dynamics.BodyDef)3 Fixture (spacegraph.space2d.phys.dynamics.Fixture)3 VisionRay (nars.rover.obj.VisionRay)2 Physics2dBody (ptrman.difficultyEnvironment.physics.Physics2dBody)2 CircleShape (spacegraph.space2d.phys.collision.shapes.CircleShape)2 DistanceJoint (spacegraph.space2d.phys.dynamics.joints.DistanceJoint)2 GLCapabilities (com.jogamp.opengl.GLCapabilities)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Material (nars.rover.Material)1 PhysicsModel (nars.rover.PhysicsModel)1 Sim (nars.rover.Sim)1