#ifndef __PUBLICMATH_H__ #define __PUBLICMATH_H__ #include "SinTable.h" #include // ¹Ý¿Ã¸² ÇÔ¼ö #define round(dTemp) ( long( dTemp + (dTemp > 0 ? 0.5 : -0.5 ) ) ) inline int Math_GetAngle(const WzVector* pvNormal) { int iAngle = g_SinTable.FACOS( pvNormal->x ); if( pvNormal->y < 0.0f ) { iAngle = 360 - iAngle; } return iAngle; } inline void Math_ZRotateVector(const WzVector* pwzVector, WzVector& wvRotate, int iAngle) { wvRotate.x = pwzVector->x * g_SinTable.FCOS(iAngle) + pwzVector->y * g_SinTable.FSIN(iAngle); wvRotate.y = -pwzVector->x * g_SinTable.FSIN(iAngle) + pwzVector->y * g_SinTable.FCOS(iAngle); wvRotate.z = pwzVector->z; } // xÃàÀÇ ¾çÀÇ ¹æÇâÀ» 0µµ·Î ½ÃÀÛÇÏ´Â º¤ÅÍÀÇ ¹æÇâ°¢À» ¸®ÅÏÇØÁØ´Ù. ¸Þ¸ð¸®¿¡ ´ã¾Æ³õÀº FACOS() °ªÀ» »ç¿ëÇÔ. (0µµ ~ 360µµ) inline int Math_GetAngleFromVector2(const WzVector* pwvDir) { WzVector vNormal; VectorNormalize(&vNormal, pwvDir); return Math_GetAngle( &vNormal ); } inline float Math_VectorLength( const WzVector& vec1, const WzVector& vec2) { WzVector tmp = vec1 - vec2; return VectorLength(&tmp); } inline float Math_VectorLength2( const WzVector& vec1, const WzVector& vec2) { WzVector tmp = vec1 - vec2; return VectorLength2(&tmp); } // x, y Æò¸é»óÀÇ °Å¸®¸¦ ±¸ÇØÁØ´Ù. inline float Math_Vector2DLength(const WzVector* pwzVector) { return (float)( sqrt(pwzVector->x * pwzVector->x + pwzVector->y * pwzVector->y) ); } inline float Math_Vector2DLength2(const WzVector* pwzVector) { return pwzVector->x * pwzVector->x + pwzVector->y * pwzVector->y; } inline float Math_Vector2DLength(const WzVector& vec1, const WzVector& vec2) { WzVector tmp = vec1 - vec2; return Math_Vector2DLength(&tmp); } inline float Math_Vector3DLength(const WzVector *pwzVector) { return (float)( sqrt(pwzVector->x * pwzVector->x + pwzVector->y * pwzVector->y + pwzVector->z * pwzVector->z) ); } inline float Math_Vector3DLength(const WzVector& vec1, const WzVector& vec2) { WzVector tmp = vec1 - vec2; return Math_Vector3DLength(&tmp); } //------------------------------------------------------------------------------------------------- // - d // -- // -- // -- // -- // -- // a ---------------------> b // -- // -- c(°Ë»ç´ë»ó) // -- // -- // - e // // ÁÂÇ¥ a, b, c, d, e°¡ ÀÖÀ» ¶§ // pwvTargetPos: ÁÂÇ¥ c // pwvAttackerPos: ÁÂÇ¥ a // pwvMainTargetDir: º¤ÅÍ a->b // iSrcAngle: º¤ÅÍ a->d¿Í º¤ÅÍ a->e°¡ ÀÌ·ç´Â °¢ //------------------------------------------------------------------------------------------------- // ºÎä²Ã ¸ð¾çÀÇ ¿µ¿ª¿¡ µé¾î°¡´ÂÁö Ã¼Å©ÇØÁØ´Ù. inline bool Math_IsPositionInFanshapedArea(const WzVector* pwvTargetPos, const WzVector* pwvAttackerPos, const WzVector* pwvMainTargetDir, int iSrcAngle) { WzVector vTargetDirNormal, vMainTargetDirNormal; WzVector vTargetVec = *pwvTargetPos - *pwvAttackerPos; WzVector vMainTargetDir = *pwvMainTargetDir; vTargetVec.z = 0.0f; vMainTargetDir.z = 0.0f; VectorNormalize( &vTargetDirNormal, &vTargetVec ); VectorNormalize( &vMainTargetDirNormal, &vMainTargetDir ); float fInner = vTargetDirNormal.x * vMainTargetDirNormal.x + vTargetDirNormal.y * vMainTargetDirNormal.y; bool bRet = ( fInner >= g_SinTable.FCOS(iSrcAngle / 2) ) || !fInner; return bRet; } //inline VOID LogToFile(char *FileName, const char *Content,...) //{ // char Buf[1024]; // char TimeBuf[128]; // int Count; // FILE *fp; // va_list arglist; // va_start(arglist,Content); // Count = vsprintf(Buf, Content, arglist); // fp = fopen(FileName, "at"); // _strtime( TimeBuf ); // fprintf(fp,"[%s] %s\n", TimeBuf, Buf); // fclose(fp); // va_end(arglist); //} inline bool Math_IsPositionInOBB(const WzVector* pvStart, const WzVector* pvEnd, float fWidth, const WzVector* pvTarget) { WzVector vDiff = *pvStart - *pvEnd; WzVector vCenter = (*pvStart + *pvEnd) * 0.5f; vDiff.z = 0.0f; vCenter.z = 0.0f; // µÎÁÂÇ¥°¡ Â÷À̰¡¾øÀ¸¸é Ÿ°ÙÀÌ ¾øÀ½À» ¸®ÅÏ if (vDiff.x == 0 && vDiff.y == 0) { #ifdef _NA_006622_20130408_BUG_DASH_AND_PIERCE_SKILL // 2013.04.09 ¹Î°æ½Â / À̺κп¡ ÀÇÇØ¼­ À̵¿Çü+°üÅëÇü ½ºÅ³ÀÌ ·çÇÁ¸¦ Çѹø¸¸ µ¹¾Æ¼­ ´Ù¼öÀÇ ÀûÀ» °ø°ÝÇÏÁö ¸øÇÑ´Ù. #else return FALSE; #endif //_NA_006622_20130408_BUG_DASH_AND_PIERCE_SKILL } #ifdef _NA_006622_20130408_BUG_DASH_AND_PIERCE_SKILL if (vDiff.x <= 0.01f && vDiff.y <= 0.01f) { vDiff.x = 0.0f; vDiff.y = 0.0f; } #endif //_NA_006622_20130408_BUG_DASH_AND_PIERCE_SKILL float fLength = VectorLength(&vDiff); VectorNormalize(&vDiff,&vDiff); // Ãà °è»ê~ float fAxis1X = vDiff.x; float fAxis1Y = vDiff.y; float fAxis2X = vDiff.y; float fAxis2Y = -vDiff.x; // ¸ñÇ¥ÀÇ ÁÂÇ¥¸¦ Ãà º¯È¯~ WzVector vOffset = *pvTarget - vCenter; float fNewAxisX = -(vOffset.x * fAxis2Y + vOffset.y * -fAxis1Y); float fNewAxisY = -(vOffset.x * -fAxis2X + vOffset.y * fAxis1X); // DEBUG: float fDet = fAxis1X * fAxis2Y - fAxis1Y * fAxis2X; // º¯È¯µÈ ÃàÁÂÇ¥°¡ »ç°¢Çü¾È¿¡ µé¾î°¡´ÂÁö üũ if (fabs(fNewAxisX) <= fLength * 0.5f) { if (fabs(fNewAxisY) <= fWidth * 0.5f) { return TRUE; } } return FALSE; } #endif