This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > VRML > December 2006 > trouble with script-long
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
trouble with script-long
|
|
|
| Hello
I try to make a simulation of rotation. There is simple object (box)
with CylinderSensor. And its possible to rotate them. There is also
a script. this script should calculate velocity and direction of
rotation. When the dragging stopped , this script should rotate objece
proportional to drag speed and in this same directiona as in last moment
of dragging.
Everything looks nice, and browser didnt show any error. But not working
and i absolutly no ide why:-(
thanks in advande for efery help
#VRML V2.0 utf8
# do testowania animacji
Viewpoint {position 0 0 1}
NavigationInfo {
headlight TRUE
type "EXAMINE"
}
DEF obrot Transform {
children [
DEF GenObr CylinderSensor #czujnik obrotu
{
}
Shape {appearance Appearance {material Material {diffuseColor 1 0 0 }}
geometry Box {size .2 .2 .2 }}
]}#end obrot
ROUTE GenObr.rotation_changed TO obrot.rotation
#script above generate timestamp for begin and end of draging
DEF GenSygn Script {
eventIn SFBool isActive
eventOut SFTime startTime
eventOut SFTime stopTime
url "java script:
function isActive(value,timestamp)
{ if (value==FALSE){ stopTime = timestamp;}
if (value==TRUE){ startTime = timestamp;}
}
"
}
ROUTE GenObr.isActive TO GenSygn.isActive
# clock for rotator interpolator
DEF Zegar TimeSensor {
loop FALSE
cycleInterval 0 # tu wartośc musi być podana później
}
ROUTE GenSygn.stopTime TO Zegar.startTime
DEF IntObr OrientationInterpolator {
key [ 0 , .2 , .5 , 1]
keyValue [ ]
}
ROUTE Zegar.fraction_changed TO IntObr.set_fraction
ROUTE IntObr.value_changed TO obrot.rotation
# dotąd oki
DEF ZegarSkanera TimeSensor {
loop FALSE
cycleInterval .1
} # sprawdza co 0.1 sekundy
ROUTE GenSygn.startTime TO ZegarSkanera.startTime
ROUTE GenSygn.stopTime TO ZegarSkanera.stopTime
#zegar powyżej pracuje tylko wtedy jak wciśniety jest przycisk
DEF Skaner Script {
eventIn SFRotation rotation
eventIn SFTime refresh
eventIn SFTime startTime
field SFRotation inRotation 0 1 0 0 'rotation form cylinder sennsor
field SFFloat pozycjaPoczatkowa 0 '
field SFFloat pozycjaKoncowa 0
field SFTime chwilaPoczatkowa 0
field SFTime chwilaKoncowa 0
field SFTime przyspieszenie 0.01 'decceleration
field SFFloat deltaT 0
field SFFloat deltaS 0
field SFFloat kierunek 1 'direction
eventOut SFFloat czasHamowania ' time of animation
field SFNode zz USE Zegar
field SFFloat droga 0
field SFRotation pozycja0 0 1 0 0
field SFRotation pozycja1 0 1 0 0
field SFRotation pozycja2 0 1 0 0
field SFRotation pozycja3 0 1 0 0
field SFNode rotator USE IntObr
url"java script:
function rotation(value){
inRotation =value; }
function refresh(value,timestamp){
pozycjaPoczatkowa=inRotation[3];
chwilaPoczatkowa = timestamp;
}
function startTime(value,timestamp){
pozycjaKoncowa=inRotation[3];
chwilaKoncowa = timestamp;
deltaT=chwilaKoncowa-chwilaPoczatkowa;
deltaS=pozycjaKoncowa-pozycjaPoczatkowa;
if (deltaS<0){deltaS=-deltaS; kierunek=-1;}
czasHamowania = (deltaS/deltaT)/przyspieszenie;
zz.cycleInterval=czasHamowania;
droga = (przyspieszenie *(czasHamowania*czasHamowania))/2 ;
if (kierunek==-1){droga=-droga;}
pozycja0[3] = pozycjaKoncowa;
pozycja1[3] = pozycjaKoncowa+(droga/3);
pozycja2[3] = pozycjaKoncowa+(droga/2);
pozycja3[3] = pozycjaKoncowa+(droga);
rotator.keyValue[0]=pozycja0;
rotator.keyValue[1]=pozycja1;
rotator.keyValue[2]=pozycja2;
rotator.keyValue[3]=pozycja3;
}
"
}
ROUTE GenSygn.stopTime TO Skaner.startTime
ROUTE ZegarSkanera.startTime TO Skaner.refresh
--
Marcin "Mamut"
diving...eat...sleep...and dream about diving
| |
| Joerg Scheurich aka MUFTI 2006-12-06, 7:37 pm |
| > Everything looks nice, and browser didnt show any error.
Dispite your browser (which one ?) did not show any error, your VRML file
contain at least 2 errors:
> # clock for rotator interpolator
> DEF Zegar TimeSensor {
> loop FALSE
> cycleInterval 0 # tu warto?c musi by? podana pó?niej
> }
http://www.web3d.org/x3d/specificat...html#TimeSensor
| ... The value of cycleInterval shall be greater than zero.
> DEF IntObr OrientationInterpolator {
> key [ 0 , .2 , .5 , 1]
> keyValue [ ]
> }
http://www.web3d.org/x3d/specificat...ionInterpolator
| ... The keyValue field shall contain exactly as many rotations as there are
| keyframes in the key field.
So the animations driven by "Zegar" and "IntObr" are useless.
so long
MUFTI
--
Tontafeln
digital beschriebene Tontafeln und Brieftauben 44
Aus dem Schlagwortregister von "Programmieren in Perl" Wall/Schwartz
| |
|
| UĹźytkownik Joerg Scheurich aka MUFTI napisaĹ:[color=darkred]
>
>
> Dispite your browser (which one ?) did not show any error, your VRML file
> contain at least 2 errors:
>
>
Yes I know about zero in cycleInterval field. But this animation is
controlled by next script above and this script set a cycleInterval,
and keyValue in interpolator.
There was not one from route at the end of file - after all scripts. :-)
Bus still something is wrong.
When I dragging an object afer dragging this obiect very fast stop.
Also sometimes direction of rotation is statistical.
I still neeeeeed help ;-(
--
Marcin "Mamut"
diving...eat...sleep...and dream about diving
| |
| fabricator 2006-12-06, 7:37 pm |
|
Add this as the last line:
ROUTE GenObr.rotation_changed TO Skaner.rotation
And alter this node:
DEF GenObr CylinderSensor #czujnik obrotu
{
autoOffset TRUE
}
It seems to work better with those changes, still not perfect though.
m wrote:
> Hello
>
> I try to make a simulation of rotation. There is simple object (box)
> with CylinderSensor. And its possible to rotate them. There is also
> a script. this script should calculate velocity and direction of
> rotation. When the dragging stopped , this script should rotate objece
> proportional to drag speed and in this same directiona as in last moment
> of dragging.
> Everything looks nice, and browser didnt show any error. But not working
> and i absolutly no ide why:-(
>
> thanks in advande for efery help
>
>
> #VRML V2.0 utf8
>
> # do testowania animacji
>
> Viewpoint {position 0 0 1}
>
> NavigationInfo {
> headlight TRUE
> type "EXAMINE"
>
>
> }
>
>
>
> DEF obrot Transform {
>
>
> children [
> DEF GenObr CylinderSensor #czujnik obrotu
> {
> }
>
> Shape {appearance Appearance {material Material {diffuseColor 1 0 0 }}
> geometry Box {size .2 .2 .2 }}
>
>
>
>
> ]}#end obrot
>
>
> ROUTE GenObr.rotation_changed TO obrot.rotation
>
>
>
> #script above generate timestamp for begin and end of draging
>
> DEF GenSygn Script {
> eventIn SFBool isActive
> eventOut SFTime startTime
> eventOut SFTime stopTime
> url "java script:
> function isActive(value,timestamp)
> { if (value=3D=3DFALSE){ stopTime =3D timestamp;}
> if (value=3D=3DTRUE){ startTime =3D timestamp;}
>
> }
>
>
> "
> }
>
> ROUTE GenObr.isActive TO GenSygn.isActive
>
> # clock for rotator interpolator
> DEF Zegar TimeSensor {
> loop FALSE
> cycleInterval 0 # tu warto=B6c musi by=E6 podana p=F3=BCniej
> }
>
> ROUTE GenSygn.stopTime TO Zegar.startTime
>
>
> DEF IntObr OrientationInterpolator {
> key [ 0 , .2 , .5 , 1]
> keyValue [ ]
> }
>
>
>
> ROUTE Zegar.fraction_changed TO IntObr.set_fraction
> ROUTE IntObr.value_changed TO obrot.rotation
>
>
> # dot=B1d oki
>
>
> DEF ZegarSkanera TimeSensor {
> loop FALSE
> cycleInterval .1
> } # sprawdza co 0.1 sekundy
>
> ROUTE GenSygn.startTime TO ZegarSkanera.startTime
> ROUTE GenSygn.stopTime TO ZegarSkanera.stopTime
> #zegar powy=BFej pracuje tylko wtedy jak wci=B6niety jest przycisk
>
>
>
> DEF Skaner Script {
> eventIn SFRotation rotation
> eventIn SFTime refresh
> eventIn SFTime startTime
>
> field SFRotation inRotation 0 1 0 0 'rotation form cylinder sennsor
> field SFFloat pozycjaPoczatkowa 0 '
> field SFFloat pozycjaKoncowa 0
> field SFTime chwilaPoczatkowa 0
> field SFTime chwilaKoncowa 0
> field SFTime przyspieszenie 0.01 'decceleration
>
> field SFFloat deltaT 0
> field SFFloat deltaS 0
>
> field SFFloat kierunek 1 'direction
>
> eventOut SFFloat czasHamowania ' time of animation
>
> field SFNode zz USE Zegar
>
> field SFFloat droga 0
>
>
> field SFRotation pozycja0 0 1 0 0
> field SFRotation pozycja1 0 1 0 0
> field SFRotation pozycja2 0 1 0 0
> field SFRotation pozycja3 0 1 0 0
>
> field SFNode rotator USE IntObr
>
> url"java script:
> function rotation(value){
> inRotation =3Dvalue; }
>
> function refresh(value,timestamp){
> pozycjaPoczatkowa=3DinRotation[3];
> chwilaPoczatkowa =3D timestamp;
>
> }
>
>
> function startTime(value,timestamp){
> pozycjaKoncowa=3DinRotation[3];
> chwilaKoncowa =3D timestamp;
>
> deltaT=3DchwilaKoncowa-chwilaPoczatkowa;
> deltaS=3DpozycjaKoncowa-pozycjaPoczatkowa;
> if (deltaS<0){deltaS=3D-deltaS; kierunek=3D-1;}
>
>
> czasHamowania =3D (deltaS/deltaT)/przyspieszenie;
> zz.cycleInterval=3DczasHamowania;
>
> droga =3D (przyspieszenie *(czasHamowania*czasHamowania))/2 ;
>
> if (kierunek=3D=3D-1){droga=3D-droga;}
>
> pozycja0[3] =3D pozycjaKoncowa;
> pozycja1[3] =3D pozycjaKoncowa+(droga/3);
> pozycja2[3] =3D pozycjaKoncowa+(droga/2);
> pozycja3[3] =3D pozycjaKoncowa+(droga);
>
> rotator.keyValue[0]=3Dpozycja0;
> rotator.keyValue[1]=3Dpozycja1;
> rotator.keyValue[2]=3Dpozycja2;
> rotator.keyValue[3]=3Dpozycja3;
>
>
> }
>
>
>
>
> "
>
> }
>
> ROUTE GenSygn.stopTime TO Skaner.startTime
> ROUTE ZegarSkanera.startTime TO Skaner.refresh
| |
|
| you might get some help from this;
http://vrml.portland.co.uk/vrml%20s...arena/arena.wrl
it uses the same idea to roll a bowling ball, you move it around with a
planesensor and when you let go the ball rolls at the speed and in the
direction it was going when you released it, i did this a while back
and cant really remember much about it, but it took some time to make
to work in contact and cortona.
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|