Beispiel #1
0
//---------------------------------------------------//
// [8/4/2009 Albert]
// Description:	清除路径点
//---------------------------------------------------//
void CDynamicObject::BeginPathPoint()
{
	if( m_hUpdateTimer != INVALID_TIMER_HANDLE )
	{
		unsigned int release_time = ThisTimer()->remove_event( m_hUpdateTimer );
		m_hUpdateTimer = INVALID_TIMER_HANDLE;

		if( release_time > 0 )
		{
			// 计算向量
			XVector3 Vec = m_vNextPosition - GetPosition();
			Vec.NormalizeFast();
			// 剩余了多少距离
			Vec *= release_time/1000.0f;
			// 下此更新坐标和剩余距离的差值则为当前的位置
			m_vNextPosition -= Vec;

			CGameMap* pScene = static_cast< CGameMap* >( CXObjectPool::GetInstance().GetObj( GetParent(), TypeGameMap ) );
			if( pScene )
			{
				if( pScene->DynamicMoveTo( this, m_vNextPosition, false ) )
				{
					OnStep( m_vNextPosition );
				}
			}
		}
	}
	m_PointList.clear();
}
Beispiel #2
0
//---------------------------------------------------//
// [8/5/2009 Albert]
// Description:	移动定时器
//---------------------------------------------------//
bool CDynamicObject::UpdateTimer( unsigned int handle, unsigned short& repeat, unsigned int& timer )
{
	repeat = 1;
	timer = TIMER_SECONDS(1.0f);

	// 先移动到当前所在的位置.
	CGameMap* pScene = static_cast< CGameMap* >( CXObjectPool::GetInstance().GetObj( GetParent(), TypeGameMap ) );
	if( pScene )
	{
		if( pScene->DynamicMoveTo( this, m_vNextPosition, false ) )
		{
			//CLogger::GetInstance(_T("Log"))->WriteLog( _T("角色[%08x]移动到路点[%f,%f,%f]")
			//	, GetObjID()
			//	, m_vNextPosition[0], m_vNextPosition[1], m_vNextPosition[2] );
			OnStep( m_vNextPosition );
		}
		else
		{
			OnArrived( m_vNextPosition );
			return true;
		}
	}
	else
	{
		m_hUpdateTimer = INVALID_TIMER_HANDLE;
		return true;
	}

	// 计算下一个点
	if( m_PointList.empty() ) 
	{
		m_hUpdateTimer = INVALID_TIMER_HANDLE;
		OnArrived( m_vNextPosition );
		return true;
	}

	const PathPoint& target = m_PointList.front();

	XVector3 Vec = target.vPosition - m_vNextPosition;

	float distance = Vec.SqurLength();
	float fSpeed = target.fSpeed;
	if( distance < fSpeed*fSpeed )
	{
		// 当前坐标到目标点的距离小于速度值
		m_vNextPosition = target.vPosition;

		float t = XMath::Sqrt( distance )/fSpeed;
		timer = TIMER_SECONDS(t);
		m_PointList.pop_front();
	}
	else
	{
		Vec.NormalizeFast();
		Vec *= fSpeed;
		m_vNextPosition += Vec;
	}

	return false;
}