Skip to content

Instantly share code, notes, and snippets.

@gjroelofs
Created January 4, 2016 16:00
Show Gist options
  • Save gjroelofs/f60762f4e6e64ff38284 to your computer and use it in GitHub Desktop.
Save gjroelofs/f60762f4e6e64ff38284 to your computer and use it in GitHub Desktop.
public class MyGdxGame extends ApplicationAdapter {
public PerspectiveCamera cam;
public ModelBatch modelBatch;
public Model model;
public ModelInstance instance;
@Override
public void create() {
modelBatch = new ModelBatch();
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(100f, 100f, 100f);
cam.lookAt(0,0,0);
cam.near = 1f;
cam.far = 300f;
cam.update();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(5f, 5f, 5f,
new Material(ColorAttribute.createDiffuse(Color.GREEN)),
Usage.Position | Usage.Normal);
instance = new ModelInstance(model);
}
@Override
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
modelBatch.begin(cam);
instance.transform.setTranslation(0, 0, 0);
for (int i = 0; i < 10; i++) {
instance.transform.trn(10, 0, 0);
modelBatch.render(instance);
}
modelBatch.end();
}
@Override
public void dispose() {
modelBatch.dispose();
model.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment