Exemplo n.º 1
0
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());
		}
	}
}
Exemplo n.º 2
0
BOOL CObject_Dynamic::DoMove( FLOAT fElapseTime, FLOAT fSpeed )
{
	const fVector3* pRrePos = GetPrevPathNode();
	if ( m_listPathNode.empty() )
		return FALSE;

	// 当前位置
	fVector3 fvCurPos = GetPosition();
	// 当前的目标路径点
	fVector3 fvBeginPathNode = (*m_listPathNode.begin());

	// 当前位置与当前的目标路径点的距离
	fVector3 fvDistToBeginPathNode = fvBeginPathNode - fvCurPos;
	FLOAT fDir = GetFaceDir();

	// 这一帧可移动的路径长度
	FLOAT fMoveDist = fSpeed * fElapseTime;
	FLOAT fMoveDistSq = fMoveDist * fMoveDist;

	// 当前位置与当前的目标路径点路径长度的平方
	FLOAT fDistToBeginPathNodeSq = fvDistToBeginPathNode.x * fvDistToBeginPathNode.x + fvDistToBeginPathNode.z * fvDistToBeginPathNode.z;

	// 如果这一帧可移动的路径长度小于当前位置到当前的目标路径点路径长度
	if ( fDistToBeginPathNodeSq > fMoveDistSq )
	{
		FLOAT fTarDist = sqrt(fDistToBeginPathNodeSq) ;
		FLOAT fDistX = (fMoveDist*(fvBeginPathNode.x-fvCurPos.x))/fTarDist ;
		FLOAT fDistZ = (fMoveDist*(fvBeginPathNode.z-fvCurPos.z))/fTarDist ;
		
		
		fVector2 fvPos;
		fvPos.x = fvCurPos.x + fDistX;
		fvPos.y = fvCurPos.z + fDistZ;
		
		//需要位置修正,防止因为误差走入阻挡区内部
		if( CObjectManager::GetMe()->GetMySelf() == this && CPath::IsPointInUnreachRegion(fvPos))
		{
			fvPos = TDU_GetReflect(
						fVector2(pRrePos->x, pRrePos->z),
						fVector2(fvBeginPathNode.x, fvBeginPathNode.z),
						fvPos);//

		}

		SetMapPosition( fvPos );
	}
	else
	{
		fVector2 fvPos;
		// 目标路径是最后一点
		if ( !NextPathNode() )
		{
			fvPos.x = fvBeginPathNode.x;
			fvPos.y = fvBeginPathNode.z;
			//需要位置修正,防止因为误差走入阻挡区内部
			if( CObjectManager::GetMe()->GetMySelf() == this && CPath::IsPointInUnreachRegion(fvPos))
			{
				//行走路线的镜像点, 点pRrePos 与 fvBeginPathNode不能是同一个点
				fvPos = TDU_GetReflect(
							fVector2(pRrePos->x, pRrePos->z),
							fVector2(fvBeginPathNode.x, fvBeginPathNode.z),
							fvPos);//
			}

			SetMapPosition( fvPos );
			OnMoveStop( );
		}
		else
		{
			FLOAT fDistToBeginPathNode = sqrt( fDistToBeginPathNodeSq );
			fMoveDist -= fDistToBeginPathNode;

			fvPos.x = fvBeginPathNode.x;
			fvPos.y = fvBeginPathNode.z;
			SetMapPosition( fvPos );
			CalcMoveDir();
			fDir = GetFaceDir();

			FLOAT fDistX = sin( fDir ) * fMoveDist;
			FLOAT fDistZ = cos( fDir ) * fMoveDist;
			fvCurPos = fvBeginPathNode;
			fvPos.x = fvCurPos.x + fDistX;
			fvPos.y = fvCurPos.z + fDistZ;
			
			//需要位置修正,防止因为误差走入阻挡区内部
			if( CObjectManager::GetMe()->GetMySelf() == this && CPath::IsPointInUnreachRegion(fvPos))
			{
				// 得到新的映射向量
				pRrePos = GetPrevPathNode();
				fvBeginPathNode = (*m_listPathNode.begin());

				//行走路线的镜像点, 点pRrePos 与 fvBeginPathNode不能是同一个点
				fvPos = TDU_GetReflect(
							fVector2(pRrePos->x, pRrePos->z),
							fVector2(fvBeginPathNode.x, fvBeginPathNode.z),
							fvPos);//

			}//
			
			SetMapPosition( fvPos );
		}

//		RegisterToZone();
	}
	return TRUE;
}
Exemplo n.º 3
0
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;
}