Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify motion tracking in AS3

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.

like image 778
Vivian Lobo Avatar asked Jan 27 '12 15:01

Vivian Lobo


2 Answers

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.

like image 151
wquist Avatar answered Oct 04 '22 20:10

wquist


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!

like image 28
Kushagra Gour Avatar answered Oct 04 '22 19:10

Kushagra Gour