MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / FindNearestPlayerPos

Method FindNearestPlayerPos

PanzerChasm/server/map.cpp:3086–3112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3084}
3085
3086bool Map::FindNearestPlayerPos( const m_Vec3& pos, m_Vec3& out_pos ) const
3087{
3088 if( players_.empty() )
3089 return false;
3090
3091 float min_square_distance= Constants::max_float;
3092 m_Vec3 nearest_player_pos;
3093
3094 const m_Vec2 z_minmax= players_.begin()->second->GetZMinMax();
3095 const float dz= ( z_minmax.x + z_minmax.y ) * 0.5f;
3096
3097 for( const PlayersContainer::value_type& player_value : players_ )
3098 {
3099 const Player& player= *player_value.second;
3100 const m_Vec3 player_pos_corrected= m_Vec3( player.Position().x, player.Position().y, player.Position().z + dz );
3101
3102 const float square_distance= ( player_pos_corrected - pos ).SquareLength();
3103 if( square_distance < min_square_distance )
3104 {
3105 nearest_player_pos= player_pos_corrected;
3106 min_square_distance= square_distance;
3107 }
3108 }
3109
3110 out_pos= nearest_player_pos;
3111 return true;
3112}
3113
3114float Map::GetFloorLevel( const m_Vec2& pos, const float radius ) const
3115{

Callers

nothing calls this directly

Calls 1

GetZMinMaxMethod · 0.80

Tested by

no test coverage detected