-
Notifications
You must be signed in to change notification settings - Fork 0
/
KalmanPointerPrediction.html
66 lines (60 loc) · 2.36 KB
/
KalmanPointerPrediction.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html>
<head>
<style>
html, body, div, canvas {
margin: 0;
padding: 0;
}
</style>
<script>
var ctx;
window.addEventListener("pointermove", function(event) {
document.getElementById("x").innerHTML = Math.floor(event.pageX);
document.getElementById("y").innerHTML = Math.floor(event.pageY);
console.log("***************next***************");
console.log("Coalesced -> ");
for (let e of event.getCoalescedEvents()) {
console.log("(" + e.pageX + ", " + e.pageY + ")");
drawCoordinates(e.pageX, e.pageY, "#00ff00", 6);
}
var predicted_points = event.getPredictedEvents();
if(predicted_points.length > 0) {
console.log("Predicted -> ");
for (let e of predicted_points) {
console.log("(" + e.pageX + ", " + e.pageY + ")");
drawCoordinates(e.pageX, e.pageY, "#ff0000", 3);
}
}
drawCoordinates(event.pageX, event.pageY, "#0000ff", 12);
});
function drawCoordinates(x, y, color, pointSize){
ctx.beginPath();
ctx.arc(x, y, pointSize, 0, Math.PI * 2, true);
ctx.strokeStyle = color;
ctx.stroke();
}
function onloadHandler() {
// Create a canvas that extends the entire screen
// and it will draw right over the other html elements, like buttons, etc
var canvas = document.createElement("canvas");
canvas.setAttribute("width", window.innerWidth);
canvas.setAttribute("height", window.innerHeight);
canvas.setAttribute("style", "position: fixed; left:0px; right:0px;");
document.body.appendChild(canvas);
ctx = canvas.getContext("2d");
}
</script>
</head>
<body onload="onloadHandler()">
<div style="position: fixed; left:0px; right:0px">
Event coalescing and prediction demo<br />
Try pointerdown -> pointermove -> pointerup<br /><br />
Info: Pointer co-ordinates: (<span id="x">0</span>, <span id="y">0</span>)<br />
(Optional: See console log for even more details on predicted event coords)<br /><br />
<span style="color:#00ff00">Green</span>: Events that are being coalesced.<br />
<span style="color:#0000ff">Blue</span>: Coalesced event.<br />
<span style="color:#ff0000">Red</span>: Predicted events.<br />
</div>
</body>
</html>