/* *======================================================================================= * Name : MecTools.c * Author : J Thénoz Date : 01/05/98 * Description : Mechanic tools funstions *======================================================================================= */ #include "MEC/MECInc.h" #include "MEC/DnmDynam.h" #include "MEC/ParsData.h" #include "MEC/DNMSurSt.h" #include "MEC/mbase.h" #include "Extheade.h" #include "COL.h" #include "MEC/MecDef.h" #include "MEC/MECTOOLS.h" #include "PCS.h" /* Physical Collide Set */ #include "SCT.h" /* SeCTor*/ #include "FIL.h" /* SeCTor*/ #include "PRT.h" /* PaRTicules*/ #include "GAM.h" /* GAMe*/ /* * Normal */ /* normal of a wall ? */ ACP_tdxBool MEC_fn_bWallNormal (struct DNM_stDynamics *p_stDynamic, MTH3D_tdstVector* p_stNormal) { MTH_tdxReal xDotProduct; MTH3D_tdstVector stVerticalVector; MTH3D_M_vSetVectorElements (&stVerticalVector, MTH_C_ZERO, MTH_C_ZERO, MTH_C_ONE); xDotProduct = MTH3D_M_xDotProductVector ( p_stNormal, &stVerticalVector ); if ( (xDotProduct>MEC_fn_xWallLimit(p_stDynamic)) && (xDotProduct=MEC_fn_xGroundLimit(p_stDynamic)) return TRUE; else return FALSE; } /* * Obstacle */ /* this obstacle is a ceil ? */ ACP_tdxBool MEC_fn_bCeilObstacle (struct DNM_stDynamics *p_stDynamic, DNM_tdstMecObstacle *p_stObstacle) { MTH_tdxReal xDotProduct; MTH3D_tdstVector stVerticalVector; MTH3D_tdstVector *p_stNormalVector; MTH3D_M_vSetVectorElements (&stVerticalVector, MTH_C_ZERO, MTH_C_ZERO, MTH_C_ONE); p_stNormalVector = DNM_M_p_stObstacleGetNorm (p_stObstacle); xDotProduct = MTH3D_M_xDotProductVector ( p_stNormalVector, &stVerticalVector ); if (xDotProductCOL_C_xMaxNumberOfCollisions) lObstacle = COL_C_xMaxNumberOfCollisions; memcpy ( p_stObstacle, a_stObstacle, lObstacle*sizeof(DNM_tdstMecObstacle) ); *p_lObstacle = lObstacle; } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC 04/06/99 */ ACP_tdxBool MEC_fn_bCanCrashActor (DNM_tdstMecObstacle* p_stCollideObstacle) { HIE_tdxHandleToSuperObject hSupObj; hSupObj = DNM_M_p_stObstacleGetObject (p_stCollideObstacle); if (!HIE_fn_bIsSuperObjectValid(hSupObj)) return FALSE; hSupObj = MEC_fn_hGetFatherActor (hSupObj); return (fn_ulStandardGameGetCustomBitsSO(hSupObj) & C_ulDNM_NO_CRASH_CUSTOM_BIT) != C_ulDNM_NO_CRASH_CUSTOM_BIT; } /* * Collision */ /* need to call collide ? */ /* yes only if we move */ BOOL MEC_fn_bDynamicsNeedCollide (struct DNM_stDynamics *p_stDynamic) { POS_tdxHandleToPosition hCurrentMatrix, hPreviousMatrix; MTH3D_tdstVector *p_stCurrentPosition, *p_stPreviousPosition; MTH3D_tdstVector *p_stCurrentI, *p_stCurrentJ, *p_stCurrentK; MTH3D_tdstVector *p_stPreviousI, *p_stPreviousJ, *p_stPreviousK; hCurrentMatrix = DNM_M_p_stDynamicsGetCurrentMatrix (p_stDynamic); hPreviousMatrix = DNM_M_p_stDynamicsGetPreviousMatrix (p_stDynamic); p_stCurrentPosition = POS_fn_p_stGetTranslationVector ( hCurrentMatrix ); p_stPreviousPosition = POS_fn_p_stGetTranslationVector ( hPreviousMatrix ); POS_fn_vGetRotationVector ( hCurrentMatrix, &p_stCurrentI, &p_stCurrentJ, &p_stCurrentK ); POS_fn_vGetRotationVector ( hPreviousMatrix, &p_stPreviousI, &p_stPreviousJ, &p_stPreviousK ); return !MTH3D_M_bEqualVector (p_stCurrentPosition,p_stPreviousPosition) || !MTH3D_M_bEqualVector (p_stCurrentI,p_stPreviousI) || !MTH3D_M_bEqualVector (p_stCurrentJ,p_stPreviousJ) || !MTH3D_M_bEqualVector (p_stCurrentK,p_stPreviousK); } MTH_tdxReal MEC_fn_xGetSlide (struct DNM_stDynamics *p_stDynamic,DNM_tdstMecObstacle *p_stObstacle) { MTH_tdxReal xSlide; GMT_tdxHandleToGameMaterial hGameMaterial; DNM_tdxHandleToMecMatCharacteristics hMatCharacteristics; hGameMaterial = hMatCharacteristics = NULL; if (!p_stObstacle) return MTH_C_ZERO; hGameMaterial = DNM_M_hObstacleGetCollidedMaterial (p_stObstacle); if (hGameMaterial!=NULL) hMatCharacteristics=GMT_fn_hGetMechanicsMaterial(hGameMaterial); xSlide = MTH_C_ZERO; /* type */ if (hGameMaterial && MEC_fn_bTypeOfGameMaterial (hGameMaterial,C_xDNM_SLIDE_TYPE_GAME_MATERIAL)) xSlide = MTH_C_ONE; /* game material */ if (hMatCharacteristics) xSlide = DNM_M_xObstacleGetSlide (p_stObstacle); /* collision control */ if (DNM_M_bDynamicsIsCollisionControl(p_stDynamic)) xSlide = DNM_M_xDynamicsGetSlide (p_stDynamic); return xSlide; } MTH_tdxReal MEC_fn_xGetRebound (struct DNM_stDynamics *p_stDynamic,DNM_tdstMecObstacle *p_stObstacle) { MTH_tdxReal xRebound; GMT_tdxHandleToGameMaterial hGameMaterial; DNM_tdxHandleToMecMatCharacteristics hMatCharacteristics; hGameMaterial = hMatCharacteristics = NULL; if (!p_stObstacle) return MTH_C_ZERO; hGameMaterial = DNM_M_hObstacleGetCollidedMaterial (p_stObstacle); if (hGameMaterial!=NULL) hMatCharacteristics=GMT_fn_hGetMechanicsMaterial(hGameMaterial); xRebound = MTH_C_ZERO; /* type */ if (hGameMaterial && MEC_fn_bTypeOfGameMaterial (hGameMaterial,C_xDNM_REBOUND_TYPE_GAME_MATERIAL)) xRebound = MTH_C_ONE; /* game material */ if (hMatCharacteristics) xRebound = DNM_M_xObstacleGetRebound (p_stObstacle); /* collsion control */ if (DNM_M_bDynamicsIsCollisionControl(p_stDynamic)) xRebound = DNM_M_xDynamicsGetRebound (p_stDynamic); return xRebound; } void MEC_fn_vComputeCollisionTranslation ( long lObstacle, DNM_tdstMecObstacle *p_stObstacle, MTH3D_tdstVector* p_stMove ) { long lCounter; MTH_tdxReal xRate/*, xNorm*/; DNM_tdstMecObstacle* p_stTmpObstacle; MTH3D_tdstVector stVector; for (lCounter=0; lCounter=1 */ MTH_tdxReal xTmpValue; if (xValue>=MTH_C_ONE) return xValue; if (xValue>MTH_C_ZERO) { xTmpValue = MTH_M_xSub ( MTH_C_ONE, xValue ); xTmpValue = MTH_M_xMul ( xTmpValue, xTmpValue ); xTmpValue = MTH_M_xMul ( xTmpValue, xTmpValue ); xTmpValue = MTH_M_xSub ( MTH_C_ONE, xTmpValue ); } else xTmpValue=MTH_C_ZERO; return xTmpValue; } #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ ACP_tdxBool MEC_fn_bVectorParallel ( MTH3D_tdstVector* p_stVector1, MTH3D_tdstVector* p_stVector2 ) { MTH_tdxReal xDotProd; MTH_tdxReal xProdNorm; xDotProd = MTH3D_M_xDotProductVector (p_stVector1,p_stVector2); xProdNorm = MTH_M_xMul ( MTH3D_M_xNormVector(p_stVector1), MTH3D_M_xNormVector(p_stVector2) ); return MTH_M_bLess ( MTH_M_xAbs(MTH_M_xSub(xDotProd,xProdNorm)), MTH_M_xDoubleToReal(0.01) ); } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC 04/06/99 */ void MEC_fn_vCheckMinVectorNorm ( MTH3D_tdstVector* p_stVector, MTH_tdxReal xLimit ) { MTH_tdxReal xNorm; xNorm = MTH3D_M_xNormVector (p_stVector); if (MTH_M_bLess(xNorm,xLimit)) { MTH3D_M_vNullVector (p_stVector); } } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC 04/06/99 */ /* * BackFace */ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC 04/06/99 */ void MEC_fn_vDeleteBackFace ( long lObstacle, DNM_tdstMecObstacle *p_stObstacle ) { long lCounter; MTH_tdxReal xDotProd; for (lCounter=0; lCounter