Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.badlogic.gdx.ApplicationListener;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.InputAdapter;
- import com.badlogic.gdx.InputMultiplexer;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.GL10;
- import com.badlogic.gdx.graphics.PerspectiveCamera;
- import com.badlogic.gdx.graphics.VertexAttributes.Usage;
- import com.badlogic.gdx.graphics.g3d.Environment;
- import com.badlogic.gdx.graphics.g3d.Material;
- import com.badlogic.gdx.graphics.g3d.Model;
- import com.badlogic.gdx.graphics.g3d.ModelBatch;
- import com.badlogic.gdx.graphics.g3d.ModelInstance;
- import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
- import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
- import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
- public class Game implements ApplicationListener {
- public PerspectiveCamera cam;
- public Model model;
- public ModelInstance instance;
- public ModelBatch modelBatch;
- public Environment environment;
- public InputMultiplexer input;
- public static int gWidth = 800;
- public static int gHeight = 600;
- @Override
- public void create() {
- this.modelBatch = new ModelBatch();
- this.environment = new Environment();
- this.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
- this.environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
- /**
- * Add input adapters.
- */
- this.cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- this.cam.position.set(10f, 20f, 0);
- this.cam.lookAt(0, 0, 0);
- this.cam.rotate(67f, 0f, 0f, 0f);
- this.cam.near = 1f;
- this.cam.far = 300f;
- this.input = new InputMultiplexer(Gdx.input.getInputProcessor());
- this.input.addProcessor(new MouseCamController());
- Gdx.input.setInputProcessor(this.input);
- this.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 resize(int width, int height) {
- }
- @Override
- public void render() {
- Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
- // if (this.cam.fieldOfView < 120) {
- // this.cam.fieldOfView += 10;
- // }
- this.cam.update();
- this.modelBatch.begin(this.cam);
- this.modelBatch.render(instance, environment);
- this.modelBatch.end();
- }
- @Override
- public void pause() {
- }
- @Override
- public void resume() {
- }
- @Override
- public void dispose() {
- this.modelBatch.dispose();
- this.model.dispose();
- }
- public class MouseCamController extends InputAdapter {
- @Override
- public boolean scrolled(int amount) {
- // Gdx.app.log("INPUT", "A: " + amount);
- return true;
- }
- }
- }
- Exception in thread "LWJGL Application" java.lang.NullPointerException
- at com.badlogic.gdx.InputMultiplexer.mouseMoved(InputMultiplexer.java:107)
- at com.badlogic.gdx.backends.lwjgl.LwjglInput.processEvents(LwjglInput.java:303)
- at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:200)
- at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement