#VRML V2.0 utf8 PROTO PlayerSocket [ eventIn SFFloat set_path_time eventIn MFFloat set_position_path_keys eventIn MFFloat set_orientation_path_keys eventIn MFVec3f set_position_path_points eventIn MFRotation set_orientation_path_points eventIn SFBool BindViewpoint eventIn SFRotation set_rotation eventIn SFVec3f set_position eventIn SFVec3f set_scale eventIn MFNode addChildren eventIn MFNode set_children eventIn MFNode removeChildren eventOut MFNode children_changed eventIn MFNode addGeometry eventIn MFNode set_geometry eventIn MFNode removeGeometry eventOut SFBool bind_changed eventOut MFNode geometry_changed eventOut SFRotation rotation_changed eventOut SFVec3f position_changed eventIn SFInt32 set_choice eventOut SFBool socketReady eventIn MFNode set_view_group ] { Group { children [ DEF ViewGroup Group { setChildren IS set_view_group } DEF P1 ProximitySensor { size 1000 1000 1000 enabled FALSE }, DEF T2 Transform { children [ Group { children [ Group { addChildren IS addChildren set_children IS set_children removeChildren IS removeChildren children_changed IS children_changed }, Switch { choice [ DEF T1 Transform { set_scale IS set_scale addChildren IS addGeometry set_children IS set_geometry removeChildren IS removeGeometry children_changed IS geometry_changed } ] set_whichChoice IS set_choice } ] } ] } ] } # Script added to avoid circular field reference. # Circularity acheived using ROUTE's back to original. DEF View_Maker2 Script { mustEvaluate TRUE eventIn SFBool viewpoint_bound eventOut SFBool bind_changed url "javascript: function initialize() { print('ViewMaker2 initialize'); } function viewpoint_bound(value, timestamp) { print('viewpoint_bound('+value+')'); bind_changed=value; } " } DEF View_Maker Script { mustEvaluate TRUE directOutput TRUE eventOut SFVec3f position_changed IS position_changed eventOut SFRotation rotation_changed IS rotation_changed eventIn SFBool viewpoint_bound eventIn SFBool BindViewpoint IS BindViewpoint eventIn SFVec3f user_moved eventIn MFNode view_changed eventIn SFRotation user_rotated eventIn SFVec3f set_position # IS set_position eventIn SFRotation set_rotation # IS set_rotation eventOut MFNode change_viewpoints eventOut SFBool bind_changed IS bind_changed field SFNode viewMaker2 USE View_Maker2 field SFNode TheViewpoint NULL field SFBool viewpoint_is_bound FALSE field SFVec3f last_position 0 0 0 field SFVec3f negate_movement 0 0 0 field SFRotation last_rotation 0 0 1 0 field SFRotation negate_rotation 0 0 1 0 url "javascript: function initialize() { print('PlayerSocket viewmaker initialize'); viewpoint_is_bound=FALSE; vpString='Viewpoint { position '+last_position.toString()+' orientation '+last_rotation.toString()+'}'; print(vpString); TheViewpoint=Browser.createVrmlFromString(vpString)[0]; Browser.addRoute(TheViewpoint,'isBound',viewMaker2,'viewpoint_bound'); change_viewpoints[0]=TheViewpoint; } function shutdown() { print('PlayerSocket viewmaker shutdown'); } function BindViewpoint() { change_viewpoints[0].set_bind=true; } function CreateNewViewpoint() { print('CreateNewViewpoint'); dest_val=viewpoint_is_bound; TheViewpoint.set_bind=false; TheViewpoint.set_position=last_position; TheViewpoint.set_orientation=last_rotation; negate_movement=last_position; negate_rotation=last_rotation; TheViewpoint.set_bind=dest_val; } function viewpoint_bound(value, timestamp) { print('viewpoint_bound '+value); if (!value) { if (viewpoint_is_bound) { viewpoint_is_bound=false; CreateNewViewpoint(); } } viewpoint_is_bound=value; bind_changed=value; } function user_moved(value,timestamp) { negate_movement=value; position_changed=value; } function user_rotated(value,timestamp) { negate_rotation=value; rotation_changed=value; } function set_rotation(value, timestamp) { print('ViewMaker set_rotation'); last_rotation=value.multiply(negate_rotation.multiply(last_rotation.inverse()).inverse()); CreateNewViewpoint(); } function set_position(value,timestamp) { print('ViewMaker set_position'); print(value); last_position=value.subtract(negate_movement.subtract(last_position)); CreateNewViewpoint(); } " } ROUTE View_Maker2.bind_changed TO View_Maker.viewpoint_bound DEF Route_Maker Script { mustEvaluate TRUE eventIn SFVec3f set_position IS set_position eventIn SFRotation set_rotation IS set_rotation eventIn SFBool set_running eventOut SFVec3f skip_position eventOut SFRotation skip_rotation eventOut SFTime start_time eventOut SFTime stop_time eventOut MFVec3f update_trail eventOut MFRotation update_spin eventOut SFBool running_changed eventOut SFBool socketReady IS socketReady field SFBool running FALSE field SFBool jump TRUE field SFBool jumpS TRUE field SFVec3f last_position 0 0 0 field SFRotation last_rotation 0 1 0 0 url "javascript: function initialize() { print('PlayerSocket route_maker initialize'); update_trail[0]=last_position; update_trail[1]=last_position; update_spin[0]=last_rotation; update_spin[1]=last_rotation; socketReady=true; } function shutdown() { print('PlayerSocket route_maker shutdown'); } function set_rotation(value, timestamp) { print('PlayerSocket route_maker set_rotation to ['+value[0]+','+value[1]+','+value[2]+','+value[3]+'] at '+timestamp); if (value==last_rotation) return; if (jumpS) { jumpS=false; last_rotation=value; skip_rotation=value; update_spin[0]=last_rotation; update_spin[1]=last_rotation; return; } update_spin[0]=last_rotation; update_spin[1]=value; if (!running) { running=true; running_changed=running; start_time=timestamp; stop_time=1+timestamp; } last_rotation=value; } function set_position(value, timestamp) { print('PlayerSocket route_maker set_position to ['+value[0]+','+value[1]+','+value[2]+'] at '+timestamp); if (value==last_position) return; if (jump) { skip_position=value; jump=false;last_position=value; update_trail[0]=last_position; update_trail[1]=last_position; return; } update_trail[0]=last_position; update_trail[1]=value; if (!running) { running=true; running_changed=running; start_time=timestamp; stop_time=timestamp+1; } last_position=value; } function set_running(value,timestamp) { running=value; running_changed=running; if (!value) { update_trail[1]=last_position; update_trail[0]=last_position; update_spin[1]=last_rotation; update_spin[0]=last_rotation; skip_position=last_position; skip_rotation=last_rotation; } } " }, DEF TIMER TimeSensor { enabled TRUE startTime -1 stopTime 0 cycleInterval 1 }, DEF INTERP PositionInterpolator { key [0,1] keyValue [0 0 0, 0 0 0] } DEF INTERPS OrientationInterpolator { key [0,1] keyValue [0 1 0 0, 0 1 0 0] } ROUTE TIMER.isActive TO Route_Maker.set_running ROUTE Route_Maker.start_time TO TIMER.set_startTime ROUTE Route_Maker.stop_time TO TIMER.set_stopTime ROUTE Route_Maker.skip_position TO T2.set_translation ROUTE Route_Maker.skip_rotation TO T2.set_rotation ROUTE TIMER.fraction_changed TO INTERP.set_fraction ROUTE TIMER.fraction_changed TO INTERPS.set_fraction ROUTE Route_Maker.update_trail TO INTERP.set_keyValue ROUTE Route_Maker.update_spin TO INTERPS.set_keyValue ROUTE INTERP.value_changed TO T2.set_translation ROUTE INTERPS.value_changed TO T2.set_rotation ROUTE View_Maker.bind_changed TO P1.set_enabled ROUTE P1.position_changed TO View_Maker.user_moved ROUTE P1.orientation_changed TO View_Maker.user_rotated ROUTE View_Maker.change_viewpoints TO ViewGroup.set_children ROUTE View_Maker.position_changed TO T2.set_translation ROUTE View_Maker.rotation_changed TO T2.set_rotation } PlayerSocket {}