Sensing the viewer
prox2.wrl

	

#VRML V2.0 utf8
#
#  Proximity pillars
#  prox2.wrl
#        by David R. Nadeau
#
#  This example illustrates the use of proximity sensors to sense
#  when the user gets close, and trigger animations or sounds.
#

WorldInfo {
    title "Proximity pillars"
    info [ "Copyright (c) 1997, David R. Nadeau" ]
}

Viewpoint {
    position 7.5 1.7 7.5
    orientation 0.0 1.0 0.0 0.785
    description "Entry view"
}

NavigationInfo {
    speed 3.0
    headlight FALSE
}

Background {
    skyColor [
        0.0 0.0 0.0
        0.0 0.0 0.0
        1.0 1.0 1.0
    ]
    skyAngle [
        1.57,
        1.87,
    ]
}

Fog {
    color 0.1 0.1 0.1
    visibilityRange 18.0
    fogType "LINEAR"
}

DirectionalLight {
    direction -1.0 -0.5 -0.5
}


#
#  Grid plane
#
Shape {
    appearance Appearance {
        # no material - emissive
        texture ImageTexture { url "grill.png" }
        textureTransform TextureTransform {
            scale 16.0 16.0
        }
    }
    geometry IndexedFaceSet {
        coord Coordinate {
            point [
                -16.0 0.0  16.0,
                 16.0 0.0  16.0,
                 16.0 0.0 -16.0,
                -16.0 0.0 -16.0,
            ]
        }
        coordIndex [ 0, 1, 2, 3 ]
        texCoord TextureCoordinate {
            point [
                0.0 0.0,
                1.0 0.0,
                1.0 1.0,
                0.0 1.0,
            ]
        }
        texCoordIndex [ 0, 1, 2, 3 ]
    }
}

#
#  Collision sound
#
Sound {
    source DEF Bonk AudioClip {
        url "dropbrk.wav"
        startTime 0.0
        stopTime 1.0
        loop FALSE
    }
    minFront 100.0
    maxFront 100.0
    minBack  100.0
    maxBack  100.0
}


#
#  Emerging bars
#
DEF HitBar1 Collision {
    children [
        Transform {
            translation -2.0 0.0 2.0
            children [
                DEF NearBar1 ProximitySensor {
                    size 14.0 14.0 14.0
                }
                Shape {
                    appearance Appearance {
                        material DEF MaterialBar1 Material {
                            diffuseColor 0.0 0.3 1.0
                            transparency 1.0
                        }
                    }
                    geometry IndexedFaceSet {
                        coord Coordinate {
                            point [
                                -0.5 0.0  0.5,
                                 0.5 0.0  0.5,
                                 0.5 0.0 -0.5,
                                -0.5 0.0 -0.5,
                                -0.5 4.0  0.5,
                                 0.5 4.0  0.5,
                                 0.5 4.0 -0.5,
                                -0.5 4.0 -0.5,
                            ]
                        }
                        coordIndex [
                            0, 1, 5, 4, -1,
                            1, 2, 6, 5, -1,
                            2, 3, 7, 6, -1,
                            3, 0, 4, 7, -1,
                            4, 5, 6, 7, -1,
                        ]
                    }
                }
            ]
        }
    ]
}
DEF ClockOnBar1 TimeSensor {
    cycleInterval 1.0
    startTime 0.0
    stopTime 1.0
    loop FALSE
}
DEF ClockOffBar1 TimeSensor {
    cycleInterval 1.0
    startTime 0.0
    stopTime 1.0
    loop FALSE
}
DEF OnBar1 ScalarInterpolator {
    key [ 0.0, 1.0 ]
    keyValue [ 1.0, 0.0 ]
}
DEF OffBar1 ScalarInterpolator {
    key [ 0.0, 1.0 ]
    keyValue [ 0.0, 1.0 ]
}
ROUTE NearBar1.enterTime TO ClockOnBar1.set_startTime
ROUTE NearBar1.exitTime  TO ClockOffBar1.set_startTime
ROUTE ClockOnBar1.fraction_changed TO OnBar1.set_fraction
ROUTE ClockOffBar1.fraction_changed TO OffBar1.set_fraction
ROUTE OnBar1.value_changed TO MaterialBar1.set_transparency
ROUTE OffBar1.value_changed TO MaterialBar1.set_transparency
ROUTE HitBar1.collideTime TO Bonk.set_startTime


DEF HitBar2 Collision {
    children [
        Transform {
            translation 4.0 0.0 0.0
            children [
                DEF NearBar2 ProximitySensor {
                    size 14.0 14.0 14.0
                }
                Shape {
                    appearance Appearance {
                        material DEF MaterialBar2 Material {
                            diffuseColor 0.0 1.0 0.0
                            transparency 1.0
                        }
                    }
                    geometry IndexedFaceSet {
                        coord Coordinate {
                            point [
                                -0.5 0.0  0.5,
                                 0.5 0.0  0.5,
                                 0.5 0.0 -0.5,
                                -0.5 0.0 -0.5,
                                -0.5 2.0  0.5,
                                 0.5 2.0  0.5,
                                 0.5 2.0 -0.5,
                                -0.5 2.0 -0.5,
                            ]
                        }
                        coordIndex [
                            0, 1, 5, 4, -1,
                            1, 2, 6, 5, -1,
                            2, 3, 7, 6, -1,
                            3, 0, 4, 7, -1,
                            4, 5, 6, 7, -1,
                        ]
                    }
                }
            ]
        }
    ]
}
DEF ClockOnBar2 TimeSensor {
    cycleInterval 1.0
    startTime 0.0
    stopTime 1.0
    loop FALSE
}
DEF ClockOffBar2 TimeSensor {
    cycleInterval 1.0
    startTime 0.0
    stopTime 1.0
    loop FALSE
}
DEF OnBar2 ScalarInterpolator {
    key [ 0.0, 1.0 ]
    keyValue [ 1.0, 0.0 ]
}
DEF OffBar2 ScalarInterpolator {
    key [ 0.0, 1.0 ]
    keyValue [ 0.0, 1.0 ]
}
ROUTE NearBar2.enterTime TO ClockOnBar2.set_startTime
ROUTE NearBar2.exitTime  TO ClockOffBar2.set_startTime
ROUTE ClockOnBar2.fraction_changed TO OnBar2.set_fraction
ROUTE ClockOffBar2.fraction_changed TO OffBar2.set_fraction
ROUTE OnBar2.value_changed TO MaterialBar2.set_transparency
ROUTE OffBar2.value_changed TO MaterialBar2.set_transparency
ROUTE HitBar2.collideTime TO Bonk.set_startTime



DEF HitBar3 Collision {
    children [
        Transform {
            translation -4.0 0.0 -4.0
            children [
                DEF NearBar3 ProximitySensor {
                    size 14.0 14.0 14.0
                }
                Shape {
                    appearance Appearance {
                        material DEF MaterialBar3 Material {
                            diffuseColor 1.0 1.0 0.0
                            transparency 1.0
                        }
                    }
                    geometry IndexedFaceSet {
                        coord Coordinate {
                            point [
                                -0.5 0.0  0.5,
                                 0.5 0.0  0.5,
                                 0.5 0.0 -0.5,
                                -0.5 0.0 -0.5,
                                -0.5 4.0  0.5,
                                 0.5 4.0  0.5,
                                 0.5 4.0 -0.5,
                                -0.5 4.0 -0.5,
                            ]
                        }
                        coordIndex [
                            0, 1, 5, 4, -1,
                            1, 2, 6, 5, -1,
                            2, 3, 7, 6, -1,
                            3, 0, 4, 7, -1,
                            4, 5, 6, 7, -1,
                        ]
                    }
                }
            ]
        }
    ]
}
DEF ClockOnBar3 TimeSensor {
    cycleInterval 1.0
    startTime 0.0
    stopTime 1.0
    loop FALSE
}
DEF ClockOffBar3 TimeSensor {
    cycleInterval 1.0
    startTime 0.0
    stopTime 1.0
    loop FALSE
}
DEF OnBar3 ScalarInterpolator {
    key [ 0.0, 1.0 ]
    keyValue [ 1.0, 0.0 ]
}
DEF OffBar3 ScalarInterpolator {
    key [ 0.0, 1.0 ]
    keyValue [ 0.0, 1.0 ]
}
ROUTE NearBar3.enterTime TO ClockOnBar3.set_startTime
ROUTE NearBar3.exitTime  TO ClockOffBar3.set_startTime
ROUTE ClockOnBar3.fraction_changed TO OnBar3.set_fraction
ROUTE ClockOffBar3.fraction_changed TO OffBar3.set_fraction
ROUTE OnBar3.value_changed TO MaterialBar3.set_transparency
ROUTE OffBar3.value_changed TO MaterialBar3.set_transparency
ROUTE HitBar3.collideTime TO Bonk.set_startTime



DEF HitBar4 Collision {
    children [
        Transform {
            translation 2.0 0.0 -2.0
            children [
                DEF NearBar4 ProximitySensor {
                    size 14.0 14.0 14.0
                }
                Shape {
                    appearance Appearance {
                        material DEF MaterialBar4 Material {
                            diffuseColor 1.0 0.0 0.0
                            transparency 1.0
                        }
                    }
                    geometry IndexedFaceSet {
                        coord Coordinate {
                            point [
                                -0.5 0.0  0.5,
                                 0.5 0.0  0.5,
                                 0.5 0.0 -0.5,
                                -0.5 0.0 -0.5,
                                -0.5 3.0  0.5,
                                 0.5 3.0  0.5,
                                 0.5 3.0 -0.5,
                                -0.5 3.0 -0.5,
                            ]
                        }
                        coordIndex [
                            0, 1, 5, 4, -1,
                            1, 2, 6, 5, -1,
                            2, 3, 7, 6, -1,
                            3, 0, 4, 7, -1,
                            4, 5, 6, 7, -1,
                        ]
                    }
                }
            ]
        }
    ]
}
DEF ClockOnBar4 TimeSensor {
    cycleInterval 1.0
    startTime 0.0
    stopTime 1.0
    loop FALSE
}
DEF ClockOffBar4 TimeSensor {
    cycleInterval 1.0
    startTime 0.0
    stopTime 1.0
    loop FALSE
}
DEF OnBar4 ScalarInterpolator {
    key [ 0.0, 1.0 ]
    keyValue [ 1.0, 0.0 ]
}
DEF OffBar4 ScalarInterpolator {
    key [ 0.0, 1.0 ]
    keyValue [ 0.0, 1.0 ]
}
ROUTE NearBar4.enterTime TO ClockOnBar4.set_startTime
ROUTE NearBar4.exitTime  TO ClockOffBar4.set_startTime
ROUTE ClockOnBar4.fraction_changed TO OnBar4.set_fraction
ROUTE ClockOffBar4.fraction_changed TO OffBar4.set_fraction
ROUTE OnBar4.value_changed TO MaterialBar4.set_transparency
ROUTE OffBar4.value_changed TO MaterialBar4.set_transparency
ROUTE HitBar4.collideTime TO Bonk.set_startTime