You.i Engine
YiMatrixUtilities.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_GL2_MATRIX_UTILITIES_H_
3 #define _YI_GL2_MATRIX_UTILITIES_H_
4 
5 #include "framework/YiPredef.h"
6 
7 #include <glm/fwd.hpp>
8 #include <glm/mat4x4.hpp>
9 
16 {
17 public:
21  static glm::vec3 TransformVector(const glm::mat4 &rMat4x4, const glm::vec3 &rV);
22 
28  static glm::vec3 ProjectVector(const glm::vec3 &A, const glm::vec3 &normalizedB);
29 
35  template<typename valType>
36  static bool SafeInverse(glm::tmat4x4<valType> const &m, glm::tmat4x4<valType> &mOut);
37 
38 private:
40 };
41 
42 inline glm::vec3 CYIMatrixUtilities::TransformVector(const glm::mat4 &rMat4x4, const glm::vec3 &rV)
43 {
44  glm::vec3 out;
45 
46  const float v0 = rV[0];
47  const float v1 = rV[1];
48  const float v2 = rV[2];
49  out[0] = (rMat4x4[0][0] * v0 + rMat4x4[1][0] * v1 + rMat4x4[2][0] * v2 + rMat4x4[3][0]);
50  out[1] = (rMat4x4[0][1] * v0 + rMat4x4[1][1] * v1 + rMat4x4[2][1] * v2 + rMat4x4[3][1]);
51  out[2] = (rMat4x4[0][2] * v0 + rMat4x4[1][2] * v1 + rMat4x4[2][2] * v2 + rMat4x4[3][2]);
52 
53  return out;
54 }
55 
56 inline glm::vec3 CYIMatrixUtilities::ProjectVector(const glm::vec3 &A, const glm::vec3 &normalizedB)
57 {
58  return glm::dot(A, normalizedB) / glm::dot(normalizedB, normalizedB) * normalizedB;
59 }
60 
65 #endif // _YI_GL2_MATRIX_UTILITIES_H_
static bool SafeInverse(glm::tmat4x4< valType > const &m, glm::tmat4x4< valType > &mOut)
Definition: YiMatrixUtilities.h:15
static glm::vec3 TransformVector(const glm::mat4 &rMat4x4, const glm::vec3 &rV)
Definition: YiMatrixUtilities.h:42
static glm::vec3 ProjectVector(const glm::vec3 &A, const glm::vec3 &normalizedB)
Definition: YiMatrixUtilities.h:56