39template <
typename DataType,
typename VectorType>
51template <
typename DataType>
60 {
static inline void copy(DataType *pTo,
const DataType *pFrom)
61 { pTo[0] = pFrom[0]; pTo[1] = pFrom[1]; pTo[2] = pFrom[2]; }
73 DataType e10 = 0.0f, DataType e11 = 1.0f, DataType e12 = 0.0f,
74 DataType e20 = 0.0f, DataType e21 = 0.0f, DataType e22 = 1.0f)
101 for (
int i = 0; i < 3; i++)
102 {
for (
int j = 0; j < 3; j++)
108 {
return *
this = *
this * m; }
112 for (
int i = 0; i < 3; i++)
113 {
for (
int j = 0; j < 3; j++)
119 {
return *
this = *
this ^ m; }
129 const DataType invdet = 1.0f / det;
147 std::swap(src[1], src[3]);
148 std::swap(src[2], src[6]);
149 std::swap(src[5], src[7]);
155 template <
typename VectorType>
161 m.
entry[0][0] = 1.0f /
v[0], m.
entry[1][1] = 1.0f /
v[1], m.
entry[2][2] = 1.0f /
v[2];
164 template <
typename VectorType>
169 template <
typename VectorType>
174 template <
typename VectorType>
179 template <
typename VectorType>
218 template <
typename VectorType>
221 const DataType cos_b = (DataType)cos(angles[0]), sin_b = (DataType)sin(angles[0]);
222 const DataType cos_c = (DataType)cos(angles[1]), sin_c = (DataType)sin(angles[1]);
223 const DataType cos_a = (DataType)cos(angles[2]), sin_a = (DataType)sin(angles[2]);
225 m.
entry[0][0] = cos_a * cos_c - sin_a * sin_b * sin_c;
226 m.
entry[0][1] = sin_a * cos_c + cos_a * sin_b * sin_c;
227 m.
entry[0][2] = cos_b * sin_c;
229 m.
entry[1][0] = -sin_a * cos_b;
230 m.
entry[1][1] = cos_a * cos_b;
231 m.
entry[1][2] = -sin_b;
233 m.
entry[2][0] = -cos_a * sin_c - sin_a * sin_b * cos_c;
234 m.
entry[2][1] = -sin_a * sin_c + cos_a * sin_b * cos_c;
235 m.
entry[2][2] = cos_b * cos_c;
238 template <
typename VectorType>
243 template <
typename VectorType>
245 { DataType xx, yy, zz, xy, yz, zx, xs, ys, zs;
246 const DataType
x =
v[0],
y =
v[1],
z =
v[2];
247 const DataType s = (DataType)sin(-angle), c = (DataType)cos(-angle);
248 const DataType mag = (DataType)sqrt(
x *
x +
y *
y +
z *
z);
251 x /= mag;
y /= mag;
z /= mag;
253 xx =
x *
x; yy =
y *
y; zz =
z *
z;
254 xy =
x *
y; yz =
y *
z; zx =
z *
x;
255 xs =
x * s; ys =
y * s; zs =
z * s;
257 const DataType one_c = 1.0f - c;
260 pMat[0] = (one_c * xx) + c;
261 pMat[1] = (one_c * xy) - zs;
262 pMat[2] = (one_c * zx) + ys;
264 pMat[3] = (one_c * xy) + zs;
265 pMat[4] = (one_c * yy) + c;
266 pMat[5] = (one_c * yz) - xs;
268 pMat[6] = (one_c * zx) - ys;
269 pMat[7] = (one_c * yz) + xs;
270 pMat[8] = (one_c * zz) + c;
274 template <
typename VectorType>
281 const DataType
x = fabs(
entry[0][0]) + fabs(
entry[0][1]) + fabs(
entry[0][2]);
282 const DataType
y = fabs(
entry[1][0]) + fabs(
entry[1][1]) + fabs(
entry[1][2]);
283 const DataType
z = fabs(
entry[2][0]) + fabs(
entry[2][1]) + fabs(
entry[2][2]);
291 (DataType)(fabs(
entry[2][0]) + fabs(
entry[2][1]) + fabs(
entry[2][2]))); }
293 template <
typename VectorType>
294 VectorType &
transform(VectorType &vec, DataType = 0.0f)
const
295 {
return vec.set(
entry[0][0] * vec.x +
entry[1][0] * vec.y +
entry[2][0] * vec.z,
298 template <
typename VectorType>
300 { VectorType tmp(vec);
return transform(tmp); }
301 template <
typename VectorType>
303 { VectorType vec(
v);
return m.
transform(vec); }
304 template <
typename VectorType>
306 { VectorType vec(
v);
return m.
transform(vec); }
308 template <
typename VectorType>
310 {
return vec.set(
entry[0][0] * vec.x +
entry[0][1] * vec.y +
entry[0][2] * vec.z,
313 template <
typename VectorType>
316 template <
typename VectorType>
319 template <
typename VectorType>
328template <
typename DataType>
337 {
static void copy(DataType *pTo,
const DataType *pFrom)
338 { pTo[0] = pFrom[0]; pTo[1] = pFrom[1]; pTo[2] = pFrom[2]; pTo[3] = pFrom[3]; }
390 DataType e10 = 0.0f, DataType e11 = 1.0f, DataType e12 = 0.0f, DataType e13 = 0.0f,
391 DataType e20 = 0.0f, DataType e21 = 0.0f, DataType e22 = 1.0f, DataType e23 = 0.0f,
392 DataType e30 = 0.0f, DataType e31 = 0.0f, DataType e32 = 0.0f, DataType e33 = 1.0f)
471 {
return *
this = *
this * m; }
499 const DataType det =
entry[0][0] * (
entry[1][1] * a2323 -
entry[1][2] * a1323 +
entry[1][3] * a1223)
507 const DataType invdet = 1.0f / det;
508 entry[0][0] = invdet * (src.
entry[1][1] * a2323 - src.
entry[1][2] * a1323 + src.
entry[1][3] * a1223);
509 entry[0][1] = invdet * -(src.
entry[0][1] * a2323 - src.
entry[0][2] * a1323 + src.
entry[0][3] * a1223);
510 entry[0][2] = invdet * (src.
entry[0][1] * a2313 - src.
entry[0][2] * a1313 + src.
entry[0][3] * a1213);
511 entry[0][3] = invdet * -(src.
entry[0][1] * a2312 - src.
entry[0][2] * a1312 + src.
entry[0][3] * a1212);
512 entry[1][0] = invdet * -(src.
entry[1][0] * a2323 - src.
entry[1][2] * a0323 + src.
entry[1][3] * a0223);
513 entry[1][1] = invdet * (src.
entry[0][0] * a2323 - src.
entry[0][2] * a0323 + src.
entry[0][3] * a0223);
514 entry[1][2] = invdet * -(src.
entry[0][0] * a2313 - src.
entry[0][2] * a0313 + src.
entry[0][3] * a0213);
515 entry[1][3] = invdet * (src.
entry[0][0] * a2312 - src.
entry[0][2] * a0312 + src.
entry[0][3] * a0212);
516 entry[2][0] = invdet * (src.
entry[1][0] * a1323 - src.
entry[1][1] * a0323 + src.
entry[1][3] * a0123);
517 entry[2][1] = invdet * -(src.
entry[0][0] * a1323 - src.
entry[0][1] * a0323 + src.
entry[0][3] * a0123);
518 entry[2][2] = invdet * (src.
entry[0][0] * a1313 - src.
entry[0][1] * a0313 + src.
entry[0][3] * a0113);
519 entry[2][3] = invdet * -(src.
entry[0][0] * a1312 - src.
entry[0][1] * a0312 + src.
entry[0][3] * a0112);
520 entry[3][0] = invdet * -(src.
entry[1][0] * a1223 - src.
entry[1][1] * a0223 + src.
entry[1][2] * a0123);
521 entry[3][1] = invdet * (src.
entry[0][0] * a1223 - src.
entry[0][1] * a0223 + src.
entry[0][2] * a0123);
522 entry[3][2] = invdet * -(src.
entry[0][0] * a1213 - src.
entry[0][1] * a0213 + src.
entry[0][2] * a0113);
523 entry[3][3] = invdet * (src.
entry[0][0] * a1212 - src.
entry[0][1] * a0212 + src.
entry[0][2] * a0112);
550 template <
typename VectorType>
553 pMat[12] =
v[0], pMat[13] =
v[1], pMat[14] =
v[2];
555 pMat[12] = -pMat[12], pMat[13] = -pMat[13], pMat[14] = -pMat[14];
558 template <
typename VectorType>
563 template <
typename VectorType>
568 template <
typename VectorType>
573 template <
typename VectorType>
582 template <
typename VectorType>
587 template <
typename VectorType>
592 template <
typename VectorType>
597 template <
typename VectorType>
602 template <
typename VectorType>
637 template <
typename VectorType>
642 template <
typename VectorType>
647 template <
typename VectorType>
652 template <
typename VectorType>
664 template <
typename VectorType>
665 VectorType &
transform(VectorType &vec, DataType
w = 1.0f)
const
669 template <
typename VectorType>
671 { VectorType tmp(vec);
return transform(tmp,
w); }
672 template <
typename VectorType>
674 { VectorType vec(
v);
return m.
transform(vec); }
675 template <
typename VectorType>
677 { VectorType vec(
v);
return m.
transform(vec); }
679 template <
typename VectorType>
684 template <
typename VectorType>
687 template <
typename VectorType>
690 template <
typename VectorType>
694 template <
typename VectorType,
typename VectorType2>
699 Yy.
set((DataType)up[0], (DataType)up[1], (DataType)up[2]);
710 l.
entry[3][0] = Ee * Xx; l.
entry[3][1] = Ee * Yy; l.
entry[3][2] = Ee * Zz; l.
entry[3][3] = 1.0f;
713 template <
typename VectorType,
typename VectorType2>
721 m.
entry[0][0] = 2.0f / (right - left); m.
entry[0][1] = 0.0f; m.
entry[0][2] = 0.0f; m.
entry[0][3] = (right + left) / (right - left);
722 m.
entry[1][0] = 0.0f; m.
entry[1][1] = 2.0f / (top - bottom); m.
entry[1][2] = 0.0f; m.
entry[1][3] = (top + bottom) / (top - bottom);
723 m.
entry[2][0] = 0.0f; m.
entry[2][1] = 0.0f; m.
entry[2][2] = -2.0f / (far_ - near_); m.
entry[2][3] = -(far_ + near_) / (far_ - near_);
729 return *
this *=
orthoMatrix(o, left, right, bottom, top, near_, far_); }
732 return *
this *=
orthoMatrix(o, left, right, bottom, top, -1.0f, 1.0f); }
736 if (near_ <= 0.0f || far_ <= 0.0f)
738 const DataType
x = (2.0f * near_) / (right - left);
739 const DataType
y = (2.0f * near_) / (top - bottom);
740 const DataType a = (right + left) / (right - left);
741 const DataType b = (top + bottom) / (top - bottom);
742 const DataType c = -(far_ + near_) / (far_ - near_);
743 const DataType d = -(2.0f * far_ * near_) / (far_ - near_);
744 v[0] =
x;
v[1] = 0.0f;
v[2] = 0.0f;
v[3] = 0.0f;
745 v[4] = 0.0f;
v[5] =
y;
v[6] = 0.0f;
v[7] = 0.0f;
746 v[8] = a;
v[9] = b;
v[10] = c;
v[11] = -1.0f;
747 v[12] = 0.0f;
v[13] = 0.0f;
v[14] = d;
v[15] = 0.0f;
752 return *
this *=
frustumMatrix(
f, left, right, bottom, top, near_, far_); }
756 if (fabs(near_ - far_) < 0.001f)
758 if (fabs(sin(fov / 2.0f)) < 0.001f)
760 const DataType h = cos(fov / 2.0f) / sin(fov / 2.0f);
761 const DataType
w = aspect * h;
762 const DataType Q = far_ / (far_ - near_);
OdTrVisMatrix4x4f OdTrVisMatrix
OdTrVisMatrix3x3Impl< double > OdTrVisMatrix3x3d
OdTrVisMatrix3x3f OdTrVisSubMat
OdTrVisMatrix4x4Impl< double > OdTrVisMatrix4x4d
OdArray< OdTrVisMatrix, OdMemoryAllocator< OdTrVisMatrix > > OdTrVisMatrixArray
OdTrVisMatrix4x4Impl< float > OdTrVisMatrix4x4f
OdTrVisMatrix3x3Impl< float > OdTrVisMatrix3x3f
GLfloat GLfloat GLfloat z
GLfloat GLfloat GLfloat GLfloat w
OdTrVisMatDefVecTypeAdaptor(const VectorType &vec)
DataType operator[](int nAxis) const
static void copy(DataType *pTo, const DataType *pFrom)
OdTrVisMatrix3x3Impl & operator/=(DataType n)
static OdTrVisMatrix3x3Impl & scaleMatrix(OdTrVisMatrix3x3Impl &m, DataType s, bool bInverse=false)
OdTrVisMatrix3x3Impl & set(DataType e00=1.0f, DataType e01=0.0f, DataType e02=0.0f, DataType e10=0.0f, DataType e11=1.0f, DataType e12=0.0f, DataType e20=0.0f, DataType e21=0.0f, DataType e22=1.0f)
OdTrVisMatrix3x3Impl operator~() const
OdTrVisMatrix3x3Impl & rotate(DataType angle, const VectorType &v, const DataType eps=1.e-8f)
static OdTrVisMatrix3x3Impl & localRotationMatrix(OdTrVisMatrix3x3Impl &m, const VectorType &angles)
static OdTrVisMatrix3x3Impl & scaleMatrix(OdTrVisMatrix3x3Impl &m, const VectorType &v, bool bInverse=false)
OdTrVisMatrix3x3Impl & setScale(const VectorType &v)
OdTrVisMatrix3x3Impl & operator^=(const OdTrVisMatrix3x3Impl &m)
OdTrVisMatrix3x3Impl & setRecipScale(const VectorType &v)
DataType * getArray(int nRow=0)
OdTrVisMatrix3x3Impl & set(const DataType *pVals)
OdTrVisMatrix3x3Impl & localRotate(const VectorType &angles)
OdTrVisMatrix3x3Impl operator-() const
VectorType transformClone(const VectorType &vec, DataType=0.0f) const
DataType operator()(int i, int j) const
OdTrVisMatrix3x3Impl recipScale(const VectorType &v) const
OdTrVisMatrix3x3Impl & setIdentity()
friend OdTrVisMatrix3x3Impl operator/(const OdTrVisMatrix3x3Impl &m, DataType n)
static OdTrVisMatrix3x3Impl & rotationMatrix(OdTrVisMatrix3x3Impl &m, DataType angle, const VectorType &v, const DataType eps=1.e-8f)
OdTrVisMatrix3x3Impl scale(const VectorType &v) const
OdTrVisMiniVec3d< DataType > getScale() const
OdTrVisMatrix3x3Impl & operator*=(const OdTrVisMatrix3x3Impl &m)
friend OdTrVisMatrix3x3Impl operator*(const OdTrVisMatrix3x3Impl &m, DataType n)
VectorType & transform(VectorType &vec, DataType=0.0f) const
OdTrVisMiniVec3d< DataType > row(int n) const
VectorType untransformClone(const VectorType &vec, DataType=0.0f) const
VectorType & untransform(VectorType &vec, DataType=0.0f) const
const DataType * getArray(int nRow=0) const
friend VectorType operator^(const OdTrVisMatrix3x3Impl m, const VectorType &v)
OdTrVisMiniVec3d< DataType > column(int n) const
OdTrVisMatrix3x3Impl & invert(const DataType eps=1.e-8f)
OdTrVisMatrix3x3Impl & transpose()
static void copy(DataType *pTo, const DataType *pFrom)
static OdTrVisMatrix4x4Impl & localRotationMatrix(OdTrVisMatrix4x4Impl &m, const VectorType &angles)
VectorType transformClone(const VectorType &vec, DataType w=1.0f) const
OdTrVisMiniVec3d< DataType > getRotationZAxis() const
OdTrVisMatrix4x4Impl & operator*=(const OdTrVisMatrix4x4Impl &m)
static OdTrVisMatrix4x4Impl & lookAtMatrix(OdTrVisMatrix4x4Impl &l, const VectorType &eye, const VectorType ¢er, const VectorType2 &up, DataType eps=1.e-8f)
OdTrVisMatrix4x4Impl operator-() const
OdTrVisMatrix4x4Impl & set(const OdGeMatrix3d &xMat, bool bTransposed=true)
OdTrVisMatrix4x4Impl & rotate(DataType angle, const VectorType &v, DataType eps=1.e-8f)
OdTrVisMiniVec3d< DataType > getRotationXAxis() const
OdTrVisMatrix4x4Impl & operator/=(DataType n)
OdTrVisMiniVec3d< DataType > getTranslation() const
OdTrVisMatrix4x4Impl & invert(DataType eps=1.e-8f)
const DataType * getArray(int nRow=0) const
OdTrVisMatrix4x4Impl & setRecipScale(const VectorType &v)
OdTrVisMatrix4x4Impl scale(const VectorType &v) const
static OdTrVisMatrix4x4Impl & scaleMatrix(OdTrVisMatrix4x4Impl &m, DataType s, bool bInverse=false)
OdTrVisMatrix4x4Impl & operator+=(const VectorType &v)
OdTrVisMatrix4x4Impl recipScale(const VectorType &v) const
DataType operator()(int i, int j) const
friend OdTrVisMatrix4x4Impl operator*(const OdTrVisMatrix4x4Impl &m, DataType n)
OdTrVisMatrix4x4Impl & ortho2d(DataType left, DataType right, DataType bottom, DataType top)
OdTrVisMatrix4x4Impl operator+(const VectorType &v) const
OdTrVisMatrix4x4Impl & operator-=(const VectorType &v)
OdTrVisMatrix4x4Impl & set(const DataType *pVals)
VectorType & untransform(VectorType &vec, DataType w=1.0f) const
OdTrVisMatrix4x4Impl & lookAt(const VectorType &eye, const VectorType ¢er, const VectorType2 &up, DataType eps=1.e-8f)
OdGeMatrix3d & get(OdGeMatrix3d &xMat, bool bTransposed=true) const
OdTrVisMatrix4x4Impl & localRotate(const VectorType &angles)
OdTrVisMatrix4x4Impl & perspective(DataType fov, DataType aspect, DataType near_, DataType far_)
friend VectorType operator^(const OdTrVisMatrix4x4Impl m, const VectorType &v)
OdTrVisMatrix4x4Impl & operator^=(const OdTrVisMatrix4x4Impl &m)
VectorType & transform(VectorType &vec, DataType w=1.0f) const
OdTrVisMatrix4x4Impl & set(DataType e00=1.0f, DataType e01=0.0f, DataType e02=0.0f, DataType e03=0.0f, DataType e10=0.0f, DataType e11=1.0f, DataType e12=0.0f, DataType e13=0.0f, DataType e20=0.0f, DataType e21=0.0f, DataType e22=1.0f, DataType e23=0.0f, DataType e30=0.0f, DataType e31=0.0f, DataType e32=0.0f, DataType e33=1.0f)
OdTrVisMatrix3x3Impl< DataType > & getSubMatrix(OdTrVisMatrix3x3Impl< DataType > &xMat) const
static OdTrVisMatrix4x4Impl & frustumMatrix(OdTrVisMatrix4x4Impl &m, DataType left, DataType right, DataType bottom, DataType top, DataType near_, DataType far_)
OdTrVisMatrix3x3Impl< DataType > getSubMatrix() const
static OdTrVisMatrix4x4Impl & translationMatrix(OdTrVisMatrix4x4Impl &m, const VectorType &v, bool bNegate=false)
OdTrVisMatrix4x4Impl & frustum(DataType left, DataType right, DataType bottom, DataType top, DataType near_, DataType far_)
OdTrVisMiniVec3d< DataType > getRotationYAxis() const
OdTrVisMatrix4x4Impl & set(const OdTrVisMatrix3x3Impl< DataType > &xMat, bool bExtend=false)
VectorType untransformClone(const VectorType &vec, DataType w=1.0f) const
friend OdTrVisMatrix4x4Impl operator/(const OdTrVisMatrix4x4Impl &m, DataType n)
static OdTrVisMatrix4x4Impl & rotationMatrix(OdTrVisMatrix4x4Impl &m, DataType angle, const VectorType &v, DataType eps=1.e-8f)
static OdTrVisMatrix4x4Impl & orthoMatrix(OdTrVisMatrix4x4Impl &m, DataType left, DataType right, DataType bottom, DataType top, DataType near_, DataType far_)
OdTrVisMatrix4x4Impl operator~() const
OdTrVisMatrix4x4Impl & setScale(const VectorType &v)
OdTrVisMatrix4x4Impl & perspective2a(DataType fovX, DataType fovY, DataType near_, DataType far_)
DataType * getArray(int nRow=0)
static OdTrVisMatrix4x4Impl & perspectiveMatrix(OdTrVisMatrix4x4Impl &m, DataType fov, DataType aspect, DataType near_, DataType far_)
OdTrVisMatrix4x4Impl & transpose()
OdTrVisMatrix4x4Impl & ortho(DataType left, DataType right, DataType bottom, DataType top, DataType near_, DataType far_)
static OdTrVisMatrix4x4Impl & scaleMatrix(OdTrVisMatrix4x4Impl &m, const VectorType &v, bool bInverse=false)
OdTrVisMatrix4x4Impl & setIdentity()
OdTrVisMiniVec3d & normalize(DataType eps=1.e-8f)
OdTrVisMiniVec3d & set(DataType _x, DataType _y, DataType _z)