Fixed projection matrix and made translation column-major
This commit is contained in:
parent
b4235873b5
commit
6d7f2ba701
|
@ -109,9 +109,9 @@ rr_vec4f_s rr_mat4f_multiply_vec4f(rr_mat4f_s matrix, rr_vec4f_s vector)
|
|||
|
||||
void rr_mat4f_translate(rr_mat4f_s *matrix, rr_vec3f_s xyz)
|
||||
{
|
||||
matrix->values[0][3] = xyz.x;
|
||||
matrix->values[1][3] = xyz.y;
|
||||
matrix->values[2][3] = xyz.z;
|
||||
matrix->values[3][0] = xyz.x;
|
||||
matrix->values[3][1] = xyz.y;
|
||||
matrix->values[3][2] = xyz.z;
|
||||
}
|
||||
|
||||
rr_mat4f_s rr_mat4f_rotate_x(float radians)
|
||||
|
@ -166,31 +166,29 @@ rr_mat4f_s rr_mat4f_rotate_xyz(float x_rad, float y_rad, float z_rad)
|
|||
|
||||
rr_mat4f_s rr_mat4f_perspective(float fov, float near_plane, float far_plane, float aspect_ratio)
|
||||
{
|
||||
float plane_range = far_plane - near_plane;
|
||||
float scale_x = (2 * near_plane) / (plane_range * aspect_ratio * 2);
|
||||
float scale_y = near_plane / plane_range;
|
||||
float scale_z = -(far_plane + near_plane) / (far_plane - near_plane);
|
||||
float pos_z = tanf(fov / 2) * near_plane;
|
||||
float a = tanf(fov / 2.0f) * near_plane;
|
||||
float planes_sum = far_plane + near_plane;
|
||||
float planes_range = far_plane - near_plane;
|
||||
|
||||
rr_mat4f_s matrix;
|
||||
matrix.values[0][0] = scale_x;
|
||||
matrix.values[0][0] = 1 / aspect_ratio;
|
||||
matrix.values[0][1] = 0.0f;
|
||||
matrix.values[0][2] = 0.0f;
|
||||
matrix.values[0][3] = 0.0f;
|
||||
|
||||
matrix.values[1][0] = 0.0f;
|
||||
matrix.values[1][1] = scale_y;
|
||||
matrix.values[1][1] = aspect_ratio;
|
||||
matrix.values[1][2] = 0.0f;
|
||||
matrix.values[1][3] = 0.0f;
|
||||
|
||||
matrix.values[2][0] = 0.0f;
|
||||
matrix.values[2][1] = 0.0f;
|
||||
matrix.values[2][2] = scale_z;
|
||||
matrix.values[2][2] = -(planes_sum / planes_range);
|
||||
matrix.values[2][3] = -1.0f;
|
||||
|
||||
matrix.values[3][0] = 0.0f;
|
||||
matrix.values[3][1] = 0.0f;
|
||||
matrix.values[3][2] = pos_z;
|
||||
matrix.values[3][2] = -(2 * planes_sum / planes_range);
|
||||
matrix.values[3][3] = 0.0f;
|
||||
|
||||
return matrix;
|
||||
|
|
Loading…
Reference in New Issue