How to create a vgObject in Code

 

Vega Code Example

 

 

 

 

 

 
 

This example function illustrates how to :

  • Create your own vgObject through code
  • How to create a new vgDataSet
  • How to set the properties for a vgDataSet
  • How to se the filename for a vgDataSet
  • How to load a 3d Model file into a vgDataSet
  • How to use vgDelete
  • How create a vgPos instance
  • How to delete a vgPos instance
  • How to set the position vpPos's position Vector suing vgPosVec
  • How to set an offset into a vgObject
  • How to optimise a vgObject by flattening and cleaning the vgObject
  • How to make a vgObject from a vgDataSet
  • How to make an vgObject Dynamic and thus positionable
  • How to to set a vgObject's Isector mask
  • How to set a vgOject's representation mask

 

 
   
 

 

 
 
 
    
 

 

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

vgObject*

createNewVegaObject( const char *filepath , const char *name ){

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

// # Public  function  

// #

// #   The function shows how to create and load a new vgObject

// #

// #   Returns a pointer to the New vgObject if successful

// #           otherwise returns NULL  

// #

// #

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

vgDataSet  *dset   = NULL;

vgObject   *obj    = NULL;

vgPosition *pos    = NULL;

int         loaded = VG_FAILURE;

 

 

    //

    //  Sanity check for a least some text

    //

    if( filepath == NULL ) {

         return NULL;

        }

 

    //

    // We first create a new empty Data Set

    //

    dset = vgNewDS();

    if( dset == NULL ) {

         return NULL;

        }

   

 

    //

    // Set the name and path to the database

    //

    vgName( dset, filepath );

 

    

    

    //

    // Call the follwoing function to load an OpenFlt file

    //

    // This does not really need to be called as we can let

    // the dataset decide which is the correct loader to use

    //

    vgProp( dset, VGDS_FLTLOADER, VGDS_SSMGFLT );

 

    //

    // We want the Dataset to load now not defered, if this

    // is set to false the dataset will not be loaded until

    // the object is added to a visible vgScene

    //

    vgProp( dset, VGDS_IMMEDIATE, VG_TRUE );

 

    

    //

    // We want to discard any constraints of any DOF/DCS nodes

    //         

    vgProp( dset, VGDS_CREATECONSTRAINTS, VG_OFF);

 

 

    //

    // If the DB is Projected the set this to ture

    //

    // vgProp( dset, VGDS_USEPROJECTION, VG_TRUE );

 

    

    //

    // Now actually try to load the DataSet  from the file

    //

    loaded = vgLoadDS( dset);

 

    if( loaded != VG_SUCCESS ) {

       

        //

        // We need to clean up

        //

        vgDelete ( dset );

 

        return NULL;

        }

 

 

    //

    // Now we create a new and empty vgObject

    //

    obj = vgNewObj();

    if( dset == NULL ) {

        

        //

        // We need to clean up

        //

        vgDelete ( dset );

 

        return NULL;

        }

 

    //

    // Name the new object

    //

    vgName( obj, name );

 

    //

    // Make the object dynamic other wise we cannot move it

    //

    vgProp( obj, VGOBJ_CS, VGOBJ_DYNAMIC );

 

    //

    // We want to make parts for named nodes etc

    //

    vgProp( obj, VGOBJ_PARTS, VG_ON );

 

 

    //

    // We want to discard any constraints of any DOF/DCS nodes

    //         

    vgProp( obj, VGOBJ_CONSTRAIN, VG_OFF );    

 

    //

    // Set the scaling factor for the new object if required

    //         

    // vgProp( obj, VGOBJ_SCALE, 1.0f );    

 

 

    

    //

    //  By default we should always clean and flatten the object

    //  this will help remove any redundant nodes and static

    //  transformations and help improve performance

    //

    //  Note that there is known bug in vega such that using

    //  Clean will  cause culling problems at the edge of the

    //  channel if the object has scaling in this case set

    //  VGOBJ_NOOPT instead of VGOBJ_CLEAN

    //

    vgProp( obj, VGOBJ_OPTIM, VGOBJ_CLEAN );

    

    vgProp( obj, VGOBJ_OPTIM, VGOBJ_FLATTEN );

        

 

    //

    // Set any object initial offset position here

    //         

    pos = vgNewPos();

    if( pos != NULL ){

        vgPosVec( pos, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);

        vgPos( obj, pos );

 

        //

        //  Free the position marker

        //

        vgDelPos( pos);

 

        }

 

 

    //

    // Set the dataset for for the new object

    //

    vgObjDS( obj, dset );

 

    

    //

    //  Now we call make object which will create the object 3d data

    //  using the tree created by the vgLoadDS         

    //

    //  Make the object using COPY mode so that we can use multiple

    //  copis of the 3d datbase if required

    //

    vgMakeObj( obj, VGOBJ_COPY);

 

 

    //

    //  Finally set the new vgObject isector and representation masks

    //     

    vgObjClass(     obj, 0xFFFFFFFF );

    vgObjRepresent( obj, 0xFF000000 );

 

 

return obj;

 

} // createNewVegaObject

  

  

   

 
    
 

 

 

Copyright 2004 Gordon Tomlinson  All Rights Reserved.

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