diff options
author | mano-wii <germano.costa@ig.com.br> | 2019-03-22 04:20:13 +0300 |
---|---|---|
committer | mano-wii <germano.costa@ig.com.br> | 2019-03-22 04:23:49 +0300 |
commit | 2b42b8b779cd29dd1d4531103cee6aa69643ac7b (patch) | |
tree | 15c01d0e72f1c2668d0ded4436e8dcd802913e7a /source/blender/blenlib/intern/math_geom.c | |
parent | 1ae6aaad43ad1e021b2e8d8298bb389a4271d185 (diff) |
BLI Math: Add and use new `projmat_dimensions` utility.
Diffstat (limited to 'source/blender/blenlib/intern/math_geom.c')
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index a513aca8e46..619a73f712f 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -4152,6 +4152,32 @@ void planes_from_projmat(float mat[4][4], float left[4], float right[4], float t } } +void projmat_dimensions(const float projmat[4][4], + float *r_left, float *r_right, + float *r_bottom, float *r_top, + float *r_near, float *r_far) +{ + bool is_persp = projmat[3][3] == 0.0f; + + if (is_persp) { + *r_left = (projmat[2][0] - 1.0f) / projmat[0][0]; + *r_right = (projmat[2][0] + 1.0f) / projmat[0][0]; + *r_bottom = (projmat[2][1] - 1.0f) / projmat[1][1]; + *r_top = (projmat[2][1] + 1.0f) / projmat[1][1]; + *r_near = projmat[3][2] / (projmat[2][2] - 1.0f); + *r_far = projmat[3][2] / (projmat[2][2] + 1.0f); + } + else { + *r_left = (-projmat[3][0] - 1.0f) / projmat[0][0]; + *r_right = (-projmat[3][0] + 1.0f) / projmat[0][0]; + *r_bottom = (-projmat[3][1] - 1.0f) / projmat[1][1]; + *r_top = (-projmat[3][1] + 1.0f) / projmat[1][1]; + *r_near = ( projmat[3][2] + 1.0f) / projmat[2][2]; + *r_far = ( projmat[3][2] - 1.0f) / projmat[2][2]; + } + +} + static void i_multmatrix(float icand[4][4], float Vm[4][4]) { int row, col; |