OpenGL VRML Shockwave 3D
Home Tutorials Books Applications Tools Docs Models Textures

Send me bugs and suggestions, please
VRML Script Tutorial
Full list

VRML Interactive Tutorial

Introduction
VRML File Structure
Drawing: Shape node
Geometry Nodes:
Box
Sphere
Cone
Cylinder
PointSet
IndexedLineSet
IndexedFaceSet
Extrusion
ElevationGrid
Example: Chessboard
Text
FontStyle
Appearance
Material
Textures
Image Texture
Movie Texture
Pixel Texture
Texture Coordinate
Texture Transform
Let there be Light
Directional Light
Point Light
Spot Light
Materials with Colored Lights
Hierarchical Node Structures
Group
Transform
Collision
Anchor
Billboard
Switch
Inlining Files
Defining and Instancing Nodes
Defining Levels of Detail
Events in VRML
Creating Paths between events: ROUTE
Generating Events based on Timers or User Actions
Timers
Touch Sensor
Visibility Sensor
Dragging Sensors
Plane Sensor
Sphere Sensor
Cylinder Sensor
Proximity Sensors
Example: Proximity sensor
Interpolators
Color
Coordinate
Normal
Orientation
Position
Scalar
Example
Let the Music Play
Sound
AudioClip
Bindable Nodes
Who Am I: NavigationInfo
Where Am I: ViewPoint
Adding Realism to the world
Background
Fog
Information about your world
WorldInfo
Definition for Auxiliary Nodes
Coordinate
Color
Normal

TouchSensor Node


The TouchSensor node is a way of providing interactivity with the user. This sensor is usually defined in a group and affects all shapes within that group. The sensor reacts when the user has the mouse over and when the user clicks a shape contained in the group.

This node has a single field which specifies if the sensor is enabled or not.

The isOver event is generated with the value TRUE by this node when the field is enabled and the mouse moves from a position where it is not over a shape contained within the group to a position where it is over a shape. A value FALSE is provided by this event when the sensor is enabled and the mouse stops being over a shape within the group.

If the shapes are not visible, i.e. they are hidden by other surfaces, then the touch sensor should not generate the isOver event.

When the mouse is over a shape within the same group as a TouchSensor, then the following events are generated when the mouse moves:
  • hitPoint_changed: Provides the 3D position on the surface of the shape in the TouchSensor's group coordinate system.
  • hitNormal_changed and hitTextCoord_changed: provide respectively the surface normal vector and the texture coordinates of the surface at the hitPoint.
  • When the user presses the mouse button the TouchSensor will also generate the event isActive with the value TRUE when the user clicks the mouse, if over a shape and enabled. When the user releases the mouse button an isActive event is generated with the value FALSE plus the event touchTime with the current time.

    Syntax:
    TouchSensor {
    enabled TRUE
    }


    When defining several TouchSensor inside nested groups, only the lowest sensor will generate events. For instance consider the following excerpt of code:

    Example:
    DEF ga Group {
         children [
    	DEF sa Shape ...
    	DEF ta TouchSensor {}
    	DEF gb Group {
    		children [
    			DEF sb Shape ...
    			DEF tb TouchSensor {}
    		]
    	}
         ]
    }
    


    When the user clicks over Shape sa, then TouchSensor ta will generate events, when the user clicks on Shape sb only the TouchSensor tb will generate events.

    Example of a TouchSensor to play a sound:

    The following source code describes a group with a Shape, a TouchSensor, and a Sound.

    Example:
    	
    #VRML V2.0 utf8
    
    Group {
          children [
    	DEF ts TouchSensor { }
    	Sound { 
    	     source DEF ac AudioClip { 
    	                      loop FALSE 
    	                      url "sfx.mid"
    	   } 
    	}
    	Shape { 
    	      appearance Appearance { 
    	          material Material {}
    	      } 
    	      geometry Sphere{} 
    	}
         ]
    }


    To play the sound when the user clicks the shape the following route should be used:
    ROUTE ts.touchTime TO ac.set_startTime

    The sound will play once because the loop field of the AudioClip is set to FALSE.

    Another possibility is to have the sound playing whenever the mouse is over the shape. This can be achieved by the following route:
    ROUTE ts.isOver TO ac.set_loop

    This will cause loop to become TRUE when the TouchSensor output an isOver event with the value TRUE. When the user is no longer over the shape the isOver event from the TouchSensor will output FALSE therefore stopping the sound as soon as the sound's duration/pitch or stopTime are achieved.



    Site designed and maintained by António Ramires Fernandes
    Your comments, suggestions and references to further material are welcome!

    Lighthouse 3D privacy statement