Paltoquet
Paltoquet

Reputation: 1234

Simplest way to convert mat3 to mat4

I have extracted the upper left 3x3 rotation matrice of a mat4:

glm::mat4 model;  
glm::mat3 rot = glm::mat3(model);

Now I want the identity matrix with the upper left being my new mat3

enter image description here

What is the simplest way of doing so?

glm::mat4 result;
result[0] = glm::vec4(rot[0], 0);
result[1] = glm::vec4(rot[1], 0);
result[2] = glm::vec4(rot[2], 0);
result[3] = glm::vec4(0, 0, 0, 1);

Is there a better way?

Upvotes: 6

Views: 9609

Answers (1)

philectron
philectron

Reputation: 123

Try if this works for you:

glm::mat4 result = glm::mat4(rot);

Upvotes: 9

Related Questions