0

I'm studying VRML as a beginner. I have a problem with TimeSensor that need help. This is my source code

DEF time TimeSensor
{
loop TRUE
cycleInterval 2
}
DEF C11 Transform
{
translation -3 0 0
children
[
       Shape
       {
        geometry Sphere
        {
          radius 0.5
        }
        appearance Appearance
        {
          material Material
          {
             diffuseColor 0 0 0
             specularColor .29 .3 .29
             shininess .08
             ambientIntensity 0
             transparency 0.0
          } 
        }
       }

     DEF moveC11 PositionInterpolator
     {
         key [0 1]
         keyValue [-3 0 0,3 3 0]
     }
]
}
ROUTE time.fraction_changed TO moveC11.set_fraction
ROUTE moveC11.value_changed TO C11.translation

When I view in browser, the sphere moves from coordinate -3 0 0 to 3 3 0 and repeat.I want it moves only 1 time. The sphere stop at coordinate 3 3 0. How can I do it?

Thank you for helping me!

Ngo Kim Huynh
  • 69
  • 3
  • 16

1 Answers1

1

VRML concept of TimeSensor is other than to stop an infinite loop

A reverse logic works:

Modify DEF time TimeSensor { loop FALSE } to avoid uncontrollable infinite loop.

Send an event set_startTime with the current time to the TimeSensor.

The problem with this approach might be how to compute the absolute current time in seconds since 1970-01-01 00:00:00.

Fortunately all sensors in VRML generate events which output a time value when they become active.

So basically all you have to do is to ROUTE the event generated by the sensor when it becomes active to the eventIn of the TimeSensor set_startTime.

user3666197
  • 1
  • 6
  • 50
  • 92