Event Routing - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Event Routing

Description:

For example, car racing game needs cars and tracks at least. ... You build at least a car and tracks that you want to use for racing game. ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 27
Provided by: Ilmi7
Category:
Tags: event | routing

less

Transcript and Presenter's Notes

Title: Event Routing


1
Event Routing
  • Some VRML nodes generate events in response to
    environmental changes or user interaction. Event
    routing gives authors a mechanism, separate from
    the scene graph hierarchy, through which these
    events can be propagated to effect changes in
    other nodes.
  • Once generated, events are sent to their routed
    destinations in time order and processed by the
    receiving node. This processing can change the
    state of the node, generate additional events, or
    change the structure of the scene graph.
  • Script nodes allow arbitrary, author-defined
    event processing. An event received by a Script
    node causes the execution of a script function
    which has the ability to send events through the
    normal event-routing mechanism.
  • The ideal event model processes all events
    instantaneously in the order that they are
    generated.
  • A timestamp, the time at which an event is
    delivered to a node, serves two purposes. First,
    it is a conceptual device used to describe the
    chronological flow of the event mechanism. It
    ensures that deterministic results can be
    achieved by real-world implementations which must
    address processing delays and asynchronous
    interaction with external devices. Second,
    timestamps are also made available to Script
    nodes to allow events to be processed based on
    the order of user actions or the elapsed time
    between events.

2
Events Routes (Interacting with the Scene)
  • A class of nodes, called sensors reacts to user
    events in some prescribed ways.
  • TouchSensor, ProximitySensor
  • a sensor is wired to a Script node that runs a
    program

TouchSensor Node
Sound Node
Rout
eventOut
eventIn
3
VRML V2.0 utf8 Event routing Group
children Shape appearance Appearance
material Material geometry Cone
DEF TS TouchSensor define
the sensor "TS" DEF DL DirectionalLight
define the light "DL" color 1 0 0 on FALSE
ROUTE TS.isOver TO DL.set_on
4
Animation and User Interaction
  • The translation field of the Transformation node
    is an exposedfield
  • set_incoming event
  • set_translation
  • _changedoutgoing event
  • translation_changed
  • ROUTE Xform1.translation_changed TO
    Xform2.set_translation
  • ROUTE Xform1.translation TO Xform2.translation

5
ROUTE
  • Routing should be done in same type (field)
  • a set_ or _changed event is the same type as the
    exposed field its associated with
  • use DEF USE

Group children DEF LIGHT_CONTROL
TouchSensor Inline url
lightswitch.wrl DEF Light PointLight
location -6 4 2 on FALSE Inline url
table.wrl ROUTE LIGHT_CONTROL.isActive TO
Light.on
6
The Animation Event Path
Trigger
Logic
Timer
Engine
Target
  • Trigger generates an event. Usually sensors
  • Logic processing on the event. Usually script
    nodes
  • Timer startTime of TimeSensor node, then
    generates time events
  • Engine route time events to nodes that animate.
    Usually interpolator node

7
The Animation Event Path
Trigger
Logic
Timer
Engine
Target
  • Target The browser sends the Engines output
    to a relevant node in the scene hierarchy, whoses
    field values changes accordingly

Trigger
Target
8
Pointing-device Sensors
  • The geometry corresponding to a sensor must be a
    sibling of the sensor
  • The objects controlled by the sensor can be
    anywhere
  • TouchSensor
  • isOver
  • isActive (on click)
  • isActive hitPoint_changed (on drop)
  • touchTime (press remaining on same object)

9
Using a TouchSensor node
Group children DEF PUSH TouchSensor
Inline url doorbell.geom.wrl Soun
d source DEF BUSS AudioClip url
doorbell.wav maxFront 50 minFront 5 ROUTE
PUSH.touchTime TO BUZZ.startTime
  • Trigger sends a time event to the Target (the
    audio clip)

10
Drag Sensors
  • Interpretation of 2D dragging
  • CylinderSensor rotating around local y axis
  • spinning a globe
  • PlaneSensor translating in the local xy plane

VRML V2.0 utf8 GROUP children DEF
SKULL_DRAG PlaneSensor minPosition 0
0 maxPosition 5 0 DEF SKULL Transform
translation 0 0 0 children Inline url
skull.wrl ROUTE SKULL_DRAG.translation_ch
anged TO SKULL.translation
11
ProximitySensor
  • Generates events whenever the user enters or
    leaves a defined box-shaped region
  • Sizes for box shapes can be difficult to estimate
    --gt so, placing a Box node of the same size at
    the same location will give a good idea of the
    exact region

12
Timers
Trigger
Logic
Timer
Engine
Target
  • Time Sensor is triggered/initiated by setting
    startTime
  • cycleInterval sets the interval of animation
  • fraction_changed is used to calculate time elapse
    among the given interval

Viewpoint position 0 0 15 DEF
DETECTOR ProximitySensor size 25 25 25 DEF
TIMER TimeSensor cycleInterval 2 DEF
LIGHT PointLight intensity 0 location 3
3 3 Inline url chacmool.wrl objects to
be lit ROUTE DETECTOR.enterTime TO TIMER.startTime
ROUTE TIME.fraction_changed TO LIGHT.intensity
13
Engines
Trigger
Logic
Timer
Engine
Target
  • Convert the output of a time sensor into a change
    in some other type of value
  • interpolator keyframe
  • PositionInterpolator
  • OrientationInterpolator
  • ColorInterpolator
  • ScalarInterpolator
  • CoordinateInterpolator

DEF Spark_mover PositionInterpolator key 0,1
keyvalue 0 0 0, 0.8, 5,0 ROUTE TIME.fraction_c
hanged TO Spark_mover.set_fraction ROUTE
Spark_mover.value_changed TO Spark.translation
14
Example (bike rider - bike.wrl)
VRML V2.0 utf8 DEF BIKE Transform
translation 0 0 0 children DEF FW Transform
translation -2 -4 0 children Inline
url "wheel2.wrl" DEF BW Transform
translation 2 -4 0 children Inline url
"wheel2.wrl" DEF FR Transform
translation 0.4 -3.5 2.1 children Inline
url "frame.wrl" DEF RIDER Transform
translation 0 0 0 children Inline url
"rider2.wrl" DEF T TimeSensor loop
TRUE enabled TRUE cycleInterval 5 stopTime
-1 DEF P PositionInterpolator key 0, 0.25,
0.5, 0.75, 1 keyValue -5 0 0, -1 0 0, 0 3 0,
2 0 0, 5 0 0 ROUTE T.fraction_changed TO
P.set_fraction ROUTE P.value_changed TO
BIKE.translation ROUTE BIKE.translation TO
RIDER.translation
15
More examples
  • rider.wrl
  • frame.wrl
  • wheel.wrl

16
Scripting (Script node)
  • Bridge between VRML programming languages.
  • Acting as the Engine stage to control animation
  • Processing input to act as the Logic stage
  • Interacting with the browser in certain ways
  • binding the browser to a Viewpoint node to
    animate the viewer along a path
  • Manipulating the scene hierarchy
  • communicating with a server or another VRML world
    across a network

17
What to know about Scripting
  • How the script node acts as a bridge between VRML
    JAVA
  • Basic JAVA classes that interact with and
    manipulate VRML
  • How to compile and run java program

18
The script node act as a gateway to the script
itself
Script node
Scene
url
A node
eventin
translation
eventOut
rotation
another node
size
translation
color
rotation
JAVA code
size
color
19
Example (ChangeColor.wrl)
VRML V2.0 utf8 Transform children
DEF TS TouchSensor TouchSensor Shape
appearance Appearance material
DEF SphereColor Material diffuseColor 1 0 0
red geometry Sphere
DEF ColorScript Script url
"ChangeColor.class" eventIn SFBool clicked
eventOut SFColor newColor field SFBool on
FALSE Routing ROUTE TS.isActive TO
ColorScript.clicked ROUTE ColorScript.newColor TO
SphereColor.set_diffuseColor
20
Example (ChangeColor.java)
import vrml. import vrml.field. import
vrml.node. public class ChangeColor extends
Script private SFBool on // status of
on-off float red 1, 0, 0 //
RGB(Red) float blue 0, 0, 1 //
RGB(Blue) private SFColor newColor public
void initialize() newColor (SFColor)
getEventOut("newColor") on (SFBool)
getField("on") public void
processEvent(Event e) ConstSFBool v
(ConstSFBool)e.getValue() if(v.getValue())
if (on.getValue())
newColor.setValue(red) // set red to
'newColor' else
newColor.setValue(blue) // set blue to
'newColor' on.setValue(!on.getValue()
) // !on.getValue()
21
Example II (mover.wrl)
VRML V2.0 utf8 DEF MOVER Transform
translation 0 0 10 children DEF TS
TouchSensor TouchSensor Shape
appearance Appearance material DEF
SphereColor Material diffuseColor 1 0 0 red
geometry Sphere DEF
MoveIt Script url "MoveIt.class" eventIn
SFBool clicked field SFNode node USE MOVER
field SFBool on FALSE Routing ROUTE
TS.isActive TO MoveIt.clicked
22
Example II (moveit.java)
import vrml. import vrml.field. import
vrml.node. public class MoveIt extends Script
private SFBool on // status of on-off
float red 1, 0, 0 // RGB(Red)
float blue 0, 0, 1 // RGB(Blue)
private SFNode theNode private SFVec3f
position public void initialize()
theNode (SFNode) getField("node") public
void processEvent(Event e) ConstSFBool v
(ConstSFBool)e.getValue() Node node
if(v.getValue()) node (Node)(theNode.getV
alue()) position (SFVec3f)(node.getExp
osedField("translation"))
position.setValue((position.getX() 5), 0, 0)

23
JAVA The script node
  • getSize()
  • getValue()
  • get1Value(int index)
  • setValue(value)
  • set1Value(int index, value)
  • addValue(value)
  • insertValue(int index, value)
  • deleteValue(int index)
  • clearValue()

24
Compiling a JAVA script
  • Download vrml package (vrml.)
  • put it in a directory where your classpath can
    reach

25
Project 1
  • Your first project is (1) to make you feel
    comfortable with VRML world. Build your (static)
    VRML world. You may import 3D models from other
    tool, but you should have full control over the
    model to make use of them in your project 2. This
    project is also (2) to make your base environment
    for project 2 (multi user game). Therefore, think
    carefully in advance, not to waste your time and
    do it again for project 2. Your project 2 should
    have some component that multi users interact in
    3D world. For example, car racing game needs cars
    and tracks at least. Shooting game needs 3D
    avatars and shooting environment. You build at
    least a car and tracks that you want to use for
    racing game. For project 1, your world can be
    static, no need to animate, respond to user
    input, nor events handling. Build your static
    world in .wrl file and test in your browser. For
    project 2, you will have to work towards
    installing (or implementing) server, EAI
    scripting of your VRML components using java
    (this also requires game algorithm collision,
    running speed, etc).

26
  • Grading Grading of project I will be based on
    your world and documentation. Your world needs
    to have textured and navigatable environment,
    with multiple light sources. If your world looks
    reasonable enough for project 2, then you will
    get most of credit. For documentation, draw scene
    graph at least. Also use this documentation as a
    proposal for your project 2 since you will have
    to spend some time to design project 2 anyway.
  • Submission Hard copy of documentation that
    obviously includes URL of your world by 400 pm
    of 10/8/2001.
Write a Comment
User Comments (0)
About PowerShow.com