Guest User

Untitled

a guest
Jan 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.04 KB | None | 0 0
  1. package mygame;
  2.  
  3. import com.jme3.app.SimpleApplication;
  4. import com.jme3.input.KeyInput;
  5. import com.jme3.input.controls.AnalogListener;
  6. import com.jme3.input.controls.KeyTrigger;
  7. import com.jme3.light.DirectionalLight;
  8. import com.jme3.math.ColorRGBA;
  9. import com.jme3.math.Vector3f;
  10. import com.jme3.scene.Spatial;
  11. import com.jme3.shadow.PssmShadowRenderer;
  12. import java.util.logging.Level;
  13.  
  14. /**
  15.  * Result
  16.  * @author +Gvrv
  17.  */
  18. public class Main extends SimpleApplication
  19. {
  20.     float angle;
  21.     Spatial circle1;
  22.     Spatial circle2;
  23.  
  24.     public static void main(String[] args)
  25.     {
  26.         java.util.logging.Logger.getLogger("").setLevel(Level.WARNING);
  27.         Main app = new Main();
  28.         app.start();
  29.     }
  30.  
  31.     @Override
  32.     public void simpleInitApp()
  33.     {
  34.         setDisplayFps(false);
  35.         setDisplayStatView(false);
  36.         setShowSettings(false);
  37.         //flyCam.setEnabled(false);
  38.         //cam.setLocation(Vector3f.ZERO);
  39.         viewPort.setBackgroundColor(ColorRGBA.Gray);
  40.  
  41.         DirectionalLight sun = new DirectionalLight();
  42.         sun.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
  43.         sun.setColor(ColorRGBA.Yellow);
  44.         rootNode.addLight(sun);
  45.        
  46.         PssmShadowRenderer shadowRenderer = new PssmShadowRenderer(assetManager, 512, 4);
  47.         shadowRenderer.setDirection(sun.getDirection());
  48.         viewPort.addProcessor(shadowRenderer);
  49.  
  50.         Spatial ground = assetManager.loadModel("Models/ground.j3o");
  51.         ground.move(0, -5f, 0);
  52.         rootNode.attachChild(ground);
  53.  
  54.         circle1 = assetManager.loadModel("Models/circle1.j3o");
  55.         circle1.move(0, -5f, 0);
  56.         rootNode.attachChild(circle1);
  57.  
  58.         circle2 = assetManager.loadModel("Models/circle2.j3o");
  59.         circle2.move(0, -5f, 0);
  60.         rootNode.attachChild(circle2);
  61.  
  62.         inputManager.addMapping("Z", new KeyTrigger(KeyInput.KEY_Z));
  63.         inputManager.addMapping("S", new KeyTrigger(KeyInput.KEY_S));
  64.         inputManager.addMapping("Q", new KeyTrigger(KeyInput.KEY_Q));
  65.         inputManager.addMapping("D", new KeyTrigger(KeyInput.KEY_D));
  66.         inputManager.addListener(analogListener, new String[]{"Z", "S", "Q", "D"});
  67.     }
  68.  
  69.     private AnalogListener analogListener = new AnalogListener()
  70.     {
  71.         public void onAnalog(String name, float value, float tpf)
  72.         {
  73.             Vector3f v = new Vector3f(cam.getLocation());
  74.             if (name.equals("Z"))
  75.             {
  76.                 v.z -= tpf;
  77.             }
  78.             if (name.equals("S"))
  79.             {
  80.                 v.z += tpf;
  81.             }
  82.             if (name.equals("Q"))
  83.             {
  84.                 v.x -= tpf;
  85.             }
  86.             if (name.equals("D"))
  87.             {
  88.                 v.x += tpf;
  89.             }
  90.             cam.setLocation(v);
  91.         }
  92.     };
  93.    
  94.     @Override
  95.     public void simpleUpdate(float tpf)
  96.     {
  97.         angle += 0.1f;
  98.         circle1.move(0, (float) (0.025f * Math.sin(angle)), 0);
  99.         circle2.move(0, (float) (0.025f * Math.cos(angle)), 0);
  100.     }
  101. }
Add Comment
Please, Sign In to add comment