Blender  V2.93
Macros | Functions
view3d_project.c 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_vector.h"
#include "BKE_camera.h"
#include "BKE_screen.h"
#include "GPU_matrix.h"
#include "ED_view3d.h"

Go to the source code of this file.

Macros

#define BL_ZERO_CLIP   0.001
 

Functions

void ED_view3d_project_float_v2_m4 (const ARegion *region, const float co[3], float r_co[2], float mat[4][4])
 
void ED_view3d_project_float_v3_m4 (const ARegion *region, const float co[3], float r_co[3], float mat[4][4])
 
eV3DProjStatus ED_view3d_project_base (const struct ARegion *region, struct Base *base)
 
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 (const RegionView3D *rv3d, const float co[3], bool *r_flip)
 
static void view3d_win_to_ray_segment (struct 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 (struct Depsgraph *depsgraph, const ARegion *region, 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_planes)
 
bool ED_view3d_win_to_ray_clipped (struct 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 vec[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 mval[2], float out[3], const float zfac)
 
void ED_view3d_win_to_origin (const ARegion *region, const float mval[2], float out[3])
 
void ED_view3d_win_to_vector (const ARegion *region, const float mval[2], float out[3])
 
bool ED_view3d_win_to_segment_clipped (struct Depsgraph *depsgraph, const ARegion *region, 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
void ED_view3d_ob_project_mat_get (const RegionView3D *rv3d, Object *ob, float r_pmat[4][4])
 
void ED_view3d_ob_project_mat_get_from_obmat (const RegionView3D *rv3d, const float obmat[4][4], float r_pmat[4][4])
 
void ED_view3d_project (const struct ARegion *region, const float world[3], float r_region_co[3])
 
bool ED_view3d_unproject (const struct 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 41 of file view3d_project.c.

Function Documentation

◆ ED_view3d_calc_zfac()

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

Calculate a depth value from co, use with ED_view3d_win_to_delta

Definition at line 310 of file view3d_project.c.

References mul_project_m4_v3_zfac(), and RegionView3D::persmat.

◆ 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  vec[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.
vecThe resulting normalized vector.

Definition at line 470 of file view3d_project.c.

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

◆ ED_view3d_ob_project_mat_get()

void ED_view3d_ob_project_mat_get ( const RegionView3D rv3d,
Object ob,
float  r_pmat[4][4] 
)

◆ ED_view3d_ob_project_mat_get_from_obmat()

void ED_view3d_ob_project_mat_get_from_obmat ( const RegionView3D rv3d,
const float  obmat[4][4],
float  r_pmat[4][4] 
)

Definition at line 799 of file view3d_project.c.

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

◆ ED_view3d_pixel_size()

float ED_view3d_pixel_size ( const RegionView3D rv3d,
const float  co[3] 
)

◆ 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()

void ED_view3d_project ( const struct ARegion region,
const float  world[3],
float  r_region_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 struct ARegion region,
struct Base base 
)

◆ 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()

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

◆ ED_view3d_project_float_object()

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

◆ ED_view3d_project_float_v2_m4()

void ED_view3d_project_float_v2_m4 ( const ARegion region,
const float  co[3],
float  r_co[2],
float  mat[4][4] 
)
Note
use ED_view3d_ob_project_mat_get to get the projection matrix

Definition at line 49 of file view3d_project.c.

References copy_v3_v3(), float(), mul_m4_v4(), ARegion::winx, ARegion::winy, and zero_v2().

◆ ED_view3d_project_float_v3_m4()

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

Definition at line 74 of file view3d_project.c.

References copy_v3_v3(), float(), mul_m4_v4(), ARegion::winx, ARegion::winy, 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 
)

◆ 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_unproject()

bool ED_view3d_unproject ( const struct ARegion region,
float  regionx,
float  regiony,
float  regionz,
float  world[3] 
)

◆ 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 535 of file view3d_project.c.

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(), madd_v3_v3v3fl(), RegionView3D::persinv, RegionView3D::persp, plane_from_point_normal_v3(), ray_point_factor_v3(), ARegion::regiondata, RV3D_CAMOB, Camera::sensor_fit, Camera::shiftx, Camera::shifty, RegionView3D::viewinv, ARegion::winx, and ARegion::winy.

Referenced by ED_view3d_win_to_3d_int().

◆ ED_view3d_win_to_3d_int()

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

Definition at line 591 of file view3d_project.c.

References ED_view3d_win_to_3d().

◆ ED_view3d_win_to_3d_on_plane()

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

◆ 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 618 of file view3d_project.c.

References ED_view3d_win_to_3d_on_plane().

◆ 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],
const 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 635 of file view3d_project.c.

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

◆ ED_view3d_win_to_delta()

void ED_view3d_win_to_delta ( const ARegion region,
const float  mval[2],
float  out[3],
const float  zfac 
)

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.

Parameters
regionThe region (used for the window width and height).
mvalThe area relative 2d difference (such as event->mval[0] - other_x).
outThe resulting world-space delta.

Definition at line 678 of file view3d_project.c.

References RegionView3D::persinv, ARegion::regiondata, ARegion::winx, and ARegion::winy.

◆ ED_view3d_win_to_origin()

void ED_view3d_win_to_origin ( const ARegion region,
const float  mval[2],
float  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 floats).
outThe resulting normalized world-space direction vector.

Definition at line 704 of file view3d_project.c.

References copy_v3_v3(), RegionView3D::is_persp, mul_project_m4_v3(), RegionView3D::persinv, RegionView3D::persp, ARegion::regiondata, RV3D_CAMOB, RegionView3D::viewinv, ARegion::winx, and ARegion::winy.

Referenced by ED_view3d_win_to_3d_on_plane(), ED_view3d_win_to_ray(), 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 454 of file view3d_project.c.

References ED_view3d_win_to_origin(), and ED_view3d_win_to_vector().

◆ ED_view3d_win_to_ray_clipped()

bool ED_view3d_win_to_ray_clipped ( struct 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 
)

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 431 of file view3d_project.c.

References depsgraph, ED_view3d_win_to_ray_clipped_ex(), and NULL.

◆ ED_view3d_win_to_ray_clipped_ex()

bool ED_view3d_win_to_ray_clipped_ex ( struct Depsgraph depsgraph,
const ARegion region,
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_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. 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.

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_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.
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 396 of file view3d_project.c.

References depsgraph, ED_view3d_clip_segment(), ARegion::regiondata, and view3d_win_to_ray_segment().

Referenced by ED_view3d_win_to_ray_clipped().

◆ ED_view3d_win_to_segment_clipped()

bool ED_view3d_win_to_segment_clipped ( struct Depsgraph depsgraph,
const ARegion region,
View3D v3d,
const float  mval[2],
float  r_ray_start[3],
float  r_ray_end[3],
const 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 769 of file view3d_project.c.

References depsgraph, ED_view3d_clip_segment(), NULL, ARegion::regiondata, and view3d_win_to_ray_segment().

◆ ED_view3d_win_to_vector()

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

Calculate a 3d direction vector from 2d window coordinates. This direction vector starts and the view in the direction of the 2d window coordinates. In orthographic view all window coordinates yield 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 floats).
outThe resulting normalized world-space direction vector.

Definition at line 738 of file view3d_project.c.

References RegionView3D::is_persp, mul_project_m4_v3(), negate_v3_v3(), normalize_v3(), RegionView3D::persinv, ARegion::regiondata, sub_v3_v3(), RegionView3D::viewinv, ARegion::winx, and ARegion::winy.

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

◆ view3d_win_to_ray_segment()

static void view3d_win_to_ray_segment ( struct 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