From 018a4af9d613fe023b6f98014a346e890df5c398 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 30 Jan 2015 09:22:39 -0800 Subject: [PATCH] Update camera tool to wrap cursor to window bounds rather than keep at center --- examples/libraries/entityCameraTool.js | 41 ++++++++++++++++++++------ 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/examples/libraries/entityCameraTool.js b/examples/libraries/entityCameraTool.js index f5095bb149..9f53d585d2 100644 --- a/examples/libraries/entityCameraTool.js +++ b/examples/libraries/entityCameraTool.js @@ -208,6 +208,11 @@ CameraManager = function() { if (that.enabled && that.mode != MODE_INACTIVE) { var x = Window.getCursorPositionX(); var y = Window.getCursorPositionY(); + if (!hasDragged) { + that.lastMousePosition.x = x; + that.lastMousePosition.y = y; + hasDragged = true; + } if (that.mode == MODE_ORBIT) { var diffX = x - that.lastMousePosition.x; var diffY = y - that.lastMousePosition.y; @@ -235,9 +240,31 @@ CameraManager = function() { that.moveFocalPoint(dPosition); } - var newX = Window.x + Window.innerWidth / 2; - var newY = Window.y + Window.innerHeight / 2; - Window.setCursorPosition(newX, newY); + + var newX = x; + var newY = y; + var updatePosition = false; + + if (x <= Window.x) { + newX = Window.x + Window.innerWidth; + updatePosition = true; + } else if (x >= (Window.x + Window.innerWidth)) { + newX = Window.x; + updatePosition = true; + } + + if (y <= Window.y) { + newY = Window.y + Window.innerHeight; + updatePosition = true; + } else if (y >= (Window.y + Window.innerHeight)) { + newY = Window.y; + updatePosition = true; + } + + if (updatePosition) { + Window.setCursorPosition(newX, newY); + } + that.lastMousePosition.x = newX; that.lastMousePosition.y = newY; @@ -246,6 +273,7 @@ CameraManager = function() { return false; } + var hasDragged = false; that.mousePressEvent = function(event) { if (cameraTool.mousePressEvent(event)) { return true; @@ -260,12 +288,7 @@ CameraManager = function() { } if (that.mode != MODE_INACTIVE) { - var newX = Window.x + Window.innerWidth / 2; - var newY = Window.y + Window.innerHeight / 2; - Window.setCursorPosition(newX, newY); - that.lastMousePosition.x = newX; - that.lastMousePosition.y = newY; - Window.setCursorVisible(false); + hasDragged = false; return true; }