code in OpenGL using GLM
im trying to rotate a direction vector (look) by either 90 degrees or 180 degrees expecting a unit vector pointing at the axis.
here is a sample.
A look vector pointing at positive Z axis, rotated in Y axis by 180 degrees should be pointing at -Z axis now, but result is {x=-6.18172393e-08 y=0.000000000 z=-0.707106769 ...} instead of (0,0,-1).
glm::vec3 look = glm::vec3(0, 0, 1);
glm::mat4 matRotY = glm::mat4(1.0f);
matRotY = glm::rotate(matRotY, glm::radians(180.0f), glm::vec3(0.0f, 1.0f, 0.0f));
glm::vec4 transformdLook = glm::normalize(matRotY * glm::vec4(look, 1.0f));
glm::vec3 newlook = glm::vec3(transformdLook.x, transformdLook.y, transformdLook.z);
tried the same thing with 90 degrees and the result is newlook = {x=0.707106769 y=0.000000000 z=-3.09086197e-08 ...} instead of (1,0,0).
Why is this? Im using a look vector to calculate angle to rotate my character on a new direction.
but since the resulting direction vector is not nearly 1, it returns a wrong angle.
In bellow code, target is the new target position to go,
glm::vec3 dir_vec_world = targ - curr;
glm::vec3 dir1 = newlook; // the look computed above
glm::vec3 dir2 = glm::normalize(dir_vec_world);
float dot = glm::dot(dir1, dir2);
float angle = glm::acos(dot);
at this iteration for example. current position is at 0,0,0 and target is moving to 0,0,-10).
the character is moving towards -z access, and look should be at (0,0-1) due to rotation above, therefore target direction vector should also be at (0,0,-1) giving a 0 angle. but since the returning vector after rotation is {x=0.707106769 y=0.000000000 z=-3.09086197e-08 ...} instead of (1,0,0) the angle returns at 45 degrees/0.785398 rad instead, which messes everything up as the character needs to rotate at 45 (along with its look) and the target direction vector is still at (0,0,-1) which rotation being applied every iteration.
do you guys have any suggestion for fixing this?