Skip to content

Commit

Permalink
Implemented additional C++ functionality needed to pass 2x2 testing p…
Browse files Browse the repository at this point in the history
…arameters: extracting euler angles and overloaded vector multiplication.

Signed-off-by: Owen Thompson <oxt3479@rit.edu>
  • Loading branch information
oxt3479 authored and cary-ilm committed Apr 17, 2020
1 parent 7583df9 commit b70eabd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
23 changes: 23 additions & 0 deletions IlmBase/Imath/ImathMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -4190,6 +4190,29 @@ operator << (std::ostream &s, const Matrix44<T> &m)
// Implementation of vector-times-matrix multiplication operators
//---------------------------------------------------------------

template <class S, class T>
inline const Vec2<S> &
operator *= (Vec2<S> &v, const Matrix22<T> &m)
{
S x = S(v.x * m[0][0] + v.y * m[1][0]);
S y = S(v.x * m[0][1] + v.y * m[1][1]);

v.x = x;
v.y = y;

return v;
}

template <class S, class T>
inline Vec2<S>
operator * (const Vec2<S> &v, const Matrix22<T> &m)
{
S x = S(v.x * m[0][0] + v.y * m[1][0]);
S y = S(v.x * m[0][1] + v.y * m[1][1]);

return Vec2<S> (x, y);
}

template <class S, class T>
inline const Vec2<S> &
operator *= (Vec2<S> &v, const Matrix33<T> &m)
Expand Down
6 changes: 6 additions & 0 deletions IlmBase/Imath/ImathMatrixAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@

IMATH_INTERNAL_NAMESPACE_SOURCE_ENTER

EXPORT_CONST M22f identity22f ( 1, 0,
0, 1);

EXPORT_CONST M22d identity22d ( 1, 0,
0, 1);

EXPORT_CONST M33f identity33f ( 1, 0, 0,
0, 1, 0,
0, 0, 1);
Expand Down
26 changes: 26 additions & 0 deletions IlmBase/Imath/ImathMatrixAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
// Identity matrices
//------------------

IMATH_EXPORT_CONST M22f identity22f;
IMATH_EXPORT_CONST M33f identity33f;
IMATH_EXPORT_CONST M44f identity44f;
IMATH_EXPORT_CONST M22d identity22d;
IMATH_EXPORT_CONST M33d identity33d;
IMATH_EXPORT_CONST M44d identity44d;

Expand Down Expand Up @@ -324,6 +326,10 @@ template <class T> bool extractAndRemoveScalingAndShear
T &shr,
bool exc = true);

template <class T> void extractEuler
(const Matrix22<T> &mat,
T &rot);

template <class T> void extractEuler
(const Matrix33<T> &mat,
T &rot);
Expand Down Expand Up @@ -1231,6 +1237,26 @@ extractAndRemoveScalingAndShear (Matrix33<T> &mat,
return true;
}

template <class T>
void
extractEuler (const Matrix22<T> &mat, T &rot)
{
//
// Normalize the local x and y axes to remove scaling.
//

Vec2<T> i (mat[0][0], mat[0][1]);
Vec2<T> j (mat[1][0], mat[1][1]);

i.normalize();
j.normalize();

//
// Extract the angle, rot.
//

rot = - Math<T>::atan2 (j[0], i[0]);
}

template <class T>
void
Expand Down

0 comments on commit b70eabd

Please sign in to comment.