mirror of
https://github.com/love2d/love-android.git
synced 2026-08-19 20:20:25 +02:00
Using latest android branch of LÖVE (6d14516b05c9) that now syncs with default (woooo!)
This commit is contained in:
+103
-12
@@ -28,41 +28,41 @@ namespace love
|
||||
{
|
||||
|
||||
/**
|
||||
* This class is the basis for all transformations in LOVE. Althought not
|
||||
* really needed for 2D, it contains 4x4 elements to be compatible with
|
||||
* OpenGL without conversions.
|
||||
* This class is the basis for all transformations in LOVE. Although not really
|
||||
* needed for 2D, it contains 4x4 elements to be compatible with OpenGL without
|
||||
* conversions.
|
||||
**/
|
||||
class Matrix
|
||||
class Matrix4
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new identity matrix.
|
||||
**/
|
||||
Matrix();
|
||||
Matrix4();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
Matrix4(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
~Matrix();
|
||||
~Matrix4();
|
||||
|
||||
/**
|
||||
* Multiplies this Matrix with another Matrix, changing neither.
|
||||
* @param m The Matrix to multiply with this Matrix.
|
||||
* @return The combined matrix.
|
||||
**/
|
||||
Matrix operator * (const Matrix &m) const;
|
||||
Matrix4 operator * (const Matrix4 &m) const;
|
||||
|
||||
/**
|
||||
* Multiplies a Matrix into this Matrix.
|
||||
* @param m The Matrix to combine into this Matrix.
|
||||
**/
|
||||
void operator *= (const Matrix &m);
|
||||
void operator *= (const Matrix4 &m);
|
||||
|
||||
/**
|
||||
* Gets a pointer to the 16 array elements.
|
||||
@@ -153,13 +153,14 @@ public:
|
||||
* @param src The source vertices.
|
||||
* @param size The number of vertices.
|
||||
**/
|
||||
void transform(Vertex *dst, const Vertex *src, int size) const;
|
||||
template <typename V>
|
||||
void transform(V *dst, const V *src, int size) const;
|
||||
|
||||
/**
|
||||
* Creates a new orthographic projection matrix with depth in the range of
|
||||
* [-1, 1].
|
||||
**/
|
||||
static Matrix ortho(float left, float right, float bottom, float top);
|
||||
static Matrix4 ortho(float left, float right, float bottom, float top);
|
||||
|
||||
private:
|
||||
|
||||
@@ -171,7 +172,97 @@ private:
|
||||
**/
|
||||
float e[16];
|
||||
|
||||
}; // Matrix
|
||||
}; // Matrix4
|
||||
|
||||
class Matrix3
|
||||
{
|
||||
public:
|
||||
|
||||
Matrix3();
|
||||
|
||||
/**
|
||||
* Constructs a 3x3 matrix from the upper left section of a 4x4 matrix.
|
||||
**/
|
||||
Matrix3(const Matrix4 &mat4);
|
||||
|
||||
~Matrix3();
|
||||
|
||||
/**
|
||||
* Resets this matrix to the identity matrix.
|
||||
**/
|
||||
void setIdentity();
|
||||
|
||||
Matrix3 operator * (const Matrix3 &m) const;
|
||||
void operator *= (const Matrix3 &m);
|
||||
|
||||
/**
|
||||
* Gets a pointer to the 9 array elements.
|
||||
**/
|
||||
const float *getElements() const;
|
||||
|
||||
/**
|
||||
* Calculates the inverse of the transpose of this matrix.
|
||||
**/
|
||||
Matrix3 transposedInverse() const;
|
||||
|
||||
/**
|
||||
* Transforms an array of vertices by this matrix.
|
||||
**/
|
||||
template <typename V>
|
||||
void transform(V *dst, const V *src, int size) const;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* | e0 e3 e6
|
||||
* | e1 e4 e7
|
||||
* | e2 e5 e8
|
||||
**/
|
||||
float e[9];
|
||||
|
||||
}; // Matrix3
|
||||
|
||||
// | x |
|
||||
// | y |
|
||||
// | 0 |
|
||||
// | 1 |
|
||||
// | e0 e4 e8 e12 |
|
||||
// | e1 e5 e9 e13 |
|
||||
// | e2 e6 e10 e14 |
|
||||
// | e3 e7 e11 e15 |
|
||||
|
||||
template <typename V>
|
||||
void Matrix4::transform(V *dst, const V *src, int size) const
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
// Store in temp variables in case src = dst
|
||||
float x = (e[0]*src[i].x) + (e[4]*src[i].y) + (0) + (e[12]);
|
||||
float y = (e[1]*src[i].x) + (e[5]*src[i].y) + (0) + (e[13]);
|
||||
|
||||
dst[i].x = x;
|
||||
dst[i].y = y;
|
||||
}
|
||||
}
|
||||
|
||||
// | x |
|
||||
// | y |
|
||||
// | 1 |
|
||||
// | e0 e3 e6 |
|
||||
// | e1 e4 e7 |
|
||||
// | e2 e5 e8 |
|
||||
template <typename V>
|
||||
void Matrix3::transform(V *dst, const V *src, int size) const
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
float x = (e[0]*src[i].x) + (e[3]*src[i].y) + (e[6]);
|
||||
float y = (e[1]*src[i].x) + (e[4]*src[i].y) + (e[7]);
|
||||
|
||||
dst[i].x = x;
|
||||
dst[i].y = y;
|
||||
}
|
||||
}
|
||||
|
||||
} //love
|
||||
|
||||
|
||||
Reference in New Issue
Block a user