gpt4 book ai didi

c++ - Quad 无法正确生成?

转载 作者:行者123 更新时间:2023-11-28 07:11:43 25 4
gpt4 key购买 nike

我有一个高度和宽度,我正在尝试用它们生成一个四边形。当我这样做时:

vector<Point2D> vertices;
vector<unsigned int> indices;

Point2D topLeft = Point2(0, height);
Point2D topRight = Point2(width, height);
Point2D bottomLeft = Point2(0, 0);
Point2D bottomRight= Point2(width, 0);

indices.push_back(0);
indices.push_back(1);
indices.push_back(2);
indices.push_back(0);
indices.push_back(2);
indices.push_back(3);

vertices.push_back(topLeft);
vertices.push_back(topRight);
vertices.push_back(bottomLeft);
vertices.push_back(bottomRight);

我得到的是三角形而不是四边形。但是当我这样做时:

vector<Point2D> vertices;
vector<unsigned int> indices;

Point2D topLeft = Point2(-width, height);
Point2D topRight = Point2(width, height);
Point2D bottomLeft = Point2(width, -height);
Point2D bottomRight= Point2(-width, -height);

indices.push_back(0);
indices.push_back(1);
indices.push_back(2);
indices.push_back(0);
indices.push_back(2);
indices.push_back(3);

vertices.push_back(topLeft);
vertices.push_back(topRight);
vertices.push_back(bottomLeft);
vertices.push_back(bottomRight);

完美运行。哪里出了问题?我认为是右下角?

最佳答案

第一段产生两个重叠的不同绕组三角形,逆时针绕组三角形被剔除。如果关闭剔除,您会看到两个三角形,但不是您想要的排列方式。

第二种排列方式完全不同,两个三角形按顺时针方向缠绕,形成一个四边形。如果将负数替换为零,您会发现它与之前的排列不同。

Point2D topLeft    = Point2(    0, height);
Point2D topRight = Point2(width, height);
Point2D bottomLeft = Point2(width, 0);
Point2D bottomRight= Point2(0, 0);

关于c++ - Quad 无法正确生成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20863595/

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