fix [#35007] clipping border error

add clip option to ED_view3d_win_to_ray(), ED_view3d_win_to_segment()
This commit is contained in:
Campbell Barton 2013-04-22 20:00:37 +00:00
parent 556705f84e
commit 36e7a98459
8 changed files with 43 additions and 43 deletions

@ -904,7 +904,7 @@ static void sk_interpolateDepth(bContext *C, SK_Stroke *stk, int start, int end,
float pval[2] = {0, 0}; float pval[2] = {0, 0};
ED_view3d_project_float_global(ar, stk->points[i].p, pval, V3D_PROJ_TEST_NOP); ED_view3d_project_float_global(ar, stk->points[i].p, pval, V3D_PROJ_TEST_NOP);
ED_view3d_win_to_ray(ar, v3d, pval, ray_start, ray_normal); ED_view3d_win_to_ray(ar, v3d, pval, ray_start, ray_normal, false);
mul_v3_fl(ray_normal, distance * progress / length); mul_v3_fl(ray_normal, distance * progress / length);
add_v3_v3(stk->points[i].p, ray_normal); add_v3_v3(stk->points[i].p, ray_normal);
@ -1557,7 +1557,7 @@ static int sk_getIntersections(bContext *C, ListBase *list, SK_Sketch *sketch, S
mval[0] = vi[0]; mval[0] = vi[0];
mval[1] = vi[1]; mval[1] = vi[1];
ED_view3d_win_to_segment_clip(ar, v3d, mval, ray_start, ray_end); ED_view3d_win_to_segment(ar, v3d, mval, ray_start, ray_end, true);
isect_line_line_v3(stk->points[s_i].p, isect_line_line_v3(stk->points[s_i].p,
stk->points[s_i + 1].p, stk->points[s_i + 1].p,

@ -196,16 +196,15 @@ eV3DProjStatus ED_view3d_project_float_global(const struct ARegion *ar, const fl
eV3DProjStatus ED_view3d_project_float_object(const struct ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag); eV3DProjStatus ED_view3d_project_float_object(const struct ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag);
float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip); float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip);
void ED_view3d_win_to_ray(const struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3]); bool ED_view3d_win_to_ray(const struct ARegion *ar, struct View3D *v3d, const float mval[2],
float ray_start[3], float ray_normal[3], const bool do_clip);
void ED_view3d_global_to_vector(const struct RegionView3D *rv3d, const float coord[3], float vec[3]); void ED_view3d_global_to_vector(const struct RegionView3D *rv3d, const float coord[3], float vec[3]);
void ED_view3d_win_to_3d(const struct ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]); void ED_view3d_win_to_3d(const struct ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]);
void ED_view3d_win_to_3d_int(const struct ARegion *ar, const float depth_pt[3], const int mval[2], float out[3]); void ED_view3d_win_to_3d_int(const struct ARegion *ar, const float depth_pt[3], const int mval[2], float out[3]);
void ED_view3d_win_to_delta(const struct ARegion *ar, const float mval[2], float out[3], const float zfac); void ED_view3d_win_to_delta(const struct ARegion *ar, const float mval[2], float out[3], const float zfac);
void ED_view3d_win_to_vector(const struct ARegion *ar, const float mval[2], float out[3]); void ED_view3d_win_to_vector(const struct ARegion *ar, const float mval[2], float out[3]);
void ED_view3d_win_to_segment(const struct ARegion *ar, struct View3D *v3d, const float mval[2], bool ED_view3d_win_to_segment(const struct ARegion *ar, struct View3D *v3d, const float mval[2],
float ray_start[3], float ray_end[3]); float r_ray_start[3], float r_ray_end[3], const bool do_clip);
bool ED_view3d_win_to_segment_clip(const struct ARegion *ar, struct View3D *v3d, const float mval[2],
float ray_start[3], float ray_end[3]);
void ED_view3d_ob_project_mat_get(const struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]); void ED_view3d_ob_project_mat_get(const struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]);
void ED_view3d_unproject(struct bglMats *mats, float out[3], const float x, const float y, const float z); void ED_view3d_unproject(struct bglMats *mats, float out[3], const float x, const float y, const float z);

@ -1394,8 +1394,8 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
return; return;
/* unproject screen line */ /* unproject screen line */
ED_view3d_win_to_segment_clip(kcd->ar, kcd->vc.v3d, s1, v1, v3); ED_view3d_win_to_segment(kcd->ar, kcd->vc.v3d, s1, v1, v3, true);
ED_view3d_win_to_segment_clip(kcd->ar, kcd->vc.v3d, s2, v2, v4); ED_view3d_win_to_segment(kcd->ar, kcd->vc.v3d, s2, v2, v4, true);
mul_m4_v3(kcd->ob->imat, v1); mul_m4_v3(kcd->ob->imat, v1);
mul_m4_v3(kcd->ob->imat, v2); mul_m4_v3(kcd->ob->imat, v2);

@ -1418,7 +1418,7 @@ bool BMBVH_EdgeVisible(struct BMBVHTree *tree, BMEdge *e, ARegion *ar, View3D *v
const float mval_f[2] = {ar->winx / 2.0f, const float mval_f[2] = {ar->winx / 2.0f,
ar->winy / 2.0f}; ar->winy / 2.0f};
ED_view3d_win_to_segment(ar, v3d, mval_f, origin, end); ED_view3d_win_to_segment(ar, v3d, mval_f, origin, end, false);
invert_m4_m4(invmat, obedit->obmat); invert_m4_m4(invmat, obedit->obmat);
mul_m4_v3(invmat, origin); mul_m4_v3(invmat, origin);

@ -3293,7 +3293,7 @@ static int brush_add(PEData *data, short number)
mco[0] = data->mval[0] + dmx; mco[0] = data->mval[0] + dmx;
mco[1] = data->mval[1] + dmy; mco[1] = data->mval[1] + dmy;
ED_view3d_win_to_segment_clip(data->vc.ar, data->vc.v3d, mco, co1, co2); ED_view3d_win_to_segment(data->vc.ar, data->vc.v3d, mco, co1, co2, true);
mul_m4_v3(imat, co1); mul_m4_v3(imat, co1);
mul_m4_v3(imat, co2); mul_m4_v3(imat, co2);

@ -4102,7 +4102,7 @@ int sculpt_stroke_get_location(bContext *C, float out[3], const float mouse[2])
sculpt_stroke_modifiers_check(C, ob); sculpt_stroke_modifiers_check(C, ob);
/* TODO: what if the segment is totally clipped? (return == 0) */ /* TODO: what if the segment is totally clipped? (return == 0) */
ED_view3d_win_to_segment_clip(vc.ar, vc.v3d, mouse, ray_start, ray_end); ED_view3d_win_to_segment(vc.ar, vc.v3d, mouse, ray_start, ray_end, true);
invert_m4_m4(obimat, ob->obmat); invert_m4_m4(obimat, ob->obmat);
mul_m4_v3(obimat, ray_start); mul_m4_v3(obimat, ray_start);

@ -307,14 +307,18 @@ float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_f
* \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 ray_start The world-space starting point of the segment. * \param ray_start The world-space starting point of the segment.
* \param ray_normal The normalized world-space direction of towards mval. * \param ray_normal The normalized world-space direction of towards mval.
* \return success, false if the segment is totally clipped.
*/ */
void ED_view3d_win_to_ray(const ARegion *ar, View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3]) bool ED_view3d_win_to_ray(const ARegion *ar, View3D *v3d, const float mval[2],
float r_ray_start[3], float r_ray_normal[3], const bool do_clip)
{ {
float ray_end[3]; float ray_end[3];
bool is_clip;
ED_view3d_win_to_segment(ar, v3d, mval, ray_start, ray_end); is_clip = ED_view3d_win_to_segment(ar, v3d, mval, r_ray_start, ray_end, do_clip);
sub_v3_v3v3(ray_normal, ray_end, ray_start); sub_v3_v3v3(r_ray_normal, ray_end, r_ray_start);
normalize_v3(ray_normal); normalize_v3(r_ray_normal);
return is_clip;
} }
/** /**
@ -474,8 +478,22 @@ void ED_view3d_win_to_vector(const ARegion *ar, const float mval[2], float out[3
normalize_v3(out); normalize_v3(out);
} }
void ED_view3d_win_to_segment(const ARegion *ar, View3D *v3d, const float mval[2], /**
float ray_start[3], float ray_end[3]) * 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.
* \param ar The region (used for the window width and height).
* \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 r_ray_start The world-space starting 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.
* \return success, false if the segment is totally clipped.
*/
bool ED_view3d_win_to_segment(const ARegion *ar, View3D *v3d, const float mval[2],
float ray_start[3], float ray_end[3], const bool do_clip)
{ {
RegionView3D *rv3d = ar->regiondata; RegionView3D *rv3d = ar->regiondata;
@ -499,29 +517,9 @@ void ED_view3d_win_to_segment(const ARegion *ar, View3D *v3d, const float mval[2
madd_v3_v3v3fl(ray_start, vec, rv3d->viewinv[2], 1000.0f); madd_v3_v3v3fl(ray_start, vec, rv3d->viewinv[2], 1000.0f);
madd_v3_v3v3fl(ray_end, vec, rv3d->viewinv[2], -1000.0f); madd_v3_v3v3fl(ray_end, vec, rv3d->viewinv[2], -1000.0f);
} }
}
/** /* bounds clipping */
* Calculate a 3d segment from 2d window coordinates. if (do_clip && (rv3d->rflag & RV3D_CLIPPING)) {
* 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.
* \param ar The region (used for the window width and height).
* \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 ray_start The world-space starting point of the segment.
* \param ray_end The world-space end point of the segment.
* \return success, false if the segment is totally clipped.
*/
bool ED_view3d_win_to_segment_clip(const ARegion *ar, View3D *v3d, const float mval[2],
float ray_start[3], float ray_end[3])
{
RegionView3D *rv3d = ar->regiondata;
ED_view3d_win_to_segment(ar, v3d, mval, ray_start, ray_end);
/* clipping */
if (rv3d->rflag & RV3D_CLIPPING) {
if (clip_segment_v3_plane_n(ray_start, ray_end, rv3d->clip, 6) == false) { if (clip_segment_v3_plane_n(ray_start, ray_end, rv3d->clip, 6) == false) {
return false; return false;
} }
@ -530,7 +528,6 @@ bool ED_view3d_win_to_segment_clip(const ARegion *ar, View3D *v3d, const float m
return true; return true;
} }
/* Utility functions for projection /* Utility functions for projection
* ******************************** */ * ******************************** */

@ -1606,7 +1606,9 @@ static bool snapObjects(Scene *scene, short snap_mode, Base *base_act, View3D *v
float ray_start[3], ray_normal[3]; float ray_start[3], ray_normal[3];
float ray_dist = TRANSFORM_DIST_MAX_RAY; float ray_dist = TRANSFORM_DIST_MAX_RAY;
ED_view3d_win_to_ray(ar, v3d, mval, ray_start, ray_normal); if (ED_view3d_win_to_ray(ar, v3d, mval, ray_start, ray_normal, true) == false) {
return false;
}
return snapObjectsRay(scene, snap_mode, base_act, v3d, ar, obedit, return snapObjectsRay(scene, snap_mode, base_act, v3d, ar, obedit,
ray_start, ray_normal, &ray_dist, ray_start, ray_normal, &ray_dist,
@ -1811,7 +1813,9 @@ static bool peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit,
bool retval = false; bool retval = false;
float ray_start[3], ray_normal[3]; float ray_start[3], ray_normal[3];
ED_view3d_win_to_ray(ar, v3d, mval, ray_start, ray_normal); if (ED_view3d_win_to_ray(ar, v3d, mval, ray_start, ray_normal, true) == false) {
return false;
}
for (base = scene->base.first; base != NULL; base = base->next) { for (base = scene->base.first; base != NULL; base = base->next) {
if (BASE_SELECTABLE(v3d, base)) { if (BASE_SELECTABLE(v3d, base)) {