0
我从奇趣科技Qt的教程学习Qt的这些日子,关于计算子弹的位置在this page源代码我'困惑:混乱的源代码CH11
QRect CannonField::shotRect() const
{
const double gravity = 4;
double time = timerCount/20.0;
double velocity = shootForce;
double radians = shootAngle * 3.14159265/180;
double velx = velocity * cos(radians);
double vely = velocity * sin(radians);
double x0 = (barrelRect.right() + 5) * cos(radians);
double y0 = (barrelRect.right() + 5) * sin(radians);
double x = x0 + velx * time;
double y = y0 + vely * time - 0.5 * gravity * time * time;
QRect result(0, 0, 6, 6);
result.moveCenter(QPoint(qRound(x), height() - 1 - qRound(y)));
return result;
}
在第三最后一行:
result.moveCenter(QPoint(qRound(x), height() - 1 - qRound(y)));
我认为- 1
是废话,不是吗?
它似乎正在采取标量计数(从高度),并将其调整为基于0的阵列;所以1的高度将对应于数组的0索引。只是一个猜测。 – tbert 2012-08-12 07:54:09
同意tbert:在不知道'height()'的返回值的语义的情况下,减去'1'可能不重要。 – wallyk 2012-08-12 07:55:46