Game Development Reference
In-Depth Information
Array<Model> models;
ModelInstance groundInstance;
ModelInstance sphereInstance;
Environment environment;
ModelBuilder modelbuilder;
@Override
public void create() {
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight,
0.4f, 0.4f, 0.4f, 1f));
environment.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(0, 10, -20);
cam.lookAt(0, 0, 0);
cam.update();
models = new Array<Model>();
modelbuilder = new ModelBuilder();
// creating a ground model using box shape
float groundWidth = 40;
modelbuilder.begin();
MeshPartBuilder mpb = modelbuilder.part("parts", GL20.GL_TRIANGLES,
Usage.Position | Usage.Normal | Usage.Color,
new Material(ColorAttribute.createDiffuse(Color.WHITE)));
mpb.setColor(1f, 1f, 1f, 1f);
mpb.box(0, 0, 0, groundWidth, 1, groundWidth);
Model model = modelbuilder.end();
models.add(model);
groundInstance = new ModelInstance(model);
// creating a sphere model
float radius = 2f;
final Model sphereModel = modelbuilder.createSphere(radius,
radius, radius, 20, 20, new Material(ColorAttribute.
createDiffuse(Color.RED),
ColorAttribute.createSpecular(Color.GRAY),
FloatAttribute.createShininess(64f)), Usage.Position
| Usage.Normal);
 
Search WWH ::




Custom Search