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

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

Introduction

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

Prototype

public Vector3 getCenter(Vector3 out) 

Source Link

Usage

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

License:Open Source License

@Override
public void update(float deltaTime) {
    Vector3f tempdir0 = new Vector3f();
    Vector3 tempdir1 = new Vector3();
    for (Entity entity : entities) {

        PositionComponent position = pm.get(entity);
        VelocityComponent velocity = vm.get(entity);
        CollisionComponent collison = cm.get(entity);

        Vector3f positionV = position.position;
        Vector3f velocityV = velocity.velocity;

        velocityV.y += -9.8f * deltaTime;

        velocityV.x *= 0.4f - velocityV.x * 0.01f;
        velocityV.z *= 0.4f - velocityV.z * 0.01f;

        collison.boundingBox.set(new Vector3(positionV.x - 0.5f, positionV.y - 1.0f, positionV.z - 0.5f),
                new Vector3(positionV.x + 0.5f, positionV.y + 0.2f, positionV.z + 0.5f));
        for (BoundingBox boundingBox : colliders) {
            tempdir1 = boundingBox.getCenter(tempdir1);
            tempdir0.set(tempdir1);//w  w  w  . ja v  a  2s. c om
            Vector3f dir = Vector3f.sub(positionV, tempdir0, null);
            dir.normalise();
            if (dir.y > 0 && velocityV.y < 0) {
                if (collison.boundingBox.intersects(boundingBox))
                    velocityV.y = 0;
            } else if (dir.y < 0 && velocityV.y > 0) {
                if (collison.boundingBox.intersects(boundingBox))
                    velocityV.y = 0;
            } else if (dir.x > 0 && velocityV.x < 0) {
                if (collison.boundingBox.intersects(boundingBox))
                    velocityV.x = 0;
            } else if (dir.x < 0 && velocityV.x > 0) {
                if (collison.boundingBox.intersects(boundingBox))
                    velocityV.x = 0;
            } else if (dir.z > 0 && velocityV.z < 0) {
                if (collison.boundingBox.intersects(boundingBox))
                    velocityV.z = 0;
            } else if (dir.z < 0 && velocityV.z > 0) {
                if (collison.boundingBox.intersects(boundingBox))
                    velocityV.z = 0;
            }
        }
        position.position.x += velocityV.x * deltaTime;
        position.position.y += velocityV.y * deltaTime;
        position.position.z += velocityV.z * deltaTime;
    }
}