Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. import com.badlogic.gdx.ApplicationListener;
  2. import com.badlogic.gdx.Gdx;
  3. import com.badlogic.gdx.InputAdapter;
  4. import com.badlogic.gdx.InputMultiplexer;
  5. import com.badlogic.gdx.graphics.Color;
  6. import com.badlogic.gdx.graphics.GL10;
  7. import com.badlogic.gdx.graphics.PerspectiveCamera;
  8. import com.badlogic.gdx.graphics.VertexAttributes.Usage;
  9. import com.badlogic.gdx.graphics.g3d.Environment;
  10. import com.badlogic.gdx.graphics.g3d.Material;
  11. import com.badlogic.gdx.graphics.g3d.Model;
  12. import com.badlogic.gdx.graphics.g3d.ModelBatch;
  13. import com.badlogic.gdx.graphics.g3d.ModelInstance;
  14. import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
  15. import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
  16. import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
  17.  
  18. public class Game implements ApplicationListener {
  19.  
  20. public PerspectiveCamera cam;
  21. public Model model;
  22. public ModelInstance instance;
  23. public ModelBatch modelBatch;
  24. public Environment environment;
  25. public InputMultiplexer input;
  26.  
  27. public static int gWidth = 800;
  28. public static int gHeight = 600;
  29.  
  30. @Override
  31. public void create() {
  32.  
  33. this.modelBatch = new ModelBatch();
  34.  
  35. this.environment = new Environment();
  36. this.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
  37. this.environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
  38.  
  39. /**
  40. * Add input adapters.
  41. */
  42. this.cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  43. this.cam.position.set(10f, 20f, 0);
  44. this.cam.lookAt(0, 0, 0);
  45. this.cam.rotate(67f, 0f, 0f, 0f);
  46. this.cam.near = 1f;
  47. this.cam.far = 300f;
  48.  
  49. this.input = new InputMultiplexer(Gdx.input.getInputProcessor());
  50. this.input.addProcessor(new MouseCamController());
  51. Gdx.input.setInputProcessor(this.input);
  52.  
  53. this.cam.update();
  54.  
  55. ModelBuilder modelBuilder = new ModelBuilder();
  56. model = modelBuilder.createBox(5f, 5f, 5f,
  57. new Material(ColorAttribute.createDiffuse(Color.GREEN)),
  58. Usage.Position | Usage.Normal);
  59. instance = new ModelInstance(model);
  60. }
  61.  
  62. @Override
  63. public void resize(int width, int height) {
  64. }
  65.  
  66. @Override
  67. public void render() {
  68. Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  69. Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  70.  
  71. // if (this.cam.fieldOfView < 120) {
  72. // this.cam.fieldOfView += 10;
  73. // }
  74. this.cam.update();
  75.  
  76. this.modelBatch.begin(this.cam);
  77. this.modelBatch.render(instance, environment);
  78. this.modelBatch.end();
  79.  
  80. }
  81.  
  82. @Override
  83. public void pause() {
  84. }
  85.  
  86. @Override
  87. public void resume() {
  88. }
  89.  
  90. @Override
  91. public void dispose() {
  92. this.modelBatch.dispose();
  93. this.model.dispose();
  94. }
  95.  
  96. public class MouseCamController extends InputAdapter {
  97. @Override
  98. public boolean scrolled(int amount) {
  99. // Gdx.app.log("INPUT", "A: " + amount);
  100. return true;
  101. }
  102. }
  103. }
  104.  
  105. Exception in thread "LWJGL Application" java.lang.NullPointerException
  106. at com.badlogic.gdx.InputMultiplexer.mouseMoved(InputMultiplexer.java:107)
  107. at com.badlogic.gdx.backends.lwjgl.LwjglInput.processEvents(LwjglInput.java:303)
  108. at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:200)
  109. at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement