visualsenderplayer.cpp

来自「2009 ROBOCUP 仿真2DSERVER 源码」· C++ 代码 · 共 1,081 行 · 第 1/3 页

CPP
1,081
字号
VisualSenderPlayerV1::sendLowPlayer( const Player & player ){    const double ang = calcRadDir( player );    //const double un_quant_dist = calcUnQuantDist( player );    const double un_quant_dist2 = self().pos().distance2( player.pos() );    if ( std::fabs( ang ) < self().visibleAngle() * 0.5 )    {        const double quant_dist = calcQuantDist( std::sqrt( un_quant_dist2 ),                                                 self().distQStep() );        //double prob = ( ( quant_dist - TEAM_FAR_LENGTH )        //              / ( TEAM_TOOFAR_LENGTH - TEAM_FAR_LENGTH ) );        double prob = ( ( quant_dist - self().teamFarLength() )                        / ( self().teamTooFarLength() - self().teamFarLength() ) );        if ( decide( prob ) )        {            serializer().serializeVisualObject( transport(),                                                calcTFarName( player ),                                                calcDegDir( ang ) );        }        else        {            //prob = ( ( quant_dist - UNUM_FAR_LENGTH )            //         / ( UNUM_TOOFAR_LENGTH - UNUM_FAR_LENGTH ) );            prob = ( ( quant_dist - self().unumFarLength() )                     / ( self().unumTooFarLength() - self().unumFarLength() ) );            if ( decide( prob ) )            {                serializer().serializeVisualObject( transport(),                                                    calcUFarName( player ),                                                    calcDegDir( ang ) );            }            else            {                serializer().serializeVisualObject( transport(),                                                    calcName( player ),                                                    calcDegDir( ang ) );            }        }    }    else if ( un_quant_dist2 <= self().vis_distance2 )    {        serializer().serializeVisualObject( transport(),                                            calcCloseName( player ),                                            calcDegDir( ang ) );    }}voidVisualSenderPlayerV1::sendHighPlayer( const Player & player ){    const double ang = calcRadDir( player );    //const double un_quant_dist = calcUnQuantDist( player );    double un_quant_dist = self().pos().distance2( player.pos() );    if ( std::fabs( ang ) < self().visibleAngle() * 0.5 )    {        un_quant_dist = std::sqrt( un_quant_dist );        const double quant_dist = calcQuantDist( un_quant_dist,                                                 self().distQStep() );        //double prob = ( ( quant_dist - TEAM_FAR_LENGTH )        //              / ( TEAM_TOOFAR_LENGTH - TEAM_FAR_LENGTH ) );        double prob = ( ( quant_dist - self().teamFarLength() )                        / ( self().teamTooFarLength() - self().teamFarLength() ) );        if ( decide( prob ) )        {            serializer().serializeVisualObject( transport(),                                                calcTFarName( player ),                                                quant_dist,                                                calcDegDir( ang ) );        }        else        {            //prob = ( ( quant_dist - UNUM_FAR_LENGTH )            //         / ( UNUM_TOOFAR_LENGTH - UNUM_FAR_LENGTH ) );            prob = ( ( quant_dist - self().unumFarLength() )                     / ( self().unumTooFarLength() - self().unumFarLength() ) );            if ( decide( prob ) )            {                serializePlayer( player,                                 calcUFarName( player ),                                 quant_dist,                                 calcDegDir( ang ) );            }            else            {                double dist_chg, dir_chg;                calcVel( player.vel(), player.pos(),                         un_quant_dist, quant_dist,                         dist_chg, dir_chg );                serializePlayer( player,                                 calcName( player ),                                 quant_dist,                                 calcDegDir( ang ),                                 dist_chg,                                 dir_chg );            }        }    }    else if ( un_quant_dist <= player.vis_distance2 )    {        //un_quant_dist = std::sqrt( un_quant_dist );        serializer().serializeVisualObject( transport(),                                            calcCloseName( player ),                                            calcQuantDist( std::sqrt( un_quant_dist ),                                                           self().distQStep() ),                                            calcDegDir( ang ) );    }}boolVisualSenderPlayerV1::sendLine( const PObject & line ){    /*! the angle of an outward pointing normal ( 90degs to ) to      the line */    double line_normal;    //! perp distance of the player from the line    double player_2_line;    //! the x of y value of where the line starts    double line_start;    //! the x or y value of where the line stops    double line_stop;    //! a flag to specify if the line is vertical or horizontal    bool vert;    /*! be very carefull here.  The lines pos.x is actually it's      distance from the center of the field, not neccesarily it's      x position. */    //! left line    if ( line.pos().x == - ServerParam::PITCH_LENGTH*0.5 )    {        line_normal = M_PI;        if ( self().pos().x < line.pos().x )            line_normal = 0.0;        player_2_line = line.pos().x - self().pos().x;        line_start = - ServerParam::PITCH_WIDTH*0.5;        line_stop = ServerParam::PITCH_WIDTH*0.5;        vert = true;    }    //! right line    else if ( line.pos().x == ServerParam::PITCH_LENGTH*0.5 )    {        line_normal = 0.0;        if( self().pos().x > line.pos().x )            line_normal = M_PI;        player_2_line = line.pos().x - self().pos().x;        line_start = - ServerParam::PITCH_WIDTH*0.5;        line_stop = ServerParam::PITCH_WIDTH*0.5;        vert = true;    }    //! top line    else if ( line.pos().x == - ServerParam::PITCH_WIDTH*0.5 )    {        line_normal = -M_PI*0.5;        if ( self().pos().y < line.pos().x )            line_normal = M_PI*0.5;        player_2_line = line.pos().x - self().pos().y;        line_start = - ServerParam::PITCH_LENGTH*0.5;        line_stop = ServerParam::PITCH_LENGTH*0.5;        vert = false;    }    //! bottom line    else if ( line.pos().x == ServerParam::PITCH_WIDTH*0.5 )    {        line_normal = M_PI*0.5;        if ( self().pos().y > line.pos().x )            line_normal = -M_PI*0.5;        player_2_line = line.pos().x - self().pos().y;        line_start = - ServerParam::PITCH_LENGTH*0.5;        line_stop = ServerParam::PITCH_LENGTH*0.5;        vert = false;    }    else    {        std::cerr << __FILE__ << ": " << __LINE__                  << ": Error, unknown line: " << line << std::endl;        return false;    }    //! angle between the players line of sight and the line's normal    double sight_2_line_ang = calcLineRadDir( line_normal );    /*! if the angle between the line of sight and the line's norm      is not within -90.0 and 90 degrees then the player is      looking parallel or away from the line, thus it cannot be      visible. */    if ( std::fabs( sight_2_line_ang ) >= M_PI*0.5 )    {        return false;    }    /*! this gives us the x or y offset from the player for where      their line of sight intersects the line */    double line_intersect = player_2_line * std::tan( sight_2_line_ang );    /*! this calculates the actual x or y value for where the line      of sight intersects the line.  Because the y axis is      inverted, we need to use -line_intersect if the line is      vertical. */    if ( vert )        line_intersect = self().pos().y - line_intersect;    else        line_intersect += self().pos().x;    /*! If the point that the players line of sight intersects the      line beyond it's beginning or end then the player wont see      this line */    if ( line_intersect < line_start         || line_intersect > line_stop )    {        return false;    }    serializeLine( calcName( line ),                   calcLineDir( sight_2_line_ang ),                   sight_2_line_ang, player_2_line );    return true;}voidVisualSenderPlayerV1::serializeLowLine( const std::string & name,                                        const int dir,                                        const double &, const double & ){    serializer().serializeVisualObject( transport(), name, dir );}voidVisualSenderPlayerV1::serializeHighLine( const std::string & name,                                         const int dir,                                         const double & sight_2_line_ang,                                         const double & player_2_line ){    double dist = calcLineDist( sight_2_line_ang, player_2_line,                                self().landDistQStep() );    serializer().serializeVisualObject( transport(), name, dist, dir );}voidVisualSenderPlayerV1::calcVel( const PVector & obj_vel,                               const PVector & obj_pos,                               const double & un_quant_dist,                               const double & quant_dist,                               double& dist_chg,                               double& dir_chg ) const{    if ( un_quant_dist != 0.0 )    {        const PVector vtmp = obj_vel - self().vel();        PVector etmp = obj_pos - self().pos();        etmp /= un_quant_dist;        dist_chg = vtmp.x * etmp.x + vtmp.y * etmp.y;//         dir_chg = RAD2DEG * ( vtmp.y * etmp.x//                               - vtmp.x * etmp.y ) / un_quant_dist;        dir_chg = vtmp.y * etmp.x - vtmp.x * etmp.y;        dir_chg /= un_quant_dist;        dir_chg *= RAD2DEG;        dir_chg = ( dir_chg == 0.0                    ? 0.0                    : Quantize( dir_chg, self().dirQStep() ) );        dist_chg = ( quant_dist                     * Quantize( dist_chg                                 / un_quant_dist, 0.02 ) );    }    else    {        dir_chg = 0.0;        dist_chg = 0.0;    }}voidVisualSenderPlayerV1::serializePlayer( const Player &,                                       const std::string & name,                                       const double & dist,                                       const int dir,                                       const double & dist_chg,                                       const double & dir_chg ){    serializer().serializeVisualObject( transport(),                                        name,                                        dist, dir,                                        dist_chg, dir_chg );}voidVisualSenderPlayerV1::serializePlayer( const Player &,                                       const std::string & name,                                       const double & dist,                                       const int dir ){    serializer().serializeVisualObject( transport(),                                        name,                                        dist,                                        dir );}// const// std::string &// VisualSenderPlayerV1::calcName( const PObject & obj ) const// {//     return obj.name();// }// const// std::string &// VisualSenderPlayerV1::calcCloseName( const PObject & obj ) const// {//     return obj.closeName();// }// const// std::string &// VisualSenderPlayerV1::calcTFarName( const Player & obj ) const// {//     return obj.nameTooFar();// }// const// std::string &// VisualSenderPlayerV1::calcUFarName( const Player & obj ) const// {//     return obj.nameFar();// }/*!//===================================================================////  CLASS: VisualSenderPlayerV4////  DESC: Class for the version 4 visual protocol.  This version//        introduced body directions of players. Everything else is//        the same.////===================================================================*/VisualSenderPlayerV4::VisualSenderPlayerV4( const Params & params )    : VisualSenderPlayerV1( params ){}VisualSenderPlayerV4::~VisualSenderPlayerV4(){}void

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?