VR-Forces 4.3.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtMatrixUtils.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2014 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 #pragma once
10 
11 #include "DtMatrix3.h"
12 #include "DtMatrix4.h"
13 
14 namespace makVrv {
15 
18  template<class T>
20  {
21  public:
22  static DtMatrix4<T> matrixRotationX(T angle);
23  static DtMatrix4<T> matrixRotationY(T angle);
24  static DtMatrix4<T> matrixRotationZ(T angle);
25  static DtMatrix4<T> matrixRotation_4x4(const DtVector3<T>& axis, T angle);
26  static DtMatrix3<T> matrixRotation_3x3(const DtVector3<T>& axis, T angle);
27  };
28 
29  template<class T>
31  {
32  DtMatrix4<T> result;
33 
34  result.setIdentity();
35 
36  result[1][1] = DtMath::Cos(angle);result[1][2] = -DtMath::Sin(angle);
37  result[2][1] = DtMath::Sin(angle);result[2][2] = DtMath::Cos(angle);
38 
39  return result;
40  }
41 
42  template<class T>
44  {
45  DtMatrix4<T> result;
46 
47  result.setIdentity();
48 
49  result[0][0] = DtMath::Cos(angle);result[0][2] = DtMath::Sin(angle);
50  result[2][0] = -DtMath::Sin(angle);result[2][2] = DtMath::Cos(angle);
51 
52  return result;
53  }
54 
55  template<class T>
57  {
58  DtMatrix4<T> result;
59 
60  result.setIdentity();
61 
62  result[0][0] = DtMath::Cos(angle);result[0][1] = -DtMath::Sin(angle);
63  result[1][0] = DtMath::Sin(angle);result[1][1] = DtMath::Cos(angle);
64 
65  return result;
66  }
67 
68  template<class T>
70  {
71  DtMatrix3<T> result;
72 
73  T sin_theta = DtMath::Sin(theta);
74  T cos_theta = DtMath::Cos(theta);
75  T one_minus_cos_theta = 1-DtMath::Cos(theta);
76 
77  result[0][0] = cos_theta + DtMath::Squared(axis.x)*(one_minus_cos_theta);
78  result[0][1] = axis.x*axis.y*one_minus_cos_theta - axis.z*sin_theta;
79  result[0][2] = axis.x*axis.z*one_minus_cos_theta + axis.y*sin_theta;
80 
81  result[1][0] = axis.y*axis.x*one_minus_cos_theta + axis.z*sin_theta;
82  result[1][1] = cos_theta + DtMath::Squared(axis.y)*one_minus_cos_theta;
83  result[1][2] = axis.y*axis.z*one_minus_cos_theta - axis.x*sin_theta;
84 
85  result[2][0] = axis.z*axis.x*one_minus_cos_theta - axis.y*sin_theta;
86  result[2][1] = axis.z*axis.y*one_minus_cos_theta + axis.x*sin_theta;
87  result[2][2] = cos_theta + DtMath::Squared(axis.z)*one_minus_cos_theta;
88 
89  return result;
90  }
91  template<class T>
93  {
94  return DtMatrix4<T>(matrixRotation_3x3(axis, theta));
95  }
96 
98  {
99  public:
100  static Matrix3_32 ToFloat32(const Matrix3_64& rhs)
101  {
102  Matrix3_32 result;
103  for(size_t i = 0; i < 3; ++i)
104  {
105  for(size_t j = 0; j < 3; ++j)
106  {
107  result[i][j] = static_cast<float32>(rhs[i][j]);
108  }
109  }
110  return result;
111  }
112 
113  static Matrix4_32 ToFloat32(const Matrix4_64& rhs)
114  {
115  Matrix4_32 result;
116  for(size_t i = 0; i < 4; ++i)
117  {
118  for(size_t j = 0; j < 4; ++j)
119  {
120  result[i][j] = static_cast<float32>(rhs[i][j]);
121  }
122  }
123  return result;
124  }
125  };
126 
127 } //namespace makVrv

Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)