:-object balllook : [bcilib]. var url = './yt/yt-with-ball.wrl'. var count = 0. var timelimit = 500. var avatarHeight = 1.5. main:- text_area(BrowserStream), set_output(BrowserStream), format('look-at-ball example is running ...~n'), format('Loading the humaniod from ~w~n', [url]), format('Please wait ...~n'), loadURL(url), format('you can run this example until the counter is ~w~n',[timelimit]), format('Use the mouse to move around the ball~n'), sleep(6000), play(hanim_HumanoidRoot,ball,timelimit), true. play(Agent,Object,Time):- count := 0, repeat, look_at_ballEx(Agent,Object), format('the counter is ~w.~n',[count]), ++count, count > Time, !. look_at_ballEx(Player,Ball) :- getSFVec3f(Player,translation, X,Y,Z), getPosition(Ball, X1,Y1,Z1), getPlayerHead(Player,PlayerHead), X =\= X1, !, Xdif is X-X1, Ydif is Y1-(Y + avatarHeight), Zdif is Z1-Z, Distance is sqrt(Xdif*Xdif+Zdif*Zdif), Ry is atan(Ydif/Distance), setRotation(PlayerHead,-1.0, 0.0, 0.0, Ry), R is atan(Zdif/Xdif) - sign(Xdif)*1.571, setRotation(Player,0.0, 1.0, 0.0, R). look_at_ballEx(Player,Ball) :- getSFVec3f(Player,translation, _X,Y,Z), getPosition(Ball, _X1,Y1,Z1), getPlayerHead(Player,PlayerHead), Z =\= Z1, !, Ydif is Y1-(Y + avatarHeight), Zdif is Z1-Z, Ry is atan(Ydif/Zdif), setRotation(PlayerHead,-1.0, 0.0, 0.0, Ry). look_at_ballEx(_,_):-!. getPlayerHead(hanim_HumanoidRoot,hanim_skullbase):-!. getPlayerHead(_,_):- format('unknown body part~n'). :-end_object balllook.