-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtracking.em
36 lines (29 loc) · 922 Bytes
/
tracking.em
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
system.require('std/core/repeatingTimer.em');
system.require('work/lookAt.em');
system.require('work/spin.em');
var trackingTimer;
var butterfly;
(function () {
var timerDelay = 0.05;
var mesh = 'meerkat:///wmonroe4/butterfly.dae/original/0/butterfly.dae';
system.create_presence(mesh, function(newPres){
butterfly = newPres;
butterfly.position = <0, 0, 10>;
spin(butterfly);
});
function track(pres1, pres2)
{
lookAt(pres1, pres2.position);
/* */
var vRel = pres2.velocity - pres1.velocity;
var disp = pres2.position - pres1.position;
var axis = disp.cross(vRel).normal();
var rotation = Math.sqrt(vRel.lengthSquared() * 1. / disp.lengthSquared());
pres1.orientationVel = (new util.Quaternion(axis, 1)).scale(rotation);
/* */
};
trackingTimer = new std.core.RepeatingTimer(timerDelay, function(){
if(typeof(butterfly) != 'undefined')
track(system.self, butterfly);
});
})();