:-object wasp1c : [bcilib].

var url = './street/street1b.wrl'.

var timelimit = 200.

main :-
%	  text_area(Browser),
%	  set_output(Browser),
        format('Loading street1 from ~w~n', [url]),
        loadURL(url),
       format('The bus1 is going to jump in front of you in 5 seconds,~n'),
      format('then you can drive the bus for ~w seconds~n', [timelimit]),
        delay(5000),
        jump_to(bus1,'ViewPoint'),
        drive(bus1, 'ViewPoint').

jump_to(Object, Viewpoint) :-
        getViewpointPosition(Viewpoint,X,_Y,Z),
        Z1 is Z-5,
        setPosition(Object,X, 0.0 ,Z1). 

drive(Object, Viewpoint) :-
        --timelimit,
        timelimit > 0, !,
        format('time left: ~w seconds~n', [timelimit]),
        delay(1000),
        getViewpointPosition(Viewpoint,X,_Y,Z),
        getViewpointOrientation(Viewpoint,_X2,Y2,_Z2,R2),
	  R3 is R2 + sign(Y2)*1.5708,
	  Y3 is sign(Y2+0.5)*1.0,
        setPosition(Object,X, 0.0 ,Z),
        setRotation(Object,0.0,Y3,0.0,R3),
        drive(Object,Viewpoint).

drive(_, _).

:-end_object wasp1c.
