为什么使用(360 * 16)而不是360度?

时间:2011-06-07 12:44:15

标签: qt graphics

我在使用Qt时注意到这一点,通过代码示例。

当他们尝试设置存储角度的变量的范围(在这种情况下为 angle )时,为什么需要360 乘以 16,而不是只有360?

代码(来自hellogl示例)是

static void qNormalizeAngle(int &angle)
{
    while (angle < 0)
        angle += 360 * 16;
    while (angle > 360 * 16)
        angle -= 360 * 16;
}

colloidingmice示例的另一个例子:

Mouse::Mouse()
    : angle(0), speed(0), mouseEyeDirection(0),
      color(qrand() % 256, qrand() % 256, qrand() % 256)
{
    setRotation(qrand() % (360 * 16));
}

承认我在Qt和图形编程方面几乎没有经验,也告诉我这是否在所有地方或仅在Qt中都很常见。

1 个答案:

答案 0 :(得分:5)

埋在this文章中:

  

将值乘以16   因为QPainter表示角度为   十六分之一。