I am working with this C# library that wraps OpenGL. I am trying to understand why my objects in the scene are rotating as I yaw my camera (view matrix).
Here is an image where I have 4 separate cubes in a row with no spacing.
If I yaw my camera you can see that the cubes have also rotated. Notice the red arrows which point to the side of a cube that is now visible:
I was expecting that these cubes would not rotate. It looked to me as if something in my code is wrong for their model matrix, but I'm not sure I understand what is happening.
Every render frame I am doing this for each cube:
shader["model_matrix"].SetValue(ModelMatrix);
ModelMatrix
is calculated as follows, once:
this.ModelMatrix = Matrix4.CreateTranslation(new Vector3(worldX * size, worldY * size, worldZ * size));
world
variables are offsets for the position of the cube, and size is just the length. Each render frame my view matrix is being set:
shader["view_matrix"].SetValue(camera.ViewMatrix);
Here is the vertex shader:
uniform mat4 projection_matrix;
uniform mat4 model_matrix;
uniform mat4 view_matrix;
attribute vec3 in_position;
attribute vec3 in_normal;
varying vec3 vertex_light_position;
varying vec3 vertex_normal;
void main(void)
{
vertex_normal = in_normal;
vertex_light_position = normalize(vec3(1, 1, 0));
gl_Position = projection_matrix * model_matrix * view_matrix * vec4(in_position, 1);
}
I have been basing this extended example off of the tutorial here. I am probably missing something basic (I am just starting OpenGL), so thanks for any help in advance!