41 #define BL_ZERO_CLIP 0.001
62 if (vec4[3] > FLT_EPSILON) {
63 r_co[0] = (
float)(region->
winx / 2.0f) + (region->
winx / 2.0f) * vec4[0] / vec4[3];
64 r_co[1] = (
float)(region->
winy / 2.0f) + (region->
winy / 2.0f) * vec4[1] / vec4[3];
87 if (vec4[3] > FLT_EPSILON) {
88 r_co[0] = (
float)(region->
winx / 2.0f) + (region->
winx / 2.0f) * vec4[0] / vec4[3];
89 r_co[1] = (
float)(region->
winy / 2.0f) + (region->
winy / 2.0f) * vec4[1] / vec4[3];
90 r_co[2] = vec4[2] / vec4[3];
118 const float perspmat[4][4],
141 const float w =
fabsf(vec4[3]);
155 const float scalar = (
w != 0.0f) ? (1.0f /
w) : 0.0f;
156 const float fx = ((
float)region->
winx / 2.0f) * (1.0f + (vec4[0] * scalar));
157 const float fy = ((
float)region->
winy / 2.0f) * (1.0f + (vec4[1] * scalar));
160 (fx <= 0.0f || fy <= 0.0f || fx >= (
float)region->
winx || fy >= (
float)region->
winy)) {
171 float perspmat[4][4],
180 if ((tvec[0] > -32700.0f && tvec[0] < 32700.0f) &&
181 (tvec[1] > -32700.0f && tvec[1] < 32700.0f)) {
182 r_co[0] = (short)
floorf(tvec[0]);
183 r_co[1] = (short)
floorf(tvec[1]);
193 float perspmat[4][4],
202 if ((tvec[0] > -2140000000.0f && tvec[0] < 2140000000.0f) &&
203 (tvec[1] > -2140000000.0f && tvec[1] < 2140000000.0f)) {
204 r_co[0] = (int)
floorf(tvec[0]);
205 r_co[1] = (int)
floorf(tvec[1]);
215 float perspmat[4][4],
315 *r_flip = (zfac < 0.0f);
320 if (zfac < 1.e-6f && zfac > -1.e-6f) {
339 float r_ray_start[3],
343 float _ray_co[3], _ray_dir[3], start_offset, end_offset;
349 r_ray_dir = _ray_dir;
357 start_offset = -end_offset;
401 float r_ray_normal[3],
402 float r_ray_start[3],
408 depsgraph, region, v3d, mval, r_ray_co, r_ray_normal, r_ray_start, ray_end);
411 if (do_clip_planes) {
435 float r_ray_start[3],
436 float r_ray_normal[3],
437 const bool do_clip_planes)
440 depsgraph, region, v3d, mval,
NULL, r_ray_normal, r_ray_start, do_clip_planes);
456 float r_ray_start[3],
457 float r_ray_normal[3])
495 bool view3d_get_view_aligned_coordinate(
ARegion *region,
498 const bool do_fallback)
508 const float mval_f[2] = {(
float)(mval_cpy[0] - mval[0]), (
float)(mval_cpy[1] - mval[1])};
519 return view3d_get_view_aligned_coordinate(region, fp, mval,
false);
537 const float depth_pt[3],
544 float ray_direction[3];
559 lambda =
fabsf(lambda);
562 float dx = (2.0f * mval[0] / (
float)region->
winx) - 1.0f;
563 float dy = (2.0f * mval[1] / (
float)region->
winy) - 1.0f;
571 const float aspy = region->
winy / (
float)region->
winx;
572 const float shiftx = cam->
shiftx * 0.5f *
574 const float shifty = cam->
shifty * 0.5f *
577 dx += (rv3d->
camdx + shiftx) * zoomfac;
578 dy += (rv3d->
camdy + shifty) * zoomfac;
593 const float depth_pt[3],
597 const float mval_fl[2] = {mval[0], mval[1]};
602 const float plane[4],
607 float ray_co[3], ray_no[3];
619 const float plane[4],
624 const float mval_fl[2] = {mval[0], mval[1]};
636 const float plane[4],
639 const float plane_fallback[4],
642 float isect_co[3], isect_no[3];
686 dx = 2.0f * mval[0] * zfac / region->
winx;
687 dy = 2.0f * mval[1] * zfac / region->
winy;
711 out[0] = 2.0f * mval[0] / region->
winx - 1.0f;
712 out[1] = 2.0f * mval[1] / region->
winy - 1.0f;
743 out[0] = 2.0f * (mval[0] / region->
winx) - 1.0f;
744 out[1] = 2.0f * (mval[1] / region->
winy) - 1.0f;
773 float r_ray_start[3],
775 const bool do_clip_planes)
780 if (do_clip_planes) {
800 const float obmat[4][4],
816 const int viewport[4] = {0, 0, region->
winx, region->
winy};
822 const struct ARegion *region,
float regionx,
float regiony,
float regionz,
float world[3])
825 const int viewport[4] = {0, 0, region->
winx, region->
winy};
826 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 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])
bool clip_segment_v3_plane_n(const float p1[3], const float p2[3], const float plane_array[][4], const int plane_tot, 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, const bool clip)
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 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.
@ V3D_PROJ_TEST_CLIP_NEAR
@ V3D_PROJ_TEST_CLIP_ZERO
#define V3D_PROJ_TEST_CLIP_DEFAULT
bool ED_view3d_clip_range_get(struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d, float *r_clipsta, float *r_clipend, const bool use_ortho_factor)
#define V3D_PROJ_TEST_ALL
bool ED_view3d_clipping_test(const struct RegionView3D *rv3d, const float co[3], const bool is_local)
#define ED_view3d_check_mats_rv3d(rv3d)
void GPU_matrix_project(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float r_win[3])
bool GPU_matrix_unproject(const float win[3], const float model[4][4], const float proj[4][4], const int view[4], float r_world[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])
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)
void ED_view3d_win_to_ray(const ARegion *region, const float mval[2], float r_ray_start[3], float r_ray_normal[3])
float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_flip)
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)
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_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])
void ED_view3d_win_to_delta(const ARegion *region, const float mval[2], float out[3], const float zfac)
void ED_view3d_project_float_v3_m4(const ARegion *region, const float co[3], float r_co[3], float mat[4][4])
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])
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)
void ED_view3d_win_to_origin(const ARegion *region, const float mval[2], float out[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)
void ED_view3d_win_to_vector(const ARegion *region, const float mval[2], float out[3])
void ED_view3d_project_float_v2_m4(const ARegion *region, const float co[3], float r_co[2], float mat[4][4])
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_project(const struct ARegion *region, const float world[3], float r_region_co[3])
void ED_view3d_global_to_vector(const RegionView3D *rv3d, const float coord[3], float vec[3])
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)
void ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, Object *ob, float r_pmat[4][4])
eV3DProjStatus ED_view3d_project_short_object(const ARegion *region, const float co[3], short r_co[2], const eV3DProjTest flag)
bool ED_view3d_unproject(const struct ARegion *region, float regionx, float regiony, float regionz, float world[3])
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])