Guest User

Untitled

a guest
May 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 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.material.Material;
  8. import com.jme3.math.ColorRGBA;
  9. import com.jme3.math.Vector3f;
  10. import com.jme3.renderer.RenderManager;
  11. import com.jme3.scene.Geometry;
  12. import com.jme3.scene.shape.Box;
  13.  
  14. /**
  15. * test
  16. * @author normenhansen
  17. */
  18. public class Main extends SimpleApplication {
  19.  
  20. Box b;
  21. Geometry geom;
  22. Material mat;
  23. float R = 0f, G = 0f, B = 0f;
  24.  
  25. public static void main(String[] args) {
  26. Main app = new Main();
  27. app.start();
  28. }
  29.  
  30. @Override
  31. public void simpleInitApp() {
  32. b = new Box(Vector3f.ZERO, 1, 1, 1);
  33. geom = new Geometry("Box", b);
  34.  
  35. mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  36. mat.setColor("Color", ColorRGBA.Blue);
  37. geom.setMaterial(mat);
  38. rootNode.attachChild(geom);
  39. initKeys();
  40. }
  41.  
  42. public void initKeys() {
  43. inputManager.addMapping("R", new KeyTrigger(KeyInput.KEY_R));
  44. inputManager.addMapping("G", new KeyTrigger(KeyInput.KEY_G));
  45. inputManager.addMapping("B", new KeyTrigger(KeyInput.KEY_B));
  46. inputManager.addListener(analogListener, new String[]{"R", "G", "B"});
  47. }
  48. private AnalogListener analogListener = new AnalogListener() {
  49.  
  50. public void onAnalog(String name, float value, float tpf) {
  51. if (name.equals("R")) {
  52. System.out.println("R");
  53. R = R+0.0001f;
  54. mat.setColor("Color", new ColorRGBA(R, G, B, 1f));
  55. } else if (name.equals("G")) {
  56. G = G+0.0001f;
  57. System.out.println("G");
  58. mat.setColor("Color", new ColorRGBA(R, G, B, 1f));
  59. } else if (name.equals("B")) {
  60. B = B+0.0001f;
  61. mat.setColor("Color", new ColorRGBA(R, G, B, 1f));
  62. }
  63. }
  64. };
  65.  
  66. @Override
  67. public void simpleUpdate(float tpf) {
  68. //TODO: add update code
  69. //if()
  70. }
  71.  
  72. @Override
  73. public void simpleRender(RenderManager rm) {
  74. //TODO: add render code
  75. }
  76. }
Add Comment
Please, Sign In to add comment