Quad无法正确生成?

问题描述 投票:0回答:2

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

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

它运行正常。出了什么问题?我认为右下角是?

c++ geometry vertices
2个回答
1
投票

此第一段产生两个三角形,它们的绕组不同,并且将逆时针绕组三角形剔除。如果您关闭剔除功能,则会看到两个三角形,但看不到您想要的布置。


0
投票

在不完全知道您正在使用什么的情况下,我建议使用x和y而不是宽度和高度,因为您将'width'设置为0(用作x坐标)。标签可能会使您对实际使用的内容感到困惑,因为您不太可能希望width或height为0。

© www.soinside.com 2019 - 2024. All rights reserved.