public void setMaxValue(double value) { if (value <= minValue.get()) { log.warning("Max value <= min value. Setting min value to max value - 1"); minValue.set(value - 1); } if (value < currentValue.get()) { log.warning("Max value < current value. Setting current value to max"); currentValue.set(value); } maxValue.set(value); }
/** * Clears collidable entities and active collisions. * Does not clear collision handlers. */ public void clear() { log.debug("Clearing physics world"); entities.clear(); collisions.clear(); }
public PhysicsWorld(int appHeight, double ppm) { this.appHeight = appHeight; PIXELS_PER_METER = ppm; METERS_PER_PIXELS = 1 / PIXELS_PER_METER; initCollisionPool(); initContactListener(); initParticles(); jboxWorld.setContactFilter(new CollisionFilterCallback()); log.debugf("Physics world initialized: appHeight=%d, physics.ppm=%.1f", appHeight, ppm); }
public void setMinValue(double value) { if (value > currentValue.get()) { log.warning("Current value < min value. Setting min value as current"); currentValue.set(value); } if (value >= maxValue.get()) { log.warning("Min value >= max value. Setting max value to min value + 1"); maxValue.set(value + 1); } minValue.set(value); }
public void setCurrentValue(double value) { double newValue = value; if (value < minValue.get()) { log.warning("Current value < min value. Setting min value as current"); newValue = minValue.get(); } else if (value > maxValue.get()) { log.warning("Current value > max value. Setting max value as current"); newValue = maxValue.get(); } currentValue.set(newValue); }
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); } }
break; default: log.warning("Unknown position: " + pos); break;