当前位置: 首页>>代码示例>>C++>>正文


C++ Rect2D::contains方法代码示例

本文整理汇总了C++中Rect2D::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ Rect2D::contains方法的具体用法?C++ Rect2D::contains怎么用?C++ Rect2D::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rect2D的用法示例。


在下文中一共展示了Rect2D::contains方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

/*!

 */
bool
RoleGoalie::execute( PlayerAgent * agent )
{
    static const Rect2D our_penalty( Vector2D( -ServerParam::i().pitchHalfLength(),
                                               -ServerParam::i().penaltyAreaHalfWidth() + 1.0 ),
                                     Size2D( ServerParam::i().penaltyAreaLength() - 1.0,
                                             ServerParam::i().penaltyAreaWidth() - 2.0 ) );

    //////////////////////////////////////////////////////////////
    // play_on play

    // catchable
    if ( agent->world().time().cycle()
         > agent->world().self().catchTime().cycle() + ServerParam::i().catchBanCycle()
         && agent->world().ball().distFromSelf() < ServerParam::i().catchableArea() - 0.05
         && our_penalty.contains( agent->world().ball().pos() ) )
    {
        dlog.addText( Logger::ROLE,
                      __FILE__": catchable. ball dist=%.1f, my_catchable=%.1f",
                      agent->world().ball().distFromSelf(),
                      ServerParam::i().catchableArea() );
        agent->doCatch();
        agent->setNeckAction( new Neck_TurnToBall() );
    }
    else if ( agent->world().self().isKickable() )
    {
        doKick( agent );
    }
    else
    {
        doMove( agent );
    }

    return true;
}
开发者ID:4SkyNet,项目名称:HFO,代码行数:38,代码来源:role_goalie.cpp

示例2: xxx

/*!

 */
bool
ShootGenerator::maybeGoalieCatch( const PlayerObject * goalie,
                                  Course & course )
{
    static const Rect2D penalty_area( Vector2D( ServerParam::i().theirPenaltyAreaLineX(),
                                                -ServerParam::i().penaltyAreaHalfWidth() ),
                                      Size2D( ServerParam::i().penaltyAreaLength(),
                                              ServerParam::i().penaltyAreaWidth() ) );
    static const double CONTROL_AREA_BUF = 0.15;  // buffer for kick table

    const ServerParam & SP = ServerParam::i();

    const PlayerType * ptype = goalie->playerTypePtr();

    const int min_cycle = FieldAnalyzer::estimate_min_reach_cycle( goalie->pos(),
                                                                   ptype->realSpeedMax(),
                                                                   M_first_ball_pos,
                                                                   course.ball_move_angle_ );
    if ( min_cycle < 0 )
    {
#ifdef DEBUG_PRINT
        dlog.addText( Logger::SHOOT,
                      "%d: (goalie) never reach" );
#endif
        return false;
    }

    const double goalie_speed = goalie->vel().r();
    const double seen_dist_noise = goalie->distFromSelf() * 0.02;

    const int max_cycle = course.ball_reach_step_;

#ifdef DEBUG_PRINT
    dlog.addText( Logger::SHOOT,
                  "%d: (goalie) minCycle=%d maxCycle=%d",
                  M_total_count,
                  min_cycle, max_cycle );
#endif

    for ( int cycle = min_cycle; cycle < max_cycle; ++cycle )
    {
        const Vector2D ball_pos = inertia_n_step_point( M_first_ball_pos,
                                                        course.first_ball_vel_,
                                                        cycle,
                                                        SP.ballDecay() );
        if ( ball_pos.x > SP.pitchHalfLength() )
        {
#ifdef DEBUG_PRINT
            dlog.addText( Logger::SHOOT,
                          "%d: (goalie) cycle=%d in the goal",
                          M_total_count, cycle );
#endif
            break;
        }

        const bool in_penalty_area = penalty_area.contains( ball_pos );

        const double control_area = ( in_penalty_area
                                      ? SP.catchableArea()
                                      : ptype->kickableArea() );

        Vector2D inertia_pos = goalie->inertiaPoint( cycle );
        double target_dist = inertia_pos.dist( ball_pos );

        if ( in_penalty_area )
        {
            target_dist -= seen_dist_noise;
        }

        if ( target_dist - control_area - CONTROL_AREA_BUF < 0.001 )
        {
#ifdef DEBUG_PRINT
            dlog.addText( Logger::SHOOT,
                          "%d: xxx (goalie) can catch. cycle=%d ball_pos(%.2f %.2f)"
                          " dist_from_goalie=%.3f",
                          M_total_count,
                          cycle,
                          ball_pos.x, ball_pos.y,
                          target_dist );
#endif
            return true;
        }

        double dash_dist = target_dist;
        if ( cycle > 1 )
        {
            //dash_dist -= control_area * 0.6;
            //dash_dist *= 0.95;
            dash_dist -= control_area * 0.9;
            dash_dist *= 0.999;
        }

        int n_dash = ptype->cyclesToReachDistance( dash_dist );

        if ( n_dash > cycle + goalie->posCount() )
        {
#ifdef DEBUG_PRINT
//.........这里部分代码省略.........
开发者ID:UNiQ10,项目名称:HFO,代码行数:101,代码来源:shoot_generator.cpp

示例3: onEvent

bool _GuiSliderBase::onEvent(const GEvent& event) {
    if (! m_visible) {
        return false;
    }

    if (event.type == GEventType::MOUSE_BUTTON_DOWN) {
        Vector2 mouse = Vector2(event.button.x, event.button.y);

        float v = floatValue();
        Rect2D thumbRect = theme()->horizontalSliderToThumbBounds(m_rect, v, m_captionSize);
        Rect2D trackRect = theme()->horizontalSliderToTrackBounds(m_rect, m_captionSize);
        
        if (thumbRect.contains(mouse)) {
            // Begin drag
            m_inDrag = true;
            m_dragStart = mouse;
            m_dragStartValue = v;

            GEvent response;
            response.gui.type = GEventType::GUI_DOWN;
            response.gui.control = m_eventSource;
            m_gui->fireEvent(response);

            response.gui.type = GEventType::GUI_CHANGE;
            response.gui.control = m_eventSource;
            m_gui->fireEvent(response);

            return true;
        } else if (trackRect.contains(mouse)) {
            // Jump to this position
            float p = clamp((mouse.x - trackRect.x0()) / trackRect.width(), 0.0f, 1.0f);
            setFloatValue(p);
            m_inDrag = false;

            GEvent response;
            response.gui.type = GEventType::GUI_CHANGE;
            response.gui.control = m_eventSource;
            m_gui->fireEvent(response);

            fireEvent(GEventType::GUI_ACTION);
            return true;
        }

    } else if (event.type == GEventType::MOUSE_BUTTON_UP) {
        if (m_inDrag) {
            // End the drag
            m_inDrag = false;

            fireEvent(GEventType::GUI_DOWN);
            fireEvent(GEventType::GUI_ACTION);

            return true;
        }

    } else if (m_inDrag && (event.type == GEventType::MOUSE_MOTION)) {
        // We'll only receive these events if we have the keyFocus, but we can't
        // help receiving the key focus if the user clicked on the control!

        Vector2 mouse = Vector2(event.button.x, event.button.y);
        Rect2D trackRect = theme()->horizontalSliderToTrackBounds(m_rect, m_captionSize);

        float delta = (mouse.x - m_dragStart.x) / trackRect.width();
        float p = clamp(m_dragStartValue + delta, 0.0f, 1.0f);
        setFloatValue(p);

        GEvent response;
        response.gui.type = GEventType::GUI_CHANGE;
        response.gui.control = m_eventSource;
        m_gui->fireEvent(response);

        return true;
    }
    return false;
}
开发者ID:luaman,项目名称:g3d-cvs,代码行数:74,代码来源:GuiSlider.cpp

示例4: onEvent

bool GuiScrollBar::onEvent(const GEvent& event) {
    if (! m_visible) {
        return false;
    }
    float m = maxValue();
        Rect2D topB;
        Rect2D bottomB; 
        Rect2D barBounds;
        Rect2D thumbBounds;

        getAllBounds(topB, bottomB, barBounds, thumbBounds);
    if (event.type == GEventType::MOUSE_BUTTON_DOWN) {
       
        const Vector2& mouse = Vector2(event.button.x, event.button.y);
      
        if(bottomB.contains(mouse)) {
            *m_value = min<float>( m * m_extent, *m_value + m_extent * BUTTON_PRESS_SCROLL);
            m_state = ARROW_DOWN_SCROLLING;
            GEvent response;

            response.gui.type = GEventType::GUI_CHANGE;
            response.gui.control = m_eventSource;
            m_gui->fireEvent(response);

            fireEvent(GEventType::GUI_ACTION);
            return true;

        } else if (topB.contains(mouse)) {

            *m_value = max<float>( 0.0f, *m_value - m_extent*BUTTON_PRESS_SCROLL);

            m_state = ARROW_UP_SCROLLING;

            GEvent response;
            response.gui.type = GEventType::GUI_CHANGE;
            response.gui.control = m_eventSource;
            m_gui->fireEvent(response);

            fireEvent(GEventType::GUI_ACTION);
            return true;

        } else if (thumbBounds.contains(mouse)) {
            m_state = IN_DRAG;
            m_dragStart = mouse;
            m_dragStartValue = floatValue();
            
            GEvent response;
            response.gui.type = GEventType::GUI_DOWN;
            response.gui.control = m_eventSource;
            m_gui->fireEvent(response);

            response.gui.type = GEventType::GUI_CHANGE;
            response.gui.control = m_eventSource;
            m_gui->fireEvent(response);

            return true;

        } else if (barBounds.contains(mouse)) {
            // Jump to this position
            float p;
            if(m_vertical) {
                p =  ( mouse.y - (float)barBounds.y0() ) / ((float)barBounds.height()/(m + 1)) - .5f;
            } else {
                p = ( mouse.x - (float)barBounds.x0() ) / ((float)barBounds.width()/(m + 1)) - .5f;
            }
            p = max<float>(0, p);
            p = min<float>(p, m);
            setFloatValue(p);

            m_state = NONE;

            GEvent response;
            response.gui.type = GEventType::GUI_CHANGE;
            response.gui.control = m_eventSource;
            m_gui->fireEvent(response);

            fireEvent(GEventType::GUI_ACTION);
            return true;
        }

        return false;

    } else if (event.type == GEventType::MOUSE_BUTTON_UP) {

        m_state = NONE;

        fireEvent(GEventType::GUI_ACTION);
        if (m_state == IN_DRAG) {
            // End the drag

            fireEvent(GEventType::GUI_DOWN);
            fireEvent(GEventType::GUI_ACTION);

            return true;
        }

    } else if (event.type == GEventType::MOUSE_MOTION) {

        // We'll only receive these events if we have the keyFocus, but we can't
        // help receiving the key focus if the user clicked on the control!
//.........这里部分代码省略.........
开发者ID:elfprince13,项目名称:G3D10,代码行数:101,代码来源:GuiScrollBar.cpp


注:本文中的Rect2D::contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。