Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: converting glm::mat4 to XMFLOAT4X4

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2011

    converting glm::mat4 to XMFLOAT4X4

    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.

    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-\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?

    Last edited by freefallr; 07-20-2013 at 04:51 AM. Reason: code layout

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    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.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts