Cómo inicializar un glm::mat4 con una matriz?


Estoy usando la Biblioteca Matemática de OpenGL ( glm.g-truc.net ) y desea inicializar un glm::mat4 con una matriz flotante.

float aaa[16];
glm::mat4 bbb(aaa);

Esto no funciona.

Supongo que la solución es trivial, pero no se como hacerlo. No pude encontrar una buena documentación sobre glm. Le agradecería algunos enlaces útiles.

Author: genpfault, 2011-09-08

4 answers

Aunque no hay un constructor, GLM incluye funciones make_* en glm/gtc/type_ptr.hpp :

#include <glm/gtc/type_ptr.hpp>
float aaa[16];
glm::mat4 bbb = glm::make_mat4(aaa);
 61
Author: Matthew Marshall,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-13 20:38:14

También puede copiar directamente la memoria:

float aaa[16] = {
   1, 2, 3, 4,
   5, 6, 7, 8,
   9, 10, 11, 12,
   13, 14, 15, 16
};
glm::mat4 bbb;

memcpy( glm::value_ptr( bbb ), aaa, sizeof( aaa ) );
 7
Author: Anderson Silva,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-15 14:31:18

Podría escribir una función de adaptador:

template<typename T>
tvec4<T> tvec4_from_t(const T *arr) {
    return tvec4<T>(arr[0], arr[1], arr[2], arr[3]);
}

template<typename T>
tmat4<T> tmat4_from_t(const T *arr) {
    return tmat4<T>(tvec4_from_t(arr), tvec4_from_t(arr + 4), tvec4_from_t(arr + 8), tvec4_from_t(arr + 12));
}


// later
float aaa[16];
glm::mat4 bbb = tmac4_from_t(aaa);
 3
Author: bdonlan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-13 00:22:22
glm::mat4x4 view{ 2 / (right - left), 0, 0, 0,
            0, 2 / (top - bottom), 0, 0,
            0, 0, -2 / (farplane - nearplane), 0,
            -((right + left) / (right - left)), -((top + bottom) / (top - bottom)), -((farplane + nearplane) / (farplane - nearplane)), 1
        };


glm::mat4 view{ 2 / (right - left), 0, 0, 0,
            0, 2 / (top - bottom), 0, 0,
            0, 0, -2 / (farplane - nearplane), 0,
            -((right + left) / (right - left)), -((top + bottom) / (top - bottom)), -((farplane + nearplane) / (farplane - nearplane)), 1
        };
 -1
Author: suraj kumar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-11 09:55:37