media @ VU
vrml-math-SplIntDemo.vr
vrml-math-SplIntDemo.vr
(wrl
)
[ flux /
bitmanagement /
cortona /
octaga
]
NavigationInfo{ type "EXAMINE" }
PROTO SplinePositionInterpolator[
eventIn SFFloat set_fraction
eventOut SFVec3f value_changed
field SFInt32 num 3
field SFBool loop TRUE
field MFFloat key []
field MFVec3f keyValue [] ]{
DEF Root Transform{ children[
Shape{ appearance Appearance{ material Material{ emissiveColor 1 1 1 } }
geometry DEF spline IndexedLineSet{ coord DEF spCoord Coordinate{} } }
]}
DEF PosInt PositionInterpolator{
set_fraction IS set_fraction
value_changed IS value_changed
}
Script{
field SFInt32 num IS num
field SFBool loop IS loop
field MFFloat key IS key
field MFVec3f val IS keyValue
field SFNode Root USE Root
field SFNode spline USE spline
field SFNode spCoord USE spCoord
field SFNode PosInt USE PosInt
directOutput TRUE
url ["javascript:
function initialize() {
n = key.length;
str = 'PROTO M[ field SFVec3f trans 0 0 0]{'+
'Transform{ translation IS trans children['+
'Shape{ appearance Appearance{ material Material{ diffuseColor 1 1 0}}'+
'geometry Sphere{ radius .1 }}]}}';
for (i= 0; i< n; i++) str += ' M{ trans '+val[i]+' }';
Root.addChildren = Browser.createVrmlFromString(str);
if( loop ){ del0 = val[1].subtract(val[n-2]).divide(4); val[n] = val[1];}
else{ del0 = val[1].subtract(val[0]).divide(4); val[n] = val[n-1];}
p = new MFVec3f(); p.length = (n-1)*num+1;
c = new MFInt32(); c.length = (n-1)*num+1;
k = new MFFloat(); k.length = (n-1)*num+1;
st = 1/num; t = 0; kt = 0;
for (j= 0; j< n-1; j++){
del1 = val[j+2].subtract(val[j]).divide(4);
delK = (key[j+1]-key[j])/num;
for (i= 0; i< num; i++){
u = i*st; u1 = 1-u; u12 = u1*u1; u2 = u*u;
b0 = u1*u12; b1 = 3*u*u12; b2 = 3*u2*u1; b3 = u*u2;
p[t]=val[j].multiply(b0).add( val[j].add(del0).multiply(b1) )
.add( val[j+1].subtract(del1).multiply(b2) ).add(val[j+1].multiply(b3));
k[t] = kt; kt += delK;
c[t] = t++;}
del0 = del1;}
p[t] = val[n-1]; c[t] = t; k[t] = 1;
spCoord.set_point = p;
spline.set_coordIndex = c;
PosInt.set_keyValue = p;
PosInt.set_key = k;
}
"]}
}
DEF splInt SplinePositionInterpolator{ #loop FALSE
key [0 .25 .5 .75 1] keyValue [0 -2 0,2 0 0,0 2 0,-2 0 0,0 -2 0]
}
DEF Model Transform{ children[ Shape{
appearance Appearance{ material Material{ diffuseColor 1 1 1 } }
geometry Box{size .5 .1 .5} }
]}
DEF TS TimeSensor{ cycleInterval 10 loop TRUE}
ROUTE TS.fraction_changed TO splInt.set_fraction
ROUTE splInt.value_changed TO Model.set_translation
(C) A. Eliëns
2/9/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.