You.i Engine
YiMatrixUtilities.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. 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 vOut;
45 
46  const float fV0 = rV[0];
47  const float fV1 = rV[1];
48  const float fV2 = rV[2];
49  vOut[0] = (rMat4x4[0][0] * fV0 + rMat4x4[1][0] * fV1 + rMat4x4[2][0] * fV2 + rMat4x4[3][0]);
50  vOut[1] = (rMat4x4[0][1] * fV0 + rMat4x4[1][1] * fV1 + rMat4x4[2][1] * fV2 + rMat4x4[3][1]);
51  vOut[2] = (rMat4x4[0][2] * fV0 + rMat4x4[1][2] * fV1 + rMat4x4[2][2] * fV2 + rMat4x4[3][2]);
52 
53  return vOut;
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