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;
}
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;
}
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);
}
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);
}
}
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);
}
Aggregations