I have a tileset. I want to pan up/down using right mouse click+drag on tileset model. I want to pan object with relation to mouse movement. Object should be there where the mouse pointer is (similar to when panning is done using left mouse by default) My code moves camera but model goes way to far from pointer.
Here is my code:
scene.screenSpaceCameraController.enableRotate = false;
scene.screenSpaceCameraController.enableTranslate = false;
scene.screenSpaceCameraController.enableZoom = false;
scene.screenSpaceCameraController.enableTilt = false;
scene.screenSpaceCameraController.enableLook = false;
var startMousePosition;
var mousePosition;
var pan = false;
var pickedCenter;
var handler = new Cesium.ScreenSpaceEventHandler(canvas);
var timeout = null;
handler.setInputAction(function(movement) {
if (pan) {
//Check if mouse is not moving
clearTimeout(timeout);
timeout = setTimeout(function() {
mousePosition = startMousePosition = Cesium.Cartesian3.clone(movement.startPosition);
}, 100);
mousePosition = movement.endPosition;
var camera = viewer.camera;
var width = canvas.clientWidth;
var height = canvas.clientHeight;
// Coordinate (0.0, 0.0) will be where the mouse was clicked.
var x = (mousePosition.x - startMousePosition.x)// / width;
var y = -(mousePosition.y - startMousePosition.y)// / height;
var moveFactor = 0.005;
camera.moveRight(x * moveFactor * -1);
camera.moveUp(y * moveFactor * -1);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
//-----Right Mouse
handler.setInputAction(function(movement) {
pan = true;
mousePosition = startMousePosition = Cesium.Cartesian3.clone(movement.position);
}, Cesium.ScreenSpaceEventType.RIGHT_DOWN);
handler.setInputAction(function(position) {
pan = false;
}, Cesium.ScreenSpaceEventType.RIGHT_UP);