Search in sources :

Example 16 with Vector3

use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.

the class GimpactTest method create.

@Override
public void create() {
    super.create();
    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));
    chassisVertexArray = new btTriangleIndexVertexArray(chassisModel.meshParts);
    btGImpactMeshShape chassisShape = new btGImpactMeshShape(chassisVertexArray);
    chassisShape.setLocalScaling(new Vector3(1f, 1f, 1f));
    chassisShape.setMargin(0f);
    chassisShape.updateBound();
    world.addConstructor("chassis", new BulletConstructor(chassisModel, 1f, chassisShape));
    (ground = world.add("ground", 0f, 0f, 0f)).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    for (float y = 10f; y < 50f; y += 5f) world.add("chassis", -2f + (float) Math.random() * 4f, y, -2f + (float) Math.random() * 4f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    btGImpactCollisionAlgorithm.registerAlgorithm(world.dispatcher);
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) com.badlogic.gdx.physics.bullet.collision.btGImpactMeshShape(com.badlogic.gdx.physics.bullet.collision.btGImpactMeshShape) Vector3(com.badlogic.gdx.math.Vector3) com.badlogic.gdx.physics.bullet.collision.btTriangleIndexVertexArray(com.badlogic.gdx.physics.bullet.collision.btTriangleIndexVertexArray)

Example 17 with Vector3

use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.

the class FrustumCullingTest method createFrustumObject.

public static btPairCachingGhostObject createFrustumObject(final Vector3... points) {
    final btPairCachingGhostObject result = new TestPairCachingGhostObject();
    final boolean USE_COMPOUND = true;
    // Using a compound shape is not necessary, but it's good practice to create shapes around the center.
    if (USE_COMPOUND) {
        final Vector3 centerNear = new Vector3(points[2]).sub(points[0]).scl(0.5f).add(points[0]);
        final Vector3 centerFar = new Vector3(points[6]).sub(points[4]).scl(0.5f).add(points[4]);
        final Vector3 center = new Vector3(centerFar).sub(centerNear).scl(0.5f).add(centerNear);
        final btConvexHullShape hullShape = new btConvexHullShape();
        for (int i = 0; i < points.length; i++) hullShape.addPoint(tmpV.set(points[i]).sub(center));
        final btCompoundShape shape = new btCompoundShape();
        shape.addChildShape(tmpM.setToTranslation(center), hullShape);
        result.setCollisionShape(shape);
    } else {
        final btConvexHullShape shape = new btConvexHullShape();
        for (int i = 0; i < points.length; i++) shape.addPoint(points[i]);
        result.setCollisionShape(shape);
    }
    result.setCollisionFlags(btCollisionObject.CollisionFlags.CF_NO_CONTACT_RESPONSE);
    return result;
}
Also used : Vector3(com.badlogic.gdx.math.Vector3) com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject(com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject) com.badlogic.gdx.physics.bullet.collision.btConvexHullShape(com.badlogic.gdx.physics.bullet.collision.btConvexHullShape) com.badlogic.gdx.physics.bullet.collision.btCompoundShape(com.badlogic.gdx.physics.bullet.collision.btCompoundShape)

Example 18 with Vector3

use of com.badlogic.gdx.math.Vector3 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 19 with Vector3

use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.

the class ControllersTest method initialize.

private void initialize() {
    if (initialized)
        return;
    // print the currently connected controllers to the console
    print("Controllers: " + Controllers.getControllers().size);
    int i = 0;
    for (Controller controller : Controllers.getControllers()) {
        print("#" + i++ + ": " + controller.getName());
    }
    if (Controllers.getControllers().size == 0)
        print("No controllers attached");
    // setup the listener that prints events to the console
    Controllers.addListener(new ControllerListener() {

        public int indexOf(Controller controller) {
            return Controllers.getControllers().indexOf(controller, true);
        }

        @Override
        public void connected(Controller controller) {
            print("connected " + controller.getName());
            int i = 0;
            for (Controller c : Controllers.getControllers()) {
                print("#" + i++ + ": " + c.getName());
            }
        }

        @Override
        public void disconnected(Controller controller) {
            print("disconnected " + controller.getName());
            int i = 0;
            for (Controller c : Controllers.getControllers()) {
                print("#" + i++ + ": " + c.getName());
            }
            if (Controllers.getControllers().size == 0)
                print("No controllers attached");
        }

        @Override
        public boolean buttonDown(Controller controller, int buttonIndex) {
            print("#" + indexOf(controller) + ", button " + buttonIndex + " down");
            return false;
        }

        @Override
        public boolean buttonUp(Controller controller, int buttonIndex) {
            print("#" + indexOf(controller) + ", button " + buttonIndex + " up");
            return false;
        }

        @Override
        public boolean axisMoved(Controller controller, int axisIndex, float value) {
            print("#" + indexOf(controller) + ", axis " + axisIndex + ": " + value);
            return false;
        }

        @Override
        public boolean povMoved(Controller controller, int povIndex, PovDirection value) {
            print("#" + indexOf(controller) + ", pov " + povIndex + ": " + value);
            return false;
        }

        @Override
        public boolean xSliderMoved(Controller controller, int sliderIndex, boolean value) {
            print("#" + indexOf(controller) + ", x slider " + sliderIndex + ": " + value);
            return false;
        }

        @Override
        public boolean ySliderMoved(Controller controller, int sliderIndex, boolean value) {
            print("#" + indexOf(controller) + ", y slider " + sliderIndex + ": " + value);
            return false;
        }

        @Override
        public boolean accelerometerMoved(Controller controller, int accelerometerIndex, Vector3 value) {
            // not printing this as we get to many values
            return false;
        }
    });
    initialized = true;
}
Also used : PovDirection(com.badlogic.gdx.controllers.PovDirection) ControllerListener(com.badlogic.gdx.controllers.ControllerListener) Vector3(com.badlogic.gdx.math.Vector3) Controller(com.badlogic.gdx.controllers.Controller)

Example 20 with Vector3

use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.

the class SkeletonTest method renderSkeleton.

public void renderSkeleton(final Vector3 from, final Node node) {
    final Vector3 pos = vectorPool.obtain();
    node.globalTransform.getTranslation(pos);
    shapeRenderer.setColor(node.isAnimated ? Color.RED : Color.YELLOW);
    shapeRenderer.box(pos.x, pos.y, pos.z, 0.5f, 0.5f, 0.5f);
    shapeRenderer.setColor(Color.WHITE);
    shapeRenderer.line(from.x, from.y, from.z, pos.x, pos.y, pos.z);
    for (Node child : node.getChildren()) renderSkeleton(pos, child);
    vectorPool.free(pos);
}
Also used : Node(com.badlogic.gdx.graphics.g3d.model.Node) Vector3(com.badlogic.gdx.math.Vector3)

Aggregations

Vector3 (com.badlogic.gdx.math.Vector3)64 Matrix4 (com.badlogic.gdx.math.Matrix4)10 Quaternion (com.badlogic.gdx.math.Quaternion)9 Vector2 (com.badlogic.gdx.math.Vector2)6 Node (com.badlogic.gdx.graphics.g3d.model.Node)5 Texture (com.badlogic.gdx.graphics.Texture)4 Model (com.badlogic.gdx.graphics.g3d.Model)4 NodeKeyframe (com.badlogic.gdx.graphics.g3d.model.NodeKeyframe)4 BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)4 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)3 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)3 Material (com.badlogic.gdx.graphics.g3d.Material)3 ModelNode (com.badlogic.gdx.graphics.g3d.model.data.ModelNode)3 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)3 Mesh (com.badlogic.gdx.graphics.Mesh)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 Animation (com.badlogic.gdx.graphics.g3d.model.Animation)2 MeshPart (com.badlogic.gdx.graphics.g3d.model.MeshPart)2 NodeAnimation (com.badlogic.gdx.graphics.g3d.model.NodeAnimation)2