等距瓷砖放置

Isometric tile placement

我正在尝试制作带顶点的等轴瓦图。我设法在没有顶点的情况下完成了它。在我看来,它应该像不使用顶点一样简单,但我无法让它工作。已经做了几十次尝试,但我遗漏了一些重要的东西。

const uint16_t tileMapSize = 16;

quad = &this->tilesDiamond[(x + y * tileMapSize) * 4]; // tilesDiamond is the vertexarray

const uint16_t blockWidth = 64, blockHeight = 64;

pos.x = (x-y) * blockWidth/2;
pos.y = (x + y) * blockWidth/2;

quad[0].position = sf::Vector2f(pos.x, pos.y);
quad[1].position = sf::Vector2f(pos.x+ blockWidth/2, pos.y+ blockWidth/2);
quad[2].position = sf::Vector2f(pos.x, pos.y + blockWidth);
quad[3].position = sf::Vector2f(pos.x - blockWidth/2, pos.y+ blockWidth/2);

这是结果,它应该看起来像拼贴在一起的钻石形状。 https://imgur.com/a/tYhvmZs.

quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);

因为我在纹理协调中犯了一个错误,所有的东西都以错误的方式旋转。