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

ProximitySensor Example


Many people have asked how to have a shape, or group of shapes, keeping its relative position to the user when the user is moving. This example shows you how to do that.

ProximitySensor nodes can be used to keep track of the users position and orientation. Two eventOuts are provided for this effect:
  • position_changed
  • orientation_changed
  • Therefore a ProximitySensor node generates events whenever the user changes its position or orientation. These events can then be routed to a Transform node where the shapes are placed.

    The only problem with this method is that a ProximitySensor requires the definition of the size of a virtual box. If the user is outside the virtual box then the ProximitySensor will NOT generate events. To avoid this problem one can always define the size of the ProximitySensor to be larger than the world itself.

    The following code should do the trick:



    Example:
    #VRML V2.0 utf8

    Group {
      children [
        DEF ps ProximitySensor {
          center 0 0 0

          size 1000 1000 1000
        }

        DEF tr Transform {
          children
            Transform {
              translation 0 0 -5

              children

              Shape {geometry Sphere{}}
            }
        }
      ]
    }

    ROUTE ps.position_changed TO tr.set_translation

    ROUTE ps.orientation_changed TO tr.set_rotation


    Note that the sphere which is 'locked' to the user position is inside a Transform node which contains a translation. This translation defines the relative position to the user, in this case the center of the sphere will be 5 units away from the user.

    Press the button below to see the VRML. Note that there is also a box in the world. The box should remain in its position while you move, only the sphere will follow your movement.



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

    Lighthouse 3D privacy statement