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

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)