Search in sources :

Example 11 with AABB

use of com.almasb.fxgl.physics.box2d.collision.AABB in project FXGL by AlmasB.

the class DynamicTree method moveProxy.

@Override
public final boolean moveProxy(int proxyId, final AABB aabb, Vec2 displacement) {
    final DynamicTreeNode node = m_nodes[proxyId];
    final AABB nodeAABB = node.aabb;
    // if (nodeAABB.contains(aabb)) {
    if (nodeAABB.lowerBound.x <= aabb.lowerBound.x && nodeAABB.lowerBound.y <= aabb.lowerBound.y && aabb.upperBound.x <= nodeAABB.upperBound.x && aabb.upperBound.y <= nodeAABB.upperBound.y) {
        return false;
    }
    removeLeaf(node);
    // Extend AABB
    final Vec2 lowerBound = nodeAABB.lowerBound;
    final Vec2 upperBound = nodeAABB.upperBound;
    lowerBound.x = aabb.lowerBound.x - JBoxSettings.aabbExtension;
    lowerBound.y = aabb.lowerBound.y - JBoxSettings.aabbExtension;
    upperBound.x = aabb.upperBound.x + JBoxSettings.aabbExtension;
    upperBound.y = aabb.upperBound.y + JBoxSettings.aabbExtension;
    // Predict AABB displacement.
    final float dx = displacement.x * JBoxSettings.aabbMultiplier;
    final float dy = displacement.y * JBoxSettings.aabbMultiplier;
    if (dx < 0.0f) {
        lowerBound.x += dx;
    } else {
        upperBound.x += dx;
    }
    if (dy < 0.0f) {
        lowerBound.y += dy;
    } else {
        upperBound.y += dy;
    }
    insertLeaf(proxyId);
    return true;
}
Also used : Vec2(com.almasb.fxgl.core.math.Vec2) AABB(com.almasb.fxgl.physics.box2d.collision.AABB)

Aggregations

AABB (com.almasb.fxgl.physics.box2d.collision.AABB)11 Vec2 (com.almasb.fxgl.core.math.Vec2)5 Shape (com.almasb.fxgl.physics.box2d.collision.shapes.Shape)1 Transform (com.almasb.fxgl.physics.box2d.common.Transform)1