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

XNA Math XMVECTOR XMVector4Transform to Eigen

Tags: None
(comma "," separated)
brad_c6
Registered Member
Posts
3
Karma
0
Hello,
I am currently working to port a game over from DirectX to open source alternatives. I am currently working to implement equivalent methods via Eigen. (In this case XMVECTOR XMVector4Transform)
Which is....
Code: Select all
XMFINLINE XMVECTOR XMVector4Transform
(
    FXMVECTOR V,
    CXMMATRIX M
)
{
    FLOAT fX = (M.m[0][0]*V.vector4_f32[0])+(M.m[1][0]*V.vector4_f32[1])+(M.m[2][0]*V.vector4_f32[2])+(M.m[3][0]*V.vector4_f32[3]);
    FLOAT fY = (M.m[0][1]*V.vector4_f32[0])+(M.m[1][1]*V.vector4_f32[1])+(M.m[2][1]*V.vector4_f32[2])+(M.m[3][1]*V.vector4_f32[3]);
    FLOAT fZ = (M.m[0][2]*V.vector4_f32[0])+(M.m[1][2]*V.vector4_f32[1])+(M.m[2][2]*V.vector4_f32[2])+(M.m[3][2]*V.vector4_f32[3]);
    FLOAT fW = (M.m[0][3]*V.vector4_f32[0])+(M.m[1][3]*V.vector4_f32[1])+(M.m[2][3]*V.vector4_f32[2])+(M.m[3][3]*V.vector4_f32[3]);
    XMVECTOR vResult = {
        fX,
        fY,
        fZ,
        fW
    };
    return vResult;
}


Would I want to use a Transform? As I imagine the more I have Eigen do, the more optimized it will be (via SSE).

Thank You
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This is just a regular matrix-vector product, so you can either use a Matrix4f or Projection3f and return M * v.
brad_c6
Registered Member
Posts
3
Karma
0
I found this to work, I multiplied the Transpose of the matrix

Code: Select all
Eigen::Matrix4f myMatrix;
Eigen::Vector4f myVector;
Eigen::Vector4f resultVector;

myMatrix << 1,2,3,4,
                        5,6,7,8,
                        9,10,11,12,
                        13,14,15,16;

myVector.x = 1;
myVector.y = 2;
myVector.z = 3;
myVector.w =  4;

resultVector = myMatrix.transpose() * myVector;



Resulting in (X,Y,Z,W) [90, 100, 110, 120] matching XNAMath

Thank You kind Sir ;D


Bookmarks



Who is online

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