2

我在 QT 中绘制等距网格时遇到了很多麻烦。仅剪切操作是正确的,并且缩放也是正确的,但是一旦我在最后添加旋转,网格就不再符合我的参考:http: //vector.tutsplus.com/tutorials/designing/quick-tip -如何在不到 2 分钟的时间内创建等距网格/

有人可以帮我理解为什么 QTransform 会产生不正确的结果吗?

void drawForeground(QPainter * painter, const QRectF& rect) //Draw isometric grid
{
    if(!CurrentActiveMap)return;

    QColor Col(0, 0, 0, 128);
    QPen G(Col);
    G.setDashPattern(QVector<qreal>() << 2 << 2);
    painter->setPen(G);

    int mx = CurrentActiveMap->MapTilesWidth;  //128
    int my = CurrentActiveMap->MapTilesHeight; //128
    int px = CurrentActiveMap->TilePixelSizeX; //32
    int py = CurrentActiveMap->TilePixelSizeY; //32

    int tx = mx * px; //Total pixels x
    int ty = my * py; //Total pixels y

    int XOrigin = 0;
    int YOrigin = 0;

    for(int x = 0; x <= tx; x += px)
    for(int y = 0; y <= ty; y += py)
    {
        int XAdder = px;
        int YAdder = py;

        if(x + px > tx)XAdder = 0; //Prevent overdraw
        if(y + py > ty)YAdder = 0; //Prevent overdraw

        QTransform TF = QTransform()/*.scale(1.0, 0.86062)*/.shear(-0.523598776, 0).rotate(30.0, Qt::ZAxis); //Make isometric matrix to transform gridlines
        painter->setTransform(TF);

        painter->drawLine(XOrigin + x, YOrigin + y, XOrigin + x + XAdder, YOrigin + y);
        painter->drawLine(XOrigin + x, YOrigin + y, XOrigin + x, YOrigin + y + YAdder);
    }
}

在此处输入图像描述

4

0 回答 0