I am trying to learn how to do some transformations on 3d points in OpenGL. Using this cheat sheet I believe that I have the correct matrix to multiply to my vector which I want to rotate. However, when I multiply and print the new coord, I believe that it is incorrect. (Rotating 1,0,0 90deg cc should result in 0,1,0 correct?) Why is this not working?
My code:
glm::vec4 vec(1.0f, 0.0f, 0.0f, 1.0f);
glm::mat4 trans = {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, cos(glm::radians(90.0f)), -sin(glm::radians(90.0f)), 0.0f,
0.0f, sin(glm::radians(90.0f)), cos(glm::radians(90.0f)), 0,
0.0f, 0.0f, 0.0f, 1.0f
};
vec = trans * vec; //I should get 0.0, 1.0, 0.0 right?
std::cout << vec.x << ", " << vec.y << ", " << vec.z << std::endl;
The above prints 1.0, 0.0, 0.0
indicating that there was no change at all?
I also tried using the rotate
function in GLM to generate my matrix rather then manually specifying but I still did not get what I think should be correct (I got a different wrong answer).
glm::mat4 trans = glm::rotate(trans, 90.0f, glm::vec3(0.0, 0.0, 1.0)); //EDIT: my bad, should've been z axis not x, still not working
The above prints: -2.14..e+08, -2.14..e+08, -2.14..e+08
(PS: I just took Geometry in the previous school year, my apologies if the math is incorrect. I have a basic understanding of matrices and matrix multiplication that I picked up today to learn OpenGL transformations but other then that I'm sort of a noob at this)
glm::mat4 trans = glm::rotate(trans, 90.0f, glm::vec3(0.0, 0.0, 1.0));
- Ashwin Gupta