Search in sources :

Example 1 with FixtureDef

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

the class ParticleEmitter method getParticleFixtureDef.

/**
 * @return Fixture def for particle, based on current settings
 */
private FixtureDef getParticleFixtureDef() {
    FixtureDef def = new FixtureDef();
    def.density = settings.particleDensity;
    // def.filter.categoryBits = CollisionFilters.PARTICLE;
    // def.filter.groupIndex = (short) -CollisionFilters.BULLET;
    // def.filter.maskBits = (short) (CollisionFilters.GROUND | CollisionFilters.ENTITY);
    def.friction = settings.particleFriction;
    def.restitution = settings.particleRestitution;
    PolygonShape particleBox = new PolygonShape();
    particleBox.setAsBox(settings.particleWidth, settings.particleHeight);
    def.shape = particleBox;
    return def;
}
Also used : PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) FixtureDef(spacegraph.space2d.phys.dynamics.FixtureDef)

Example 2 with FixtureDef

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

the class DynamicEntity method init.

/**
 * Initialize this DynamicEntity and add it to the Physics world
 */
public void init(World world) {
    // only initialize if not intiialized
    if (!this.isInitialized) {
        // create a body using the given body def
        body = world.createBody(bodyDef);
        // set a pointer back to this object
        body.setUserData(this);
        // if we're given fixture defs, use them to create body
        if (fixtureDefs != null) {
            for (FixtureDef def : fixtureDefs) {
                body.createFixture(def);
            // def.shape.dispose();
            }
            fixtureDefs.clear();
            fixtureDefs = null;
        // else we're given a single shape as the body
        } else if (shape != null) {
            body.createFixture(shape, density);
            // shape.dispose();
            shape = null;
        } else {
            System.err.println("DynamicEntity not given enough parameters to initialize physics info!");
        }
        isInitialized = true;
    }
}
Also used : FixtureDef(spacegraph.space2d.phys.dynamics.FixtureDef)

Example 3 with FixtureDef

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

the class BoxEntity method getBoxShape.

/**
 * Gets a box shape with a given width and height
 */
private static FixtureDef getBoxShape(float width, float height, float density) {
    PolygonShape box = new PolygonShape();
    box.setAsBox(width, height);
    FixtureDef fixture = new FixtureDef();
    fixture.shape = box;
    // fixture.filter.categoryBits = CollisionFilters.ENTITY;
    // fixture.filter.maskBits = CollisionFilters.EVERYTHING;
    fixture.density = density;
    return fixture;
}
Also used : PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) FixtureDef(spacegraph.space2d.phys.dynamics.FixtureDef)

Example 4 with FixtureDef

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

the class Racer method addObstacle.

private void addObstacle(final float pX, final float pY) {
    // final Sprite box = new Sprite(pX, pY, OBSTACLE_SIZE, OBSTACLE_SIZE, this.mBoxTextureRegion, this.getVertexBufferObjectManager());
    final FixtureDef boxFixtureDef = new FixtureDef(PolygonShape.box(pX, pY), 0.1f, 0.5f);
    boxFixtureDef.restitution = 0.5f;
    // PhysicsFactory.createBoxBody(this.mPhysicsWorld, box, BodyType.DynamicBody, boxFixtureDef);
    final Body2D boxBody = mPhysicsWorld.addDynamic(boxFixtureDef);
    boxBody.setLinearDamping(10);
    boxBody.setAngularDamping(10);
// this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(box, boxBody, true, true));
// this.mScene.attachChild(box);
}
Also used : FixtureDef(spacegraph.space2d.phys.dynamics.FixtureDef) Body2D(spacegraph.space2d.phys.dynamics.Body2D)

Example 5 with FixtureDef

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

the class Racer method initRacetrackBorders.

private void initRacetrackBorders() {
    // final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
    final PolygonShape bottomOuter = PolygonShape.box(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2);
    final PolygonShape topOuter = PolygonShape.box(0, 0, CAMERA_WIDTH, 2);
    final PolygonShape leftOuter = PolygonShape.box(0, 0, 2, CAMERA_HEIGHT);
    final PolygonShape rightOuter = PolygonShape.box(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT);
    final PolygonShape bottomInner = PolygonShape.box(RACETRACK_WIDTH, CAMERA_HEIGHT - 2 - RACETRACK_WIDTH, CAMERA_WIDTH - 2 * RACETRACK_WIDTH, 2);
    final PolygonShape topInner = PolygonShape.box(RACETRACK_WIDTH, RACETRACK_WIDTH, CAMERA_WIDTH - 2 * RACETRACK_WIDTH, 2);
    final PolygonShape leftInner = PolygonShape.box(RACETRACK_WIDTH, RACETRACK_WIDTH, 2, CAMERA_HEIGHT - 2 * RACETRACK_WIDTH);
    final PolygonShape rightInner = PolygonShape.box(CAMERA_WIDTH - 2 - RACETRACK_WIDTH, RACETRACK_WIDTH, 2, CAMERA_HEIGHT - 2 * RACETRACK_WIDTH);
    // final FixtureDef wallFixtureDef = new FixtureDef(bottomOuter, 0, 0.5f);
    // //        wallFixtureDef.restitution = 0.5f;
    this.mPhysicsWorld.addStatic(new FixtureDef(bottomOuter, 0, 0.5f));
    this.mPhysicsWorld.addStatic(new FixtureDef(leftOuter, 0, 0.5f));
    this.mPhysicsWorld.addStatic(new FixtureDef(rightOuter, 0, 0.5f));
    this.mPhysicsWorld.addStatic(new FixtureDef(topOuter, 0, 0.5f));
    this.mPhysicsWorld.addStatic(new FixtureDef(bottomInner, 0, 0.5f));
    this.mPhysicsWorld.addStatic(new FixtureDef(leftInner, 0, 0.5f));
    this.mPhysicsWorld.addStatic(new FixtureDef(rightInner, 0, 0.5f));
    this.mPhysicsWorld.addStatic(new FixtureDef(topInner, 0, 0.5f));
}
Also used : PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) FixtureDef(spacegraph.space2d.phys.dynamics.FixtureDef)

Aggregations

FixtureDef (spacegraph.space2d.phys.dynamics.FixtureDef)5 PolygonShape (spacegraph.space2d.phys.collision.shapes.PolygonShape)3 Body2D (spacegraph.space2d.phys.dynamics.Body2D)1