|
51 | 51 |
|
52 | 52 | window.onload = function() { |
53 | 53 | var tracker = new tracking.ColorTracker(); |
| 54 | + tracker.setMinDimension(5); |
| 55 | + tracker.setMinGroupSize(10); |
54 | 56 |
|
55 | 57 | tracking.track('#video', tracker, { camera: true }); |
56 | 58 |
|
|
114 | 116 | return; |
115 | 117 | } |
116 | 118 |
|
117 | | - var rect = event.data[0]; |
118 | | - |
119 | | - rectangle.style.border = '2px solid ' + rect.color; |
120 | | - rectangle.style.width = rect.width + 'px'; |
121 | | - rectangle.style.height = rect.height + 'px'; |
122 | | - rectangle.style.left = (video.offsetLeft + rect.x) + 'px'; |
123 | | - rectangle.style.top = (video.offsetTop + rect.y) + 'px'; |
124 | | - |
125 | | - var x = rect.x + (rect.width >> 1); |
126 | | - var y = rect.y + (rect.height >> 1); |
127 | | - |
128 | | - mouseX = (((320 - x) / 320) * window.innerWidth) - windowHalfX; |
129 | | - mouseY = (((240 - y) / 240) * window.innerHeight) - windowHalfY; |
| 119 | + var maxRectArea = 0; |
| 120 | + var maxRect; |
| 121 | + event.data.forEach(function(rect) { |
| 122 | + if (rect.width * rect.height > maxRectArea){ |
| 123 | + maxRectArea = rect.width * rect.height; |
| 124 | + maxRect = rect; |
| 125 | + } |
| 126 | + }); |
| 127 | + |
| 128 | + if (maxRectArea > 0) { |
| 129 | + var rectCenterX = maxRect.x + (maxRect.width/2); |
| 130 | + var rectCenterY = maxRect.y + (maxRect.height/2); |
| 131 | + mouseX = (rectCenterX - 160) * (window.innerWidth/320) * 10; |
| 132 | + mouseY = (rectCenterY - 120) * (window.innerHeight/240) * 10; |
| 133 | + |
| 134 | + rectangle.style.border = '2px solid ' + maxRect.color; |
| 135 | + rectangle.style.width = maxRect.width + 'px'; |
| 136 | + rectangle.style.height = maxRect.height + 'px'; |
| 137 | + rectangle.style.left = (video.offsetLeft + maxRect.x) + 'px'; |
| 138 | + rectangle.style.top = (video.offsetTop + maxRect.y) + 'px'; |
| 139 | + } |
130 | 140 | } |
131 | 141 |
|
132 | 142 | function animate() { |
|
139 | 149 | camera.position.y += (- mouseY - camera.position.y) * 0.05; |
140 | 150 | camera.lookAt(scene.position); |
141 | 151 |
|
142 | | - group.rotation.x += 0.01; |
143 | | - group.rotation.y += 0.02; |
144 | | - |
145 | 152 | renderer.render(scene, camera); |
146 | 153 | } |
147 | 154 | </script> |
|
0 commit comments