Slightly reduced the CPU usage of SpriteBatch:add, Text:add, and love.graphics.draw(ParticleSystem).

This commit is contained in:
Alex Szpakowski
2015-08-11 18:01:24 -03:00
parent 6d9409a337
commit bfef97c48a
8 changed files with 68 additions and 39 deletions
+24
View File
@@ -221,6 +221,11 @@ Matrix3::Matrix3(const Matrix4 &mat4)
e[8] = mat4elems[10];
}
Matrix3::Matrix3(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);
}
Matrix3::~Matrix3()
{
}
@@ -288,4 +293,23 @@ Matrix3 Matrix3::transposedInverse() const
return m;
}
void Matrix3::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
{
float c = cosf(angle), s = sinf(angle);
// matrix multiplication carried out on paper:
// |1 x| |c -s | |sx | | 1 ky | |1 -ox|
// | 1 y| |s c | | sy | |kx 1 | | 1 -oy|
// | 1| | 1| | 1| | 1| | 1 |
// move rotate scale skew origin
e[0] = c * sx - ky * s * sy; // = a
e[1] = s * sx + ky * c * sy; // = b
e[3] = kx * c * sx - s * sy; // = c
e[4] = kx * s * sx + c * sy; // = d
e[6] = x - ox * e[0] - oy * e[3];
e[7] = y - ox * e[1] - oy * e[4];
e[2] = e[5] = 0.0f;
e[8] = 1.0f;
}
} // love
+21
View File
@@ -185,6 +185,11 @@ public:
**/
Matrix3(const Matrix4 &mat4);
/**
* Creates a new matrix set to a transformation.
**/
Matrix3(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
~Matrix3();
/**
@@ -205,6 +210,22 @@ public:
**/
Matrix3 transposedInverse() const;
/**
* Creates a transformation with a certain position, orientation, scale
* and offset.
*
* @param x The translation along the x-axis.
* @param y The translation along the y-axis.
* @param angle The rotation (rad) around the center with offset (ox,oy).
* @param sx Scale along x-axis.
* @param sy Scale along y-axis.
* @param ox The offset for rotation along the x-axis.
* @param oy The offset for rotation along the y-axis.
* @param kx Shear along x-axis
* @param ky Shear along y-axis
**/
void setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
/**
* Transforms an array of vertices by this matrix.
**/