25 #define BL_ZERO_CLIP 0.001
33 const float mat[4][4])
43 if (
vec4[3] > FLT_EPSILON) {
55 const float mat[4][4])
65 if (
vec4[3] > FLT_EPSILON) {
96 const float perspmat[4][4],
133 const float scalar = (
w != 0.0f) ? (1.0f /
w) : 0.0f;
134 const float fx = ((
float)region->
winx / 2.0f) * (1.0f + (
vec4[0] * scalar));
135 const float fy = ((
float)region->
winy / 2.0f) * (1.0f + (
vec4[1] * scalar));
138 (fx <= 0.0f || fy <= 0.0f || fx >= (
float)region->
winx || fy >= (
float)region->
winy)) {
149 float perspmat[4][4],
158 if ((tvec[0] > -32700.0f && tvec[0] < 32700.0f) &&
159 (tvec[1] > -32700.0f && tvec[1] < 32700.0f)) {
160 r_co[0] = (short)
floorf(tvec[0]);
161 r_co[1] = (short)
floorf(tvec[1]);
171 float perspmat[4][4],
180 if ((tvec[0] > -2140000000.0f && tvec[0] < 2140000000.0f) &&
181 (tvec[1] > -2140000000.0f && tvec[1] < 2140000000.0f)) {
182 r_co[0] = (int)
floorf(tvec[0]);
183 r_co[1] = (int)
floorf(tvec[1]);
193 float perspmat[4][4],
284 *r_flip = (zfac < 0.0f);
289 if (zfac < 1.e-6f && zfac > -1.e-6f) {
321 float r_ray_start[3],
325 float _ray_co[3], _ray_dir[3], start_offset, end_offset;
331 r_ray_dir = _ray_dir;
339 start_offset = -end_offset;
367 float r_ray_normal[3],
368 float r_ray_start[3],
374 depsgraph, region, v3d, mval, r_ray_co, r_ray_normal, r_ray_start, ray_end);
377 if (do_clip_planes) {
388 float r_ray_start[3],
389 float r_ray_normal[3],
390 const bool do_clip_planes)
393 depsgraph, region, v3d, mval,
NULL, r_ray_normal, r_ray_start, do_clip_planes);
398 float r_ray_start[3],
399 float r_ray_normal[3])
430 bool view3d_get_view_aligned_coordinate(
ARegion *region,
433 const bool do_fallback)
443 const float mval_f[2] = {(
float)(mval_cpy[0] - mval[0]), (
float)(mval_cpy[1] - mval[1])};
454 return view3d_get_view_aligned_coordinate(region, fp, mval,
false);
465 const float depth_pt[3],
472 float ray_direction[3];
487 lambda =
fabsf(lambda);
490 float dx = (2.0f * mval[0] / (
float)region->
winx) - 1.0f;
491 float dy = (2.0f * mval[1] / (
float)region->
winy) - 1.0f;
499 const float aspy = region->
winy / (
float)region->
winx;
500 const float shiftx = cam->
shiftx * 0.5f *
502 const float shifty = cam->
shifty * 0.5f *
505 dx += (rv3d->
camdx + shiftx) * zoomfac;
506 dy += (rv3d->
camdy + shifty) * zoomfac;
521 const float depth_pt[3],
525 const float mval_fl[2] = {mval[0], mval[1]};
530 const float plane[4],
537 const bool do_clip_ray_plane = do_clip && !ray_co_is_centered;
538 float ray_co[3], ray_no[3];
547 if (do_clip && (do_clip_ray_plane ==
false)) {
552 if (z_offset > 1.0f) {
562 const float plane[4],
567 const float mval_fl[2] = {mval[0], mval[1]};
572 const float plane[4],
575 const float plane_fallback[4],
578 float isect_co[3], isect_no[3];
607 const float xy_delta[2],
614 dx = 2.0f * xy_delta[0] * zfac / region->
winx;
615 dy = 2.0f * xy_delta[1] * zfac / region->
winy;
629 r_out[0] = 2.0f * mval[0] / region->
winx - 1.0f;
630 r_out[1] = 2.0f * mval[1] / region->
winy - 1.0f;
648 r_out[0] = 2.0f * (mval[0] / region->
winx) - 1.0f;
649 r_out[1] = 2.0f * (mval[1] / region->
winy) - 1.0f;
664 float r_ray_start[3],
666 const bool do_clip_planes)
671 if (do_clip_planes) {
691 const float obmat[4][4],
704 const int viewport[4] = {0, 0, region->
winx, region->
winy};
712 const int viewport[4] = {0, 0, region->
winx, region->
winy};
717 const struct ARegion *region,
float regionx,
float regiony,
float regionz,
float world[3])
720 const int viewport[4] = {0, 0, region->
winx, region->
winy};
721 const float region_co[3] = {regionx, regiony, regionz};
typedef float(TangentPoint)[2]
Camera data-block and utility functions.
int BKE_camera_sensor_fit(int sensor_fit, float sizex, float sizey)
float BKE_screen_view3d_zoom_to_fac(float camzoom)
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
bool clip_segment_v3_plane_n(const float p1[3], const float p2[3], const float plane_array[][4], int plane_num, float r_p1[3], float r_p2[3])
bool isect_ray_plane_v3(const float ray_origin[3], const float ray_direction[3], const float plane[4], float *r_lambda, bool clip)
bool isect_plane_plane_v3(const float plane_a[4], const float plane_b[4], float r_isect_co[3], float r_isect_no[3]) ATTR_WARN_UNUSED_RESULT
float ray_point_factor_v3(const float p[3], const float ray_origin[3], const float ray_direction[3])
void closest_to_plane_v3(float r_close[3], const float plane[4], const float pt[3])
void mul_project_m4_v3(const float M[4][4], float vec[3])
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void mul_m4_v4(const float M[4][4], float r[4])
void copy_m4_m3(float m1[4][4], const float m2[3][3])
void transform_pivot_set_m4(float mat[4][4], const float pivot[3])
void mul_m4_v3(const float M[4][4], float r[3])
void rotation_between_vecs_to_mat3(float m[3][3], const float v1[3], const float v2[3])
MINLINE float normalize_v3(float r[3])
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float dot_m4_v3_row_z(const float M[4][4], const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v2(float r[2])
MINLINE float mul_project_m4_v3_zfac(const float mat[4][4], const float co[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE void zero_v3(float r[3])
struct Depsgraph Depsgraph
Object is a sort of wrapper for general info.
bool ED_view3d_clip_range_get(const struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d, float *r_clipsta, float *r_clipend, bool use_ortho_factor)
@ V3D_PROJ_TEST_CLIP_NEAR
@ V3D_PROJ_TEST_CLIP_ZERO
bool ED_view3d_clipping_test(const struct RegionView3D *rv3d, const float co[3], bool is_local)
#define V3D_PROJ_TEST_CLIP_DEFAULT
#define V3D_PROJ_TEST_ALL
#define ED_view3d_check_mats_rv3d(rv3d)
void GPU_matrix_project_2fv(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float r_win[2])
bool GPU_matrix_unproject_3fv(const float win[3], const float model_inverted[4][4], const float proj[4][4], const int view[4], float r_world[3])
void GPU_matrix_project_3fv(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float r_win[3])
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
const Depsgraph * depsgraph
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])
void ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob, float r_pmat[4][4])
void ED_view3d_project_float_v3_m4(const ARegion *region, const float co[3], float r_co[3], const float mat[4][4])
void ED_view3d_win_to_ray(const ARegion *region, const float mval[2], float r_ray_start[3], float r_ray_normal[3])
eV3DProjStatus ED_view3d_project_base(const struct ARegion *region, struct Base *base)
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_float_object(const ARegion *region, const float co[3], float r_co[2], const eV3DProjTest flag)
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_3d_int(const View3D *v3d, const ARegion *region, const float depth_pt[3], const int mval[2], float r_out[3])
float ED_view3d_pixel_size_no_ui_scale(const RegionView3D *rv3d, const float co[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])
bool ED_view3d_win_to_segment_clipped(const struct 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)
void ED_view3d_project_v3(const struct ARegion *region, const float world[3], float r_region_co[3])
void ED_view3d_win_to_delta(const ARegion *region, const float xy_delta[2], const float zfac, float r_out[3])
float ED_view3d_calc_depth_for_comparison(const RegionView3D *rv3d, const float co[3])
float ED_view3d_pixel_size(const RegionView3D *rv3d, const float co[3])
bool ED_view3d_clip_segment(const RegionView3D *rv3d, float ray_start[3], float ray_end[3])
static void view3d_win_to_ray_segment(const 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])
eV3DProjStatus ED_view3d_project_float_global(const ARegion *region, const float co[3], float 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_short_global(const ARegion *region, const float co[3], short r_co[2], const eV3DProjTest flag)
bool ED_view3d_unproject_v3(const struct ARegion *region, float regionx, float regiony, float regionz, float world[3])
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)
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_global_to_vector(const RegionView3D *rv3d, const float coord[3], float vec[3])
float ED_view3d_calc_zfac_ex(const RegionView3D *rv3d, const float co[3], bool *r_flip)
void ED_view3d_win_to_origin(const ARegion *region, const float mval[2], float r_out[3])
float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3])
void ED_view3d_project_v2(const struct ARegion *region, const float world[3], float r_region_co[2])
void ED_view3d_ob_project_mat_get_from_obmat(const RegionView3D *rv3d, const float obmat[4][4], float r_pmat[4][4])
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_object(const ARegion *region, const float co[3], short r_co[2], const eV3DProjTest flag)
void ED_view3d_win_to_vector(const ARegion *region, const float mval[2], float r_out[3])
void ED_view3d_project_float_v2_m4(const ARegion *region, const float co[3], float r_co[2], const float mat[4][4])
eV3DProjStatus ED_view3d_project_int_global(const ARegion *region, const float co[3], int r_co[2], const eV3DProjTest flag)
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)
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_3d_on_plane_int(const ARegion *region, const float plane[4], const int mval[2], const bool do_clip, float r_out[3])