private boolean needManualCheck(Entity e1, Entity e2) { // if no physics -> check manually BodyType type1 = e1.getComponentOptional(PhysicsComponent.class) .map(p -> p.body.getType()) .orElse(null); if (type1 == null) return true; BodyType type2 = e2.getComponentOptional(PhysicsComponent.class) .map(p -> p.body.getType()) .orElse(null); if (type2 == null) return true; // if one is kinematic and the other is static -> check manually return (type1 == BodyType.KINEMATIC && type2 == BodyType.STATIC) || (type2 == BodyType.KINEMATIC && type1 == BodyType.STATIC); }
private boolean needManualCheck(Entity e1, Entity e2) { // if no physics -> check manually BodyType type1 = e1.getComponentOptional(PhysicsComponent.class) .map(p -> p.body.getType()) .orElse(null); if (type1 == null) return true; BodyType type2 = e2.getComponentOptional(PhysicsComponent.class) .map(p -> p.body.getType()) .orElse(null); if (type2 == null) return true; // if one is kinematic and the other is static -> check manually return (type1 == BodyType.KINEMATIC && type2 == BodyType.STATIC) || (type2 == BodyType.KINEMATIC && type1 == BodyType.STATIC); }
private Shape createShape(HitBox box, Entity e) { // take world center bounds and subtract from entity center (all in pixels) to get local center // because box2d operates on vector offsets from the body center, also in local coordinates Point2D boundsCenterWorld = new Point2D((box.getMinXWorld() + box.getMaxXWorld()) / 2, (box.getMinYWorld() + box.getMaxYWorld()) / 2); Point2D boundsCenterLocal = boundsCenterWorld.subtract(e.getCenter()); double w = box.getMaxXWorld() - box.getMinXWorld(); double h = box.getMaxYWorld() - box.getMinYWorld(); BoundingShape boundingShape = box.getShape(); switch (boundingShape.type) { case CIRCLE: return circle(w, boundsCenterLocal); case POLYGON: if (boundingShape.data instanceof Dimension2D) { return polygonAsBox(w, h, boundsCenterLocal); } else { return polygon((Point2D[]) boundingShape.data, boundsCenterLocal, e.getBoundingBoxComponent().getCenterLocal()); } case CHAIN: if (e.getComponent(PhysicsComponent.class).body.getType() != BodyType.STATIC) { throw new IllegalArgumentException("BoundingShape.chain() can only be used with BodyType.STATIC"); } return chain((Point2D[]) boundingShape.data, boundsCenterLocal, e.getBoundingBoxComponent().getCenterLocal()); case EDGE: default: log.warning("Unsupported hit box shape"); throw new UnsupportedOperationException("Using unsupported shape: " + boundingShape.type); } }
private Shape createShape(HitBox box, Entity e) { Bounds bounds = box.translate(e.getX(), e.getY()); // take world center bounds and subtract from entity center (all in pixels) to get local center // because box2d operates on vector offsets from the body center, also in local coordinates Point2D boundsCenterWorld = new Point2D((bounds.getMinX() + bounds.getMaxX()) / 2, (bounds.getMinY() + bounds.getMaxY()) / 2); Point2D boundsCenterLocal = boundsCenterWorld.subtract(e.getCenter()); double w = bounds.getWidth(); double h = bounds.getHeight(); BoundingShape boundingShape = box.getShape(); switch (boundingShape.type) { case CIRCLE: return circle(w, boundsCenterLocal); case POLYGON: if (boundingShape.data instanceof Dimension2D) { return polygonAsBox(w, h, boundsCenterLocal); } else { return polygon((Point2D[]) boundingShape.data, boundsCenterLocal, e.getBoundingBoxComponent().getCenterLocal()); } case CHAIN: if (e.getComponent(PhysicsComponent.class).body.getType() != BodyType.STATIC) { throw new IllegalArgumentException("BoundingShape.chain() can only be used with BodyType.STATIC"); } return chain((Point2D[]) boundingShape.data, boundsCenterLocal, e.getBoundingBoxComponent().getCenterLocal()); case EDGE: default: log.warning("Unsupported hit box shape"); throw new UnsupportedOperationException("Using unsupported shape: " + boundingShape.type); } }
Body bB = fB.getBody(); BodyType typeA = bA.getType(); BodyType typeB = bB.getType(); assert (typeA == BodyType.DYNAMIC || typeB == BodyType.DYNAMIC); for (int i = 0; i < 2; ++i) { Body body = tempBodies[i]; if (body.getType() == BodyType.DYNAMIC) { for (ContactEdge ce = body.m_contactList; ce != null; ce = ce.next) { if (island.m_bodyCount == island.m_bodyCapacity) { if (other.getType() == BodyType.DYNAMIC && !body.isBullet() && !other.isBullet()) { continue; if (other.getType() != BodyType.STATIC) { other.setAwake(true); body.m_flags &= ~Body.e_islandFlag; if (body.getType() != BodyType.DYNAMIC) { continue;
Body bB = fB.getBody(); BodyType typeA = bA.getType(); BodyType typeB = bB.getType(); assert (typeA == BodyType.DYNAMIC || typeB == BodyType.DYNAMIC); for (int i = 0; i < 2; ++i) { Body body = tempBodies[i]; if (body.getType() == BodyType.DYNAMIC) { for (ContactEdge ce = body.m_contactList; ce != null; ce = ce.next) { if (island.m_bodyCount == island.m_bodyCapacity) { if (other.getType() == BodyType.DYNAMIC && !body.isBullet() && !other.isBullet()) { continue; if (other.getType() != BodyType.STATIC) { other.setAwake(true); body.m_flags &= ~Body.e_islandFlag; if (body.getType() != BodyType.DYNAMIC) { continue;