-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add and remove voxels, rotate camera
- Loading branch information
Showing
6 changed files
with
284 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class InputManager { | ||
|
||
static mouseX = 0; | ||
static mouseY = 0; | ||
static middleDown; | ||
static initialize(canvas, addCallback, removeCallback, cameraCallback, zoomCallback) | ||
{ | ||
InputManager.mouseX = 0; | ||
InputManager.mouseY = 0; | ||
canvas.addEventListener('mousemove', function(evt) { | ||
var mousePos = InputManager.getMousePos(canvas, evt); | ||
InputManager.mouseX = mousePos.x; | ||
InputManager.mouseY = mousePos.y; | ||
if(InputManager.middleDown) | ||
{ | ||
cameraCallback(evt.movementX, evt.movementY); | ||
} | ||
//console.log(mousePos); | ||
}); | ||
canvas.addEventListener('mousedown', function(evt) { | ||
if(evt.button == 0) | ||
{ | ||
if(evt.altKey) | ||
{ | ||
removeCallback(); | ||
} | ||
else | ||
{ | ||
addCallback(); | ||
} | ||
} | ||
else if(evt.button == 1){ | ||
InputManager.middleDown = true; | ||
} | ||
}); | ||
canvas.addEventListener('mouseup', function(evt) { | ||
if(evt.button == 1) | ||
{ | ||
InputManager.middleDown = false; | ||
} | ||
}); | ||
canvas.addEventListener('wheel', function(evt) { | ||
zoomCallback(evt.deltaY); | ||
}) | ||
} | ||
|
||
static getMousePos(canvas, evt) { | ||
var rect = canvas.getBoundingClientRect(); | ||
return { | ||
x: evt.clientX - rect.left, | ||
y: rect.height - (evt.clientY - rect.top) | ||
}; | ||
} | ||
} | ||
|
||
export {InputManager} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.