Search in sources :

Example 76 with Vec2

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

the class JBoxUtils method clamp.

public static final Vec2 clamp(final Vec2 a, final Vec2 low, final Vec2 high) {
    final Vec2 min = new Vec2();
    min.x = a.x < high.x ? a.x : high.x;
    min.y = a.y < high.y ? a.y : high.y;
    min.x = low.x > min.x ? low.x : min.x;
    min.y = low.y > min.y ? low.y : min.y;
    return min;
}
Also used : Vec2(com.almasb.fxgl.core.math.Vec2)

Example 77 with Vec2

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

the class ChainShape method getChildEdge.

/**
 * Get a child edge.
 */
public void getChildEdge(EdgeShape edge, int index) {
    assert (0 <= index && index < m_count - 1);
    edge.setRadius(getRadius());
    final Vec2 v0 = m_vertices[index + 0];
    final Vec2 v1 = m_vertices[index + 1];
    edge.m_vertex1.x = v0.x;
    edge.m_vertex1.y = v0.y;
    edge.m_vertex2.x = v1.x;
    edge.m_vertex2.y = v1.y;
    if (index > 0) {
        Vec2 v = m_vertices[index - 1];
        edge.m_vertex0.x = v.x;
        edge.m_vertex0.y = v.y;
        edge.m_hasVertex0 = true;
    } else {
        edge.m_vertex0.x = m_prevVertex.x;
        edge.m_vertex0.y = m_prevVertex.y;
        edge.m_hasVertex0 = m_hasPrevVertex;
    }
    if (index < m_count - 2) {
        Vec2 v = m_vertices[index + 2];
        edge.m_vertex3.x = v.x;
        edge.m_vertex3.y = v.y;
        edge.m_hasVertex3 = true;
    } else {
        edge.m_vertex3.x = m_nextVertex.x;
        edge.m_vertex3.y = m_nextVertex.y;
        edge.m_hasVertex3 = m_hasNextVertex;
    }
}
Also used : Vec2(com.almasb.fxgl.core.math.Vec2)

Example 78 with Vec2

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

the class VarsSample method initGame.

@Override
protected void initGame() {
    getGameState().<Vec2>addListener("vector", ((prev, now) -> System.out.println(prev + " " + now)));
    System.out.println(getGameState().getInt("test"));
    System.out.println(getGameState().<Vec2>getObject("vector").x);
    System.out.println(getGameState().<Vec2>objectProperty("vector").get().y);
    getGameState().setValue("vector", new Vec2(300, 300));
}
Also used : Text(javafx.scene.text.Text) Color(javafx.scene.paint.Color) Map(java.util.Map) Vec2(com.almasb.fxgl.core.math.Vec2) GameSettings(com.almasb.fxgl.settings.GameSettings) GameApplication(com.almasb.fxgl.app.GameApplication) Vec2(com.almasb.fxgl.core.math.Vec2)

Example 79 with Vec2

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

the class DefaultWorldPool method getVec2Array.

public final Vec2[] getVec2Array(int argLength) {
    if (!avecs.containsKey(argLength)) {
        Vec2[] ray = new Vec2[argLength];
        for (int i = 0; i < argLength; i++) {
            ray[i] = new Vec2();
        }
        avecs.put(argLength, ray);
    }
    assert (avecs.get(argLength).length == argLength) : "Array not built with correct length";
    return avecs.get(argLength);
}
Also used : Vec2(com.almasb.fxgl.core.math.Vec2)

Example 80 with Vec2

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

the class VarsSample method initGame.

@Override
protected void initGame() {
    getWorldProperties().<Vec2>addListener("vector", (prev, now) -> System.out.println(prev + " " + now));
    System.out.println(getd("testDouble"));
    System.out.println(getb("testBoolean"));
    Vec2 vector = geto("vector");
    System.out.println(vector.x);
    System.out.println(getWorldProperties().<Vec2>objectProperty("vector").get().y);
    set("vector", new Vec2(300, 300));
}
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