Search in sources :

Example 1 with BoundingBox

use of com.badlogic.gdx.math.collision.BoundingBox in project libgdx by libgdx.

the class ParticleEffect method getBoundingBox.

/** @return the merged bounding box of all controllers. */
public BoundingBox getBoundingBox() {
    if (bounds == null)
        bounds = new BoundingBox();
    BoundingBox bounds = this.bounds;
    bounds.inf();
    for (ParticleController emitter : controllers) bounds.ext(emitter.getBoundingBox());
    return bounds;
}
Also used : BoundingBox(com.badlogic.gdx.math.collision.BoundingBox)

Example 2 with BoundingBox

use of com.badlogic.gdx.math.collision.BoundingBox in project libgdx by libgdx.

the class ParticleEmitter method getBoundingBox.

/** Returns the bounding box for all active particles. z axis will always be zero. */
public BoundingBox getBoundingBox() {
    if (bounds == null)
        bounds = new BoundingBox();
    Particle[] particles = this.particles;
    boolean[] active = this.active;
    BoundingBox bounds = this.bounds;
    bounds.inf();
    for (int i = 0, n = active.length; i < n; i++) if (active[i]) {
        Rectangle r = particles[i].getBoundingRectangle();
        bounds.ext(r.x, r.y, 0);
        bounds.ext(r.x + r.width, r.y + r.height, 0);
    }
    return bounds;
}
Also used : BoundingBox(com.badlogic.gdx.math.collision.BoundingBox) Rectangle(com.badlogic.gdx.math.Rectangle)

Example 3 with BoundingBox

use of com.badlogic.gdx.math.collision.BoundingBox in project libgdx by libgdx.

the class VehicleTest method create.

@Override
public void create() {
    super.create();
    instructions = "Tap to shoot\nArrow keys to drive\nR to reset\nLong press to toggle debug mode\nSwipe for next test";
    final Model chassisModel = objLoader.loadModel(Gdx.files.internal("data/car.obj"));
    disposables.add(chassisModel);
    chassisModel.materials.get(0).clear();
    chassisModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE));
    final Model wheelModel = objLoader.loadModel(Gdx.files.internal("data/wheel.obj"));
    disposables.add(wheelModel);
    wheelModel.materials.get(0).clear();
    wheelModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.BLACK), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(128));
    Texture checkboard = new Texture(Gdx.files.internal("data/g3d/checkboard.png"));
    final Model largeGroundModel = modelBuilder.createBox(200f, 2f, 200f, new Material(TextureAttribute.createDiffuse(checkboard), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(16f)), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    largeGroundModel.manageDisposable(checkboard);
    disposables.add(largeGroundModel);
    world.addConstructor("largeground", new BulletConstructor(largeGroundModel, 0f));
    BoundingBox bounds = new BoundingBox();
    Vector3 chassisHalfExtents = chassisModel.calculateBoundingBox(bounds).getDimensions(new Vector3()).scl(0.5f);
    Vector3 wheelHalfExtents = wheelModel.calculateBoundingBox(bounds).getDimensions(new Vector3()).scl(0.5f);
    world.addConstructor("chassis", new BulletConstructor(chassisModel, 5f, new btBoxShape(chassisHalfExtents)));
    world.addConstructor("wheel", new BulletConstructor(wheelModel, 0, null));
    for (int i = 0; i < 1000; i += 200) world.add("largeground", 0f, -1f, i);
    chassis = world.add("chassis", 0, 3f, 0);
    wheels[0] = world.add("wheel", 0, 0, 0);
    wheels[1] = world.add("wheel", 0, 0, 0);
    wheels[2] = world.add("wheel", 0, 0, 0);
    wheels[3] = world.add("wheel", 0, 0, 0);
    // Create the vehicle
    raycaster = getRaycaster();
    tuning = new btVehicleTuning();
    vehicle = new btRaycastVehicle(tuning, (btRigidBody) chassis.body, raycaster);
    chassis.body.setActivationState(Collision.DISABLE_DEACTIVATION);
    ((btDynamicsWorld) world.collisionWorld).addVehicle(vehicle);
    vehicle.setCoordinateSystem(0, 1, 2);
    btWheelInfo wheelInfo;
    Vector3 point = new Vector3();
    Vector3 direction = new Vector3(0, -1, 0);
    Vector3 axis = new Vector3(-1, 0, 0);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, 0.7f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, 0.7f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, -0.5f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, -0.5f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBoxShape(com.badlogic.gdx.physics.bullet.collision.btBoxShape) com.badlogic.gdx.physics.bullet.dynamics.btRaycastVehicle(com.badlogic.gdx.physics.bullet.dynamics.btRaycastVehicle) com.badlogic.gdx.physics.bullet.dynamics.btWheelInfo(com.badlogic.gdx.physics.bullet.dynamics.btWheelInfo) com.badlogic.gdx.physics.bullet.dynamics.btRaycastVehicle.btVehicleTuning(com.badlogic.gdx.physics.bullet.dynamics.btRaycastVehicle.btVehicleTuning) Material(com.badlogic.gdx.graphics.g3d.Material) Vector3(com.badlogic.gdx.math.Vector3) Texture(com.badlogic.gdx.graphics.Texture) com.badlogic.gdx.physics.bullet.dynamics.btRigidBody(com.badlogic.gdx.physics.bullet.dynamics.btRigidBody) com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld(com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld) BoundingBox(com.badlogic.gdx.math.collision.BoundingBox) Model(com.badlogic.gdx.graphics.g3d.Model)

Example 4 with BoundingBox

use of com.badlogic.gdx.math.collision.BoundingBox in project libgdx by libgdx.

the class Animation3DTest method onLoaded.

@Override
protected void onLoaded() {
    if (skydome == null) {
        skydome = new ModelInstance(assets.get("data/g3d/skydome.g3db", Model.class));
        floorModel.getMaterial("concrete").set(TextureAttribute.createDiffuse(assets.get("data/g3d/concrete.png", Texture.class)));
        floorModel.getMaterial("tree").set(TextureAttribute.createDiffuse(assets.get("data/tree.png", Texture.class)), new BlendingAttribute());
        instances.add(new ModelInstance(floorModel, "floor"));
        instances.add(tree = new ModelInstance(floorModel, "tree"));
        assets.load("data/g3d/knight.g3db", Model.class);
        loading = true;
    } else if (character == null) {
        character = new ModelInstance(assets.get("data/g3d/knight.g3db", Model.class));
        BoundingBox bbox = new BoundingBox();
        character.calculateBoundingBox(bbox);
        character.transform.setToRotation(Vector3.Y, 180).trn(0, -bbox.min.y, 0);
        instances.add(character);
        animation = new AnimationController(character);
        animation.animate("Idle", -1, 1f, null, 0.2f);
        status = idle;
        for (Animation anim : character.animations) Gdx.app.log("Test", anim.id);
        // Now attach the node of another model at the tip of this knights sword:
        ship = assets.get("data/g3d/ship.obj", Model.class).nodes.get(0).copy();
        ship.detach();
        // offset from the sword node to the tip of the sword, in rest pose
        ship.translation.x = 10f;
        ship.rotation.set(Vector3.Z, 90f);
        ship.scale.scl(5f);
        ship.parts.get(0).enabled = false;
        character.getNode("sword").addChild(ship);
    }
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) BoundingBox(com.badlogic.gdx.math.collision.BoundingBox) Model(com.badlogic.gdx.graphics.g3d.Model) Animation(com.badlogic.gdx.graphics.g3d.model.Animation)

Example 5 with BoundingBox

use of com.badlogic.gdx.math.collision.BoundingBox in project libgdx by libgdx.

the class LightsTest method onLoaded.

@Override
protected void onLoaded() {
    super.onLoaded();
    BoundingBox bounds = instances.get(0).calculateBoundingBox(new BoundingBox());
    bounds.getCenter(center);
    radius = bounds.getDimensions(tmpV).len() * .5f;
    pointLight.position.set(0, radius, 0).add(transformedCenter.set(center).mul(transform));
    pointLight.intensity = radius * radius;
    ((ColorAttribute) pLight.material.get(ColorAttribute.Diffuse)).color.set(pointLight.color);
    final float s = 0.2f * radius;
    pLight.worldTransform.setToScaling(s, s, s);
}
Also used : BoundingBox(com.badlogic.gdx.math.collision.BoundingBox)

Aggregations

BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)10 Model (com.badlogic.gdx.graphics.g3d.Model)4 Vector3 (com.badlogic.gdx.math.Vector3)4 Texture (com.badlogic.gdx.graphics.Texture)2 Material (com.badlogic.gdx.graphics.g3d.Material)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 Node (com.badlogic.gdx.graphics.g3d.model.Node)2 com.badlogic.gdx.physics.bullet.collision.btBoxShape (com.badlogic.gdx.physics.bullet.collision.btBoxShape)2 AssetManager (com.badlogic.gdx.assets.AssetManager)1 Camera (com.badlogic.gdx.graphics.Camera)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 BlendingAttribute (com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute)1 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)1 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)1 DirectionalShadowLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight)1 Animation (com.badlogic.gdx.graphics.g3d.model.Animation)1 MeshPart (com.badlogic.gdx.graphics.g3d.model.MeshPart)1 NodePart (com.badlogic.gdx.graphics.g3d.model.NodePart)1 AnimationController (com.badlogic.gdx.graphics.g3d.utils.AnimationController)1