Code joystick

Code joystick

enum Direction { 
        CENTER = 0 , 
        UP, 
        DOWN, 
        LEFT, 
        RIGHT 
}; 

Direction JudgeUpDownLeftRight (CPoint pt, CPoint centre, int nCenterR) 
{ 
    // 不 包含 边界 计算
    int absToY = abs (pt.x - center.x);
    int absToX = abs (pt.y - center.y);
    if ((absToX <nCenterR) && 
        (absToY < nCenterR)) 
    { 
        return CENTER; 
    } 
    if (pt.x> = center.x && pt.y < center.y) 
    {
        if (absToX < absToY) 
        { 
            return RIGHT; 
        } 
        else 
        { 
            return UP; 
        } 
    } 
    else  if (pt.x <center.x && pt.y < center.y) 
    { 
        if (absToX < absToY) 
        { 
            return LEFT; 
        } 
        else 
        { 
            return UP; 
        } 
    } 
    else  if (pt.x <center.x && pt.y> = center.y) 
    { 
        if (absToX < absToY) 
        { 
            returnLA GAUCHE; 
        } 
        else 
        { 
            return DOWN; 
        } 
    } 
    else  / * if (pt.x> = center.x && pt.y> = center.y) * / 
    { 
        if (absToX < absToY) 
        { 
            return RIGHT; 
        } 
        else 
        { 
            return DOWN; 
        } 
    } 
}

 

Je suppose que tu aimes

Origine www.cnblogs.com/2018shawn/p/12750132.html
conseillé
Classement