media @ VU
vrml-math-FlyInt.vr
vrml-math-FlyInt.vr
(wrl
)
[ flux /
bitmanagement /
cortona /
octaga
]
NavigationInfo{ type "EXAMINE" }
Viewpoint {position 0 2 8 description "Start"}
PROTO FlyInterpolator[
eventIn SFFloat set_fraction
eventOut SFVec3f position_changed
eventOut SFRotation orientation_changed
field SFInt32 num 3
field SFFloat alpha 4
field SFBool loop TRUE
field MFFloat key []
field MFFloat phi []
field MFVec3f keyValue [] ]{
DEF PosInt PositionInterpolator{
set_fraction IS set_fraction
value_changed IS position_changed
}
DEF OrInt OrientationInterpolator{
set_fraction IS set_fraction
value_changed IS orientation_changed
}
Script{
field SFInt32 num IS num
field SFBool loop IS loop
field MFFloat key IS key
field MFVec3f val IS keyValue
field SFFloat alpha IS alpha
field MFFloat phi IS phi
field SFNode PosInt USE PosInt
field SFNode OrInt USE OrInt
directOutput TRUE
url ["javascript:
function initialize() {
n = key.length;
p = new MFVec3f(); p.length = (n-1)*num+1;
k = new MFFloat(); k.length = (n-1)*num+1;
ind = new MFInt32(); ind.length = (n-1)*num+1;
r = new MFFloat(); r.length = (n-1)*num+1;
if( loop ){ del0 = val[1].subtract(val[n-2]).divide(alpha); val[n] = val[1];}
else{ del0 = val[1].subtract(val[0]).divide(alpha); val[n] = val[n-1];}
st = 1/num; t = 0; kt = 0; rt = phi[0];
for (j= 0; j< n-1; j++){
del1 = val[j+2].subtract(val[j]).divide(alpha);
delK = (Math.abs(key[j+1])-Math.abs(key[j]))/num;
delR = (phi[j+1]-phi[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;
if (key[j+1] < 0) ind[t] = -1; else ind[t] = 1;
kt += delK;
r[t] = rt; rt += delR;
t++;}
del0 = del1;}
p[t] = val[n-1]; k[t] = kt; ind[t] = 1; r[t] = rt;
PosInt.set_keyValue = p;
PosInt.set_key = k;
rot = new MFRotation(); rot.length = (n-1)*num+1;
M = new VrmlMatrix(); M1 = new VrmlMatrix();
O = new SFVec3f(0,0,0);
Rx = new SFVec3f(1,0,0); Ry = new SFVec3f(0,1,0); Rz = new SFVec3f(0,0,1);
dum = new SFVec3f(0,0,0);
for (i= 0; i< t; i++){
norm = p[i+1].subtract(p[i]).normalize();
th = Math.asin(norm.y);
if (norm.x == 0) ph = 0;
else ph = -Math.atan(norm.z / norm.x);
if (norm.x < 0)
if( ind[i] < 0) th = 3.1415 - th; else ph += 3.1415;
ri = new SFRotation(Rx, r[i]);
M1.setTransform(O, ri );
ri = new SFRotation(Rz, th);
M.setTransform(O, ri );
M = M.multLeft(M1);
ri = new SFRotation(Ry, ph);
M1.setTransform(O, ri );
M = M1.multLeft(M);
M.getTransform(dum, ri);
rot[i] = ri;
}
rot[t] = rot[0];
OrInt.set_keyValue = rot;
OrInt.set_key = k;
}
"]}
}
DEF FlyInt FlyInterpolator{ #loop FALSE
num 7
keyValue [0 0 -2,2 0 0,0 0 2,-2 0 0,0 0 -2,
2 2 -2, 0 4 -2, -2 2 -2, 0 0 -2]
phi [0 0 0 0 0 0 0 0 0]
key [0 .125 .25 .375 .5 -.625 -.75 -.875 -1]
}
DEF TS TimeSensor{ cycleInterval 20 loop TRUE}
DEF Model Transform{ children[
Shape{ appearance Appearance{ material Material{ diffuseColor 1 1 1 } }
geometry TimeSensor{ cycleInterval 20 loop TRUE}
DEF Model Transform{ children[
Shape{ appearance Appearance{ material Box{size .3 .05 .6} }
]}
ROUTE TS.fraction_changed TO FlyInt.set_fraction
ROUTE FlyInt.position_changed TO Model.set_translation
ROUTE FlyInt.orientation_changed TO Model.set_rotation
(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.