Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save podgorskiy/04a3cb36a27159e296599183215a71b0 to your computer and use it in GitHub Desktop.
Save podgorskiy/04a3cb36a27159e296599183215a71b0 to your computer and use it in GitHub Desktop.
Eigen to GLM
#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;
}
@TimKrause2
Copy link

Just what I was looking for. I was hoping that there would be a way to access the Eigen data directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment