Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mygame;
- import com.jme3.app.SimpleApplication;
- import com.jme3.input.KeyInput;
- import com.jme3.input.controls.AnalogListener;
- import com.jme3.input.controls.KeyTrigger;
- import com.jme3.material.Material;
- import com.jme3.math.ColorRGBA;
- import com.jme3.math.Vector3f;
- import com.jme3.renderer.RenderManager;
- import com.jme3.scene.Geometry;
- import com.jme3.scene.shape.Box;
- /**
- * test
- * @author normenhansen
- */
- public class Main extends SimpleApplication {
- Box b;
- Geometry geom;
- Material mat;
- float R = 0f, G = 0f, B = 0f;
- public static void main(String[] args) {
- Main app = new Main();
- app.start();
- }
- @Override
- public void simpleInitApp() {
- b = new Box(Vector3f.ZERO, 1, 1, 1);
- geom = new Geometry("Box", b);
- mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
- mat.setColor("Color", ColorRGBA.Blue);
- geom.setMaterial(mat);
- rootNode.attachChild(geom);
- initKeys();
- }
- public void initKeys() {
- inputManager.addMapping("R", new KeyTrigger(KeyInput.KEY_R));
- inputManager.addMapping("G", new KeyTrigger(KeyInput.KEY_G));
- inputManager.addMapping("B", new KeyTrigger(KeyInput.KEY_B));
- inputManager.addListener(analogListener, new String[]{"R", "G", "B"});
- }
- private AnalogListener analogListener = new AnalogListener() {
- public void onAnalog(String name, float value, float tpf) {
- if (name.equals("R")) {
- System.out.println("R");
- R = R+0.0001f;
- mat.setColor("Color", new ColorRGBA(R, G, B, 1f));
- } else if (name.equals("G")) {
- G = G+0.0001f;
- System.out.println("G");
- mat.setColor("Color", new ColorRGBA(R, G, B, 1f));
- } else if (name.equals("B")) {
- B = B+0.0001f;
- mat.setColor("Color", new ColorRGBA(R, G, B, 1f));
- }
- }
- };
- @Override
- public void simpleUpdate(float tpf) {
- //TODO: add update code
- //if()
- }
- @Override
- public void simpleRender(RenderManager rm) {
- //TODO: add render code
- }
- }
Add Comment
Please, Sign In to add comment