[Bf-blender-cvs] [51af7510fba] soc-2019-openxr: Cleanup: Avoid duplication of projection matrix calculation

Julian Eisel noreply at git.blender.org
Tue Oct 15 22:11:15 CEST 2019


Commit: 51af7510fba6c05a7c9e4333ab80a6828f70dcda
Author: Julian Eisel
Date:   Tue Oct 15 22:09:27 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rB51af7510fba6c05a7c9e4333ab80a6828f70dcda

Cleanup: Avoid duplication of projection matrix calculation

===================================================================

M	source/blender/blenlib/intern/math_geom.c

===================================================================

diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 285ec610920..2c72db4ec8d 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -4665,21 +4665,13 @@ void perspective_m4_fov(float mat[4][4],
 {
   const float tan_angle_left = tanf(angle_left);
   const float tan_angle_right = tanf(angle_right);
-  const float tan_angle_up = tanf(angle_up);
-  const float tan_angle_down = tanf(angle_down);
-  const float Xdelta = tan_angle_right - tan_angle_left;
-  const float Ydelta = tan_angle_up - tan_angle_down;
-
-  mat[0][0] = 2 / Xdelta;
-  mat[1][1] = 2 / Ydelta;
-  mat[2][0] = (tan_angle_right + tan_angle_left) / Xdelta;
-  mat[2][1] = (tan_angle_up + tan_angle_down) / Ydelta;
-  mat[2][2] = -(farClip + nearClip) / (farClip - nearClip);
-  mat[2][3] = -1;
-  mat[3][2] = -(farClip * (nearClip + nearClip)) / (farClip - nearClip);
+  const float tan_angle_bottom = tanf(angle_up);
+  const float tan_angle_top = tanf(angle_down);
 
-  mat[0][1] = mat[0][2] = mat[0][3] = mat[1][0] = mat[1][2] = mat[1][3] = mat[3][0] = mat[3][1] =
-      mat[3][3] = 0.0f;
+  perspective_m4(
+      mat, tan_angle_left, tan_angle_right, tan_angle_top, tan_angle_bottom, nearClip, farClip);
+  mat[0][0] /= nearClip;
+  mat[1][1] /= nearClip;
 }
 
 /* translate a matrix created by orthographic_m4 or perspective_m4 in XY coords



More information about the Bf-blender-cvs mailing list