I am having an issue with my rotations in my opengl shaders. My program works fine before I add in my rotation matrices. Here is an example, at YouTube. After I add rotations to my shaders, there are issues. Here is an example.
Here is my vertex shader:
#version 130
in vec3 position;
in vec4 color;
in vec2 texcoord;
uniform mat4 view_array;
uniform mat4 end_array;
uniform mat4 projection_matrix;
uniform mat4 trans_matrix;
uniform mat4 x_rotation_matrix;
uniform mat4 y_rotation_matrix;
uniform mat4 z_rotation_matrix;
out vec4 pos;
out vec2 texture_coordinate;
//out vec4 color_value;
void main()
{
mat4 vw_matrix = mat4(1.0);
mat4 rotation_matrix = x_rotation_matrix * y_rotation_matrix;
mat4 model_matrix = trans_matrix * rotation_matrix;//
pos = projection_matrix * vw_matrix * model_matrix * vec4(position, 1.0);
gl_Position = pos;
texture_coordinate = texcoord;
//color_value = color
}
Here are the values for my matrices:
// rotation matrices
x_rotation_matrix[0] = 1;
x_rotation_matrix[1] = 0;
x_rotation_matrix[2] = 0;
x_rotation_matrix[3] = 0;
x_rotation_matrix[4] = (float) cos(-yaw * (PI / 180));
x_rotation_matrix[5] = (float) -sin(-yaw * (PI / 180));
x_rotation_matrix[6] = 0;
x_rotation_matrix[7] = (float) sin(-yaw * (PI / 180));
x_rotation_matrix[8] = (float) cos(-yaw * (PI / 180));
x_rotation_matrix[9] = 0;
x_rotation_matrix[10] = 1;
x_rotation_matrix[11] = 0;
x_rotation_matrix[12] = 0;
x_rotation_matrix[13] = 0;
x_rotation_matrix[14] = 0;
x_rotation_matrix[15] = 1;
y_rotation_matrix[0] = (float) cos(-pitch * (PI / 180));
y_rotation_matrix[1] = 0;
y_rotation_matrix[2] = (float) sin(-pitch * (PI / 180));
y_rotation_matrix[3] = 0;
y_rotation_matrix[4] = 0;
y_rotation_matrix[5] = 1;
y_rotation_matrix[6] = (float) -sin(-pitch * (PI / 180));
y_rotation_matrix[7] = 0;
y_rotation_matrix[8] = (float) cos(-pitch * (PI / 180));
y_rotation_matrix[9] = 0;
y_rotation_matrix[10] = 1;
y_rotation_matrix[11] = 0;
y_rotation_matrix[12] = 0;
y_rotation_matrix[13] = 0;
y_rotation_matrix[14] = 0;
y_rotation_matrix[15] = 1;
z_rotation_matrix[0] = (float) cos(-pitch * (PI / 180));
z_rotation_matrix[1] = (float) -sin(-pitch * (PI / 180));
z_rotation_matrix[2] = 0;
z_rotation_matrix[3] = (float) sin(-pitch * (PI / 180));
z_rotation_matrix[4] = (float) cos(-pitch * (PI / 180));
z_rotation_matrix[5] = 1;
z_rotation_matrix[6] = 0;
z_rotation_matrix[7] = 0;
z_rotation_matrix[8] = 0;
z_rotation_matrix[9] = 0;
z_rotation_matrix[10] = 1;
z_rotation_matrix[11] = 0;
z_rotation_matrix[12] = 0;
z_rotation_matrix[13] = 0;
z_rotation_matrix[14] = 0;
z_rotation_matrix[15] = 1;
GL20.glUniformMatrix4fv(
GL20.glGetUniformLocation(programID, "x_rotation_matrix"), true, x_rotation_matrix);
GL20.glUniformMatrix4fv(
GL20.glGetUniformLocation(programID, "y_rotation_matrix"), true, y_rotation_matrix);
GL20.glUniformMatrix4fv(
GL20.glGetUniformLocation(programID, "z_rotation_matrix"), true, z_rotation_matrix);
Here is my transformation matrix:
trans_matrix[0] = 1;
trans_matrix[5] = 1;
trans_matrix[10] = 1;
trans_matrix[12] = x;
trans_matrix[13] = y;
trans_matrix[14] = z;
trans_matrix[15] = 1;
What am I doing wrong?