/** * Initialize the bodies, anchors, and reference angle using a world anchor point. * * @param bA * @param bB * @param anchor */ public void initialize(Body bA, Body bB, Vec2 anchor) { bodyA = bA; bodyB = bB; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
/** * Initialize the bodies, anchors, and reference angle using the world anchor. * * @param b1 * @param b2 * @param anchor */ public void initialize(final Body b1, final Body b2, final Vec2 anchor) { bodyA = b1; bodyB = b2; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
/** * Initialize the bodies, anchors, and reference angle using a world anchor point. * * @param bA * @param bB * @param anchor */ public void initialize(Body bA, Body bB, Vec2 anchor) { bodyA = bA; bodyB = bB; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
/** * Initialize the bodies, anchors, and reference angle using the world anchor. * * @param b1 * @param b2 * @param anchor */ public void initialize(final Body b1, final Body b2, final Vec2 anchor) { bodyA = b1; bodyB = b2; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
/** * Initialize the bodies, anchors, axis, and reference angle using the world anchor and world * axis. */ public void initialize(Body b1, Body b2, Vec2 anchor, Vec2 axis) { bodyA = b1; bodyB = b2; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); bodyA.getLocalVectorToOut(axis, localAxisA); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
/** * Initialize the bodies, anchors, axis, and reference angle using the world anchor and world * axis. */ public void initialize(Body b1, Body b2, Vec2 anchor, Vec2 axis) { bodyA = b1; bodyB = b2; bodyA.getLocalPointToOut(anchor, localAnchorA); bodyB.getLocalPointToOut(anchor, localAnchorB); bodyA.getLocalVectorToOut(axis, localAxisA); referenceAngle = bodyB.getAngle() - bodyA.getAngle(); } }
@Override public void onUpdate(double tpf) { if (body == null) return; // these give us min world coordinates of the overall bbox // but they are not coordinates of the entity minMeters.set( getBody().getPosition().x - physicsWorld.toMetersF(entity.getWidth() / 2), getBody().getPosition().y + physicsWorld.toMetersF(entity.getHeight() / 2) ); Point2D minWorld = physicsWorld.toPoint(minMeters); // hence we do the following, as entity.x = minXWorld - minXLocal // we round positions so that it's easy for the rest of the world to work with // snapped to pixel values entity.setX( Math.round(minWorld.getX() - entity.getBoundingBoxComponent().getMinXLocal()) ); entity.setY( Math.round(minWorld.getY() - entity.getBoundingBoxComponent().getMinYLocal()) ); entity.setRotation(-Math.toDegrees(getBody().getAngle())); }
@Override public void onUpdate(double tpf) { if (body == null) return; // these give us min world coordinates of the overall bbox // but they are not coordinates of the entity minMeters.set( getBody().getPosition().x - physicsWorld.toMetersF(entity.getWidth() / 2), getBody().getPosition().y + physicsWorld.toMetersF(entity.getHeight() / 2) ); Point2D minWorld = physicsWorld.toPoint(minMeters); // hence we do the following, as entity.x = minXWorld - minXLocal // we round positions so that it's easy for the rest of the world to work with // snapped to pixel values entity.setX( Math.round(minWorld.getX() - entity.getBoundingBoxComponent().getMinXLocal()) ); entity.setY( Math.round(minWorld.getY() - entity.getBoundingBoxComponent().getMinYLocal()) ); entity.setRotation(-Math.toDegrees(getBody().getAngle())); }
/** * Repositions an entity that supports physics directly in the physics world. * Note: depending on how it is used, it may cause non-physical behavior. * * @param point point in game world coordinates (pixels) */ public void reposition(Point2D point) { double w = getEntity().getWidth(); double h = getEntity().getHeight(); Vec2 positionMeters = physicsWorld.toPoint(new Point2D( point.getX() + w / 2, point.getY() + h / 2 )); getBody().setTransform(positionMeters, getBody().getAngle()); } }
/** * Repositions an entity that supports physics directly in the physics world. * Note: depending on how it is used, it may cause non-physical behavior. * * @param point point in game world coordinates (pixels) */ public void reposition(Point2D point) { double w = getEntity().getWidth(); double h = getEntity().getHeight(); Vec2 positionMeters = physicsWorld.toPoint(new Point2D( point.getX() + w / 2, point.getY() + h / 2 )); getBody().setTransform(positionMeters, getBody().getAngle()); } }