use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project libgdx by libgdx.
the class ProjectTest method create.
@Override
public void create() {
ObjLoader objLoader = new ObjLoader();
sphere = objLoader.loadModel(Gdx.files.internal("data/sphere.obj"));
sphere.materials.get(0).set(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE));
cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.far = 200;
Random rand = new Random();
for (int i = 0; i < instances.length; i++) {
instances[i] = new ModelInstance(sphere, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * -100 - 3);
}
batch = new SpriteBatch();
font = new BitmapFont();
logo = new TextureRegion(new Texture(Gdx.files.internal("data/badlogicsmall.jpg")));
modelBatch = new ModelBatch();
}
use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project libgdx by libgdx.
the class ViewportTest3 method create.
public void create() {
modelBatch = new ModelBatch();
modelBuilder = new ModelBuilder();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
shadowLight = new DirectionalLight();
shadowLight.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
environment.add(shadowLight);
modelBatch = new ModelBatch();
camera = new PerspectiveCamera();
camera.fieldOfView = 67;
camera.near = 0.1f;
camera.far = 300f;
camera.position.set(0, 0, 100);
camera.lookAt(0, 0, 0);
viewports = ViewportTest1.getViewports(camera);
viewport = viewports.first();
names = ViewportTest1.getViewportNames();
name = names.first();
ModelBuilder modelBuilder = new ModelBuilder();
Model boxModel = modelBuilder.createBox(50f, 50f, 50f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
boxInstance = new ModelInstance(boxModel);
boxInstance.transform.rotate(1, 0, 0, 30);
boxInstance.transform.rotate(0, 1, 0, 30);
Gdx.input.setInputProcessor(new InputAdapter() {
public boolean keyDown(int keycode) {
if (keycode == Input.Keys.SPACE) {
int index = (viewports.indexOf(viewport, true) + 1) % viewports.size;
name = names.get(index);
viewport = viewports.get(index);
resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
return false;
}
});
}
use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project libgdx by libgdx.
the class BasicBulletTest method create.
@Override
public void create() {
super.create();
instructions = "Swipe for next test";
lights = new Environment();
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.2f, 0.2f, 0.2f, 1.f));
lights.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1f, -0.7f));
// Set up the camera
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 the model batch
modelBatch = new ModelBatch();
// Create some basic 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.BLUE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(16f)), Usage.Position | Usage.Normal);
models.add(groundModel);
final Model sphereModel = modelBuilder.createSphere(1f, 1f, 1f, 10, 10, new Material(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f)), Usage.Position | Usage.Normal);
models.add(sphereModel);
// Load the bullet library
// Normally use: Bullet.init();
BaseBulletTest.init();
// Create the bullet world
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
broadphase = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver();
collisionWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
collisionWorld.setGravity(gravity);
// Create the shapes and body construction infos
btCollisionShape groundShape = new btBoxShape(tempVector.set(20, 0, 20));
shapes.add(groundShape);
btRigidBodyConstructionInfo groundInfo = new btRigidBodyConstructionInfo(0f, null, groundShape, Vector3.Zero);
bodyInfos.add(groundInfo);
btCollisionShape sphereShape = new btSphereShape(0.5f);
shapes.add(sphereShape);
sphereShape.calculateLocalInertia(1f, tempVector);
btRigidBodyConstructionInfo sphereInfo = new btRigidBodyConstructionInfo(1f, null, sphereShape, tempVector);
bodyInfos.add(sphereInfo);
// Create the ground
ModelInstance ground = new ModelInstance(groundModel);
instances.add(ground);
btDefaultMotionState groundMotionState = new btDefaultMotionState();
groundMotionState.setWorldTransform(ground.transform);
motionStates.add(groundMotionState);
btRigidBody groundBody = new btRigidBody(groundInfo);
groundBody.setMotionState(groundMotionState);
bodies.add(groundBody);
collisionWorld.addRigidBody(groundBody);
// Create the spheres
for (float x = -10f; x <= 10f; x += 2f) {
for (float y = 5f; y <= 15f; y += 2f) {
for (float z = 0f; z <= 0f; z += 2f) {
ModelInstance sphere = new ModelInstance(sphereModel);
instances.add(sphere);
sphere.transform.trn(x + 0.1f * MathUtils.random(), y + 0.1f * MathUtils.random(), z + 0.1f * MathUtils.random());
btDefaultMotionState sphereMotionState = new btDefaultMotionState();
sphereMotionState.setWorldTransform(sphere.transform);
motionStates.add(sphereMotionState);
btRigidBody sphereBody = new btRigidBody(sphereInfo);
sphereBody.setMotionState(sphereMotionState);
bodies.add(sphereBody);
collisionWorld.addRigidBody(sphereBody);
}
}
}
}
use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project libgdx by libgdx.
the class Animation3DTest method create.
@Override
public void create() {
super.create();
lights = new Environment();
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
lights.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -.4f, -.4f, -.4f));
lights.shadowMap = shadowLight;
inputController.rotateLeftKey = inputController.rotateRightKey = inputController.forwardKey = inputController.backwardKey = 0;
cam.position.set(25, 25, 25);
cam.lookAt(0, 0, 0);
cam.update();
modelsWindow.setVisible(false);
assets.load("data/g3d/skydome.g3db", Model.class);
assets.load("data/g3d/concrete.png", Texture.class);
assets.load("data/tree.png", Texture.class);
assets.load("data/g3d/ship.obj", Model.class);
loading = true;
trForward.translation.set(0, 0, 8f);
trBackward.translation.set(0, 0, -8f);
trLeft.rotation.setFromAxis(Vector3.Y, 90);
trRight.rotation.setFromAxis(Vector3.Y, -90);
ModelBuilder builder = new ModelBuilder();
builder.begin();
builder.node().id = "floor";
MeshPartBuilder part = builder.part("floor", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates | Usage.Normal, new Material("concrete"));
((MeshBuilder) part).ensureRectangles(1600);
for (float x = -200f; x < 200f; x += 10f) {
for (float z = -200f; z < 200f; z += 10f) {
part.rect(x, 0, z + 10f, x + 10f, 0, z + 10f, x + 10f, 0, z, x, 0, z, 0, 1, 0);
}
}
builder.node().id = "tree";
part = builder.part("tree", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates | Usage.Normal, new Material("tree"));
part.rect(0f, 0f, -10f, 10f, 0f, -10f, 10f, 10f, -10f, 0f, 10f, -10f, 0, 0, 1f);
part.setUVRange(1, 0, 0, 1);
part.rect(10f, 0f, -10f, 0f, 0f, -10f, 0f, 10f, -10f, 10f, 10f, -10f, 0, 0, -1f);
floorModel = builder.end();
shadowBatch = new ModelBatch(new DepthShaderProvider());
}
use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project libgdx by libgdx.
the class Basic3DSceneTest method create.
@Override
public void create() {
modelBatch = new ModelBatch();
lights = new Environment();
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
lights.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0f, 7f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 0.1f;
cam.far = 300f;
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
assets = new AssetManager();
assets.load("data/g3d/invaders.g3dj", Model.class);
loading = true;
}
Aggregations