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