VR-Forces Developer's Guide
 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) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 #pragma once
10 
11 #include <vrvMath/DtMatrix4.h>
12 
13 namespace makVrv
14 {
15 
18  template<class T>
20  {
21  public:
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 
99  {
100  public:
102  static Matrix3_32 ToFloat32(const Matrix3_64& rhs)
103  {
104  Matrix3_32 result;
105  for(size_t i = 0; i < 3; ++i)
106  {
107  for(size_t j = 0; j < 3; ++j)
108  {
109  result[i][j] = static_cast<float32>(rhs[i][j]);
110  }
111  }
112  return result;
113  }
114 
116  static Matrix4_32 ToFloat32(const Matrix4_64& rhs)
117  {
118  Matrix4_32 result;
119  for(size_t i = 0; i < 4; ++i)
120  {
121  for(size_t j = 0; j < 4; ++j)
122  {
123  result[i][j] = static_cast<float32>(rhs[i][j]);
124  }
125  }
126  return result;
127  }
128  };
129 
130 } //namespace makVrv
static Matrix3_32 ToFloat32(const Matrix3_64 &rhs)
convert a 64-bit 3x3 matrix to 32-bit
Definition: DtMatrixUtils.h:102
static T Sin(T val)
Standard math routines.
Definition: DtMath.h:61
class for converting from 32-bit to 64-bit floating point versions of matricies
Definition: DtMatrixUtils.h:98
static T Squared(T val)
Standard math routines.
Definition: DtMath.h:69
static DtMatrix4< T > matrixRotationX(T angle)
Definition: DtMatrixUtils.h:30
static T Cos(T val)
Standard math routines.
Definition: DtMath.h:62
static DtMatrix4< T > matrixRotationY(T angle)
Definition: DtMatrixUtils.h:43
T z
Definition: DtVector3.h:132
T x
Definition: DtVector3.h:132
DT_DLL_vrfutil double angle(double vec1[3], double vec2[3])
static DtMatrix4< T > matrixRotation_4x4(const DtVector3< T > &axis, T angle)
Definition: DtMatrixUtils.h:92
float float32
Definition: DtCommonTypes.h:33
T y
Definition: DtVector3.h:132
static DtMatrix4< T > matrixRotationZ(T angle)
Definition: DtMatrixUtils.h:56
Matrix manipulation utilities.
Definition: DtMatrixUtils.h:19
3 dimensional matrix
Definition: DtMatrix3.h:20
2 dimensional vector
Definition: DtMath.h:21
void setIdentity(void)
Set matrix to identity matrix.
Definition: DtMatrix4.h:256
static Matrix4_32 ToFloat32(const Matrix4_64 &rhs)
convert a 64-bit 4x4 matrix to 32-bit
Definition: DtMatrixUtils.h:116
4 dimensional matrix
4 dimensional matrix
Definition: DtMatrix4.h:22
static DtMatrix3< T > matrixRotation_3x3(const DtVector3< T > &axis, T angle)
Definition: DtMatrixUtils.h:69

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)