diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-02-25 23:58:23 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-02-26 02:16:46 +0300 |
commit | 2724fad582676d2c164b05fe6fccf7a15d88adba (patch) | |
tree | 350f10451c9220f258eb3c60f5b5270c6c3d0d1a /source/blender/gpu | |
parent | e9011100f75c22b3a9c9021fd49fb007efa03ed0 (diff) |
OpenGL: replace gluProject and gluUnProject, and simplify surrounding code.
Part of T49042.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_matrix.h | 16 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_matrix.c | 24 |
2 files changed, 18 insertions, 22 deletions
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h index 2bf52c954a0..1be75be1253 100644 --- a/source/blender/gpu/GPU_matrix.h +++ b/source/blender/gpu/GPU_matrix.h @@ -1,6 +1,3 @@ -#ifndef _GPU_MATRIX_H_ -#define _GPU_MATRIX_H_ - /* * ***** BEGIN GPL LICENSE BLOCK ***** * @@ -32,8 +29,11 @@ * \ingroup gpu */ +#ifndef _GPU_MATRIX_H_ +#define _GPU_MATRIX_H_ + +#include "BLI_sys_types.h" #include "GPU_glew.h" -#include <stdbool.h> #ifdef __cplusplus extern "C" { @@ -110,12 +110,10 @@ void gpuOrtho(float left, float right, float bottom, float top, float near, floa void gpuFrustum(float left, float right, float bottom, float top, float near, float far); void gpuPerspective(float fovy, float aspect, float near, float far); -/* pass vector through current transform (world --> screen) */ -void gpuProject(const float obj[3], const float model[4][4], const float proj[4][4], const GLint view[4], float win[3]); - -/* pass vector through inverse transform (world <-- screen) */ -bool gpuUnProject(const float win[3], const float model[4][4], const float proj[4][4], const GLint view[4], float obj[3]); +/* 3D Projection between Window and World Space */ +void gpuProject(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float win[3]); +bool gpuUnProject(const float win[3], const float model[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 a987e3ba1ce..c022301d6a9 100644 --- a/source/blender/gpu/intern/gpu_matrix.c +++ b/source/blender/gpu/intern/gpu_matrix.c @@ -487,19 +487,23 @@ void gpuLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, gpuTranslate3f(-eyeX, -eyeY, -eyeZ); } -void gpuProject(const float obj[3], const float model[4][4], const float proj[4][4], const GLint view[4], float win[3]) +void gpuProject(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float win[3]) { float v[4]; - mul_v4_m4v3(v, model, obj); + mul_v4_m4v3(v, model, world); mul_m4_v4(proj, v); + if (v[3] != 0.0f) { + mul_v3_fl(v, 1.0f / v[3]); + } + win[0] = view[0] + (view[2] * (v[0] + 1)) * 0.5f; win[1] = view[1] + (view[3] * (v[1] + 1)) * 0.5f; win[2] = (v[2] + 1) * 0.5f; } -bool gpuUnProject(const float win[3], const float model[4][4], const float proj[4][4], const GLint view[4], float obj[3]) +bool gpuUnProject(const float win[3], const float model[4][4], const float proj[4][4], const int view[4], float world[3]) { float pm[4][4]; float in[4]; @@ -508,6 +512,7 @@ bool gpuUnProject(const float win[3], const float model[4][4], const float proj[ mul_m4_m4m4(pm, proj, model); if (!invert_m4(pm)) { + zero_v3(world); return false; } @@ -528,19 +533,12 @@ bool gpuUnProject(const float win[3], const float model[4][4], const float proj[ mul_v4_m4v3(out, pm, in); if (out[3] == 0.0f) { + copy_v3_v3(world, out); return false; } - else { - out[0] /= out[3]; - out[1] /= out[3]; - out[2] /= out[3]; - obj[0] = out[0]; - obj[1] = out[1]; - obj[2] = out[2]; - - return true; - } + mul_v3_v3fl(world, out, 1.0f / out[3]); + return true; } const float *gpuGetModelViewMatrix3D(float m[4][4]) |