Controlling time
- A TimeSensor node is similar to a stop watch
- You control the start and stop time
- The sensor generates time events while it is running
- To animate, route time events into other nodes
Using absolute time
- A TimeSensor node generates absolute and fractional time events
- Absolute time events give the wall-clock time
- Absolute time is measured in seconds since 12:00am January 1, 1970!
- Useful for triggering events at specific dates and times
Using fractional time
- Fractional time events give a number from 0.0 to 1.0
- When the sensor starts, it outputs a 0.0
- At the end of a cycle, it outputs a 1.0
- The number of seconds between 0.0 and 1.0 is controlled by the cycle interval
- The sensor can loop forever, or run through only one cycle and stop
Syntax: TimeSensor
- A TimeSensor node generates events based upon time
- startTime and stopTime - when to run
- cycleInterval - how long a cycle is
- loop - whether or not to repeat cycles
1 2 3 4 5 6 |
TimeSensor { cycleInterval 1.0 loop FALSE startTime 0.0 stopTime 0.0 } |
Using timers
To create a continuously running timer:
- loop TRUE
- stopTime <= startTime
When stop time <= start time, stop time is ignored
To run until the stop time:
- loop TRUE
- stopTime > startTime
To run one cycle then stop:
- loop FALSE
- stopTime <= startTime
The set_startTime input event:
- Sets when the timer should start
The set_stopTime input event:
- Sets when the timer should stop
A sample time sensor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Shape { appearance Appearance { material DEF Monolith1Facade Material { diffuseColor 0.2 0.2 0.2 } } geometry Box { size 2.0 4.0 0.3 } } DEF Monolith1Timer TimeSensor { cycleInterval 4.0 loop FALSE startTime 0.0 stopTime 0.1 } ROUTE Monolith1Touch.touchTime TO Monolith1Timer.set_startTime ROUTE Monolith1Timer.fraction_changed TO Monolith1Facade.set_transparency |
Converting time to position
To animate the position of a shape you provide:
- A list of key positions for a movement path
- A time at which to be at each position
An interpolator node converts an input time to an output position
- When a time is in between two key positions, the interpolator computes an intermediate position
Syntax: PositionInterpolator
A PositionInterpolator node describes a position path
- key - key fractional times
- keyValue - key positions
1 2 3 4 |
PositionInterpolator { key [ 0.0, ... ] keyValue [ 0.0 0.0 0.0, ... ] } |
Typically route into a Transform node's set_translation input
A sample using position interpolators
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
DEF Particle1 Transform { children [ Shape { ... } ] } DEF Timer1 TimeSensor { cycleInterval 12.0 loop TRUE startTime 0.0 stopTime -1.0 } DEF Position1 PositionInterpolator { key [ 0.0, ... ] keyValue [ 0.0 0.0 0.0, ... ] } ROUTE Timer1.fraction_changed TO Position1.set_fraction ROUTE Position1.value_changed TO Particle1.set_translation |
Using other types of interpolators
Animate position | PositionInterpolator |
Animate rotation | OrientationInterpolator |
Animate scale | PositionInterpolator |
Animate color | ColorInterpolator |
Animate transparency | ScalarInterpolator |
Syntax: OrientationInterpolator
A OrientationInterpolator node describes an orientation path
- key - key fractional times
- keyValue - key rotations (axis and angle)
1 2 3 4 |
OrientationInterpolator { key [ 0.0, ... ] keyValue [ 0.0 1.0 0.0 0.0, ... ] } |
Typically route into a Transform node's set_rotation input
Syntax: ColorInterpolator
ColorInterpolator node describes a color path
- key - key fractional times
- keyValue - key colors (red, green, blue)
1 2 3 4 |
ColorInterpolator { key [ 0.0, ... ] keyValue [ 1.0 1.0 0.0, ... ] } |
Typically route into a Material node's set_diffuseColor or set_emissiveColor inputs
Syntax: ScalarInterpolator
ScalarInterpolator node describes a scalar path
- key - key fractional times
- keyValue - key scalars (used for anything)
1 2 3 4 |
ScalarInterpolator { key [ 0.0, ... ] keyValue [ 4.5, ... ] } |
Often route into a Material node's set_transparency input
Summary
The TimeSensor node's fields control:
- Timer start and stop times
- The cycle interval
- Whether the timer loops or not
The sensor outputs:
- true/false on isActive at start and stop
- absolute time on time while running
- fractional time on fraction_changed while running
Interpolators use key times and values and compute intermediate values
All interpolators have:
- a set_fraction input to set the fractional time
- a value_changed output to send new values
Some interpolators are:
- The PositionInterpolator node converts times to positions (or scales)
- The OrientationInterpolator node converts times to rotations
- The ColorInterpolator node converts times to colors
- The ScalarInterpolator node converts times to scalars (such as transparencies)