compass_0.wrl source
#VRML V2.0 utf8

Viewpoint {
description "initial"
position 0 1.6 10
}

NavigationInfo {
type "WALK"
headlight FALSE
speed 3
}

DirectionalLight {
direction -1 -1 -1
}

# 背景
Background {
skyColor [ 0 0.3 1, 0.7 1 1 ]
skyAngle 1.57
}


# 地面
Transform {
translation 0 -0.05 0
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 0 0.8 0
}
texture ImageTexture {
url "green.jpg"
}
textureTransform TextureTransform {
scale 50 50
}
}
geometry Box {
size 50 0.1 50
}
}
]
}

# コンソール
DEF Console-Tf Transform {
children [
Transform {
translation 0 -1 -3
children [
Shape {
appearance Appearance {
material Material {
transparency 0.5
}
}
geometry Cylinder {
radius 0.5
height 0.2
}
}
Shape {
appearance Appearance {
material Material {
diffuseColor 0 1 0
}
}
geometry Cylinder {
radius 0.02
height 0.2
}
}
# コンパスの針
DEF Compass-Tf Transform {
children [
Transform {
rotation 1 0 0 -1.5708
translation 0 0 -0.35
children [
Shape {
appearance DEF Compass-Ap Appearance {
material Material {
diffuseColor 1 0.5 0
}
}
geometry Cone {
bottomRadius 0.1
height 0.2
}
}
]
}
Transform {
rotation 1 0 0 -1.5708
children [
Shape {
appearance USE Compass-Ap
geometry Cylinder {
radius 0.02
height 0.8
}
}
]
}
]
}
]
}
]
}

DEF PrS ProximitySensor {
size 1000 1000 1000
}

ROUTE PrS.position_changed TO Console-Tf.set_translation
ROUTE PrS.orientation_changed TO Console-Tf.set_rotation


# スクリプト
DEF Sc Script {
eventIn SFRotation set_orientation
eventOut SFRotation compassRotation
url "javascript:
function set_orientation (viewerOrientation) {

compassRotation = viewerOrientation.inverse();

}
"
}

ROUTE PrS.orientation_changed TO Sc.set_orientation
ROUTE Sc.compassRotation TO Compass-Tf.rotation