diff --git a/src/mesh.cpp b/src/mesh.cpp index 77ec91e..ede7baa 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -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 diff --git a/src/mesh.h b/src/mesh.h index ddf68fe..aafda2a 100644 --- a/src/mesh.h +++ b/src/mesh.h @@ -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);}