Advertisement
kecsot

Untitled

Jul 5th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. package com.mygdx.game;
  2.  
  3. import com.badlogic.gdx.ApplicationAdapter;
  4. import com.badlogic.gdx.Gdx;
  5. import com.badlogic.gdx.Input;
  6. import com.badlogic.gdx.assets.AssetManager;
  7. import com.badlogic.gdx.assets.loaders.ModelLoader;
  8. import com.badlogic.gdx.graphics.GL20;
  9. import com.badlogic.gdx.graphics.PerspectiveCamera;
  10. import com.badlogic.gdx.graphics.Pixmap;
  11. import com.badlogic.gdx.graphics.Texture;
  12. import com.badlogic.gdx.graphics.VertexAttributes;
  13. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  14. import com.badlogic.gdx.graphics.g3d.Environment;
  15. import com.badlogic.gdx.graphics.g3d.Material;
  16. import com.badlogic.gdx.graphics.g3d.Model;
  17. import com.badlogic.gdx.graphics.g3d.ModelBatch;
  18. import com.badlogic.gdx.graphics.g3d.ModelInstance;
  19. import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
  20. import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
  21. import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
  22. import com.badlogic.gdx.graphics.g3d.loader.ObjLoader;
  23. import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
  24. import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
  25. import com.badlogic.gdx.math.Vector3;
  26. import com.badlogic.gdx.math.collision.Sphere;
  27. import com.badlogic.gdx.utils.Array;
  28.  
  29.  
  30. import java.io.File;
  31.  
  32. import sun.rmi.runtime.Log;
  33.  
  34. public class MyGdxGame extends ApplicationAdapter {
  35.  
  36. public PerspectiveCamera cam;
  37. public CameraInputController camController;
  38. public ModelBatch modelBatch;
  39. public AssetManager assets;
  40. public Array<ModelInstance> instances = new Array<ModelInstance>();
  41. public Environment environment;
  42. public boolean loading;
  43. public ModelInstance maleBodyInstance;
  44. public Model maleBodyModel;
  45. public Model pantModel;
  46. public Material material;
  47. public TextureAttribute textureAttribute1;
  48.  
  49. public Texture blueTexture;
  50. public Texture greenTexture;
  51. public Texture redTexture;
  52. long startTime = System.nanoTime();
  53. int frames = 0;
  54. public boolean lol = true;
  55.  
  56. @Override
  57. public void create() {
  58. modelBatch = new ModelBatch();
  59. environment = new Environment();
  60. environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
  61. environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
  62.  
  63. cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  64. cam.position.set(7f, 7f, 7f);
  65. cam.lookAt(0,0,0);
  66. cam.near = 0.1f;
  67. cam.far = 300f;
  68. cam.update();
  69.  
  70. camController = new CameraInputController(cam);
  71. Gdx.input.setInputProcessor(camController);
  72.  
  73.  
  74. greenTexture = new Texture(Gdx.files.internal("twok.jpg"));
  75. redTexture = new Texture(Gdx.files.internal("twok_empty.png"));
  76.  
  77. assets = new AssetManager();
  78. assets.load("lol2.obj", Model.class);
  79. loading = true;
  80.  
  81. }
  82.  
  83. private void doneLoading() {
  84. if(maleBodyModel == null)
  85. {
  86. maleBodyModel = assets.get("lol2.obj", Model.class);
  87. maleBodyInstance = new ModelInstance(maleBodyModel);
  88. maleBodyInstance.transform.setToTranslation(1, 0, 1);
  89. maleBodyInstance.transform.setToRotation(0, 1, 0, 45);
  90. }
  91.  
  92.  
  93. if(lol)
  94. {
  95. textureAttribute1 = new TextureAttribute(TextureAttribute.Diffuse, greenTexture);
  96. lol = false;
  97.  
  98. }else
  99. {
  100. textureAttribute1 = new TextureAttribute(TextureAttribute.Diffuse, redTexture);
  101. lol = true;
  102. }
  103. material = maleBodyInstance.materials.get(0);
  104. material.set(textureAttribute1);
  105.  
  106. instances.clear();
  107. instances.add(maleBodyInstance);
  108.  
  109.  
  110. //loading = false;
  111. }
  112.  
  113. @Override
  114. public void render () {
  115. if (assets.update())
  116. doneLoading();
  117.  
  118.  
  119.  
  120. camController.update();
  121. Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  122. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
  123.  
  124. modelBatch.begin(cam);
  125. modelBatch.render(instances, environment);
  126. modelBatch.end();
  127.  
  128. }
  129.  
  130. @Override
  131. public void dispose () {
  132. modelBatch.dispose();
  133. instances.clear();
  134. assets.dispose();
  135. }
  136.  
  137. @Override
  138. public void resize(int width, int height) {
  139. }
  140.  
  141. @Override
  142. public void pause() {
  143. }
  144.  
  145. @Override
  146. public void resume() {
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement