| Cover | TOC | Chap | Prev Chap | Prev Fig | Next Fig | Next Chap |
|
Figure 15.17
A wiggling snake whose spine is animated using a CoordinateInterpolator node. |
|
|
Click on the image to view the VRML scene. |
#VRML V2.0 utf8
# The VRML 2.0 Sourcebook
# Copyright (c) 1997
# Andrea L. Ames, David R. Nadeau, and John L. Moreland
Group {
children [
# Ground
Shape {
appearance Appearance {
material Material {
diffuseColor 0.6 0.6 0.0
}
}
geometry Box { size 20.0 0.01 20.0 }
},
# Snake shape
Transform {
translation 0.0 0.3 0.0
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.0 1.0 0.2
}
}
geometry DEF Snake Extrusion {
creaseAngle 1.57
crossSection [
# Circle
1.00 0.00, 0.92 -0.38,
0.71 -0.71, 0.38 -0.92,
0.00 -1.00, -0.38 -0.92,
-0.71 -0.71, -0.92 -0.38,
-1.00 -0.00, -0.92 0.38,
-0.71 0.71, -0.38 0.92,
0.00 1.00, 0.38 0.92,
0.71 0.71, 0.92 0.38,
1.00 0.00
]
spine [
# Sine wave
-4.100 0.0 0.000, -4.000 0.0 0.000,
-3.529 0.0 0.674, -3.059 0.0 0.996,
-2.588 0.0 0.798, -2.118 0.0 0.184,
-1.647 0.0 -0.526, -1.176 0.0 -0.962,
-0.706 0.0 -0.895, -0.235 0.0 -0.361,
0.235 0.0 0.361, 0.706 0.0 0.895,
1.176 0.0 0.962, 1.647 0.0 0.526,
2.118 0.0 -0.184, 2.588 0.0 -0.798,
3.059 0.0 -0.996, 3.529 0.0 -0.674,
4.000 0.0 0.000,
]
scale [
0.050 0.020, 0.200 0.100,
0.400 0.150, 0.300 0.300,
0.300 0.300, 0.300 0.300,
0.300 0.300, 0.300 0.300,
0.300 0.300, 0.300 0.300,
0.290 0.290, 0.290 0.290,
0.290 0.290, 0.280 0.280,
0.280 0.280, 0.250 0.250,
0.200 0.200, 0.100 0.100,
0.050 0.050,
]
}
}
},
# Animation clock
DEF Clock TimeSensor {
cycleInterval 4.0
loop TRUE
},
# Animation morph
DEF SnakeWiggle CoordinateInterpolator {
key [ 0.0, 0.25, 0.50, 0.75, 1.0 ]
keyValue [
# time 0.0 position
-4.100 0.0 0.000, -4.000 0.0 0.000,
-3.529 0.0 0.674, -3.059 0.0 0.996,
-2.588 0.0 0.798, -2.118 0.0 0.184,
-1.647 0.0 -0.526, -1.176 0.0 -0.962,
-0.706 0.0 -0.895, -0.235 0.0 -0.361,
0.235 0.0 0.361, 0.706 0.0 0.895,
1.176 0.0 0.962, 1.647 0.0 0.526,
2.118 0.0 -0.184, 2.588 0.0 -0.798,
3.059 0.0 -0.996, 3.529 0.0 -0.674,
4.000 0.0 0.000,
# time 0.25 position
-4.100 0.0 -1.000, -4.000 0.0 -1.000,
-3.529 0.0 -0.739, -3.059 0.0 -0.092,
-2.588 0.0 0.603, -2.118 0.0 0.983,
-1.647 0.0 0.850, -1.176 0.0 0.274,
-0.706 0.0 -0.446, -0.235 0.0 -0.932,
0.235 0.0 -0.932, 0.706 0.0 -0.446,
1.176 0.0 0.274, 1.647 0.0 0.850,
2.118 0.0 0.983, 2.588 0.0 0.603,
3.059 0.0 -0.092, 3.529 0.0 -0.739,
4.000 0.0 -1.000,
# time 0.50 position
-4.100 0.0 0.000, -4.000 0.0 0.000,
-3.529 0.0 -0.674, -3.059 0.0 -0.996,
-2.588 0.0 -0.798, -2.118 0.0 -0.184,
-1.647 0.0 0.526, -1.176 0.0 0.962,
-0.706 0.0 0.895, -0.235 0.0 0.361,
0.235 0.0 -0.361, 0.706 0.0 -0.895,
1.176 0.0 -0.962, 1.647 0.0 -0.526,
2.118 0.0 0.184, 2.588 0.0 0.798,
3.059 0.0 0.996, 3.529 0.0 0.674,
4.000 0.0 0.000,
# time 0.75 position
-4.100 0.0 1.000, -4.000 0.0 1.000,
-3.529 0.0 0.739, -3.059 0.0 0.092,
-2.588 0.0 -0.603, -2.118 0.0 -0.983,
-1.647 0.0 -0.850, -1.176 0.0 -0.274,
-0.706 0.0 0.446, -0.235 0.0 0.932,
0.235 0.0 0.932, 0.706 0.0 0.446,
1.176 0.0 -0.274, 1.647 0.0 -0.850,
2.118 0.0 -0.983, 2.588 0.0 -0.603,
3.059 0.0 0.092, 3.529 0.0 0.739,
4.000 0.0 1.000,
# time 1.0 position
-4.100 0.0 0.000, -4.000 0.0 0.000,
-3.529 0.0 0.674, -3.059 0.0 0.996,
-2.588 0.0 0.798, -2.118 0.0 0.184,
-1.647 0.0 -0.526, -1.176 0.0 -0.962,
-0.706 0.0 -0.895, -0.235 0.0 -0.361,
0.235 0.0 0.361, 0.706 0.0 0.895,
1.176 0.0 0.962, 1.647 0.0 0.526,
2.118 0.0 -0.184, 2.588 0.0 -0.798,
3.059 0.0 -0.996, 3.529 0.0 -0.674,
4.000 0.0 0.000,
]
}
]
}
ROUTE Clock.fraction_changed TO SnakeWiggle.set_fraction
ROUTE SnakeWiggle.value_changed TO Snake.set_spine