c++ - glm translate matrix does not translate the vector -
i have crossed simple error while started using glm (in vs2010). have got short code:
glm::mat4 translate = glm::translate(glm::mat4(1.f), glm::vec3(2.f, 0.f, 0.f)); glm::vec4 vector(1.f,1.f,1.f,0.f); glm::vec4 transformedvector = translate * vector;
the result of transformedvector same original value (1.f, 1.f, 1.f, 0.f). not know missing here. have tried rotation matrix , working fine, point transformated correctly.
glm::mat4 rotate = glm::rotate(glm::mat4(1.f), 90.f, glm::vec3(0.f, 0.f, 1.f)); glm::vec4 vector(1.f, 1.f, 1.f, 0.f); glm::vec4 transformedvector = rotate * vector;
ok, have found out problem. translate vertex not vector, in case had set w value 1.
you're forgetting projective coordinates. last component of
glm::vec4 vector
should 1. correction doing this:
glm::mat4 translate = glm::translate(glm::mat4(1.f), glm::vec3(2.f, 0.f, 0.f)); glm::vec4 vector(1.f,1.f,1.f,1.f); glm::vec4 transformedvector = translate * vector;
this due way projective coordinates work, projective coordinates (vec4) normal coordinates (vec3) divide w component. (which can't if it's zero.)
the reason works rotations not translations because in projective space rotations "the same" in normal space, translations different.
i've noticed worked out error thought explanation may help.
Comments
Post a Comment