/* FM970130 : Matrix tool*/ /*========================================================================= * ToolMatr.c : This module contain simple used functions * This is a part of the Game project. * * It contains adding function concerning the matrix management * * Version 1.0 * Creation date 30/01/97 * Author Fabien MORALES * Revision date * * That file needs to be compatible for all platforms. * * (c) Ubi Studios 1996 *=======================================================================*/ #include "ToolsCPA.h" #include "Actions\AllActs.h" #include "ToolMatr.h" #include "TypeCam.h" #define CAM_C_xAngleEpsilon ((MTH_tdxReal)1E-4) /********************************************/ /* Operations on Rotation-Matrices */ /********************************************/ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Description: fn_vSetRotationMatrixX*/ /* Set the absolute angle of rotation (X axis) for a super perso matrix*/ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Methods: */ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Input: POS_tdstCompletePosition *p_stMatrix : super perso matrix*/ /* GLI_tdxValue xAngle*/ /* Output: void*/ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Creation date: Jan.30, 1997 Author: Fabien MORALES*/ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Modifications: */ /* Modification date: Modification Author: Fabien MORALES*/ /*/////////////////////////////////////////////////////////////////////////////////*/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ void fn_vSetRotationMatrixX ( POS_tdstCompletePosition *p_stMatrix , GLI_tdxValue xAngle ) { MTH3D_tdstVector I,J,K; /* compute the modified angle*/ /* x axis is (-y) axis*/ /* to do...*/ MTH3D_M_vSetVectorElements(&I,MTH_C_ONE,MTH_C_ZERO,MTH_C_ZERO); MTH3D_M_vSetVectorElements(&J,MTH_C_ZERO,MTH_M_xCos(xAngle),MTH_M_xSin(xAngle)); MTH3D_M_vSetVectorElements(&K,MTH_C_ZERO,MTH_M_xNeg(MTH_M_xSin(xAngle)),MTH_M_xCos(xAngle)); POS_fn_vSetRotationMatrix( p_stMatrix ,&I,&J,&K) ; } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Description: fn_vSetRotationMatrixY*/ /* Set the absolute angle of rotation (Y axis) for a superperso matrix*/ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Methods: */ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Input: POS_tdstCompletePosition *p_stMatrix : super perso matrix*/ /* GLI_tdxValue xAngle*/ /* Output: void*/ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Creation date: Jan.30, 1997 Author: Fabien MORALES*/ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Modifications: */ /* Modification date: Modification Author: Fabien MORALES*/ /*/////////////////////////////////////////////////////////////////////////////////*/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ void fn_vSetRotationMatrixY ( POS_tdstCompletePosition *p_stMatrix , GLI_tdxValue xAngle ) { MTH3D_tdstVector I,J,K; /* compute the modified angle*/ /* x axis is (-y) axis*/ /* to do...*/ MTH3D_M_vSetVectorElements(&I,MTH_M_xCos(xAngle),MTH_C_ZERO,MTH_M_xNeg(MTH_M_xSin(xAngle))); MTH3D_M_vSetVectorElements(&J,MTH_C_ZERO,MTH_C_ONE,MTH_C_ZERO); MTH3D_M_vSetVectorElements(&K,MTH_M_xSin(xAngle),MTH_C_ZERO,MTH_M_xCos(xAngle)); POS_fn_vSetRotationMatrix( p_stMatrix ,&I,&J,&K) ; } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Description: fn_vSetRotationMatrixZ*/ /* Set the absolute angle of rotation (Z axis) for a superperso matrix*/ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Methods: */ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Input: POS_tdstCompletePosition *p_stMatrix : super perso matrix*/ /* GLI_tdxValue xAngle*/ /* Output: void*/ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Creation date: Jan.30, 1997 Author: Fabien MORALES*/ /*/////////////////////////////////////////////////////////////////////////////////*/ /* Modifications: */ /* Modification date: Modification Author: Fabien MORALES*/ /*/////////////////////////////////////////////////////////////////////////////////*/ void fn_vSetRotationMatrixZ ( POS_tdstCompletePosition *p_stMatrix , GLI_tdxValue xAngle ) { MTH3D_tdstVector I,J,K; GLI_tdxValue xModifiedAngle; /* x axis is (-y) axis*/ xModifiedAngle= MTH_M_xAdd(xAngle,MTH_C_PiBy2); MTH3D_M_vSetVectorElements(&I,MTH_M_xCos(xModifiedAngle),MTH_M_xSin(xModifiedAngle),MTH_C_ZERO); MTH3D_M_vSetVectorElements(&J,MTH_M_xNeg(MTH_M_xSin(xModifiedAngle)),MTH_M_xCos(xModifiedAngle),MTH_C_ZERO); MTH3D_M_vSetVectorElements(&K,MTH_C_ZERO,MTH_C_ZERO,MTH_C_ONE); POS_fn_vSetRotationMatrix( p_stMatrix ,&I,&J,&K) ; } /* *===================================================================================================== * Set the absolute angle of rotation (X axis) for a super perso matrix *===================================================================================================== */ void fn_vTurnMatrixX(POS_tdstCompletePosition *_p_stMatrix, MTH_tdxReal _xAngle) { POS_tdstCompletePosition TmpMatrix; MTH3D_tdstVector I,J,K; MTH_tdxReal xCos,xSin; POS_fn_vSetIdentityMatrix ( &TmpMatrix ) ; xCos = MTH_M_xCos(_xAngle); xSin = MTH_M_xSin(_xAngle); if (MTH_M_bIsNullWithEpsilon(xCos,CAM_C_xAngleEpsilon)) xCos = MTH_C_ZERO; if (MTH_M_bIsNullWithEpsilon(xSin,CAM_C_xAngleEpsilon)) xSin= MTH_C_ZERO; MTH3D_M_vSetBaseIVector(&I); MTH3D_M_vSetVectorElements(&J,MTH_C_ZERO,xCos,xSin); MTH3D_M_vSetVectorElements(&K,MTH_C_ZERO,MTH_M_xNeg(xSin),xCos); POS_fn_vSetRotationMatrix ( &TmpMatrix ,&I,&J,&K) ; POS_fn_vMulMatrixMatrix (_p_stMatrix,&TmpMatrix,_p_stMatrix); } /* *===================================================================================================== * Set the absolute angle of rotation (Y axis) for a super perso matrix * *===================================================================================================== */ void fn_vTurnMatrixY ( POS_tdstCompletePosition *_p_stMatrix , MTH_tdxReal _xAngle ) { POS_tdstCompletePosition TmpMatrix; MTH3D_tdstVector I,J,K; MTH_tdxReal xCos,xSin; POS_fn_vSetIdentityMatrix ( &TmpMatrix ) ; xCos = MTH_M_xCos(_xAngle); xSin = MTH_M_xSin(_xAngle); if (MTH_M_bIsNullWithEpsilon(xCos,CAM_C_xAngleEpsilon)) xCos = MTH_C_ZERO; if (MTH_M_bIsNullWithEpsilon(xSin,CAM_C_xAngleEpsilon)) xSin= MTH_C_ZERO; MTH3D_M_vSetVectorElements(&I,xCos,MTH_C_ZERO,MTH_M_xNeg(xSin)); MTH3D_M_vSetBaseJVector(&J); MTH3D_M_vSetVectorElements(&K,xSin,MTH_C_ZERO,xCos); POS_fn_vSetRotationMatrix ( &TmpMatrix ,&I,&J,&K) ; POS_fn_vMulMatrixMatrix (_p_stMatrix,&TmpMatrix,_p_stMatrix) ; } /* *===================================================================================================== * Set the absolute angle of rotation (Z axis) for a super perso matrix * *===================================================================================================== */ void fn_vTurnMatrixZ ( POS_tdstCompletePosition *_p_stMatrix , MTH_tdxReal _xAngle ) { POS_tdstCompletePosition TmpMatrix; MTH3D_tdstVector I,J,K; MTH_tdxReal xCos,xSin; POS_fn_vSetIdentityMatrix ( &TmpMatrix ) ; xCos = MTH_M_xCos(_xAngle); xSin = MTH_M_xSin(_xAngle); if (MTH_M_bIsNullWithEpsilon(xCos,CAM_C_xAngleEpsilon)) xCos = MTH_C_ZERO; if (MTH_M_bIsNullWithEpsilon(xSin,CAM_C_xAngleEpsilon)) xSin= MTH_C_ZERO; MTH3D_M_vSetVectorElements(&I,xCos,xSin,MTH_C_ZERO); MTH3D_M_vSetVectorElements(&J,MTH_M_xNeg(xSin),xCos,MTH_C_ZERO); MTH3D_M_vSetBaseKVector(&K); POS_fn_vSetRotationMatrix ( &TmpMatrix ,&I,&J,&K) ; POS_fn_vMulMatrixMatrix (_p_stMatrix,&TmpMatrix,_p_stMatrix) ; }