示例#1
0
	/// ------------------------------------------------ //
	/// [4/18/2014 jianglei.kinly]
	/// 扇形
	/// ------------------------------------------------ //
	xObjectSet XGameMap::CaptureObjectBySector( const XVector3& vCenter, const XVector3& vDir, xgc_uint32 dwRadius, xgc_uint16 wAngle, const std::function< xgc_bool( xObject ) > &fnFilter/* = xgc_nullptr*/ )
	{
		// 计算旋转向量
		XVector3 vRotate = vDir.RotateZ( DEG2RAD( wAngle / 2 ) );
		xgc_real32 fDotValue = vDir.DotProduct( vRotate );
		auto fn = [&]( xObject hObject )->xgc_bool {
			if( xgc_nullptr == fnFilter || fnFilter( hObject ) )
			{
				XGameObject* pObj = ObjectCast<XGameObject>( hObject );
				XGC_ASSERT_RETURN( pObj, false );

				XVector3 vDistance = pObj->GetPosition() - vCenter;
				if( vDistance.SqurLength() > dwRadius * dwRadius * 1.0f )
					return false;

				if( vDir.DotProduct( vDistance ) < fDotValue )
					return false;

				return true;
			}

			return false;
		};

		iRect rc(
			WorldToArea( vCenter.x - dwRadius, vCenter.y - dwRadius ),
			WorldToArea( vCenter.x + dwRadius, vCenter.y + dwRadius ) );
		return FetchObject( rc, fn );
	}
示例#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;
}