Skip to content
This repository has been archived by the owner on Nov 30, 2017. It is now read-only.

Commit

Permalink
Fix touch screen events in Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
s-macke committed Nov 26, 2017
1 parent 9be3cf6 commit b87536d
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions VoxelSpace.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,28 @@

}

// ---------------------------------------------
// Keyboard and mouse event handlers
// ---------------------------------------------
// Keyboard and mouse event handlers

function GetMousePosition(e)
{
// fix for Chrome
if (isNaN(e.pageX))
{
return [e.targetTouches[0].pageX, e.targetTouches[0].pageY];
} else
{
return [e.pageX, e.pageY];
}
}


function DetectMouseDown(e)
{
input.forwardbackward = 3.;
input.mouseposition = [e.pageX, e.pageY];
input.mouseposition = GetMousePosition(e);
time = new Date().getTime();

if (!updaterunning) Draw();
Expand All @@ -223,9 +238,11 @@
if (input.mouseposition == null) return;
if (input.forwardbackward == 0) return;

input.leftright = (input.mouseposition[0]-e.pageX) / window.innerWidth * 2;
camera.horizon = 100 + (input.mouseposition[1]-e.pageY) / window.innerHeight * 500;
input.updown = (input.mouseposition[1]-e.pageY) / window.innerHeight * 10;
var currentMousePosition = GetMousePosition(e);

input.leftright = (input.mouseposition[0] - currentMousePosition[0]) / window.innerWidth * 2;
camera.horizon = 100 + (input.mouseposition[1] - currentMousePosition[1]) / window.innerHeight * 500;
input.updown = (input.mouseposition[1] - currentMousePosition[1]) / window.innerHeight * 10;
}


Expand Down

0 comments on commit b87536d

Please sign in to comment.