Cafu Engine
DepRelMatrix.hpp
1 /*
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.
5 */
6 
7 /****************************************/
8 /*** Dependency Relationship Matrices ***/
9 /****************************************/
10 
11 #ifndef CAFU_DEP_REL_MATRIX_HPP_INCLUDED
12 #define CAFU_DEP_REL_MATRIX_HPP_INCLUDED
13 
14 #include "Math3D/Matrix.hpp"
15 
16 
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.
23 {
24  public:
25 
26  DepRelMatrixT();
27  DepRelMatrixT(const DepRelMatrixT& Other);
28  virtual ~DepRelMatrixT() { }
29 
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().
35  virtual void Update()
36  {
37  }
38 
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.
42 
43 
44  private:
45 
46  static unsigned long GlobalIDCount;
47 };
48 
49 
50 /// This class models the relationship with which a inverse matrix depends on its original matrix.
52 {
53  public:
54 
55  InverseMatrixT(DepRelMatrixT* Source=NULL);
56 
57  /// Sets the source matrix. Useful if InverseMatrixTs are stored in an array.
58  void SetSourceMatrix(DepRelMatrixT* Source);
59 
60  /// Overwrite the base class method.
61  virtual void Update();
62 
63 
64  private:
65 
66  DepRelMatrixT* m_Source;
67 };
68 
69 
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).
72 ///
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.
77 {
78  public:
79 
81 
82  /// Overwrite the base class method.
83  virtual void Update();
84 
85 
86  private:
87 
88  DepRelMatrixT& m_A;
89  DepRelMatrixT& m_B;
90 };
91 
92 #endif
void SetSourceMatrix(DepRelMatrixT *Source)
Sets the source matrix. Useful if InverseMatrixTs are stored in an array.
Definition: DepRelMatrix.cpp:40
This class models the relationship with which a product matrix A*B depends on its components A and B ...
Definition: DepRelMatrix.hpp:76
virtual void Update()
Overwrite the base class method.
Definition: DepRelMatrix.cpp:46
virtual void Update()
This method updates this matrix from the matrices it depends on (the source matrices).
Definition: DepRelMatrix.hpp:35
This class models the relationship with which a inverse matrix depends on its original matrix...
Definition: DepRelMatrix.hpp:51
MatrixT Matrix
The matrix.
Definition: DepRelMatrix.hpp:39
A matrix class with which dependencies among matrices can be handled.
Definition: DepRelMatrix.hpp:22
virtual void Update()
Overwrite the base class method.
Definition: DepRelMatrix.cpp:68
unsigned long Age
The "age" or change-count of this matrix. How old the source matrix was when we were last updated...
Definition: DepRelMatrix.hpp:40
const unsigned long ID
The unique ID of this matrix. Useful for unambiguous identification.
Definition: DepRelMatrix.hpp:41