Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XformMatrix.h
Go to the documentation of this file.
1 /*
2 
3 License
4 
5 Menge
6 Copyright and trademark 2012-14 University of North Carolina at Chapel Hill.
7 All rights reserved.
8 
9 Permission to use, copy, modify, and distribute this software and its documentation
10 for educational, research, and non-profit purposes, without fee, and without a
11 written agreement is hereby granted, provided that the above copyright notice,
12 this paragraph, and the following four paragraphs appear in all copies.
13 
14 This software program and documentation are copyrighted by the University of North
15 Carolina at Chapel Hill. The software program and documentation are supplied "as is,"
16 without any accompanying services from the University of North Carolina at Chapel
17 Hill or the authors. The University of North Carolina at Chapel Hill and the
18 authors do not warrant that the operation of the program will be uninterrupted
19 or error-free. The end-user understands that the program was developed for research
20 purposes and is advised not to rely exclusively on the program for any reason.
21 
22 IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS
23 BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
24 DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
25 DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
26 AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
29 DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY
31 OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
32 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS
33 TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
34 
35 Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
36 
37 */
38 
45 #ifndef __XFORMMATRIX_H__
46 #define __XFORMMATRIX_H__
47 
48 #include "CoreConfig.h"
49 #include "graphCommon.h"
50 #include <iostream>
51 
52 namespace Menge {
53 
54  namespace SceneGraph {
55 
56  class Transform;
57 
69  class MENGE_API XformMatrix {
70  public:
74  XformMatrix();
75 
81  void setTranslation( const Vector3 & vec ) { _trans = vec; setDirty( MAT | IMAT ); }
82 
88  void addTranslation( const Vector3 & vec ) { _trans += vec; setDirty( MAT | IMAT ); }
89 
95  void setScale( const Vector3 & vec ) { _scale = vec; setDirty( MAT | IMAT ); }
96 
106  void setRotationDeg( const Vector3 & vec ) { _rot = vec * DEG_TO_RAD; setDirty(); }
107 
117  void setRotationRad( const Vector3 & vec ) { _rot = vec; setDirty(); }
118 
130  void addRotationDeg( const Vector3 & vec ) { _rot.SumScale( DEG_TO_RAD, vec ); setDirty(); }
131 
143  void addRotationRad( const Vector3 & vec ) { _rot += vec; setDirty(); }
144 
154  void setRotAxisDeg( const Vector3 & vec );
155 
165  void setRotAxisRad( const Vector3 & vec );
166 
170  //void rotatePivotMatrix( Matrix4x4 & mat );
176  void translationMatrix( Matrix4x4 & mat );
177 
183  void translationInverseMatrix( Matrix4x4 & mat );
184 
190  void scaleMatrix( Matrix4x4 & mat );
191 
197  void scaleInverseMatrix( Matrix4x4 & mat );
198 
204  void rotationMatrix( Matrix4x4 & mat );
205 
211  void rotationInverseMatrix( Matrix4x4 & mat );
212 
218  void getMatrix( Matrix4x4 & mat );
219 
225  void getInverseMatrix( Matrix4x4 & mat );
226 
227  friend class Transform;
228 
235  friend Logger & operator << ( Logger & out, const XformMatrix & xformMat );
236 
237  protected:
238 
243 
248 
254 
260 
265 
270 
276  enum MatrixBit {
277  ROT_MAT = 1, // rotation matrix
278  MAT = 2, // full matrix
279  IMAT = 4 // inverse matrix
280  };
281 
288  int _clean;
289 
294 
299 
304 
308  void updateRotAxisMat();
309 
313  inline void setDirty() { _clean = 0; }
314 
321  inline void setDirty( int bit ) { _clean &= ~bit; }
322 
328  inline void setDirty( MatrixBit bit ) { _clean &= (int)(~bit); }
329 
336  inline bool isClean( MatrixBit bit ) { return ( _clean & (int)bit ) != 0x0; }
337 
343  inline void setClean( MatrixBit bit ) { _clean |= (int)bit; }
344 
351  inline void setClean( int bit ) { _clean |= bit; }
352  };
353  } // namespace SceneGraph
354 } // namespace Menge
355 #endif // __XFORMMATRIX_H__
Vector3 _rot
The rotation component of the transformation. Euler angles in radians.
Definition: XformMatrix.h:253
void setTranslation(const Vector3 &vec)
Set the translation of this node.
Definition: XformMatrix.h:81
void setScale(const Vector3 &vec)
Set the scale of this node.
Definition: XformMatrix.h:95
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
Scene graph node which applies transforms to nodes.
Definition: Transform.h:59
void setClean(MatrixBit bit)
Sets the indicated matrix to be clean.
Definition: XformMatrix.h:343
Logger & operator<<(Logger &out, const BFSM::PropertyOperand op)
Friend function for printing string versions of the PropertyOperand enum.
Definition: FSMEnumeration.cpp:43
Basic 4x4 matrix of floats.
Definition: Matrix.h:70
Sets up the proper compiler directives for platform and dll export/import.
void setClean(int bit)
Sets the indicated matrix to be clean.
Definition: XformMatrix.h:351
Vector3 _trans
The translation component of the transformation.
Definition: XformMatrix.h:242
void setRotationRad(const Vector3 &vec)
Set the orientation of this node.
Definition: XformMatrix.h:117
int _clean
An integer mask for determining which cached matrices are clean/dirty.
Definition: XformMatrix.h:288
void setDirty(int bit)
Set the matrix corresponding to the given bit dirty.
Definition: XformMatrix.h:321
Matrix4x4 _rotAxisMat
Cached rotation axis matrix.
Definition: XformMatrix.h:264
MatrixBit
Enumeration of dirty matrices.
Definition: XformMatrix.h:276
The transformation matrix.
Definition: XformMatrix.h:69
An html logger - writes messages to a formatted html file.
Definition: Logger.h:59
The SceneGraph (SceneGraph) name space, containing all elements to use in a SceneGraph.
Matrix4x4 _mat
Cached transformation matrix.
Definition: XformMatrix.h:298
Matrix4x4 _iMat
Cached inverse transformation matrix.
Definition: XformMatrix.h:303
void setDirty()
Set all matrices dirty.
Definition: XformMatrix.h:313
void addRotationRad(const Vector3 &vec)
Offsets the orientation of this node.
Definition: XformMatrix.h:143
bool isClean(MatrixBit bit)
Reports if the indicated matrix is clean.
Definition: XformMatrix.h:336
void addTranslation(const Vector3 &vec)
Offset the translation of this node.
Definition: XformMatrix.h:88
void setDirty(MatrixBit bit)
Set the matrix corresponding to the given bit dirty.
Definition: XformMatrix.h:328
Vector3 _rotAxis
The rotation axis component of the transformation. Pre-rotation Euler angles in radians.
Definition: XformMatrix.h:259
Various important pre-compiler directives for the scene graph.
void addRotationDeg(const Vector3 &vec)
Offsets the orientation of this node.
Definition: XformMatrix.h:130
Matrix4x4 _rotAxisIMat
Cached inverse rotation axis matrix.
Definition: XformMatrix.h:269
MENGE_API const float DEG_TO_RAD
Scale factor for converting degrees to radians.
Definition: geomQuery.cpp:50
Matrix4x4 _rotMat
Cached rotation matrix.
Definition: XformMatrix.h:293
Vector3 _scale
The scale component of the transformation.
Definition: XformMatrix.h:247
void setRotationDeg(const Vector3 &vec)
Set the orientation of this node.
Definition: XformMatrix.h:106