36 template<
typename T >
43 static const size_t DIM = 2;
75 Matrix22(
const T *dt,
bool srcIsRowMajor =
false );
78 Matrix22( T d0, T d1, T d2, T d3,
bool srcIsRowMajor =
false );
83 template<
typename FromT >
88 operator T*() {
return (T*)
m; }
89 operator const T*()
const {
return (
const T*)
m; }
94 template<
typename FromT >
123 T&
at(
int row,
int col );
124 const T&
at(
int row,
int col )
const;
127 void set(
const T *dt,
bool srcIsRowMajor =
false );
129 void set( T d0, T d1, T d2, T d3,
bool srcIsRowMajor =
false );
193 friend std::ostream& operator<<( std::ostream& lhs, const Matrix22<T>& rhs ) {
194 for(
int i = 0; i < 2; i++ ) {
196 for(
int j = 0; j < 2; j++ ) {
197 lhs << rhs.at( i, j ) <<
"\t";
199 lhs <<
"|" << std::endl;
207 template<
typename T >
213 template<
typename T >
216 for(
int i = 0; i < DIM_SQ; ++i ) {
221 template<
typename T >
224 set( dt, srcIsRowMajor );
227 template<
typename T >
231 d2, d3, srcIsRowMajor );
234 template<
typename T >
237 m00 = vx.
x; m01 = vy.
x;
238 m10 = vx.
y; m11 = vy.
y;
241 template<
typename T >
242 template<
typename FromT >
245 for(
int i = 0; i < DIM_SQ; ++i ) {
246 m[i] =
static_cast<T
>( src.
m[i] );
250 template<
typename T >
253 std::memcpy(
m, src.
m, MEM_LEN );
256 template<
typename T >
259 memcpy(
m, rhs.
m, MEM_LEN );
263 template<
typename T >
266 for(
int i = 0; i < DIM_SQ; ++i ) {
272 template<
typename T >
273 template<
typename FromT >
276 for(
int i = 0; i < DIM_SQ; i++ ) {
277 m[i] =
static_cast<T
>(rhs.
m[i]);
282 template<
typename T >
285 for(
int i = 0; i < DIM_SQ; ++i ) {
286 T diff = fabs(
m[i] - rhs.
m[i] );
287 if( diff >= epsilon )
293 template<
typename T >
298 mat.
m[0] =
m[0]*rhs.
m[0] +
m[2]*rhs.
m[1];
299 mat.
m[1] =
m[1]*rhs.
m[0] +
m[3]*rhs.
m[1];
301 mat.
m[2] =
m[0]*rhs.
m[2] +
m[2]*rhs.
m[3];
302 mat.
m[3] =
m[1]*rhs.
m[2] +
m[3]*rhs.
m[3];
309 template<
typename T >
312 for(
int i = 0; i < DIM_SQ; ++i ) {
318 template<
typename T >
321 for(
int i = 0; i < DIM_SQ; ++i ) {
327 template<
typename T >
330 for(
int i = 0; i < DIM_SQ; ++i ) {
336 template<
typename T >
340 for(
int i = 0; i < DIM_SQ; ++i ) {
346 template<
typename T >
349 for(
int i = 0; i < DIM_SQ; ++i ) {
355 template<
typename T >
358 for(
int i = 0; i < DIM_SQ; ++i ) {
364 template<
typename T >
369 ret.
m[0] =
m[0]*rhs.
m[0] +
m[2]*rhs.
m[1];
370 ret.
m[1] =
m[1]*rhs.
m[0] +
m[3]*rhs.
m[1];
372 ret.
m[2] =
m[0]*rhs.
m[2] +
m[2]*rhs.
m[3];
373 ret.
m[3] =
m[1]*rhs.
m[2] +
m[3]*rhs.
m[3];
378 template<
typename T >
382 for(
int i = 0; i < DIM_SQ; ++i ) {
383 ret.
m[i] =
m[i] + rhs.
m[i];
388 template<
typename T >
392 for(
int i = 0; i < DIM_SQ; ++i ) {
393 ret.
m[i] =
m[i] - rhs.
m[i];
398 template<
typename T >
402 m[0]*rhs.
x +
m[2]*rhs.
y,
403 m[1]*rhs.
x +
m[3]*rhs.
y
408 template<
typename T >
412 for(
int i = 0; i < DIM_SQ; ++i ) {
418 template<
typename T >
423 for(
int i = 0; i < DIM_SQ; ++i ) {
429 template<
typename T >
433 for(
int i = 0; i < DIM_SQ; ++i ) {
434 ret.
m[i] =
m[i] + rhs;
439 template<
typename T >
443 for(
int i = 0; i < DIM_SQ; ++i ) {
444 ret.
m[i] =
m[i] - rhs;
449 template<
typename T >
452 assert(row >= 0 && row < DIM);
453 assert(col >= 0 && col < DIM);
454 return m[col*DIM +
row];
457 template<
typename T >
460 assert(row >= 0 && row < DIM);
461 assert(col >= 0 && col < DIM);
462 return m[col*DIM +
row];
465 template<
typename T >
468 if( srcIsRowMajor ) {
469 m00 = dt[0]; m01 = dt[2];
470 m10 = dt[1]; m11 = dt[3];
473 std::memcpy(
m, dt, MEM_LEN );
477 template<
typename T >
480 if( srcIsRowMajor ) {
481 m[0] = d0;
m[2] = d1;
482 m[1] = d2;
m[3] = d3;
485 m[0] = d0;
m[2] = d2;
486 m[1] = d1;
m[3] = d3;
490 template<
typename T >
500 template<
typename T >
508 template<
typename T >
517 template<
typename T >
524 template<
typename T >
527 *c0 = getColumn( 0 );
528 *c1 = getColumn( 1 );
531 template<
typename T >
538 template<
typename T >
545 template<
typename T >
552 template<
typename T >
555 std::memset(
m, 0, MEM_LEN );
558 template<
typename T >
565 template<
typename T >
568 T det =
m[0]*
m[3] -
m[1]*
m[2];
572 template<
typename T >
578 template<
typename T >
582 ret.
m00 = m00; ret.
m01 = 0;
583 ret.
m10 = 0; ret.
m11 = m11;
587 template<
typename T >
591 ret.
m00 = m00; ret.
m01 = 0;
592 ret.
m10 = m10; ret.
m11 = m11;
596 template<
typename T >
600 ret.
m00 = m00; ret.
m01 = m01;
601 ret.
m10 = 0; ret.
m11 = m11;
605 template<
typename T >
609 t = m01; m01 = m10; m10 =
t;
612 template<
typename T >
621 template<
typename T >
626 T det =
m[0]*
m[3] -
m[1]*
m[2];
628 if( fabs( det ) > epsilon ) {
630 inv.
m[0] = m[3]*invDet;
631 inv.
m[1] = -m[1]*invDet;
632 inv.
m[2] = -m[2]*invDet;
633 inv.
m[3] = m[0]*invDet;
639 template<
typename T >
648 template<
typename T >
657 template<
typename T >
663 for(
int i = 0; i < DIM; i++ ) {
664 for(
int j = 0; j < DIM; j++ ) {
665 ret.
at( j, i ) = at( i, j );
672 template<
typename T >
676 T ac = cos( radians );
677 T as = sin( radians );
678 ret.
m00 = ac; ret.
m01 = as;
679 ret.
m10 = -as; ret.
m11 = ac;
683 template<
typename T >
692 template<
typename T >
Matrix22< T > upperTriangular() const
Definition: Matrix22.h:597
void set(const T *dt, bool srcIsRowMajor=false)
Definition: Matrix22.h:466
void setRows(const Vec2< T > &r0, const Vec2< T > &r1)
Definition: Matrix22.h:546
T m[4]
Definition: Matrix22.h:58
static Matrix22< T > one()
Definition: Matrix22.h:182
void setColumns(const Vec2< T > &c0, const Vec2< T > &c1)
Definition: Matrix22.h:532
void setColumn(int col, const Vec2< T > &v)
Definition: Matrix22.h:501
Matrix22< T > lowerTriangular() const
Definition: Matrix22.h:588
static Matrix22< T > zero()
Definition: Matrix22.h:184
void rotate(T radians)
Definition: Matrix22.h:170
T trace() const
Definition: Matrix22.h:573
T m01
Definition: Matrix22.h:64
#define EPSILON
Definition: CinderMath.h:125
Matrix22< double > Matrix22d
Definition: Matrix22.h:704
static Matrix22< T > identity()
Definition: Matrix22.h:180
T determinant() const
Definition: Matrix22.h:566
void setToNull()
Definition: Matrix22.h:553
GLuint src
Definition: GLee.h:10873
const Matrix22< T > operator*(const Matrix22< T > &rhs) const
Definition: Matrix22.h:365
Matrix22< T > & operator=(const Matrix22< T > &rhs)
Definition: Matrix22.h:257
void transpose()
Definition: Matrix22.h:606
T x
Definition: Vector.h:71
Matrix22< T > inverted(T epsilon=FLT_MIN) const
Definition: Matrix22.h:622
static const size_t DIM
Definition: Matrix22.h:43
T mcols[2][2]
Definition: Matrix22.h:67
void setToIdentity()
Definition: Matrix22.h:559
void scale(const Vec2< T > &v)
Definition: Matrix22.h:174
T m10
Definition: Matrix22.h:63
GLenum GLenum GLvoid * row
Definition: GLee.h:1089
bool operator!=(const Matrix22< T > &rhs) const
Definition: Matrix22.h:99
void scale(T s)
Definition: Matrix22.h:173
bool equalCompare(const Matrix22< T > &rhs, T epsilon) const
Definition: Matrix22.h:283
Vec2< T > getColumn(int col) const
Definition: Matrix22.h:491
void invert(T epsilon=FLT_MIN)
Definition: Matrix22.h:157
void getRows(Vec2< T > *r0, Vec2< T > *r1) const
Definition: Matrix22.h:539
Matrix22< T > invertTransform() const
Definition: Matrix22.h:658
Vec2< T > transformVec(const Vec2< T > &v) const
Definition: Matrix22.h:167
static const size_t DIM_SQ
Definition: Matrix22.h:44
bool operator==(const Matrix22< T > &rhs) const
Definition: Matrix22.h:98
Vec2< T > postMultiply(const Vec2< T > &v) const
Definition: Matrix22.h:649
T value_type
Definition: Matrix22.h:41
Matrix22< T > & operator*=(const Matrix22< T > &rhs)
Definition: Matrix22.h:294
T & at(int row, int col)
Definition: Matrix22.h:450
const GLdouble * v
Definition: GLee.h:1384
static const size_t MEM_LEN
Definition: Matrix22.h:45
T y
Definition: Vector.h:71
Matrix22< T > & operator/=(T s)
Definition: Matrix22.h:337
const Matrix22< T > operator/(T rhs) const
Definition: Matrix22.h:419
T m00
Definition: Matrix22.h:63
Matrix22< T > & operator+=(const Matrix22< T > &rhs)
Definition: Matrix22.h:310
Definition: Matrix22.h:37
void setRow(int row, const Vec2< T > &v)
Definition: Matrix22.h:518
void getColumns(Vec2< T > *c0, Vec2< T > *c1) const
Definition: Matrix22.h:525
Matrix22< T > & operator-=(const Matrix22< T > &rhs)
Definition: Matrix22.h:319
Matrix22()
Definition: Matrix22.h:208
T m11
Definition: Matrix22.h:64
Vec2< T > preMultiply(const Vec2< T > &v) const
Definition: Matrix22.h:640
const Matrix22< T > operator-(const Matrix22< T > &rhs) const
Definition: Matrix22.h:389
const GLfloat * m
Definition: GLee.h:13493
Matrix22< float > Matrix22f
Definition: Matrix22.h:703
Matrix22< T > diagonal() const
Definition: Matrix22.h:579
static Matrix22< T > createScale(T s)
Definition: Matrix22.h:684
GLdouble GLdouble t
Definition: GLee.h:1426
static Matrix22< T > createRotation(T radians)
Definition: Matrix22.h:673
GLdouble s
Definition: GLee.h:1378
T TYPE
Definition: Matrix22.h:40
const Matrix22< T > operator+(const Matrix22< T > &rhs) const
Definition: Matrix22.h:379
Matrix22< T > transposed() const
Definition: Matrix22.h:613
Vec2< T > getRow(int row) const
Definition: Matrix22.h:509