47 #include "CUMathBase.h"
86 #if defined CU_MATH_VECTOR_SSE
87 __attribute__((__aligned__(16)))
union {
91 #elif defined CU_MATH_VECTOR_NEON64
92 __attribute__((__aligned__(16)))
union {
109 #pragma mark Constructors
141 Mat4(
float m11,
float m12,
float m13,
float m14,
142 float m21,
float m22,
float m23,
float m24,
143 float m31,
float m32,
float m33,
float m34,
144 float m41,
float m42,
float m43,
float m44);
159 Mat4(
const float* mat);
191 #pragma mark Static Constructors
235 float targetX,
float targetY,
float targetZ,
236 float upX,
float upY,
float upZ) {
239 targetX, targetY, targetZ,
240 upX, upY, upZ, &result));
260 float targetX,
float targetY,
float targetZ,
261 float upX,
float upY,
float upZ,
Mat4* dst);
282 float zNearPlane,
float zFarPlane) {
284 return *(
createPerspective(fieldOfView, aspectRatio, zNearPlane, zFarPlane, &result));
306 float zNearPlane,
float zFarPlane,
Mat4* dst);
334 float zNearPlane,
float zFarPlane) {
367 float zNearPlane,
float zFarPlane,
Mat4* dst) {
368 float halfWidth = width / 2.0f;
369 float halfHeight = height / 2.0f;
371 zNearPlane, zFarPlane, dst);
402 float zNearPlane,
float zFarPlane) {
437 float zNearPlane,
float zFarPlane,
Mat4* dst);
715 memcpy(this->m, mat.m,
sizeof(
float)*16);
771 Mat4&
set(
float m11,
float m12,
float m13,
float m14,
float m21,
float m22,
float m23,
float m24,
772 float m31,
float m32,
float m33,
float m34,
float m41,
float m42,
float m43,
float m44);
825 #pragma mark Static Arithmetic
934 #pragma mark Arithmetic
943 return *(
add(*
this,scalar,
this));
954 return *(
add(*
this,mat,
this));
965 return *(
subtract(*
this,scalar,
this));
987 return *(
multiply(*
this,scalar,
this));
1001 return *(
multiply(*
this,mat,
this));
1010 return *(
negate(*
this,
this));
1035 return *(
invert(*
this,
this));
1085 #pragma mark Operators
1144 return result.
add(mat);
1205 #pragma mark Comparisons
1229 bool equals(
const Mat4& mat,
float variance=CU_MATH_EPSILON)
const;
1262 #pragma mark Matrix Attributes
1274 bool isIdentity(
float variance=CU_MATH_EPSILON)
const;
1298 bool isOrthogonal(
float variance=CU_MATH_EPSILON)
const;
1387 #pragma mark Static Vector Operations
1484 static float*
transform(
const Mat4& mat,
float const* input,
float* output,
size_t size);
1488 #pragma mark Vector Operations
1580 #pragma mark Static Matrix Transforms
1811 #pragma mark Matrix Transforms
1823 return *(
rotate(*
this,q,
this));
1840 return *(
rotate(*
this,axis,angle,
this));
1856 return *(
rotateX(*
this,angle,
this));
1872 return *(
rotateY(*
this,angle,
this));
1888 return *(
rotateZ(*
this,angle,
this));
1902 return *(
scale(*
this,value,
this));
1916 return *(
scale(*
this,s,
this));
1932 return *(
scale(*
this,sx,sy,sz,
this));
1962 return *(
translate(*
this,tx,ty,tz,
this));
1967 #pragma mark Conversion Methods
1978 std::string
toString(
bool verbose =
false)
const;
2026 #pragma mark Vector Operations
2040 inline Vec2& operator*=(Vec2& v,
const Mat4& m) {
2055 inline const Vec2 operator*(
const Vec2& v,
const Mat4& m) {
2056 return m.transform(v);
2070 inline Vec3& operator*=(Vec3& v,
const Mat4& m) {
2085 inline const Vec3 operator*(
const Vec3& v,
const Mat4& m) {
2086 return m.transform(v);
2100 inline Vec4& operator*=(Vec4& v,
const Mat4& m) {
2115 inline const Vec4 operator*(
const Vec4& v,
const Mat4& m) {
2116 return m.transform(v);
2127 inline const Mat4 operator*(
float scalar,
const Mat4& m) {
2129 return result.multiply(scalar);
static Mat4 createRotationX(float angle)
Definition: CUMat4.h:571
Mat4 & set(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)
bool isOrthogonal(float variance=CU_MATH_EPSILON) const
Mat4 & operator=(const Mat4 &mat)
Definition: CUMat4.h:703
Vec3 getTranslation() const
Vec3 getForwardVector() const
static Vec2 * transform(const Mat4 &mat, const Vec2 &point, Vec2 *dst)
static Mat4 * multiply(const Mat4 &mat, float scalar, Mat4 *dst)
Vec3 getBackVector() const
static Mat4 createRotation(const Vec3 &axis, float angle)
Definition: CUMat4.h:542
Mat4(const Quaternion &rotation)
Definition: CUMat4.h:180
bool isIdentity(float variance=CU_MATH_EPSILON) const
Definition: CUAffine2.h:63
float getDeterminant() const
Mat4 & operator=(Mat4 &&mat)
Definition: CUMat4.h:714
static Mat4 createScale(float sx, float sy, float sz)
Definition: CUMat4.h:470
static Mat4 createOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane)
Definition: CUMat4.h:401
Mat4 & scale(const Vec3 &s)
Definition: CUMat4.h:1915
Mat4 & scale(float value)
Definition: CUMat4.h:1901
~Mat4()
Definition: CUMat4.h:187
Mat4 & add(float scalar)
Definition: CUMat4.h:942
static Vec2 * transformVector(const Mat4 &mat, const Vec2 &vec, Vec2 *dst)
static Mat4 createScale(const Vec3 &scale)
Definition: CUMat4.h:494
Mat4 & operator+=(const Mat4 &mat)
Definition: CUMat4.h:1093
Mat4 & rotateZ(float angle)
Definition: CUMat4.h:1887
static const Mat4 ONE
Definition: CUMat4.h:103
static Mat4 createRotationY(float angle)
Definition: CUMat4.h:599
bool isExactly(const Mat4 &mat) const
Mat4 & translate(float tx, float ty, float tz)
Definition: CUMat4.h:1961
static Mat4 * subtract(const Mat4 &mat, float scalar, Mat4 *dst)
static Mat4 * rotateX(const Mat4 &mat, float angle, Mat4 *dst)
Definition: CUMat4.h:1636
Mat4 & rotateY(float angle)
Definition: CUMat4.h:1871
Mat4 & operator-=(const Mat4 &mat)
Definition: CUMat4.h:1104
static Mat4 createScale(float scale)
Definition: CUMat4.h:446
Mat4 & rotateX(float angle)
Definition: CUMat4.h:1855
Mat4 & negate()
Definition: CUMat4.h:1009
Mat4 & operator*=(float scalar)
Definition: CUMat4.h:1129
Mat4 & multiply(float scalar)
Definition: CUMat4.h:986
static Mat4 * rotate(const Mat4 &mat, const Quaternion &quat, Mat4 *dst)
Definition: CUMat4.h:1593
static Mat4 * scale(const Mat4 &mat, float value, Mat4 *dst)
Definition: CUMat4.h:1697
Vec3 getRightVector() const
Mat4 & transpose()
Definition: CUMat4.h:1062
static Mat4 * translate(const Mat4 &mat, float tx, float ty, float tz, Mat4 *dst)
Definition: CUMat4.h:1777
Mat4 & rotate(const Vec3 &axis, float angle)
Definition: CUMat4.h:1839
static Mat4 * scale(const Mat4 &mat, float sx, float sy, float sz, Mat4 *dst)
Definition: CUMat4.h:1737
Mat4 getInverse() const
Definition: CUMat4.h:1047
const Mat4 operator*(const Mat4 &mat) const
Definition: CUMat4.h:1184
static Mat4 createOrthographic(float width, float height, float zNearPlane, float zFarPlane)
Definition: CUMat4.h:333
static Mat4 createTranslation(float tx, float ty, float tz)
Definition: CUMat4.h:676
static Mat4 * rotateZ(const Mat4 &mat, float angle, Mat4 *dst)
Definition: CUMat4.h:1678
Mat4 & subtract(const Mat4 &mat)
Definition: CUMat4.h:975
static bool decompose(const Mat4 &mat, Vec3 *scale, Quaternion *rot, Vec3 *trans)
Mat4 & multiply(const Mat4 &mat)
Definition: CUMat4.h:1000
const Mat4 operator-(const Mat4 &mat) const
Definition: CUMat4.h:1156
bool isInvertible(float variance=CU_MATH_EPSILON) const
Definition: CUMat4.h:1285
static Mat4 createPerspective(float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane)
Definition: CUMat4.h:281
const Mat4 operator+(const Mat4 &mat) const
Definition: CUMat4.h:1142
std::string toString(bool verbose=false) const
Mat4 & operator=(const float *array)
Definition: CUMat4.h:734
Mat4 & operator=(const Quaternion &quat)
Definition: CUMat4.h:745
Mat4 & add(const Mat4 &mat)
Definition: CUMat4.h:953
static Mat4 * rotateY(const Mat4 &mat, float angle, Mat4 *dst)
Definition: CUMat4.h:1657
bool equals(const Mat4 &mat, float variance=CU_MATH_EPSILON) const
static const Mat4 IDENTITY
Definition: CUMat4.h:105
static Mat4 * scale(const Mat4 &mat, const Vec3 &s, Mat4 *dst)
Definition: CUMat4.h:1716
static Mat4 * createOrthographic(float width, float height, float zNearPlane, float zFarPlane, Mat4 *dst)
Definition: CUMat4.h:366
const Mat4 operator*(float scalar) const
Definition: CUMat4.h:1198
static Mat4 createLookAt(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ)
Definition: CUMat4.h:234
Mat4 & subtract(float scalar)
Definition: CUMat4.h:964
Mat4 getTranspose() const
Definition: CUMat4.h:1077
Mat4 getNegation() const
Definition: CUMat4.h:1020
Mat4 & scale(float sx, float sy, float sz)
Definition: CUMat4.h:1931
static Mat4 createRotation(const Quaternion &quat)
Definition: CUMat4.h:516
Mat4 & translate(const Vec3 &t)
Definition: CUMat4.h:1945
static Mat4 * add(const Mat4 &mat, float scalar, Mat4 *dst)
const Mat4 operator-() const
Definition: CUMat4.h:1168
Mat4 & rotate(const Quaternion &q)
Definition: CUMat4.h:1822
Definition: CUAction.h:51
Vec3 getDownVector() const
Definition: CUQuaternion.h:97
static Mat4 createTranslation(const Vec3 &trans)
Definition: CUMat4.h:652
static Mat4 * translate(const Mat4 &mat, const Vec3 &t, Mat4 *dst)
Definition: CUMat4.h:1756
static Mat4 createRotationZ(float angle)
Definition: CUMat4.h:627
static const Mat4 ZERO
Definition: CUMat4.h:101
static Mat4 createLookAt(const Vec3 &eye, const Vec3 &target, const Vec3 &up)
Definition: CUMat4.h:201
Quaternion getRotation() const
Vec3 getLeftVector() const
static Mat4 * rotate(const Mat4 &mat, const Vec3 &axis, float angle, Mat4 *dst)
Definition: CUMat4.h:1615
bool operator==(const Mat4 &mat) const
Definition: CUMat4.h:1242
Mat4 & operator*=(const Mat4 &mat)
Definition: CUMat4.h:1118
Mat4 & invert()
Definition: CUMat4.h:1034
bool operator!=(const Mat4 &mat) const
Definition: CUMat4.h:1256