Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Matrix.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 
44 #ifndef __MATRIX_H__
45 #define __MATRIX_H__
46 
47 #include "CoreConfig.h"
48 #include "vector.h"
49 #include <string.h>
50 #include <iostream>
51 
52 namespace Menge {
53 
54  namespace Math {
70  class MENGE_API Matrix4x4 {
71  public:
77  Matrix4x4();
78 
87  Matrix4x4( bool garbage ){} // DOESN'T initialize data
88 
92  void identity();
93 
103  inline float operator()( int row, int col ) const { return _matData[row][col]; }
104 
114  inline float & operator()( int row, int col ) { return _matData[row][col]; }
115 
125  void setRow( int row, float v0, float v1, float v2, float v3 = 1.f );
126 
134  void setRow( int row, const Vector3 & vec, float v3 = 1.f );
135 
150  void scale( const Vector3 & scale, Matrix4x4 & m );
151 
166  void scaleRight( const Vector3 & scale, Matrix4x4 & m );
167 
175  inline float trace() const {
176  return _matData[0][0] * _matData[1][1] * _matData[2][2] * _matData[3][3];
177  };
178 
186  inline float trace3x3() const {
187  return _matData[0][0] * _matData[1][1] * _matData[2][2];
188  };
189 
202  void translateRotation( const Vector3 & trans );
203 
216  void translateRotationLeft( const Vector3 & trans );
217 
226  void setDiagonal( float v0, float v1, float v2, float v3 = 1.f );
227 
234  void setDiagonal( const Vector3 & vec, float v3 = 1.f );
235 
245  void product( const Matrix4x4 & m1, const Matrix4x4 & m2 );
246 
258  void product3x3( const Matrix4x4 & m1, const Matrix4x4 & m2 );
259 
265  void setAsTranspose( Matrix4x4 & m1 );
266 
270  void transpose();
271 
279  friend Logger & operator << ( Logger & out, const Matrix4x4 & mat );
280 
286  inline float * getFlattened() { return _flatData; }
287 
288  private:
293  union {
294  float _flatData[16];
295  float _matData[4][4];
296  };
297  };
298 
302  extern MENGE_API Matrix4x4 IDENTITY4x4;
303  } // namespace Math
304 } // namespace Menge
305 #endif // __MATRIX_H__
float operator()(int row, int col) const
Index operation.
Definition: Matrix.h:103
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
float & operator()(int row, int col)
Reference index operation.
Definition: Matrix.h:114
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.
Matrix4x4(bool garbage)
Non-initializing constructor.
Definition: Matrix.h:87
float trace3x3() const
Compute the trace of the upper-left 3x3 sub-matrix.
Definition: Matrix.h:186
An html logger - writes messages to a formatted html file.
Definition: Logger.h:59
The namespace for math primitives for simulation and visualization.
Collection of Vector2, Vector3, and constants for simple inclusion.
float trace() const
Compute the trace of the 4x4 matrix.
Definition: Matrix.h:175
float * getFlattened()
Get a pointer to the underlying data as a flat array.
Definition: Matrix.h:286