Search in sources :

Example 1 with Physics2dBody

use of ptrman.difficultyEnvironment.physics.Physics2dBody 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 2 with Physics2dBody

use of ptrman.difficultyEnvironment.physics.Physics2dBody 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)

Aggregations

Physics2dBody (ptrman.difficultyEnvironment.physics.Physics2dBody)2 PolygonShape (spacegraph.space2d.phys.collision.shapes.PolygonShape)2 Vec2 (spacegraph.space2d.phys.common.Vec2)2