media @ VU
x-ball-8.vr
x-ball-8.vr
(wrl
)
[ flux /
bitmanagement /
cortona /
octaga
]
bouncing ball (8)
object
PROTO object [
exposedField SFFloat radius 1
exposedField SFColor color 1 0 0
exposedField SFVec3f translation 0 0 0
exposedField SFVec3f scale 1 1 1
exposedField SFRotation rotation 0 0 0 0
]{
Transform {
translation IS translation
scale IS scale
rotation IS rotation
children [
Shape {
geometry Box { size 1 1 1 }
appearance Appearance {
material Material {
diffuseColor IS color
}
}
}
] }
}
bounce
PROTO bounce [
exposedField SFFloat accel 0.1
exposedField SFNode object NULL
exposedField SFVec3f translation 0 0 0
exposedField SFVec3f scale 1 1 1
exposedField SFRotation rotation 0 0 0 0
]{
DEF GROUP Transform {
translation IS translation
scale IS scale
rotation IS rotation
children [
Transform {
translation 0 -10 0
children [
Shape {
geometry Box { size 5 0.2 5 }
appearance Appearance {
material DEF GROUND Material {
diffuseColor 1 0 0
}
}
}
]}
]}
sensor
DEF TIME TimeSensor { loop TRUE cycleInterval 5 } #<l++>
script
DEF SCRIPT Script {
directOutput TRUE
field SFFloat accel IS accel
field SFTime tick 0
field SFNode group USE GROUP
field SFNode object IS object
field SFNode ground USE GROUND
field SFFloat position 0
field SFFloat color 0.5
field SFFloat rotation 0
field SFInt32 sign 1
field SFFloat speed 1
eventIn SFFloat set_fraction
url "javascript:
initialize
function initialize() {
group.addChildren = new MFNode(object);
}
fraction
function set_fraction(value) {
if (tick == 0) {
tick = value;
position = 0;
color = 0.5;
}
while (tick < value) {
update(value);
tick = tick + 0.01;
}
tick = value;
}
update
function update(value) {
check(value);
position += 0.01 * sign * speed;
rotation += 0.1;
color = value;
speed = speed * ( 1 - sign * accel);
object.translation.y = position;
object.color = new SFColor(1,color,color);
object.rotation = new SFRotation(0.5,0.5,0,rotation);
}
check
function check(value) {
if (speed < 0.1 ) sign = -1;
if ((position - object.radius) < -10 ) {
effect(value);
sign = 1;
}
}
effect
function effect(value) {
ground.diffuseColor = new SFColor(1,color,color);
}
"
}#<l++>
routing
ROUTE TIME.fraction_changed TO SCRIPT.set_fraction
}
element
PROTO element [
exposedField SFFloat radius 1
exposedField SFColor color 1 0 0
exposedField SFFloat speed 0.1
exposedField SFFloat accel 0.1
exposedField SFVec3f translation 0 0 0
exposedField SFVec3f scale 0.2 0.2 0.2
exposedField SFRotation rotation 0 0 0 0
]{
DEF GROUP Transform {
translation IS translation
scale IS scale
rotation IS rotation
children [
Shape {
geometry Sphere { radius 10 }
appearance Appearance {
material DEF MATERIAL Material {
diffuseColor IS color
transparency 0.9
}
}
}
Switch {
whichChoice -1
choice [
DEF OBJECT object { }
] }
bounce { translation 0 0 0 scale 0.5 0.5 0.5 accel IS speed object USE OBJECT }
]}
}
system
PROTO system [
exposedField SFVec3f translation 0 0 0
exposedField SFVec3f scale 1 1 1
exposedField SFRotation rotation 0 0 0 0
]{
DEF GROUP Transform {
translation IS translation
scale IS scale
rotation IS rotation
children [
Switch {
whichChoice -1
choice [
DEF OBJECT1 element { accel 0.1 speed 0.5 }
DEF OBJECT2 element { accel 0.2 speed 0.6 }
DEF OBJECT3 element { accel 0.3 speed 0.7 }
DEF OBJECT4 element { accel 0.4 speed 0.8 }
DEF OBJECT5 element { accel 0.5 speed 0.9 }
] }
bounce {translation -12 0 0 accel 0.1 object USE OBJECT1 }
bounce {translation 0 0 0 accel 0.2 object USE OBJECT2 }
bounce {translation 12 0 0 accel 0.3 object USE OBJECT3 }
bounce {translation -6 0 -10 accel 0.4 object USE OBJECT4 }
bounce {translation 6 0 -10 accel 0.5 object USE OBJECT5 }
]}
}
instance(s)
system { translation -8 0 0 scale 0.5 0.5 0.5 }
system { translation 8 0 0 scale 0.5 0.5 0.5 }
system { translation 0 0 10 scale 0.5 0.5 0.5 }
environment
DirectionalLight { direction 0 -1 -1 }
Viewpoint { position 0 0 30 }
Background { skyColor 0.2 0.2 0.4 }
(C) A. Eliëns
21/5/2007
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.