I have a piece of code that takes a normal and a position and then creates a matrix. The matrix should orient values in the direction of the normal and offset everything in a certain direction. using namespace glm;
//Initialize a base translation matrix:
mat4 matrix = translate(mat4(),vec3(pos.x,pos.y,pos.z));
vec3 normal = vec3(inputnormal.x,inputnormal.y,inputnormal.z);
const vec3 upvector = vec3(0.0,0.0,1.0);
//Rotate around normal axis a bit (input by artists)
//matrix = rotate(matrix,radians(degrees),normal);
//Build orientation matrix from normal + upvector:
vec3 tangent = normalize(cross( normal, upvector ));
vec3 binormal = normalize(cross(normal, tangent));
mat3 orient = mat3(tangent, binormal, normal);
//Multiply by the orientation matrix
matrix *= mat4(orient);
The orientation works, the top of the box is correctly pointed in the direction of the normal. But the box rotates around the normal axis for a lot of normals. (even with rad being 0.0)
Here is a video of the problem: the decal in the level editor point into the normal direct, but also rotates along normal axis.
EDIT: Added video and new calculation... https://www.youtube.com/watch?v=Yeq9Fn4f9Gs
So my question is: how do i prevent rotation around the normal axis, OR how do i find the proper angle to undo said rotation in my matrix. (So, Given matrix and arbitrary axis, how do i find angle?)