sliderLoop_1.wrl source
#VRML V2.0 utf8

Viewpoint {}
NavigationInfo {
type "EXAMINE"
}

# 赤円錐
DEF Cone-Tf Transform {
children [
Transform {
translation 3 0 0
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 0 0
}
}
geometry Cone {
height 0.5
bottomRadius 0.2
}
}
]
}
]
}

# スライダー
Group {
children [
DEF Slider-Tf Transform {
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 0 0.8 0
}
}
geometry Sphere {
radius 0.2
}
}
]
}
Shape {
appearance Appearance {
material Material {
diffuseColor 0.5 0 0
}
}
geometry Box {
size 2 0.1 0.1
}
}
DEF Slider-PlS PlaneSensor {
minPosition -1 0
maxPosition 1 0
}
]
}

ROUTE Slider-PlS.translation_changed TO Slider-Tf.translation

# タイムセンサー
DEF TiS TimeSensor {
loop TRUE
cycleInterval 5
}

# 回転アニメ
DEF OI OrientationInterpolator {
key [ 0.0 0.25 0.5 0.75 1.0 ]
keyValue [
0 0 1 0
0 0 1 1.5708
0 0 1 3.1416
0 0 1 4.7124
0 0 1 6.2832
]
}

# スピード調整スクリプト
DEF Sc Script {
eventIn SFVec3f adjustSpeed
eventIn SFFloat set_fraction
eventOut SFFloat fraction_out
field SFFloat speed 0
field SFFloat oldF 0
url "javascript:

function adjustSpeed (vec) {

speed = vec.x;

}

function set_fraction (f) {

var df = f - oldF;
if ( df < 0 ) df++;
oldF = f;

fraction_out += df * speed;
if ( fraction_out > 1 ) fraction_out--;
else if ( fraction_out < 0 ) fraction_out++;

}

"
}

ROUTE Slider-PlS.translation_changed TO Sc.adjustSpeed

ROUTE TiS.fraction_changed TO Sc.set_fraction
ROUTE Sc.fraction_out TO OI.set_fraction
ROUTE OI.value_changed TO Cone-Tf.rotation