#VRML V2.0 utf8 ## ##:@* viewpoint animation ##- Example to show how to animate between viewpoints. ##- (See note below.) This example smoothly animates ##- the viewpoint when a user clicks on any of the ##- objects in the scene. ##-

##- ##- Technical Note: ##- The VRML spec does not require the ##- viewpoint to change when a viewpoint becomes ##- active by virtue of it being at the top of the ##- viewpoint stack (either by pushing it onto the stack ##- or poping the current one off). ##-

##- ##- Author: Leonard Daly (daly@realism.com) ##- Copyright 1999, Leonard Daly ##@ proximity sensor ## Define a world encompassing proximity sensor. This ## is needed so that we always "know" where we are. DEF Where ProximitySensor { size 1000 1000 1000 } ##@ viewpoint ## Define a viewpoint node that we can manipulate. ## This node does not show up on the viewpoint list ## because it does not have a description. DEF Look Viewpoint { jump FALSE } ##@ background ## Define a background to provide orientation has we ## move around in the world. Background { groundAngle [1.57] skyAngle [1.57] groundColor [0 .7 0, .7 .7 .7] skyColor [0 0 .7, .7 .7 .7] } ##@ concepts ## Define the objects in the world. There are ## 3 - Box (red), Cone (orange), and Sphere (purple). ## Each object detects a mouse button up event that ## starts the animation. ##@ box Transform { translation -2 0 2 children [ DEF ClickBox TouchSensor {} Shape { appearance Appearance { material Material { diffuseColor 1 0 0 } } geometry Box {} } ] } ##@ cone Transform { translation .5 -1 -1 children [ DEF ClickCone TouchSensor {} Shape { appearance Appearance { material Material { diffuseColor 1 .5 0 } } geometry Cone {} } ] } ##@ sphere Transform { translation 3 1 1 children [ DEF ClickSphere TouchSensor {} Shape { appearance Appearance { material Material { diffuseColor .8 0 1 } } geometry Sphere {} } ] } ##@ timer ## Time control on the animation DEF Timer TimeSensor { enabled FALSE loop FALSE cycleInterval 1 startTime 1 stopTime 2 } ##@ interpolators ## Define the two interpolators that provide viewpoint ## animation. The PositionInterpolator moves us from ## one viewpoint to the next. The OrientationInterpolator ## smoothly changes our orientation so that when we arrive ## at the destination we are pointing the correct way. ## The keyValue fields for each interpolator will be ## provided before the animation starts. ##@ code DEF FlyPos PositionInterpolator { key [0, 1] } DEF FlyRot OrientationInterpolator { key [0, 1] } ##@ the script ## The script is the "heart" of the solution. ## It monitors the viewers position and orientation ## at all times so a smooth animation can be performed ## from their current viewpoint to the predetermined ## viewpoint choosen by a mouse click. ## The animation last 4 seconds (duration). ##@ interface DEF Move Script { field SFTime duration 4.0 field SFVec3f cur_pos 0 0 0 field SFRotation cur_rot 0 1 0 0 field SFVec3f new_pos 0 0 0 field SFRotation new_rot 0 1 0 0 eventIn SFTime touchBox # click Box eventIn SFTime touchCone # click Cone eventIn SFTime touchSphere # click Sphere eventIn SFVec3f position # current position eventIn SFRotation orientation # current orientation ##@ out eventOut SFBool bind eventOut MFVec3f pos_changed eventOut MFRotation rot_changed eventOut SFTime startTime eventOut SFTime endTime eventOut SFTime cycle ##@ script (body) url "javascript: // Set the starting and ending (keyValue) position // and oroientation. These generate events. function setDestination () { pos_changed = new MFVec3f (cur_pos, new_pos); rot_changed = new MFRotation (cur_rot, new_rot); } ##@ set times // Set the starting, ending, and duration times of the // animation. function setTime (time) { startTime = time + .05; endTime = startTime + duration; cycle = duration; bind = true; } ##@ set targets // Set the target viewpoint when the Box is clicked. function touchBox (value, time) { new_pos[0] = -.343; new_pos[1] = 11.72; new_pos[2] = 5.19; new_rot[0] = -.966; new_rot[1] = -.257; new_rot[2] = 0.036; new_rot[3] = 1.20; setDestination (); setTime (time); } ##@ cone function touchCone (value, time) { new_pos[0] = -.436; new_pos[1] = 2.79; new_pos[2] = -12.29; new_rot[0] = .029; new_rot[1] = .994; new_rot[2] = .107; new_rot[3] = 3.18; setDestination (); setTime (time); } ##@ sphere function touchSphere (value, time) { new_pos[0] = 9.36; new_pos[1] = -11.67; new_pos[2] = .09; new_rot[0] = .806; new_rot[1] = .590; new_rot[2] = -.063; new_rot[3] = 1.62; setDestination (); setTime (time); } ##@ track users position // Track the user's current position. function position (value) { cur_pos[0] = value[0]; cur_pos[1] = value[1]; cur_pos[2] = value[2]; } ##@ track users orientation // Track the user's current orientation. function orientation (value) { cur_rot[0] = value[0]; cur_rot[1] = value[1]; cur_rot[2] = value[2]; cur_rot[3] = value[3]; } " } ##@ event routing ## Wire up the events. First ensure that the user's ## current position and orientation is recorded. ROUTE Where.position_changed TO Move.position ROUTE Where.orientation_changed TO Move.orientation ##@ mouse clicks ## Capture the mouse clicks on the objects ROUTE ClickBox.touchTime TO Move.touchBox ROUTE ClickCone.touchTime TO Move.touchCone ROUTE ClickSphere.touchTime TO Move.touchSphere ##@ set interpolator values ## Set the keyValues for the Interpolators and ## the fields values for the timer. ROUTE Move.startTime TO Timer.startTime ROUTE Move.endTime TO Timer.stopTime ROUTE Move.cycle TO Timer.cycleInterval ROUTE Move.bind TO Timer.enabled ROUTE Move.pos_changed TO FlyPos.keyValue ROUTE Move.rot_changed TO FlyRot.keyValue ##@ set viewpoint ## Send the output of the interpolators to the ## viewpoint node. Bind the node if necessary. ROUTE Timer.fraction_changed TO FlyPos.set_fraction ROUTE Timer.fraction_changed TO FlyRot.set_fraction ROUTE FlyPos.value_changed TO Look.position ROUTE FlyRot.value_changed TO Look.orientation ROUTE Move.bind TO Look.set_bind ##