Skip to content

Commit

Permalink
Merge pull request xeolabs#183 from sascha-hendel/patch-20
Browse files Browse the repository at this point in the history
Update src/examples/texture-atlas/texture-atlas.js
  • Loading branch information
xeolabs committed Feb 27, 2012
2 parents d2f1f16 + 15dfd86 commit e88ffa5
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/examples/texture-atlas/texture-atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,40 @@ 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");

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);
}

function actionMove(posX, posY) {
if (dragging) {
yaw += (event.clientX - lastX) * 0.5;
pitch += (event.clientY - lastY) * -0.5;
lastX = event.clientX;
lastY = event.clientY;
yaw += (posX - lastX) * 0.5;
pitch += (posY - lastY) * -0.5;
lastX = posX;
lastY = posY;

scene.findNode("pitch").set("angle", pitch);
scene.findNode("yaw").set("angle", yaw);
Expand All @@ -219,5 +241,8 @@ function mouseMove(event) {
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);

scene.start();

0 comments on commit e88ffa5

Please sign in to comment.