Drag objects an move them

Hi,



I would like to move an object which I pick up with my crosshair. For this I sum up the location vector and the direction vector of the camera. I can pick it up and move it but the problem is that when I click on it it jumps to the location of my cam. Is there a solution for my problem? I want to move it with a predefined distance to my cam.



I tried this to change the position of the object:

Vector3f camPos = cam.getLocation();
Vector3f camDir = cam.getDirection();
Vector3f newPos = new Vector3f();
newPos.setX(camPos.getX() + camDir.getX());
newPos.setY(camPos.getY() + camDir.getY());
newPos.setZ(camPos.getZ() + camDir.getZ());
System.out.println(newPosTestBox.getLocalTranslation().set(newPos);

The camera direction is a normalized vector (i.e. size 1), the only thing you need to do is scale it to whatever you need:



float sz = 100.0f;
Vector3f camPos = cam.getLocation();
Vector3f camDir = cam.getDirection();
Vector3f newPos = new Vector3f();
newPos.setX(camPos.getX() + sz * camDir.getX());
newPos.setY(camPos.getY() + sz * camDir.getY());
newPos.setZ(camPos.getZ() + sz * camDir.getZ());
System.out.println(newPosTestBox.getLocalTranslation().set(newPos);

Thanks a lot. In the last night this were my thoughts too  :D. Now I tried it and it works.