public static Vector3f getDragVectorWorld (int eventX, int eventY, Vector3f dragStartWorld,
Point dragStartScreen, Vector3f ret) {
logger.fine("dragStartWorld rel = " + dragStartWorld);
if (ret == null) {
ret = new Vector3f();
}
// The current world position of the eye
Vector3f eyeWorld = InputPicker3D.getInputPicker().getCameraPosition(null);
logger.fine("eyeWorld = " + eyeWorld);
// The float movement vector in screen space
Vector2f scrPos = new Vector2f((float)(eventX - dragStartScreen.x),
(float)(eventY - dragStartScreen.y));
logger.fine("scrPos = " + scrPos);
Vector2f pressXY = new Vector2f((float)dragStartScreen.x, (float)dragStartScreen.y);
Vector3f pressWorld = ((InputManager3D)InputManager3D.getInputManager()).
getCamera().getWorldCoordinates(pressXY, 0f);
Vector2f dragXY = new Vector2f((float)eventX, (float)eventY);
Vector3f dragWorld = ((InputManager3D)InputManager3D.getInputManager()).
getCamera().getWorldCoordinates(dragXY, 0f);
// The world position of this event (in the view plane)
Vector3f thisWorld = ((InputManager3D)InputManager3D.getInputManager()).
getCamera().getWorldCoordinates(scrPos, 0f);
logger.fine("thisWorld = " + thisWorld);
// The calculations need to take place in eye space. Get the necessary matrices.
Matrix4f camMatrix = InputPicker3D.getInputPicker().getCameraModelViewMatrix(null);
Matrix4f camInverse = InputPicker3D.getInputPicker().getCameraModelViewMatrixInverse(null);
logger.finest("camInverse = " + camInverse);
// Transform vectors from world space into eye space
Vector3f dragEye = new Vector3f();
Vector3f dragStartEye = new Vector3f();
Vector3f pressEye = new Vector3f();
Vector3f eyeEye = new Vector3f();
Vector3f thisEye = new Vector3f();
camInverse.mult(dragWorld, dragEye);
camInverse.mult(dragStartWorld, dragStartEye);
camInverse.mult(pressWorld, pressEye);
// TODO: perf: only really need to recalc eyeEye on camera change
camInverse.mult(eyeWorld, eyeEye);
camInverse.mult(thisWorld, thisEye);
// The displacement vector of this event from the center of the drag plane
Vector3f dragVectorEye = new Vector3f(
(dragEye.x - pressEye.x) * (dragStartEye.z - eyeEye.z) / (thisEye.z - eyeEye.z),
(pressEye.y - dragEye.y) * (dragStartEye.z - eyeEye.z) / (thisEye.z - eyeEye.z),
0f);
logger.fine("dragVectorEye = " + dragVectorEye);