Blender V4.3
view3d_project.cc File Reference
#include "DNA_camera_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_view3d_types.h"
#include "BLI_sys_types.h"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BKE_camera.h"
#include "BKE_screen.hh"
#include "GPU_matrix.hh"
#include "ED_view3d.hh"

Go to the source code of this file.

Macros

#define BL_ZERO_CLIP   0.001
 

Functions

blender::float2 ED_view3d_project_float_v2_m4 (const ARegion *region, const float co[3], const blender::float4x4 &mat)
 
void ED_view3d_project_float_v3_m4 (const ARegion *region, const float co[3], float r_co[3], const float mat[4][4])
 
eV3DProjStatus ED_view3d_project_base (const ARegion *region, Base *base, float r_co[2])
 
static eV3DProjStatus ed_view3d_project__internal (const ARegion *region, const float perspmat[4][4], const bool is_local, const float co[3], float r_co[2], const eV3DProjTest flag)
 
eV3DProjStatus ED_view3d_project_short_ex (const ARegion *region, float perspmat[4][4], const bool is_local, const float co[3], short r_co[2], const eV3DProjTest flag)
 
eV3DProjStatus ED_view3d_project_int_ex (const ARegion *region, float perspmat[4][4], const bool is_local, const float co[3], int r_co[2], const eV3DProjTest flag)
 
eV3DProjStatus ED_view3d_project_float_ex (const ARegion *region, float perspmat[4][4], const bool is_local, const float co[3], float r_co[2], const eV3DProjTest flag)
 
eV3DProjStatus ED_view3d_project_short_global (const ARegion *region, const float co[3], short r_co[2], const eV3DProjTest flag)
 
eV3DProjStatus ED_view3d_project_short_object (const ARegion *region, const float co[3], short r_co[2], const eV3DProjTest flag)
 
eV3DProjStatus ED_view3d_project_int_global (const ARegion *region, const float co[3], int r_co[2], const eV3DProjTest flag)
 
eV3DProjStatus ED_view3d_project_int_object (const ARegion *region, const float co[3], int r_co[2], const eV3DProjTest flag)
 
eV3DProjStatus ED_view3d_project_float_global (const ARegion *region, const float co[3], float r_co[2], const eV3DProjTest flag)
 
eV3DProjStatus ED_view3d_project_float_object (const ARegion *region, const float co[3], float r_co[2], const eV3DProjTest flag)
 
float ED_view3d_pixel_size (const RegionView3D *rv3d, const float co[3])
 
float ED_view3d_pixel_size_no_ui_scale (const RegionView3D *rv3d, const float co[3])
 
float ED_view3d_calc_zfac_ex (const RegionView3D *rv3d, const float co[3], bool *r_flip)
 
float ED_view3d_calc_zfac (const RegionView3D *rv3d, const float co[3])
 
float ED_view3d_calc_depth_for_comparison (const RegionView3D *rv3d, const float co[3])
 
static void view3d_win_to_ray_segment (const Depsgraph *depsgraph, const ARegion *region, 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])
 
bool ED_view3d_clip_segment (const RegionView3D *rv3d, float ray_start[3], float ray_end[3])
 
bool ED_view3d_win_to_ray_clipped_ex (Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const float mval[2], const bool do_clip_planes, float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], float r_ray_end[3])
 
bool ED_view3d_win_to_ray_clipped (Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_normal[3], const bool do_clip_planes)
 
void ED_view3d_win_to_ray (const ARegion *region, const float mval[2], float r_ray_start[3], float r_ray_normal[3])
 
void ED_view3d_global_to_vector (const RegionView3D *rv3d, const float coord[3], float r_out[3])
 
void ED_view3d_win_to_3d (const View3D *v3d, const ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
 
void ED_view3d_win_to_3d_int (const View3D *v3d, const ARegion *region, const float depth_pt[3], const int mval[2], float r_out[3])
 
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])
 
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])
 
bool ED_view3d_win_to_3d_on_plane_with_fallback (const ARegion *region, const float plane[4], const float mval[2], const bool do_clip, const float plane_fallback[4], float r_out[3])
 
void ED_view3d_win_to_delta (const ARegion *region, const float xy_delta[2], const float zfac, float r_out[3])
 
void ED_view3d_win_to_origin (const ARegion *region, const float mval[2], float r_out[3])
 
void ED_view3d_win_to_vector (const ARegion *region, const float mval[2], float r_out[3])
 
bool ED_view3d_win_to_segment_clipped (const Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_end[3], const bool do_clip_planes)
 
Utility functions for projection
blender::float4x4 ED_view3d_ob_project_mat_get (const RegionView3D *rv3d, const Object *ob)
 
blender::float4x4 ED_view3d_ob_project_mat_get_from_obmat (const RegionView3D *rv3d, const blender::float4x4 &obmat)
 
void ED_view3d_project_v3 (const ARegion *region, const float world[3], float r_region_co[3])
 
void ED_view3d_project_v2 (const ARegion *region, const float world[3], float r_region_co[2])
 
bool ED_view3d_unproject_v3 (const ARegion *region, float regionx, float regiony, float regionz, float world[3])
 

Macro Definition Documentation

◆ BL_ZERO_CLIP

#define BL_ZERO_CLIP   0.001

Definition at line 29 of file view3d_project.cc.

Referenced by ed_view3d_project__internal().

Function Documentation

◆ ED_view3d_calc_depth_for_comparison()

float ED_view3d_calc_depth_for_comparison ( const RegionView3D * rv3d,
const float co[3] )

Calculate a depth value from co (result should only be used for comparison).

Definition at line 317 of file view3d_project.cc.

References dot_v3v3(), ED_view3d_calc_zfac(), RegionView3D::is_persp, and RegionView3D::viewinv.

Referenced by annotation_stroke_eraser_is_occluded().

◆ ED_view3d_calc_zfac()

◆ ED_view3d_calc_zfac_ex()

float ED_view3d_calc_zfac_ex ( const RegionView3D * rv3d,
const float co[3],
bool * r_flip )

Calculate a depth value from co, use with ED_view3d_win_to_delta.

Parameters
r_flipSet to zfac < 0.0 before the value is made signed. Since it's important in some cases to know if the value was flipped.
Returns
The unsigned depth component of co multiplied by rv3d->persmat matrix, with additional sanitation to ensure the result is never negative as this isn't useful for tool-code.

Definition at line 289 of file view3d_project.cc.

References mul_project_m4_v3_zfac(), and RegionView3D::persmat.

Referenced by ED_view3d_calc_zfac(), and ED_view3d_cursor3d_position().

◆ ED_view3d_clip_segment()

bool ED_view3d_clip_segment ( const RegionView3D * rv3d,
float ray_start[3],
float ray_end[3] )

◆ ED_view3d_global_to_vector()

void ED_view3d_global_to_vector ( const RegionView3D * rv3d,
const float coord[3],
float r_out[3] )

Calculate a normalized 3D direction vector from the viewpoint towards a global location. In orthographic view the resulting vector will match the view vector.

Parameters
rv3dThe region (used for the window width and height).
coordThe world-space location.
r_outThe resulting normalized vector.

Definition at line 424 of file view3d_project.cc.

References copy_v3_v3(), RegionView3D::is_persp, mul_m4_v4(), mul_v3_fl(), normalize_v3(), sub_v3_v3v3(), RegionView3D::viewinv, and RegionView3D::viewmat.

Referenced by add_vertex_invoke(), dial_ghostarc_get_angles(), gizmo_get_idot(), blender::ed::sculpt_paint::project_brush_radius(), update_location_for_2d_curve(), and v3d_cursor_plane_draw().

◆ ED_view3d_ob_project_mat_get()

blender::float4x4 ED_view3d_ob_project_mat_get ( const RegionView3D * rv3d,
const Object * ob )

Definition at line 699 of file view3d_project.cc.

References mul_m4_m4m4(), blender::MatBase< T, NumCol, NumRow, Alignment >::ptr(), RegionView3D::viewmat, and RegionView3D::winmat.

Referenced by blender::ed::sculpt_paint::CombOperationExecutor::comb_projected(), content_planes_from_clip_flag(), blender::ed::sculpt_paint::DeleteOperationExecutor::delete_projected(), ed_curves_select_pick(), edbm_rip_edge_invoke(), edbm_rip_invoke__edge(), edbm_rip_invoke__vert(), blender::ed::sculpt_paint::PuffOperationExecutor::find_curve_weights_projected(), blender::ed::sculpt_paint::find_curves_brush_position(), blender::ed::sculpt_paint::SmoothOperationExecutor::find_projected_smooth_factors(), blender::ed::sculpt_paint::CurvesEffectOperationExecutor::gather_influences_projected(), blender::ed::greasepencil::grease_pencil_primitive_invoke(), blender::ed::greasepencil::grease_pencil_primitive_modal(), blender::ed::sculpt_paint::gesture::init_from_lasso(), knifeproject_poly_from_object(), obedit_circle_select(), blender::ed::sculpt_paint::greasepencil::GrabOperation::on_stroke_begin(), paint_convert_bb_to_rect(), blender::ed::sculpt_paint::SelectionPaintOperationExecutor::paint_curve_selection_projected(), blender::ed::sculpt_paint::SelectionPaintOperationExecutor::paint_point_selection_projected(), blender::ed::sculpt_paint::PinchOperationExecutor::pinch_projected(), blender::ed::sculpt_paint::SnakeHookOperatorExecutor::projected_snake_hook(), blender::ed::sculpt_paint::DensitySubtractOperationExecutor::reduce_density_projected(), blender::ed::sculpt_paint::DensityAddOperationExecutor::sample_projected_with_symmetry(), blender::ed::sculpt_paint::sculpt_update_cache_invariants(), blender::ed::sculpt_paint::SlideOperationExecutor::slide(), blender::ed::sculpt_paint::vwpaint::update_cache_invariants(), EdgeSlideData::update_proj_mat(), VertSlideData::update_proj_mat(), view3d_box_select_exec(), and view3d_lasso_select().

◆ ED_view3d_ob_project_mat_get_from_obmat()

◆ ED_view3d_pixel_size()

◆ ED_view3d_pixel_size_no_ui_scale()

float ED_view3d_pixel_size_no_ui_scale ( const RegionView3D * rv3d,
const float co[3] )

◆ ed_view3d_project__internal()

static eV3DProjStatus ed_view3d_project__internal ( const ARegion * region,
const float perspmat[4][4],
const bool is_local,
const float co[3],
float r_co[2],
const eV3DProjTest flag )
static

◆ ED_view3d_project_base()

eV3DProjStatus ED_view3d_project_base ( const ARegion * region,
Base * base,
float r_co[2] )

◆ ED_view3d_project_float_ex()

eV3DProjStatus ED_view3d_project_float_ex ( const ARegion * region,
float perspmat[4][4],
const bool is_local,
const float co[3],
float r_co[2],
const eV3DProjTest flag )

◆ ED_view3d_project_float_global()

◆ ED_view3d_project_float_object()

◆ ED_view3d_project_float_v2_m4()

blender::float2 ED_view3d_project_float_v2_m4 ( const ARegion * region,
const float co[3],
const blender::float4x4 & mat )
Note
use ED_view3d_ob_project_mat_get to get the projection matrix

Definition at line 34 of file view3d_project.cc.

References copy_v3_v3(), float, mul_m4_v4(), blender::MatBase< T, NumCol, NumRow, Alignment >::ptr(), vec4, and zero_v2().

Referenced by blender::ed::greasepencil::build_curves_2d_bvh_from_visible(), blender::ed::sculpt_paint::CombOperationExecutor::comb_projected(), blender::ed::sculpt_paint::DeleteOperationExecutor::delete_projected(), edbm_rip_edge_invoke(), edbm_rip_edge_side_measure(), edbm_rip_edgedist_squared(), blender::ed::sculpt_paint::PuffOperationExecutor::find_curve_weights_projected(), blender::ed::sculpt_paint::find_curves_brush_position(), blender::ed::sculpt_paint::SmoothOperationExecutor::find_projected_smooth_factors(), blender::ed::sculpt_paint::CurvesEffectOperationExecutor::gather_influences_projected(), blender::ed::sculpt_paint::gesture::is_affected_lasso(), knifeproject_poly_from_object(), paint_convert_bb_to_rect(), blender::ed::sculpt_paint::PinchOperationExecutor::pinch_projected(), blender::ed::greasepencil::primitive_local_to_screen(), blender::ed::sculpt_paint::SnakeHookOperatorExecutor::projected_snake_hook(), blender::ed::sculpt_paint::DensityAddOperationExecutor::sample_projected_with_symmetry(), sculpt_apply_texture(), SCULPT_vertex_is_occluded(), blender::ed::curves::select_box(), blender::ed::curves::select_box_mask(), blender::ed::curves::select_circle(), blender::ed::curves::select_circle_mask(), blender::ed::curves::select_lasso(), and blender::ed::curves::select_lasso_mask().

◆ ED_view3d_project_float_v3_m4()

void ED_view3d_project_float_v3_m4 ( const ARegion * region,
const float co[3],
float r_co[3],
const float mat[4][4] )
Note
use ED_view3d_ob_project_mat_get to get projecting mat

Definition at line 57 of file view3d_project.cc.

References copy_v3_v3(), float, mul_m4_v4(), vec4, and zero_v3().

◆ ED_view3d_project_int_ex()

eV3DProjStatus ED_view3d_project_int_ex ( const ARegion * region,
float perspmat[4][4],
const bool is_local,
const float co[3],
int r_co[2],
const eV3DProjTest flag )

◆ ED_view3d_project_int_global()

eV3DProjStatus ED_view3d_project_int_global ( const ARegion * region,
const float co[3],
int r_co[2],
const eV3DProjTest flag )

◆ ED_view3d_project_int_object()

eV3DProjStatus ED_view3d_project_int_object ( const ARegion * region,
const float co[3],
int r_co[2],
const eV3DProjTest flag )

◆ ED_view3d_project_short_ex()

eV3DProjStatus ED_view3d_project_short_ex ( const ARegion * region,
float perspmat[4][4],
const bool is_local,
const float co[3],
short r_co[2],
const eV3DProjTest flag )

◆ ED_view3d_project_short_global()

eV3DProjStatus ED_view3d_project_short_global ( const ARegion * region,
const float co[3],
short r_co[2],
const eV3DProjTest flag )

Definition at line 222 of file view3d_project.cc.

References ED_view3d_project_short_ex(), flag, and RegionView3D::persmat.

◆ ED_view3d_project_short_object()

eV3DProjStatus ED_view3d_project_short_object ( const ARegion * region,
const float co[3],
short r_co[2],
const eV3DProjTest flag )

◆ ED_view3d_project_v2()

◆ ED_view3d_project_v3()

void ED_view3d_project_v3 ( const ARegion * region,
const float world[3],
float r_region_co[3] )

Convert between region relative coordinates (x,y) and depth component z and a point in world space.

Definition at line 715 of file view3d_project.cc.

References GPU_matrix_project_3fv(), RegionView3D::viewmat, and RegionView3D::winmat.

Referenced by blender::ed::sculpt_paint::cursor_draw_point_screen_space(), key_test_depth(), and blender::ed::object::object_transform_axis_target_calc_depth_init().

◆ ED_view3d_unproject_v3()

◆ ED_view3d_win_to_3d()

void ED_view3d_win_to_3d ( const View3D * v3d,
const ARegion * region,
const float depth_pt[3],
const float mval[2],
float r_out[3] )

Calculate a 3D location from 2D window coordinates.

Parameters
regionThe region (used for the window width and height).
depth_ptThe reference location used to calculate the Z depth.
mvalThe area relative location (such as event->mval converted to floats).
r_outThe resulting world-space location.

Definition at line 482 of file view3d_project.cc.

References BKE_camera_sensor_fit(), BKE_screen_view3d_zoom_to_fac(), RegionView3D::camdx, RegionView3D::camdy, View3D::camera, CAMERA_SENSOR_FIT_HOR, RegionView3D::camzoom, copy_v3_v3(), Object::data, ED_view3d_win_to_vector(), fabsf, float, RegionView3D::is_persp, isect_ray_plane_v3_factor(), madd_v3_v3v3fl(), RegionView3D::persinv, RegionView3D::persp, ray_point_factor_v3(), RV3D_CAMOB, Camera::sensor_fit, Camera::shiftx, Camera::shifty, and RegionView3D::viewinv.

Referenced by armature_click_extrude_invoke(), blender::ed::sculpt_paint::brush_delta_update(), blender::ed::sculpt_paint::CombOperationExecutor::comb_projected(), blender::ed::sculpt_paint::CombOperationExecutor::comb_spherical_with_symmetry(), curve_draw_invoke(), blender::ed::curves::curves_draw_invoke(), blender::ed::sculpt_paint::DeleteOperationExecutor::delete_spherical_with_symmetry(), depthdropper_depth_sample_pt(), ED_view3d_win_to_3d_int(), blender::ed::sculpt_paint::PuffOperationExecutor::find_curves_weights_spherical_with_symmetry(), blender::ed::sculpt_paint::SmoothOperationExecutor::find_spherical_smooth_factors_with_symmetry(), blender::ed::sculpt_paint::CurvesEffectOperationExecutor::gather_influences_projected(), blender::ed::sculpt_paint::CurvesEffectOperationExecutor::gather_influences_spherical(), blender::ed::sculpt_paint::trim::generate_geometry(), gizmo_window_project_3d(), ViewOpsData::init_navigation(), initBend(), knife_constrain_axis(), knifetool_raycast_planes(), blender::ed::sculpt_paint::gesture::line_calculate_plane_points(), mesh_bisect_interactive_calc(), blender::ed::sculpt_paint::SelectionPaintOperationExecutor::paint_curve_selection_spherical_with_symmetry(), blender::ed::sculpt_paint::SelectionPaintOperationExecutor::paint_point_selection_spherical_with_symmetry(), blender::ed::sculpt_paint::PinchOperationExecutor::pinch_projected(), blender::ed::sculpt_paint::PinchOperationExecutor::pinch_spherical_with_symmetry(), blender::ed::greasepencil::DrawingPlacement::project(), blender::ed::sculpt_paint::SnakeHookOperatorExecutor::projected_snake_hook(), screenspace_to_worldspace(), blender::ed::sculpt_paint::SnakeHookOperatorExecutor::spherical_snake_hook_with_symmetry(), blender::ed::curves::stroke_elem_project_fallback(), stroke_elem_project_fallback(), and v3d_cursor_snap_update().

◆ ED_view3d_win_to_3d_int()

◆ ED_view3d_win_to_3d_on_plane()

◆ ED_view3d_win_to_3d_on_plane_int()

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] )

Definition at line 577 of file view3d_project.cc.

References ED_view3d_win_to_3d_on_plane(), and float.

Referenced by gizmo_mesh_spin_redo_setup().

◆ ED_view3d_win_to_3d_on_plane_with_fallback()

bool ED_view3d_win_to_3d_on_plane_with_fallback ( const ARegion * region,
const float plane[4],
const float mval[2],
bool do_clip,
const float plane_fallback[4],
float r_out[3] )

A wrapper for ED_view3d_win_to_3d_on_plane that projects onto plane_fallback then maps this back to plane.

This is intended to be used when plane is orthogonal to the views Z axis where projecting the mval doesn't work well (or fail completely when exactly aligned).

Definition at line 587 of file view3d_project.cc.

References closest_to_plane_v3(), copy_m4_m3(), ED_view3d_win_to_3d_on_plane(), isect_plane_plane_v3(), mat4, mul_m4_v3(), normalize_v3(), rotation_between_vecs_to_mat3(), and transform_pivot_set_m4().

Referenced by view3d_win_to_3d_on_plane_maybe_fallback().

◆ ED_view3d_win_to_delta()

void ED_view3d_win_to_delta ( const ARegion * region,
const float xy_delta[2],
float zfac,
float r_out[3] )

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.

When the zfac is calculated based on a world-space location directly under the cursor, the value of r_out can be subtracted from RegionView3D.ofs to pan the view with the contents following the cursor perfectly (without sliding).

Parameters
regionThe region (used for the window width and height).
xy_delta2D difference (in pixels) such as event->mval[0] - other_x.
zfacThe depth result typically calculated by ED_view3d_calc_zfac (see its doc-string for details).
r_outThe resulting world-space delta.

Definition at line 622 of file view3d_project.cc.

References RegionView3D::persinv.

Referenced by annotation_stroke_convertcoords(), brush_edit_apply(), blender::ed::sculpt_paint::calc_local_from_screen(), convertViewVec(), blender::ed::sculpt_paint::greasepencil::get_screen_projection_fn(), gpencil_stroke_convertcoords(), mesh_bisect_interactive_calc(), move3d_get_translate(), paint_calc_object_space_radius(), blender::ed::greasepencil::pixel_radius_to_world_space_radius(), view3d_zoom_border_exec(), view_zoom_to_window_xy_3d(), and viewmove_apply().

◆ ED_view3d_win_to_origin()

void ED_view3d_win_to_origin ( const ARegion * region,
const float mval[2],
float r_out[3] )

Calculate a 3D origin from 2D window coordinates.

Note
Orthographic views have a less obvious origin, Since far clip can be a very large value resulting in numeric precision issues, the origin in this case is close to zero coordinate.
Parameters
regionThe region (used for the window width and height).
mvalThe area relative 2D location (such as event->mval converted to float).
r_outThe resulting normalized world-space direction vector.

Definition at line 638 of file view3d_project.cc.

References copy_v3_v3(), RegionView3D::is_persp, mul_project_m4_v3(), RegionView3D::persinv, RegionView3D::persp, RV3D_CAMOB, and RegionView3D::viewinv.

Referenced by ED_view3d_win_to_3d_on_plane(), ED_view3d_win_to_ray(), SCULPT_raycast_init(), and view3d_win_to_ray_segment().

◆ ED_view3d_win_to_ray()

void ED_view3d_win_to_ray ( const ARegion * region,
const float mval[2],
float r_ray_start[3],
float r_ray_normal[3] )

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.

Parameters
regionThe region (used for the window width and height).
mvalThe area relative 2D location (such as event->mval, converted into float[2]).
r_ray_startThe world-space point where the ray intersects the window plane.
r_ray_normalThe normalized world-space direction of towards mval.
Note
Ignores view near/far clipping, to take this into account use ED_view3d_win_to_ray_clipped.

Definition at line 415 of file view3d_project.cc.

References ED_view3d_win_to_origin(), and ED_view3d_win_to_vector().

Referenced by gizmo_arrow_modal(), and blender::ed::object::object_transform_axis_target_calc_depth_init().

◆ ED_view3d_win_to_ray_clipped()

bool ED_view3d_win_to_ray_clipped ( Depsgraph * depsgraph,
const ARegion * region,
const View3D * v3d,
const float mval[2],
float r_ray_start[3],
float r_ray_normal[3],
bool 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. 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.

Parameters
regionThe region (used for the window width and height).
v3dThe 3D viewport (used for near clipping value).
mvalThe area relative 2D location (such as event->mval, converted into float[2]).
r_ray_startThe world-space point where the ray intersects the window plane.
r_ray_normalThe normalized world-space direction of towards mval.
do_clip_planesOptionally clip the start of the ray by the view clipping planes.
Returns
success, false if the ray is totally clipped.

Definition at line 395 of file view3d_project.cc.

References depsgraph, and ED_view3d_win_to_ray_clipped_ex().

Referenced by EDBM_unified_findnearest_from_raycast(), and knife_snap_curr().

◆ ED_view3d_win_to_ray_clipped_ex()

bool ED_view3d_win_to_ray_clipped_ex ( Depsgraph * depsgraph,
const ARegion * region,
const View3D * v3d,
const float mval[2],
const bool do_clip_planes,
float r_ray_co[3],
float r_ray_normal[3],
float r_ray_start[3],
float r_ray_end[3] )

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. 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. This version also returns the ray_co point of the ray on window plane, useful to fix precision issues especially with orthographic view, where default ray_start is set rather far away.

Parameters
regionThe region (used for the window width and height).
v3dThe 3D viewport (used for near clipping value).
mvalThe area relative 2D location (such as event->mval, converted into float[2]).
do_clip_planesOptionally clip the start of the ray by the view clipping planes.
r_ray_coThe world-space point where the ray intersects the window plane.
r_ray_normalThe normalized world-space direction of towards mval.
r_ray_startThe world-space starting point of the ray.
r_ray_endThe world-space end point of the segment.
Returns
success, false if the ray is totally clipped.

Definition at line 373 of file view3d_project.cc.

References depsgraph, ED_view3d_clip_segment(), and view3d_win_to_ray_segment().

Referenced by ED_transform_snap_object_project_all_view3d_ex(), ED_transform_snap_object_project_view3d_ex(), and ED_view3d_win_to_ray_clipped().

◆ ED_view3d_win_to_segment_clipped()

bool ED_view3d_win_to_segment_clipped ( const Depsgraph * depsgraph,
const ARegion * region,
const View3D * v3d,
const float mval[2],
float r_ray_start[3],
float r_ray_end[3],
bool do_clip_planes )

Calculate a 3D segment from 2D window coordinates. This ray_start is located at the viewpoint, ray_end is a far point. 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.

Parameters
regionThe region (used for the window width and height).
v3dThe 3D viewport (used for near and far clipping range).
mvalThe area relative 2D location (such as event->mval, converted into float[2]).
r_ray_startThe world-space starting point of the segment.
r_ray_endThe world-space end point of the segment.
do_clip_planesOptionally clip the ray by the view clipping planes.
Returns
success, false if the segment is totally clipped.

Definition at line 676 of file view3d_project.cc.

References depsgraph, ED_view3d_clip_segment(), and view3d_win_to_ray_segment().

Referenced by BMBVH_EdgeVisible(), brush_add_count_iter(), imapaint_pick_face(), knife_find_line_hits(), knife_input_ray_segment(), blender::ed::sculpt_paint::min_distance_edit::min_distance_edit_invoke(), blender::ed::sculpt_paint::sample_curves_3d_brush(), blender::ed::sculpt_paint::sample_curves_surface_3d_brush(), blender::ed::sculpt_paint::AddOperationExecutor::sample_in_center_with_symmetry(), blender::ed::sculpt_paint::AddOperationExecutor::sample_projected(), blender::ed::sculpt_paint::DensityAddOperationExecutor::sample_projected_with_symmetry(), blender::ed::sculpt_paint::AddOperationExecutor::sample_spherical_with_symmetry(), and SCULPT_raycast_init().

◆ ED_view3d_win_to_vector()

void ED_view3d_win_to_vector ( const ARegion * region,
const float mval[2],
float r_out[3] )

Calculate a 3D direction vector from 2D window coordinates. The resulting direction points away from the view-point, making the result useful to perform ray-casts into a 3D scene. In orthographic view all input coordinates result in the same vector.

Note
doesn't rely on ED_view3d_calc_zfac for perspective view, get the vector direction to the mouse cursor as a normalized vector.
Parameters
regionThe region (used for the window width and height).
mvalThe area relative 2D location (such as event->mval converted to float).
r_outThe resulting normalized world-space direction vector.

Definition at line 659 of file view3d_project.cc.

References RegionView3D::is_persp, mul_project_m4_v3(), negate_v3_v3(), normalize_v3(), RegionView3D::persinv, sub_v3_v3(), and RegionView3D::viewinv.

Referenced by ED_view3d_win_to_3d(), ED_view3d_win_to_3d_on_plane(), ED_view3d_win_to_ray(), gizmo_find_intersected_3d_intern(), ViewOpsData::init_navigation(), mesh_bisect_interactive_calc(), and view3d_win_to_ray_segment().

◆ view3d_win_to_ray_segment()

static void view3d_win_to_ray_segment ( const Depsgraph * depsgraph,
const ARegion * region,
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] )
static