Example usage for com.badlogic.gdx.math.collision BoundingBox set

List of usage examples for com.badlogic.gdx.math.collision BoundingBox set

Introduction

In this page you can find the example usage for com.badlogic.gdx.math.collision BoundingBox set.

Prototype

public BoundingBox set(Vector3 minimum, Vector3 maximum) 

Source Link

Document

Sets the given minimum and maximum vector.

Usage

From source file:gaia.cu9.ari.gaiaorbit.util.math.BoundingBoxd.java

License:Apache License

public BoundingBox put(BoundingBox bounds) {
    return bounds.set(this.min.toVector3(), this.max.toVector3());
}

From source file:net.guerra24.voxel.client.world.physics.PhysicsSystem.java

License:Open Source License

public void move(Vector3f dir, BoundingBox currentBox, Vector3f velocity) {

    BoundingBox newBox = currentBox.set(
            new Vector3(currentBox.min.x + dir.x, currentBox.min.y + dir.y, currentBox.min.z + dir.z),
            new Vector3(currentBox.max.x + dir.x, currentBox.max.y + dir.y, currentBox.max.z + dir.z));
    List<BoundingBox> boxes = world.getGlobalBoundingBox(currentBox.ext(newBox));
    Vector3 temp = new Vector3(0, 0, 0);
    Vector3 end = new Vector3(0, 0, 0);
    float precision = (float) dir.length() * 99 + 1;
    boolean colisionX = false, colisionY = false, colisionZ = false;

    for (int i = 1; i < precision; i++) {
        float avance = (i / precision);
        if (!colisionX) {
            temp.set(avance * dir.getX(), end.y, end.z);
            BoundingBox check = currentBox.set(
                    new Vector3(currentBox.min.x + temp.x, currentBox.min.y + temp.y,
                            currentBox.min.z + temp.z),
                    new Vector3(currentBox.max.x + temp.x, currentBox.max.y + temp.y,
                            currentBox.max.z + temp.z));

            for (BoundingBox box : boxes) {
                if (check.intersects(box) || box.intersects(check)) {
                    colisionX = true;//ww w  .  j a v a  2  s . c o m
                    break;
                }
            }

            if (!colisionX) {
                end.set(temp.x, end.y, end.z);
            }
        }

        if (!colisionY) {
            temp.set(end.x, avance * dir.getY(), end.z);
            BoundingBox check = currentBox.set(
                    new Vector3(currentBox.min.x + temp.x, currentBox.min.y + temp.y,
                            currentBox.min.z + temp.z),
                    new Vector3(currentBox.max.x + temp.x, currentBox.max.y + temp.y,
                            currentBox.max.z + temp.z));

            for (BoundingBox box : boxes) {
                if (check.intersects(box) || box.intersects(check)) {
                    colisionY = true;
                    break;
                }
            }

            if (!colisionY) {
                end.set(end.x, temp.y, end.z);
            }
        }
        if (!colisionZ) {
            temp.set(end.x, end.y, avance * dir.getZ());
            BoundingBox check = currentBox.set(
                    new Vector3(currentBox.min.x + temp.x, currentBox.min.y + temp.y,
                            currentBox.min.z + temp.z),
                    new Vector3(currentBox.max.x + temp.x, currentBox.max.y + temp.y,
                            currentBox.max.z + temp.z));

            for (BoundingBox box : boxes) {
                if (check.intersects(box) || box.intersects(check)) {
                    colisionZ = true;
                    break;
                }
            }

            if (!colisionZ) {
                end.set(end.x, end.y, temp.z);
            }
        }
    }
    if (colisionX)
        velocity.x = 0;
    if (colisionY)
        velocity.y = 0;
    if (colisionZ)
        velocity.z = 0;
}