How to create a vgNavigator and vgPath in Code

 

Vega Code Example

 

 

 

 

 

 
 

This example shows you how to create a simple vgPath and vgNavigator instance:

  • How to create a new vgPostion using vgNewPos
  • How to create an empty and new vgPath instance
  • How to set a file and filename for the vgPath instance
  • How to set the name for the vgPath
  • How to create an empty and new vgSplineNavigator
  • How to set a file and filename for the vgSplineNavigator instance
  • How to set the name for the vgSplineNavigator
  • How to set the XYZ, HPR  vectors of a vgPosition using vgPosVec
  • How to add way point to a vgPath with vgPathAddCtrlPointPos
  • How to add event markers to a vgSplineNavigator with vgNavigatorAddMarker
  • How to set the vgSplineNavigator's type to Hermite and cardinal spline
  • How to set the vgSplineNavigator paths default rendering state to Off
  • How to set the HPR interpolation to addative for the segement
  • How to set the tension factor the paths segment through the control points
  • How to turn Loop closing off for the vgSplineNavigator
  • How to tell the vgSplineNavigator to restart at the starting control point when the last one is reached
  • How to write the vgPath to a file using vgPathWriteFile
  • How to write the vgSplineNavigator to a file using vgNavigatorWriteFile
  • How to tell the vgSplineNavigator to actually make the path to traverse

 

 
   
 

 

 
 
 
    
 

 

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

vgSplineNavigator*

createSimpleVegaNavigatorAndVegaPath(){

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

// # Public Function

// #

// #

// # This functions show you how to create a  

// # simple and vgNavigator and control point  

// # event markers

// #

// #

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

vgSplineNavigator   *navigator = NULL;

vgPath              *path      = NULL;

vgPosition          *pos       = NULL;

float                xVec      = 0.0f;

float                yVec      = 0.0f;

FILE                 file      = NULL;

 

    //

    // We need to create the vega position

    //

    pos = vgNewPos();

 

 

    //

    // Create the new empty vgPath instance

    //

    path = vgNewPath( NULL, NULL);

 

    //

    //   Clear the path file to zero bytes

    //

    file = fopen( "my_vgPath_1.pth", "w+");

    fclose( file );

 

    //

    //  Set the file name for the path instance

    //  and name the instance

    //

    vgPathFileName( path , "my_vgPath_1.pth" );

 

    vgName( path, "Path_1" );

 

 

    //

    // Clear the navigator file to zero bytes

    //

    file = fopen( "myVgNav1.nav", "w+");

 

    fclose( file );

 

 

    //

    //  Create a new blank navigator passing the vgpath

    //  instance for the actual definition of the way points

    //

    navigator = vgNewSplineNavigator( "my_vgNav_1.nav", path );

 

 

    //

    //  Set the file name for the path instance

    //  and name the instance

    //

    vgNavigatorFileName( navigator,  "my_vgNav_1.nav");

 

    vgName( navigator, "Nav_1" );

 

 

    //

    //  Create 50 waypoints in the vgpath instance and

    //  the create the required  control point markers

    //

    for( int i = 0; i < 50; i++ ){

 

        

        //

        // Create some coordinates for the vgPath way point  

        //

        vgPosVec( pos, xVec, yVec, 1.83f, 0.0f, 0.0f, 0.0f);

        

        if( i < 26 ){

 

            xVec += 35.0f;

            yVec += 25.0f;

 

            }

        else {

 

            xVec -= 35.0f;

            yVec -= 25.0f;

 

            }

 

 

 

        //

        // Add the position as anew control point on the path  

        //

        vgPathAddCtrlPointPos(path, pos);

 

 

        //

        // For the first control point add the event markers that

        // describe the vgNavigator

        //

        if ( i == 0) {

 

            //

            //  Make the path a Hermite Spline, this will be a Cardinal as

            //  no tangents are supplied

            //

            vgNavigatorAddMarker( navigator, 0, VGSPLINENAV_HERMITE, 0, NULL, 0);

 

            //

            //  Turn rendering of the path Off

            //

            vgNavigatorAddMarker( navigator, 0, VGSPLINENAV_RENDER, VG_OFF,NULL, 0);

        

            //

            //  Step the HPR to interpet the HPR as additive to the curve  

            //

            vgNavigatorAddMarker( navigator, 0, VGSPLINENAV_ABSOLUTE_HPR, TRUE, NULL, 0);

        

            //

            // Set the tension value how close through the control

            // points the segment goes

            //

            vgNavigatorAddMarker(navigator,0,VGSPLINENAV_TENSION_FACTOR, 4.5,NULL, 0);

        

            //

            //  Set the initial speed to 20

            //

            vgNavigatorAddMarker( navigator, 0, VGSPLINENAV_VELOCITY, 20.0, NULL, 0);

            }

        else{

        

            //

            //  Step the HPR to linterpet the HPR as additive to the curve  

            //

            vgNavigatorAddMarker( navigator, i, VGSPLINENAV_ABSOLUTE_HPR, TRUE, NULL, 0);

        

            //

            // Set the tension value how close through the control

            // points the segment goes

            //

            vgNavigatorAddMarker(navigator, i,VGSPLINENAV_TENSION_FACTOR, 4.5, NULL, 0);

        

            //

            //  Set the same velocity on each control point

            //

            vgNavigatorAddMarker( navigator, i, VGSPLINENAV_VELOCITY, 20.0, NULL, 0);

            }

        }

    

 

    //

    //  Navigator will restart when it get to the end control point

    //

    vgNavigatorAddMarker( navigator, i - 1, VGSPLINENAV_LOOP, VG_OFF, NULL, 0);

 

    vgProp( navigator, VGSPLINENAV_STOP_AT_END, VG_OFF );

 

 

    //

    // Write out vgPath to its file

    //

    vgPathWriteFile( path );

 

    //

    //  Tell the Navigator to make spline

    //

    vgMakeSplineNavigator( navigator );

 

    //

    //  Write out the Navigator to its file

    //

    vgNavigatorWriteFile ( navigator );

 

    //

    //  Release the vgPos now were done with it

    //

    vgDelPos( pos );

 

 

return navigator;

 

} // createSimpleVegaNavigatorAndVegaPath

 

   

 
    
 

 

 

Copyright 2004 Gordon Tomlinson  All Rights Reserved.

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