/*
Tested with LINT
*/
#include "gli_st.h"
#include "matstack.h"
 
#ifdef __cplusplus
extern "C" 
{
#endif
  
  void 
    GLI_xInitMatrixStack ( void ) /*marc*/
  {
	ACP_tdxIndex xI;
    g_lNbMatrixInStack = 0;
    
/*    POS_fn_vSetIdentityMatrix(&g_aDEF_stMatrixStack [ g_lNbMatrixInStack ]);*/
/*	MTH3D_M_vNullVector(&(g_aDEF_stMatrixStack [ g_lNbMatrixInStack ].stTranslationVector));
	MTH3D_M_vSetIdentityMatrix(&(g_aDEF_stMatrixStack [ g_lNbMatrixInStack ].stRotationMatrix));
	MTH3D_M_vSetIdentityMatrix(&(g_aDEF_stMatrixStack [ g_lNbMatrixInStack ].stTransformMatrix));
	g_aDEF_stMatrixStack [ g_lNbMatrixInStack ].ulType = POS_C_ulIdentityMatrixFlag;
*/    
 
    
	/* Initialise all the matrix of the matrix stack before using them*/
	for(xI=0;xI<GLI_C_lMaxMatrixInStack;++xI)
	{
		MTH3D_M_vNullVector(&(g_aDEF_stMatrixStack [ xI ].stTranslationVector));
		MTH3D_M_vSetIdentityMatrix(&(g_aDEF_stMatrixStack [ xI ].stRotationMatrix));
		MTH3D_M_vSetIdentityMatrix(&(g_aDEF_stMatrixStack [ xI ].stTransformMatrix));
		g_aDEF_stMatrixStack [ xI ].ulType = POS_C_ulIdentityMatrixFlag;
/*	   POS_fn_vSetIdentityMatrix(&g_aDEF_stMatrixStack[xI]);*/
	}
    g_p_stCurrentMatrix = &g_aDEF_stMatrixStack [ g_lNbMatrixInStack ] ;
    
    g_lNbMatrixInStack ++;
 
    return  ;
  }
  
  
  
  void 
    GLI_xPushMatrix ( POS_tdstCompletePosition *p_stMatrix )
  {
    if ( g_lNbMatrixInStack == GLI_C_lMaxMatrixInStack )
      return ;
    
    POS_fn_vMulMatrixMatrix ( &g_aDEF_stMatrixStack [ g_lNbMatrixInStack ] ,
      &g_aDEF_stMatrixStack [ g_lNbMatrixInStack - 1 ] ,
      p_stMatrix ) ;
    
    g_p_stCurrentMatrix = &g_aDEF_stMatrixStack [ g_lNbMatrixInStack ] ;
    
    g_lNbMatrixInStack ++ ;
    
    return ;
  }
  
  void 
    GLI_xPrePushMatrix ( POS_tdstCompletePosition *p_stMatrix )/*NZO*/
  {
    if ( g_lNbMatrixInStack == GLI_C_lMaxMatrixInStack )
      return ;
    
    POS_fn_vMulMatrixMatrix ( &g_aDEF_stMatrixStack [ g_lNbMatrixInStack ] ,
      p_stMatrix ,
      &g_aDEF_stMatrixStack [ g_lNbMatrixInStack - 1 ] );
    
    g_p_stCurrentMatrix = &g_aDEF_stMatrixStack [ g_lNbMatrixInStack ] ;
    
    g_lNbMatrixInStack ++ ;
    
    return ;
  }
  
  void 
    GLI_xPopMatrix ( void )
  {
    if ( g_lNbMatrixInStack == 0 )
      return ;
    
    g_lNbMatrixInStack -- ;
    
    g_p_stCurrentMatrix = &g_aDEF_stMatrixStack [ g_lNbMatrixInStack ] ;
    
    return ;
  }
  
  void 
    GLI_xLoadMatrix ( POS_tdstCompletePosition *p_stMatrix )
  {
    if ( g_lNbMatrixInStack == GLI_C_lMaxMatrixInStack )
      return ;
    
    g_aDEF_stMatrixStack [ g_lNbMatrixInStack ] = *p_stMatrix ;
    
    g_p_stCurrentMatrix = &g_aDEF_stMatrixStack [ g_lNbMatrixInStack ] ;
    
    g_lNbMatrixInStack ++ ;
    
    return  ;
  }
  
  void 
    GLI_xResetMatrixStack ( void )
  {
    g_lNbMatrixInStack = 0 ;
    
    g_p_stCurrentMatrix = NULL ;
    
    return  ;
  }
  
  void 
    GLI_xLoadAndResetMatrix ( POS_tdstCompletePosition *p_stMatrix )
  {
    GLI_xResetMatrixStack ( ) ;
    GLI_xLoadMatrix ( p_stMatrix ) ;
    
    return  ;
  }
  
  
#ifdef __cplusplus
} /*extern "C"*/
#endif
 
 
 
 
