Search in sources :

Example 1 with ShapeType

use of com.almasb.fxgl.physics.box2d.collision.shapes.ShapeType in project FXGL by AlmasB.

the class HitBox method readObject.

private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
    name = (String) in.readObject();
    bounds = new BoundingBox(in.readDouble(), in.readDouble(), in.readDouble(), in.readDouble());
    Dimension2D size = new Dimension2D(in.readDouble(), in.readDouble());
    ShapeType type = (ShapeType) in.readObject();
    switch(type) {
        case CIRCLE:
            shape = BoundingShape.circle(size.getWidth() / 2);
            break;
        case POLYGON:
            shape = BoundingShape.box(size.getWidth(), size.getHeight());
            break;
        case CHAIN:
            int length = in.readInt();
            Point2D[] points = new Point2D[length];
            for (int i = 0; i < length; i++) {
                points[i] = new Point2D(in.readDouble(), in.readDouble());
            }
            shape = BoundingShape.chain(points);
            break;
        default:
            throw new IllegalArgumentException("Unknown shape type");
    }
}
Also used : Point2D(javafx.geometry.Point2D) BoundingBox(javafx.geometry.BoundingBox) Dimension2D(javafx.geometry.Dimension2D) ShapeType(com.almasb.fxgl.physics.box2d.collision.shapes.ShapeType)

Example 2 with ShapeType

use of com.almasb.fxgl.physics.box2d.collision.shapes.ShapeType in project FXGL by AlmasB.

the class ContactManager method pushContact.

private void pushContact(Contact contact) {
    Fixture fixtureA = contact.getFixtureA();
    Fixture fixtureB = contact.getFixtureB();
    if (contact.m_manifold.pointCount > 0 && !fixtureA.isSensor() && !fixtureB.isSensor()) {
        fixtureA.getBody().setAwake(true);
        fixtureB.getBody().setAwake(true);
    }
    ShapeType type1 = fixtureA.getType();
    ShapeType type2 = fixtureB.getType();
    IDynamicStack<Contact> creator = contactStacks[type1.ordinal()][type2.ordinal()].creator;
    creator.push(contact);
}
Also used : ShapeType(com.almasb.fxgl.physics.box2d.collision.shapes.ShapeType) Contact(com.almasb.fxgl.physics.box2d.dynamics.contacts.Contact)

Example 3 with ShapeType

use of com.almasb.fxgl.physics.box2d.collision.shapes.ShapeType in project FXGL by AlmasB.

the class ContactManager method popContact.

private Contact popContact(Fixture fixtureA, int indexA, Fixture fixtureB, int indexB) {
    final ShapeType type1 = fixtureA.getType();
    final ShapeType type2 = fixtureB.getType();
    final ContactRegister reg = contactStacks[type1.ordinal()][type2.ordinal()];
    if (reg == null)
        return null;
    Contact c = reg.creator.pop();
    if (reg.primary) {
        c.init(fixtureA, indexA, fixtureB, indexB);
    } else {
        c.init(fixtureB, indexB, fixtureA, indexA);
    }
    return c;
}
Also used : ShapeType(com.almasb.fxgl.physics.box2d.collision.shapes.ShapeType) ContactRegister(com.almasb.fxgl.physics.box2d.dynamics.contacts.ContactRegister) Contact(com.almasb.fxgl.physics.box2d.dynamics.contacts.Contact)

Aggregations

ShapeType (com.almasb.fxgl.physics.box2d.collision.shapes.ShapeType)3 Contact (com.almasb.fxgl.physics.box2d.dynamics.contacts.Contact)2 ContactRegister (com.almasb.fxgl.physics.box2d.dynamics.contacts.ContactRegister)1 BoundingBox (javafx.geometry.BoundingBox)1 Dimension2D (javafx.geometry.Dimension2D)1 Point2D (javafx.geometry.Point2D)1