User Tools

Site Tools


using_the_inertial_filter_with_the_drag_gesture

Using The "Inertial Filter" With The Drag Gesture

The Inertial Filter

When objects in the “real world” are moved on surfaces they have a tendency to want to stay in motion this is called inertia. When using the translation of touch point clusters to move virtual objects it is often necessary to continue the motion of the virtual object after touch points have been removed in the same way objects move in the “real world”. In GML we can uses inertial filters to add an inertial effect to gesture events so that they automatically continue to dispatch after touch points have been removed from touch objects.

In this example a processing block and and inertial filter block has been added to the “n-drag” gesture to create a “n-drag-inertia” gesture. The inertial filter is then activated on each dimension by setting active=“true”. To set how much the value of the dimension is reduced in each processing cycle we set friction= “0.9”. This makes each successive return value 90 percent of the last value, which has the effect of creating an exponentially decaying return value. The closer the value of friction is to zero the faster the return value approaches zero and the faster any “dragged” object stops moving

<Gesture id="n-drag-inertia-simple" type="drag">
    <match>
        <action>
            <initial>
                <cluster point_number="0" point_number_min="1" point_number_max="10"/>
            </initial>
        </action>
    </match>
    <analysis>
        <algorithm class="kinemetric" type="continuous">
            <library module="drag"/>
            <returns>
                <property id="drag_dx" result="dx"/>
                <property id="drag_dy" result="dy"/>
            </returns>
        </algorithm>
    </analysis>
    <processing>
        <inertial_filter>
            <property ref="drag_dx" active="true" friction="0.9"/>
            <property ref="drag_dy" active="true" friction="0.9"/>
        </inertial_filter>
    </processing>
    <mapping>
        <update dispatch_type="continuous">
            <gesture_event type="drag">
                <property ref="drag_dx" target="x"/>
                <property ref="drag_dy" target="y"/>
            </gesture_event>
        </update>
    </mapping>
</Gesture>

By default a touch object with inertia will continue to process the gesture until the value of each of gesture dimensions equals zero or if 120 processing cycles have taken place (which ever one happens first). To increase application performance a second filter can be added to each gesture dimension so that if the value of the dimension falls below a specific threshold it will be set to zero. This can be achieved using the “delta filter”.

In the example below a second “delta_filter” block has been added to the processing block. To activate the delta filter set the “active” property to “true” and then set the “delta_min” value to any number above zero.

<Gesture id="n-drag-inertia" type="drag">
    <match>
        <action>
            <initial>
                <cluster point_number="0" point_number_min="1" point_number_max="10"/>
            </initial>
        </action>
    </match>
    <analysis>
        <algorithm class="kinemetric" type="continuous">
            <library module="drag"/>
            <returns>
                <property id="drag_dx" result="dx"/>
                <property id="drag_dy" result="dy"/>
            </returns>
        </algorithm>
    </analysis>
    <processing>
        <inertial_filter>
            <property ref="drag_dx" active="true" friction="0.9"/>
            <property ref="drag_dy" active="true" friction="0.9"/>
        </inertial_filter>
        <delta_filter>
            <property ref="drag_dx" active="true" delta_min="0.05"/>
            <property ref="drag_dy" active="true" delta_min="0.05"/>
        </delta_filter>
    </processing>
    <mapping>
        <update dispatch_type="continuous">
            <gesture_event type="drag">
                <property ref="drag_dx" target="x"/>
                <property ref="drag_dy" target="y"/>
            </gesture_event>
        </update>
    </mapping>
</Gesture>

In the example above when the inertial filter sets the value of the dimension to 0.05 the delta filter will in turn then set the return value to zero. This has the effect of rendering the dimension “inactive”. When both dimensions are in the inactive state the gesture processing on the gesture object is shut down and all gesture events (from n-drag-inertia) cease by default. The gesture object will remain in this state until a new match is established and values for the gesture dimensions are re-calculated (new touch points are added to the associated touch object and begin to move).

using_the_inertial_filter_with_the_drag_gesture.txt · Last modified: 2019/01/29 19:07 (external edit)