This forum has been archived. All content is frozen. Please use KDE Discuss instead.

From Eigen::Matrix4d to QMatrix4x4

Tags: None
(comma "," separated)
linello
Registered Member
Posts
56
Karma
0
OS

From Eigen::Matrix4d to QMatrix4x4

Fri Jul 26, 2013 9:01 am
Is there a simple way to map a Eigen::Matrix4d content to a Qt QMatrix4x4?
Since I'm using a QGlShaderProgram that takes a QMatrix4x4 as uniform for the GLSL mat4 type, I have to copy the content of my Eigen matrices to Qt QMatrix4x4 with a double nested for loop.

I don't want to write the loop everytime, nor I don't want to write a conversion function, I think that since I already have the data, they should be mapped simply.

Code: Select all
    Eigen::Matrix4d eMVP = Projection*ModelView;

    QMatrix4x4 MVP;
    for (int i=0; i<4;i++)
    {
        for (int j=0; j<4; j++)
            MVP(i,j)=eMVP(i,j);
    }
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
That's more a Qt question, but you can simply do QMatrix4x4(eMVP.data()).
Hauke
Registered Member
Posts
109
Karma
3
OS
I do something like this
Code: Select all
QMatrix4x4 eigenToQt( const mtk::RigidTransform3D& transform )
{
  return QMatrix4x4(transform.cast<qreal>().data()).transposed();
}

Something similar should work with regular matrices as well.

Regards,
Hauke


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]