use of com.badlogic.gdx.graphics.g3d.Material in project libgdx by libgdx.
the class BillboardParticleBatch method allocRenderable.
protected Renderable allocRenderable() {
Renderable renderable = new Renderable();
renderable.meshPart.primitiveType = GL20.GL_TRIANGLES;
renderable.meshPart.offset = 0;
renderable.material = new Material(this.blendingAttribute, this.depthTestAttribute, TextureAttribute.createDiffuse(texture));
renderable.meshPart.mesh = new Mesh(false, MAX_VERTICES_PER_MESH, MAX_PARTICLES_PER_MESH * 6, currentAttributes);
renderable.meshPart.mesh.setIndices(indices);
renderable.shader = shader;
return renderable;
}
use of com.badlogic.gdx.graphics.g3d.Material 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.Material 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.Material 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.Material in project libgdx by libgdx.
the class MeshShapeTest method create.
@Override
public void create() {
super.create();
final Model sphereModel = modelBuilder.createSphere(0.5f, 0.5f, 0.5f, 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.25f, new btSphereShape(0.25f));
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);
world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90)).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("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 x = -3; x < 7; x++) {
for (float z = -5; z < 5; z++) {
world.add("sphere", x, 10f + (float) Math.random() * 0.1f, z).setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
}
}
}
Aggregations