[Bf-blender-cvs] [5005210f407] master: GPU: Add a matrix unproject function that takes an inverted matrix
Campbell Barton
noreply at git.blender.org
Wed May 15 08:34:21 CEST 2019
Commit: 5005210f407b8f3426c0137a70443b2e53a02be1
Author: Campbell Barton
Date: Wed May 15 14:16:35 2019 +1000
Branches: master
https://developer.blender.org/rB5005210f407b8f3426c0137a70443b2e53a02be1
GPU: Add a matrix unproject function that takes an inverted matrix
This is normally already calculated so add a version that takes the
inverted matrix.
===================================================================
M source/blender/gpu/GPU_matrix.h
M source/blender/gpu/intern/gpu_matrix.c
===================================================================
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h
index 67fb2bb2bd4..6f7d25dafa7 100644
--- a/source/blender/gpu/GPU_matrix.h
+++ b/source/blender/gpu/GPU_matrix.h
@@ -106,6 +106,11 @@ bool GPU_matrix_unproject(const float win[3],
const float proj[4][4],
const int view[4],
float world[3]);
+void GPU_matrix_unproject_model_inverted(const float win[3],
+ const float model_inverted[4][4],
+ const float proj[4][4],
+ const int view[4],
+ float world[3]);
/* 2D Projection Matrix */
diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c
index 5d65861c1e2..cc89da19705 100644
--- a/source/blender/gpu/intern/gpu_matrix.c
+++ b/source/blender/gpu/intern/gpu_matrix.c
@@ -502,19 +502,13 @@ static void gpu_mul_invert_projmat_m4_unmapped_v3(const float projmat[4][4], flo
co[2] *= -1;
}
-bool GPU_matrix_unproject(const float win[3],
- const float model[4][4],
- const float proj[4][4],
- const int view[4],
- float world[3])
+void GPU_matrix_unproject_model_inverted(const float win[3],
+ const float model_inverted[4][4],
+ const float proj[4][4],
+ const int view[4],
+ float world[3])
{
float in[3];
- float viewinv[4][4];
-
- if (!invert_m4_m4(viewinv, model)) {
- zero_v3(world);
- return false;
- }
copy_v3_v3(in, win);
@@ -523,8 +517,22 @@ bool GPU_matrix_unproject(const float win[3],
in[1] = (in[1] - view[1]) / view[3];
gpu_mul_invert_projmat_m4_unmapped_v3(proj, in);
- mul_v3_m4v3(world, viewinv, in);
+ mul_v3_m4v3(world, model_inverted, in);
+}
+bool GPU_matrix_unproject(const float win[3],
+ const float model[4][4],
+ const float proj[4][4],
+ const int view[4],
+ float world[3])
+{
+ float model_inverted[4][4];
+
+ if (!invert_m4_m4(model_inverted, model)) {
+ zero_v3(world);
+ return false;
+ }
+ GPU_matrix_unproject_model_inverted(win, model_inverted, proj, view, world);
return true;
}
More information about the Bf-blender-cvs
mailing list