forked from zenorocha/tracking.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove_threejs_minecraft.html
More file actions
74 lines (57 loc) · 2.46 KB
/
Copy pathmove_threejs_minecraft.html
File metadata and controls
74 lines (57 loc) · 2.46 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
<!doctype html>
<html>
<head>
<title>tracking.js + three.js: minecraft</title>
<meta charset="utf-8">
<script src="../dist/tracking.min.js"></script>
<script src="../dist/tracker/color/color.min.js"></script>
<script src="js/threejs/Three.js"></script>
<script src="js/threejs/ImprovedNoise.js"></script>
<script src="js/threejs/Detector.js"></script>
<script src="js/threejs/Stats.js"></script>
<link rel="stylesheet" href="css/minecraft.css">
</head>
<body>
<div id="container"><br /><br /><br /><br /><br />Generating world...</div>
<div id="info"><a href="http://github.com/eduardolundgren/tracking.js" target="_blank">tracking.js</a> and <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - <a href="http://www.minecraft.net/" target="_blank">minecraft</a> demo. featuring <a href="http://painterlypack.net/" target="_blank">painterly pack</a><br />(left or right: magenta, forward: cyan)</div>
<div id="aim"></div>
<div id="videoContainer"></div>
<script src="js/threejs/minecraft.js"></script>
<script>
var videoCamera = new tracking.VideoCamera().hide().render().renderVideoCanvas('#videoContainer');
var aim = tracking.one('#aim');
videoCamera.track({
type: 'color',
color: 'magenta',
onFound: function(track) {
var x = track.x,
y = track.y;
if (x && y) {
var mouseX = ((320 - track.x)/320)*window.innerWidth - controls.viewHalfX,
mouseY = ((240 - track.y)/240)*window.innerHeight - controls.viewHalfY;
controls.mouseX = mouseX;
controls.mouseY = mouseY;
aim.style.top = window.innerHeight - (mouseY + controls.viewHalfY) + 'px';
aim.style.left = mouseX + controls.viewHalfX + 'px';
}
},
onNotFound: function() {
controls.moveLeft = false;
controls.moveRight = false;
controls.moveForward = false;
controls.moveBackward = false;
}
});
videoCamera.track({
type: 'color',
color: 'cyan',
onFound: function(track) {
controls.moveForward = true;
},
onNotFound: function() {
controls.moveForward = false;
}
});
</script>
</body>
</html>