0
我知道這可能是一個愚蠢的問題,但我真的似乎無法在任何地方找到答案。我創建了一個這樣的三角形:Qt即時旋轉動畫
QPolygonF triangle;
triangle.append(QPointF(0., -15));
triangle.append(QPointF(30., 0));
triangle.append(QPointF(0., 15));
triangle.append(QPointF(15., 0));
這個三角形應該代表我的地圖上的一輛汽車,我需要爲它製作動畫。所以,我做了以下內容:
QGraphicsItemAnimation *animation;
QGraphicsPolygonItem *clientCar;
QTimeLine *timer;
animation = new QGraphicsItemAnimation;
timer = new QTimeLine(10000);
timer->setFrameRange(0, 100);
clientCar = scene->addPolygon(triangle, myPen, myBrush)
animation->setItem(clientCar);
animation->setTimeLine(10000);
animation->setPosAt(0.f/200.f, map.street1);
animation->setRotationAt(10.f/200.f, 90.f);
animation->setPosAt(10.f/200.f, map.street2);
animation->setRotationAt(20.f/200.f, 180.f);
animation->setPosAt(20.f/200.f, map.street3);
scene->addItem(clientCar);
ui->graphicsView->setScene(scene);
timer->start();
的問題是,當它達到一個路口(道路交叉)應轉動,使得其將面臨它會旁邊的道路。正如你在上面看到的,我嘗試過使用setRotationAt(),但它做的是在交叉點之間緩慢旋轉,直到它到達下一個交點。只有當它改變方向時,它纔會立即轉向。任何幫助?
它的工作!非常感謝你! –
@ R.Andrei如果您不介意,請接受我的回答;) – 0Tech