Browse Source

Merged in brocoli_/love/set-raw-transform (pull request #69)

Added new raw values constructor to Matrix4 and Matrix4::setRawTransformation().
Alex Szpakowski 8 years ago
parent
commit
db78c89639
2 changed files with 37 additions and 0 deletions
  1. 17 0
      src/common/Matrix.cpp
  2. 20 0
      src/common/Matrix.h

+ 17 - 0
src/common/Matrix.cpp

@@ -36,6 +36,11 @@ Matrix4::Matrix4()
 {
 	setIdentity();
 }
+	
+Matrix4::Matrix4(float t00, float t10, float t01, float t11, float x, float y)
+{
+	setRawTransformation(t00, t10, t01, t11, x, y);
+}
 
 Matrix4::Matrix4(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
 {
@@ -129,6 +134,18 @@ void Matrix4::setShear(float kx, float ky)
 	e[1] = ky;
 	e[4] = kx;
 }
+	
+void Matrix4::setRawTransformation(float t00, float t10, float t01, float t11, float x, float y)
+{
+	memset(e, 0, sizeof(float)*16); // zero out matrix
+	e[10] = e[15] = 1.0f;
+	e[0] = t00;
+	e[1] = t10;
+	e[4] = t01;
+	e[5] = t11;
+	e[12] = x;
+	e[13] = y;
+}
 
 void Matrix4::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
 {

+ 20 - 0
src/common/Matrix.h

@@ -40,6 +40,11 @@ public:
 	 * Creates a new identity matrix.
 	 **/
 	Matrix4();
+	
+	/**
+	 * Creates a new matrix with the transform values set.
+	 **/
+	Matrix4(float t00, float t10, float t01, float t11, float x, float y);
 
 	/**
 	 * Creates a new matrix set to a transformation.
@@ -101,6 +106,21 @@ public:
 	 * @param ky Shear along y-axis.
 	 **/
 	void setShear(float kx, float ky);
+	
+	/**
+	 * Sets a transformation's values directly. Useful if you want to modify them inplace,
+	 * or if you want to create a transformation that's not buildable with setTransformation()
+	 * i.e. the inverse of setTransformation() is not easily built with another call
+	 * to setTransformation() with tweaked values.
+	 *
+	 * @param t00 The sx*cos(angle) component of the transformation.
+	 * @param t10 The sx*sin(angle) component of the transformation.
+	 * @param t01 The sy*(-sin(angle)) component of the transformation.
+	 * @param t11 The sy*cos(angle) component of the transformation.
+	 * @param x The x translation component of the transformation.
+	 * @param y The y translation component of the transformation.
+	 **/
+	void setRawTransformation(float t00, float t10, float t01, float t11, float x, float y);
 
 	/**
 	 * Creates a transformation with a certain position, orientation, scale