-
-
Save harishletsgo/2df3c102a38ab9b2585d to your computer and use it in GitHub Desktop.
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
// Matrix building -- Check the bottom for the matrix calling function | |
void BuildPerspProjMat(float *m, float fov, float aspect, | |
float znear, float zfar) | |
{ | |
float ymax = znear * tan(fov * PI_OVER_360); | |
float ymin = -ymax; | |
float xmax = ymax * aspect; | |
float xmin = ymin * aspect; | |
float width = xymax - xmin; | |
float height = xymax - ymin; | |
float depth = zfar - znear; | |
float q = -(zfar + znear) / depth; | |
float qn = -2 * (zfar * znear) / depth; | |
float w = 2 * znear / width; | |
w = w / aspect; | |
float h = 2 * znear / height; | |
m[0] = w; | |
m[1] = 0; | |
m[2] = 0; | |
m[3] = 0; | |
m[4] = 0; | |
m[5] = h; | |
m[6] = 0; | |
m[7] = 0; | |
m[8] = 0; | |
m[9] = 0; | |
m[10] = q; | |
m[11] = -1; | |
m[12] = 0; | |
m[13] = 0; | |
m[14] = qn; | |
m[15] = 0; | |
} | |
//loader | |
{ | |
glUseProgram(shaderId); | |
glUniformMatrix4fv(glGetUniformLocation(shaderId, "u_proj_matrix"), | |
1, GL_FALSE, theProjectionMatrix); | |
RenderObject(); | |
glUseProgram(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment