0

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

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);

它工作得很好。出了什么问题?我认为右下角?

4

2 回答 2

1

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

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

Point2D topLeft    = Point2(    0, height);
Point2D topRight   = Point2(width, height);
Point2D bottomLeft = Point2(width, 0);
Point2D bottomRight= Point2(0,     0);
于 2013-12-31T22:49:21.587 回答
0

在不确切知道您在使用什么的情况下,我建议使用 x 和 y 而不是宽度和高度,因为您将“宽度”设置为 0,它用作 x 坐标。标签可能会导致您对实际使用的内容感到困惑,因为您不太可能希望宽度或高度为 0。

如果您在纸上绘制要添加为顶点的点的坐标,则似乎您正在制作一个三角形。如果高度 = 3 和宽度 = 4,您的顶点列表是:

(0, 3) // 沿 y 向上

(3, 4) // 沿着 x

(0, 0) // 回到 0 - 三角形!

(4, 0) // 沿 x 的孤立线段

在我看来,您推动顶点的顺序应该是 topLeft->topRight->bottomRight->bottomLeft 以制作顺时针多边形。

于 2013-12-31T22:31:38.783 回答