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");
}
}
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);
}
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;
}
Aggregations