2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
7 /****************************************/
8 /*** Dependency Relationship Matrices ***/
9 /****************************************/
11 #ifndef CAFU_DEP_REL_MATRIX_HPP_INCLUDED
12 #define CAFU_DEP_REL_MATRIX_HPP_INCLUDED
14 #include "Math3D/Matrix.hpp"
17 /// A matrix class with which dependencies among matrices can be handled.
18 /// In order to model a specific dependency relationship, child classes should be derived from this class,
19 /// see InverseMatrixT and ProductMatrixT for examples.
20 /// Note that also the roots/parents/sources of the dep. relationships should (or at least: can) be matrix objects
21 /// of the DepRelMatrixT class, because that helps to avoid unecessary updates of the dependents.
27 DepRelMatrixT(const DepRelMatrixT
& Other
);
28 virtual ~DepRelMatrixT() { }
30 /// This method updates this matrix from the matrices it depends on (the source matrices).
31 /// Derived classes are expected to overwrite this method in order to provide the desired behaviour.
32 /// Their code should make good use of the Age member in order to minimize update efforts.
33 /// User code should call this method before accessing the Matrix (or Age) member whenever
34 /// there is a chance that the source matrices changed since the last call to Update().
39 MatrixT Matrix
; ///< The matrix.
40 unsigned long Age
; ///< The "age" or change-count of this matrix. How old the source matrix was when we were last updated.
41 const unsigned long ID
; ///< The unique ID of this matrix. Useful for unambiguous identification.
46 static unsigned long GlobalIDCount
;
50 /// This class models the relationship with which a inverse matrix depends on its original matrix.
51 class InverseMatrixT
: public DepRelMatrixT
55 InverseMatrixT(DepRelMatrixT
* Source
=NULL
);
57 /// Sets the source matrix. Useful if InverseMatrixTs are stored in an array.
58 void SetSourceMatrix(DepRelMatrixT
* Source
);
60 /// Overwrite the base class method.
61 virtual void Update();
66 DepRelMatrixT
* m_Source
;
70 /// This class models the relationship with which a product matrix A*B depends on its components A and B
71 /// (e.g.\ how a model-to-view matrix depends on the model-to-world and world-to-view matrices).
73 /// Note that \code ProductMatrixT ModelView(WorldToView, ModelToWorld); \endcode would be the correct statement
74 /// for a model-to-view matrix, whereas the opposite component order
75 /// \code ProductMatrixT ModelView(ModelToWorld, WorldToView); \endcode is wrong.
76 class ProductMatrixT
: public DepRelMatrixT
80 ProductMatrixT(DepRelMatrixT
& A
, DepRelMatrixT
& B
);
82 /// Overwrite the base class method.
83 virtual void Update();