120 #ifndef __vmath_Header_File__ 121 #define __vmath_Header_File__ 129 #define VMATH_NAMESPACE vmath 131 #ifdef VMATH_NAMESPACE 137 #define M_PI 3.14159265358979323846 140 #define DEG2RAD(x) ((x * M_PI) / 180.0) 141 #define RAD2DEG(x) ((x *180) / M_PI) 144 const double epsilon = 4.37114e-05;
145 #define EPSILON epsilon 146 #define sinf(x) (float)sin((double)(x)) 147 #define cosf(x) (float)cos((double)(x)) 148 template <
typename T>
149 inline T radians(T angleInRadians)
151 return angleInRadians *
static_cast<T
>(180.0/M_PI);
154 inline bool closeEnough(
float a,
float b,
float eps = epsilon) {
155 return (eps > abs(a - b));
234 template<
class FromT>
236 :
x(static_cast<T>(src.
x)),
y(static_cast<T>(src.
y))
246 template<
class FromT>
249 x =
static_cast<T
>(rhs.
x);
250 y =
static_cast<T
>(rhs.
y);
273 assert(n >= 0 && n <= 1);
288 assert(n >= 0 && n <= 1);
469 return (std::abs(
x - rhs.
x) < EPSILON) && (std::abs(
y - rhs.
y) < EPSILON);
479 return !(*
this == rhs);
499 return (T) std::sqrt(
x *
x +
y *
y);
538 return x *
x +
y *
y;
553 return (*
this) + (r - (*this)) * fact;
571 operator const T*()
const 573 return (
const T*)
this;
583 friend std::ostream& operator<<(std::ostream& lhs, const Vector2<T>& rhs)
585 lhs <<
"[" << rhs.x <<
"," << rhs.y <<
"]";
594 std::ostringstream oss;
609 typedef class Vector2<float> Vector2f;
611 typedef class Vector2<double> Vector2d;
613 typedef class Vector2<int> Vector2i;
704 :
x(nx),
y(ny), z(nz)
710 :
x(v.
x),
y(v.
y), z(nz)
719 :
x(src.
x),
y(src.
y), z(src.z)
728 :
x(v[0]),
y(v[1]), z(v[2])
736 template<
class FromT>
738 :
x(static_cast<T>(src.
x)),
y(static_cast<T>(src.
y)), z(static_cast<T>(src.z))
759 template<
class FromT>
762 x =
static_cast<T
>(rhs.
x);
763 y =
static_cast<T
>(rhs.
y);
764 z =
static_cast<T
>(rhs.
z);
777 assert(n >= 0 && n <= 2);
795 assert(n >= 0 && n <= 2);
895 return x * rhs.
x +
y * rhs.
y + z * rhs.
z;
910 v1.
z * v2.
x - v1.
x * v2.
z,
911 v1.
x * v2.
y - v1.
y * v2.
x);
942 return (v1 + v2 + v3)/3;
947 return (v - *
this).
length();
952 return (v1 - v2).length();
1050 return std::fabs(
x - rhs.
x) < EPSILON && std::fabs(
y - rhs.
y) < EPSILON && std::fabs(z - rhs.
z) < EPSILON;
1060 return !(*
this == rhs);
1080 return (T) std::sqrt(
x *
x +
y *
y + z * z);
1092 return x *
x +
y *
y + z * z;
1115 T a = cos(DEG2RAD(ax));
1116 T b = sin(DEG2RAD(ax));
1117 T c = cos(DEG2RAD(ay));
1118 T d = sin(DEG2RAD(ay));
1119 T e = cos(DEG2RAD(az));
1120 T f = sin(DEG2RAD(az));
1121 T nx = c * e *
x - c * f *
y + d * z;
1122 T ny = (a * f + b * d * e) *
x + (a * e - b * d * f) *
y - b * c * z;
1123 T nz = (b * f - a * d * e) *
x + (a * d * f + b * e) *
y + a * c * z;
1141 return (*
this) + (r - (*this)) * fact;
1161 operator const T*()
const 1163 return (
const T*)
this;
1173 friend std::ostream& operator<<(std::ostream& lhs, const Vector3<T> rhs)
1175 lhs <<
"[" << rhs.x <<
"," << rhs.y <<
"," << rhs.z <<
"]";
1184 std::ostringstream oss;
1277 :
x(0),
y(0), z(0), w(0)
1289 :
x(nx),
y(ny), z(nz), w(nw)
1301 :
x(nx),
y(ny), z(nz), w(1)
1306 :
x(v.
x),
y(v.
y), z(v.
z), w(nw)
1311 :
x(v.
x),
y(v.
y), z(v.
z), w(1)
1320 :
x(src.
x),
y(src.
y), z(src.z), w(src.w)
1328 template<
class FromT>
1330 :
x(static_cast<T>(src.
x)),
y(static_cast<T>(src.
y)), z(static_cast<T>(src.z)), w(static_cast<T>(src.w))
1334 template <
typename FromT>
1336 :
x(static_cast<T>(src.
x)),
y(static_cast<T>(src.
y)), z(static_cast<T>(src.
z)), w(static_cast<T>(w))
1357 template<
class FromT>
1360 x =
static_cast<T
>(rhs.x);
1361 y =
static_cast<T
>(rhs.
y);
1362 z =
static_cast<T
>(rhs.
z);
1363 w =
static_cast<T
>(rhs.
w);
1376 assert(n >= 0 && n <= 3);
1396 assert(n >= 0 && n <= 3);
1506 return std::fabs(
x - rhs.x) < EPSILON && std::fabs(
y - rhs.
y) < EPSILON && std::fabs(z - rhs.
z) < EPSILON
1507 && std::fabs(w - rhs.
w) < EPSILON;
1517 return !(*
this == rhs);
1627 return (T) std::sqrt(
x *
x +
y *
y + z * z + w * w);
1651 return x *
x +
y *
y + z * z + w * w;
1666 return (*
this) + (r - (*this)) * fact;
1686 operator const T*()
const 1688 return (
const T*)
this;
1698 if (w == 0 || w == 1)
1701 const T invW = 1.0 / w;
1702 return Vector3<T>(x * invW, y * invW, z * invW);
1712 friend std::ostream& operator<<(std::ostream& lhs, const Vector4<T>& rhs)
1714 lhs <<
"[" << rhs.
x <<
"," << rhs.y <<
"," << rhs.z <<
"," << rhs.w <<
"]";
1723 std::ostringstream oss;
1761 for (
int i = 0; i < 9; i++)
1762 data[i] = (i % 4) ? 0 : 1;
1771 std::memcpy(data, dt,
sizeof(T) * 9);
1780 std::memcpy(data, src.
data,
sizeof(T) * 9);
1787 template<
class FromT>
1790 for (
int i = 0; i < 9; i++)
1792 data[i] =
static_cast<T
>(src.
data[i]);
1801 for (
int i = 0; i < 9; i++)
1802 data[i] = (i % 4) ? 0 : 1;
1813 for(
int i = 0; i < 3; i++){
1814 for(
int j = 0; j < 3; j++){
1815 vxm[i] += at(i,j) * v[j];
1830 for(
int i = 0; i < 3; i++){
1831 for(
int j = 0; j < 3; j++){
1832 vxm[i] += m.
at(i,j) * v[j];
1847 T xRads(DEG2RAD(xDeg));
1848 T yRads(DEG2RAD(yDeg));
1849 T zRads(DEG2RAD(zDeg));
1852 float ac = cos(xRads);
1853 float as = sin(xRads);
1854 float bc = cos(yRads);
1855 float bs = sin(yRads);
1856 float cc = cos(zRads);
1857 float cs = sin(zRads);
1881 if (closeEnough(R.
at(2,0), -1.0f)) {
1884 float z = x + atan2(R.
at(0,1), R.
at(0,2));
1886 }
else if (closeEnough(R.
at(2,0), 1.0f)) {
1888 float y = -M_PI / 2;
1889 float z = -x + atan2(-R.
at(0,1), -R.
at(0,2));
1892 float x1 = -asin(R.
at(2,0));
1893 float x2 = M_PI - x1;
1895 float y1 = atan2(R.
at(2,1) / cos(x1), R.
at(2,2) / cos(x1));
1896 float y2 = atan2(R.
at(2,1) / cos(x2), R.
at(2,2) / cos(x2));
1898 float z1 = atan2(R.
at(1,0) / cos(x1), R.
at(0,0) / cos(x1));
1899 float z2 = atan2(R.
at(1,0) / cos(x2), R.
at(0,0) / cos(x2));
1903 if ((abs(x1) + abs(y1) + abs(z1)) <= (abs(x2) + abs(y2) + abs(z2))) {
1918 for (
int i = 0; i < 3; i++)
1920 for (
int j = 0; j < 3; j++)
1922 ret.
at(i, j) =
static_cast<T
>(mat[j * 4 + i]);
1934 template<
class FromT>
1938 {
static_cast<T
>(arr[0]), static_cast<T>(arr[3]),
static_cast<T
>(arr[6]), static_cast<T>(arr[1]),
1939 static_cast<T
>(arr[4]), static_cast<T>(arr[7]),
static_cast<T
>(arr[2]), static_cast<T>(arr[5]),
1940 static_cast<T
>(arr[8]) };
1951 template<
class FromT>
1955 {
static_cast<T
>(arr[0]), static_cast<T>(arr[1]),
static_cast<T
>(arr[2]), static_cast<T>(arr[3]),
1956 static_cast<T
>(arr[4]), static_cast<T>(arr[5]),
static_cast<T
>(arr[6]), static_cast<T>(arr[7]),
1957 static_cast<T
>(arr[8]) };
1973 for (
int i = 0; i < 9; i++)
1975 if (std::fabs(data[i] - rhs.
data[i]) >= EPSILON)
1988 return !(*
this == rhs);
1999 assert(x >= 0 && x < 3);
2000 assert(y >= 0 && y < 3);
2001 return data[x * 3 +
y];
2011 assert(x >= 0 && x < 3);
2012 assert(y >= 0 && y < 3);
2013 return data[x * 3 +
y];
2023 assert(i >= 1 && i <= 3);
2024 assert(j >= 1 && j <= 3);
2025 return data[(j - 1) * 3 + i - 1];
2035 assert(i >= 1 && i <= 3);
2036 assert(j >= 1 && j <= 3);
2037 return data[(j - 1) * 3 + i - 1];
2046 std::memcpy(data, rhs.
data,
sizeof(T) * 9);
2054 template<
class FromT>
2057 for (
int i = 0; i < 9; i++)
2059 data[i] =
static_cast<T
>(rhs.
data[i]);
2070 std::memcpy(data, rhs,
sizeof(T) * 9);
2088 for (
int i = 0; i < 9; i++)
2089 ret.
data[i] = data[i] + rhs.
data[i];
2100 for (
int i = 0; i < 9; i++)
2101 ret.
data[i] = data[i] - rhs.
data[i];
2113 for (
int i = 0; i < 9; i++)
2114 ret.
data[i] = data[i] + rhs;
2125 for (
int i = 0; i < 9; i++)
2126 ret.
data[i] = data[i] - rhs;
2137 for (
int i = 0; i < 9; i++)
2138 ret.
data[i] = data[i] * rhs;
2149 for (
int i = 0; i < 9; i++)
2150 ret.
data[i] = data[i] / rhs;
2161 return Vector3<T>(data[0] * rhs.
x + data[3] * rhs.
y + data[6] * rhs.
z,
2162 data[1] * rhs.
x + data[4] * rhs.
y + data[7] * rhs.
z,
2163 data[2] * rhs.
x + data[5] * rhs.
y + data[8] * rhs.
z);
2173 for (
int i = 0; i < 3; i++)
2175 for (
int j = 0; j < 3; j++)
2178 for (
int k = 0; k < 3; k++)
2179 n += rhs.
at(i, k) * at(k, j);
2194 for (
int i = 0; i < 3; i++)
2196 for (
int j = 0; j < 3; j++)
2198 ret.
at(i, j) = at(j, i);
2215 Matrix3<T> ret = (*this) + (rhs - (*this)) * fact;
2221 return +at(0, 0) * at(1, 1) * at(2, 2) + at(0, 1) * at(1, 2) * at(2, 0) + at(0, 2) * at(1, 0) * at(2, 1)
2222 - at(0, 0) * at(1, 2) * at(2, 1) - at(0, 1) * at(1, 0) * at(2, 2) - at(0, 2) * at(1, 1) * at(2, 0);
2232 ret.
at(0, 0) = at(1, 1) * at(2, 2) - at(2, 1) * at(1, 2);
2233 ret.
at(0, 1) = at(2, 1) * at(0, 2) - at(0, 1) * at(2, 2);
2234 ret.
at(0, 2) = at(0, 1) * at(1, 2) - at(1, 1) * at(0, 2);
2235 ret.
at(1, 0) = at(2, 0) * at(1, 2) - at(1, 0) * at(2, 2);
2236 ret.
at(1, 1) = at(0, 0) * at(2, 2) - at(2, 0) * at(0, 2);
2237 ret.
at(1, 2) = at(1, 0) * at(0, 2) - at(0, 0) * at(1, 2);
2238 ret.
at(2, 0) = at(1, 0) * at(2, 1) - at(2, 0) * at(1, 1);
2239 ret.
at(2, 1) = at(2, 0) * at(0, 1) - at(0, 0) * at(2, 1);
2240 ret.
at(2, 2) = at(0, 0) * at(1, 1) - at(1, 0) * at(0, 1);
2241 return ret * (1.0f / det());
2261 operator const T*()
const 2263 return (
const T*) data;
2273 friend std::ostream& operator <<(std::ostream& lhs, const Matrix3<T>& rhs)
2275 for (
int i = 0; i < 3; i++)
2278 for (
int j = 0; j < 3; j++)
2280 lhs << rhs.
at(j, i) <<
"\t";
2282 lhs <<
"|" << std::endl;
2292 std::ostringstream oss;
2324 for (
int i = 0; i < 16; i++)
2325 data[i] = (i % 5) ? 0 : 1;
2334 std::memcpy(data, dt,
sizeof(T) * 16);
2343 for(
int i=0;i<4;i++){
2344 for(
int j=0;j<4;j++){
2348 std::memcpy(data, dt,
sizeof(T) * 16);
2368 std::memcpy(data, src.
data,
sizeof(T) * 16);
2373 for(
int i=0;i<4;i++){
2379 std::memcpy(data,m.
data,
sizeof(T)*16);
2386 template<
class FromT>
2389 for (
int i = 0; i < 16; i++)
2391 data[i] =
static_cast<T
>(src.
data[i]);
2402 for (
int i = 0; i < 16; i++)
2403 data[i] = (i % 5) ? 0 : 1;
2415 m.
at(0,0)= n.
at(0,0); m.
at(1,0)= n.
at(1,0); m.
at(2,0)= n.
at(2,0); m.
at(3,0)= 0.0f;
2416 m.
at(0,1)= n.
at(0,1); m.
at(1,1)= n.
at(1,1); m.
at(2,1)= n.
at(2,1); m.
at(3,1)= 0.0f;
2417 m.
at(0,2)= n.
at(0,2); m.
at(1,2)= n.
at(1,2); m.
at(2,2)= n.
at(2,2); m.
at(3,2)= 0.0f;
2418 m.
at(0,3)= 0.0f; m.
at(1,3)= 0.0f; m.
at(2,3)= 0.0f; m.
at(3,3)= 1.0f;
2430 for(
int i = 0; i < 4; i++){
2431 for(
int j = 0; j < 4; j++){
2432 vxm[i] += at(i,j) * v[j];
2447 for(
int i = 0; i < 4; i++){
2448 for(
int j = 0; j < 4; j++){
2449 vxm[i] += m.
at(i,j) * v[j];
2463 T xRads(DEG2RAD(xDeg));
2464 T yRads(DEG2RAD(yDeg));
2465 T zRads(DEG2RAD(zDeg));
2468 float ac = cos(xRads);
2469 float as = sin(xRads);
2470 float bc = cos(yRads);
2471 float bs = sin(yRads);
2472 float cc = cos(zRads);
2473 float cs = sin(zRads);
2504 if (closeEnough(R.
at(2,0), -1.0f)) {
2507 float z = x + atan2(R.
at(0,1), R.
at(0,2));
2509 }
else if (closeEnough(R.
at(2,0), 1.0f)) {
2511 float y = -M_PI / 2;
2512 float z = -x + atan2(-R.
at(0,1), -R.
at(0,2));
2515 float x1 = -asin(R.
at(2,0));
2516 float x2 = M_PI - x1;
2518 float y1 = atan2(R.
at(2,1) / cos(x1), R.
at(2,2) / cos(x1));
2519 float y2 = atan2(R.
at(2,1) / cos(x2), R.
at(2,2) / cos(x2));
2521 float z1 = atan2(R.
at(1,0) / cos(x1), R.
at(0,0) / cos(x1));
2522 float z2 = atan2(R.
at(1,0) / cos(x2), R.
at(0,0) / cos(x2));
2526 if ((abs(x1) + abs(y1) + abs(z1)) <= (abs(x2) + abs(y2) + abs(z2))) {
2583 forward = centerPos - eyePos;
2595 m.
at(0, 0) = side.
x;
2596 m.
at(1, 0) = side.
y;
2597 m.
at(2, 0) = side.
z;
2603 m.
at(0, 2) = -forward.
x;
2604 m.
at(1, 2) = -forward.
y;
2605 m.
at(2, 2) = -forward.
z;
2651 const T invWidth = 1.0 / (right - left);
2652 const T invHeight = 1.0 / (top - bottom);
2653 const T invDepth = 1.0 / (zFar - zNear);
2655 const T twoZNear = 2 * zNear;
2657 ret.
at(0,0) = twoZNear * invWidth;
2658 ret.
at(1,1) = twoZNear * invHeight;
2660 ret.
at(2,0) = (right + left) * invWidth;
2661 ret.
at(2,1) = (top + bottom) * invHeight;
2662 ret.
at(2,2) = - (zFar + zNear) * invDepth;
2665 ret.
at(3,2) = - twoZNear * zFar * invDepth;
2709 const T invWidth = 1.0 / (right - left);
2710 const T invHeight = 1.0 / (top - bottom);
2711 const T invDepth = 1.0 / (zFar - zNear);
2715 ret.
at(0,0) = 2 * invWidth;
2716 ret.
at(1,1) = 2 * invHeight;
2717 ret.
at(2,2) = -2 * invDepth;
2719 ret.
at(3,0) = -(right + left) * invWidth;
2720 ret.
at(3,1) = -(top + bottom) * invHeight;
2721 ret.
at(3,2) = -(zFar + zNear) * invDepth;
2738 T q = 1.0f / tan(radians(0.5f * fovy));
2740 T B = (n + f) / (n - f);
2741 T C = (2.0f * n * f) / (n - f);
2746 result[2] =
Vector4<T>(0.0f, 0.0f, B, -1.0f);
2766 if (nearPlane == farPlane || aspectRatio == 0.0f)
2771 T radians = (verticalAngle / 2.0f) * M_PI / 180.0f;
2772 T sine = sin(radians);
2775 T cotan = cos(radians) / sine;
2776 T clip = farPlane - nearPlane;
2777 ret.
at(0,0) = cotan / aspectRatio;
2778 ret.
at(1,1) = cotan;
2779 ret.
at(2,2) = -(nearPlane + farPlane) / clip;
2780 ret.
at(3,2) = -(2.0f * nearPlane * farPlane) / clip;
2781 ret.
at(2,3) = -1.0f;
2794 template<
class FromT>
2798 {
static_cast<T
>(arr[0]), static_cast<T>(arr[4]),
static_cast<T
>(arr[8]), static_cast<T>(arr[12]),
2799 static_cast<T
>(arr[1]), static_cast<T>(arr[5]),
static_cast<T
>(arr[9]), static_cast<T>(arr[13]),
2800 static_cast<T
>(arr[2]), static_cast<T>(arr[6]),
static_cast<T
>(arr[10]), static_cast<T>(arr[14]),
2801 static_cast<T
>(arr[3]), static_cast<T>(arr[7]),
static_cast<T
>(arr[11]), static_cast<T>(arr[15]) };
2812 template<
class FromT>
2816 {
static_cast<T
>(arr[0]), static_cast<T>(arr[1]),
static_cast<T
>(arr[2]), static_cast<T>(arr[3]),
2817 static_cast<T
>(arr[4]), static_cast<T>(arr[5]),
static_cast<T
>(arr[6]), static_cast<T>(arr[7]),
2818 static_cast<T
>(arr[8]), static_cast<T>(arr[9]),
static_cast<T
>(arr[10]), static_cast<T>(arr[11]),
2819 static_cast<T
>(arr[12]), static_cast<T>(arr[13]),
static_cast<T
>(arr[14]), static_cast<T>(arr[15]) };
2835 for (
int i = 0; i < 16; i++)
2837 if (std::fabs(data[i] - rhs.
data[i]) >= EPSILON
2851 return !(*
this == rhs);
2862 assert(x >= 0 && x < 4);
2863 assert(y >= 0 && y < 4);
2864 return data[x * 4 +
y];
2874 assert(x >= 0 && x < 4);
2875 assert(y >= 0 && y < 4);
2876 return data[x * 4 +
y];
2886 assert(i >= 1 && i <= 4);
2887 assert(j >= 1 && j <= 4);
2888 return data[(j - 1) * 4 + i - 1];
2898 assert(i >= 1 && i <= 4);
2899 assert(j >= 1 && j <= 4);
2900 return data[(j - 1) * 4 + i - 1];
2932 return Vector3<T>(at(3, 0), at(3, 1), at(3, 2));
2942 for (
int i = 0; i < 3; i++)
2944 for (
int j = 0; j < 3; j++)
2946 at(i, j) = m.
at(i, j);
2956 {
return Vector3<T>(at(0,0), at(1,1), at(2,2)); }
2964 at(0,0) = at(1,1) = at(2,2) =
s;
2997 std::memcpy(data, rhs.
data,
sizeof(T) * 16);
3005 template<
class FromT>
3008 for (
int i = 0; i < 16; i++)
3010 data[i] =
static_cast<T
>(rhs.
data[i]);
3021 std::memcpy(data, rhs,
sizeof(T) * 16);
3039 for (
int i = 0; i < 16; i++)
3040 ret.
data[i] = data[i] + rhs.
data[i];
3051 for (
int i = 0; i < 16; i++)
3052 ret.
data[i] = data[i] - rhs.
data[i];
3064 for (
int i = 0; i < 16; i++)
3065 ret.
data[i] = data[i] + rhs;
3076 for (
int i = 0; i < 16; i++)
3077 ret.
data[i] = data[i] - rhs;
3088 for (
int i = 0; i < 16; i++)
3089 ret.
data[i] = data[i] * rhs;
3100 for (
int i = 0; i < 16; i++)
3101 ret.
data[i] = data[i] / rhs;
3112 return Vector4<T>(data[0] * rhs.x + data[4] * rhs.
y + data[8] * rhs.
z + data[12] * rhs.
w,
3113 data[1] * rhs.x + data[5] * rhs.
y + data[9] * rhs.
z + data[13] * rhs.
w,
3114 data[2] * rhs.x + data[6] * rhs.
y + data[10] * rhs.
z + data[14] * rhs.
w,
3115 data[3] * rhs.x + data[7] * rhs.
y + data[11] * rhs.
z + data[15] * rhs.
w);
3125 return Vector3<T>(data[0] * rhs.
x + data[4] * rhs.
y + data[8] * rhs.
z,
3126 data[1] * rhs.
x + data[5] * rhs.
y + data[9] * rhs.
z,
3127 data[2] * rhs.
x + data[6] * rhs.
y + data[10] * rhs.
z);
3137 for (
int i = 0; i < 4; i++)
3139 for (
int j = 0; j < 4; j++)
3142 for (
int k = 0; k < 4; k++)
3143 n += rhs.
at(i, k) * at(k, j);
3161 return +at(3, 0) * at(2, 1) * at(1, 2) * at(0, 3) - at(2, 0) * at(3, 1) * at(1, 2) * at(0, 3)
3162 - at(3, 0) * at(1, 1) * at(2, 2) * at(0, 3) + at(1, 0) * at(3, 1) * at(2, 2) * at(0, 3)
3164 + at(2, 0) * at(1, 1) * at(3, 2) * at(0, 3) - at(1, 0) * at(2, 1) * at(3, 2) * at(0, 3)
3165 - at(3, 0) * at(2, 1) * at(0, 2) * at(1, 3) + at(2, 0) * at(3, 1) * at(0, 2) * at(1, 3)
3167 + at(3, 0) * at(0, 1) * at(2, 2) * at(1, 3) - at(0, 0) * at(3, 1) * at(2, 2) * at(1, 3)
3168 - at(2, 0) * at(0, 1) * at(3, 2) * at(1, 3) + at(0, 0) * at(2, 1) * at(3, 2) * at(1, 3)
3170 + at(3, 0) * at(1, 1) * at(0, 2) * at(2, 3) - at(1, 0) * at(3, 1) * at(0, 2) * at(2, 3)
3171 - at(3, 0) * at(0, 1) * at(1, 2) * at(2, 3) + at(0, 0) * at(3, 1) * at(1, 2) * at(2, 3)
3173 + at(1, 0) * at(0, 1) * at(3, 2) * at(2, 3) - at(0, 0) * at(1, 1) * at(3, 2) * at(2, 3)
3174 - at(2, 0) * at(1, 1) * at(0, 2) * at(3, 3) + at(1, 0) * at(2, 1) * at(0, 2) * at(3, 3)
3176 + at(2, 0) * at(0, 1) * at(1, 2) * at(3, 3) - at(0, 0) * at(2, 1) * at(1, 2) * at(3, 3)
3177 - at(1, 0) * at(0, 1) * at(2, 2) * at(3, 3) + at(0, 0) * at(1, 1) * at(2, 2) * at(3, 3);
3191 ret.
at(0, 0) = +at(2, 1) * at(3, 2) * at(1, 3) - at(3, 1) * at(2, 2) * at(1, 3) + at(3, 1) * at(1, 2) * at(2, 3)
3192 - at(1, 1) * at(3, 2) * at(2, 3) - at(2, 1) * at(1, 2) * at(3, 3) + at(1, 1) * at(2, 2) * at(3, 3);
3194 ret.
at(1, 0) = +at(3, 0) * at(2, 2) * at(1, 3) - at(2, 0) * at(3, 2) * at(1, 3) - at(3, 0) * at(1, 2) * at(2, 3)
3195 + at(1, 0) * at(3, 2) * at(2, 3) + at(2, 0) * at(1, 2) * at(3, 3) - at(1, 0) * at(2, 2) * at(3, 3);
3197 ret.
at(2, 0) = +at(2, 0) * at(3, 1) * at(1, 3) - at(3, 0) * at(2, 1) * at(1, 3) + at(3, 0) * at(1, 1) * at(2, 3)
3198 - at(1, 0) * at(3, 1) * at(2, 3) - at(2, 0) * at(1, 1) * at(3, 3) + at(1, 0) * at(2, 1) * at(3, 3);
3200 ret.
at(3, 0) = +at(3, 0) * at(2, 1) * at(1, 2) - at(2, 0) * at(3, 1) * at(1, 2) - at(3, 0) * at(1, 1) * at(2, 2)
3201 + at(1, 0) * at(3, 1) * at(2, 2) + at(2, 0) * at(1, 1) * at(3, 2) - at(1, 0) * at(2, 1) * at(3, 2);
3203 ret.
at(0, 1) = +at(3, 1) * at(2, 2) * at(0, 3) - at(2, 1) * at(3, 2) * at(0, 3) - at(3, 1) * at(0, 2) * at(2, 3)
3204 + at(0, 1) * at(3, 2) * at(2, 3) + at(2, 1) * at(0, 2) * at(3, 3) - at(0, 1) * at(2, 2) * at(3, 3);
3206 ret.
at(1, 1) = +at(2, 0) * at(3, 2) * at(0, 3) - at(3, 0) * at(2, 2) * at(0, 3) + at(3, 0) * at(0, 2) * at(2, 3)
3207 - at(0, 0) * at(3, 2) * at(2, 3) - at(2, 0) * at(0, 2) * at(3, 3) + at(0, 0) * at(2, 2) * at(3, 3);
3209 ret.
at(2, 1) = +at(3, 0) * at(2, 1) * at(0, 3) - at(2, 0) * at(3, 1) * at(0, 3) - at(3, 0) * at(0, 1) * at(2, 3)
3210 + at(0, 0) * at(3, 1) * at(2, 3) + at(2, 0) * at(0, 1) * at(3, 3) - at(0, 0) * at(2, 1) * at(3, 3);
3212 ret.
at(3, 1) = +at(2, 0) * at(3, 1) * at(0, 2) - at(3, 0) * at(2, 1) * at(0, 2) + at(3, 0) * at(0, 1) * at(2, 2)
3213 - at(0, 0) * at(3, 1) * at(2, 2) - at(2, 0) * at(0, 1) * at(3, 2) + at(0, 0) * at(2, 1) * at(3, 2);
3215 ret.
at(0, 2) = +at(1, 1) * at(3, 2) * at(0, 3) - at(3, 1) * at(1, 2) * at(0, 3) + at(3, 1) * at(0, 2) * at(1, 3)
3216 - at(0, 1) * at(3, 2) * at(1, 3) - at(1, 1) * at(0, 2) * at(3, 3) + at(0, 1) * at(1, 2) * at(3, 3);
3218 ret.
at(1, 2) = +at(3, 0) * at(1, 2) * at(0, 3) - at(1, 0) * at(3, 2) * at(0, 3) - at(3, 0) * at(0, 2) * at(1, 3)
3219 + at(0, 0) * at(3, 2) * at(1, 3) + at(1, 0) * at(0, 2) * at(3, 3) - at(0, 0) * at(1, 2) * at(3, 3);
3221 ret.
at(2, 2) = +at(1, 0) * at(3, 1) * at(0, 3) - at(3, 0) * at(1, 1) * at(0, 3) + at(3, 0) * at(0, 1) * at(1, 3)
3222 - at(0, 0) * at(3, 1) * at(1, 3) - at(1, 0) * at(0, 1) * at(3, 3) + at(0, 0) * at(1, 1) * at(3, 3);
3224 ret.
at(3, 2) = +at(3, 0) * at(1, 1) * at(0, 2) - at(1, 0) * at(3, 1) * at(0, 2) - at(3, 0) * at(0, 1) * at(1, 2)
3225 + at(0, 0) * at(3, 1) * at(1, 2) + at(1, 0) * at(0, 1) * at(3, 2) - at(0, 0) * at(1, 1) * at(3, 2);
3227 ret.
at(0, 3) = +at(2, 1) * at(1, 2) * at(0, 3) - at(1, 1) * at(2, 2) * at(0, 3) - at(2, 1) * at(0, 2) * at(1, 3)
3228 + at(0, 1) * at(2, 2) * at(1, 3) + at(1, 1) * at(0, 2) * at(2, 3) - at(0, 1) * at(1, 2) * at(2, 3);
3230 ret.
at(1, 3) = +at(1, 0) * at(2, 2) * at(0, 3) - at(2, 0) * at(1, 2) * at(0, 3) + at(2, 0) * at(0, 2) * at(1, 3)
3231 - at(0, 0) * at(2, 2) * at(1, 3) - at(1, 0) * at(0, 2) * at(2, 3) + at(0, 0) * at(1, 2) * at(2, 3);
3233 ret.
at(2, 3) = +at(2, 0) * at(1, 1) * at(0, 3) - at(1, 0) * at(2, 1) * at(0, 3) - at(2, 0) * at(0, 1) * at(1, 3)
3234 + at(0, 0) * at(2, 1) * at(1, 3) + at(1, 0) * at(0, 1) * at(2, 3) - at(0, 0) * at(1, 1) * at(2, 3);
3236 ret.
at(3, 3) = +at(1, 0) * at(2, 1) * at(0, 2) - at(2, 0) * at(1, 1) * at(0, 2) + at(2, 0) * at(0, 1) * at(1, 2)
3237 - at(0, 0) * at(2, 1) * at(1, 2) - at(1, 0) * at(0, 1) * at(2, 2) + at(0, 0) * at(1, 1) * at(2, 2);
3248 for (
int i = 0; i < 4; i++)
3250 for (
int j = 0; j < 4; j++)
3252 ret.
at(i, j) = at(j, i);
3269 Matrix4<T> ret = (*this) + (rhs - (*this)) * fact;
3289 operator const T*()
const 3291 return (
const T*) data;
3301 friend std::ostream& operator <<(std::ostream& lhs, const Matrix4<T>& rhs)
3303 for (
int i = 0; i < 4; i++)
3306 for (
int j = 0; j < 4; j++)
3308 lhs << rhs.
at(j, i) <<
"\t";
3310 lhs <<
"|" << std::endl;
3320 std::ostringstream oss;
3373 template<
class FromT>
3375 : w(static_cast<T>(q.w)), v(q.v)
3416 template<
class FromT>
3420 w =
static_cast<T
>(rhs.
w);
3442 lhs.
w * rhs.
v.x + lhs.
v.x * rhs.
w + lhs.
v.y * rhs.
v.z - lhs.
v.z * rhs.
v.y,
3443 lhs.
w * rhs.
v.y - lhs.
v.x * rhs.
v.z + lhs.
v.y * rhs.
w + lhs.
v.z * rhs.
v.x,
3444 lhs.
w * rhs.
v.z + lhs.
v.x * rhs.
v.y - lhs.
v.y * rhs.
v.x + lhs.
v.z * rhs.
w);
3521 return (std::fabs(lhs.
w - rhs.
w) < EPSILON) && lhs.
v == rhs.
v;
3531 return !(*
this == rhs);
3559 return (T) std::sqrt(w * w + v.
lengthSq());
3605 double angleRad = DEG2RAD(angleDeg);
3606 double sa2 = std::sin(angleRad / 2);
3607 double ca2 = std::cos(angleRad / 2);
3643 ret.
at(0, 0) = 1 - 2 * (yy + zz);
3644 ret.
at(1, 0) = 2 * (xy - zw);
3645 ret.
at(2, 0) = 2 * (xz + yw);
3647 ret.
at(0, 1) = 2 * (xy + zw);
3648 ret.
at(1, 1) = 1 - 2 * (xx + zz);
3649 ret.
at(2, 1) = 2 * (yz - xw);
3651 ret.
at(0, 2) = 2 * (xz - yw);
3652 ret.
at(1, 2) = 2 * (yz + xw);
3653 ret.
at(2, 2) = 1 - 2 * (xx + yy);
3680 ret.
at(0, 0) = 1 - 2 * (yy + zz);
3681 ret.
at(1, 0) = 2 * (xy - zw);
3682 ret.
at(2, 0) = 2 * (xz + yw);
3685 ret.
at(0, 1) = 2 * (xy + zw);
3686 ret.
at(1, 1) = 1 - 2 * (xx + zz);
3687 ret.
at(2, 1) = 2 * (yz - xw);
3690 ret.
at(0, 2) = 2 * (xz - yw);
3691 ret.
at(1, 2) = 2 * (yz + xw);
3692 ret.
at(2, 2) = 1 - 2 * (xx + yy);
3721 friend std::ostream& operator <<(std::ostream& oss, const Quaternion<T>& q)
3723 oss <<
"Re: " << q.
w <<
" Im: " << q.v;
3732 std::ostringstream oss;
3749 tr = m(1, 1) + m(2, 2) + m(3, 3);
3752 s = 0.5 / (T) sqrt(tr + 1.0);
3754 q.
v.x = (m(3, 2) - m(2, 3)) * s;
3755 q.
v.y = (m(1, 3) - m(3, 1)) * s;
3756 q.
v.z = (m(2, 1) - m(1, 2)) * s;
3764 char bigIdx = (d0 > d1) ? ((d0 > d2) ? 0 : 2):((d1 > d2) ? 1 : 2);
3768 s = 2.0 * (T) sqrt(1.0 + m(1, 1) - m(2, 2) - m(3, 3));
3769 q.
w = (m(3, 2) - m(2, 3)) / s;
3771 q.
v.y = (m(1, 2) + m(2, 1)) / s;
3772 q.
v.z = (m(1, 3) + m(3, 1)) / s;
3774 else if (bigIdx == 1)
3776 s = 2.0 * (T) sqrt(1.0 + m(2, 2) - m(1, 1) - m(3, 3));
3777 q.
w = (m(1, 3) - m(3, 1)) / s;
3778 q.
v.x = (m(1, 2) + m(2, 1)) / s;
3780 q.
v.z = (m(2, 3) + m(3, 2)) / s;
3784 s = 2.0 * (T) sqrt(1.0 + m(3, 3) - m(1, 1) - m(2, 2));
3785 q.
w = (m(2, 1) - m(1, 2)) / s;
3786 q.
v.x = (m(1, 3) + m(3, 1)) / s;
3787 q.
v.y = (m(2, 3) + m(3, 2)) / s;
3808 tr = m(1, 1) + m(2, 2) + m(3, 3);
3811 s = 0.5 / (T) sqrt(tr + 1.0);
3813 q.
v.x = (m(3, 2) - m(2, 3)) * s;
3814 q.
v.y = (m(1, 3) - m(3, 1)) * s;
3815 q.
v.z = (m(2, 1) - m(1, 2)) * s;
3823 char bigIdx = (d0 > d1) ? ((d0 > d2) ? 0 : 2):((d1 > d2) ? 1 : 2);
3827 s = 2.0 * (T) sqrt(1.0 + m(1, 1) - m(2, 2) - m(3, 3));
3828 q.
w = (m(3, 2) - m(2, 3)) / s;
3830 q.
v.y = (m(1, 2) + m(2, 1)) / s;
3831 q.
v.z = (m(1, 3) + m(3, 1)) / s;
3833 else if (bigIdx == 1)
3835 s = 2.0 * (T) sqrt(1.0 + m(2, 2) - m(1, 1) - m(3, 3));
3836 q.
w = (m(1, 3) - m(3, 1)) / s;
3837 q.
v.x = (m(1, 2) + m(2, 1)) / s;
3839 q.
v.z = (m(2, 3) + m(3, 2)) / s;
3843 s = 2.0 * (T) sqrt(1.0 + m(3, 3) - m(1, 1) - m(2, 2));
3844 q.
w = (m(2, 1) - m(1, 2)) / s;
3845 q.
v.x = (m(1, 3) + m(3, 1)) / s;
3846 q.
v.y = (m(2, 3) + m(3, 2)) / s;
3865 T cosTheta = w * q2.
w + v.
x * q2.
v.x + v.
y * q2.
v.y + v.
z * q2.
v.z;
3866 T theta = (T) acos(cosTheta);
3867 if (fabs(theta) < epsilon)
3873 T sinTheta = (T) sqrt(1.0 - cosTheta * cosTheta);
3874 if (fabs(sinTheta) < epsilon)
3876 ret.
w = 0.5 * w + 0.5 * q2.
w;
3877 ret.
v = v.
lerp(0.5, q2.
v);
3881 T rA = (T) sin((1.0 - r) * theta) / sinTheta;
3882 T rB = (T) sin(r * theta) / sinTheta;
3884 ret.
w = w * rA + q2.
w * rB;
3885 ret.
v.x = v.
x * rA + q2.
v.x * rB;
3886 ret.
v.y = v.
y * rA + q2.
v.y * rB;
3887 ret.
v.z = v.
z * rA + q2.
v.z * rB;
3898 #ifdef VMATH_NAMESPACE 3912 #ifdef VMATH_NAMESPACE 3913 #define VEC2 VMATH_NAMESPACE::Vector2 3914 #define VEC3 VMATH_NAMESPACE::Vector3 3915 #define VEC4 VMATH_NAMESPACE::Vector4 3917 #define VEC2 Vector2 3918 #define VEC3 Vector3 3919 #define VEC4 Vector4 3929 template <
typename T>
3930 VEC2<T> min(
const VEC2<T>& a,
const VEC2<T>& b)
3932 return VEC2<T>(::std::min(a.x, b.x), ::std::min(a.y, b.y));
3939 template <
typename T>
3940 VEC3<T> min(
const VEC3<T>& a,
const VEC3<T>& b)
3942 return VEC3<T>(::std::min(a.x, b.x), ::std::min(a.y, b.y), ::std::min(a.z, b.z));
3949 template <
typename T>
3950 VEC4<T> min(
const VEC4<T>& a,
const VEC4<T>& b)
3952 return VEC4<T>(::std::min(a.x, b.x), ::std::min(a.y, b.y), ::std::min(a.z, b.z), ::std::min(a.w, b.w));
3959 template <
typename T>
3960 VEC2<T> max(
const VEC2<T>& a,
const VEC2<T>& b)
3962 return VEC2<T>(::std::max(a.x, b.x), ::std::max(a.y, b.y));
3969 template <
typename T>
3970 VEC3<T> max(
const VEC3<T>& a,
const VEC3<T>& b)
3972 return VEC3<T>(::std::max(a.x, b.x), ::std::max(a.y, b.y), ::std::max(a.z, b.z));
3979 template <
typename T>
3980 VEC4<T> max(
const VEC4<T>& a,
const VEC4<T>& b)
3982 return VEC4<T>(::std::max(a.x, b.x), ::std::max(a.y, b.y), ::std::max(a.z, b.z), ::std::max(a.w, b.w));
3991 #ifdef VMATH_NAMESPACE 3994 #endif //VMATH_NAMESPACE 4012 template <
typename T>
4031 : min(1,1,1), max(-1,-1,-1)
4038 template <
typename SrcT>
4040 : min(point), max(point)
4053 template <
typename SrcT>
4054 Aabb3(SrcT x0, SrcT y0, SrcT z0, SrcT x1, SrcT y1, SrcT z1)
4055 : min(
std::min(x0,x1),
std::min(y0,y1),
std::min(z0,z1)),
4056 max(
std::max(x0,x1),
std::max(y0,y1),
std::max(z0,z1))
4065 template <
typename SrcT>
4067 : min(x,y,z), max(x,y,z)
4074 template <
typename SrcT>
4076 : min(src.min), max(src.max)
4084 template <
typename SrcT>
4100 {
return min.
x <= max.
x && min.
y <= max.
y && min.
z <= max.
z; }
4113 template <
typename SrcT>
4122 min = std::min(min, point);
4123 max = std::max(max, point);
4131 template <
typename SrcT>
4141 min = std::min(min, box.
min);
4142 max = std::max(max, box.
max);
4151 template <
typename SrcT>
4164 template <
typename SrcT>
4177 template <
typename SrcT>
4188 if (min.
x > point.
x || point.
x > max.
x)
4190 if (min.
y > point.
y || point.
y > max.
y)
4192 if (min.
z > point.
z || point.
z > max.
z)
4203 template <
typename SrcT>
4214 if (max.
x < box.
min.x || min.
x > box.
max.x)
4216 if (max.
y < box.
min.y || min.
y > box.
max.y)
4218 if (max.
z < box.
min.z || min.
z > box.
max.z)
4231 template <
typename SrcT>
4235 if (max.
x < other.
min.x || min.
x > other.
max.x)
4237 if (max.
y < other.
min.y || min.
y > other.
max.y)
4239 if (max.
z < other.
min.z || min.
z > other.
max.z)
4242 ret.
min = std::max(min, other.
min);
4243 ret.
max = std::min(max, other.
max);
4253 {
return (min + max) * 0.5f; }
4260 {
return (max - min) * 0.5f; }
4267 {
return max - min; }
4287 return Vector3<T>(i & 1 ? min.
x : max.
x, i & 2 ? min.
y : max.
y, i & 4 ? min.
z : max.
z);
4298 for (
size_t i = 0; i < 8; i++)
4301 ret.
extend((t * p).xyz());
4315 template <
typename RhsT>
4318 return min == rhs.
min && max == rhs.
max;
4326 template <
typename RhsT>
4329 return min != rhs.
min || max != rhs.
max;
4339 return transformed(rhs);
4349 *
this = transformed(rhs);
4359 template <
typename SrcT>
4371 template <
typename SrcT>
4383 template <
typename RhsT>
4386 return extended(rhs);
4394 template <
typename RhsT>
4397 return intersection(rhs);
4406 friend std::ostream& operator<<(std::ostream& lhs, const Aabb3<T>& rhs)
4408 lhs << rhs.min <<
" x " << rhs.max;
4417 #ifdef VMATH_NAMESPACE 4419 #endif //VMATH_NAMESPACE 4422 #endif // __vmath_Header_File__ static Quaternion< T > fromAxisRot(Vector3< T > axis, float angleDeg)
Vector4(T nx, T ny, T nz, T nw)
Vector3< T > operator*(const Vector3< T > &rhs) const
Vector4< T > & operator*=(T rhs)
Vector2< T > operator*(T rhs) const
static Matrix3< T > fromOde(const It *mat)
Aabb3< T > intersection(const Aabb3< SrcT > &other) const
Vector3< T > & operator*=(T rhs)
bool operator!=(const Vector3< T > &rhs) const
Aabb3< T > extended(const Vector3< SrcT > &point) const
bool operator==(const Aabb3< RhsT > &rhs) const
Vector3(T nx, T ny, T nz)
Vector2< T > operator+(const Vector2< T > &rhs) const
Matrix3< T > operator/(T rhs) const
std::string toString() const
T dotProduct(const Vector3< T > &rhs) const
Vector3(const Vector3< T > &src)
static Matrix4< T > createLookAt(const Vector3< T > &eyePos, const Vector3< T > ¢erPos, const Vector3< T > &upDir)
Matrix4< T > & operator=(const Matrix4< T > &rhs)
const T & operator[](int n) const
Matrix4< T > transform() const
void setTranslation(T nx, T ny, T nz)
Sets translation part of matrix.
Vector3< T > operator+(T rhs) const
Matrix3< T > operator*(Matrix3< T > rhs) const
Vector3< T > point(size_t i) const
Vector2< T > operator/(T rhs) const
Vector4< T > & operator*=(const Vector4< T > &rhs)
Quaternion(const Quaternion< T > &q)
Vector3< T > & operator*=(const Vector3< T > &rhs)
Matrix3(const Matrix3< FromT > &src)
static Quaternion< T > fromMatrix(const Matrix4< T > &m)
Vector4< T > operator-(const Vector4< T > &rhs) const
Matrix3(const Matrix3< T > &src)
Vector3< T > operator/(T rhs) const
Quaternion(const Quaternion< FromT > &q)
bool operator==(const Quaternion< T > &rhs) const
Vector2< T > operator/(const Vector2< T > &rhs) const
bool operator==(const Vector4< T > &rhs) const
static Matrix4< T > createTranslation(T x, T y, T z, T w=1)
Creates translation matrix.
Quaternion< T > operator+(const Quaternion< T > &rhs) const
void setTranslation(const Vector3< T > &v)
Quaternion< T > & operator=(const Quaternion< T > &rhs)
Vector3< T > operator*(T rhs) const
Matrix3< T > operator+(T rhs) const
static Quaternion< T > fromEulerAngles(T x, T y, T z)
Vector2< T > & operator-=(T rhs)
Vector3< T > & operator/=(const Vector3< T > &rhs)
void rotate(T ax, T ay, T az)
Quaternion< T > slerp(T r, const Quaternion< T > &q2) const
Vector3< T > lerp(T fact, const Vector3< T > &r) const
static Matrix4< T > Perspective(T verticalAngle, T aspectRatio, T nearPlane, T farPlane)
set up a perspective projection matrix
Vector2< T > & operator=(const Vector2< T > &rhs)
Vector2< T > & operator-=(const Vector2< T > &rhs)
std::string toString() const
const T & operator[](int n) const
void extend(const Vector3< SrcT > &point)
Matrix3< T > operator-(T rhs) const
Quaternion< T > & operator+=(const Quaternion< T > &rhs)
Vector2< T > & operator/=(const Vector2< T > &rhs)
Vector3< T > crossProduct(const Vector3< T > &rhs) const
Vector4< T > lerp(T fact, const Vector4< T > &r) const
Vector3< T > & operator-=(T rhs)
const T & at(int x, int y) const
const T & operator()(int i, int j) const
Matrix4< T > & operator=(const T *rhs)
Vector2< T > & operator*=(T rhs)
std::string toString() const
Aabb3(const Vector3< SrcT > &point)
Quaternion< T > operator*(T rhs) const
Aabb3(SrcT x, SrcT y, SrcT z)
T data[16]
Data stored in column major order.
static Matrix3< T > fromColumnMajorArray(const FromT *arr)
Vector4(const Vector4< FromT > &src)
Aabb3< T > extended(const Aabb3< SrcT > &box) const
static Vector4< T > vectorProductMatrix(const Vector4< T > v, Matrix4< T > m)
vectorProductMatrix: Multiplication function
Vector4< T > operator/(const Vector4< T > &rhs) const
Aabb3< T > transformed(const Matrix4< T > &t) const
bool intersects(const Aabb3< SrcT > &box) const
static Matrix3< T > createRotationAroundAxis(T xDeg, T yDeg, T zDeg)
Vector2(const Vector2< T > &src)
Vector4< T > operator+(const Vector4< T > &rhs) const
static Matrix4< T > createRotationAroundAxis(T xDeg, T yDeg, T zDeg)
Vector3< T > operator-(const Vector3< T > &rhs) const
static Matrix3< T > fromRowMajorArray(const FromT *arr)
Matrix3< T > operator-(const Matrix3< T > &rhs) const
void setRotation(const Matrix3< T > &m)
Vector4< T > operator-() const
Vector3< T > operator*(const Vector3< T > &rhs) const
Quaternion(T w_, T x, T y, T z)
Vector2< T > operator+(T rhs) const
Vector3< T > operator-() const
Vector4< T > operator-(T rhs) const
bool operator==(const Vector3< T > &rhs) const
Vector2< T > & operator+=(const Vector2< T > &rhs)
Aabb3< T > & operator=(const Aabb3< SrcT > &rhs)
Vector3< T > operator+(const Vector3< T > &rhs) const
Vector2< T > & operator+=(T rhs)
Vector4< T > & operator+=(const Vector4< T > &rhs)
T & operator()(int i, int j)
Quaternion< T > & operator*=(T rhs)
Quaternion(T w_, const Vector3< T > &v_)
bool operator==(const Matrix3< T > &rhs) const
Matrix4< T > lerp(T fact, const Matrix4< T > &rhs) const
Quaternion< T > lerp(T fact, const Quaternion< T > &rhs) const
bool operator==(const Matrix4< T > &rhs) const
Vector4< T > operator*(const Vector4< T > rhs) const
void extend(const Aabb3< SrcT > &box)
Vector4< T > operator=(const Vector4< FromT > &rhs)
Vector3< T > operator=(const Vector3< T > &rhs)
std::string toString() const
T data[9]
Data stored in column major order.
Vector4< T > & operator-=(T rhs)
Quaternion< T > & operator*=(const Quaternion< T > &rhs)
bool operator!=(const Vector4< T > &rhs) const
Matrix3< T > & operator=(const T *rhs)
Vector4< T > operator*(T rhs) const
Vector2< T > operator-(T rhs) const
const T & at(int x, int y) const
Aabb3(const Aabb3< SrcT > &src)
Vector3(const Vector3< FromT > &src)
Quaternion< T > & operator-=(const Quaternion< T > &rhs)
Vector4< T > & operator-=(const Vector4< T > &rhs)
Vector4< T > & operator/=(T rhs)
Vector4< T > & operator/=(const Vector4< T > &rhs)
Quaternion< T > operator~() const
Matrix4< T > operator+(const Matrix4< T > &rhs) const
void setScale(const Vector3< T > &s)
static Matrix4< T > Perspective_vmath(T fovy, T aspect, T n, T f)
set up a perspective projection matrix
static Matrix4< T > createScale(T sx, T sy, T sz)
Matrix4(const Matrix4< FromT > &src)
bool operator!=(const Matrix4< T > &rhs) const
Matrix4< T > operator*(Matrix4< T > rhs) const
bool intersects(const Vector3< SrcT > &point) const
std::string toString() const
Matrix4< T > operator-(const Matrix4< T > &rhs) const
Vector3< T > extent() const
static Quaternion< T > fromMatrix(const Matrix3< T > &m)
Vector2< T > operator-(const Vector2< T > &rhs) const
Vector2(const Vector2< FromT > &src)
Vector4< T > operator+(T rhs) const
Quaternion< T > operator-(const Quaternion< T > &rhs) const
Aabb3< T > operator|(const Aabb3< RhsT > &rhs) const
Vector4(T nx, T ny, T nz)
Vector3< T > operator/(const Vector3< T > &rhs) const
Matrix4< T > & operator=(const Matrix4< FromT > &rhs)
Matrix4< T > operator/(T rhs) const
bool operator!=(const Quaternion< T > &rhs) const
Vector3< T > operator=(const Vector3< FromT > &rhs)
Aabb3< T > & operator*=(const Matrix4< T > &rhs)
Vector4< T > operator=(const Vector4< T > &rhs)
static Matrix4< T > fromRowMajorArray(const FromT *arr)
Vector4< T > operator*(const Vector4< T > &rhs) const
Matrix4< T > operator*(T rhs) const
Vector2< T > lerp(T fact, const Vector2< T > &r) const
Matrix3< T > operator*(T rhs) const
Matrix3< T > lerp(T fact, const Matrix3< T > &rhs) const
Matrix4(const T dt[4][4])
Vector4< T > & operator+=(T rhs)
Matrix4< T > operator+(T rhs) const
static Vector3< T > vectorProductMatrix(const Vector3< T > v, Matrix3< T > m)
vectorProductMatrix: Multiplication function
void setScale(T sx, T sy, T sz)
bool operator!=(const Matrix3< T > &rhs) const
Vector2< T > operator-() const
Vector4< T > operator/(T rhs) const
Vector4(const Vector4< T > &src)
Vector3< T > getScale() const
std::string toString() const
Aabb3< T > operator*(const Matrix4< T > &rhs) const
bool operator==(const Vector2< T > &rhs) const
static Matrix4< T > fromColumnMajorArray(const FromT *arr)
bool operator!=(const Vector2< T > &rhs) const
Vector3< T > & operator+=(const Vector3< T > &rhs)
Vector3< T > operator*(const Vector3< T > &rhs) const
const T & operator()(int i, int j) const
Matrix3< T > & operator=(const Matrix3< FromT > &rhs)
Vector3< T > operator-(T rhs) const
Matrix4< T > operator-(T rhs) const
const T & operator[](int n) const
Vector3< T > vectorProductMatrix(const Vector3< T > &v) const
vectorProductMatrix: Multiplication function
static Matrix4< T > createFrustum(T left, T right, T bottom, T top, T zNear, T zFar)
Vector3< T > size() const
Quaternion< T > operator-() const
Vector3< T > & operator/=(T rhs)
T & operator()(int i, int j)
Matrix4(const Matrix4< T > &src)
Vector3< T > & operator+=(T rhs)
Vector2< T > & operator=(const Vector2< FromT > &rhs)
bool operator!=(const Aabb3< RhsT > &rhs) const
Vector2< T > operator*(const Vector2< T > &rhs) const
Quaternion< T > & operator=(const Quaternion< FromT > &rhs)
Vector4< T > vectorProductMatrix(const Vector4< T > &v) const
vectorProductMatrix: Multiplication function
Matrix3< T > operator+(const Matrix3< T > &rhs) const
Aabb3(SrcT x0, SrcT y0, SrcT z0, SrcT x1, SrcT y1, SrcT z1)
Vector2< T > & operator*=(const Vector2< T > &rhs)
Vector3< T > center() const
static Matrix4< T > createOrtho(T left, T right, T bottom, T top, T zNear, T zFar)
static Matrix4< T > createMat4FromMat3(Matrix3< T > n)
createMat4FromMat3 Creates 4x4 Matrix from 3x3 Matrix (Homogeneous Matrix).
Matrix3< T > & operator=(const Matrix3< T > &rhs)
Vector2< T > & operator/=(T rhs)
Vector3< T > & operator-=(const Vector3< T > &rhs)
Quaternion< T > operator*(const Quaternion< T > &rhs) const