PDA

View Full Version : converting glm::mat4 to XMFLOAT4X4



freefallr
07-20-2013, 04:49 AM
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?

XMFLOAT4X4 is a simple union containing 16 floats (http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xmfloat4x4(v=vs.85 ).aspx).

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'

The actual code in glm\core\type_vec4.inl is heavily templated and way over my head. Can anyone suggest a solution to this?

thanks

thokra
07-22-2013, 02:27 AM
I don't know where you actually invoke template code that tries to do this conversion, but I can't locate anything in the code you posted above. Neither do I see any glm::vec3 anywhere, nor is there any copy, initialization or argument passing involving a glm::vec3 and a float. Also, please read the forum guidelines if you're going to continue to participate here. Put your code in '['code']' tags.

carsten neumann
07-22-2013, 10:15 AM
I guess you may be looking for glm::value_ptr() from glm/gtc/type_ptr.hpp. It returns a pointer to the data stored in a glm vector or matrix.