Created
March 9, 2018 16:57
-
-
Save podgorskiy/04a3cb36a27159e296599183215a71b0 to your computer and use it in GitHub Desktop.
Eigen to GLM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <Eigen/Dense> | |
#include <glm/matrix.hpp> | |
template<typename T, int m, int n> | |
inline glm::mat<m, n, float, glm::precision::highp> E2GLM(const Eigen::Matrix<T, m, n>& em) | |
{ | |
glm::mat<m, n, float, glm::precision::highp> mat; | |
for (int i = 0; i < m; ++i) | |
{ | |
for (int j = 0; j < n; ++j) | |
{ | |
mat[j][i] = em(i, j); | |
} | |
} | |
return mat; | |
} | |
template<typename T, int m> | |
inline glm::vec<m, float, glm::precision::highp> E2GLM(const Eigen::Matrix<T, m, 1>& em) | |
{ | |
glm::vec<m, float, glm::precision::highp> v; | |
for (int i = 0; i < m; ++i) | |
{ | |
v[i] = em(i); | |
} | |
return v; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just what I was looking for. I was hoping that there would be a way to access the Eigen data directly.