This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > VRML > December 2003 > usage of time in TimeSensor
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 |
usage of time in TimeSensor
|
|
| Robert Ludewig 2003-12-04, 1:00 pm |
| I want to make a Timesensor that cycles two times and the stops. It
shall start right away. This is how I tried:
TimeSensor
{
startTime 0
stopTime 10.0
cycleInterval 5.0
loop TRUE
}
but ot doesn`t do anything....
in the DR.Clue documentation it says:
SFTime startTime 0
which specifies when the TimeSensor starts to
generate events. The value of this field is the number
of seconds since midnight, January the first, 1970
What does that mean? Do I have to specify the time by calculating the
amount of seconds passed since 1970 till the point of time I want to
start my application? That would be kind of very strange ...
| |
| Herbert Stocker 2003-12-04, 1:00 pm |
|
Robert Ludewig wrote:quote:
> I want to make a Timesensor that cycles two times and the stops. It
> shall start right away. This is how I tried:
>
> TimeSensor
> {
> startTime 0
> stopTime 10.0
> cycleInterval 5.0
> loop TRUE
> }
>
> but ot doesn`t do anything....
>
> in the DR.Clue documentation it says:
>
> SFTime startTime 0
> which specifies when the TimeSensor starts to
> generate events. The value of this field is the number
> of seconds since midnight, January the first, 1970
>
> What does that mean? Do I have to specify the time by calculating the
> amount of seconds passed since 1970 till the point of time I want to
> start my application?
Indeed you understood it right, LOL.
But if you use the touchTime eventOut of a TouchSensor it sends
the correct time (number of seconds between Jan 1, 1970 till
when the user clicked the object).
Maybe this Script node helps you to generate correct
time stamps:
DEF Scr Script
{
eventOut SFString initOt
eventIn SFString initIn
eventOut SFTime startTime
eventOut SFTime stopTime
url "vrmlscript:
function initialize()
{
initOt= 'foo bar';
}
function initIn(foo, now)
{
startTime= now;
stopTime= now + 10;
}
"
}
ROUTE Scr.initOt TO Scr.initIn
DEF Timer TimeSensor
{
cycleInterval 5.0
loop TRUE
}
ROUTE Scr.startTime TO Timer.startTime
ROUTE Scr.stopTime TO Timer.stopTime
It sends an event to itself at world startup time.
And since each event carries a value and a time stamp, you
know the time of when your application starts. Then add 10 seconds,
and you have all you need.
If you use BS Contact VRML, the following extension makes
time stamps work like you expected:
Script {
url "vrmlscript: function initialize() {
Browser.setOption('relativeTime', 'TRUE'); }"
}
I think this is a very basic problem and my solution with
a Script node is not very straight-forward.
So what is every body else doing to solve this?
Herbert
--
Herbert Stocker (aka hersto)
http://www.hersto.de
www.bitmanagement.de
| |
| R. Russell Kinter 2003-12-04, 1:00 pm |
| k, here is my shot at it: (btw doing this from a computer
with no vrml browser to actually test it,
so please have mercy :)
DEF Tms TimeSensor {cycleInterval 5.0 loop TRUE }
DEF Sc Script {
eventIn SFFloat set_float
field SFNode Foo USE Foo # 'Foo' being the what the time sensor is driving
field SFNode Tms USE Tms
field SFInt32 a 0
directOutput TRUE
url "vrmlscript:
// I avoid intialize as much as possible, unreliable in my experience.
//looping timesensors don't count to 1. Loop is set to false before
//it starts over for third pass.
function set_float(v,ts){Foo.set_fraction = v;
if(.98<v){if(a==0){a = 1;}else{Tms.loop = false;}}}"}
ROUTE Tms.fraction_changed TO Sc.set_float
Herbert Stocker <hst-uzd-nospam@hersto.de> wrote in message news:<3FC798C3.80904@hersto.de>...quote:
> Robert Ludewig wrote:
>
> Indeed you understood it right, LOL.
>
> But if you use the touchTime eventOut of a TouchSensor it sends
> the correct time (number of seconds between Jan 1, 1970 till
> when the user clicked the object).
>
> Maybe this Script node helps you to generate correct
> time stamps:
>
>
> DEF Scr Script
> {
> eventOut SFString initOt
>
> eventIn SFString initIn
>
> eventOut SFTime startTime
> eventOut SFTime stopTime
>
> url "vrmlscript:
>
> function initialize()
> {
> initOt= 'foo bar';
> }
>
> function initIn(foo, now)
> {
> startTime= now;
> stopTime= now + 10;
> }
>
> "
> }
>
> ROUTE Scr.initOt TO Scr.initIn
>
> DEF Timer TimeSensor
> {
> cycleInterval 5.0
> loop TRUE
> }
>
> ROUTE Scr.startTime TO Timer.s|artTime
> ROUTE(Scr.stopTime TO Timer.stopTime
>
> It sends an event to itself at world startup time.
> And sijce each(event carries a value and a time stamp, you
> know the time of when your application starts. Then add 10 seconds,
> and you have all you need.
>
>
>
>
> If you use BS Contact VRML, the following extension makes
> time stamps work like you expected:
>
> Script {
> url "vrmlscript: function initialize() {
> ( Browser.setOption('relativeTime', 'TRUE'); }"
> }
>
>
>
> I think this is a very basic problem and my solution with
> a Script node is not very straight-forward.
> So what is every body else doing to solve this?
>
> Herbert
| |
| R. Russell Kinter 2003-12-04, 1:00 pm |
| ok ok, after I had posted the first attempt I realized
it was wrong cuz the float will a = 1; and then shut off
the TimeSensor before the second pass by making loop FALSE.
Since I had no vrml browser I get a second chance ;P
DEF Tms TimeSensor {cycleInterval 5.0 loop TRUE }
DEF Sc Script {
eventIn SFFloat set_float
field SFNode Tms USE Pms
field SFNode Foo USE Foo
field SFInt32 a 0
directOutput TRUE
url "vrmlscript:
//loop is only needed to get the TimeSensor going at world start time
//"artificial" loop! With loop now at false TimeSensor
//fraction_changed will go to 1 and avoid my previous mistake.
function set_float(v,ts){ Foo.set_fraction = v;
if(a==0){Tms.loop = false; a = 1;}
if(v==1&&a==1){Tms.startTime = ts; a = 2;}}"}
ROUTE Tms.fraction_changed TO Sc.set_float
Better? Do I get the exploding cigar?
Herbert Stocker <hst-uzd-nospam@hersto.de> wrote in message news:<3FC798C3.80904@hersto.de>...quote:
> Robert Ludewig wrote:
>
> Indeed you understood it right, LOL.
>
> But if you use the touchTime eventOut of a TouchSensor it sends
> the correct time (number of seconds between Jan 1, 1970 till
> when the user clicked the object).
>
> Maybe this Script node helps you to generate correct
> time stamps:
>
>
> DEF Scr Script
> {
> eventOut SFString initOt
>
> eventIn SFString initIn
>
> eventOut SFTime startTime
> eventOut SFTime stopTime
>
> url "vrmlscript:
>
> function initialize()
> {
> initOt= 'foo bar';
> }
>
> function initIn(foo, now)
> {
> startTime= now;
> stopTime= now + 10;
> }
>
> "
> }
>
> ROUTE Scr.initOt TO Scr.initIn
>
> DEF Timer TimeSensor
> {
> cycleInterval 5.0
> loop TRUE
> }
>
> ROUTE Scr.startTime TO Timer.startTime
> ROUTE Scr.stopTime TO Timer.stopTime
>
> It sends an event to itself at world startup time.
> And since each event carries a value and a time stamp, you
> know the time of when your application starts. Then add 10 seconds,
> and you have all you need.
>
>
>
>
> If you use BS Contact VRML, the following extension makes
> time stamps work like you expected:
>
> Script {
> url "vrmlscript: function initialize() {
> Browser.setOption('relativeTime', 'TRUE'); }"
> }
>
>
>
> I think this is a very basic problem and my solution with
> a Script node is not very straight-forward.
> So what is every body else doing to solve this?
>
> Herbert
| |
| Herbert Stocker 2003-12-04, 1:00 pm |
|
R. Russell Kinter wrote:quote:
> ok ok, after I had posted the first attempt I realized
> it was wrong cuz the float will a = 1; and then shut off
> the TimeSensor before the second pass by making loop FALSE.
> Since I had no vrml browser I get a second chance ;P
>
> DEF Tms TimeSensor {cycleInterval 5.0 loop TRUE }
>
> DEF Sc Script {
> eventIn SFFloat set_float
> field SFNode Tms USE Tms
> field SFNode Foo USE Foo
> field SFInt32 a 0
> directOutput TRUE
> url "vrmlscript:
> //loop is only needed to get the TimeSensor going at world start time
> //"artificial" loop! With loop now at false TimeSensor
> //fraction_changed will go to 1 and avoid my previous mistake.
> function set_float(v,ts){ Foo.set_fraction = v;
> if(a==0){Tms.loop = false; a = 1;}
> if(v==1&&a==1){Tms.startTime = ts; a = 2;}}"}
> ROUTE Tms.fraction_changed TO Sc.set_float
>
> Better? Do I get the exploding cigar?
Ummm, ........ Yes. ;-D
because the first loop does not start at fraction_changed = 0
and the script advances the first loop to fraction_changed = 1
I.e. with the following Script as Foo it outputs:
0.4842725396156311 // this is where the first loop happens to start.
1
0.01361599005758762 // the second loop runs normally
0.01747765578329563
0.02332947216928005
0.02958531305193901
0.03280825540423393
0.03892946243286133
....
0.9858511686325073
0.992094099521637
0.9952028393745422
0.9984225630760193
1 // second loop finished correctly.
DEF Foo Script {
eventIn SFFloat set_fraction
url "vrmlscript:
function set_fraction(frac)
{ print(frac); } "
}
You asked for the cigar, so i felt i should respond.
Herbert
--
Herbert Stocker (aka hersto)
http://www.hersto.de
www.bitmanagement.de
| |
|
| Hello,
I'd like to ask you a stupid question :
I'm french, and I regularly see the words "foo bar" in programming
examples.
What doest it mean ? What's this expression ?
Thank you !
O.L.
| |
| Robert Ludewig 2003-12-04, 1:00 pm |
| I don't know. But I am sure google does. Let me try .....
http://www.faqs.org/rfcs/rfc3092.html
Now I know.
(the above shown procedure is applicable in any similar situation)
:)
| |
| R. Russell Kinter 2003-12-04, 1:00 pm |
| Herbert Stocker <hst-uzd-nospam@hersto.de> wrote in message news:<3FC83EC8.80007@hersto.de>...quote:
> R. Russell Kinter wrote:
>
> Ummm, ........ Yes. ;-D
>
> because the first loop does not start at fraction_changed = 0
> and the script advances the first loop to fraction_changed = 1
>
> I.e. with the following Script as Foo it outputs:
>
> 0.4842725396156311 // this is where the first loop happens to start.
> 1
> 0.01361599005758762 // the second loop runs normally
> 0.01747765578329563
> 0.02332947216928005
> 0.02958531305193901
> 0.03280825540423393
> 0.03892946243286133
> ...
> 0.9858511686325073
> 0.992094099521637
> 0.9952028393745422
> 0.9984225630760193
> 1 // second loop finished correctly.
>
>
>
> DEF Foo Script {
> eventIn SFFloat set_fraction
> url "vrmlscript:
> function set_fraction(frac)
> { print(frac); } "
> }
>
>
> You asked for the cigar, so i felt i should respond.
>
> Herbert
In the spirit of the season:
We three kings of orient are
trying to smoke a rubber cigar
it was loaded, it exploded...can't remember rest...
I tried your method out in several plugins.
Worked fine in Contact, Cosmoplayer, and WorldView 2.1,
We need one more king, because Cortona printed:
0.2880000174045563 <started here, on this try, but starts anywhere
really.
0.28800004720687866
0.28800004720687866
0.2980000078678131
0.2980000376701355
.....
0.2639999985694885
0.2640000283718109
0.2640000581741333
0.2640000879764557
0.2640001177787781
0.2759999930858612
0.2760000228881836
0.276000052690506
ends close to same place, ten seconds all right out
of sync.
I then used the tried and true method of starting
the TimeSensor with a ProximitySensor enterTime
I realize the question revolves around the world start
time, but given the imperceptable difference to
humans, we may as well argue about how many angels are
on the head of a pin.
It works in all four VRML browsers.
DEF Prx ProximitySensor { size 1000 1000 1000 }
DEF Foo Script {
eventIn SFFloat set_fraction
url "vrmlscript:
function set_fraction(frac)
{ print(frac); } "
}
DEF Tms TimeSensor {cycleInterval 5.0 loop FALSE }
DEF Sc Script {
eventIn SFBool set_bool
eventIn SFTime set_time
eventIn SFFloat set_float
field SFNode Tms USE Tms
field SFNode Foo USE Foo
field SFInt32 a 1
directOutput TRUE
url "vrmlscript:
//artficial loop
function set_float(v,ts){ Foo.set_fraction =
v;if(v==1&&a<2){Tms.startTime = ts;a +=1;}}"}
ROUTE Tms.fraction_changed TO Sc.set_float
ROUTE Prx.enterTime TO Tms.startTime
Cortona's console printout:
2.3841858265427618e-8 <but what are these numbers from? I tried
animating a
4.7683716530855236e-8 < box, they dont seem to affect the animation.
0.009999990463256836
0.010000014677643776
0.010000037960708141
.........................
0.9980000257492065
0.9980000853538513
1
2.3841858265427618e-8 < again, what the heck are these?
4.7683716530855236e-8
7.152557657263969e-8
9.536743306171047e-8
0.010000014677643776
0.010000037960708141
0.010000062175095081
........................
0.9880000948905945
0.9880000948905945
1
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|