diff --git a/src/common/Matrix.cpp b/src/common/Matrix.cpp index d403e8b02..8a603a3f6 100644 --- a/src/common/Matrix.cpp +++ b/src/common/Matrix.cpp @@ -37,6 +37,11 @@ Matrix::Matrix() setIdentity(); } +Matrix::Matrix(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +{ + setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky); +} + Matrix::~Matrix() { } diff --git a/src/common/Matrix.h b/src/common/Matrix.h index 0e33b37d9..cac6c747a 100644 --- a/src/common/Matrix.h +++ b/src/common/Matrix.h @@ -41,6 +41,11 @@ public: **/ Matrix(); + /** + * Creates a new matrix set to a transformation. + **/ + Matrix(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); + /** * Destructor. **/ diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp index 0f35e92e5..67596ad53 100644 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ b/src/modules/graphics/opengl/SpriteBatch.cpp @@ -99,20 +99,9 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl if ((index == -1 && next >= size) || index < -1 || index >= size) return -1; - Vertex sprite[4]; + Matrix t(x, y, a, sx, sy, ox, oy, kx, ky); - // Needed for colors. - memcpy(sprite, texture->getVertices(), sizeof(Vertex) * 4); - - // Transform. - Matrix t; - t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky); - t.transform(sprite, sprite, 4); - - if (color) - setColorv(sprite, *color); - - addv(sprite, (index == -1) ? next : index); + addv(texture->getVertices(), t, (index == -1) ? next : index); // Increment counter. if (index == -1) @@ -127,19 +116,9 @@ int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy, if ((index == -1 && next >= size) || index < -1 || index >= next) return -1; - Vertex sprite[4]; + Matrix t(x, y, a, sx, sy, ox, oy, kx, ky); - // Needed for colors. - memcpy(sprite, quad->getVertices(), sizeof(Vertex) * 4); - - Matrix t; - t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky); - t.transform(sprite, sprite, 4); - - if (color) - setColorv(sprite, *color); - - addv(sprite, (index == -1) ? next : index); + addv(quad->getVertices(), t, (index == -1) ? next : index); // Increment counter. if (index == -1) @@ -254,8 +233,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float if (next == 0) return; - static Matrix t; - t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky); + Matrix t(x, y, angle, sx, sy, ox, oy, kx, ky); OpenGL::TempTransform transform(gl); transform.get() *= t; @@ -299,9 +277,16 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float texture->postdraw(); } -void SpriteBatch::addv(const Vertex *v, int index) +void SpriteBatch::addv(const Vertex *v, const Matrix &m, int index) { - static const size_t sprite_size = 4 * sizeof(Vertex); // bytecount + // Needed for colors. + Vertex sprite[4] = {v[0], v[1], v[2], v[3]}; + const size_t sprite_size = 4 * sizeof(Vertex); // bytecount + + m.transform(sprite, sprite, 4); + + if (color) + setColorv(sprite, *color); VertexBuffer::Bind bind(*array_buf); @@ -309,7 +294,7 @@ void SpriteBatch::addv(const Vertex *v, int index) // on draw.) array_buf->map(); - array_buf->fill(index * sprite_size, sprite_size, v); + array_buf->fill(index * sprite_size, sprite_size, sprite); buffer_used_offset = std::min(buffer_used_offset, index * sprite_size); buffer_used_size = std::max(buffer_used_size, (index + 1) * sprite_size - buffer_used_offset); diff --git a/src/modules/graphics/opengl/SpriteBatch.h b/src/modules/graphics/opengl/SpriteBatch.h index 5f48b2f54..dd9e5bfe7 100644 --- a/src/modules/graphics/opengl/SpriteBatch.h +++ b/src/modules/graphics/opengl/SpriteBatch.h @@ -113,7 +113,7 @@ public: private: - void addv(const Vertex *v, int index); + void addv(const Vertex *v, const Matrix &m, int index); /** * Set the color for vertices.