Skip to content

Commit

Permalink
Simplified perspective matrix calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmoran committed May 20, 2019
1 parent 31960dc commit c51522a
Show file tree
Hide file tree
Showing 57 changed files with 171 additions and 171 deletions.
6 changes: 3 additions & 3 deletions 03_vertex_buffer_objects/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 04_mats_and_vecs/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 05_virtual_camera/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 05_virtual_camera/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 06_vcam_with_quaternion/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 07_ray_picking/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 08_phong/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 08_phong/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 09_texture_mapping/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 09_texture_mapping/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 10_screen_capture/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 10_screen_capture/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 11_video_capture/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 11_video_capture/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 12_debugging_shaders/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 12_debugging_shaders/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 13_mesh_import/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 13_mesh_import/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 14_multi_tex/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 14_multi_tex/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 15_phongtextures/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 15_phongtextures/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 16_frag_reject/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 16_frag_reject/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 17_alpha_blending/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 17_alpha_blending/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 18_spotlights/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 18_spotlights/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
6 changes: 3 additions & 3 deletions 19_fog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ int main() {
float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians
float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio
// matrix components
float range = tan( fov * 0.5f ) * near;
float Sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float Sy = near / range;
float inverse_range = 1.0f / tan( fov * 0.5f );
float Sx = inverse_range / aspect;
float Sy = inverse_range;
float Sz = -( far + near ) / ( far - near );
float Pz = -( 2.0f * far * near ) / ( far - near );
GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f,
Expand Down
6 changes: 3 additions & 3 deletions 19_fog/maths_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ mat4 look_at( const vec3 &cam_pos, vec3 targ_pos, const vec3 &up ) {
// returns a perspective function mimicking the opengl projection style.
mat4 perspective( float fovy, float aspect, float near, float far ) {
float fov_rad = fovy * ONE_DEG_IN_RAD;
float range = tan( fov_rad / 2.0f ) * near;
float sx = ( 2.0f * near ) / ( range * aspect + range * aspect );
float sy = near / range;
float inverse_range = 1.0f / tan( fov_rad / 2.0f );
float sx = inverse_range / aspect;
float sy = inverse_range;
float sz = -( far + near ) / ( far - near );
float pz = -( 2.0f * far * near ) / ( far - near );
mat4 m = zero_mat4(); // make sure bottom-right corner is zero
Expand Down
Loading

0 comments on commit c51522a

Please sign in to comment.