CabMasterPro User Guide
In This Topic
    Timer Variable For Animation : Developer
    In This Topic

    Timer Variable For Animation

    SetValueTimed allows you to create a timer for animation. For example, you may want something to rotate from 0 to 360 degrees continuously, like a ceiling fan.

    We can build a "cabinet" with attachment point at the centre of the fan, and with the blades coming out as sections in three directions. We can then animate the "angle" of the cabinet by formula control and cause the fan to rotate one full cycle every 2 seconds, giving rise to a gentle refreshing breeze in the room.

    You can use as many concurrent timers as required, to both increment and decrement.

    Timer Testing Example 1

    Open the example zip here to load the drawing timertest.qid into CabMasterPro. Then open the Drawing Properties. You will see the following, which has 3 sliders.

    Timertest1

    When you press the button, the top two sliders will increment at different speeds and the third slider will decrement, as per the formula shown below.

    Timer Formula

    Timertest2

    Timer Testing Example 2

    The next example increments sliderval from its current value (startval) up to 100 in steps of 1. The delay between increments is 200 milliseconds (5 steps per second). If the processing cannot keep up with this it will just have a longer delay between steps.

    Set up a button to autoincrement the middleware variable "sliderval" like this:
    SetValueTimed("sliderval",sliderval,100,1,200)

    If the user changes the slider manually and therefore changes the sliderval, the automatic incrementing will notice the change and stop the automatic incrementing.

    It may be helpful to the user to be able to click on a Play/Stop button to start and then interrupt the playing directly also. For example if the user wants to zoom/pan or rotate to change the 3D viewing position during the "playing".', 'You can set up a middleware button which changes its label based on a yesno variable PlayStop.

    And when you click the button it can execute a PlayAction variable which could be defined like this:
    :If PlayStop

    Then SetValueTimed("sliderval",sliderval,100,1,200);SetValue("PlayStop",No)
    Else SetValue("sliderval",sliderval-1);SetValue("PlayStop",Yes)

    Notice in the Else clause we set the sliderval to sliderval-1, making a deliberate small change. This is enough to stop any automatic "playing" in progress.