0

Is it possible to build XMMATRIX using four FMVECTOR ? I took the idea from Frank Luna's book and I tried to build something around that but unfortunately it is clear that I did not grasp the concept well. Here it is what I wrote. Ok, I know that this code sucks but I am one of those who wants to learn everything ( and possibly even more ) so I tried.

XMVECTOR MyArray[4];
XMMATRIX() {}

XMMATRIX MyMatrix(FXMVECTOR MyArray0, FXMVECTOR MyArray1, FXMVECTOR MyArray2, CXMVECTOR My Array3 )
{
    r[0] = MyArray1;  r[1] = MyArray1; r[2] = MyArray1; r[3] = MyArray1;
}

float MyArray1[4] = { 1.0f, 3.0f, 6.0f, 5.0f };
float MyArray2[4] = { 4.0f, 3.0f, 3.0f, 7.0f };
float MyArray3[4] = { 1.0f, 3.0f, 6.0f, 3.0f };
float MyArray4[4] = { 1.0f, 0.0f, 6.0f, 0.0f };
JesusFreke
  • 19,784
  • 5
  • 65
  • 68
cppstudent
  • 23
  • 4
  • [Don't write it yourself](https://learn.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-xmmatrix-xmmatrix(fxmvector_fxmvector_fxmvector_cxmvector)). – Hans Passant Mar 14 '20 at 14:50

1 Answers1

1

There is a constructor you need, as said here.

Usage example:

XMVECTOR vec_array[4] = 
{
    { 1.0f, 3.0f, 6.0f, 5.0f },
    { 4.0f, 3.0f, 3.0f, 7.0f },
    { 1.0f, 3.0f, 6.0f, 3.0f },
    { 1.0f, 0.0f, 6.0f, 0.0f }
}; 

XMMATRIX matrix(vec_array[0], vec_array[1], vec_array[2], vec_array[3]);
mylibh
  • 153
  • 9
  • great. THANK YOU ! – cppstudent Mar 15 '20 at 09:45
  • Note a slightly more efficient approach if you have four ``XMVECTOR`` values already is: ``XMMATRIX matrix; matrix.r[0] = vec_array[0]; matrix.r[1] = vec_array[1]; matrix.r[2] = vec_array[2]; matrix.r[3] = vec_array[3];`` That said, remember that ``XMVECTOR`` and ``XMMATRIX`` are really proxies for SSE registers more than data-types. See [Microsoft Docs(https://learn.microsoft.com/en-us/windows/win32/dxmath/pg-xnamath-getting-started#type-usage-guidelines). – Chuck Walbourn Mar 17 '20 at 22:38
  • Thank you Chuck for answering me again. Sorry for the late acknowledgement. – cppstudent Apr 01 '20 at 19:48