Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_project.c
| Show First 20 Lines • Show All 298 Lines • ▼ Show 20 Lines | float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_flip) | ||||
| if (zfac < 0.0f) { | if (zfac < 0.0f) { | ||||
| zfac = -zfac; | zfac = -zfac; | ||||
| } | } | ||||
| return zfac; | return zfac; | ||||
| } | } | ||||
| static void view3d_win_to_ray_segment( | static void view3d_win_to_ray_segment( | ||||
| const struct Depsgraph *depsgraph, | |||||
| const ARegion *ar, const View3D *v3d, const float mval[2], | const ARegion *ar, const View3D *v3d, const float mval[2], | ||||
| float r_ray_co[3], float r_ray_dir[3], float r_ray_start[3], float r_ray_end[3]) | float r_ray_co[3], float r_ray_dir[3], float r_ray_start[3], float r_ray_end[3]) | ||||
| { | { | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| float _ray_co[3], _ray_dir[3], start_offset, end_offset; | float _ray_co[3], _ray_dir[3], start_offset, end_offset; | ||||
| if (!r_ray_co) r_ray_co = _ray_co; | if (!r_ray_co) r_ray_co = _ray_co; | ||||
| if (!r_ray_dir) r_ray_dir = _ray_dir; | if (!r_ray_dir) r_ray_dir = _ray_dir; | ||||
| ED_view3d_win_to_origin(ar, mval, r_ray_co); | ED_view3d_win_to_origin(ar, mval, r_ray_co); | ||||
| ED_view3d_win_to_vector(ar, mval, r_ray_dir); | ED_view3d_win_to_vector(ar, mval, r_ray_dir); | ||||
| if ((rv3d->is_persp == false) && (rv3d->persp != RV3D_CAMOB)) { | if ((rv3d->is_persp == false) && (rv3d->persp != RV3D_CAMOB)) { | ||||
| end_offset = v3d->far / 2.0f; | end_offset = v3d->far / 2.0f; | ||||
| start_offset = -end_offset; | start_offset = -end_offset; | ||||
| } | } | ||||
| else { | else { | ||||
| ED_view3d_clip_range_get(v3d, rv3d, &start_offset, &end_offset, false); | ED_view3d_clip_range_get(depsgraph, v3d, rv3d, &start_offset, &end_offset, false); | ||||
| } | } | ||||
| if (r_ray_start) { | if (r_ray_start) { | ||||
| madd_v3_v3v3fl(r_ray_start, r_ray_co, r_ray_dir, start_offset); | madd_v3_v3v3fl(r_ray_start, r_ray_co, r_ray_dir, start_offset); | ||||
| } | } | ||||
| if (r_ray_end) { | if (r_ray_end) { | ||||
| madd_v3_v3v3fl(r_ray_end, r_ray_co, r_ray_dir, end_offset); | madd_v3_v3v3fl(r_ray_end, r_ray_co, r_ray_dir, end_offset); | ||||
| } | } | ||||
| Show All 22 Lines | |||||
| * \param mval The area relative 2d location (such as event->mval, converted into float[2]). | * \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. | * \param r_ray_co The world-space point where the ray intersects the window plane. | ||||
| * \param r_ray_normal The normalized world-space direction of towards mval. | * \param r_ray_normal The normalized world-space direction of towards mval. | ||||
| * \param r_ray_start The world-space starting point of the ray. | * \param r_ray_start The world-space starting point of the ray. | ||||
| * \param do_clip Optionally clip the start of the ray by the view clipping planes. | * \param do_clip Optionally clip the start of the ray by the view clipping planes. | ||||
| * \return success, false if the ray is totally clipped. | * \return success, false if the ray is totally clipped. | ||||
| */ | */ | ||||
| bool ED_view3d_win_to_ray_ex( | bool ED_view3d_win_to_ray_ex( | ||||
| const struct Depsgraph *depsgraph, | |||||
| const ARegion *ar, const View3D *v3d, const float mval[2], | const ARegion *ar, const View3D *v3d, const float mval[2], | ||||
| float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], bool do_clip) | float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], bool do_clip) | ||||
| { | { | ||||
| float ray_end[3]; | float ray_end[3]; | ||||
| view3d_win_to_ray_segment(ar, v3d, mval, r_ray_co, r_ray_normal, r_ray_start, ray_end); | view3d_win_to_ray_segment(depsgraph, ar, v3d, mval, r_ray_co, r_ray_normal, r_ray_start, ray_end); | ||||
| /* bounds clipping */ | /* bounds clipping */ | ||||
| if (do_clip) { | if (do_clip) { | ||||
| return ED_view3d_clip_segment(ar->regiondata, r_ray_start, ray_end); | return ED_view3d_clip_segment(ar->regiondata, r_ray_start, ray_end); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| /** | /** | ||||
| * Calculate a 3d viewpoint and direction vector from 2d window coordinates. | * 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. | * 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. | * 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. | * In orthographic view the resulting ray_normal will match the view vector. | ||||
| * \param ar The region (used for the window width and height). | * \param ar The region (used for the window width and height). | ||||
| * \param v3d The 3d viewport (used for near clipping value). | * \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 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_start The world-space point where the ray intersects the window plane. | ||||
| * \param r_ray_normal The normalized world-space direction of towards mval. | * \param r_ray_normal The normalized world-space direction of towards mval. | ||||
| * \param do_clip Optionally clip the start of the ray by the view clipping planes. | * \param do_clip Optionally clip the start of the ray by the view clipping planes. | ||||
| * \return success, false if the ray is totally clipped. | * \return success, false if the ray is totally clipped. | ||||
| */ | */ | ||||
| bool ED_view3d_win_to_ray( | bool ED_view3d_win_to_ray( | ||||
| const struct Depsgraph *depsgraph, | |||||
| const ARegion *ar, const View3D *v3d, const float mval[2], | const ARegion *ar, const View3D *v3d, const float mval[2], | ||||
| float r_ray_start[3], float r_ray_normal[3], const bool do_clip) | float r_ray_start[3], float r_ray_normal[3], const bool do_clip) | ||||
| { | { | ||||
| return ED_view3d_win_to_ray_ex(ar, v3d, mval, NULL, r_ray_normal, r_ray_start, do_clip); | return ED_view3d_win_to_ray_ex(depsgraph,ar, v3d, mval, NULL, r_ray_normal, r_ray_start, do_clip); | ||||
| } | } | ||||
| /** | /** | ||||
| * Calculate a normalized 3d direction vector from the viewpoint towards a global location. | * Calculate a normalized 3d direction vector from the viewpoint towards a global location. | ||||
| * In orthographic view the resulting vector will match the view vector. | * In orthographic view the resulting vector will match the view vector. | ||||
| * \param rv3d The region (used for the window width and height). | * \param rv3d The region (used for the window width and height). | ||||
| * \param coord The world-space location. | * \param coord The world-space location. | ||||
| * \param vec The resulting normalized vector. | * \param vec The resulting normalized vector. | ||||
| ▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | |||||
| * \param ar The region (used for the window width and height). | * \param ar The region (used for the window width and height). | ||||
| * \param v3d The 3d viewport (used for near and far clipping range). | * \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 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. | * \param r_ray_start The world-space starting point of the segment. | ||||
| * \param r_ray_end The world-space end point of the segment. | * \param r_ray_end The world-space end point of the segment. | ||||
| * \param do_clip Optionally clip the ray by the view clipping planes. | * \param do_clip Optionally clip the ray by the view clipping planes. | ||||
| * \return success, false if the segment is totally clipped. | * \return success, false if the segment is totally clipped. | ||||
| */ | */ | ||||
| bool ED_view3d_win_to_segment(const ARegion *ar, View3D *v3d, const float mval[2], | bool ED_view3d_win_to_segment(const struct Depsgraph *depsgraph, | ||||
| const ARegion *ar, View3D *v3d, const float mval[2], | |||||
| float r_ray_start[3], float r_ray_end[3], const bool do_clip) | float r_ray_start[3], float r_ray_end[3], const bool do_clip) | ||||
| { | { | ||||
| view3d_win_to_ray_segment(ar, v3d, mval, NULL, NULL, r_ray_start, r_ray_end); | view3d_win_to_ray_segment(depsgraph, ar, v3d, mval, NULL, NULL, r_ray_start, r_ray_end); | ||||
| /* bounds clipping */ | /* bounds clipping */ | ||||
| if (do_clip) { | if (do_clip) { | ||||
| return ED_view3d_clip_segment((RegionView3D *)ar->regiondata, r_ray_start, r_ray_end); | return ED_view3d_clip_segment((RegionView3D *)ar->regiondata, r_ray_start, r_ray_end); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| Show All 40 Lines | |||||