I have this amazing tutorial at http://www.computerarts.co.uk/tutorials/build-your-own-motion-tracking-system In the developer version, the tracker moves along the X-axis. I want it to stay stationary rather than moving and when the object from the webcam comes in front of it. The stationary cross mark should be able to trigger an event preferably a sound when anybody is in front of it. Would be grateful for the help I get. I am a complete noob in AS. If you have any other tutorial and link me to it I would appreciate it.
The easiest way to do this would probably be to create either a second Point
to keep track of the position. Then you can test collision with the TrackerMC
that doesn't move. To do this:
At the top, add
private var _movingPos:Point = new Point();
Then, in the resize()
function, add:
_tracker.x = sW * 0.5;
_movingPos.y = sH * 0.5;
Then, in loop()
change _tracker.x += (_pos.x - _tracker.x) * .1;
to:
_movingPos.x += (_pos.x - _movingPos.x) * 0.1;
And, to test if the point is in front of the crosshair, add at the end of the loop()
function:
if (_tracker.hitTestPoint(_movingPos.x, _movingPos.y, true))
doSomething(); // Add whatever custom function here.
In your doSomething();
function, you can play a sound, or anything else.
For debugging, you can add a second TrackerMC
and update its position to equal _movingPos
to see where you are.
I wrote a similar motion tracker in AS3. Its on github. You can check it out here: https://github.com/chinchang/AS3-Motion-Tracker
Let me know if you have any queries on it.
Also a sample game made with it here.
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With