How to set a Constant Speed for a vgNavigator

 

Vega Code Example

 

 

 

 

 

 

 
 

This example function illustrates how to set a constant Speed/Velocity for 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

setNavigatorOverallSpeed( const int   navIdx,

                          const float speed   ){

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

// # Public Function

// #

// #

// # This function shows how to set a constant speed

// # on for the Navigator on all it velocitcy control

// # markers

// #

// #

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

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;

 

    //

    // 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 the marker is the type Velocity

        //

        if( eventType == VGSPLINENAV_VELOCITY ) {

 

            //

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

            //

            vgNavigatorMarker( (vgNavigator*)navigator,

                              j,

                              ctrlptIdx,

                              VGSPLINENAV_VELOCITY,

                              speed,

                              NULL, 0 );

                        

            }

        }    

 

 

    //

    // We also need to set the default overal speed

    //

    vgProp( navigator,VGSPLINENAV_VELOCITY, speed );

 

    //

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

 

 

 

} // setNavigatorOverallSpeed

 

 

 

 

 

 
 

 

 

© Copyright 2004 Gordon Tomlinson  All Rights Reserved.

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