40 #ifndef GLS_MATRIXAFFINE_H
41 #define GLS_MATRIXAFFINE_H
114 static const unsigned int SIZE = 4*4;
117 for (
unsigned int i = 0; i < SIZE; ++i)
119 if (fabs(this->
_data[i] - b.
Data()[i]) > PRECISION)
172 void Scale(Type x, Type y, Type z);
185 void Scale(Type x, Type y, Type z,
const Vector& anchor);
207 _matrix[0][1] += y * _matrix[0][3];
208 _matrix[0][2] += z * _matrix[0][3];
210 _matrix[1][0] += x * _matrix[1][3];
211 _matrix[1][1] += y * _matrix[1][3];
212 _matrix[1][2] += z * _matrix[1][3];
214 _matrix[2][0] += x * _matrix[2][3];
215 _matrix[2][1] += y * _matrix[2][3];
216 _matrix[2][2] += z * _matrix[2][3];
218 _matrix[3][0] += x * _matrix[3][3];
219 _matrix[3][1] += y * _matrix[3][3];
220 _matrix[3][2] += z * _matrix[3][3];
235 using _BaseClass::operator*;
247 float( (M(0,0) * v.x) + (M(0,1) * v.y) + (M(0,2) * v.z) + M(0,3) ),
248 float( (M(1,0) * v.x) + (M(1,1) * v.y) + (M(1,2) * v.z) + M(1,3) ),
249 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) ),
290 template <
class Type>
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) ) );
305 template <
class Type>
316 if( 0 != scale.x && 0 != scale.y && 0 != scale.z )
339 template <
class Type>
345 location =
Vector(
float( matrix(0,3) ),
float( matrix(1,3) ),
float( matrix(2,3) ) );
351 typedef GlsMatrixAffine<float> GlsMatrixAffineF;
352 typedef GlsMatrixAffine<double> GlsMatrixAffineD;
395 const double a (
double(angle) * DEG_TO_RAD);
396 const Type sina( (Type) sin(a) );
397 const Type cosa( (Type) cos(a) );
414 temp = _matrix[0][1];
415 _matrix[0][1] = temp * cosa - _matrix[0][2] * sina;
416 _matrix[0][2] = temp * sina + _matrix[0][2] * cosa;
417 temp = _matrix[1][1];
418 _matrix[1][1] = temp * cosa - _matrix[1][2] * sina;
419 _matrix[1][2] = temp * sina + _matrix[1][2] * cosa;
420 temp = _matrix[2][1];
421 _matrix[2][1] = temp * cosa - _matrix[2][2] * sina;
422 _matrix[2][2] = temp * sina + _matrix[2][2] * cosa;
423 temp = _matrix[3][1];
424 _matrix[3][1] = temp * cosa - _matrix[3][2] * sina;
425 _matrix[3][2] = temp * sina + _matrix[3][2] * cosa;
440 temp = _matrix[0][0];
441 _matrix[0][0] = temp * cosa + _matrix[0][2] * sina;
442 _matrix[0][2] = _matrix[0][2] * cosa - temp * sina;
443 temp = _matrix[1][0];
444 _matrix[1][0] = temp * cosa + _matrix[1][2] * sina;
445 _matrix[1][2] = _matrix[1][2] * cosa - temp * sina;
446 temp = _matrix[2][0];
447 _matrix[2][0] = temp * cosa + _matrix[2][2] * sina;
448 _matrix[2][2] = _matrix[2][2] * cosa - temp * sina;
449 temp = _matrix[3][0];
450 _matrix[3][0] = temp * cosa + _matrix[3][2] * sina;
451 _matrix[3][2] = _matrix[3][2] * cosa - temp * sina;
466 temp = _matrix[0][0];
467 _matrix[0][0] = temp * cosa - _matrix[0][1] * sina;
468 _matrix[0][1] = temp * sina + _matrix[0][1] * cosa;
469 temp = _matrix[1][0];
470 _matrix[1][0] = temp * cosa - _matrix[1][1] * sina;
471 _matrix[1][1] = temp * sina + _matrix[1][1] * cosa;
472 temp = _matrix[2][0];
473 _matrix[2][0] = temp * cosa - _matrix[2][1] * sina;
474 _matrix[2][1] = temp * sina + _matrix[2][1] * cosa;
475 temp = _matrix[3][0];
476 _matrix[3][0] = temp * cosa - _matrix[3][1] * sina;
477 _matrix[3][1] = temp * sina + _matrix[3][1] * cosa;
486 const Vector& centerOfRotation,
495 const double a (
double(angle) * DEG_TO_RAD);
496 const Type sina( (Type) sin(a) );
497 const Type cosa( (Type) cos(a) );
516 const Type T11(cosa), T12(-sina), T21(sina), T22(cosa),
518 T13( centerOfRotation.y-(cosa*centerOfRotation.y-sina*centerOfRotation.z) ),
519 T23( centerOfRotation.z-(sina*centerOfRotation.y+cosa*centerOfRotation.z) );
523 temp = _matrix[0][1];
524 _matrix[0][1] = temp * T11 + _matrix[0][2] * T12 + _matrix[0][3] * T13;
525 _matrix[0][2] = temp * T21 + _matrix[0][2] * T22 + _matrix[0][3] * T23;
526 temp = _matrix[1][1];
527 _matrix[1][1] = temp * T11 + _matrix[1][2] * T12 + _matrix[1][3] * T13;
528 _matrix[1][2] = temp * T21 + _matrix[1][2] * T22 + _matrix[1][3] * T23;
529 temp = _matrix[2][1];
530 _matrix[2][1] = temp * T11 + _matrix[2][2] * T12 + _matrix[2][3] * T13;
531 _matrix[2][2] = temp * T21 + _matrix[2][2] * T22 + _matrix[2][3] * T23;
532 temp = _matrix[3][1];
533 _matrix[3][1] = temp * T11 + _matrix[3][2] * T12 + _matrix[3][3] * T13;
534 _matrix[3][2] = temp * T21 + _matrix[3][2] * T22 + _matrix[3][3] * T23;
551 const Type T00(cosa), T02(sina), T20(-sina), T22(cosa),
552 T03( centerOfRotation.x-(sina*centerOfRotation.z+cosa*centerOfRotation.x) ),
554 T23( centerOfRotation.z-(cosa*centerOfRotation.z-sina*centerOfRotation.x) );
558 temp = _matrix[0][0];
559 _matrix[0][0] = temp * T00 + _matrix[0][2] * T02 + _matrix[0][3] * T03;
560 _matrix[0][2] = temp * T20 + _matrix[0][2] * T22 + _matrix[0][3] * T23;
561 temp = _matrix[1][0];
562 _matrix[1][0] = temp * T00 + _matrix[1][2] * T02 + _matrix[1][3] * T03;
563 _matrix[1][2] = temp * T20 + _matrix[1][2] * T22 + _matrix[1][3] * T23;
564 temp = _matrix[2][0];
565 _matrix[2][0] = temp * T00 + _matrix[2][2] * T02 + _matrix[2][3] * T03;
566 _matrix[2][2] = temp * T20 + _matrix[2][2] * T22 + _matrix[2][3] * T23;
567 temp = _matrix[3][0];
568 _matrix[3][0] = temp * T00 + _matrix[3][2] * T02 + _matrix[3][3] * T03;
569 _matrix[3][2] = temp * T20 + _matrix[3][2] * T22 + _matrix[3][3] * T23;
586 const Type T00(cosa), T01(-sina), T10(sina), T11(cosa),
587 T03( centerOfRotation.x-(cosa*centerOfRotation.x-sina*centerOfRotation.y) ),
588 T13( centerOfRotation.y-(sina*centerOfRotation.x+cosa*centerOfRotation.y) );
593 temp = _matrix[0][0];
594 _matrix[0][0] = temp * T00 + _matrix[0][1] * T01 + _matrix[0][3] * T03;
595 _matrix[0][1] = temp * T10 + _matrix[0][1] * T11 + _matrix[0][3] * T13;
596 temp = _matrix[1][0];
597 _matrix[1][0] = temp * T00 + _matrix[1][1] * T01 + _matrix[1][3] * T03;
598 _matrix[1][1] = temp * T10 + _matrix[1][1] * T11 + _matrix[1][3] * T13;
599 temp = _matrix[2][0];
600 _matrix[2][0] = temp * T00 + _matrix[2][1] * T01 + _matrix[2][3] * T03;
601 _matrix[2][1] = temp * T10 + _matrix[2][1] * T11 + _matrix[2][3] * T13;
602 temp = _matrix[3][0];
603 _matrix[3][0] = temp * T00 + _matrix[3][1] * T01 + _matrix[3][3] * T03;
604 _matrix[3][1] = temp * T10 + _matrix[3][1] * T11 + _matrix[3][3] * T13;
613 const Vector& centerOfRotation,
650 const Type xx(Type(u.x * u.x));
651 const Type yy(Type(u.y * u.y));
652 const Type zz(Type(u.z * u.z));
653 const Type xy(Type(u.x * u.y));
654 const Type xz(Type(u.x * u.z));
655 const Type yz(Type(u.y * u.z));
659 const double a (
double(angle) * DEG_TO_RAD);
660 const Type sina( (Type) sin(a) );
661 const Type cosa( (Type) cos(a) );
671 R(0,0) = xx + (1-xx)*cosa;
672 R(1,0) = xy - xy*cosa + u.z*sina;
673 R(2,0) = xz - xz*cosa - u.y*sina;
675 R(0,1) = xy - xy*cosa - u.z*sina;
676 R(1,1) = yy + (1-yy)*cosa;
677 R(2,1) = yz - yz*cosa + u.x*sina;
679 R(0,2) = xz - xz*cosa + u.y*sina;
680 R(1,2) = yz - yz*cosa - u.x*sina;
681 R(2,2) = zz + (1-zz)*cosa;
686 this->Translate(-centerOfRotation.x, -centerOfRotation.y, -centerOfRotation.z);
688 this->Translate(centerOfRotation.x, centerOfRotation.y, centerOfRotation.z);
703 _matrix[0][0] = _matrix[0][0] * x;
704 _matrix[0][1] = _matrix[0][1] * y;
705 _matrix[0][2] = _matrix[0][2] * z;
708 _matrix[1][0] = _matrix[1][0] * x;
709 _matrix[1][1] = _matrix[1][1] * y;
710 _matrix[1][2] = _matrix[1][2] * z;
713 _matrix[2][0] = _matrix[2][0] * x;
714 _matrix[2][1] = _matrix[2][1] * y;
715 _matrix[2][2] = _matrix[2][2] * z;
718 _matrix[3][0] = _matrix[3][0] * x;
719 _matrix[3][1] = _matrix[3][1] * y;
720 _matrix[3][2] = _matrix[3][2] * z;
742 const Type T03 = anchor.x*(1-x);
743 const Type T13 = anchor.y*(1-y);
744 const Type T23 = anchor.z*(1-z);
749 _matrix[0][0] = _matrix[0][0] * T00 + _matrix[0][3] * T03;
750 _matrix[0][1] = _matrix[0][1] * T11 + _matrix[0][3] * T13;
751 _matrix[0][2] = _matrix[0][2] * T22 + _matrix[0][3] * T23;
754 _matrix[1][0] = _matrix[1][0] * T00 + _matrix[1][3] * T03;
755 _matrix[1][1] = _matrix[1][1] * T11 + _matrix[1][3] * T13;
756 _matrix[1][2] = _matrix[1][2] * T22 + _matrix[1][3] * T23;
759 _matrix[2][0] = _matrix[2][0] * T00 + _matrix[2][3] * T03;
760 _matrix[2][1] = _matrix[2][1] * T11 + _matrix[2][3] * T13;
761 _matrix[2][2] = _matrix[2][2] * T22 + _matrix[2][3] * T23;
764 _matrix[3][0] = _matrix[3][0] * T00 + _matrix[3][3] * T03;
765 _matrix[3][1] = _matrix[3][1] * T11 + _matrix[3][3] * T13;
766 _matrix[3][2] = _matrix[3][2] * T22 + _matrix[3][3] * T23;
773 #ifdef MATRIX_TYPE_FLOAT
774 typedef float GlsMatrixElementType;
776 #define GLS_glLoadMatrix_TYPE glLoadMatrixf
777 #define GLS_glMultMatrix_TYPE glMultMatrixf
779 typedef double GlsMatrixElementType;
780 typedef GlsMatrixAffineD GlsMatrixType;
781 #define GLS_glLoadMatrix_TYPE glLoadMatrixd
782 #define GLS_glMultMatrix_TYPE glMultMatrixd
unsigned char R(void) const
Definition: gls_color.h:201
RotationAxis
Definition: vertex.h:73
Definition: gls_matrix.h:62
float MagnitudeSquared() const
Definition: vertex.h:296
void Normalize(void)
Definition: vertex.h:271
static const double PRECISION
Definition: gls_matrix.h:314
Type * _matrix[DIM]
Definition: gls_matrix.h:335
void Translate(const Vector &v)
Definition: gls_matrix_affine.h:232
void Transform(Vector &v) const
Definition: gls_matrix_affine.h:271
VertexNoColor Vector
Definition: gls_font_base.h:68
Type _data[DIM *DIM]
Definition: gls_matrix.h:323
The disti::Vertex class. A class for manipulating 3D vertices.
unsigned char G(void) const
Definition: gls_color.h:204
Type * Data()
Definition: gls_matrix.h:132
void Translate(Type x, Type y, Type z)
Definition: gls_matrix_affine.h:197
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:385
GlsMatrix< Type, 4 > DecomposeRotationMatrix(const GlsMatrix< Type, 4 > &matrix, const Vector &scale)
Definition: gls_matrix_affine.h:306
void Rotate(Type angle, RotationAxis axis)
Definition: gls_matrix_affine.h:391
Vector DecomposeScale(const GlsMatrix< Type, 4 > &m)
Definition: gls_matrix_affine.h:291
Definition: gls_quaternion.h:57
The disti::GlsQuaternion class.
float Magnitude() const
Definition: vertex.h:290
unsigned char B(void) const
Definition: gls_color.h:207
bool IsVeryClose(const GlsMatrix< Type, 4 > &b) const
Definition: gls_matrix_affine.h:112
Definition: bmpimage.h:46
unsigned char A(void) const
Definition: gls_color.h:210
void Scale(Type x, Type y, Type z)
Definition: gls_matrix_affine.h:693
Vector operator*(const Vector &v) const
Definition: gls_matrix_affine.h:243
Definition: gls_matrix_affine.h:61
GlsMatrixAffine()
Definition: gls_matrix_affine.h:362