Search in sources :

Example 1 with Model

use of com.badlogic.gdx.graphics.g3d.Model in project libgdx by libgdx.

the class CharacterTest method create.

@Override
public void create() {
    super.create();
    instructions = "Tap to shoot\nArrow keys to move\nR to reset\nLong press to toggle debug mode\nSwipe for next test";
    // Create a visual representation of the character (note that we don't use the physics part of BulletEntity, we'll do that manually)
    final Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    disposables.add(texture);
    final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1, 1, 1, 1), FloatAttribute.createShininess(8f));
    final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
    final Model capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes);
    disposables.add(capsule);
    world.addConstructor("capsule", new BulletConstructor(capsule, null));
    character = world.add("capsule", 5f, 3f, 5f);
    // Set by reference
    characterTransform = character.transform;
    characterTransform.rotate(Vector3.X, 90);
    // Create the physics representation of the character
    ghostObject = new btPairCachingGhostObject();
    ghostObject.setWorldTransform(characterTransform);
    ghostShape = new btCapsuleShape(2f, 2f);
    ghostObject.setCollisionShape(ghostShape);
    ghostObject.setCollisionFlags(btCollisionObject.CollisionFlags.CF_CHARACTER_OBJECT);
    characterController = new btKinematicCharacterController(ghostObject, ghostShape, .35f, Vector3.Y);
    // And add it to the physics world
    world.collisionWorld.addCollisionObject(ghostObject, (short) btBroadphaseProxy.CollisionFilterGroups.CharacterFilter, (short) (btBroadphaseProxy.CollisionFilterGroups.StaticFilter | btBroadphaseProxy.CollisionFilterGroups.DefaultFilter));
    ((btDiscreteDynamicsWorld) (world.collisionWorld)).addAction(characterController);
    // Add the ground
    (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);
    // Create some boxes to play with
    for (int x = 0; x < BOXCOUNT_X; x++) {
        for (int y = 0; y < BOXCOUNT_Y; y++) {
            for (int z = 0; z < BOXCOUNT_Z; z++) {
                world.add("box", BOXOFFSET_X + x, BOXOFFSET_Y + y, BOXOFFSET_Z + z).setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
            }
        }
    }
}
Also used : com.badlogic.gdx.physics.bullet.collision.btCapsuleShape(com.badlogic.gdx.physics.bullet.collision.btCapsuleShape) Model(com.badlogic.gdx.graphics.g3d.Model) com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld(com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld) Material(com.badlogic.gdx.graphics.g3d.Material) Texture(com.badlogic.gdx.graphics.Texture) com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject(com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject) com.badlogic.gdx.physics.bullet.dynamics.btKinematicCharacterController(com.badlogic.gdx.physics.bullet.dynamics.btKinematicCharacterController)

Example 2 with Model

use of com.badlogic.gdx.graphics.g3d.Model in project libgdx by libgdx.

the class CollisionWorldTest method create.

@Override
public void create() {
    super.create();
    instructions = "Long press to toggle debug mode\nSwipe for next test\nCtrl+drag to rotate\nScroll to zoom";
    contactCB = new TestContactResultCallback();
    Model groundModel = world.getConstructor("ground").model;
    Model boxModel = world.getConstructor("box").model;
    world.addConstructor("collisionGround", new BulletConstructor(groundModel));
    world.addConstructor("collisionBox", new BulletConstructor(boxModel));
    world.add("collisionGround", 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);
    world.add("collisionBox", 0f, 1f, 5f).setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
    world.add("collisionBox", 0f, 1f, -5f).setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
    world.add("collisionBox", 5f, 1f, 0f).setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
    world.add("collisionBox", -5f, 1f, 0f).setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
    movingBox = world.add("collisionBox", -5f, 1f, 0f);
    normalColor.set(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model)

Example 3 with Model

use of com.badlogic.gdx.graphics.g3d.Model in project libgdx by libgdx.

the class ContactCacheTest method create.

@Override
public void create() {
    super.create();
    final Model sphereModel = modelBuilder.createSphere(1f, 1f, 1f, 8, 8, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE)), Usage.Position | Usage.Normal);
    disposables.add(sphereModel);
    final BulletConstructor sphereConstructor = new BulletConstructor(sphereModel, 0.5f, new btSphereShape(0.5f));
    sphereConstructor.bodyInfo.setRestitution(1f);
    world.addConstructor("sphere", sphereConstructor);
    final Model sceneModel = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
    disposables.add(sceneModel);
    final BulletConstructor sceneConstructor = new BulletConstructor(sceneModel, 0f, new btBvhTriangleMeshShape(sceneModel.meshParts));
    sceneConstructor.bodyInfo.setRestitution(0.25f);
    world.addConstructor("scene", sceneConstructor);
    final BulletEntity scene = world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90));
    scene.setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    scene.body.setContactCallbackFlag(2);
    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 (int x = 0; x < SPHERECOUNT_X; x++) {
        for (int y = 0; y < SPHERECOUNT_Y; y++) {
            for (int z = 0; z < SPHERECOUNT_Z; z++) {
                final BulletEntity e = (BulletEntity) world.add("sphere", SPHEREOFFSET_X + x * 3f, SPHEREOFFSET_Y + y * 3f, SPHEREOFFSET_Z + z * 3f);
                e.setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
                e.body.setContactCallbackFilter(2);
            }
        }
    }
    if (USE_CONTACT_CACHE) {
        contactCache = new TestContactCache();
        contactCache.entities = world.entities;
        contactCache.setCacheTime(0.5f);
    } else {
        contactListener = new TestContactListener();
        contactListener.entities = world.entities;
    }
    time = 0;
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape(com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape) com.badlogic.gdx.physics.bullet.collision.btSphereShape(com.badlogic.gdx.physics.bullet.collision.btSphereShape) Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material) TestContactListener(com.badlogic.gdx.tests.bullet.ContactCallbackTest2.TestContactListener) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 4 with Model

use of com.badlogic.gdx.graphics.g3d.Model in project libgdx by libgdx.

the class BaseBulletTest method create.

@Override
public void create() {
    init();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
    light = shadows ? new DirectionalShadowLight(1024, 1024, 20f, 20f, 1f, 300f) : new DirectionalLight();
    light.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
    environment.add(light);
    if (shadows)
        environment.shadowMap = (DirectionalShadowLight) light;
    shadowBatch = new ModelBatch(new DepthShaderProvider());
    modelBatch = new ModelBatch();
    world = createWorld();
    world.performanceCounter = performanceCounter;
    final float width = Gdx.graphics.getWidth();
    final float height = Gdx.graphics.getHeight();
    if (width > height)
        camera = new PerspectiveCamera(67f, 3f * width / height, 3f);
    else
        camera = new PerspectiveCamera(67f, 3f, 3f * height / width);
    camera.position.set(10f, 10f, 10f);
    camera.lookAt(0, 0, 0);
    camera.update();
    // Create some simple models
    final Model groundModel = modelBuilder.createRect(20f, 0f, -20f, -20f, 0f, -20f, -20f, 0f, 20f, 20f, 0f, 20f, 0, 1, 0, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(16f)), Usage.Position | Usage.Normal);
    disposables.add(groundModel);
    final Model boxModel = modelBuilder.createBox(1f, 1f, 1f, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f)), Usage.Position | Usage.Normal);
    disposables.add(boxModel);
    // Add the constructors
    // mass = 0: static body
    world.addConstructor("ground", new BulletConstructor(groundModel, 0f));
    // mass = 1kg: dynamic body
    world.addConstructor("box", new BulletConstructor(boxModel, 1f));
    // mass = 0: static body
    world.addConstructor("staticbox", new BulletConstructor(boxModel, 0f));
}
Also used : DirectionalShadowLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Model(com.badlogic.gdx.graphics.g3d.Model) Environment(com.badlogic.gdx.graphics.g3d.Environment) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) DepthShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DepthShaderProvider)

Example 5 with Model

use of com.badlogic.gdx.graphics.g3d.Model in project libgdx by libgdx.

the class BasicBulletTest method dispose.

@Override
public void dispose() {
    collisionWorld.dispose();
    solver.dispose();
    broadphase.dispose();
    dispatcher.dispose();
    collisionConfiguration.dispose();
    for (btRigidBody body : bodies) body.dispose();
    bodies.clear();
    for (btDefaultMotionState motionState : motionStates) motionState.dispose();
    motionStates.clear();
    for (btCollisionShape shape : shapes) shape.dispose();
    shapes.clear();
    for (btRigidBodyConstructionInfo info : bodyInfos) info.dispose();
    bodyInfos.clear();
    modelBatch.dispose();
    instances.clear();
    for (Model model : models) model.dispose();
    models.clear();
}
Also used : com.badlogic.gdx.physics.bullet.dynamics.btRigidBody(com.badlogic.gdx.physics.bullet.dynamics.btRigidBody) Model(com.badlogic.gdx.graphics.g3d.Model) com.badlogic.gdx.physics.bullet.linearmath.btDefaultMotionState(com.badlogic.gdx.physics.bullet.linearmath.btDefaultMotionState) com.badlogic.gdx.physics.bullet.collision.btCollisionShape(com.badlogic.gdx.physics.bullet.collision.btCollisionShape) com.badlogic.gdx.physics.bullet.dynamics.btRigidBody.btRigidBodyConstructionInfo(com.badlogic.gdx.physics.bullet.dynamics.btRigidBody.btRigidBodyConstructionInfo)

Aggregations

Model (com.badlogic.gdx.graphics.g3d.Model)34 Material (com.badlogic.gdx.graphics.g3d.Material)14 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)7 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)7 Texture (com.badlogic.gdx.graphics.Texture)6 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)5 Environment (com.badlogic.gdx.graphics.g3d.Environment)4 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)4 Vector3 (com.badlogic.gdx.math.Vector3)4 BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)4 com.badlogic.gdx.physics.bullet.collision.btBoxShape (com.badlogic.gdx.physics.bullet.collision.btBoxShape)4 com.badlogic.gdx.physics.bullet.collision.btSphereShape (com.badlogic.gdx.physics.bullet.collision.btSphereShape)4 com.badlogic.gdx.physics.bullet.dynamics.btRigidBody (com.badlogic.gdx.physics.bullet.dynamics.btRigidBody)4 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)3 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)3 Node (com.badlogic.gdx.graphics.g3d.model.Node)3 com.badlogic.gdx.physics.bullet.collision.btCollisionShape (com.badlogic.gdx.physics.bullet.collision.btCollisionShape)3 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)2 AssetManager (com.badlogic.gdx.assets.AssetManager)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2