media @ VU
web3d-x-viewpoint.vr
web3d-x-viewpoint.vr
(wrl
)
[ flux /
bitmanagement /
cortona /
octaga
]
Web3D/VR
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
DEF Where ProximitySensor {
size 1000 1000 1000
}
viewpoint
DEF Look Viewpoint {
jump FALSE
}
background
Background {
groundAngle [1.57]
skyAngle [1.57]
groundColor [0 .7 0, .7 .7 .7]
skyColor [0 0 .7, .7 .7 .7]
}
concepts
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
DEF Timer TimeSensor {
enabled FALSE
loop FALSE
cycleInterval 1
startTime 1
stopTime 2
}
interpolators
code
DEF FlyPos PositionInterpolator {
key [0, 1]
}
DEF FlyRot OrientationInterpolator {
key [0, 1]
}
the script
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
ROUTE Where.position_changed TO Move.position
ROUTE Where.orientation_changed TO Move.orientation
mouse clicks
ROUTE ClickBox.touchTime TO Move.touchBox
ROUTE ClickCone.touchTime TO Move.touchCone
ROUTE ClickSphere.touchTime TO Move.touchSphere
set interpolator values
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
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
(C) A. Eliëns
21/5/2007
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.