How to Scale  a vgObject

 

Vega Code Example

 

 

 

 

 

 

 
 

This example provides 1 functions which  illustrates How to Scale an vgObject:

  • How to create vgStackMatrix
  • How to use vgMat
  • How to create a new vgPosition
  • How to get a the World coordinates of a vgObject
  • How to retrieve the Translations and Rotation vectors from a vgPosition
  • How to use vgPushMatStack
  • How to use vgTransMat
  • How to use vgRotMat
  • How to use vgScaleMat
  • How to use vgGetMat to get the accumulated matrix operations
  • How to us vgPopMatStack
  • How to apply a vgMat to a vgPosition
  • How to apply a vgPosition to a vgObject
  • How to correctly delete a vgStackMatrix
  • How to correctly delete a vgPosition

 

 
   
 

 

 
 
 
    
 

#include <vgutil.h>

#include <vg.h>

 

 

void    

setObjectScale( vgObject *obj, float* xyzScale  ){

// -------------------------------------------------------

//

//  Public Function                             

//

//   Set the Scale of the vgObject using the XYZ scale

//   values passed in thru xyzScale[3]             

//

// -------------------------------------------------------

vgMat scaleMat;

double x,y,z,h,p,r;

 

    

    //

    // Sanity check we need an object and scale

    //

    if( obj == NULL || xyzScale == NULL){

        return;

        }

 

    //

    // We need a Matrix stack so create one

    //

    vgMatStack *scaleStack = vgNewMatStack();

 

 

    //

    // We need to grab the Real coordinate position

    // of the object

    //

    vgPosition *objPos = vgNewPos();

    vgGetWCSPos ( obj, objPos );

    vgGetPosVecD( objPos, &x, &y, &z,  &h, &p, &r);

 

    //

    // Set up the Matrix stack for the operation

    // required to set a scale matric on the object

    //

    vgPushMatStack( scaleStack);

 

    vgTransMat( scaleStack, x, y, z);

    

    vgRotMat(   scaleStack, h, 'z' );

    

    vgRotMat(   scaleStack, p, 'x' );

    

    vgRotMat(   scaleStack, r, 'y' );

    

    vgScaleMat( scaleStack,  sxyz[0],  sxyz[1],  sxyz[2]);

    

    //

    // Grab the accumlate matrix from the stack

    //

    vgGetMat(   scaleStack, scaleMat );

    

    //

    // Clear the stack

    //

    vgPopMatStack( scaleStack );

 

    //  

    // Apply the Matrix to the vgPos and then to the vgObject

    //

    vgPosMat( objPos, scaleMat );        

    vgPos( obj, objPos );

 

    //

    // Now Free the dynamically create variables

    //

    vgDelMatStack( scaleStack );

    vgDelPos( objPos );

 

} // setObjectScale

 

   

 
    
 

 

 

Copyright 2004 Gordon Tomlinson  All Rights Reserved.

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