Search in sources :

Example 1 with Mirror

use of com.b3dgs.lionengine.Mirror in project lionengine by b3dgs.

the class CollidableUpdater method notifyTransformed.

/**
 * Notify transformable modification.
 *
 * @param origin The origin used.
 * @param provider The provider owner.
 * @param transformable The modified transformable.
 * @param collisions The declared collisions.
 * @param cacheRectRender Cache for rendering.
 */
public void notifyTransformed(Origin origin, FeatureProvider provider, Shape transformable, List<Collision> collisions, Map<Collision, Rectangle> cacheRectRender) {
    final int length = collisions.size();
    for (int i = 0; i < length; i++) {
        final Collision collision = collisions.get(i);
        final Mirror mirror = getMirror(provider, collision);
        final int offsetX = getOffsetX(collision, mirror);
        final int offsetY = getOffsetY(collision, mirror);
        final int width;
        final int height;
        if (Collision.AUTOMATIC == collision) {
            width = transformable.getWidth();
            height = transformable.getHeight();
        } else {
            width = collision.getWidth();
            height = collision.getHeight();
        }
        if (width > maxWidth) {
            maxWidth = width;
        }
        if (height > maxHeight) {
            maxHeight = height;
        }
        final double x = origin.getX(transformable.getX() + offsetX, width);
        final double y = origin.getY(transformable.getY() + offsetY, height) + height;
        update(collision, x, y, width, height, cacheRectRender);
    }
}
Also used : Mirror(com.b3dgs.lionengine.Mirror)

Example 2 with Mirror

use of com.b3dgs.lionengine.Mirror in project lionengine by b3dgs.

the class CollidableModel method collide.

/**
 * Check if other collides with collision and its rectangle area.
 *
 * @param other The other collidable to check.
 * @param collision The collision to check with.
 * @param rectangle The collision rectangle.
 * @return The collision collides with other, <code>null</code> if none.
 */
private Collision collide(Collidable other, Collision collision, Rectangle rectangle) {
    final Mirror mirror = getMirror(collision);
    final int offsetX = getOffsetX(collision, mirror);
    final int offsetY = getOffsetY(collision, mirror);
    final double sh = rectangle.getX();
    final double sv = rectangle.getY();
    final double dh = origin.getX(transformable.getX() + offsetX, rectangle.getWidthReal()) - sh;
    final double dv = origin.getY(transformable.getY() + offsetY, rectangle.getHeightReal()) - sv;
    final double norm = Math.sqrt(dh * dh + dv * dv);
    final double sx;
    final double sy;
    if (Double.compare(norm, 0.0) == 0) {
        sx = 0;
        sy = 0;
    } else {
        sx = dh / norm;
        sy = dv / norm;
    }
    for (int count = 0; count <= norm; count++) {
        if (checkCollide(rectangle, other)) {
            return collision;
        }
        rectangle.translate(sx, sy);
    }
    return null;
}
Also used : Mirror(com.b3dgs.lionengine.Mirror)

Example 3 with Mirror

use of com.b3dgs.lionengine.Mirror in project lionengine by b3dgs.

the class CollidableModel method notifyTransformed.

/*
     * TransformableListener
     */
@Override
public void notifyTransformed(Transformable transformable) {
    if (enabled) {
        final int length = collisions.size();
        for (int i = 0; i < length; i++) {
            final Collision collision = collisions.get(i);
            final Mirror mirror = getMirror(collision);
            final int offsetX = getOffsetX(collision, mirror);
            final int offsetY = getOffsetY(collision, mirror);
            final int width;
            final int height;
            if (Collision.AUTOMATIC == collision) {
                width = transformable.getWidth();
                height = transformable.getHeight();
            } else {
                width = collision.getWidth();
                height = collision.getHeight();
            }
            if (width > maxWidth) {
                maxWidth = width;
            }
            if (height > maxHeight) {
                maxHeight = height;
            }
            final double x = origin.getX(transformable.getX() + offsetX, collision.getWidth());
            final double y = origin.getY(transformable.getY() + offsetY, collision.getHeight());
            update(collision, x, y, width, height);
        }
    }
}
Also used : Mirror(com.b3dgs.lionengine.Mirror)

Example 4 with Mirror

use of com.b3dgs.lionengine.Mirror in project lionengine by b3dgs.

the class CollidableUpdater method collide.

/**
 * Check if other collides with collision and its rectangle area.
 *
 * @param origin The origin used.
 * @param provider The provider owner.
 * @param transformable The transformable owner.
 * @param with The collision to check with.
 * @param other The other collidable to check.
 * @param rectangle The collision rectangle.
 * @param collisions The collisions couple.
 */
private static void collide(Origin origin, FeatureProvider provider, Transformable transformable, Collision with, Collidable other, Rectangle rectangle, List<CollisionCouple> collisions) {
    final Mirror mirror = getMirror(provider, with);
    final int offsetX = getOffsetX(with, mirror);
    final int offsetY = getOffsetY(with, mirror);
    final double sh = origin.getX(transformable.getOldX() + offsetX, rectangle.getWidthReal());
    final double sv = origin.getY(transformable.getOldY() + offsetY, rectangle.getHeightReal());
    final double dh = origin.getX(transformable.getX() + offsetX, rectangle.getWidthReal()) - sh;
    final double dv = origin.getY(transformable.getY() + offsetY, rectangle.getHeightReal()) - sv;
    final double nh = Math.abs(dh);
    final double nv = Math.abs(dv);
    final int max = (int) Math.ceil(Math.max(nh, nv));
    final double sx;
    final double sy;
    if (Double.compare(nh, 1.0) >= 0 || Double.compare(nv, 1.0) >= 0) {
        sx = dh / max;
        sy = dv / max;
    } else {
        sx = dh;
        sy = dv;
    }
    final double oldX = rectangle.getX();
    final double oldY = rectangle.getY();
    for (int count = 0; count < max + 1; count++) {
        if (checkCollide(with, rectangle, other, collisions)) {
            return;
        }
        rectangle.translate(sx, sy);
    }
    rectangle.set(oldX, oldY, rectangle.getWidth(), rectangle.getHeight());
}
Also used : Mirror(com.b3dgs.lionengine.Mirror)

Aggregations

Mirror (com.b3dgs.lionengine.Mirror)4