How to Position a vgObject in Code

 

Vega Code Example

 

 

 

 

 

 
 

This example function illustrates :

  • How to position a  vgObject
  • How to test if a vgObject is positionable
  • How to set just the X,Y, Z of an vgObject
  • How to use vgDeletePos
  • How create a vgPos instance
  • How to use a vgPos instancev
  • Notean vgObject coordinate system type property (VGOBJ_CS) must be set to VGPOBJ_DYNAMIC in order to be able to position an vgObject
  • Note if an vgObject is attached to a vgPlayer then you have to position the vgPlayer and not the vgObject

 

 
   
 

 

 
 
 
    
     
 

 

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

 

int

setVegaObjectXYZ( vgObject *object,

                  const float x, const float y, const float z){

 

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

// # Public  function  

// #

// #   Function shows how to set the X Y Z of a vgObject

// #

// #   returns VG_SUCCESS if the Object can be positioned

// #

// #            otherwise returns VG_FAILURE

// #

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

vgPosition *pos    = NULL;

int         result = VG_FAILURE;

    

    //

    //  Sanity check we need a vgObject

    //     

    if( object == NULL )

        return VG_FAILURE;

 

 

    //

    //  Retrieve the coord type of the object

    //     

    int cstype = vgGetProp ( object, VGOBJ_CS );

 

    //

    //  If the object is a Static we cannot position it

    //     

    if( cstype == VGPOBJ_STATIC )

      return VG_FAILURE;

 

 

 

    //

    //  Create a vgPos

    //     

    pos = vgNewPos();

    if( pos == NULL )

        return VG_FAILURE;

 

 

    double  d = 0.0, h = 0.0, p = 0.0, r = 0.0;

 

    //

    //  Retrieve the current H P R as we are only adjusting the XYZ

    //  

    vgGetPos( object, pos );   

 

    vgGetPosVec( pos, &d, &d, &d, &h, &p, &r );

 

    

    //

    //  Set the vgPos to the passed in X Y Z coordinates

    //     

    vgPosVec( pos, x, y, z, h, p, r );

 

 

    //

    //  Set position of the object

    //     

    vgPos( object, pos );

 

 

 

    //

    //  Release the vgPos as where done

    //     

    vgDelPos( pos);

        

 

 

return VG_SUCCESS;

 

} // setVegaObjectsXYZ

 

   

  
    
 

 

 

Copyright 2004 Gordon Tomlinson  All Rights Reserved.

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