-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
78 lines (63 loc) · 2.08 KB
/
test.html
File metadata and controls
78 lines (63 loc) · 2.08 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
<html>
<head>
<script src='socket.io.js'></script>
</head>
<body>
<div id="vel"> </div>
<form id='joinRoom'>
<input id="room-id" type='text' name="name">
<input id='button' type='submit' name='submit'>
</form>
<script>
var socket = io.connect('http://10.0.1.169:9000');
var form = document.getElementById('joinRoom');
var input = document.getElementById('room-id');
var index = null;
socket.on('updateScore', function() {
// do shit
});
form.addEventListener("submit", function(e) {
console.log(input.value);
socket.emit('joinRoom', 'controller', input.value);
socket.on('notifyRoomID', function(id) {
console.log("connected");
});
e.preventDefault();
return false;
});
var shark_velocity = {'direction':0, 'depth':0};
var last_direction = 0;
var last_depth = 0;
var sendDepth = function() {
socket.emit('setDepth', Math.round(shark_velocity.depth));
};
var sendDirection = function() {
socket.emit('setDirection', Math.round(shark_velocity.direction));
};
window.addEventListener('deviceorientation', function(eventData) {
// gamma is the left-to-right tilt in degrees, where right is positive
shark_velocity.depth = eventData.gamma/180;
// between -1 and 1
// beta is the front-to-back tilt in degrees, where front is positive
shark_velocity.direction = eventData.beta/90;
// also between -1 and 1
// alpha is the compass direction the device is facing in degrees
var dir = eventData.alpha;
// call our orientation event handler
if (Math.abs(Math.round(shark_velocity.direction) - last_direction)) {
sendDirection();
last_direction = Math.round(shark_velocity.direction);
}
if (Math.abs(Math.round(shark_velocity.depth) - last_depth)) {
sendDepth();
last_depth = Math.round(shark_velocity.depth);
}
document.getElementById("vel").textContent = "dir: " + shark_velocity.direction.toString() + " dep: " + shark_velocity.depth.toString();
}, false);
if (window.DeviceOrientationEvent) {
console.log("DeviceOrientation is supported");
}
// Listen for the deviceorientation event and handle the raw data
</script>
</body>
</html>