How to retrieve the Speed of a vgNavigator

 

Vega Code Example

 

 

 

 

 

 
 

This example function illustrates how to retrieve the  Speed/Velocity of  a vgNavigator and shows how to do the following

  • How to get retrieve a pointer to a vgNavigator by Index
  • How to use vgGetProp
  • How to get the number of event Markers in a vgNavigator
  • How to retrieve an event Marker from a vgNavigator
  • How to test if the marker is a velocity Marker
  • How to get a overall speed of a vgNavigator
  • How to get a control point markers speed of a vgNavigator

 

 
   
 

 

 
 
 
 

 

#include "vg.h"          // Required for the standard Vega classes
#include "vgutil.h"

 

 
 

 

 

float

getNavigatorSpeed( const int   navIdx, const int pointIdx ){

// ##############################################################

// # Public Function

// #

// #

// # This functions show how to retrieve the speed of a control

// # marker on the indexed Navigator, if the Navigator

// # does not have a velocity marker at the given control point

// # then retrun the overall navigator speed

// #

// #

// # To get the overall speed simply pass pointIdx with a value

// # set to less than Zero

// #

// #

// ##############################################################

char      data[256];

unsigned  ctrlptIdx  = -1;

int       eventType  = -1;

double    value      = -1;

unsigned  nbytes     = 0;

 

    //

    // Sanity check we need the indexed navigator

    //

    vgSplineNavigator *navigator = vgGetNavigator( navIdx );

 

    if( navigator == NULL )

        return 0.0f;

 

  

    //

    //  Retrieve how many markers the navigator has

    //

    int numMarkers = vgGetProp( navigator,VGNAV_NUM_MARKERS);

 

    //

    // If index is out of rage then return the overall speed

    //

    if( pointIdx < 0 || pointIdx >= numMarkers )

        return vgGetProp( navigator,VGSPLINENAV_VELOCITY );

 

    //

    // Unfortunately we have to search through every marker

    // that the Navigator has to find the Velocity marker

    // for the control point as Vega does not provide a

    // a straight forward interface to do this

    //

    for( int j = 0; j < numMarkers; j++ ){

        

        vgNavigatorGetMarker( (vgNavigator*)navigator,

                              j,

                             &ctrlptIdx,

                             &eventType,

                             &value,

                             (void**)data,

                             &nbytes );

 

        //

        // If we have found the Velocites of the control point then

        // return the speed which is returned in 'value'

        //

        if( eventType == VGSPLINENAV_VELOCITY && pointIdx == ctrlptIdx) {

 

            return ( float ) value;

            

            }

        }    

 

    

//

// If no velocity markers found then return the overall speed

//

return vgGetProp( navigator,VGSPLINENAV_VELOCITY );

 

 

} // getNavigatorSpeed

 

 

 
 

 

 

© Copyright 2004 Gordon Tomlinson  All Rights Reserved.

All logos, trademarks and copyrights in this site are property of their respective owner.