Search in sources :

Example 1 with Vec2

use of com.almasb.fxgl.core.math.Vec2 in project FXGL by AlmasB.

the class ViewportSample method cinematicViewportBezier.

private void cinematicViewportBezier() {
    // 1. get viewport
    Viewport viewport = getGameScene().getViewport();
    viewport.setX(-getWidth() / 2);
    viewport.setY(-getHeight() / 2);
    // 2. define "waypoints"
    Vec2[] points = { new Vec2(98, 80), new Vec2(1520, 90), new Vec2(1470, 272), new Vec2(171, 293), new Vec2(154, 485), new Vec2(1500, 483), new Vec2(1474, 683), new Vec2(144, 698), new Vec2(161, 892), new Vec2(1475, 888), new Vec2(1477, 1064), new Vec2(108, 1066) };
    BezierSpline spline = FXGLMath.closedBezierSpline(points);
    Path path = new Path();
    path.getElements().add(new MoveTo(98, 80));
    for (BezierSpline.BezierCurve c : spline.getCurves()) {
        path.getElements().add(new CubicCurveTo(c.getControl1().x, c.getControl1().y, c.getControl2().x, c.getControl2().y, c.getEnd().x, c.getEnd().y));
    }
    // if open bezier is needed
    path.getElements().remove(path.getElements().size() - 1);
    Entity camera = Entities.builder().build();
    viewport.xProperty().bind(camera.getPositionComponent().xProperty().subtract(getWidth() / 2));
    viewport.yProperty().bind(camera.getPositionComponent().yProperty().subtract(getHeight() / 2));
    Entities.animationBuilder().duration(Duration.seconds(24)).translate(camera).buildAndPlay();
}
Also used : Entity(com.almasb.fxgl.entity.Entity) BezierSpline(com.almasb.fxgl.core.math.BezierSpline) Vec2(com.almasb.fxgl.core.math.Vec2) Viewport(com.almasb.fxgl.scene.Viewport)

Example 2 with Vec2

use of com.almasb.fxgl.core.math.Vec2 in project FXGL by AlmasB.

the class PhysicsControl method reposition.

/**
 * 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));
    body.setTransform(positionMeters, body.getAngle());
}
Also used : Point2D(javafx.geometry.Point2D) Vec2(com.almasb.fxgl.core.math.Vec2)

Example 3 with Vec2

use of com.almasb.fxgl.core.math.Vec2 in project FXGL by AlmasB.

the class PhysicsWorld method createGroundSensor.

private void createGroundSensor(Entity e) {
    // 3 is a good ratio of entity width, since we don't want to occupy the full width
    // if we want to ban "ledge" jumps
    double sensorWidth = e.getWidth() / 3;
    double sensorHeight = 5;
    // center with respect to entity center
    Point2D sensorCenterLocal = new Point2D(0, e.getHeight() / 2 - sensorHeight / 2);
    PolygonShape polygonShape = new PolygonShape();
    polygonShape.setAsBox(toMetersF(sensorWidth / 2), toMetersF(sensorHeight / 2), new Vec2(toMetersF(sensorCenterLocal.getX()), -toMetersF(sensorCenterLocal.getY())), 0);
    // https://github.com/AlmasB/FXGL/issues/491
    FixtureDef fd = new FixtureDef().sensor(true).shape(polygonShape);
    e.getComponent(PhysicsComponent.class).body.createFixture(fd);
}
Also used : Point2D(javafx.geometry.Point2D) Vec2(com.almasb.fxgl.core.math.Vec2)

Example 4 with Vec2

use of com.almasb.fxgl.core.math.Vec2 in project FXGL by AlmasB.

the class SAT method cleanArrays.

private static void cleanArrays() {
    for (Vec2 v : axes) freeVec(v);
    for (Vec2 v : corners1) freeVec(v);
    for (Vec2 v : corners2) freeVec(v);
    axes.clear();
    corners1.clear();
    corners2.clear();
}
Also used : Vec2(com.almasb.fxgl.core.math.Vec2)

Example 5 with Vec2

use of com.almasb.fxgl.core.math.Vec2 in project FXGL by AlmasB.

the class VarsSample method initGameVars.

@Override
protected void initGameVars(Map<String, Object> vars) {
    vars.put("test", -1);
    vars.put("vector", new Vec2(1, 1));
    vars.put("score", 0);
    vars.put("lives", 3);
}
Also used : Vec2(com.almasb.fxgl.core.math.Vec2)

Aggregations

Vec2 (com.almasb.fxgl.core.math.Vec2)138 Rotation (com.almasb.fxgl.physics.box2d.common.Rotation)36 Point2D (javafx.geometry.Point2D)7 Mat22 (com.almasb.fxgl.physics.box2d.common.Mat22)6 Body (com.almasb.fxgl.physics.box2d.dynamics.Body)6 Rectangle (javafx.scene.shape.Rectangle)6 GameApplication (com.almasb.fxgl.app.GameApplication)5 Vec3 (com.almasb.fxgl.core.math.Vec3)5 AABB (com.almasb.fxgl.physics.box2d.collision.AABB)5 ManifoldPoint (com.almasb.fxgl.physics.box2d.collision.ManifoldPoint)5 VelocityConstraintPoint (com.almasb.fxgl.physics.box2d.dynamics.contacts.ContactVelocityConstraint.VelocityConstraintPoint)5 Rectangle2D (javafx.geometry.Rectangle2D)5 Color (javafx.scene.paint.Color)5 Interpolators (com.almasb.fxgl.animation.Interpolators)4 GameSettings (com.almasb.fxgl.app.GameSettings)4 FXGL (com.almasb.fxgl.dsl.FXGL)4 ImagesKt (com.almasb.fxgl.texture.ImagesKt)4 Comparator (java.util.Comparator)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4