LouiZeForum
Would you like to react to this message? Create an account in a few clicks or log in to continue.
LouiZeForum

3D vrml
 
HomeHome  SearchSearch  Latest imagesLatest images  RegisterRegister  Log in  3Dchats / forums3Dchats / forums  
Le Deal du moment : -24%
PC Portable Gaming 15.6″ Medion Erazer Deputy ...
Voir le deal
759.99 €

 

 Resetting Timer

Go down 
5 posters
AuthorMessage
milostylo
1/20



Number of posts : 6
Registration date : 2007-12-08

Resetting Timer Empty
PostSubject: Resetting Timer   Resetting Timer EmptyFri 28 Dec - 9:44

Does anyone know how to reset a timer while it is running?

For e.g, I did something like this in my script

DEF DelayTime TimeSensor{
cycleInterval 10
enabled FALSE
LOOP TRUE
}

DEF testing SCRIPT{
eventIn SFTime SomeFunc
field SFNode delayTimer USE DelayTimer

url "javascript:"
function running(){
delayTimer.enabled = 'FALSE';
// Reset the timer
delayTimer.enabled = 'TRUE';
}
"
}

ROUTE DelayTimer.cycleTime TO testing.SomeFunc

I would like to reset the cycleTime so that it is set to a new value. But it seems that the cycleTime can't be set. Even if I disabled and then enabled the timer again, the cycleTime will still be the previous cycleTime unless it hits the current time where current time = cycleTime + cycleInterval. It is only then the cycleTime will be set to a new value.
Back to top Go down
magnus
+200
+200
magnus


Number of posts : 367
Registration date : 2006-11-21

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyFri 28 Dec - 11:01

pause avec reprise


Code:
#VRML V2.0 utf8

DEF Cube Transform { children [
Shape { geometry Box { } }
DEF Clic TouchSensor { } ] }

DEF Rot OrientationInterpolator {
key [ 0 .25 .5 .75 1 ]
keyValue [ 0 1 0 6.2832 0 1 0 1.5708 0 1 0 3.1416 0 1 0 4.7124 0 1 0 6.2832 ] }

DEF TimeSensor TimeSensor{ cycleInterval 10 loop TRUE }

DEF Script Script{
eventIn SFTime set_startTime
field SFNode node USE TimeSensor
field SFBool bool TRUE
field SFTime time 0
url "javascript:
function set_startTime( value ){
if( bool ) {
bool = FALSE;
time = value - node.startTime ;
}
else {
bool = TRUE;
node.startTime = value - time ;
time = 0 ;
}   
node.enabled = bool ;
node.loop = bool ;
}
"
}

ROUTE Clic.touchTime TO Script.set_startTime
ROUTE TimeSensor.fraction_changed TO Rot.set_fraction
ROUTE Rot.value_changed TO Cube.set_rotation
Bon c'est moche mais sa fonctionne.
Back to top Go down
alain
fondateur
fondateur
alain


Number of posts : 23529
Localisation : Dompierre sur Veyle ,France
Registration date : 2005-04-19

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyFri 28 Dec - 13:11

well magnus ,
it stops and reset , ok

pause et reprise ...


but I guess that milo whants to change the cycleinterval ....


I searched on google


http://www.web3d.org/message_boards/viewtopic.php?t=858


so may be in that stuff :



Code:

#VRML V2.0 utf8

NavigationInfo {
type ["EXAMINE"]
}

DEF TIMER TimeSensor {
cycleInterval 7
loop TRUE
startTime 0
stopTime -1
}

DEF SPEED Script {
eventIn SFTime speedup
eventIn SFTime slowdown
field SFNode TMR USE TIMER
field SFBool newVelocity FALSE
field SFFloat offset 0.0
field SFTime tval 0
eventIn SFFloat set_fraction
field SFFloat fraction 0.0
eventOut SFFloat fraction_changed
url "javascript:
function initialize() {
TMR.cycleInterval = 7;
}
function speedup(value, time) {
newVelocity = TRUE;
TMR.enabled = FALSE;
TMR.cycleInterval -= 2.0;
TMR.enabled = TRUE;
tval = time;
}
function slowdown(value,time) {
newVelocity = TRUE;
TMR.enabled = FALSE;
TMR.cycleInterval += 2.0;
TMR.enabled = TRUE;
tval = time;
}
function set_fraction(value,time) {
if (time > tval) {
if (newVelocity == TRUE) {
if (value < fraction) {
offset = 1.0 + value - fraction;
} else {
offset = value - fraction;
}
newVelocity = FALSE;
}
if ((value - offset) < 0.0) {
fraction = (1.0 + value - offset) % 1.0;
fraction_changed = (1.0 + value - offset) % 1.0;
} else {
fraction = (value - offset) % 1.0;
fraction_changed = (value - offset) % 1.0;
}
}
}
"
}

DEF INTERP PositionInterpolator {
key [0, 0.5, 1]
keyValue [-5 0 0, 5 0 0, -5 0 0]
}

DEF SPHERE Transform {
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 1 0
}
}
geometry Sphere {}
}
]
}

Transform {
rotation 0 0 1 1.57
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 0 0
}
}
geometry Cylinder {
height 12
radius 0.25
}
}
]
}

Transform {
translation -1 -3 0
children [
DEF GREENBALL TouchSensor {}
Shape {
appearance Appearance {
material Material {
diffuseColor 0 1 0
}
}
geometry Sphere {}
}
]
}

Transform {
translation 1 -3 0
children [
DEF REDBALL TouchSensor {}
Shape {
appearance Appearance {
material Material {
diffuseColor 1 0 0
}
}
geometry Sphere {}
}
]
}


ROUTE TIMER.fraction_changed TO SPEED.set_fraction
ROUTE SPEED.fraction_changed TO INTERP.set_fraction
ROUTE INTERP.value_changed TO SPHERE.set_translation
ROUTE GREENBALL.touchTime TO SPEED.speedup
ROUTE REDBALL.touchTime TO SPEED.slowdown


??


ps btw thay worked on

Code:
function initialize() {
TMR.cycleInterval = 7;
}
Back to top Go down
milostylo
1/20



Number of posts : 6
Registration date : 2007-12-08

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyFri 28 Dec - 18:38

I think my idea has been mistaken.

Suppose I set the cycleInterval to be 10s and enabled the timer. There will be a cycleTime event generated when the current time is 10s away from the time the timer is enabled.

Let's say if I disabled the timer and set the cycleInterval to be 5s instead. After the timer has been re-enabled, there should be a cycleTime event generated 5s from the time the timer is re-enabled.

However according to the characteristics of the TimerSensor node in VRML, the idea above won't work. Even if I disabled the timer, set the cycleInterval from 10s to 5s and then enabled the timer again, it still don't work.


E.g

When the timer is first enabled at t=10 and the cycleInterval is set to 10,
cycleTime=10.

1st cycleTime event will be at t=20 cos (cycleTime + cycleInterval)
2nd cycleTime event will be at t=30 cos (1st cycleTime + cycleInterval)
and so on....

If I stop the timer at t=3,set the cycleInterval to be 5 and then re enabled the timer, I should get this:
1st cycleTime event should be at t=8
2nd cycleTime event should be at t=13

This is the results I would like to get.
I am not good at explaining things, hope this is clearer.
Back to top Go down
alain
fondateur
fondateur
alain


Number of posts : 23529
Localisation : Dompierre sur Veyle ,France
Registration date : 2005-04-19

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyFri 28 Dec - 20:36

yes , I think it is clear ...

but too difficult for me . Sad

and our friend Peter is off home nowdays ...

well , web3d.org is may be still alive ,

as http://www.x79.net/forum/ ,
the forum for contact and x3D ..

hey , milo , have you seen , ( scuse me if I bore you to repeat ,
have you seen my question about where we could see your works ?

still curious Smile
Back to top Go down
alain
fondateur
fondateur
alain


Number of posts : 23529
Localisation : Dompierre sur Veyle ,France
Registration date : 2005-04-19

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptySat 29 Dec - 10:59

I must take a look more closely here :

http://www.smeenk.com/vrml/protos/viewpointrecorder1.wrl


it seems it uses the cycleInterval

ROUTE CameraScript.time_changed TO CameraTimer.cycleInterval
Back to top Go down
peter le cochon
+1000
+1000
peter le cochon


Number of posts : 1032
Localisation : deutschland (sniff)
Registration date : 2005-05-28

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyWed 9 Jan - 23:14

Very Happy lol, what a great script by smeenk.

As far as I know, cycleTime (not cycleInterval, Alain pirat ) is an eventOut SFTime fired by the timeSensor at startTime and at startTime+cycleInterval.

Dunno if it's also fired at stopTime.

Aparently not very useful... the sort of thing you commonly need to filter out with a script (ignore first cycleTime, the one at startTime, for example). I have sometimes used it for counting the loops of a looping timeSensor.

As far as I understand, you are using enabled true or false for starting and stoping the timer. I would rather more use startTime and stopTime for it.

- at startTime, the sensor sends it's first cycleTime, you need to filter it out with a script.

- at startTime+cycleInterval it would send the second cycleTime.

- if you stop the timer, may be it fires another cycleTime that would need to be filtered out

- now you can change it's cycleInterval and set a new startTime

- filter out again the first cycleTime
- catch the second cycleTime at startTime+cycleTime

Setting the start and stopTime of a timer to the actual time is easy using

startTime=Browser.getTime();

inside a script node.

May be you knew all that ... but I love posting this sort of stuff Laughing


Good luck with it.


Peter pig
Back to top Go down
alain
fondateur
fondateur
alain


Number of posts : 23529
Localisation : Dompierre sur Veyle ,France
Registration date : 2005-04-19

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyWed 9 Jan - 23:57

Quote :
but I love posting this sort of stuff

and we love you posting that Smile)
Back to top Go down
peter le cochon
+1000
+1000
peter le cochon


Number of posts : 1032
Localisation : deutschland (sniff)
Registration date : 2005-05-28

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyThu 10 Jan - 16:47

Very Happy Very Happy Very Happy At least I've got one "supporter" Very Happy Very Happy Very Happy

Thank's Alain.

Even though Milostylo has probably solved the problem since long ago here goes a piece of boring code, just for not having unanswered questions in Alain's forum What a Face :

The timesensor starts when you click at the box.

It runs for 10 seconds, then the script changes it's cycle interval to 5 seconds, then again to 10 ... and so on it keeps swapping from 5 to 10 and back. Nothing really amazing on that ....

As said in a previous posting, cycleTime is just an eventOut of the timeSensor, carrying it's timestamp (What the fuck ?!? ... in seconds since whatever) . It is fired once at startTime, this event is being cancelled by the script, and once at startTime+cycleInterval.

This second event is being processed by the script :

Each time a cycleInterval is completed, the console shows the time elapsed since the very first time the sensor was activated, and the time elapsed since the last cycleTime.

Now, if you click the box again during a cycleInterval, the timer is being reset. The next cycleInterval will be finished exactly 10 seconds after you have reset the timer.

Would be very interesting to know, what this should be good for .... Very Happy


Code:

#VRML V2.0 utf8

DEF   timer TimeSensor {

   loop TRUE
   cycleInterval 10
   startTime -1
   stopTime 0
   enabled   TRUE

}

DEF   tr_button Transform   {

   translation   0 0 -1

   children [
   
      Shape {
      
         geometry Box {size .1 .1 .1}
      
      }
   
      DEF   button TouchSensor {}
   
   ]

}

DEF   eval Script{

   eventIn   SFTime touchTime

   eventIn   SFTime cicleTime
   field SFNode timer USE timer

   field SFTime globalStart 0
   field SFTime lastStart 0
   field SFTime lastCycleTime 0
   field SFTime lastTotalElapsed 0

   field SFBool cancelNextCt TRUE
                field SFBool changeInterval TRUE
   field SFBool timer_active FALSE


   url   "javascript:
   
   function touchTime(_ct){

   
      if(timer_active==false){

        timer_active=true;
        actualTime=Browser.getTime();
        timer.startTime=actualTime;
        lastCycleTime=actualTime;
        globalStart=actualTime;
        print('Timer started at :'+globalStart);
        print('###########################################');
         
      
      }else{
 
          timer.stopTime=_ct;
          actualTime=_ct;
          var timer_setpoint=10;
          var totalElapsed=actualTime-globalStart;
          var delta_time=totalElapsed-lastTotalElapsed;
          lastTotalElapsed=totalElapsed;


          print('cycleInterval changed -------------------');
          print(' ');
          print('Total Time Elapsed :'+totalElapsed);
          print('Time Gap :'+delta_time);
          print(' ');

          filterNextCt=true;
          timer.cycleInterval=timer_setpoint-1;
          timer.startTime=actualTime+1;
   
      }


   
   
   }
   
   function cicleTime(_ct){


      if(cancelNextCt==false){


          actualTime=_ct;

          var   totalElapsed=actualTime-globalStart;
          var delta_time=totalElapsed-lastTotalElapsed;
         lastTotalElapsed=totalElapsed;

         cancelNextCt=true;   
         
         print('------------------------------------------- ');
          print('Total Time Elapsed    :'+totalElapsed);
         print('Time gap : '+delta_time);
         print('--------------------------------------------');
         print(' ');


        timer.stopTime=actualTime;
      
        var new_cycleTime;

        if(changeInterval==true){
         
           new_cycleTime=5;      
           changeInterval=false;

        }else{
       
           new_cycleTime=10;
           changeInterval=true;

        }

        timer.cycleInterval=new_cycleTime-1;
        timer.startTime=actualTime+1;

    
     }else{

        cancelNextCt=false;

    
     }

   }

   
   "



}

ROUTE timer.cycleTime TO eval.cicleTime
ROUTE button.touchTime TO eval.touchTime


Bisous,


pig
Back to top Go down
alain
fondateur
fondateur
alain


Number of posts : 23529
Localisation : Dompierre sur Veyle ,France
Registration date : 2005-04-19

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyThu 10 Jan - 16:58

hey LOL , don't worry about

Quote :
unanswered questions in Alain's forum

because I asked him 2 times
"who are you , could we see your artwork" ,
and he never answered LOL

ahah just joke , milo , dont worry too Smile

and btw one of the most funny thing on LouiZe is

https://closed.forumactif.com/search.forum?search_id=unanswered

all the topics where we feel alone LOOOOOOOOL
Smile)

well , I have to re take a look at all this stuff , Peter ,

but I am a bit busy with stupid pupils , these times Smile

I wasted all my holidays trying to have these flash Tv in vrml LOL


It is very stupid because when I open my webcam ,
I have only my garden to show , with a car each day crossing on the road LOOOL

Happy you travelling all other that bad World Smile))
Back to top Go down
peter le cochon
+1000
+1000
peter le cochon


Number of posts : 1032
Localisation : deutschland (sniff)
Registration date : 2005-05-28

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyThu 10 Jan - 17:01

Cool the code was wrong .... here goes the right one ...

Code:
#VRML V2.0 utf8

DEF   timer TimeSensor {

   loop TRUE
   cycleInterval 10
   startTime -1
   stopTime 0
   enabled   TRUE

}

DEF   tr_button Transform   {

   translation   0 0 -1

   children [
   
      Shape {
      
         geometry Box {size .1 .1 .1}
      
      }
   
      DEF   button TouchSensor {}
   
   ]

}

DEF   eval Script{

   eventIn   SFTime touchTime

   eventIn   SFTime cicleTime
   field SFNode timer USE timer

   field SFTime globalStart 0
   field SFTime lastStart 0
   field SFTime lastCycleTime 0
   field SFTime lastTotalElapsed 0

   field SFBool filterNextCt TRUE
    field SFBool changeInterval TRUE
   field SFBool timer_active FALSE


   url   "javascript:
   
   function touchTime(_ct){

   
      if(timer_active==false){

        timer_active=true;
        actualTime=Browser.getTime();
        timer.startTime=actualTime;
        lastCycleTime=actualTime;
        globalStart=actualTime;
        print('Timer started at :'+globalStart);
        print('###########################################');
         
      
      }else{
 
          timer.stopTime=_ct;
          actualTime=_ct;
          var timer_setpoint=10;
          var totalElapsed=actualTime-globalStart;
          var delta_time=totalElapsed-lastTotalElapsed;
          lastTotalElapsed=totalElapsed;


          print('cycleInterval changed -------------------');
          print(' ');
          print('Total Time Elapsed :'+totalElapsed);
          print('Time Gap :'+delta_time);
          print(' ');

          filterNextCt=true;
          changeInterval=true;
          timer.cycleInterval=timer_setpoint-1;
          timer.startTime=actualTime+1;
   
      }


   
   
   }
   
   function cicleTime(_ct){


      if(filterNextCt==false){


          actualTime=_ct;

          var   totalElapsed=actualTime-globalStart;
          var delta_time=totalElapsed-lastTotalElapsed;
         lastTotalElapsed=totalElapsed;

         filterNextCt=true;   
         
         print('------------------------------------------- ');
          print('Total Time Elapsed    :'+totalElapsed);
         print('Time gap : '+delta_time);
         print('--------------------------------------------');
         print(' ');


        timer.stopTime=actualTime;
      
        var new_cycleTime;

        if(changeInterval==true){
         
           new_cycleTime=5;      
           changeInterval=false;

        }else{
       
           new_cycleTime=10;
           changeInterval=true;

        }

        timer.cycleInterval=new_cycleTime-1;
        timer.startTime=actualTime+1;

    
     }else{

        filterNextCt=false;

    
     }

   }

   
   "



}

ROUTE timer.cycleTime TO eval.cicleTime
ROUTE button.touchTime TO eval.touchTime

Pardon Embarassed

pig
Back to top Go down
alain
fondateur
fondateur
alain


Number of posts : 23529
Localisation : Dompierre sur Veyle ,France
Registration date : 2005-04-19

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyThu 10 Jan - 19:33

just sad thet you didn't saw my patate woman , LOL , Peter

http://dumenieu.free.fr/vrml/dindes/petercicletimepatate.wrl


scuse , milo , not very useful Shocked
Back to top Go down
peter le cochon
+1000
+1000
peter le cochon


Number of posts : 1032
Localisation : deutschland (sniff)
Registration date : 2005-05-28

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyThu 10 Jan - 21:13

Very Happy Lol, yes ... I saw it, the potato-woman.

Very good potatoes, and even better skins ...

Pigs, like me, actually enjoy potato-skins.

I usually have them for friday's dinner, when it's forbidden to eat meat ... I don't remember well who invented that rule... but pigs celebrate him/her/it eating potato-skins on friday, sice ever ...

Further on, I did not notice how much some "third-party enhanced" avtar studio's hair dressing looks like potato skins ... till you did open my eyes.

Thank's for it.

Peter pig
Back to top Go down
alain
fondateur
fondateur
alain


Number of posts : 23529
Localisation : Dompierre sur Veyle ,France
Registration date : 2005-04-19

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptyThu 10 Jan - 22:37

the prob is if when you look at a nice "blonde" with her blonde hair ,
it remembers you potatoes LOL

but very happy that you noticed my joke Smile

Who said " dont eat pig on sunday ? " Smile)

be well , Peter Smile
Back to top Go down
magnus
+200
+200
magnus


Number of posts : 367
Registration date : 2006-11-21

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptySun 13 Apr - 20:54

Je l'avais oublié se pause reprise time.
Resetting Timer Disco10
ça va bien le faire avec ce projet en cours.
pff quand j'aurais fini cette fameuse console qui va avec.
Back to top Go down
alain
fondateur
fondateur
alain


Number of posts : 23529
Localisation : Dompierre sur Veyle ,France
Registration date : 2005-04-19

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptySun 13 Apr - 21:58

ah magnus , je me souvenais même plus de cette girl patate LOL

merci Smile
Back to top Go down
Erny
1/20
Erny


Number of posts : 7
Localisation : Germany
Registration date : 2005-09-11

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptySat 19 Apr - 20:13

Dont know if it´s helpfull ...
In this example the JS reset the timer on loading so that the animation always start from beginning.

Code:

#VRML V2.0 utf8


DEF   ob Transform   {
   children   [
      Shape   {
         geometry   Box   {
            size   0.1 1 1
         }
      }
   ]
}


DEF   o OrientationInterpolator   {
   key   [0 1]
   keyValue   [0 1 0 0, 0 1 0 1.57]
   ROUTE   o.value_changed   TO   ob.rotation
}

DEF   t TimeSensor   {
   cycleInterval   30
   enabled   FALSE
   loop   TRUE
   startTime   0
   stopTime   0
   ROUTE   t.fraction_changed   TO   o.set_fraction
}

DEF   s Script   {
   eventOut   SFBool   start
   eventOut SFTime   stime

   directOutput   TRUE

   url   "javascript:
   function initialize() {
      now = new MFTime();
      mom = new Date();
      momF = mom.getTime();
      if(Browser.getName() != 'blaxxunCC3D') {
       momF = Math.round(momF/1000);
      }

      now[0] = momF;
      stime = now[0];
      start = true;
   }
   "
}

ROUTE   s.start   TO   t.enabled
ROUTE   s.stime   TO   t.startTime

I work with new Date() and .getTime(), which present the absolute time in milliseconds. For blaxxun ok, but for Cortona you need to divide by 1000 to get the seconds. With e.g. now[0]+5 you can also define the startTime 5 Seconds in future ... Sure you can also get the time by a TouchSensor or another script or whatever.

So long
Erny
Back to top Go down
http://ernys.de
alain
fondateur
fondateur
alain


Number of posts : 23529
Localisation : Dompierre sur Veyle ,France
Registration date : 2005-04-19

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptySat 19 Apr - 20:55

Ok , thanx Smile

but I guess milostylo is AFK Smile
Back to top Go down
peter le cochon
+1000
+1000
peter le cochon


Number of posts : 1032
Localisation : deutschland (sniff)
Registration date : 2005-05-28

Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer EmptySun 20 Apr - 1:26

Very Happy Hallo Erny !!!

Nice to see you arround! Thanks for the nice piece of code, well done thumright

study It gives me some ideas.

Peter pig
Back to top Go down
Sponsored content





Resetting Timer Empty
PostSubject: Re: Resetting Timer   Resetting Timer Empty

Back to top Go down
 
Resetting Timer
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
LouiZeForum :: ARTS :: 3D art :: Script-
Jump to: