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