/// ------------------------------------------------ // /// [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 ); }