我在QT中绘制等距网格时遇到了很多麻烦。只是单独的剪切操作是正确的,并且还有缩放,但只要我在末尾添加旋转,网格就不再匹配我的参考:http://vector.tutsplus.com/tutorials/designing/quick-tip-how-to-create-an-isometric-grid-in-less-than-2-minutes/
有人可以帮我理解为什么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);
}
}