int KHero::LuaChangeFaceDir(Lua_State* L) { BOOL bRetCode = false; int nTopIndex = 0; int nFaceDir = 0; nTopIndex = Lua_GetTopIndex(L); KGLOG_PROCESS_ERROR(nTopIndex == 1); nFaceDir = (int)Lua_ValueToNumber(L, 1); SetFaceDir((KTWO_DIRECTION)nFaceDir, true); Exit0: return 0; }
BOOL CObject_Dynamic::CalcMoveDir( VOID ) { if ( m_listPathNode.empty() ) return FALSE; fVector3 fvNextPos; fVector2 fvNextPos2D; fvNextPos = (*m_listPathNode.begin()); fvNextPos2D.x = fvNextPos.x; fvNextPos2D.y = fvNextPos.z; FLOAT fYAngle = TDU_GetYAngle( fVector2(GetPosition().x, GetPosition().z), fvNextPos2D); SetFaceDir( fYAngle ); return TRUE; }
VOID CObject_Bus::CreateRenderInterface(VOID) { if(m_pBusData != NULL && m_pBusData->m_nModelID != INVALID_ID) { DBC_DEFINEHANDLE(s_pCharModelDBC, DBC_CHARACTER_MODEL) LPCSTR lpszModelFileName = NULL; const _DBC_CHARACTER_MODEL *pCharModel = (const _DBC_CHARACTER_MODEL*)(s_pCharModelDBC->Search_Index_EQU(m_pBusData->m_nModelID)); if (pCharModel != NULL) { lpszModelFileName = pCharModel->m_pszModelName; } if (lpszModelFileName != NULL) { m_pRenderInterface = CGameProcedure::s_pGfxSystem->New_EntityObject(tEntityNode::ETYPE_ACTOR); m_pRenderInterface->SetData(GetID()); m_pRenderInterface->Actor_SetFile(lpszModelFileName); setVisible(isVisible()); m_pRenderInterface->SetRayQuery(FALSE); BOOL bEnable = (isVisible() && CGameProcedure::s_pVariableSystem->GetAs_Int("View_HumanLightmap") == 1); if(bEnable) { m_pRenderInterface->Attach_ProjTexture(tEntityNode::SHADOW_BLOB, GetShadowRange()); } m_pRenderInterface->SetAnimationEndEvent( (FUNC_ONANIMATIONENDEX)(CObject_Bus::_OnAnimationEnd), (DWORD)GetID() ,0); UpdatePassengerAttached(); UpdateCharActionSetFile(); SetPosition(GetPosition()); SetFaceDir( GetFaceDir() ); setVisible(isVisible()); } } }
BOOL CObject_Bus::Tick_Move(UINT uElapseTime) { FLOAT fElapseTime = (FLOAT)uElapseTime / 1000.f; FLOAT fMoveDist = fElapseTime * GetMoveSpeed(); FLOAT fDist = KLU_GetDist(fVector3(GetPosition().x, 0.f, GetPosition().z), fVector3(m_fvMoveTargetPos.x, 0.f, m_fvMoveTargetPos.z)); if(fMoveDist >= fDist) { if(m_fvMoveTargetPos.y <= DEF_BUS_PATH_NODE_INVALID_Y) { SetMapPosition(fVector2(m_fvMoveTargetPos.x, m_fvMoveTargetPos.z)); } else { SetPosition(m_fvMoveTargetPos); } StopMove(); } else { if(fDist > 0.f) { fVector3 fvThisPos = GetPosition(); fVector3 fvLen = m_fvMoveTargetPos - fvThisPos; if(m_fvMoveTargetPos.y <= DEF_BUS_PATH_NODE_INVALID_Y) { fvThisPos.x += (fvLen.x/fDist) * fMoveDist; fvThisPos.z += (fvLen.z/fDist) * fMoveDist; SetMapPosition(fVector2(fvThisPos.x, fvThisPos.z)); } else { fvThisPos.x += (fvLen.x/fDist) * fMoveDist; fvThisPos.y += (fvLen.y/fDist) * fMoveDist; fvThisPos.z += (fvLen.z/fDist) * fMoveDist; SetPosition(fvThisPos); } } } FLOAT fFaceDir = GetFaceDir(); if(fabsf(m_fTargetDir - fFaceDir) > 0.01f) { if(fabsf(m_fTargetDir - fFaceDir) < __PI * 5.f / 4.f && fabsf(m_fTargetDir - fFaceDir) > __PI * 3.f / 4.f) { SetFaceDir(m_fTargetDir); } else { FLOAT fElapseDir = fElapseTime * __PI; if(m_fTargetDir - fFaceDir > __PI || (m_fTargetDir - fFaceDir < 0.f && m_fTargetDir - fFaceDir > -__PI)) {// 正转 fFaceDir -= fElapseDir; if(fFaceDir < 0.f) { fFaceDir += 2.f *__PI; } SetFaceDir(fFaceDir); } else {// 反转 fFaceDir += fElapseDir; if(fFaceDir > m_fTargetDir) { fFaceDir = m_fTargetDir; } SetFaceDir(fFaceDir); } } } return TRUE; }