added addRectangle2D method to Mesh

This commit is contained in:
Anselme 2016-06-30 15:26:55 +02:00
parent f284cb769f
commit 78a2720a82
2 changed files with 28 additions and 1 deletions

View File

@ -225,6 +225,30 @@ unsigned int Mesh::getFlags()
return flags;
}
void Mesh::addRectangle2D(const glm::vec2 &pos, const glm::vec2 &dim, const glm::vec2 &texCoord, const glm::vec2 &texRange, bool indexed)
{
if(indexed)
{
addVertex(pos, texCoord);
addVertex(pos+glm::vec2(dim.x, 0), texCoord+glm::vec2(texRange.x, 0));
addVertex(pos+dim, texCoord+texRange);
addVertex(pos+glm::vec2(0, dim.y), texCoord+glm::vec2(0, texRange.y));
addTriangle(0, 1, 2);
addTriangle(2, 3, 0);
}
else
{
addVertex(pos, texCoord);
addVertex(pos+glm::vec2(dim.x, 0), texCoord+glm::vec2(texRange.x, 0));
addVertex(pos+dim, texCoord+texRange);
addVertex(pos+dim, texCoord+texRange);
addVertex(pos+glm::vec2(0, dim.y), texCoord+glm::vec2(0, texRange.y));
addVertex(pos, texCoord);
}
}
struct VertexComparator
{
// c'est plutot crade mais j'ai pas trouve d'autre moyen pour le moment

View File

@ -126,7 +126,10 @@ public:
void addVertex(const glm::vec2 &position, const glm::vec2 &texCoord) {addVertex(position); addTexCoord(texCoord);}
void addVertex(const glm::vec3 &position, const glm::vec3 &normal) {addVertex(position); addNormal(normal);}
void addVertex(const glm::vec3 &position, const glm::vec3 &normal, const glm::vec2 &texCoord) {addVertex(position, normal); addTexCoord(texCoord);}
void addRectangle2D(const glm::vec2 &pos, const glm::vec2 &dim, const glm::vec2 &texCoord, const glm::vec2 &texRange, bool indexed = false);
void addRectangle2D(const glm::vec2 &pos, const glm::vec2 &dim, bool indexed = false) {addRectangle2D(pos, dim, glm::vec2(0), glm::vec2(1), indexed);}
void addRectangle2D(float x, float y, float width, float height, bool indexed = false) {addRectangle2D(glm::vec2(x, y), glm::vec2(width, height), indexed);}
// add indices
void addTriangle(int i1, int i2, int i3) {indices.push_back(i1), indices.push_back(i2), indices.push_back(i3);}
void addLine(int i1, int i2) {indices.push_back(i1), indices.push_back(i2);}