diff options
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_project.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_project.c | 212 |
1 files changed, 109 insertions, 103 deletions
diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c index 56c8b4bcbe9..10791bd1c9f 100644 --- a/source/blender/editors/space_view3d/view3d_project.c +++ b/source/blender/editors/space_view3d/view3d_project.c @@ -47,7 +47,7 @@ /** * \note use #ED_view3d_ob_project_mat_get to get the projection matrix */ -void ED_view3d_project_float_v2_m4(const ARegion *ar, +void ED_view3d_project_float_v2_m4(const ARegion *region, const float co[3], float r_co[2], float mat[4][4]) @@ -61,8 +61,8 @@ void ED_view3d_project_float_v2_m4(const ARegion *ar, mul_m4_v4(mat, vec4); if (vec4[3] > FLT_EPSILON) { - r_co[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3]; - r_co[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3]; + r_co[0] = (float)(region->winx / 2.0f) + (region->winx / 2.0f) * vec4[0] / vec4[3]; + r_co[1] = (float)(region->winy / 2.0f) + (region->winy / 2.0f) * vec4[1] / vec4[3]; } else { zero_v2(r_co); @@ -72,7 +72,7 @@ void ED_view3d_project_float_v2_m4(const ARegion *ar, /** * \note use #ED_view3d_ob_project_mat_get to get projecting mat */ -void ED_view3d_project_float_v3_m4(const ARegion *ar, +void ED_view3d_project_float_v3_m4(const ARegion *region, const float vec[3], float r_co[3], float mat[4][4]) @@ -86,8 +86,8 @@ void ED_view3d_project_float_v3_m4(const ARegion *ar, mul_m4_v4(mat, vec4); if (vec4[3] > FLT_EPSILON) { - r_co[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3]; - r_co[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3]; + r_co[0] = (float)(region->winx / 2.0f) + (region->winx / 2.0f) * vec4[0] / vec4[3]; + r_co[1] = (float)(region->winy / 2.0f) + (region->winy / 2.0f) * vec4[1] / vec4[3]; r_co[2] = vec4[2] / vec4[3]; } else { @@ -98,10 +98,10 @@ void ED_view3d_project_float_v3_m4(const ARegion *ar, /* Clipping Projection Functions * ***************************** */ -eV3DProjStatus ED_view3d_project_base(const struct ARegion *ar, struct Base *base) +eV3DProjStatus ED_view3d_project_base(const struct ARegion *region, struct Base *base) { eV3DProjStatus ret = ED_view3d_project_short_global( - ar, base->object->obmat[3], &base->sx, V3D_PROJ_TEST_CLIP_DEFAULT); + region, base->object->obmat[3], &base->sx, V3D_PROJ_TEST_CLIP_DEFAULT); if (ret != V3D_PROJ_RET_OK) { base->sx = IS_CLIPPED; @@ -115,7 +115,7 @@ eV3DProjStatus ED_view3d_project_base(const struct ARegion *ar, struct Base *bas * - 'rv3d->perspmat', is_local == false * - 'rv3d->persmatob', is_local == true */ -static eV3DProjStatus ed_view3d_project__internal(const ARegion *ar, +static eV3DProjStatus ed_view3d_project__internal(const ARegion *region, const float perspmat[4][4], const bool is_local, /* normally hidden */ const float co[3], @@ -128,7 +128,7 @@ static eV3DProjStatus ed_view3d_project__internal(const ARegion *ar, BLI_assert((flag & V3D_PROJ_TEST_ALL) == flag); if (flag & V3D_PROJ_TEST_CLIP_BB) { - RegionView3D *rv3d = ar->regiondata; + RegionView3D *rv3d = region->regiondata; if (rv3d->rflag & RV3D_CLIPPING) { if (ED_view3d_clipping_test(rv3d, co, is_local)) { return V3D_PROJ_RET_CLIP_BB; @@ -143,10 +143,10 @@ static eV3DProjStatus ed_view3d_project__internal(const ARegion *ar, if (((flag & V3D_PROJ_TEST_CLIP_ZERO) == 0) || (fabsf(vec4[3]) > (float)BL_ZERO_CLIP)) { if (((flag & V3D_PROJ_TEST_CLIP_NEAR) == 0) || (vec4[3] > (float)BL_NEAR_CLIP)) { const float scalar = (vec4[3] != 0.0f) ? (1.0f / vec4[3]) : 0.0f; - const float fx = ((float)ar->winx / 2.0f) * (1.0f + (vec4[0] * scalar)); - if (((flag & V3D_PROJ_TEST_CLIP_WIN) == 0) || (fx > 0.0f && fx < (float)ar->winx)) { - const float fy = ((float)ar->winy / 2.0f) * (1.0f + (vec4[1] * scalar)); - if (((flag & V3D_PROJ_TEST_CLIP_WIN) == 0) || (fy > 0.0f && fy < (float)ar->winy)) { + 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; @@ -174,7 +174,7 @@ static eV3DProjStatus ed_view3d_project__internal(const ARegion *ar, return V3D_PROJ_RET_OK; } -eV3DProjStatus ED_view3d_project_short_ex(const ARegion *ar, +eV3DProjStatus ED_view3d_project_short_ex(const ARegion *region, float perspmat[4][4], const bool is_local, const float co[3], @@ -182,7 +182,7 @@ eV3DProjStatus ED_view3d_project_short_ex(const ARegion *ar, const eV3DProjTest flag) { float tvec[2]; - eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag); + eV3DProjStatus ret = ed_view3d_project__internal(region, perspmat, is_local, co, tvec, flag); if (ret == V3D_PROJ_RET_OK) { if ((tvec[0] > -32700.0f && tvec[0] < 32700.0f) && (tvec[1] > -32700.0f && tvec[1] < 32700.0f)) { @@ -196,7 +196,7 @@ eV3DProjStatus ED_view3d_project_short_ex(const ARegion *ar, return ret; } -eV3DProjStatus ED_view3d_project_int_ex(const ARegion *ar, +eV3DProjStatus ED_view3d_project_int_ex(const ARegion *region, float perspmat[4][4], const bool is_local, const float co[3], @@ -204,7 +204,7 @@ eV3DProjStatus ED_view3d_project_int_ex(const ARegion *ar, const eV3DProjTest flag) { float tvec[2]; - eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag); + eV3DProjStatus ret = ed_view3d_project__internal(region, perspmat, is_local, co, tvec, flag); if (ret == V3D_PROJ_RET_OK) { if ((tvec[0] > -2140000000.0f && tvec[0] < 2140000000.0f) && (tvec[1] > -2140000000.0f && tvec[1] < 2140000000.0f)) { @@ -218,7 +218,7 @@ eV3DProjStatus ED_view3d_project_int_ex(const ARegion *ar, return ret; } -eV3DProjStatus ED_view3d_project_float_ex(const ARegion *ar, +eV3DProjStatus ED_view3d_project_float_ex(const ARegion *region, float perspmat[4][4], const bool is_local, const float co[3], @@ -226,7 +226,7 @@ eV3DProjStatus ED_view3d_project_float_ex(const ARegion *ar, const eV3DProjTest flag) { float tvec[2]; - eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag); + eV3DProjStatus ret = ed_view3d_project__internal(region, perspmat, is_local, co, tvec, flag); if (ret == V3D_PROJ_RET_OK) { if (isfinite(tvec[0]) && isfinite(tvec[1])) { copy_v2_v2(r_co, tvec); @@ -239,63 +239,63 @@ eV3DProjStatus ED_view3d_project_float_ex(const ARegion *ar, } /* --- short --- */ -eV3DProjStatus ED_view3d_project_short_global(const ARegion *ar, +eV3DProjStatus ED_view3d_project_short_global(const ARegion *region, const float co[3], short r_co[2], const eV3DProjTest flag) { - RegionView3D *rv3d = ar->regiondata; - return ED_view3d_project_short_ex(ar, rv3d->persmat, false, co, r_co, flag); + RegionView3D *rv3d = region->regiondata; + return ED_view3d_project_short_ex(region, rv3d->persmat, false, co, r_co, flag); } /* object space, use ED_view3d_init_mats_rv3d before calling */ -eV3DProjStatus ED_view3d_project_short_object(const ARegion *ar, +eV3DProjStatus ED_view3d_project_short_object(const ARegion *region, const float co[3], short r_co[2], const eV3DProjTest flag) { - RegionView3D *rv3d = ar->regiondata; + RegionView3D *rv3d = region->regiondata; ED_view3d_check_mats_rv3d(rv3d); - return ED_view3d_project_short_ex(ar, rv3d->persmatob, true, co, r_co, flag); + return ED_view3d_project_short_ex(region, rv3d->persmatob, true, co, r_co, flag); } /* --- int --- */ -eV3DProjStatus ED_view3d_project_int_global(const ARegion *ar, +eV3DProjStatus ED_view3d_project_int_global(const ARegion *region, const float co[3], int r_co[2], const eV3DProjTest flag) { - RegionView3D *rv3d = ar->regiondata; - return ED_view3d_project_int_ex(ar, rv3d->persmat, false, co, r_co, flag); + RegionView3D *rv3d = region->regiondata; + return ED_view3d_project_int_ex(region, rv3d->persmat, false, co, r_co, flag); } /* object space, use ED_view3d_init_mats_rv3d before calling */ -eV3DProjStatus ED_view3d_project_int_object(const ARegion *ar, +eV3DProjStatus ED_view3d_project_int_object(const ARegion *region, const float co[3], int r_co[2], const eV3DProjTest flag) { - RegionView3D *rv3d = ar->regiondata; + RegionView3D *rv3d = region->regiondata; ED_view3d_check_mats_rv3d(rv3d); - return ED_view3d_project_int_ex(ar, rv3d->persmatob, true, co, r_co, flag); + return ED_view3d_project_int_ex(region, rv3d->persmatob, true, co, r_co, flag); } /* --- float --- */ -eV3DProjStatus ED_view3d_project_float_global(const ARegion *ar, +eV3DProjStatus ED_view3d_project_float_global(const ARegion *region, const float co[3], float r_co[2], const eV3DProjTest flag) { - RegionView3D *rv3d = ar->regiondata; - return ED_view3d_project_float_ex(ar, rv3d->persmat, false, co, r_co, flag); + RegionView3D *rv3d = region->regiondata; + return ED_view3d_project_float_ex(region, rv3d->persmat, false, co, r_co, flag); } /* object space, use ED_view3d_init_mats_rv3d before calling */ -eV3DProjStatus ED_view3d_project_float_object(const ARegion *ar, +eV3DProjStatus ED_view3d_project_float_object(const ARegion *region, const float co[3], float r_co[2], const eV3DProjTest flag) { - RegionView3D *rv3d = ar->regiondata; + RegionView3D *rv3d = region->regiondata; ED_view3d_check_mats_rv3d(rv3d); - return ED_view3d_project_float_ex(ar, rv3d->persmatob, true, co, r_co, flag); + return ED_view3d_project_float_ex(region, rv3d->persmatob, true, co, r_co, flag); } /* More Generic Window/Ray/Vector projection functions @@ -338,7 +338,7 @@ float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_f } static void view3d_win_to_ray_segment(struct Depsgraph *depsgraph, - const ARegion *ar, + const ARegion *region, const View3D *v3d, const float mval[2], float r_ray_co[3], @@ -346,7 +346,7 @@ static void view3d_win_to_ray_segment(struct Depsgraph *depsgraph, float r_ray_start[3], float r_ray_end[3]) { - RegionView3D *rv3d = ar->regiondata; + RegionView3D *rv3d = region->regiondata; float _ray_co[3], _ray_dir[3], start_offset, end_offset; if (!r_ray_co) { @@ -356,8 +356,8 @@ static void view3d_win_to_ray_segment(struct Depsgraph *depsgraph, r_ray_dir = _ray_dir; } - ED_view3d_win_to_origin(ar, mval, r_ray_co); - ED_view3d_win_to_vector(ar, mval, r_ray_dir); + ED_view3d_win_to_origin(region, mval, r_ray_co); + ED_view3d_win_to_vector(region, mval, r_ray_dir); if ((rv3d->is_persp == false) && (rv3d->persp != RV3D_CAMOB)) { end_offset = v3d->clip_end / 2.0f; @@ -391,7 +391,7 @@ bool ED_view3d_clip_segment(const RegionView3D *rv3d, float ray_start[3], float * In orthographic view the resulting ray_normal will match the view vector. * This version also returns the ray_co point of the ray on window plane, useful to fix precision * issues esp. with ortho view, where default ray_start is set rather far away. - * \param ar: The region (used for the window width and height). + * \param region: The region (used for the window width and height). * \param v3d: The 3d viewport (used for near clipping value). * \param mval: The area relative 2d location (such as event->mval, converted into float[2]). * \param r_ray_co: The world-space point where the ray intersects the window plane. @@ -401,7 +401,7 @@ bool ED_view3d_clip_segment(const RegionView3D *rv3d, float ray_start[3], float * \return success, false if the ray is totally clipped. */ bool ED_view3d_win_to_ray_clipped_ex(struct Depsgraph *depsgraph, - const ARegion *ar, + const ARegion *region, const View3D *v3d, const float mval[2], float r_ray_co[3], @@ -412,11 +412,11 @@ bool ED_view3d_win_to_ray_clipped_ex(struct Depsgraph *depsgraph, float ray_end[3]; view3d_win_to_ray_segment( - depsgraph, ar, v3d, mval, r_ray_co, r_ray_normal, r_ray_start, ray_end); + depsgraph, region, v3d, mval, r_ray_co, r_ray_normal, r_ray_start, ray_end); /* bounds clipping */ if (do_clip_planes) { - return ED_view3d_clip_segment(ar->regiondata, r_ray_start, ray_end); + return ED_view3d_clip_segment(region->regiondata, r_ray_start, ray_end); } return true; @@ -427,7 +427,7 @@ bool ED_view3d_win_to_ray_clipped_ex(struct Depsgraph *depsgraph, * This ray_start is located at the viewpoint, ray_normal is the direction towards mval. * ray_start is clipped by the view near limit so points in front of it are always in view. * In orthographic view the resulting ray_normal will match the view vector. - * \param ar: The region (used for the window width and height). + * \param region: The region (used for the window width and height). * \param v3d: The 3d viewport (used for near clipping value). * \param mval: The area relative 2d location (such as event->mval, converted into float[2]). * \param r_ray_start: The world-space point where the ray intersects the window plane. @@ -436,7 +436,7 @@ bool ED_view3d_win_to_ray_clipped_ex(struct Depsgraph *depsgraph, * \return success, false if the ray is totally clipped. */ bool ED_view3d_win_to_ray_clipped(struct Depsgraph *depsgraph, - const ARegion *ar, + const ARegion *region, const View3D *v3d, const float mval[2], float r_ray_start[3], @@ -444,13 +444,13 @@ bool ED_view3d_win_to_ray_clipped(struct Depsgraph *depsgraph, const bool do_clip_planes) { return ED_view3d_win_to_ray_clipped_ex( - depsgraph, ar, v3d, mval, NULL, r_ray_normal, r_ray_start, do_clip_planes); + depsgraph, region, v3d, mval, NULL, r_ray_normal, r_ray_start, do_clip_planes); } /** * Calculate a 3d viewpoint and direction vector from 2d window coordinates. * This ray_start is located at the viewpoint, ray_normal is the direction towards mval. - * \param ar: The region (used for the window width and height). + * \param region: The region (used for the window width and height). * \param mval: The area relative 2d location (such as event->mval, converted into float[2]). * \param r_ray_start: The world-space point where the ray intersects the window plane. * \param r_ray_normal: The normalized world-space direction of towards mval. @@ -458,13 +458,13 @@ bool ED_view3d_win_to_ray_clipped(struct Depsgraph *depsgraph, * \note Ignores view near/far clipping, * to take this into account use #ED_view3d_win_to_ray_clipped. */ -void ED_view3d_win_to_ray(const ARegion *ar, +void ED_view3d_win_to_ray(const ARegion *region, const float mval[2], float r_ray_start[3], float r_ray_normal[3]) { - ED_view3d_win_to_origin(ar, mval, r_ray_start); - ED_view3d_win_to_vector(ar, mval, r_ray_normal); + ED_view3d_win_to_origin(region, mval, r_ray_start); + ED_view3d_win_to_vector(region, mval, r_ray_normal); } /** @@ -499,22 +499,22 @@ void ED_view3d_global_to_vector(const RegionView3D *rv3d, const float coord[3], /* very similar to ED_view3d_win_to_3d() but has no advantage, de-duplicating */ #if 0 -bool view3d_get_view_aligned_coordinate(ARegion *ar, +bool view3d_get_view_aligned_coordinate(ARegion *region, float fp[3], const int mval[2], const bool do_fallback) { - RegionView3D *rv3d = ar->regiondata; + RegionView3D *rv3d = region->regiondata; float dvec[3]; int mval_cpy[2]; eV3DProjStatus ret; - ret = ED_view3d_project_int_global(ar, fp, mval_cpy, V3D_PROJ_TEST_NOP); + ret = ED_view3d_project_int_global(region, fp, mval_cpy, V3D_PROJ_TEST_NOP); if (ret == V3D_PROJ_RET_OK) { const float mval_f[2] = {(float)(mval_cpy[0] - mval[0]), (float)(mval_cpy[1] - mval[1])}; const float zfac = ED_view3d_calc_zfac(rv3d, fp, NULL); - ED_view3d_win_to_delta(ar, mval_f, dvec, zfac); + ED_view3d_win_to_delta(region, mval_f, dvec, zfac); sub_v3_v3(fp, dvec); return true; @@ -523,7 +523,7 @@ bool view3d_get_view_aligned_coordinate(ARegion *ar, /* fallback to the view center */ if (do_fallback) { negate_v3_v3(fp, rv3d->ofs); - return view3d_get_view_aligned_coordinate(ar, fp, mval, false); + return view3d_get_view_aligned_coordinate(region, fp, mval, false); } else { return false; @@ -534,18 +534,18 @@ bool view3d_get_view_aligned_coordinate(ARegion *ar, /** * Calculate a 3d location from 2d window coordinates. - * \param ar: The region (used for the window width and height). + * \param region: The region (used for the window width and height). * \param depth_pt: The reference location used to calculate the Z depth. * \param mval: The area relative location (such as event->mval converted to floats). * \param r_out: The resulting world-space location. */ void ED_view3d_win_to_3d(const View3D *v3d, - const ARegion *ar, + const ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3]) { - RegionView3D *rv3d = ar->regiondata; + RegionView3D *rv3d = region->regiondata; float ray_origin[3]; float ray_direction[3]; @@ -555,7 +555,7 @@ void ED_view3d_win_to_3d(const View3D *v3d, float plane[4]; copy_v3_v3(ray_origin, rv3d->viewinv[3]); - ED_view3d_win_to_vector(ar, mval, ray_direction); + ED_view3d_win_to_vector(region, mval, ray_direction); /* note, we could use isect_line_plane_v3() * however we want the intersection to be infront of the view no matter what, @@ -566,16 +566,16 @@ void ED_view3d_win_to_3d(const View3D *v3d, lambda = fabsf(lambda); } else { - float dx = (2.0f * mval[0] / (float)ar->winx) - 1.0f; - float dy = (2.0f * mval[1] / (float)ar->winy) - 1.0f; + float dx = (2.0f * mval[0] / (float)region->winx) - 1.0f; + float dy = (2.0f * mval[1] / (float)region->winy) - 1.0f; if (rv3d->persp == RV3D_CAMOB) { /* ortho camera needs offset applied */ const Camera *cam = v3d->camera->data; - const int sensor_fit = BKE_camera_sensor_fit(cam->sensor_fit, ar->winx, ar->winy); + const int sensor_fit = BKE_camera_sensor_fit(cam->sensor_fit, region->winx, region->winy); const float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom) * 4.0f; - const float aspx = ar->winx / (float)ar->winy; - const float aspy = ar->winy / (float)ar->winx; + const float aspx = region->winx / (float)region->winy; + const float aspy = region->winy / (float)region->winx; const float shiftx = cam->shiftx * 0.5f * (sensor_fit == CAMERA_SENSOR_FIT_HOR ? 1.0f : aspy); const float shifty = cam->shifty * 0.5f * @@ -596,24 +596,24 @@ void ED_view3d_win_to_3d(const View3D *v3d, } void ED_view3d_win_to_3d_int(const View3D *v3d, - const ARegion *ar, + const ARegion *region, const float depth_pt[3], const int mval[2], float r_out[3]) { const float mval_fl[2] = {mval[0], mval[1]}; - ED_view3d_win_to_3d(v3d, ar, depth_pt, mval_fl, r_out); + ED_view3d_win_to_3d(v3d, region, depth_pt, mval_fl, r_out); } -bool ED_view3d_win_to_3d_on_plane(const ARegion *ar, +bool ED_view3d_win_to_3d_on_plane(const ARegion *region, const float plane[4], const float mval[2], const bool do_clip, float r_out[3]) { float ray_co[3], ray_no[3]; - ED_view3d_win_to_origin(ar, mval, ray_co); - ED_view3d_win_to_vector(ar, mval, ray_no); + ED_view3d_win_to_origin(region, mval, ray_co); + ED_view3d_win_to_vector(region, mval, ray_no); float lambda; if (isect_ray_plane_v3(ray_co, ray_no, plane, &lambda, do_clip)) { madd_v3_v3v3fl(r_out, ray_co, ray_no, lambda); @@ -622,28 +622,34 @@ bool ED_view3d_win_to_3d_on_plane(const ARegion *ar, return false; } -bool ED_view3d_win_to_3d_on_plane_int( - const ARegion *ar, const float plane[4], const int mval[2], const bool do_clip, float r_out[3]) +bool ED_view3d_win_to_3d_on_plane_int(const ARegion *region, + const float plane[4], + const int mval[2], + const bool do_clip, + float r_out[3]) { const float mval_fl[2] = {mval[0], mval[1]}; - return ED_view3d_win_to_3d_on_plane(ar, plane, mval_fl, do_clip, r_out); + return ED_view3d_win_to_3d_on_plane(region, plane, mval_fl, do_clip, r_out); } /** * Calculate a 3d difference vector from 2d window offset. * note that #ED_view3d_calc_zfac() must be called first to determine * the depth used to calculate the delta. - * \param ar: The region (used for the window width and height). + * \param region: The region (used for the window width and height). * \param mval: The area relative 2d difference (such as event->mval[0] - other_x). * \param out: The resulting world-space delta. */ -void ED_view3d_win_to_delta(const ARegion *ar, const float mval[2], float out[3], const float zfac) +void ED_view3d_win_to_delta(const ARegion *region, + const float mval[2], + float out[3], + const float zfac) { - RegionView3D *rv3d = ar->regiondata; + RegionView3D *rv3d = region->regiondata; float dx, dy; - dx = 2.0f * mval[0] * zfac / ar->winx; - dy = 2.0f * mval[1] * zfac / ar->winy; + dx = 2.0f * mval[0] * zfac / region->winx; + dy = 2.0f * mval[1] * zfac / region->winy; out[0] = (rv3d->persinv[0][0] * dx + rv3d->persinv[1][0] * dy); out[1] = (rv3d->persinv[0][1] * dx + rv3d->persinv[1][1] * dy); @@ -656,19 +662,19 @@ void ED_view3d_win_to_delta(const ARegion *ar, const float mval[2], float out[3] * Since far clip can be a very large value resulting in numeric precision issues, * the origin in this case is close to zero coordinate. * - * \param ar: The region (used for the window width and height). + * \param region: The region (used for the window width and height). * \param mval: The area relative 2d location (such as event->mval converted to floats). * \param out: The resulting normalized world-space direction vector. */ -void ED_view3d_win_to_origin(const ARegion *ar, const float mval[2], float out[3]) +void ED_view3d_win_to_origin(const ARegion *region, const float mval[2], float out[3]) { - RegionView3D *rv3d = ar->regiondata; + RegionView3D *rv3d = region->regiondata; if (rv3d->is_persp) { copy_v3_v3(out, rv3d->viewinv[3]); } else { - out[0] = 2.0f * mval[0] / ar->winx - 1.0f; - out[1] = 2.0f * mval[1] / ar->winy - 1.0f; + out[0] = 2.0f * mval[0] / region->winx - 1.0f; + out[1] = 2.0f * mval[1] / region->winy - 1.0f; if (rv3d->persp == RV3D_CAMOB) { out[2] = -1.0f; @@ -690,17 +696,17 @@ void ED_view3d_win_to_origin(const ARegion *ar, const float mval[2], float out[3 * for perspective view, get the vector direction to * the mouse cursor as a normalized vector. * - * \param ar: The region (used for the window width and height). + * \param region: The region (used for the window width and height). * \param mval: The area relative 2d location (such as event->mval converted to floats). * \param out: The resulting normalized world-space direction vector. */ -void ED_view3d_win_to_vector(const ARegion *ar, const float mval[2], float out[3]) +void ED_view3d_win_to_vector(const ARegion *region, const float mval[2], float out[3]) { - RegionView3D *rv3d = ar->regiondata; + RegionView3D *rv3d = region->regiondata; if (rv3d->is_persp) { - out[0] = 2.0f * (mval[0] / ar->winx) - 1.0f; - out[1] = 2.0f * (mval[1] / ar->winy) - 1.0f; + out[0] = 2.0f * (mval[0] / region->winx) - 1.0f; + out[1] = 2.0f * (mval[1] / region->winy) - 1.0f; out[2] = -0.5f; mul_project_m4_v3(rv3d->persinv, out); sub_v3_v3(out, rv3d->viewinv[3]); @@ -717,7 +723,7 @@ void ED_view3d_win_to_vector(const ARegion *ar, const float mval[2], float out[3 * ray_start and ray_end are clipped by the view near and far limits * so points along this line are always in view. * In orthographic view all resulting segments will be parallel. - * \param ar: The region (used for the window width and height). + * \param region: The region (used for the window width and height). * \param v3d: The 3d viewport (used for near and far clipping range). * \param mval: The area relative 2d location (such as event->mval, converted into float[2]). * \param r_ray_start: The world-space starting point of the segment. @@ -726,18 +732,18 @@ void ED_view3d_win_to_vector(const ARegion *ar, const float mval[2], float out[3 * \return success, false if the segment is totally clipped. */ bool ED_view3d_win_to_segment_clipped(struct Depsgraph *depsgraph, - const ARegion *ar, + const ARegion *region, View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_end[3], const bool do_clip_planes) { - view3d_win_to_ray_segment(depsgraph, ar, v3d, mval, NULL, NULL, r_ray_start, r_ray_end); + view3d_win_to_ray_segment(depsgraph, region, v3d, mval, NULL, NULL, r_ray_start, r_ray_end); /* bounds clipping */ if (do_clip_planes) { - return ED_view3d_clip_segment((RegionView3D *)ar->regiondata, r_ray_start, r_ray_end); + return ED_view3d_clip_segment((RegionView3D *)region->regiondata, r_ray_start, r_ray_end); } return true; @@ -767,21 +773,21 @@ void ED_view3d_ob_project_mat_get_from_obmat(const RegionView3D *rv3d, /** * Convert between region relative coordinates (x,y) and depth component z and * a point in world space. */ -void ED_view3d_project(const struct ARegion *ar, const float world[3], float region[3]) +void ED_view3d_project(const struct ARegion *region, const float world[3], float r_region_co[3]) { // viewport is set up to make coordinates relative to the region, not window - RegionView3D *rv3d = ar->regiondata; - int viewport[4] = {0, 0, ar->winx, ar->winy}; + RegionView3D *rv3d = region->regiondata; + int viewport[4] = {0, 0, region->winx, region->winy}; - GPU_matrix_project(world, rv3d->viewmat, rv3d->winmat, viewport, region); + GPU_matrix_project(world, rv3d->viewmat, rv3d->winmat, viewport, r_region_co); } bool ED_view3d_unproject( - const struct ARegion *ar, float regionx, float regiony, float regionz, float world[3]) + const struct ARegion *region, float regionx, float regiony, float regionz, float world[3]) { - RegionView3D *rv3d = ar->regiondata; - int viewport[4] = {0, 0, ar->winx, ar->winy}; - float region[3] = {regionx, regiony, regionz}; + RegionView3D *rv3d = region->regiondata; + int viewport[4] = {0, 0, region->winx, region->winy}; + float region_co[3] = {regionx, regiony, regionz}; - return GPU_matrix_unproject(region, rv3d->viewmat, rv3d->winmat, viewport, world); + return GPU_matrix_unproject(region_co, rv3d->viewmat, rv3d->winmat, viewport, world); } |