Skip to content

Commit

Permalink
Merge pull request xeolabs#172 from sascha-hendel/patch-9
Browse files Browse the repository at this point in the history
Update src/examples/moving-point-light/moving-point-light.js
  • Loading branch information
xeolabs committed Feb 27, 2012
2 parents 2f5ad00 + 6ef8974 commit 066dc73
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/examples/moving-point-light/moving-point-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,41 @@ function mouseDown(event) {
dragging = true;
}

function touchStart(event) {
lastX = event.targetTouches[0].clientX;
lastY = event.targetTouches[0].clientY;
dragging = true;
}

function mouseUp() {
dragging = false;
}

function touchEnd() {
dragging = false;
}

var scene = SceneJS.scene("theScene");

/* On a mouse drag, we'll re-render the scene, passing in
function mouseMove(event) {
var posX = event.clientX;
var posY = event.clientY;
actionMove(posX,posY);
}

function touchMove(event) {
var posX = event.targetTouches[0].clientX;
var posY = event.targetTouches[0].clientY;
actionMove(posX,posY);
}

/* On a mouse/touch drag, we'll re-render the scene, passing in
* incremented angles in each time.
*/
function mouseMove(event) {
function actionMove(posX, posY) {
if (dragging) {
roty = (event.clientX - lastX);
rotx = (event.clientY - lastY);
roty = (posX - lastX);
rotx = (posY - lastY);

if (Math.abs(roty) > Math.abs(rotx)) {

Expand All @@ -213,14 +235,17 @@ function mouseMove(event) {
}
});
}
lastX = event.clientX;
lastY = event.clientY;
lastX = posX;
lastY = posY;
}
}

canvas.addEventListener('mousedown', mouseDown, true);
canvas.addEventListener('mousemove', mouseMove, true);
canvas.addEventListener('mouseup', mouseUp, true);
canvas.addEventListener('touchstart', touchStart, true);
canvas.addEventListener('touchmove', touchMove, true);
canvas.addEventListener('touchend', touchEnd, true);

SceneJS.bind("error", function(e) {
alert(e.exception.message);
Expand Down

0 comments on commit 066dc73

Please sign in to comment.