Moving an object with getPickRay [solved] [Source Included***]

hello.



today i have sort of an interesting problem. Seen from the picture below, I am trying to get a box to move to world coordinates derived from mouse coordinates on the screen. basically, where ever the mouse is, i want the box to be. The camera is top down.



what happens is, I can move the box around, but only inside the pink lines drawn below. outside of the actual screen bounds of the camera, the box will not go. the reason this is not working is because it is getting the world coordinates of the camera's screen. I am confused how to get the actual representation of these coordinates on the "ground". the green thing is the camera, which is 200 units above the ground, and the blue lines are the view which the camera can actually see.



here is the code with which i am doing this




   Vector3f target;
   Ray mouseRay = null;
   Vector2f mousePos = new Vector2f();

      mousePos.x = MouseInput.get().getXAbsolute();
      mousePos.y = MouseInput.get().getYAbsolute();
      System.out.println(mousePos);
      mouseRay = DisplaySystem.getDisplaySystem().getPickRay(mousePos, false, mouseRay);
      target = mouseRay.getOrigin();
      target.y = 0f;

      System.out.println("player2:" + player2.getLocalTranslation() + " Ray:" + target);
      player2.setLocalTranslation(target);
        player2.updateGeometricState(tpf, true);



thanks. sorry if this is kind of weird! haha.
my end goal is to have an object moved by the camera, which the players character will always be facing, and this was the easiest way i saw to do this.

well, heres my code:

statemanager

package MouseWork;



import com.jmex.game.StandardGame;
import com.jmex.game.state.GameStateManager;

public class statemanager{

   public static StandardGame manager;

   public static ingame ingamestate;

      
   public statemanager(){
      // initiate the main game, which is running off standard game
      manager = new StandardGame("JMonkey Game ");
      manager.getSettings().setSFX(false);
      manager.getSettings().setMusic(false);
      manager.getSettings().setWidth(800);
      manager.getSettings().setHeight(600);
      manager.getSettings().setFullscreen(false);
      manager.getSettings().setStencilBits(4);
      manager.start();
      
      // initiate the different states
      ingamestate = new ingame("Main Menu");      
      // Activate the game state   
      ingamestate.setActive(true);
      // Add it to the manager   
      GameStateManager.getInstance().attachChild(ingamestate);
   }

   public static void main(String[] args) throws Exception {
      new statemanager();
   }

}



game

package MouseWork;


import java.util.ArrayList;
import java.util.concurrent.Callable;

import com.jme.bounding.BoundingBox;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.input.action.InputAction;
import com.jme.input.action.InputActionEvent;
import com.jme.light.DirectionalLight;
import com.jme.math.Plane;
import com.jme.math.Ray;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.CameraNode;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueueManager;
import com.jme.util.Timer;
import com.jmex.bui.BButton;
import com.jmex.bui.BComponent;
import com.jmex.bui.BContainer;
import com.jmex.bui.BDecoratedWindow;
import com.jmex.bui.BWindow;
import com.jmex.bui.BuiSystem;
import com.jmex.bui.PolledRootNode;
import com.jmex.bui.event.ActionEvent;
import com.jmex.bui.event.ActionListener;
import com.jmex.bui.layout.GroupLayout;
import com.jmex.bui.layout.TableLayout;
import com.jmex.game.state.BasicGameStateNode;
import com.jmex.game.state.GameStateManager;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.PhysicsSpace;
import com.jmex.physics.StaticPhysicsNode;
import java.lang.reflect.Field;

public class ingame extends BasicGameStateNode{
   
   public CameraNode camNode;
   public PhysicsSpace pSpace = PhysicsSpace.create();
   public DynamicPhysicsNode player;
   public Node player2;
   public Node scene;
   public Node camHolder;
    protected float tpf;
   public Vector3f camLoc;
   public InputHandler input = new InputHandler();
   Node rootNode = super.rootNode;
   
   //extras
   Vector3f target;
   float zoomValue = 3;
   Ray mouseRay = null;
   Vector2f mousePos = new Vector2f();
   
   public ingame(String name){
      super(name);
      initSystem();
      initGame();
      
   }
   
   public void update(float tpf) {
      super.update(tpf);
      pSpace.update(tpf);
      if (KeyBindingManager.getKeyBindingManager().isValidCommand("Exit"))
      {
          System.exit(0);
      }
        input.update(tpf);

        camHolder.setLocalTranslation(player.getLocalTranslation());


        camLoc = player.getLocalTranslation();
        if(camLoc.y <= 0){
           player.setLocalTranslation(0,6,1);
           player.clearDynamics();
        }
      mousePos.x = MouseInput.get().getXAbsolute();
      mousePos.y = MouseInput.get().getYAbsolute();
      System.out.println(mousePos);
      mouseRay = DisplaySystem.getDisplaySystem().getPickRay(mousePos, false, mouseRay);
      target = mouseRay.getOrigin();
      target.y = 0f;
      System.out.println("player2:" + player2.getLocalTranslation() + " Ray:" + target);
      player2.setLocalTranslation(target);
        player2.updateGeometricState(tpf, true);
   }
   

   public void render(float tpf) {
      super.render(tpf);
   }
   
   public void initSystem(){
      buildInput();

   }
   
   public void initGame(){
      buildZone();
      buildPlayers();
      buildCamera();
      




      
      
        color( player, new ColorRGBA( 0, 1, 0, 1 ) );
        color( player2, new ColorRGBA( 0, 0, 1, 1 ) );
      
      rootNode.updateGeometricState(0.0f, true);
      rootNode.updateRenderState();
      
   }
   
   
   
   public void buildInput(){
      // show mouse cursor
      MouseInput.get().setCursorVisible(true);
      KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
      //controls for player -- physics
       input.addAction( new up(),
                InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_W, InputHandler.AXIS_NONE, true );
       input.addAction( new left(),
                InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_A, InputHandler.AXIS_NONE, true );
       input.addAction( new down(),
                InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_S, InputHandler.AXIS_NONE, true );
       input.addAction( new right(),
                InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_D, InputHandler.AXIS_NONE, true );

   }
   

   
   public void buildZone(){
      scene = new Node("scene");
      StaticPhysicsNode staticNode = pSpace.createStaticNode();
        scene.attachChild( staticNode );
        final Box visualFloorBox = new Box( "floor", new Vector3f(0,0,0), 100, 1 ,100);
        staticNode.attachChild( visualFloorBox );
        staticNode.generatePhysicsGeometry();      
        scene.setLocalTranslation(0,0,1);
        scene.updateGeometricState(tpf, true);
       rootNode.attachChild(scene);
         /** Set up a basic, default light. */
          DirectionalLight light = new DirectionalLight();
        light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
          light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
          light.setDirection(new Vector3f(1,-1,0));
          light.setEnabled(true);
    
            /** Attach the light to a lightState and the lightState to rootNode. */
          LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
          lightState.setEnabled(true);
          lightState.attach(light);
          rootNode.setRenderState(lightState);
      
   }
   
   public void buildPlayers(){
      //build physics sphere
        player = pSpace.createDynamicNode();
        final Sphere visualFallingBox = new Sphere("Sphere", 20, 20, 5);
        player.attachChild( visualFallingBox );
        player.generatePhysicsGeometry();
        player.setLocalTranslation( 50, 10, 1 );
       player.setModelBound(new BoundingBox());
       player.updateModelBound();
        player.updateGeometricState(tpf, true);
      System.out.println("changing sphere location");
      rootNode.attachChild(player);
        
      //build player box
      player2 = new Node("scene");
        Box s = new Box( "floor", new Vector3f(0,0,0), 5, 5 ,5);
       s.setLocalTranslation(new Vector3f(0,0,0));
       s.setModelBound(new BoundingBox());
       s.updateModelBound();
          player2.attachChild(s);
        player2.setLocalTranslation(0,5,1);
        player2.updateGeometricState(tpf, true);
      rootNode.attachChild(player2);
      
   }
   
   public void buildCamera(){
      // attach the CameraNode to the player node
      camHolder = new Node("camera holder");
      camNode = new CameraNode("cam node", statemanager.manager.getCamera());
      camNode.setCamera(statemanager.manager.getCamera());
      // moves the camera x,y,z coordinates currently 0,220,1 *edited need fix
      camNode.setLocalTranslation(0,200,1);
      camHolder.attachChild(camNode);
      camNode.lookAt(camHolder.getLocalTranslation(), scene.getLocalTranslation());
      rootNode.attachChild(camHolder);
   }
   

   
    public class left extends InputAction {
        public void performAction( InputActionEvent evt ) {  
            player.addForce(new Vector3f( 2, 0, 0 ));
        }
    }
    public class right extends InputAction {
        public void performAction( InputActionEvent evt ) {        
            player.addForce(new Vector3f( -2, 0, 0 ));
        }
    }
    public class down extends InputAction {
        public void performAction( InputActionEvent evt ) {        
            player.addForce(new Vector3f( 0, 0, -2 ));
        }
    }
    public class up extends InputAction {
        public void performAction( InputActionEvent evt ) {        
            player.addForce(new Vector3f( 0, 0, 2 ));
        }
    }
   

    void color( Spatial spatial, ColorRGBA color ) {
        final MaterialState materialState = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
        materialState.setDiffuse( color );
        if ( color.a < 1 ) {
            final BlendState blendState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
            blendState.setEnabled( true );
            blendState.setBlendEnabled( true );
            blendState.setSourceFunction( BlendState.SourceFunction.SourceAlpha );
            blendState.setDestinationFunction( BlendState.DestinationFunction.OneMinusSourceAlpha );
            spatial.setRenderState( blendState );
            spatial.setRenderQueueMode( Renderer.QUEUE_TRANSPARENT );
        }
        spatial.setRenderState( materialState );
    }
    


}

You might have had it already in the mousePick result from display.getPickRay().



Instead of that method, I got the following general thing from the forum under the subject of terrain picking and it works great for me. Where the ray intersects your ground is the point that your mouse is pointing on he ground.



Ray pickRay = new Ray();
DisplaySystem display = DisplaySystem.getDisplaySystem();
display.getWorldCoordinates(mousePos, 0, pickRay.getOrigin());
display.getWorldCoordinates(mousePos, 1, pickRay.getDirection());
pickRay.getDirection().subtractLocal(pickRay.getOrigin()).normalizeLocal();



ok so I think I have been attacking this wrong, but I am still confused.



Basically, what I need to do is to cast a ray from my mouse and find where it collides with my scene node. However, the only pick tests that I have come across use the camera to get origin and direction. I know how to get the origin location of my mouse, but I do not understand how to get the direction my mouse is pointing in. How would I go about doing this so that I  can cast a ray from my mouse location?



Once I can cast this ray correctly, it should be pretty easy to get the intersection location.

Hello. Thank you very very much for the reply.



Right now, It sort of works depending on the Node I set to work with.

If I set it to work with a regular box node then it picks the position just fine.



Physics Nodes and the rootNode are throwing

Nov 1, 2009 12:45:48 AM com.jmex.game.DefaultUncaughtExceptionHandler uncaughtException
SEVERE: Main game loop broken by uncaught exception
java.lang.AbstractMethodError
   at com.jme.scene.Node.findPick(Node.java:630)
   at MouseWork.ingame.update(ingame.java:122)
   at com.jmex.game.state.GameStateNode.update(GameStateNode.java:71)
   at com.jmex.game.StandardGame.update(StandardGame.java:381)
   at com.jmex.game.StandardGame.run(StandardGame.java:250)
   at java.lang.Thread.run(Thread.java:619)

If i call findpick() on them. Is there something special I need to do to work with picking physicsnodes?

Also... one thing which would be really awesome is if you could explain how exactly the code you showed me works. I am very interested, most specifically with this line

pickRay.getDirection().subtractLocal(pickRay.getOrigin()).normalizeLocal();


what does that line do?
and what does NormalizeLocal() to that do?
Thanks!!! :)

All that line does is turn the two points into a ray. The ray's origin is the first mouse point (x, y, 0) in world coords. The ray's direction is the second mouse point (x, y, 1) in world coord minus the first point. The normalize adjusts the ray length to 1.



The code in display.getPickRay seems to have exactly the same thing. I thought it gave me funny results before but I should switch back.



I don't know anything about physics nodes, sorry.

well, big thanks to JavaMcgee for helping me out with this one.



I am going to lay down the source code here, its plug and play so I hope someone finds it useful!

The primary use of this code is that it has a top down camera casting a ray to the ground from the mouse which moves a ball to the location, and then the 'player' follows the ball. So the player is looking at where the mouse is!! :slight_smile:



statemanager

package MouseWork;



import com.jmex.game.StandardGame;
import com.jmex.game.state.GameStateManager;

public class statemanager{

   public static StandardGame manager;

   public static ingame ingamestate;

      
   public statemanager(){
      // initiate the main game, which is running off standard game
      manager = new StandardGame("JMonkey Game ");
      manager.getSettings().setSFX(false);
      manager.getSettings().setMusic(false);
      manager.getSettings().setWidth(800);
      manager.getSettings().setHeight(600);
      manager.getSettings().setFullscreen(false);
      manager.getSettings().setStencilBits(4);
      manager.start();
      
      // initiate the different states
      ingamestate = new ingame("Main Menu");      
      // Activate the game state   
      ingamestate.setActive(true);
      // Add it to the manager   
      GameStateManager.getInstance().attachChild(ingamestate);
   }

   public static void main(String[] args) throws Exception {
      new statemanager();
   }

}



ingamestate

package MouseWork;


import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.input.action.InputAction;
import com.jme.input.action.InputActionEvent;
import com.jme.intersection.TrianglePickResults;
import com.jme.light.DirectionalLight;
import com.jme.math.Ray;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.CameraNode;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.TriMesh;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;
import com.jmex.game.state.BasicGameStateNode;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.PhysicsSpace;
import com.jmex.physics.StaticPhysicsNode;

public class ingame extends BasicGameStateNode{
   
   public CameraNode camNode;
   public PhysicsSpace pSpace = PhysicsSpace.create();
   public DynamicPhysicsNode movementSphere;
   public Node mouseFollowMesh;
   public Node player2;
   public Node scene;
   public Node groundMesh;
   public Node camHolder;
    protected float tpf;
   public Vector3f camLoc;
   public InputHandler input = new InputHandler();
   Node rootNode = super.rootNode;
   
   boolean left;
   boolean right;
   boolean up;
   boolean down;
   
   //extras
   Vector2f mousePos = new Vector2f();
   
   public ingame(String name){
      super(name);
      initSystem();
      initGame();
      
   }
   
   public void update(float tpf) {
      super.update(tpf);
      pSpace.update(tpf);
      if (KeyBindingManager.getKeyBindingManager().isValidCommand("Exit"))
      {
          System.exit(0);
      }
        input.update(tpf);

        camHolder.setLocalTranslation(player2.getLocalTranslation());

        player2.setLocalTranslation(movementSphere.getLocalTranslation());
        camLoc = mouseFollowMesh.getLocalTranslation();
        if(movementSphere.getLocalTranslation().y <= 0){
           movementSphere.clearDynamics();
           movementSphere.setLocalTranslation(0,6,1);
        }

      mousePos.x = MouseInput.get().getXAbsolute();
      mousePos.y = MouseInput.get().getYAbsolute();



       
        // Get the mouse input device from the jME mouse
        // Is button 0 down? Button 0 is left click

           Ray pickRay = new Ray();
           DisplaySystem display = DisplaySystem.getDisplaySystem();
           display.getWorldCoordinates(mousePos, 0, pickRay.getOrigin());
           display.getWorldCoordinates(mousePos, 1, pickRay.getDirection());
           pickRay.getDirection().subtractLocal(pickRay.getOrigin()).normalizeLocal();

            // Does the mouse's ray intersect the box's world bounds?
          TrianglePickResults pr =  new TrianglePickResults();
            pr.clear();
            groundMesh.findPick(pickRay, pr);
           
           Vector3f loc = new Vector3f();
           Vector3f[] vertex = new Vector3f[3];
           boolean foundMeshHit = false;
           if(pr.getNumber() > 0) {
             TriMesh mesh = (TriMesh) pr.getPickData(0).getTargetMesh();
             
             for(int j=0; j<mesh.getTriangleCount(); j++) {
                 mesh.getTriangle(j, vertex);
                 foundMeshHit = (pickRay.intersectWhere(
                    vertex[0].addLocal(mesh.getWorldTranslation()),
                    vertex[1].addLocal(mesh.getWorldTranslation()),
                    vertex[2].addLocal(mesh.getWorldTranslation()), loc));            
                 if(foundMeshHit) {
                    //translate your object to loc                  
                      //System.out.println( "Loc: " + loc);
                      loc.y = .1f;
                    mouseFollowMesh.setLocalTranslation(loc);
                      mouseFollowMesh.updateGeometricState(tpf, true);
                      player2.lookAt(mouseFollowMesh.getLocalTranslation(), new Vector3f(0,1,0) );
                 }
                    
                
             
             }
           }

          
   }
   

   



   public void render(float tpf) {
      super.render(tpf);
   }
   
   public void initSystem(){
      buildInput();

   }
   
   public void initGame(){
      buildZone();
      buildPlayers();
      buildCamera();
      




      
      
        color( mouseFollowMesh, new ColorRGBA( 0, 1, 0, 1 ) );
        color( player2, new ColorRGBA( 0, 0, 1, 1 ) );
      
      rootNode.updateGeometricState(0.0f, true);
      rootNode.updateRenderState();
      
   }
   
   
   
   public void buildInput(){
      // show mouse cursor
      MouseInput.get().setCursorVisible(true);
      KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
      //controls for player -- physics
       input.addAction( new up(),
                InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_W, InputHandler.AXIS_NONE, true );
       input.addAction( new left(),
                InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_A, InputHandler.AXIS_NONE, true );
       input.addAction( new down(),
                InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_S, InputHandler.AXIS_NONE, true );
       input.addAction( new right(),
                InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_D, InputHandler.AXIS_NONE, true );

   }
   

   
   public void buildZone(){
      scene = new Node("scene");
      groundMesh = new Node("groundscene");
      StaticPhysicsNode staticNode = pSpace.createStaticNode();
        scene.attachChild( staticNode );
        Box visualFloorBox = new Box( "floor", new Vector3f(0,0,0), 100, 1 ,100);
        groundMesh.attachChild(visualFloorBox);
        staticNode.attachChild( groundMesh );
       staticNode.setModelBound(new BoundingBox());
       staticNode.updateModelBound();
        staticNode.generatePhysicsGeometry();      
        scene.setLocalTranslation(0,0,1);
       scene.setModelBound(new BoundingBox());
       scene.updateModelBound();
        scene.updateGeometricState(tpf, true);    
       rootNode.attachChild(scene);
         /** Set up a basic, default light. */
          DirectionalLight light = new DirectionalLight();
        light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
          light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
          light.setDirection(new Vector3f(1,-1,0));
          light.setEnabled(true);
    
            /** Attach the light to a lightState and the lightState to rootNode. */
          LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
          lightState.setEnabled(true);
          lightState.attach(light);
          rootNode.setRenderState(lightState);
      
   }
   
   public void buildPlayers(){

        final Sphere vs = new Sphere("Sphere", 20, 20, 2);
       vs.setModelBound(new BoundingSphere());
       vs.updateModelBound();
      mouseFollowMesh = new Node("scesne");
        mouseFollowMesh.attachChild( vs );
       mouseFollowMesh.setModelBound(new BoundingSphere());
       mouseFollowMesh.updateModelBound();
        mouseFollowMesh.setLocalTranslation( 50, 10, 1 );
        mouseFollowMesh.updateGeometricState(tpf, true);
      System.out.println("Building Mouse Follower Sphere");
      rootNode.attachChild(mouseFollowMesh);
       
      //build player box
      player2 = new Node("Player 2");
        Box s = new Box( "floor", new Vector3f(0,0,0), 5, 5 ,5);
        Sphere ball = new Sphere("Sphere", 20, 20, 2);
       ball.setModelBound(new BoundingBox());
       ball.updateModelBound();
       player2.attachChild(ball);
       ball.setLocalTranslation(new Vector3f(0,0,5));
       s.setLocalTranslation(new Vector3f(0,0,0));
       s.setModelBound(new BoundingBox());
       s.updateModelBound();
          player2.attachChild(s);
        player2.setLocalTranslation(0,0,1);
        player2.updateGeometricState(tpf, true);
      rootNode.attachChild(player2);
      
      movementSphere = pSpace.createDynamicNode();
        Sphere bv = new Sphere("Sphere", 20, 20, 5);
        movementSphere.attachChild( bv );
        movementSphere.generatePhysicsGeometry();
        movementSphere.setLocalTranslation( 0, 6, 1 );
        movementSphere.updateGeometricState(tpf, true);
      System.out.println("Adding sphere for player movement");
      rootNode.attachChild(movementSphere);
   }
   
   public void buildCamera(){
      // attach the CameraNode to the player node
      camHolder = new Node("camera holder");
      camNode = new CameraNode("cam node", statemanager.manager.getCamera());
      camNode.setCamera(statemanager.manager.getCamera());
      // moves the camera x,y,z coordinates currently 0,220,1 *edited need fix
      camNode.setLocalTranslation(0,200,1);
      camHolder.attachChild(camNode);
      camNode.lookAt(camHolder.getLocalTranslation(), scene.getLocalTranslation());
      rootNode.attachChild(camHolder);
   }
   

   
    public class left extends InputAction {
        public void performAction( InputActionEvent evt ) { 
           if(left == true){
            movementSphere.addForce(new Vector3f( 12, 0, 0 ));
           }else{
              left = true;
              right = false;
              movementSphere.clearDynamics();
           }
        }
    }
    public class right extends InputAction {
        public void performAction( InputActionEvent evt ) {
           if(right == true){
            movementSphere.addForce(new Vector3f( -12, 0, 0 ));
           }else{
              right = true;
              left = false;
              movementSphere.clearDynamics();
           }
        }
    }
    public class down extends InputAction {
        public void performAction( InputActionEvent evt ) {       
           if(down == true){
                movementSphere.addForce(new Vector3f( 0, 0, -12 ));
               }else{
                  down = true;
                  up = false;
                  movementSphere.clearDynamics();
               }
            }
        }
   
    public class up extends InputAction {
        public void performAction( InputActionEvent evt ) {       
           if(up == true){
                movementSphere.addForce(new Vector3f( 0, 0, 12 ));
               }else{
                  up = true;
                  down = false;
                  movementSphere.clearDynamics();
               }
        }
    }
   

    void color( Spatial spatial, ColorRGBA color ) {
        final MaterialState materialState = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
        materialState.setDiffuse( color );
        if ( color.a < 1 ) {
            final BlendState blendState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
            blendState.setEnabled( true );
            blendState.setBlendEnabled( true );
            blendState.setSourceFunction( BlendState.SourceFunction.SourceAlpha );
            blendState.setDestinationFunction( BlendState.DestinationFunction.OneMinusSourceAlpha );
            spatial.setRenderState( blendState );
            spatial.setRenderQueueMode( Renderer.QUEUE_TRANSPARENT );
        }
        spatial.setRenderState( materialState );
    }
   


}