1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.tests.bullet; 18 19 import com.badlogic.gdx.Gdx; 20 import com.badlogic.gdx.graphics.Texture; 21 import com.badlogic.gdx.graphics.VertexAttributes.Usage; 22 import com.badlogic.gdx.graphics.g3d.Material; 23 import com.badlogic.gdx.graphics.g3d.Model; 24 import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute; 25 import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute; 26 import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute; 27 import com.badlogic.gdx.math.Vector3; 28 import com.badlogic.gdx.physics.bullet.collision.btBoxShape; 29 import com.badlogic.gdx.physics.bullet.collision.btCapsuleShape; 30 import com.badlogic.gdx.physics.bullet.collision.btConeShape; 31 import com.badlogic.gdx.physics.bullet.collision.btCylinderShape; 32 import com.badlogic.gdx.physics.bullet.collision.btSphereShape; 33 34 public class BasicShapesTest extends BaseBulletTest { 35 @Override create()36 public void create () { 37 super.create(); 38 39 final Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); 40 disposables.add(texture); 41 final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1, 1, 1, 1), 42 FloatAttribute.createShininess(8f)); 43 final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates; 44 45 final Model sphere = modelBuilder.createSphere(4f, 4f, 4f, 24, 24, material, attributes); 46 disposables.add(sphere); 47 world.addConstructor("sphere", new BulletConstructor(sphere, 10f, new btSphereShape(2f))); 48 49 final Model cylinder = modelBuilder.createCylinder(4f, 6f, 4f, 16, material, attributes); 50 disposables.add(cylinder); 51 world.addConstructor("cylinder", new BulletConstructor(cylinder, 10f, new btCylinderShape(tmpV1.set(2f, 3f, 2f)))); 52 53 final Model capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes); 54 disposables.add(capsule); 55 world.addConstructor("capsule", new BulletConstructor(capsule, 10f, new btCapsuleShape(2f, 2f))); 56 57 final Model box = modelBuilder.createBox(4f, 4f, 2f, material, attributes); 58 disposables.add(box); 59 world.addConstructor("box2", new BulletConstructor(box, 10f, new btBoxShape(tmpV1.set(2f, 2f, 1f)))); 60 61 final Model cone = modelBuilder.createCone(4f, 6f, 4f, 16, material, attributes); 62 disposables.add(cone); 63 world.addConstructor("cone", new BulletConstructor(cone, 10f, new btConeShape(2f, 6f))); 64 65 // Create the entities 66 world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 67 0.25f + 0.5f * (float)Math.random(), 1f); 68 world.add("sphere", 0, 5, 5); 69 world.add("cylinder", 5, 5, 0); 70 world.add("box2", 0, 5, 0); 71 world.add("capsule", 5, 5, 5); 72 world.add("cone", 10, 5, 0); 73 } 74 75 @Override tap(float x, float y, int count, int button)76 public boolean tap (float x, float y, int count, int button) { 77 shoot(x, y); 78 return true; 79 } 80 } 81