40 #ifndef GLS_MATRIXAFFINE_H
41 #define GLS_MATRIXAFFINE_H
64 DISTI_DEPRECATED(
"This identifier is forbidden by the C++ standard. Use BaseClass instead." )
115 static const unsigned int SIZE = 4 * 4;
118 for(
unsigned int i = 0; i < SIZE; ++i )
120 if( fabs( this->
_data[ i ] - b.
Data()[ i ] ) > PRECISION )
173 void Scale( Type x, Type y, Type z );
186 void Scale( Type x, Type y, Type z,
const Vector& anchor );
208 _matrix[ 0 ][ 1 ] += y * _matrix[ 0 ][ 3 ];
209 _matrix[ 0 ][ 2 ] += z * _matrix[ 0 ][ 3 ];
211 _matrix[ 1 ][ 0 ] += x * _matrix[ 1 ][ 3 ];
212 _matrix[ 1 ][ 1 ] += y * _matrix[ 1 ][ 3 ];
213 _matrix[ 1 ][ 2 ] += z * _matrix[ 1 ][ 3 ];
215 _matrix[ 2 ][ 0 ] += x * _matrix[ 2 ][ 3 ];
216 _matrix[ 2 ][ 1 ] += y * _matrix[ 2 ][ 3 ];
217 _matrix[ 2 ][ 2 ] += z * _matrix[ 2 ][ 3 ];
219 _matrix[ 3 ][ 0 ] += x * _matrix[ 3 ][ 3 ];
220 _matrix[ 3 ][ 1 ] += y * _matrix[ 3 ][ 3 ];
221 _matrix[ 3 ][ 2 ] += z * _matrix[ 3 ][ 3 ];
236 using BaseClass::operator*;
248 float( ( M( 0, 0 ) * v.x ) + ( M( 0, 1 ) * v.y ) + ( M( 0, 2 ) * v.z ) + M( 0, 3 ) ),
249 float( ( M( 1, 0 ) * v.x ) + ( M( 1, 1 ) * v.y ) + ( M( 1, 2 ) * v.z ) + M( 1, 3 ) ),
250 float( ( M( 2, 0 ) * v.x ) + ( M( 2, 1 ) * v.y ) + ( M( 2, 2 ) * v.z ) + M( 2, 3 ) ) );
256 float( ( M( 0, 0 ) * v.x ) + ( M( 0, 1 ) * v.y ) + ( M( 0, 2 ) * v.z ) + M( 0, 3 ) ),
257 float( ( M( 1, 0 ) * v.x ) + ( M( 1, 1 ) * v.y ) + ( M( 1, 2 ) * v.z ) + M( 1, 3 ) ),
258 float( ( M( 2, 0 ) * v.x ) + ( M( 2, 1 ) * v.y ) + ( M( 2, 2 ) * v.z ) + M( 2, 3 ) ),
293 const Vector xAxis =
Vector(
float( m( 0, 0 ) ),
float( m( 1, 0 ) ),
float( m( 2, 0 ) ) );
294 const Vector yAxis =
Vector(
float( m( 0, 1 ) ),
float( m( 1, 1 ) ),
float( m( 2, 1 ) ) );
295 const Vector zAxis =
Vector(
float( m( 0, 2 ) ),
float( m( 1, 2 ) ),
float( m( 2, 2 ) ) );
316 if( 0 != scale.x && 0 != scale.y && 0 != scale.z )
318 m( 0, 0 ) /= scale.x;
319 m( 1, 0 ) /= scale.x;
320 m( 2, 0 ) /= scale.x;
321 m( 0, 1 ) /= scale.y;
322 m( 1, 1 ) /= scale.y;
323 m( 2, 1 ) /= scale.y;
324 m( 0, 2 ) /= scale.z;
325 m( 1, 2 ) /= scale.z;
326 m( 2, 2 ) /= scale.z;
345 location =
Vector(
float( matrix( 0, 3 ) ),
float( matrix( 1, 3 ) ),
float( matrix( 2, 3 ) ) );
350 typedef GlsMatrixAffine<float> GlsMatrixAffineF;
351 typedef GlsMatrixAffine<double> GlsMatrixAffineD;
394 const double a(
double( angle ) *
DEG_TO_RAD );
395 const Type sina( (Type)sin( a ) );
396 const Type cosa( (Type)cos( a ) );
413 temp = _matrix[ 0 ][ 1 ];
414 _matrix[ 0 ][ 1 ] = temp * cosa - _matrix[ 0 ][ 2 ] * sina;
415 _matrix[ 0 ][ 2 ] = temp * sina + _matrix[ 0 ][ 2 ] * cosa;
416 temp = _matrix[ 1 ][ 1 ];
417 _matrix[ 1 ][ 1 ] = temp * cosa - _matrix[ 1 ][ 2 ] * sina;
418 _matrix[ 1 ][ 2 ] = temp * sina + _matrix[ 1 ][ 2 ] * cosa;
419 temp = _matrix[ 2 ][ 1 ];
420 _matrix[ 2 ][ 1 ] = temp * cosa - _matrix[ 2 ][ 2 ] * sina;
421 _matrix[ 2 ][ 2 ] = temp * sina + _matrix[ 2 ][ 2 ] * cosa;
422 temp = _matrix[ 3 ][ 1 ];
423 _matrix[ 3 ][ 1 ] = temp * cosa - _matrix[ 3 ][ 2 ] * sina;
424 _matrix[ 3 ][ 2 ] = temp * sina + _matrix[ 3 ][ 2 ] * cosa;
439 temp = _matrix[ 0 ][ 0 ];
440 _matrix[ 0 ][ 0 ] = temp * cosa + _matrix[ 0 ][ 2 ] * sina;
441 _matrix[ 0 ][ 2 ] = _matrix[ 0 ][ 2 ] * cosa - temp * sina;
442 temp = _matrix[ 1 ][ 0 ];
443 _matrix[ 1 ][ 0 ] = temp * cosa + _matrix[ 1 ][ 2 ] * sina;
444 _matrix[ 1 ][ 2 ] = _matrix[ 1 ][ 2 ] * cosa - temp * sina;
445 temp = _matrix[ 2 ][ 0 ];
446 _matrix[ 2 ][ 0 ] = temp * cosa + _matrix[ 2 ][ 2 ] * sina;
447 _matrix[ 2 ][ 2 ] = _matrix[ 2 ][ 2 ] * cosa - temp * sina;
448 temp = _matrix[ 3 ][ 0 ];
449 _matrix[ 3 ][ 0 ] = temp * cosa + _matrix[ 3 ][ 2 ] * sina;
450 _matrix[ 3 ][ 2 ] = _matrix[ 3 ][ 2 ] * cosa - temp * sina;
465 temp = _matrix[ 0 ][ 0 ];
466 _matrix[ 0 ][ 0 ] = temp * cosa - _matrix[ 0 ][ 1 ] * sina;
467 _matrix[ 0 ][ 1 ] = temp * sina + _matrix[ 0 ][ 1 ] * cosa;
468 temp = _matrix[ 1 ][ 0 ];
469 _matrix[ 1 ][ 0 ] = temp * cosa - _matrix[ 1 ][ 1 ] * sina;
470 _matrix[ 1 ][ 1 ] = temp * sina + _matrix[ 1 ][ 1 ] * cosa;
471 temp = _matrix[ 2 ][ 0 ];
472 _matrix[ 2 ][ 0 ] = temp * cosa - _matrix[ 2 ][ 1 ] * sina;
473 _matrix[ 2 ][ 1 ] = temp * sina + _matrix[ 2 ][ 1 ] * cosa;
474 temp = _matrix[ 3 ][ 0 ];
475 _matrix[ 3 ][ 0 ] = temp * cosa - _matrix[ 3 ][ 1 ] * sina;
476 _matrix[ 3 ][ 1 ] = temp * sina + _matrix[ 3 ][ 1 ] * cosa;
485 const Vector& centerOfRotation,
494 const double a(
double( angle ) *
DEG_TO_RAD );
495 const Type sina( (Type)sin( a ) );
496 const Type cosa( (Type)cos( a ) );
515 const Type T11( cosa ), T12( -sina ), T21( sina ), T22( cosa ),
517 T13( centerOfRotation.y - ( cosa * centerOfRotation.y - sina * centerOfRotation.z ) ),
518 T23( centerOfRotation.z - ( sina * centerOfRotation.y + cosa * centerOfRotation.z ) );
522 temp = _matrix[ 0 ][ 1 ];
523 _matrix[ 0 ][ 1 ] = temp * T11 + _matrix[ 0 ][ 2 ] * T12 + _matrix[ 0 ][ 3 ] * T13;
524 _matrix[ 0 ][ 2 ] = temp * T21 + _matrix[ 0 ][ 2 ] * T22 + _matrix[ 0 ][ 3 ] * T23;
525 temp = _matrix[ 1 ][ 1 ];
526 _matrix[ 1 ][ 1 ] = temp * T11 + _matrix[ 1 ][ 2 ] * T12 + _matrix[ 1 ][ 3 ] * T13;
527 _matrix[ 1 ][ 2 ] = temp * T21 + _matrix[ 1 ][ 2 ] * T22 + _matrix[ 1 ][ 3 ] * T23;
528 temp = _matrix[ 2 ][ 1 ];
529 _matrix[ 2 ][ 1 ] = temp * T11 + _matrix[ 2 ][ 2 ] * T12 + _matrix[ 2 ][ 3 ] * T13;
530 _matrix[ 2 ][ 2 ] = temp * T21 + _matrix[ 2 ][ 2 ] * T22 + _matrix[ 2 ][ 3 ] * T23;
531 temp = _matrix[ 3 ][ 1 ];
532 _matrix[ 3 ][ 1 ] = temp * T11 + _matrix[ 3 ][ 2 ] * T12 + _matrix[ 3 ][ 3 ] * T13;
533 _matrix[ 3 ][ 2 ] = temp * T21 + _matrix[ 3 ][ 2 ] * T22 + _matrix[ 3 ][ 3 ] * T23;
550 const Type T00( cosa ), T02( sina ), T20( -sina ), T22( cosa ),
551 T03( centerOfRotation.x - ( sina * centerOfRotation.z + cosa * centerOfRotation.x ) ),
553 T23( centerOfRotation.z - ( cosa * centerOfRotation.z - sina * centerOfRotation.x ) );
557 temp = _matrix[ 0 ][ 0 ];
558 _matrix[ 0 ][ 0 ] = temp * T00 + _matrix[ 0 ][ 2 ] * T02 + _matrix[ 0 ][ 3 ] * T03;
559 _matrix[ 0 ][ 2 ] = temp * T20 + _matrix[ 0 ][ 2 ] * T22 + _matrix[ 0 ][ 3 ] * T23;
560 temp = _matrix[ 1 ][ 0 ];
561 _matrix[ 1 ][ 0 ] = temp * T00 + _matrix[ 1 ][ 2 ] * T02 + _matrix[ 1 ][ 3 ] * T03;
562 _matrix[ 1 ][ 2 ] = temp * T20 + _matrix[ 1 ][ 2 ] * T22 + _matrix[ 1 ][ 3 ] * T23;
563 temp = _matrix[ 2 ][ 0 ];
564 _matrix[ 2 ][ 0 ] = temp * T00 + _matrix[ 2 ][ 2 ] * T02 + _matrix[ 2 ][ 3 ] * T03;
565 _matrix[ 2 ][ 2 ] = temp * T20 + _matrix[ 2 ][ 2 ] * T22 + _matrix[ 2 ][ 3 ] * T23;
566 temp = _matrix[ 3 ][ 0 ];
567 _matrix[ 3 ][ 0 ] = temp * T00 + _matrix[ 3 ][ 2 ] * T02 + _matrix[ 3 ][ 3 ] * T03;
568 _matrix[ 3 ][ 2 ] = temp * T20 + _matrix[ 3 ][ 2 ] * T22 + _matrix[ 3 ][ 3 ] * T23;
585 const Type T00( cosa ), T01( -sina ), T10( sina ), T11( cosa ),
586 T03( centerOfRotation.x - ( cosa * centerOfRotation.x - sina * centerOfRotation.y ) ),
587 T13( centerOfRotation.y - ( sina * centerOfRotation.x + cosa * centerOfRotation.y ) );
592 temp = _matrix[ 0 ][ 0 ];
593 _matrix[ 0 ][ 0 ] = temp * T00 + _matrix[ 0 ][ 1 ] * T01 + _matrix[ 0 ][ 3 ] * T03;
594 _matrix[ 0 ][ 1 ] = temp * T10 + _matrix[ 0 ][ 1 ] * T11 + _matrix[ 0 ][ 3 ] * T13;
595 temp = _matrix[ 1 ][ 0 ];
596 _matrix[ 1 ][ 0 ] = temp * T00 + _matrix[ 1 ][ 1 ] * T01 + _matrix[ 1 ][ 3 ] * T03;
597 _matrix[ 1 ][ 1 ] = temp * T10 + _matrix[ 1 ][ 1 ] * T11 + _matrix[ 1 ][ 3 ] * T13;
598 temp = _matrix[ 2 ][ 0 ];
599 _matrix[ 2 ][ 0 ] = temp * T00 + _matrix[ 2 ][ 1 ] * T01 + _matrix[ 2 ][ 3 ] * T03;
600 _matrix[ 2 ][ 1 ] = temp * T10 + _matrix[ 2 ][ 1 ] * T11 + _matrix[ 2 ][ 3 ] * T13;
601 temp = _matrix[ 3 ][ 0 ];
602 _matrix[ 3 ][ 0 ] = temp * T00 + _matrix[ 3 ][ 1 ] * T01 + _matrix[ 3 ][ 3 ] * T03;
603 _matrix[ 3 ][ 1 ] = temp * T10 + _matrix[ 3 ][ 1 ] * T11 + _matrix[ 3 ][ 3 ] * T13;
612 const Vector& centerOfRotation,
649 const Type xx( Type( u.x * u.x ) );
650 const Type yy( Type( u.y * u.y ) );
651 const Type zz( Type( u.z * u.z ) );
652 const Type xy( Type( u.x * u.y ) );
653 const Type xz( Type( u.x * u.z ) );
654 const Type yz( Type( u.y * u.z ) );
658 const double a(
double( angle ) *
DEG_TO_RAD );
659 const Type sina( (Type)sin( a ) );
660 const Type cosa( (Type)cos( a ) );
670 R( 0, 0 ) = xx + ( 1 - xx ) * cosa;
671 R( 1, 0 ) = xy - xy * cosa + u.z * sina;
672 R( 2, 0 ) = xz - xz * cosa - u.y * sina;
674 R( 0, 1 ) = xy - xy * cosa - u.z * sina;
675 R( 1, 1 ) = yy + ( 1 - yy ) * cosa;
676 R( 2, 1 ) = yz - yz * cosa + u.x * sina;
678 R( 0, 2 ) = xz - xz * cosa + u.y * sina;
679 R( 1, 2 ) = yz - yz * cosa - u.x * sina;
680 R( 2, 2 ) = zz + ( 1 - zz ) * cosa;
685 this->Translate( -centerOfRotation.x, -centerOfRotation.y, -centerOfRotation.z );
687 this->Translate( centerOfRotation.x, centerOfRotation.y, centerOfRotation.z );
702 _matrix[ 0 ][ 0 ] = _matrix[ 0 ][ 0 ] * x;
703 _matrix[ 0 ][ 1 ] = _matrix[ 0 ][ 1 ] * y;
704 _matrix[ 0 ][ 2 ] = _matrix[ 0 ][ 2 ] * z;
707 _matrix[ 1 ][ 0 ] = _matrix[ 1 ][ 0 ] * x;
708 _matrix[ 1 ][ 1 ] = _matrix[ 1 ][ 1 ] * y;
709 _matrix[ 1 ][ 2 ] = _matrix[ 1 ][ 2 ] * z;
712 _matrix[ 2 ][ 0 ] = _matrix[ 2 ][ 0 ] * x;
713 _matrix[ 2 ][ 1 ] = _matrix[ 2 ][ 1 ] * y;
714 _matrix[ 2 ][ 2 ] = _matrix[ 2 ][ 2 ] * z;
717 _matrix[ 3 ][ 0 ] = _matrix[ 3 ][ 0 ] * x;
718 _matrix[ 3 ][ 1 ] = _matrix[ 3 ][ 1 ] * y;
719 _matrix[ 3 ][ 2 ] = _matrix[ 3 ][ 2 ] * z;
739 const Type T03 = anchor.x * ( 1 - x );
740 const Type T13 = anchor.y * ( 1 - y );
741 const Type T23 = anchor.z * ( 1 - z );
746 _matrix[ 0 ][ 0 ] = _matrix[ 0 ][ 0 ] * T00 + _matrix[ 0 ][ 3 ] * T03;
747 _matrix[ 0 ][ 1 ] = _matrix[ 0 ][ 1 ] * T11 + _matrix[ 0 ][ 3 ] * T13;
748 _matrix[ 0 ][ 2 ] = _matrix[ 0 ][ 2 ] * T22 + _matrix[ 0 ][ 3 ] * T23;
751 _matrix[ 1 ][ 0 ] = _matrix[ 1 ][ 0 ] * T00 + _matrix[ 1 ][ 3 ] * T03;
752 _matrix[ 1 ][ 1 ] = _matrix[ 1 ][ 1 ] * T11 + _matrix[ 1 ][ 3 ] * T13;
753 _matrix[ 1 ][ 2 ] = _matrix[ 1 ][ 2 ] * T22 + _matrix[ 1 ][ 3 ] * T23;
756 _matrix[ 2 ][ 0 ] = _matrix[ 2 ][ 0 ] * T00 + _matrix[ 2 ][ 3 ] * T03;
757 _matrix[ 2 ][ 1 ] = _matrix[ 2 ][ 1 ] * T11 + _matrix[ 2 ][ 3 ] * T13;
758 _matrix[ 2 ][ 2 ] = _matrix[ 2 ][ 2 ] * T22 + _matrix[ 2 ][ 3 ] * T23;
761 _matrix[ 3 ][ 0 ] = _matrix[ 3 ][ 0 ] * T00 + _matrix[ 3 ][ 3 ] * T03;
762 _matrix[ 3 ][ 1 ] = _matrix[ 3 ][ 1 ] * T11 + _matrix[ 3 ][ 3 ] * T13;
763 _matrix[ 3 ][ 2 ] = _matrix[ 3 ][ 2 ] * T22 + _matrix[ 3 ][ 3 ] * T23;
769 #ifdef MATRIX_TYPE_FLOAT
770 typedef float GlsMatrixElementType;
772 # define GLS_glLoadMatrix_TYPE glLoadMatrixf
773 # define GLS_glMultMatrix_TYPE glMultMatrixf
775 typedef double GlsMatrixElementType;
776 typedef GlsMatrixAffineD GlsMatrixType;
777 # define GLS_glLoadMatrix_TYPE glLoadMatrixd
778 # define GLS_glMultMatrix_TYPE glMultMatrixd
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
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:233
GlsMatrix< Type, 4 > DecomposeRotationMatrix(const GlsMatrix< Type, 4 > &matrix, const Vector &scale)
Definition: gls_matrix_affine.h:306
void Transform(Vector &v) const
Definition: gls_matrix_affine.h:271
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:198
void DecomposeMatrix(const GlsMatrix< Type, 4 > &matrix, Vector &scale, Vector &location, GlsQuaternion< Type > &rotation)
Definition: gls_matrix_affine.h:340
~GlsMatrixAffine()
Definition: gls_matrix_affine.h:384
void Rotate(Type angle, RotationAxis axis)
Definition: gls_matrix_affine.h:390
Vector DecomposeScale(const GlsMatrix< Type, 4 > &m)
Definition: gls_matrix_affine.h:291
Definition: gls_quaternion.h:56
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:113
Definition: bmpimage.h:46
void Scale(Type x, Type y, Type z)
Definition: gls_matrix_affine.h:692
Vector operator*(const Vector &v) const
Definition: gls_matrix_affine.h:244
Definition: gls_matrix_affine.h:60
GlsMatrixAffine()
Definition: gls_matrix_affine.h:361