0

I want to create an initial transform matrix from an orientation quaternion and a position vector.

My initial matrix is in glm format, but I want toconvert the glm matrix to an XMFLOAT4X4 matrix.

glm::mat4 glm_mWorld= glm::toMat4(_qOrientation);
glm_mWorld[3]       = glm::vec4(_vPosition);

glm_mWorld = glm::transpose(glm_mWorld);

So how can I load the content of glm_mWorld into an XMFLOAT4X4?

Update: So after suggestion that I use memcpy, I came up with the following:

XMFLOAT4X4  mTransform;
XMFLOAT4    qOrient;

glm::mat4 glm_mWorld    = glm::toMat4(_descriptor._qOrientation);
glm_mWorld[3]           = glm::vec4(_descriptor._vPosition);

glm_mWorld = glm::transpose(glm_mWorld);

memcpy(&mTransform.m[0][0], &glm_mWorld[0][0], sizeof(glm::mat4));

This results in an error:

glm-0.9.4.3\glm\core\type_vec4.inl(251): error C2440: '<function-style-cast>' : cannot convert from 'const glm::vec3' to 'float'

Also, regarding column major / row major matrices, glm uses column major and XMFLOAT4X4 uses row major, which is why I transpose the glm matrix before attempting to convert it.

genpfault
  • 51,148
  • 11
  • 85
  • 139
fishfood
  • 4,092
  • 4
  • 28
  • 35
  • What did you try so far? `XMFLOAT4x4` is just a simple union according to http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xmfloat4x4(v=vs.85).aspx So, you can try to just memcpy (but you should care about order in which glm and xnamath store their matrices - column or row-major) – acrilige Jul 19 '13 at 11:09
  • try to use glm::valut_ptr – acrilige Jul 20 '13 at 19:01

1 Answers1

1

XMFLOAT4X4 has a constructor from float * so you can just call:

auto xmMatrix = XMFLOAT4X4( &glmMatrix[0][0] );

Just make sure that your matrices are the same sizes and use the same row/column major ordering.