How to Set the Speed for a vgNavigators Control Point

 

Vega Code Example

 

 

 

 

 

 

 
 

This example function illustrates how to set the Speed/Velocity at a particular control point in a vgNavigator and shows how to do the following

  • How to get retrieve a pointer to a vgNavigator by Index
  • How to get the Render State of a vgNavigator
  • How to get the current enabled state of a vgNavigator
  • How to use vgGetProp
  • How to use vgProp
  • 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 change the value of the found vgNavigator marker
  • How to create a new velocity marker in a vgNavigator
  • How to enable and disable the rendering  of the vgNavigator path
  • How to enable and disable a vgNavigator

 

 
   
 

 

 
 
 
 

 

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

void

setNavigatorMarkerSpeed( const int   navIdx,

                         const int   pointIdx,

                         const float speed   ){

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

// # Public Function

// #

// #

// # This functions show how to Set the speed of a velocity

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

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

// # index the one will be created and added to the navigator

// #

// #

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

char      data[256];

unsigned  ctrlptIdx  = -1;

int       eventType  = -1;

double    value      = -1;

unsigned  nbytes     = 0;

bool      idxFound   = false;

 

    //

    // Sanity check we need the indexed navigator

    //

    vgSplineNavigator *navigator = vgGetNavigator( navIdx );

 

    if( navigator == NULL )

        return;

 

    //

    // Retrieve the current rendering state

    //

    int render = vgProp( navigator, VGSPLINENAV_RENDER );

 

    //

    // Retrieve the current navigator state

    //

    int navstate = vgProp( navigator, VGCOMMON_ENABLED );

 

    //

    //  First switch the navigator and rendering off

    //  off because we may need a rebuild and the

    //  rendering is not multibuffered and can crash

    //

    vgProp( navigator, VGSPLINENAV_RENDER, VG_OFF );

    vgProp( navigator, VGCOMMON_ENABLED,   VG_OFF );

 

    //

    // Force an update of the navigators state

    //

    vgUpdate(navigator );

 

    //

    //  Retrieve how many markers the navigator has

    //

    int numMarkers = vgGetProp( navigator,VGNAV_NUM_MARKERS);

    

    //

    // 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

        // when the index matches

        //

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

 

            //

            // Now we can set the Velocity marker to the new speed

            //

            vgNavigatorMarker( (vgNavigator*)navigator,

                              j,

                              pointIdx,

                              VGSPLINENAV_VELOCITY,

                              speed,

                              NULL, 0 );

            

            

            //

            // Break out of the for loop as we found the velocity marker

            //

            idxFound = true;

            break;

            

            }

        }    

 

    //

    // If we did not find a Velocity Marker then add a new one

    //

    if( !idxFound ){

        vgNavigatorAddMarker( navigator,

                              pointIdx,

                              VGSPLINENAV_VELOCITY,

                              speed,

                              NULL, 0);

        }

    

    //

    // We need to call make after changes to markers

    //

    vgMakeSplineNavigator(navigator);

 

    

    

    //

    // Set the path render state back to its original state

    //

    if( render == VG_ON )

        vgProp( navigator, VGSPLINENAV_RENDER, VG_ON );

    

    //

    // Set the path render state back to its original state

    //

    if( navstate == VG_ON )

        vgProp( navigator, VGCOMMON_ENABLED, VG_ON );

 

 

 

} // setNavigatorMarkerSpeed

 

 

 

 
 

 

 

Copyright 2004 Gordon Tomlinson  All Rights Reserved.

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