protected void handleRotate(Vector3f start, Vector3f end, float direction) { LOGGER.warning( "Handling rotate, start: " + start + "" + "\nlast: " + lastTranslation + "" + "\nend: " + end); Vector3f increment = end.subtract(lastTranslation); increment.y = 0; float length = increment.length(); float magic = 3f; // ~ 180 degrees float percent = length / magic; // if the difference is negative, we need to rotate in the opposite // direction. Caclulate the difference after taking into account // the direction of the camera // CellTransform viewTransform = ViewManager.getViewManager().getCameraTransform(); // Quaternion viewRotation = viewTransform.getRotation(null); // increment = viewRotation.mult(increment); // // LOGGER.warning("viewTransform: " + viewTransform + ", increment: " + // increment); // // if (increment.x < 0 || increment.z < 0) { // percent = -percent; // } // take direction into account percent *= direction; Quaternion rotation = new Quaternion(); rotation.fromAngles(0f, percent * FastMath.PI, 0f); // rotation is the total rotation since we started moving the mouse, // so calculate just the delta to apply Quaternion deltaRotation = rotation.mult(lastRotation.inverse()); LOGGER.warning( "Percent: " + percent + " = " + toAnglesString(rotation) + ". Last = " + toAnglesString(lastRotation) + ". Delta = " + toAnglesString(deltaRotation)); applyDelta(Vector3f.ZERO, deltaRotation); }