All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.almasb.fxgl.physics.box2d.collision.GenericCollision Maven / Gradle / Ivy

There is a newer version: 21.1
Show newest version
/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB ([email protected]).
 * See LICENSE for details.
 */

package com.almasb.fxgl.physics.box2d.collision;

import com.almasb.fxgl.physics.box2d.collision.shapes.Shape;
import com.almasb.fxgl.physics.box2d.common.JBoxSettings;
import com.almasb.fxgl.physics.box2d.common.Transform;
import com.almasb.fxgl.physics.box2d.pooling.IWorldPool;

/**
 * @author Almas Baimagambetov ([email protected])
 */
public final class GenericCollision {

    private static final DistanceInput input = new DistanceInput();
    private static final Distance.SimplexCache cache = new Distance.SimplexCache();
    private static final DistanceOutput output = new DistanceOutput();

    /**
     * @return true if two generic shapes (shapeA and shapeB) overlap
     */
    public static boolean testOverlap(
            IWorldPool pool,
            Shape shapeA, int indexA,
            Shape shapeB, int indexB,
            Transform xfA, Transform xfB) {

        input.proxyA.set(shapeA, indexA);
        input.proxyB.set(shapeB, indexB);
        input.transformA.set(xfA);
        input.transformB.set(xfB);
        input.useRadii = true;

        cache.count = 0;

        pool.getDistance().distance(output, cache, input);

        return output.distance < 10.0f * JBoxSettings.EPSILON;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy