Skip to content

Commit

Permalink
Merge pull request xeolabs#171 from sascha-hendel/patch-8
Browse files Browse the repository at this point in the history
Update src/examples/vertex-sharing/vertex-sharing.js
  • Loading branch information
xeolabs committed Feb 27, 2012
2 parents 066dc73 + e9be3ff commit a3b343a
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/examples/vertex-sharing/vertex-sharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,22 +428,44 @@ 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) {
yaw += (event.clientX - lastX) * 0.5;
pitch += (event.clientY - lastY) * -0.5;
yaw += (posX - lastX) * 0.5;
pitch += (posY - lastY) * -0.5;

lastX = event.clientX;
lastY = event.clientY;
lastX = posX;
lastY = posY;

scene.findNode("yaw").set({angle: yaw});
scene.findNode("pitch").set({angle: pitch});
Expand All @@ -453,7 +475,9 @@ 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();

Expand Down

0 comments on commit a3b343a

Please sign in to comment.