提高坐标精度
This commit is contained in:
1 parent
202b75d324
commit
dd4edc5643
2 files changed
+14
-14
No files matched your search
@@ -27,32 +27,32 @@ Cars::Cars(QGraphicsItem *parent, int dir, Cars::Color color) : QGraphicsPixmapI
|
||||
setTransformOriginPoint(M_WID/2, M_LEN/2); //设置旋转中心
|
||||
}
|
||||
|
||||
void Cars::Forward(int vel)
|
||||
void Cars::Forward(qreal vel)
|
||||
{
|
||||
double ang = qDegreesToRadians(rotation());
|
||||
qreal ang = qDegreesToRadians(rotation());
|
||||
this->moveBy(+vel*qSin(ang), -vel*qCos(ang));
|
||||
}
|
||||
|
||||
void Cars::Backward(int vel)
|
||||
void Cars::Backward(qreal vel)
|
||||
{
|
||||
double ang = qDegreesToRadians(rotation());
|
||||
qreal ang = qDegreesToRadians(rotation());
|
||||
this->moveBy(-vel*qSin(ang), +vel*qCos(ang));
|
||||
}
|
||||
|
||||
void Cars::moveLeft(int vel)
|
||||
void Cars::moveLeft(qreal vel)
|
||||
{
|
||||
double ang = qDegreesToRadians(rotation());
|
||||
qreal ang = qDegreesToRadians(rotation());
|
||||
moveBy(-vel*qCos(ang), -vel*qSin(ang));
|
||||
}
|
||||
|
||||
void Cars::moveRight(int vel)
|
||||
void Cars::moveRight(qreal vel)
|
||||
{
|
||||
double ang = qDegreesToRadians(rotation());
|
||||
qreal ang = qDegreesToRadians(rotation());
|
||||
moveBy(vel*qCos(ang), vel*qSin(ang));
|
||||
}
|
||||
|
||||
//ang为旋转角度(弧度),正数为顺时针,负数逆时针
|
||||
void Cars::Rotate(int ang)
|
||||
void Cars::Rotate(qreal ang)
|
||||
{
|
||||
setRotation(rotation() + ang);
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@ class Cars : public QGraphicsPixmapItem
|
||||
public:
|
||||
enum Color { Pink, Red, Yellow, RANDOM };
|
||||
explicit Cars(QGraphicsItem *parent = Q_NULLPTR, int dir = 0, Cars::Color color = RANDOM);
|
||||
void Forward(int vel = 3);
|
||||
void Backward(int vel = 3);
|
||||
void moveLeft(int vel = 3);
|
||||
void moveRight(int vel = 3);
|
||||
void Rotate(int ang = 30);
|
||||
void Forward(qreal vel = 3);
|
||||
void Backward(qreal vel = 3);
|
||||
void moveLeft(qreal vel = 3);
|
||||
void moveRight(qreal vel = 3);
|
||||
void Rotate(qreal ang = 30);
|
||||
void turnLeft(int r, int ang);
|
||||
void turnRight(int r, int ang);
|
||||
|
||||
|
||||
Reference in new issue
Block a user