40 #ifndef GLS_MATRIXAFFINE_H
41 #define GLS_MATRIXAFFINE_H
113 static const unsigned int SIZE = 4 * 4;
116 for(
unsigned int i = 0; i < SIZE; ++i )
118 if( fabs( this->
_data[ i ] - b.
Data()[ i ] ) > PRECISION )
171 void Scale( Type x, Type y, Type z );
184 void Scale( Type x, Type y, Type z,
const Vector& anchor );
206 _matrix[ 0 ][ 1 ] += y * _matrix[ 0 ][ 3 ];
207 _matrix[ 0 ][ 2 ] += z * _matrix[ 0 ][ 3 ];
209 _matrix[ 1 ][ 0 ] += x * _matrix[ 1 ][ 3 ];
210 _matrix[ 1 ][ 1 ] += y * _matrix[ 1 ][ 3 ];
211 _matrix[ 1 ][ 2 ] += z * _matrix[ 1 ][ 3 ];
213 _matrix[ 2 ][ 0 ] += x * _matrix[ 2 ][ 3 ];
214 _matrix[ 2 ][ 1 ] += y * _matrix[ 2 ][ 3 ];
215 _matrix[ 2 ][ 2 ] += z * _matrix[ 2 ][ 3 ];
217 _matrix[ 3 ][ 0 ] += x * _matrix[ 3 ][ 3 ];
218 _matrix[ 3 ][ 1 ] += y * _matrix[ 3 ][ 3 ];
219 _matrix[ 3 ][ 2 ] += z * _matrix[ 3 ][ 3 ];
234 using _BaseClass::operator*;
246 float( ( M( 0, 0 ) * v.x ) + ( M( 0, 1 ) * v.y ) + ( M( 0, 2 ) * v.z ) + M( 0, 3 ) ),
247 float( ( M( 1, 0 ) * v.x ) + ( M( 1, 1 ) * v.y ) + ( M( 1, 2 ) * v.z ) + M( 1, 3 ) ),
248 float( ( M( 2, 0 ) * v.x ) + ( M( 2, 1 ) * v.y ) + ( M( 2, 2 ) * v.z ) + M( 2, 3 ) ) );
254 float( ( M( 0, 0 ) * v.x ) + ( M( 0, 1 ) * v.y ) + ( M( 0, 2 ) * v.z ) + M( 0, 3 ) ),
255 float( ( M( 1, 0 ) * v.x ) + ( M( 1, 1 ) * v.y ) + ( M( 1, 2 ) * v.z ) + M( 1, 3 ) ),
256 float( ( M( 2, 0 ) * v.x ) + ( M( 2, 1 ) * v.y ) + ( M( 2, 2 ) * v.z ) + M( 2, 3 ) ),
291 const Vector xAxis =
Vector(
float( m( 0, 0 ) ),
float( m( 1, 0 ) ),
float( m( 2, 0 ) ) );
292 const Vector yAxis =
Vector(
float( m( 0, 1 ) ),
float( m( 1, 1 ) ),
float( m( 2, 1 ) ) );
293 const Vector zAxis =
Vector(
float( m( 0, 2 ) ),
float( m( 1, 2 ) ),
float( m( 2, 2 ) ) );
314 if( 0 != scale.x && 0 != scale.y && 0 != scale.z )
316 m( 0, 0 ) /= scale.x;
317 m( 1, 0 ) /= scale.x;
318 m( 2, 0 ) /= scale.x;
319 m( 0, 1 ) /= scale.y;
320 m( 1, 1 ) /= scale.y;
321 m( 2, 1 ) /= scale.y;
322 m( 0, 2 ) /= scale.z;
323 m( 1, 2 ) /= scale.z;
324 m( 2, 2 ) /= scale.z;
343 location =
Vector(
float( matrix( 0, 3 ) ),
float( matrix( 1, 3 ) ),
float( matrix( 2, 3 ) ) );
348 typedef GlsMatrixAffine<float> GlsMatrixAffineF;
349 typedef GlsMatrixAffine<double> GlsMatrixAffineD;
392 const double a(
double( angle ) *
DEG_TO_RAD );
393 const Type sina( (Type)sin( a ) );
394 const Type cosa( (Type)cos( a ) );
411 temp = _matrix[ 0 ][ 1 ];
412 _matrix[ 0 ][ 1 ] = temp * cosa - _matrix[ 0 ][ 2 ] * sina;
413 _matrix[ 0 ][ 2 ] = temp * sina + _matrix[ 0 ][ 2 ] * cosa;
414 temp = _matrix[ 1 ][ 1 ];
415 _matrix[ 1 ][ 1 ] = temp * cosa - _matrix[ 1 ][ 2 ] * sina;
416 _matrix[ 1 ][ 2 ] = temp * sina + _matrix[ 1 ][ 2 ] * cosa;
417 temp = _matrix[ 2 ][ 1 ];
418 _matrix[ 2 ][ 1 ] = temp * cosa - _matrix[ 2 ][ 2 ] * sina;
419 _matrix[ 2 ][ 2 ] = temp * sina + _matrix[ 2 ][ 2 ] * cosa;
420 temp = _matrix[ 3 ][ 1 ];
421 _matrix[ 3 ][ 1 ] = temp * cosa - _matrix[ 3 ][ 2 ] * sina;
422 _matrix[ 3 ][ 2 ] = temp * sina + _matrix[ 3 ][ 2 ] * cosa;
437 temp = _matrix[ 0 ][ 0 ];
438 _matrix[ 0 ][ 0 ] = temp * cosa + _matrix[ 0 ][ 2 ] * sina;
439 _matrix[ 0 ][ 2 ] = _matrix[ 0 ][ 2 ] * cosa - temp * sina;
440 temp = _matrix[ 1 ][ 0 ];
441 _matrix[ 1 ][ 0 ] = temp * cosa + _matrix[ 1 ][ 2 ] * sina;
442 _matrix[ 1 ][ 2 ] = _matrix[ 1 ][ 2 ] * cosa - temp * sina;
443 temp = _matrix[ 2 ][ 0 ];
444 _matrix[ 2 ][ 0 ] = temp * cosa + _matrix[ 2 ][ 2 ] * sina;
445 _matrix[ 2 ][ 2 ] = _matrix[ 2 ][ 2 ] * cosa - temp * sina;
446 temp = _matrix[ 3 ][ 0 ];
447 _matrix[ 3 ][ 0 ] = temp * cosa + _matrix[ 3 ][ 2 ] * sina;
448 _matrix[ 3 ][ 2 ] = _matrix[ 3 ][ 2 ] * cosa - temp * sina;
463 temp = _matrix[ 0 ][ 0 ];
464 _matrix[ 0 ][ 0 ] = temp * cosa - _matrix[ 0 ][ 1 ] * sina;
465 _matrix[ 0 ][ 1 ] = temp * sina + _matrix[ 0 ][ 1 ] * cosa;
466 temp = _matrix[ 1 ][ 0 ];
467 _matrix[ 1 ][ 0 ] = temp * cosa - _matrix[ 1 ][ 1 ] * sina;
468 _matrix[ 1 ][ 1 ] = temp * sina + _matrix[ 1 ][ 1 ] * cosa;
469 temp = _matrix[ 2 ][ 0 ];
470 _matrix[ 2 ][ 0 ] = temp * cosa - _matrix[ 2 ][ 1 ] * sina;
471 _matrix[ 2 ][ 1 ] = temp * sina + _matrix[ 2 ][ 1 ] * cosa;
472 temp = _matrix[ 3 ][ 0 ];
473 _matrix[ 3 ][ 0 ] = temp * cosa - _matrix[ 3 ][ 1 ] * sina;
474 _matrix[ 3 ][ 1 ] = temp * sina + _matrix[ 3 ][ 1 ] * cosa;
483 const Vector& centerOfRotation,
492 const double a(
double( angle ) *
DEG_TO_RAD );
493 const Type sina( (Type)sin( a ) );
494 const Type cosa( (Type)cos( a ) );
513 const Type T11( cosa ), T12( -sina ), T21( sina ), T22( cosa ),
515 T13( centerOfRotation.y - ( cosa * centerOfRotation.y - sina * centerOfRotation.z ) ),
516 T23( centerOfRotation.z - ( sina * centerOfRotation.y + cosa * centerOfRotation.z ) );
520 temp = _matrix[ 0 ][ 1 ];
521 _matrix[ 0 ][ 1 ] = temp * T11 + _matrix[ 0 ][ 2 ] * T12 + _matrix[ 0 ][ 3 ] * T13;
522 _matrix[ 0 ][ 2 ] = temp * T21 + _matrix[ 0 ][ 2 ] * T22 + _matrix[ 0 ][ 3 ] * T23;
523 temp = _matrix[ 1 ][ 1 ];
524 _matrix[ 1 ][ 1 ] = temp * T11 + _matrix[ 1 ][ 2 ] * T12 + _matrix[ 1 ][ 3 ] * T13;
525 _matrix[ 1 ][ 2 ] = temp * T21 + _matrix[ 1 ][ 2 ] * T22 + _matrix[ 1 ][ 3 ] * T23;
526 temp = _matrix[ 2 ][ 1 ];
527 _matrix[ 2 ][ 1 ] = temp * T11 + _matrix[ 2 ][ 2 ] * T12 + _matrix[ 2 ][ 3 ] * T13;
528 _matrix[ 2 ][ 2 ] = temp * T21 + _matrix[ 2 ][ 2 ] * T22 + _matrix[ 2 ][ 3 ] * T23;
529 temp = _matrix[ 3 ][ 1 ];
530 _matrix[ 3 ][ 1 ] = temp * T11 + _matrix[ 3 ][ 2 ] * T12 + _matrix[ 3 ][ 3 ] * T13;
531 _matrix[ 3 ][ 2 ] = temp * T21 + _matrix[ 3 ][ 2 ] * T22 + _matrix[ 3 ][ 3 ] * T23;
548 const Type T00( cosa ), T02( sina ), T20( -sina ), T22( cosa ),
549 T03( centerOfRotation.x - ( sina * centerOfRotation.z + cosa * centerOfRotation.x ) ),
551 T23( centerOfRotation.z - ( cosa * centerOfRotation.z - sina * centerOfRotation.x ) );
555 temp = _matrix[ 0 ][ 0 ];
556 _matrix[ 0 ][ 0 ] = temp * T00 + _matrix[ 0 ][ 2 ] * T02 + _matrix[ 0 ][ 3 ] * T03;
557 _matrix[ 0 ][ 2 ] = temp * T20 + _matrix[ 0 ][ 2 ] * T22 + _matrix[ 0 ][ 3 ] * T23;
558 temp = _matrix[ 1 ][ 0 ];
559 _matrix[ 1 ][ 0 ] = temp * T00 + _matrix[ 1 ][ 2 ] * T02 + _matrix[ 1 ][ 3 ] * T03;
560 _matrix[ 1 ][ 2 ] = temp * T20 + _matrix[ 1 ][ 2 ] * T22 + _matrix[ 1 ][ 3 ] * T23;
561 temp = _matrix[ 2 ][ 0 ];
562 _matrix[ 2 ][ 0 ] = temp * T00 + _matrix[ 2 ][ 2 ] * T02 + _matrix[ 2 ][ 3 ] * T03;
563 _matrix[ 2 ][ 2 ] = temp * T20 + _matrix[ 2 ][ 2 ] * T22 + _matrix[ 2 ][ 3 ] * T23;
564 temp = _matrix[ 3 ][ 0 ];
565 _matrix[ 3 ][ 0 ] = temp * T00 + _matrix[ 3 ][ 2 ] * T02 + _matrix[ 3 ][ 3 ] * T03;
566 _matrix[ 3 ][ 2 ] = temp * T20 + _matrix[ 3 ][ 2 ] * T22 + _matrix[ 3 ][ 3 ] * T23;
583 const Type T00( cosa ), T01( -sina ), T10( sina ), T11( cosa ),
584 T03( centerOfRotation.x - ( cosa * centerOfRotation.x - sina * centerOfRotation.y ) ),
585 T13( centerOfRotation.y - ( sina * centerOfRotation.x + cosa * centerOfRotation.y ) );
590 temp = _matrix[ 0 ][ 0 ];
591 _matrix[ 0 ][ 0 ] = temp * T00 + _matrix[ 0 ][ 1 ] * T01 + _matrix[ 0 ][ 3 ] * T03;
592 _matrix[ 0 ][ 1 ] = temp * T10 + _matrix[ 0 ][ 1 ] * T11 + _matrix[ 0 ][ 3 ] * T13;
593 temp = _matrix[ 1 ][ 0 ];
594 _matrix[ 1 ][ 0 ] = temp * T00 + _matrix[ 1 ][ 1 ] * T01 + _matrix[ 1 ][ 3 ] * T03;
595 _matrix[ 1 ][ 1 ] = temp * T10 + _matrix[ 1 ][ 1 ] * T11 + _matrix[ 1 ][ 3 ] * T13;
596 temp = _matrix[ 2 ][ 0 ];
597 _matrix[ 2 ][ 0 ] = temp * T00 + _matrix[ 2 ][ 1 ] * T01 + _matrix[ 2 ][ 3 ] * T03;
598 _matrix[ 2 ][ 1 ] = temp * T10 + _matrix[ 2 ][ 1 ] * T11 + _matrix[ 2 ][ 3 ] * T13;
599 temp = _matrix[ 3 ][ 0 ];
600 _matrix[ 3 ][ 0 ] = temp * T00 + _matrix[ 3 ][ 1 ] * T01 + _matrix[ 3 ][ 3 ] * T03;
601 _matrix[ 3 ][ 1 ] = temp * T10 + _matrix[ 3 ][ 1 ] * T11 + _matrix[ 3 ][ 3 ] * T13;
610 const Vector& centerOfRotation,
647 const Type xx( Type( u.x * u.x ) );
648 const Type yy( Type( u.y * u.y ) );
649 const Type zz( Type( u.z * u.z ) );
650 const Type xy( Type( u.x * u.y ) );
651 const Type xz( Type( u.x * u.z ) );
652 const Type yz( Type( u.y * u.z ) );
656 const double a(
double( angle ) *
DEG_TO_RAD );
657 const Type sina( (Type)sin( a ) );
658 const Type cosa( (Type)cos( a ) );
668 R( 0, 0 ) = xx + ( 1 - xx ) * cosa;
669 R( 1, 0 ) = xy - xy * cosa + u.z * sina;
670 R( 2, 0 ) = xz - xz * cosa - u.y * sina;
672 R( 0, 1 ) = xy - xy * cosa - u.z * sina;
673 R( 1, 1 ) = yy + ( 1 - yy ) * cosa;
674 R( 2, 1 ) = yz - yz * cosa + u.x * sina;
676 R( 0, 2 ) = xz - xz * cosa + u.y * sina;
677 R( 1, 2 ) = yz - yz * cosa - u.x * sina;
678 R( 2, 2 ) = zz + ( 1 - zz ) * cosa;
683 this->Translate( -centerOfRotation.x, -centerOfRotation.y, -centerOfRotation.z );
685 this->Translate( centerOfRotation.x, centerOfRotation.y, centerOfRotation.z );
700 _matrix[ 0 ][ 0 ] = _matrix[ 0 ][ 0 ] * x;
701 _matrix[ 0 ][ 1 ] = _matrix[ 0 ][ 1 ] * y;
702 _matrix[ 0 ][ 2 ] = _matrix[ 0 ][ 2 ] * z;
705 _matrix[ 1 ][ 0 ] = _matrix[ 1 ][ 0 ] * x;
706 _matrix[ 1 ][ 1 ] = _matrix[ 1 ][ 1 ] * y;
707 _matrix[ 1 ][ 2 ] = _matrix[ 1 ][ 2 ] * z;
710 _matrix[ 2 ][ 0 ] = _matrix[ 2 ][ 0 ] * x;
711 _matrix[ 2 ][ 1 ] = _matrix[ 2 ][ 1 ] * y;
712 _matrix[ 2 ][ 2 ] = _matrix[ 2 ][ 2 ] * z;
715 _matrix[ 3 ][ 0 ] = _matrix[ 3 ][ 0 ] * x;
716 _matrix[ 3 ][ 1 ] = _matrix[ 3 ][ 1 ] * y;
717 _matrix[ 3 ][ 2 ] = _matrix[ 3 ][ 2 ] * z;
737 const Type T03 = anchor.x * ( 1 - x );
738 const Type T13 = anchor.y * ( 1 - y );
739 const Type T23 = anchor.z * ( 1 - z );
744 _matrix[ 0 ][ 0 ] = _matrix[ 0 ][ 0 ] * T00 + _matrix[ 0 ][ 3 ] * T03;
745 _matrix[ 0 ][ 1 ] = _matrix[ 0 ][ 1 ] * T11 + _matrix[ 0 ][ 3 ] * T13;
746 _matrix[ 0 ][ 2 ] = _matrix[ 0 ][ 2 ] * T22 + _matrix[ 0 ][ 3 ] * T23;
749 _matrix[ 1 ][ 0 ] = _matrix[ 1 ][ 0 ] * T00 + _matrix[ 1 ][ 3 ] * T03;
750 _matrix[ 1 ][ 1 ] = _matrix[ 1 ][ 1 ] * T11 + _matrix[ 1 ][ 3 ] * T13;
751 _matrix[ 1 ][ 2 ] = _matrix[ 1 ][ 2 ] * T22 + _matrix[ 1 ][ 3 ] * T23;
754 _matrix[ 2 ][ 0 ] = _matrix[ 2 ][ 0 ] * T00 + _matrix[ 2 ][ 3 ] * T03;
755 _matrix[ 2 ][ 1 ] = _matrix[ 2 ][ 1 ] * T11 + _matrix[ 2 ][ 3 ] * T13;
756 _matrix[ 2 ][ 2 ] = _matrix[ 2 ][ 2 ] * T22 + _matrix[ 2 ][ 3 ] * T23;
759 _matrix[ 3 ][ 0 ] = _matrix[ 3 ][ 0 ] * T00 + _matrix[ 3 ][ 3 ] * T03;
760 _matrix[ 3 ][ 1 ] = _matrix[ 3 ][ 1 ] * T11 + _matrix[ 3 ][ 3 ] * T13;
761 _matrix[ 3 ][ 2 ] = _matrix[ 3 ][ 2 ] * T22 + _matrix[ 3 ][ 3 ] * T23;
767 #ifdef MATRIX_TYPE_FLOAT
768 typedef float GlsMatrixElementType;
770 # define GLS_glLoadMatrix_TYPE glLoadMatrixf
771 # define GLS_glMultMatrix_TYPE glMultMatrixf
773 typedef double GlsMatrixElementType;
774 typedef GlsMatrixAffineD GlsMatrixType;
775 # define GLS_glLoadMatrix_TYPE glLoadMatrixd
776 # define GLS_glMultMatrix_TYPE glMultMatrixd
RotationAxis
Definition: vertex.h:73
unsigned char R(void) const
Definition: gls_color.h:208
Definition: gls_matrix.h:61
const double DEG_TO_RAD
Definition: vertex.h:61
float MagnitudeSquared() const
Definition: vertex.h:335
unsigned char B(void) const
Definition: gls_color.h:214
void Normalize(void)
Definition: vertex.h:308
static const double PRECISION
Definition: gls_matrix.h:313
Type * _matrix[DIM]
Definition: gls_matrix.h:334
void Translate(const Vector &v)
Definition: gls_matrix_affine.h:231
GlsMatrix< Type, 4 > DecomposeRotationMatrix(const GlsMatrix< Type, 4 > &matrix, const Vector &scale)
Definition: gls_matrix_affine.h:304
void Transform(Vector &v) const
Definition: gls_matrix_affine.h:269
VertexNoColor Vector
Definition: gls_font_base.h:66
Type _data[DIM *DIM]
Definition: gls_matrix.h:322
The disti::Vertex class. A class for manipulating 3D vertices.
unsigned char G(void) const
Definition: gls_color.h:211
Type * Data()
Definition: gls_matrix.h:131
void Translate(Type x, Type y, Type z)
Definition: gls_matrix_affine.h:196
void DecomposeMatrix(const GlsMatrix< Type, 4 > &matrix, Vector &scale, Vector &location, GlsQuaternion< Type > &rotation)
Definition: gls_matrix_affine.h:338
~GlsMatrixAffine()
Definition: gls_matrix_affine.h:382
void Rotate(Type angle, RotationAxis axis)
Definition: gls_matrix_affine.h:388
Vector DecomposeScale(const GlsMatrix< Type, 4 > &m)
Definition: gls_matrix_affine.h:289
Definition: gls_quaternion.h:54
The disti::GlsQuaternion class.
float Magnitude() const
Definition: vertex.h:327
unsigned char A(void) const
Definition: gls_color.h:217
bool IsVeryClose(const GlsMatrix< Type, 4 > &b) const
Definition: gls_matrix_affine.h:111
Definition: bmpimage.h:46
void Scale(Type x, Type y, Type z)
Definition: gls_matrix_affine.h:690
Vector operator*(const Vector &v) const
Definition: gls_matrix_affine.h:242
Definition: gls_matrix_affine.h:60
GlsMatrixAffine()
Definition: gls_matrix_affine.h:359