Move object in "empty space"?

D'oh, I am stuck on a logical problem and need some help:

In my application I move an object while holding the right MouseButton (the object follows the mouse; it's like pulling an object in a scenegraph-editor). This works smooth. The bad thing however is: everything is dependent on the Terrain getting hit by a Ray.

Now if I want to translate objects without any Terrain the object doesn't move anymore - because there are no "intersectionpoints" anymore.

My first approach to achieve a translation on either x/y/z axis again was to create 3 giant planes on xy,xz,yz-Axes and catch the intersectionpoint on the appropriate plane. Though I think this solution would be too dirty and I somehow feel that this approach is "wrong".



This is my current code to handle the mouse-Action:


InputAction mouseAction2 = new InputAction(){
   public void performAction(InputActionEvent iae2){
                     
      if(iae2.getTriggerPressed()==true)   //for "MouseButton _pressed_"
      {
         // get Intersectionpoint with Terrain,
                                    // and setLocation of Object equal to Intersectionpoint
      }   
      else   //for "MouseButton _released_"
         //do nothing
   }
};
         
//set to "true" to allow repeating trigger
inputModes.addAction(mouseAction2,InputHandler.DEVICE_MOUSE,1,InputHandler.AXIS_NONE,true);



I already tried something like InputHandler.AXIS_ALL so that the Intersectionpoints are created while solely moving the mouse but then again - it was dependent on the TerrainIntersection. Now how can I achieve a movement in "empty space" without being dependent on the intersectionpoints?

Maybe you can do this with trigonometry?



I havent tried this so the following may have errors in it but I think the idea is sound:



      b

  _____

          |

          |

          |   a

          |

          |

c





a = mousePosition.y (+ thought plane's y position)



ac = angle between thought plane and camera. (Cameras x rotation + 90 degrees, if you are going to drag along xz)



b = distance from camera to object





Use a and ac to find out b.



If I have understood the javadocs correctly you can then do:



object.setLocalTranslation(cam.getWorldCoordinates(mousePosition), b);


hmm I'm not sure that I understood right but tried to implement it. I think I missed something:

InputAction mouseAction2 = new InputAction()
{
   public void performAction(InputActionEvent iae2)
            {
      if(iae2.getTriggerPressed()==true)   //for "MouseButton _pressed_"
      {
         camCoords = cam.getLocation();               
         float dist = camCoords.distance(spatial.getLocalTranslation));               
               
         // Get the position that the mouse is pointing to
         int mouse_x = MouseInput.get().getXAbsolute();
         int mouse_y = MouseInput.get().getYAbsolute();
                
         Vector2f mouse_xy = new Vector2f(mouse_x,mouse_y);
                
         // Get the world location of that X,Y value
         worldCoords = DisplaySystem.getDisplaySystem().getWorldCoordinates(mouse_xy,dist);
                
         System.out.println("t"+worldCoords);
                
                                    // slide along x-Axis
         spatial.setLocalTranslation(worldCoords.x,spatial.getLocalTranslation().y,spatial.getLocalTranslation().z);
                            
      }   
      else   //for "MouseButton _released_"
      {               
         //do nothing
      }
   }
};         
// "true", (allow triggerrepeat)
inputModes.addAction(mouseAction2,InputHandler.DEVICE_MOUSE,1,InputHandler.AXIS_NONE,true);



Sadly it doesn't work the way I hoped. I guess I am missing something in my understanding and therefore in the calculation.

Though I am also confused in this line: worldCoords = DisplaySystem.getDisplaySystem().getWorldCoordinates(mouse_xy,dist);
I am not sure that I am allowed to fill in here the distance because...

the API claims: public Vector3f getWorldCoordinates(Vector2f screenPosition,float zPos)
screenPosition - Vector2f representing the screen position with 0,0 at the bottom left.
zPos - The z position away from the viewing plane, between 0 and 1


on the other Hand HelloMousePick.java-Tutorial says: "The 3rd float I pass in, 0, is the distance away from the screen’s position that this 3D position will take. 0 would be the screen position right in front of you. 10 would be the screen position 10 units away from you."

So if I use a value between 0 and 1 in my example the spatial *slides* on the x-Axis when holding the right MouseButton (however not the way I wanted it because when moving the mouse slightly left or right from the centerposition of the screen the spatial slides away very fast at 1 and very slow at 0). If I use a value greater than 1 however (e.g. the distance value) my Spatial makes only 1 single move.
Also when I check the worldCoords of the Mouse (when using the distance value as zPos, I expected the mouse Position somewhere in 3d space with a distance of "dist" units away from the camera position) - but when I print the worldCoords they are the same as the camCoords! How come that? What is the zPos now? And where are the worldCoords of the MousePosition really?
:?

(If I only knew how MW3D did spatial translations, but can't find the file which handles the translation calculations :'()





I found this in the forum:



http://www.jmonkeyengine.com/jmeforum/index.php?topic=7517.msg60271#msg60271