37 #ifndef INCLUDED_IMATHMATRIX_H 38 #define INCLUDED_IMATHMATRIX_H 55 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER 57 #pragma warning(disable:4290) 101 Matrix33 (T a, T b, T c, T d, T e, T f, T g, T h, T i);
263 throw (Iex::MathExc);
266 throw (Iex::MathExc);
269 throw (Iex::MathExc);
272 throw (Iex::MathExc);
382 template <
typename R,
typename S>
388 template <
typename R>
389 struct isSameType<R, R>
396 template <
class T>
class Matrix44
434 Matrix44 (T a, T b, T c, T d, T e, T f, T g, T h,
435 T i, T j, T k, T l, T m, T n, T o, T p);
607 throw (Iex::MathExc);
610 throw (Iex::MathExc);
613 throw (Iex::MathExc);
616 throw (Iex::MathExc);
752 template <
typename R,
typename S>
758 template <
typename R>
759 struct isSameType<R, R>
771 std::ostream & operator << (std::ostream & s, const Matrix33<T> &m);
774 std::ostream & operator << (std::ostream & s, const Matrix44<T> &m);
781 template <
class S,
class T>
782 const Vec2<S> &
operator *= (Vec2<S> &v,
const Matrix33<T> &m);
784 template <
class S,
class T>
785 Vec2<S>
operator * (
const Vec2<S> &v,
const Matrix33<T> &m);
787 template <
class S,
class T>
788 const Vec3<S> &
operator *= (Vec3<S> &v,
const Matrix33<T> &m);
790 template <
class S,
class T>
791 Vec3<S>
operator * (
const Vec3<S> &v,
const Matrix33<T> &m);
793 template <
class S,
class T>
794 const Vec3<S> &
operator *= (Vec3<S> &v,
const Matrix44<T> &m);
796 template <
class S,
class T>
797 Vec3<S>
operator * (
const Vec3<S> &v,
const Matrix44<T> &m);
799 template <
class S,
class T>
800 const Vec4<S> &
operator *= (Vec4<S> &v,
const Matrix44<T> &m);
802 template <
class S,
class T>
803 Vec4<S>
operator * (
const Vec4<S> &v,
const Matrix44<T> &m);
837 memset (x, 0,
sizeof (x));
862 memcpy (x, a,
sizeof (x));
884 memcpy (x, v.
x, sizeof (x));
892 x[0][0] = T (v.
x[0][0]);
893 x[0][1] = T (v.
x[0][1]);
894 x[0][2] = T (v.
x[0][2]);
895 x[1][0] = T (v.
x[1][0]);
896 x[1][1] = T (v.
x[1][1]);
897 x[1][2] = T (v.
x[1][2]);
898 x[2][0] = T (v.
x[2][0]);
899 x[2][1] = T (v.
x[2][1]);
900 x[2][2] = T (v.
x[2][2]);
907 memcpy (x, v.
x, sizeof (x));
931 return (T *) &x[0][0];
938 return (
const T *) &x[0][0];
946 if (isSameType<S,T>::value)
948 memcpy (v.
x, x, sizeof (x));
969 if (isSameType<S,T>::value)
971 memcpy (x, v.
x, sizeof (x));
994 if (isSameType<S,T>::value)
996 memcpy (x, v.
x, sizeof (x));
1000 x[0][0] = v.
x[0][0];
1001 x[0][1] = v.
x[0][1];
1002 x[0][2] = v.
x[0][2];
1003 x[1][0] = v.
x[1][0];
1004 x[1][1] = v.
x[1][1];
1005 x[1][2] = v.
x[1][2];
1006 x[2][0] = v.
x[2][0];
1007 x[2][1] = v.
x[2][1];
1008 x[2][2] = v.
x[2][2];
1018 memset (x, 0,
sizeof (x));
1028 return x[0][0] == v.
x[0][0] &&
1029 x[0][1] == v.
x[0][1] &&
1030 x[0][2] == v.
x[0][2] &&
1031 x[1][0] == v.
x[1][0] &&
1032 x[1][1] == v.
x[1][1] &&
1033 x[1][2] == v.
x[1][2] &&
1034 x[2][0] == v.
x[2][0] &&
1035 x[2][1] == v.
x[2][1] &&
1036 x[2][2] == v.
x[2][2];
1043 return x[0][0] != v.
x[0][0] ||
1044 x[0][1] != v.
x[0][1] ||
1045 x[0][2] != v.
x[0][2] ||
1046 x[1][0] != v.
x[1][0] ||
1047 x[1][1] != v.
x[1][1] ||
1048 x[1][2] != v.
x[1][2] ||
1049 x[2][0] != v.
x[2][0] ||
1050 x[2][1] != v.
x[2][1] ||
1051 x[2][2] != v.
x[2][2];
1058 for (
int i = 0; i < 3; i++)
1059 for (
int j = 0; j < 3; j++)
1070 for (
int i = 0; i < 3; i++)
1071 for (
int j = 0; j < 3; j++)
1082 x[0][0] += v.
x[0][0];
1083 x[0][1] += v.
x[0][1];
1084 x[0][2] += v.
x[0][2];
1085 x[1][0] += v.
x[1][0];
1086 x[1][1] += v.
x[1][1];
1087 x[1][2] += v.
x[1][2];
1088 x[2][0] += v.
x[2][0];
1089 x[2][1] += v.
x[2][1];
1090 x[2][2] += v.
x[2][2];
1117 x[0][1] + v.
x[0][1],
1118 x[0][2] + v.
x[0][2],
1119 x[1][0] + v.
x[1][0],
1120 x[1][1] + v.
x[1][1],
1121 x[1][2] + v.
x[1][2],
1122 x[2][0] + v.
x[2][0],
1123 x[2][1] + v.
x[2][1],
1124 x[2][2] + v.
x[2][2]);
1131 x[0][0] -= v.
x[0][0];
1132 x[0][1] -= v.
x[0][1];
1133 x[0][2] -= v.
x[0][2];
1134 x[1][0] -= v.
x[1][0];
1135 x[1][1] -= v.
x[1][1];
1136 x[1][2] -= v.
x[1][2];
1137 x[2][0] -= v.
x[2][0];
1138 x[2][1] -= v.
x[2][1];
1139 x[2][2] -= v.
x[2][2];
1166 x[0][1] - v.
x[0][1],
1167 x[0][2] - v.
x[0][2],
1168 x[1][0] - v.
x[1][0],
1169 x[1][1] - v.
x[1][1],
1170 x[1][2] - v.
x[1][2],
1171 x[2][0] - v.
x[2][0],
1172 x[2][1] - v.
x[2][1],
1173 x[2][2] - v.
x[2][2]);
1253 for (
int i = 0; i < 3; i++)
1254 for (
int j = 0; j < 3; j++)
1255 for (
int k = 0; k < 3; k++)
1256 tmp.
x[i][j] += x[i][k] * v.
x[k][j];
1268 for (
int i = 0; i < 3; i++)
1269 for (
int j = 0; j < 3; j++)
1270 for (
int k = 0; k < 3; k++)
1271 tmp.
x[i][j] += x[i][k] * v.
x[k][j];
1283 a = src[0] * x[0][0] + src[1] * x[1][0] + x[2][0];
1284 b = src[0] * x[0][1] + src[1] * x[1][1] + x[2][1];
1285 w = src[0] * x[0][2] + src[1] * x[1][2] + x[2][2];
1298 a = src[0] * x[0][0] + src[1] * x[1][0];
1299 b = src[0] * x[0][1] + src[1] * x[1][1];
1373 *
this = gjInverse (singExc);
1387 for (i = 0; i < 2 ; i++)
1391 T pivotsize = t[i][i];
1394 pivotsize = -pivotsize;
1396 for (j = i + 1; j < 3; j++)
1403 if (tmp > pivotsize)
1413 throw ::Imath::SingMatrixExc (
"Cannot invert singular matrix.");
1420 for (j = 0; j < 3; j++)
1425 t[i][j] = t[pivot][j];
1429 s[i][j] = s[pivot][j];
1434 for (j = i + 1; j < 3; j++)
1436 T f = t[j][i] / t[i][i];
1438 for (k = 0; k < 3; k++)
1440 t[j][k] -= f * t[i][k];
1441 s[j][k] -= f * s[i][k];
1448 for (i = 2; i >= 0; --i)
1452 if ((f = t[i][i]) == 0)
1455 throw ::Imath::SingMatrixExc (
"Cannot invert singular matrix.");
1460 for (j = 0; j < 3; j++)
1466 for (j = 0; j < i; j++)
1470 for (k = 0; k < 3; k++)
1472 t[j][k] -= f * t[i][k];
1473 s[j][k] -= f * s[i][k];
1485 *
this = inverse (singExc);
1493 if (x[0][2] != 0 || x[1][2] != 0 || x[2][2] != 1)
1495 Matrix33 s (x[1][1] * x[2][2] - x[2][1] * x[1][2],
1496 x[2][1] * x[0][2] - x[0][1] * x[2][2],
1497 x[0][1] * x[1][2] - x[1][1] * x[0][2],
1499 x[2][0] * x[1][2] - x[1][0] * x[2][2],
1500 x[0][0] * x[2][2] - x[2][0] * x[0][2],
1501 x[1][0] * x[0][2] - x[0][0] * x[1][2],
1503 x[1][0] * x[2][1] - x[2][0] * x[1][1],
1504 x[2][0] * x[0][1] - x[0][0] * x[2][1],
1505 x[0][0] * x[1][1] - x[1][0] * x[0][1]);
1507 T r = x[0][0] * s[0][0] + x[0][1] * s[1][0] + x[0][2] * s[2][0];
1511 for (
int i = 0; i < 3; ++i)
1513 for (
int j = 0; j < 3; ++j)
1523 for (
int i = 0; i < 3; ++i)
1525 for (
int j = 0; j < 3; ++j)
1534 throw SingMatrixExc (
"Cannot invert " 1535 "singular matrix.");
1558 T r = x[0][0] * x[1][1] - x[1][0] * x[0][1];
1562 for (
int i = 0; i < 2; ++i)
1564 for (
int j = 0; j < 2; ++j)
1574 for (
int i = 0; i < 2; ++i)
1576 for (
int j = 0; j < 2; ++j)
1585 throw SingMatrixExc (
"Cannot invert " 1586 "singular matrix.");
1593 s[2][0] = -x[2][0] * s[0][0] - x[2][1] * s[1][0];
1594 s[2][1] = -x[2][0] * s[0][1] - x[2][1] * s[1][1];
1638 memset (x, 0,
sizeof (x));
1651 memset (x, 0,
sizeof (x));
1699 return Vec2<T> (x[2][0], x[2][1]);
1707 x[2][0] += t[0] * x[0][0] + t[1] * x[1][0];
1708 x[2][1] += t[0] * x[0][1] + t[1] * x[1][1];
1709 x[2][2] += t[0] * x[0][2] + t[1] * x[1][2];
1765 x[1][0] += xy * x[0][0];
1766 x[1][1] += xy * x[0][1];
1767 x[1][2] += xy * x[0][2];
1779 x[0][0] = P[0][0] + h[1] * P[1][0];
1780 x[0][1] = P[0][1] + h[1] * P[1][1];
1781 x[0][2] = P[0][2] + h[1] * P[1][2];
1783 x[1][0] = P[1][0] + h[0] * P[0][0];
1784 x[1][1] = P[1][1] + h[0] * P[0][1];
1785 x[1][2] = P[1][2] + h[0] * P[0][2];
1813 memset (x, 0,
sizeof (x));
1846 memcpy (x, a,
sizeof (x));
1852 T i, T j, T k, T l, T m, T n, T o, T p)
1899 x[0][0] = v.x[0][0];
1900 x[0][1] = v.x[0][1];
1901 x[0][2] = v.x[0][2];
1902 x[0][3] = v.x[0][3];
1903 x[1][0] = v.x[1][0];
1904 x[1][1] = v.x[1][1];
1905 x[1][2] = v.x[1][2];
1906 x[1][3] = v.x[1][3];
1907 x[2][0] = v.x[2][0];
1908 x[2][1] = v.x[2][1];
1909 x[2][2] = v.x[2][2];
1910 x[2][3] = v.x[2][3];
1911 x[3][0] = v.x[3][0];
1912 x[3][1] = v.x[3][1];
1913 x[3][2] = v.x[3][2];
1914 x[3][3] = v.x[3][3];
1922 x[0][0] = T (v.x[0][0]);
1923 x[0][1] = T (v.x[0][1]);
1924 x[0][2] = T (v.x[0][2]);
1925 x[0][3] = T (v.x[0][3]);
1926 x[1][0] = T (v.x[1][0]);
1927 x[1][1] = T (v.x[1][1]);
1928 x[1][2] = T (v.x[1][2]);
1929 x[1][3] = T (v.x[1][3]);
1930 x[2][0] = T (v.x[2][0]);
1931 x[2][1] = T (v.x[2][1]);
1932 x[2][2] = T (v.x[2][2]);
1933 x[2][3] = T (v.x[2][3]);
1934 x[3][0] = T (v.x[3][0]);
1935 x[3][1] = T (v.x[3][1]);
1936 x[3][2] = T (v.x[3][2]);
1937 x[3][3] = T (v.x[3][3]);
1944 x[0][0] = v.x[0][0];
1945 x[0][1] = v.x[0][1];
1946 x[0][2] = v.x[0][2];
1947 x[0][3] = v.x[0][3];
1948 x[1][0] = v.x[1][0];
1949 x[1][1] = v.x[1][1];
1950 x[1][2] = v.x[1][2];
1951 x[1][3] = v.x[1][3];
1952 x[2][0] = v.x[2][0];
1953 x[2][1] = v.x[2][1];
1954 x[2][2] = v.x[2][2];
1955 x[2][3] = v.x[2][3];
1956 x[3][0] = v.x[3][0];
1957 x[3][1] = v.x[3][1];
1958 x[3][2] = v.x[3][2];
1959 x[3][3] = v.x[3][3];
1990 return (T *) &x[0][0];
1997 return (
const T *) &x[0][0];
2005 if (isSameType<S,T>::value)
2007 memcpy (v.x, x, sizeof (x));
2011 v.x[0][0] = x[0][0];
2012 v.x[0][1] = x[0][1];
2013 v.x[0][2] = x[0][2];
2014 v.x[0][3] = x[0][3];
2015 v.x[1][0] = x[1][0];
2016 v.x[1][1] = x[1][1];
2017 v.x[1][2] = x[1][2];
2018 v.x[1][3] = x[1][3];
2019 v.x[2][0] = x[2][0];
2020 v.x[2][1] = x[2][1];
2021 v.x[2][2] = x[2][2];
2022 v.x[2][3] = x[2][3];
2023 v.x[3][0] = x[3][0];
2024 v.x[3][1] = x[3][1];
2025 v.x[3][2] = x[3][2];
2026 v.x[3][3] = x[3][3];
2035 if (isSameType<S,T>::value)
2037 memcpy (x, v.x, sizeof (x));
2041 x[0][0] = v.x[0][0];
2042 x[0][1] = v.x[0][1];
2043 x[0][2] = v.x[0][2];
2044 x[0][3] = v.x[0][3];
2045 x[1][0] = v.x[1][0];
2046 x[1][1] = v.x[1][1];
2047 x[1][2] = v.x[1][2];
2048 x[1][3] = v.x[1][3];
2049 x[2][0] = v.x[2][0];
2050 x[2][1] = v.x[2][1];
2051 x[2][2] = v.x[2][2];
2052 x[2][3] = v.x[2][3];
2053 x[3][0] = v.x[3][0];
2054 x[3][1] = v.x[3][1];
2055 x[3][2] = v.x[3][2];
2056 x[3][3] = v.x[3][3];
2067 if (isSameType<S,T>::value)
2069 memcpy (x, v.x, sizeof (x));
2073 x[0][0] = v.x[0][0];
2074 x[0][1] = v.x[0][1];
2075 x[0][2] = v.x[0][2];
2076 x[0][3] = v.x[0][3];
2077 x[1][0] = v.x[1][0];
2078 x[1][1] = v.x[1][1];
2079 x[1][2] = v.x[1][2];
2080 x[1][3] = v.x[1][3];
2081 x[2][0] = v.x[2][0];
2082 x[2][1] = v.x[2][1];
2083 x[2][2] = v.x[2][2];
2084 x[2][3] = v.x[2][3];
2085 x[3][0] = v.x[3][0];
2086 x[3][1] = v.x[3][1];
2087 x[3][2] = v.x[3][2];
2088 x[3][3] = v.x[3][3];
2098 memset (x, 0,
sizeof (x));
2109 return x[0][0] == v.x[0][0] &&
2110 x[0][1] == v.x[0][1] &&
2111 x[0][2] == v.x[0][2] &&
2112 x[0][3] == v.x[0][3] &&
2113 x[1][0] == v.x[1][0] &&
2114 x[1][1] == v.x[1][1] &&
2115 x[1][2] == v.x[1][2] &&
2116 x[1][3] == v.x[1][3] &&
2117 x[2][0] == v.x[2][0] &&
2118 x[2][1] == v.x[2][1] &&
2119 x[2][2] == v.x[2][2] &&
2120 x[2][3] == v.x[2][3] &&
2121 x[3][0] == v.x[3][0] &&
2122 x[3][1] == v.x[3][1] &&
2123 x[3][2] == v.x[3][2] &&
2124 x[3][3] == v.x[3][3];
2131 return x[0][0] != v.x[0][0] ||
2132 x[0][1] != v.x[0][1] ||
2133 x[0][2] != v.x[0][2] ||
2134 x[0][3] != v.x[0][3] ||
2135 x[1][0] != v.x[1][0] ||
2136 x[1][1] != v.x[1][1] ||
2137 x[1][2] != v.x[1][2] ||
2138 x[1][3] != v.x[1][3] ||
2139 x[2][0] != v.x[2][0] ||
2140 x[2][1] != v.x[2][1] ||
2141 x[2][2] != v.x[2][2] ||
2142 x[2][3] != v.x[2][3] ||
2143 x[3][0] != v.x[3][0] ||
2144 x[3][1] != v.x[3][1] ||
2145 x[3][2] != v.x[3][2] ||
2146 x[3][3] != v.x[3][3];
2153 for (
int i = 0; i < 4; i++)
2154 for (
int j = 0; j < 4; j++)
2165 for (
int i = 0; i < 4; i++)
2166 for (
int j = 0; j < 4; j++)
2177 x[0][0] += v.x[0][0];
2178 x[0][1] += v.x[0][1];
2179 x[0][2] += v.x[0][2];
2180 x[0][3] += v.x[0][3];
2181 x[1][0] += v.x[1][0];
2182 x[1][1] += v.x[1][1];
2183 x[1][2] += v.x[1][2];
2184 x[1][3] += v.x[1][3];
2185 x[2][0] += v.x[2][0];
2186 x[2][1] += v.x[2][1];
2187 x[2][2] += v.x[2][2];
2188 x[2][3] += v.x[2][3];
2189 x[3][0] += v.x[3][0];
2190 x[3][1] += v.x[3][1];
2191 x[3][2] += v.x[3][2];
2192 x[3][3] += v.x[3][3];
2225 return Matrix44 (x[0][0] + v.x[0][0],
2226 x[0][1] + v.x[0][1],
2227 x[0][2] + v.x[0][2],
2228 x[0][3] + v.x[0][3],
2229 x[1][0] + v.x[1][0],
2230 x[1][1] + v.x[1][1],
2231 x[1][2] + v.x[1][2],
2232 x[1][3] + v.x[1][3],
2233 x[2][0] + v.x[2][0],
2234 x[2][1] + v.x[2][1],
2235 x[2][2] + v.x[2][2],
2236 x[2][3] + v.x[2][3],
2237 x[3][0] + v.x[3][0],
2238 x[3][1] + v.x[3][1],
2239 x[3][2] + v.x[3][2],
2240 x[3][3] + v.x[3][3]);
2247 x[0][0] -= v.x[0][0];
2248 x[0][1] -= v.x[0][1];
2249 x[0][2] -= v.x[0][2];
2250 x[0][3] -= v.x[0][3];
2251 x[1][0] -= v.x[1][0];
2252 x[1][1] -= v.x[1][1];
2253 x[1][2] -= v.x[1][2];
2254 x[1][3] -= v.x[1][3];
2255 x[2][0] -= v.x[2][0];
2256 x[2][1] -= v.x[2][1];
2257 x[2][2] -= v.x[2][2];
2258 x[2][3] -= v.x[2][3];
2259 x[3][0] -= v.x[3][0];
2260 x[3][1] -= v.x[3][1];
2261 x[3][2] -= v.x[3][2];
2262 x[3][3] -= v.x[3][3];
2295 return Matrix44 (x[0][0] - v.x[0][0],
2296 x[0][1] - v.x[0][1],
2297 x[0][2] - v.x[0][2],
2298 x[0][3] - v.x[0][3],
2299 x[1][0] - v.x[1][0],
2300 x[1][1] - v.x[1][1],
2301 x[1][2] - v.x[1][2],
2302 x[1][3] - v.x[1][3],
2303 x[2][0] - v.x[2][0],
2304 x[2][1] - v.x[2][1],
2305 x[2][2] - v.x[2][2],
2306 x[2][3] - v.x[2][3],
2307 x[3][0] - v.x[3][0],
2308 x[3][1] - v.x[3][1],
2309 x[3][2] - v.x[3][2],
2310 x[3][3] - v.x[3][3]);
2413 inline const Matrix44<T> &
2418 multiply (*
this, v, tmp);
2429 multiply (*
this, v, tmp);
2450 cp[0] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12];
2451 cp[1] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13];
2452 cp[2] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14];
2453 cp[3] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15];
2460 cp[4] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12];
2461 cp[5] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13];
2462 cp[6] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14];
2463 cp[7] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15];
2470 cp[8] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12];
2471 cp[9] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13];
2472 cp[10] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14];
2473 cp[11] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15];
2480 cp[12] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12];
2481 cp[13] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13];
2482 cp[14] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14];
2483 cp[15] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15];
2486 template <
class T>
template <
class S>
2492 a = src[0] * x[0][0] + src[1] * x[1][0] + src[2] * x[2][0] + x[3][0];
2493 b = src[0] * x[0][1] + src[1] * x[1][1] + src[2] * x[2][1] + x[3][1];
2494 c = src[0] * x[0][2] + src[1] * x[1][2] + src[2] * x[2][2] + x[3][2];
2495 w = src[0] * x[0][3] + src[1] * x[1][3] + src[2] * x[2][3] + x[3][3];
2502 template <
class T>
template <
class S>
2508 a = src[0] * x[0][0] + src[1] * x[1][0] + src[2] * x[2][0];
2509 b = src[0] * x[0][1] + src[1] * x[1][1] + src[2] * x[2][1];
2510 c = src[0] * x[0][2] + src[1] * x[1][2] + src[2] * x[2][2];
2613 *
this = gjInverse (singExc);
2627 for (i = 0; i < 3 ; i++)
2631 T pivotsize = t[i][i];
2634 pivotsize = -pivotsize;
2636 for (j = i + 1; j < 4; j++)
2643 if (tmp > pivotsize)
2653 throw ::Imath::SingMatrixExc (
"Cannot invert singular matrix.");
2660 for (j = 0; j < 4; j++)
2665 t[i][j] = t[pivot][j];
2669 s[i][j] = s[pivot][j];
2674 for (j = i + 1; j < 4; j++)
2676 T f = t[j][i] / t[i][i];
2678 for (k = 0; k < 4; k++)
2680 t[j][k] -= f * t[i][k];
2681 s[j][k] -= f * s[i][k];
2688 for (i = 3; i >= 0; --i)
2692 if ((f = t[i][i]) == 0)
2695 throw ::Imath::SingMatrixExc (
"Cannot invert singular matrix.");
2700 for (j = 0; j < 4; j++)
2706 for (j = 0; j < i; j++)
2710 for (k = 0; k < 4; k++)
2712 t[j][k] -= f * t[i][k];
2713 s[j][k] -= f * s[i][k];
2725 *
this = inverse (singExc);
2733 if (x[0][3] != 0 || x[1][3] != 0 || x[2][3] != 0 || x[3][3] != 1)
2734 return gjInverse(singExc);
2736 Matrix44 s (x[1][1] * x[2][2] - x[2][1] * x[1][2],
2737 x[2][1] * x[0][2] - x[0][1] * x[2][2],
2738 x[0][1] * x[1][2] - x[1][1] * x[0][2],
2741 x[2][0] * x[1][2] - x[1][0] * x[2][2],
2742 x[0][0] * x[2][2] - x[2][0] * x[0][2],
2743 x[1][0] * x[0][2] - x[0][0] * x[1][2],
2746 x[1][0] * x[2][1] - x[2][0] * x[1][1],
2747 x[2][0] * x[0][1] - x[0][0] * x[2][1],
2748 x[0][0] * x[1][1] - x[1][0] * x[0][1],
2756 T r = x[0][0] * s[0][0] + x[0][1] * s[1][0] + x[0][2] * s[2][0];
2760 for (
int i = 0; i < 3; ++i)
2762 for (
int j = 0; j < 3; ++j)
2772 for (
int i = 0; i < 3; ++i)
2774 for (
int j = 0; j < 3; ++j)
2783 throw SingMatrixExc (
"Cannot invert singular matrix.");
2791 s[3][0] = -x[3][0] * s[0][0] - x[3][1] * s[1][0] - x[3][2] * s[2][0];
2792 s[3][1] = -x[3][0] * s[0][1] - x[3][1] * s[1][1] - x[3][2] * s[2][1];
2793 s[3][2] = -x[3][0] * s[0][2] - x[3][1] * s[1][2] - x[3][2] * s[2][2];
2803 S cos_rz, sin_rz, cos_ry, sin_ry, cos_rx, sin_rx;
2813 x[0][0] = cos_rz * cos_ry;
2814 x[0][1] = sin_rz * cos_ry;
2818 x[1][0] = -sin_rz * cos_rx + cos_rz * sin_ry * sin_rx;
2819 x[1][1] = cos_rz * cos_rx + sin_rz * sin_ry * sin_rx;
2820 x[1][2] = cos_ry * sin_rx;
2823 x[2][0] = sin_rz * sin_rx + cos_rz * sin_ry * cos_rx;
2824 x[2][1] = -cos_rz * sin_rx + sin_rz * sin_ry * cos_rx;
2825 x[2][2] = cos_ry * cos_rx;
2845 x[0][0] = unit[0] * unit[0] * (1 - cosine) + cosine;
2846 x[0][1] = unit[0] * unit[1] * (1 - cosine) + unit[2] * sine;
2847 x[0][2] = unit[0] * unit[2] * (1 - cosine) - unit[1] * sine;
2850 x[1][0] = unit[0] * unit[1] * (1 - cosine) - unit[2] * sine;
2851 x[1][1] = unit[1] * unit[1] * (1 - cosine) + cosine;
2852 x[1][2] = unit[1] * unit[2] * (1 - cosine) + unit[0] * sine;
2855 x[2][0] = unit[0] * unit[2] * (1 - cosine) + unit[1] * sine;
2856 x[2][1] = unit[1] * unit[2] * (1 - cosine) - unit[0] * sine;
2857 x[2][2] = unit[2] * unit[2] * (1 - cosine) + cosine;
2873 S cos_rz, sin_rz, cos_ry, sin_ry, cos_rx, sin_rx;
2886 m00 = cos_rz * cos_ry;
2887 m01 = sin_rz * cos_ry;
2889 m10 = -sin_rz * cos_rx + cos_rz * sin_ry * sin_rx;
2890 m11 = cos_rz * cos_rx + sin_rz * sin_ry * sin_rx;
2891 m12 = cos_ry * sin_rx;
2892 m20 = -sin_rz * -sin_rx + cos_rz * sin_ry * cos_rx;
2893 m21 = cos_rz * -sin_rx + sin_rz * sin_ry * cos_rx;
2894 m22 = cos_ry * cos_rx;
2898 x[0][0] = P[0][0] * m00 + P[1][0] * m01 + P[2][0] * m02;
2899 x[0][1] = P[0][1] * m00 + P[1][1] * m01 + P[2][1] * m02;
2900 x[0][2] = P[0][2] * m00 + P[1][2] * m01 + P[2][2] * m02;
2901 x[0][3] = P[0][3] * m00 + P[1][3] * m01 + P[2][3] * m02;
2903 x[1][0] = P[0][0] * m10 + P[1][0] * m11 + P[2][0] * m12;
2904 x[1][1] = P[0][1] * m10 + P[1][1] * m11 + P[2][1] * m12;
2905 x[1][2] = P[0][2] * m10 + P[1][2] * m11 + P[2][2] * m12;
2906 x[1][3] = P[0][3] * m10 + P[1][3] * m11 + P[2][3] * m12;
2908 x[2][0] = P[0][0] * m20 + P[1][0] * m21 + P[2][0] * m22;
2909 x[2][1] = P[0][1] * m20 + P[1][1] * m21 + P[2][1] * m22;
2910 x[2][2] = P[0][2] * m20 + P[1][2] * m21 + P[2][2] * m22;
2911 x[2][3] = P[0][3] * m20 + P[1][3] * m21 + P[2][3] * m22;
2920 memset (x, 0,
sizeof (x));
2934 memset (x, 0,
sizeof (x));
2998 return Vec3<T> (x[3][0], x[3][1], x[3][2]);
3006 x[3][0] += t[0] * x[0][0] + t[1] * x[1][0] + t[2] * x[2][0];
3007 x[3][1] += t[0] * x[0][1] + t[1] * x[1][1] + t[2] * x[2][1];
3008 x[3][2] += t[0] * x[0][2] + t[1] * x[1][2] + t[2] * x[2][2];
3009 x[3][3] += t[0] * x[0][3] + t[1] * x[1][3] + t[2] * x[2][3];
3081 for (
int i=0; i < 4; i++)
3083 x[2][i] += h[1] * x[0][i] + h[2] * x[1][i];
3084 x[1][i] += h[0] * x[0][i];
3097 for (
int i=0; i < 4; i++)
3099 x[0][i] = P[0][i] + h.
yx * P[1][i] + h.
zx * P[2][i];
3100 x[1][i] = h.
xy * P[0][i] + P[1][i] + h.
zy * P[2][i];
3101 x[2][i] = h.
xz * P[0][i] + h.
yz * P[1][i] + P[2][i];
3114 operator << (std::ostream &s, const Matrix33<T> &m)
3116 std::ios_base::fmtflags oldFlags = s.flags();
3119 if (s.flags() & std::ios_base::fixed)
3121 s.setf (std::ios_base::showpoint);
3122 width = s.precision() + 5;
3126 s.setf (std::ios_base::scientific);
3127 s.setf (std::ios_base::showpoint);
3128 width = s.precision() + 8;
3131 s <<
"(" << std::setw (width) << m[0][0] <<
3132 " " << std::setw (width) << m[0][1] <<
3133 " " << std::setw (width) << m[0][2] <<
"\n" <<
3135 " " << std::setw (width) << m[1][0] <<
3136 " " << std::setw (width) << m[1][1] <<
3137 " " << std::setw (width) << m[1][2] <<
"\n" <<
3139 " " << std::setw (width) << m[2][0] <<
3140 " " << std::setw (width) << m[2][1] <<
3141 " " << std::setw (width) << m[2][2] <<
")\n";
3149 operator << (std::ostream &s, const Matrix44<T> &m)
3151 std::ios_base::fmtflags oldFlags = s.flags();
3154 if (s.flags() & std::ios_base::fixed)
3156 s.setf (std::ios_base::showpoint);
3157 width = s.precision() + 5;
3161 s.setf (std::ios_base::scientific);
3162 s.setf (std::ios_base::showpoint);
3163 width = s.precision() + 8;
3166 s <<
"(" << std::setw (width) << m[0][0] <<
3167 " " << std::setw (width) << m[0][1] <<
3168 " " << std::setw (width) << m[0][2] <<
3169 " " << std::setw (width) << m[0][3] <<
"\n" <<
3171 " " << std::setw (width) << m[1][0] <<
3172 " " << std::setw (width) << m[1][1] <<
3173 " " << std::setw (width) << m[1][2] <<
3174 " " << std::setw (width) << m[1][3] <<
"\n" <<
3176 " " << std::setw (width) << m[2][0] <<
3177 " " << std::setw (width) << m[2][1] <<
3178 " " << std::setw (width) << m[2][2] <<
3179 " " << std::setw (width) << m[2][3] <<
"\n" <<
3181 " " << std::setw (width) << m[3][0] <<
3182 " " << std::setw (width) << m[3][1] <<
3183 " " << std::setw (width) << m[3][2] <<
3184 " " << std::setw (width) << m[3][3] <<
")\n";
3195 template <
class S,
class T>
3196 inline const Vec2<S> &
3199 S x = S(v.
x * m[0][0] + v.
y * m[1][0] + m[2][0]);
3200 S y = S(v.
x * m[0][1] + v.
y * m[1][1] + m[2][1]);
3201 S w = S(v.
x * m[0][2] + v.
y * m[1][2] + m[2][2]);
3209 template <
class S,
class T>
3213 S x = S(v.
x * m[0][0] + v.
y * m[1][0] + m[2][0]);
3214 S y = S(v.
x * m[0][1] + v.
y * m[1][1] + m[2][1]);
3215 S w = S(v.
x * m[0][2] + v.
y * m[1][2] + m[2][2]);
3217 return Vec2<S> (x / w, y / w);
3221 template <
class S,
class T>
3222 inline const Vec3<S> &
3225 S x = S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0]);
3226 S y = S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1]);
3227 S z = S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2]);
3236 template <
class S,
class T>
3240 S x = S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0]);
3241 S y = S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1]);
3242 S z = S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2]);
3248 template <
class S,
class T>
3249 inline const Vec3<S> &
3252 S x = S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0] + m[3][0]);
3253 S y = S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1] + m[3][1]);
3254 S z = S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2] + m[3][2]);
3255 S w = S(v.
x * m[0][3] + v.
y * m[1][3] + v.
z * m[2][3] + m[3][3]);
3264 template <
class S,
class T>
3268 S x = S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0] + m[3][0]);
3269 S y = S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1] + m[3][1]);
3270 S z = S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2] + m[3][2]);
3271 S w = S(v.
x * m[0][3] + v.
y * m[1][3] + v.
z * m[2][3] + m[3][3]);
3273 return Vec3<S> (x / w, y / w, z / w);
3277 template <
class S,
class T>
3278 inline const Vec4<S> &
3281 S x = S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0] + v.
w * m[3][0]);
3282 S y = S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1] + v.
w * m[3][1]);
3283 S z = S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2] + v.
w * m[3][2]);
3284 S w = S(v.
x * m[0][3] + v.
y * m[1][3] + v.
z * m[2][3] + v.
w * m[3][3]);
3294 template <
class S,
class T>
3298 S x = S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0] + v.
w * m[3][0]);
3299 S y = S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1] + v.
w * m[3][1]);
3300 S z = S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2] + v.
w * m[3][2]);
3301 S w = S(v.
x * m[0][3] + v.
y * m[1][3] + v.
z * m[2][3] + v.
w * m[3][3]);
const Matrix33 & invert(bool singExc=false)
Definition: ImathMatrix.h:1483
T x
Definition: ImathVec.h:76
static T baseTypeMin()
Definition: ImathMatrix.h:375
Uninitialized
Definition: ImathMatrix.h:63
Matrix44()
Definition: ImathMatrix.h:1811
Matrix33(Uninitialized)
Definition: ImathMatrix.h:84
Definition: ImathShear.h:59
const Matrix33 & shear(const S &xy)
const Vec3< T > translation() const
Definition: ImathMatrix.h:2996
const Matrix33 & operator*=(T a)
Definition: ImathMatrix.h:1210
Matrix33 operator+(const Matrix33 &v) const
Definition: ImathMatrix.h:1114
T y
Definition: ImathVec.h:76
Vec2< T > translation() const
Definition: ImathMatrix.h:1697
Definition: ImathFrame.h:42
const Matrix33 & rotate(S r)
Definition: ImathFrame.h:43
T * operator[](int i)
Definition: ImathMatrix.h:821
Matrix44 operator-() const
Definition: ImathMatrix.h:2315
const Matrix44 & scale(const Vec3< S > &s)
Matrix33 & setValue(const Matrix33< S > &v)
T xy
Definition: ImathShear.h:67
const Matrix44 & rotate(const Vec3< S > &r)
Matrix44 & setTheMatrix(const Matrix44< S > &v)
Matrix44< T > inverse(bool singExc=false) const
Definition: ImathMatrix.h:2731
Definition: ImathMatrix.h:63
const Matrix44 & setAxisAngle(const Vec3< S > &ax, S ang)
T * getValue()
Definition: ImathMatrix.h:1988
static T baseTypeMax()
Definition: ImathMatrix.h:746
bool operator!=(const Matrix44 &v) const
Definition: ImathMatrix.h:2129
const Matrix44 & operator-=(const Matrix44 &v)
Definition: ImathMatrix.h:2245
bool equalWithRelError(const Matrix44< T > &v, T e) const
Definition: ImathMatrix.h:2163
const Matrix33 & transpose()
Definition: ImathMatrix.h:1339
const Matrix33 & operator/=(T a)
Definition: ImathMatrix.h:1307
const Matrix33 & setRotation(S r)
Definition: ImathVec.h:63
const Matrix44 & translate(const Vec3< S > &t)
const Matrix44 & operator*=(T a)
Definition: ImathMatrix.h:2361
T abs(T a)
Definition: ImathFun.h:53
const Matrix44 & operator/=(T a)
Definition: ImathMatrix.h:2519
Matrix44< double > M44d
Definition: ImathMatrix.h:812
const Matrix44 & shear(const Vec3< S > &h)
Definition: ImathMatrix.h:66
T xz
Definition: ImathShear.h:67
Matrix33 & setTheMatrix(const Matrix33< S > &v)
const Matrix44 & gjInvert(bool singExc=false)
Definition: ImathMatrix.h:2611
const Matrix33 & operator+=(const Matrix33 &v)
Definition: ImathMatrix.h:1080
const Matrix33 & translate(const Vec2< S > &t)
T * getValue()
Definition: ImathMatrix.h:929
Matrix33< float > M33f
Definition: ImathMatrix.h:809
T x
Definition: ImathVec.h:274
bool equalWithAbsError(T x1, T x2, T e)
Definition: ImathMath.h:191
T y
Definition: ImathVec.h:274
Matrix33< T > gjInverse(bool singExc=false) const
Definition: ImathMatrix.h:1379
static T cos(T x)
Definition: ImathMath.h:97
Matrix33 operator-() const
Definition: ImathMatrix.h:1178
Matrix33 operator/(T a) const
Definition: ImathMatrix.h:1324
T * operator[](int i)
Definition: ImathMatrix.h:1797
bool operator==(const Matrix33 &v) const
Definition: ImathMatrix.h:1026
T z
Definition: ImathVec.h:274
void makeIdentity()
Definition: ImathMatrix.h:1016
const Matrix44 & setEulerAngles(const Vec3< S > &r)
Vec3< T > normalized() const
Definition: ImathVec.h:1730
static T baseTypeMax()
Definition: ImathMatrix.h:376
Matrix33 transposed() const
Definition: ImathMatrix.h:1356
bool equalWithRelError(T x1, T x2, T e)
Definition: ImathMath.h:199
void multDirMatrix(const Vec2< S > &src, Vec2< S > &dst) const
Definition: ImathMatrix.h:1294
Matrix44(Uninitialized)
Definition: ImathMatrix.h:414
const Matrix44 & invert(bool singExc=false)
Definition: ImathMatrix.h:2723
const Matrix33 & scale(const Vec2< S > &s)
const Matrix33 & setTranslation(const Vec2< S > &t)
Definition: ImathVec.h:61
static void multiply(const Matrix44 &a, const Matrix44 &b, Matrix44 &c)
Definition: ImathMatrix.h:2435
T zx
Definition: ImathShear.h:67
Matrix44 operator/(T a) const
Definition: ImathMatrix.h:2543
void multVecMatrix(const Vec2< S > &src, Vec2< S > &dst) const
Definition: ImathMatrix.h:1279
T x
Definition: ImathVec.h:487
Matrix44 & setValue(const Matrix44< S > &v)
bool operator==(const Matrix44 &v) const
Definition: ImathMatrix.h:2107
const Matrix33 & setScale(T s)
Definition: ImathMatrix.h:1636
static T baseTypeMin()
Definition: ImathMatrix.h:745
const Matrix44 & operator+=(const Matrix44 &v)
Definition: ImathMatrix.h:2175
Matrix33()
Definition: ImathMatrix.h:835
bool operator!=(const Matrix33 &v) const
Definition: ImathMatrix.h:1041
static T baseTypeEpsilon()
Definition: ImathMatrix.h:378
const Matrix33 & operator=(const Matrix33 &v)
Definition: ImathMatrix.h:905
T yz
Definition: ImathShear.h:67
bool equalWithRelError(const Matrix33< T > &v, T e) const
Definition: ImathMatrix.h:1068
Matrix44 operator*(T a) const
Definition: ImathMatrix.h:2385
const Matrix44 & setTranslation(const Vec3< S > &t)
Definition: ImathBox.h:67
T y
Definition: ImathVec.h:487
T zy
Definition: ImathShear.h:67
const Matrix33 & setShear(const S &h)
T z
Definition: ImathVec.h:487
bool equalWithAbsError(const Matrix33< T > &v, T e) const
Definition: ImathMatrix.h:1056
bool equalWithAbsError(const Matrix44< T > &v, T e) const
Definition: ImathMatrix.h:2151
Matrix33< double > M33d
Definition: ImathMatrix.h:810
Matrix33< T > inverse(bool singExc=false) const
Definition: ImathMatrix.h:1491
static T baseTypeSmallest()
Definition: ImathMatrix.h:747
T w
Definition: ImathVec.h:487
Color4< T > operator*(S a, const Color4< T > &v)
Definition: ImathColor.h:727
const Matrix44 & negate()
Definition: ImathMatrix.h:2337
static T sin(T x)
Definition: ImathMath.h:98
Matrix44 transposed() const
Definition: ImathMatrix.h:2589
const Matrix44 & setShear(const Vec3< S > &h)
Matrix44< T > gjInverse(bool singExc=false) const
Definition: ImathMatrix.h:2619
Matrix44< float > M44f
Definition: ImathMatrix.h:811
const Matrix44 & operator=(const Matrix44 &v)
Definition: ImathMatrix.h:1942
const Matrix33 & negate()
Definition: ImathMatrix.h:1193
const Matrix44 & transpose()
Definition: ImathMatrix.h:2565
static T baseTypeSmallest()
Definition: ImathMatrix.h:377
const Vec2< S > & operator*=(Vec2< S > &v, const Matrix33< T > &m)
Definition: ImathMatrix.h:3197
void multDirMatrix(const Vec3< S > &src, Vec3< S > &dst) const
Definition: ImathMatrix.h:2504
Matrix44 operator+(const Matrix44 &v) const
Definition: ImathMatrix.h:2223
void makeIdentity()
Definition: ImathMatrix.h:2096
static T baseTypeEpsilon()
Definition: ImathMatrix.h:748
void multVecMatrix(const Vec3< S > &src, Vec3< S > &dst) const
Definition: ImathMatrix.h:2488
T x[4][4]
Definition: ImathMatrix.h:404
const Matrix33 & gjInvert(bool singExc=false)
Definition: ImathMatrix.h:1371
const Matrix33 & operator-=(const Matrix33 &v)
Definition: ImathMatrix.h:1129
const Matrix44 & setScale(T s)
Definition: ImathMatrix.h:2918
Matrix33 operator*(T a) const
Definition: ImathMatrix.h:1227
T yx
Definition: ImathShear.h:67
T x[3][3]
Definition: ImathMatrix.h:74