Created
May 24, 2015 11:31
-
-
Save Kerollmops/62b835662dedad5ca267 to your computer and use it in GitHub Desktop.
view matrices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t_mat4 classic_mat4_pers_proj(float width, float height) | |
{ | |
float aspect; | |
float znear; | |
float zfar; | |
aspect = width / height; | |
znear = 0.1f; | |
zfar = 1000.f; | |
return (mat4_pers_proj(60.f, aspect, znear, zfar)); | |
} | |
t_mat4 mat4_pers_proj(float fov, float ar, float near, float far) | |
{ | |
t_mat4 mat; | |
float xymax; | |
float width; | |
float height; | |
float depth; | |
xymax = near * tan(fov * M_PI / 360); | |
width = xymax + xymax; | |
height = xymax + xymax; | |
depth = far - near; | |
ft_bzero(mat.m, sizeof(mat.m)); | |
mat.m[0] = (2.f * near / width) / ar; | |
mat.m[5] = 2.f * near / height; | |
mat.m[10] = -(far + near) / depth; | |
mat.m[11] = -1.f; | |
mat.m[14] = -2.f * (far * near) / depth; | |
return (mat); | |
} | |
t_mat4 mat4_view_lookat(t_vec3 eye, t_vec3 targ, t_vec3 up) | |
{ | |
t_mat4 out; | |
t_vec3 zaxis; | |
t_vec3 xaxis; | |
t_vec3 yaxis; | |
zaxis = vec3_normal(vec3_sub(eye, targ)); | |
xaxis = vec3_normal(vec3_cross(up, zaxis)); | |
yaxis = vec3_cross(zaxis, xaxis); | |
out = mat4_ident(); | |
out.m[0] = xaxis.x; | |
out.m[1] = yaxis.x; | |
out.m[2] = zaxis.x; | |
out.m[4] = xaxis.y; | |
out.m[5] = yaxis.y; | |
out.m[6] = zaxis.y; | |
out.m[8] = xaxis.z; | |
out.m[9] = yaxis.z; | |
out.m[10] = zaxis.z; | |
out.m[12] = -vec3_dot(xaxis, eye); | |
out.m[13] = -vec3_dot(yaxis, eye); | |
out.m[14] = -vec3_dot(zaxis, eye); | |
return (out); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment