Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_project.c
| Show All 32 Lines | |||||
| #include "BKE_camera.h" | #include "BKE_camera.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "GPU_matrix.h" | #include "GPU_matrix.h" | ||||
| #include "ED_view3d.h" /* own include */ | #include "ED_view3d.h" /* own include */ | ||||
| #define BL_NEAR_CLIP 0.001 | |||||
| #define BL_ZERO_CLIP 0.001 | #define BL_ZERO_CLIP 0.001 | ||||
| /* Non Clipping Projection Functions | /* Non Clipping Projection Functions | ||||
| * ********************************* */ | * ********************************* */ | ||||
| /** | /** | ||||
| * \note use #ED_view3d_ob_project_mat_get to get the projection matrix | * \note use #ED_view3d_ob_project_mat_get to get the projection matrix | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | if (rv3d->rflag & RV3D_CLIPPING) { | ||||
| return V3D_PROJ_RET_CLIP_BB; | return V3D_PROJ_RET_CLIP_BB; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| copy_v3_v3(vec4, co); | copy_v3_v3(vec4, co); | ||||
| vec4[3] = 1.0; | vec4[3] = 1.0; | ||||
| mul_m4_v4(perspmat, vec4); | mul_m4_v4(perspmat, vec4); | ||||
| const float w = fabsf(vec4[3]); | |||||
| if (((flag & V3D_PROJ_TEST_CLIP_ZERO) == 0) || (fabsf(vec4[3]) > (float)BL_ZERO_CLIP)) { | if ((flag & V3D_PROJ_TEST_CLIP_ZERO) && (w <= (float)BL_ZERO_CLIP)) { | ||||
| if (((flag & V3D_PROJ_TEST_CLIP_NEAR) == 0) || (vec4[3] > (float)BL_NEAR_CLIP)) { | return V3D_PROJ_RET_CLIP_ZERO; | ||||
| const float scalar = (vec4[3] != 0.0f) ? (1.0f / vec4[3]) : 0.0f; | |||||
| const float fx = ((float)region->winx / 2.0f) * (1.0f + (vec4[0] * scalar)); | |||||
| if (((flag & V3D_PROJ_TEST_CLIP_WIN) == 0) || (fx > 0.0f && fx < (float)region->winx)) { | |||||
| const float fy = ((float)region->winy / 2.0f) * (1.0f + (vec4[1] * scalar)); | |||||
| if (((flag & V3D_PROJ_TEST_CLIP_WIN) == 0) || (fy > 0.0f && fy < (float)region->winy)) { | |||||
| r_co[0] = fx; | |||||
| r_co[1] = fy; | |||||
| /* check if the point is behind the view, we need to flip in this case */ | |||||
| if (UNLIKELY((flag & V3D_PROJ_TEST_CLIP_NEAR) == 0) && (vec4[3] < 0.0f)) { | |||||
| negate_v2(r_co); | |||||
| } | |||||
| } | |||||
| else { | |||||
| return V3D_PROJ_RET_CLIP_WIN; | |||||
| } | |||||
| } | |||||
| else { | |||||
| return V3D_PROJ_RET_CLIP_WIN; | |||||
| } | |||||
| } | } | ||||
| else { | |||||
| if ((flag & V3D_PROJ_TEST_CLIP_NEAR) && (vec4[2] <= -w)) { | |||||
| return V3D_PROJ_RET_CLIP_NEAR; | return V3D_PROJ_RET_CLIP_NEAR; | ||||
| } | } | ||||
| if ((flag & V3D_PROJ_TEST_CLIP_FAR) && (vec4[2] >= w)) { | |||||
| return V3D_PROJ_RET_CLIP_FAR; | |||||
| } | } | ||||
| else { | |||||
| return V3D_PROJ_RET_CLIP_ZERO; | const float scalar = (w != 0.0f) ? (1.0f / w) : 0.0f; | ||||
| const float fx = ((float)region->winx / 2.0f) * (1.0f + (vec4[0] * scalar)); | |||||
| const float fy = ((float)region->winy / 2.0f) * (1.0f + (vec4[1] * scalar)); | |||||
| if ((flag & V3D_PROJ_TEST_CLIP_WIN) && | |||||
| (fx <= 0.0f || fy <= 0.0f || fx >= (float)region->winx || fy >= (float)region->winy)) { | |||||
| return V3D_PROJ_RET_CLIP_WIN; | |||||
| } | } | ||||
| r_co[0] = fx; | |||||
| r_co[1] = fy; | |||||
| return V3D_PROJ_RET_OK; | return V3D_PROJ_RET_OK; | ||||
| } | } | ||||
| eV3DProjStatus ED_view3d_project_short_ex(const ARegion *region, | eV3DProjStatus ED_view3d_project_short_ex(const ARegion *region, | ||||
| float perspmat[4][4], | float perspmat[4][4], | ||||
| const bool is_local, | const bool is_local, | ||||
| const float co[3], | const float co[3], | ||||
| short r_co[2], | short r_co[2], | ||||
| ▲ Show 20 Lines • Show All 657 Lines • Show Last 20 Lines | |||||