gpt4 book ai didi

c++ - 从网格中选定的图 block 绘制大矩形

转载 作者:太空宇宙 更新时间:2023-11-04 13:38:53 25 4
gpt4 key购买 nike

我有一个二维 map 网格系统。当我在一个图 block 上按住鼠标并将鼠标移动到其他图 block 时,我想绘制更大的矩形,其中第一个图 block 作为一个角,当前图 block 作为更大绘制矩形的另一个角。

目前我有以下内容,但它只是一团糟并且还在不断增长。必须有更简单的方法来做到这一点。请注意,在我将鼠标放在一个图 block 上之后,我可以向上/向下/向左/向右移动以制作矩形。我的大脑被炸毁了,无法将其分解为我所知道的更少的代码。

enter image description here

if (startBuyTile.col < mposTile.col)
{
// use startBuyTile as top/left
// use current tile as bottom/right
int i = 0;

Vec2 spos = TileToWorldCoords(startBuyTile.row, startBuyTile.col);
spos.x = spos.x / 100;
spos.y = spos.y / 100;

if (startBuyTile.row < mposTile.row)
{
topLeft.x = spos.x - .64;
topLeft.y = 0;
topLeft.z = spos.y + .64;

bottomRight.x = pos.x + .64;
bottomRight.y = 0;
bottomRight.z = pos.y - .64;

topRight.x = spos.x + .64 + (1.28 * Math::Abs(colCount));
topRight.y = 0;
topRight.z = spos.y + .64;

bottomLeft.x = spos.x - .64;
bottomLeft.y = 0;
bottomLeft.z = pos.y - .64;
}
else if (startBuyTile.row > mposTile.row)
{
topLeft.x = pos.x - .64;
topLeft.y = 0;
topLeft.z = pos.y + .64;

topRight.x = spos.x + .64;
topRight.y = 0;
topRight.z = pos.y + .64;

bottomLeft.x = pos.x + .64;
bottomLeft.y = 0;
bottomLeft.z = spos.y - .64;

bottomRight.x = spos.x - .64;
bottomRight.y = 0;
bottomRight.z = spos.y - .64;
}
else
{
topLeft.x = spos.x - .64;
topLeft.y = 0;
topLeft.z = spos.y + .64;

bottomRight.x = pos.x + .64;
bottomRight.y = 0;
bottomRight.z = pos.y - .64;

topRight.x = pos.x + .64;
topRight.y = 0;
topRight.z = pos.y + .64;

bottomLeft.x = spos.x - .64;
bottomLeft.y = 0;
bottomLeft.z = spos.y - .64;
}
}
else if (startBuyTile.col > mposTile.col)
{
// use current tile as top/left
// use startBuyTile as bottom/right
int j = 0;
}
else
{
topLeft.x = pos.x - .64;
topLeft.y = 0;
topLeft.z = pos.y + .64;

topRight.x = pos.x + .64;
topRight.y = 0;
topRight.z = pos.y + .64;

bottomLeft.x = pos.x - .64;
bottomLeft.y = 0;
bottomLeft.z = pos.y - .64;

bottomRight.x = pos.x + .64;
bottomRight.y = 0;
bottomRight.z = pos.y - .64;
}
}
else
{
topLeft.x = pos.x - .64;
topLeft.y = 0;
topLeft.z = pos.y + .64;

topRight.x = pos.x + .64;
topRight.y = 0;
topRight.z = pos.y + .64;

bottomLeft.x = pos.x - .64;
bottomLeft.y = 0;
bottomLeft.z = pos.y - .64;

bottomRight.x = pos.x + .64;
bottomRight.y = 0;
bottomRight.z = pos.y - .64;
}

最佳答案

我想通了。在起始图 block 和我当前所在的图 block 之间,我需要在它们之间获得最低的行/列和最高的行/列,这将给我我的角落,从中我可以得到我的左上/右和左下/右点来制作我的矩形。

我使用 min() 和 max() 来获取这些角 block 。

关于c++ - 从网格中选定的图 block 绘制大矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28552997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com