Skip to content

Commit c68d63c

Browse files
mairatmaeduardolundgren
authored andcommitted
Fixing fish tank demo for color
1 parent c818317 commit c68d63c

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

examples/color_fish_tank.html

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151

5252
window.onload = function() {
5353
var tracker = new tracking.ColorTracker();
54+
tracker.setMinDimension(5);
55+
tracker.setMinGroupSize(10);
5456

5557
tracking.track('#video', tracker, { camera: true });
5658

@@ -114,19 +116,27 @@
114116
return;
115117
}
116118

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+
}
130140
}
131141

132142
function animate() {
@@ -139,9 +149,6 @@
139149
camera.position.y += (- mouseY - camera.position.y) * 0.05;
140150
camera.lookAt(scene.position);
141151

142-
group.rotation.x += 0.01;
143-
group.rotation.y += 0.02;
144-
145152
renderer.render(scene, camera);
146153
}
147154
</script>

0 commit comments

Comments
 (0)