Search in sources :

Example 1 with AABB

use of spacegraph.space2d.phys.collision.AABB in project narchy by automenta.

the class DynamicTree method validateMetrics.

private void validateMetrics(DynamicTreeNode node) {
    if (node == null) {
        return;
    }
    DynamicTreeNode child1 = node.child1;
    DynamicTreeNode child2 = node.child2;
    if (node.child1 == null) {
        assert (child1 == null);
        assert (child2 == null);
        assert (node.height == 0);
        return;
    }
    assert (child1 != null && 0 <= child1.id && child1.id < m_nodeCapacity);
    assert (child2 != null && 0 <= child2.id && child2.id < m_nodeCapacity);
    int height1 = child1.height;
    int height2 = child2.height;
    int height;
    height = 1 + MathUtils.max(height1, height2);
    assert (node.height == height);
    AABB aabb = new AABB();
    aabb.combine(child1.aabb, child2.aabb);
    assert (aabb.lowerBound.equals(node.aabb.lowerBound));
    assert (aabb.upperBound.equals(node.aabb.upperBound));
    validateMetrics(child1);
    validateMetrics(child2);
}
Also used : AABB(spacegraph.space2d.phys.collision.AABB)

Example 2 with AABB

use of spacegraph.space2d.phys.collision.AABB in project narchy by automenta.

the class Polygon method getAABB.

/**
 * @return Vrati AABB pre Polygon sluziaci na rozsah generovanych ohnisk pre
 * fraktury. Preto je to umelo nafunknute o konstantu 1.
 */
public AABB getAABB() {
    if (count == 0) {
        return null;
    } else {
        float minX = Float.POSITIVE_INFINITY;
        float minY = Float.POSITIVE_INFINITY;
        float maxX = Float.NEGATIVE_INFINITY;
        float maxY = Float.NEGATIVE_INFINITY;
        for (int i = 0; i < count; ++i) {
            Tuple2f v = get(i);
            minX = Math.min(v.x, minX);
            maxX = Math.max(v.x, maxX);
            minY = Math.min(v.y, minY);
            maxY = Math.max(v.y, maxY);
        }
        return new AABB(new v2(minX - AABBConst, minY - AABBConst), new v2(maxX + AABBConst, maxY + AABBConst), false);
    }
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) spacegraph.util.math.v2(spacegraph.util.math.v2) AABB(spacegraph.space2d.phys.collision.AABB)

Example 3 with AABB

use of spacegraph.space2d.phys.collision.AABB in project narchy by automenta.

the class DynamicTree method moveProxy.

@Override
public final boolean moveProxy(int proxyId, final AABB aabb, Tuple2f displacement) {
    assert (aabb.isValid());
    assert (0 <= proxyId && proxyId < m_nodeCapacity);
    final DynamicTreeNode node = this.node[proxyId];
    assert (node.child1 == null);
    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 Tuple2f lowerBound = nodeAABB.lowerBound;
    final Tuple2f upperBound = nodeAABB.upperBound;
    lowerBound.x = aabb.lowerBound.x - Settings.aabbExtension;
    lowerBound.y = aabb.lowerBound.y - Settings.aabbExtension;
    upperBound.x = aabb.upperBound.x + Settings.aabbExtension;
    upperBound.y = aabb.upperBound.y + Settings.aabbExtension;
    // Predict AABB displacement.
    final float dx = displacement.x * Settings.aabbMultiplier;
    final float dy = displacement.y * Settings.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 : Tuple2f(spacegraph.util.math.Tuple2f) AABB(spacegraph.space2d.phys.collision.AABB)

Example 4 with AABB

use of spacegraph.space2d.phys.collision.AABB in project narchy by automenta.

the class DynamicTree method createProxy.

@Override
public final int createProxy(final AABB aabb, Object userData) {
    assert (aabb.isValid());
    final DynamicTreeNode node = allocateNode();
    int proxyId = node.id;
    // Fatten the aabb
    final AABB nodeAABB = node.aabb;
    nodeAABB.lowerBound.x = aabb.lowerBound.x - Settings.aabbExtension;
    nodeAABB.lowerBound.y = aabb.lowerBound.y - Settings.aabbExtension;
    nodeAABB.upperBound.x = aabb.upperBound.x + Settings.aabbExtension;
    nodeAABB.upperBound.y = aabb.upperBound.y + Settings.aabbExtension;
    node.data = userData;
    insertLeaf(proxyId);
    return proxyId;
}
Also used : AABB(spacegraph.space2d.phys.collision.AABB)

Example 5 with AABB

use of spacegraph.space2d.phys.collision.AABB in project narchy by automenta.

the class DefaultBroadPhaseBuffer method updatePairs.

@Override
public final void updatePairs(PairCallback callback) {
    // Reset pair buffer
    m_pairCount = 0;
    // Perform tree queries for all moving proxies.
    for (int i = 0; i < m_moveCount; ++i) {
        m_queryProxyId = m_moveBuffer[i];
        if (m_queryProxyId == NULL_PROXY) {
            continue;
        }
        // We have to query the tree with the fat AABB so that
        // we don't fail to create a pair that may touch later.
        final AABB fatAABB = m_tree.getFatAABB(m_queryProxyId);
        // Query tree, create pairs and add them pair buffer.
        // log.debug("quering aabb: "+m_queryProxy.aabb);
        m_tree.query(this, fatAABB);
    }
    // log.debug("Number of pairs found: "+m_pairCount);
    // Reset move buffer
    m_moveCount = 0;
    // Sort the pair buffer to expose duplicates.
    Arrays.sort(m_pairBuffer, 0, m_pairCount);
    // Send the pairs back to the client.
    int i = 0;
    while (i < m_pairCount) {
        Pair primaryPair = m_pairBuffer[i];
        Object userDataA = m_tree.getUserData(primaryPair.proxyIdA);
        Object userDataB = m_tree.getUserData(primaryPair.proxyIdB);
        // log.debug("returning pair: "+userDataA+", "+userDataB);
        callback.addPair(userDataA, userDataB);
        ++i;
        // Skip any duplicate pairs.
        while (i < m_pairCount) {
            Pair pair = m_pairBuffer[i];
            if (pair.proxyIdA != primaryPair.proxyIdA || pair.proxyIdB != primaryPair.proxyIdB) {
                break;
            }
            ++i;
        }
    }
}
Also used : AABB(spacegraph.space2d.phys.collision.AABB)

Aggregations

AABB (spacegraph.space2d.phys.collision.AABB)21 Tuple2f (spacegraph.util.math.Tuple2f)7 spacegraph.util.math.v2 (spacegraph.util.math.v2)3 QueryCallback (spacegraph.space2d.phys.callbacks.QueryCallback)1 Shape (spacegraph.space2d.phys.collision.shapes.Shape)1 Vec2 (spacegraph.space2d.phys.common.Vec2)1 Body (spacegraph.space2d.phys.dynamics.Body)1 Fixture (spacegraph.space2d.phys.dynamics.Fixture)1