diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-09-20 08:56:24 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-09-20 08:56:24 +0400 |
commit | edb78d090cca36110290f8f37d27767d75894a1a (patch) | |
tree | 792844cfe7e78cbf8a679328a742ae4fee73fab4 | |
parent | f169643d46ce05d1ac1054d15e280e15b8d78abc (diff) |
code cleanup:
- make view3d project names more consistent.
- remove apply_project_float() its not needed.
- update comments referencing an old function name.
- move doxygen docs into the C file, prefer they are kept here to avoid getting out of sync with code.
24 files changed, 252 insertions, 277 deletions
diff --git a/source/blender/blenlib/intern/uvproject.c b/source/blender/blenlib/intern/uvproject.c index 1b59dc6a3f5..05ebc9500a1 100644 --- a/source/blender/blenlib/intern/uvproject.c +++ b/source/blender/blenlib/intern/uvproject.c @@ -105,7 +105,7 @@ void BLI_uvproject_from_view(float target[2], float source[3], float persmat[4][ /* rotmat is the object matrix in this case */ mul_m4_v4(rotmat, pv4); - /* almost project_short */ + /* almost ED_view3d_project_short */ mul_m4_v4(persmat, pv4); if (fabsf(pv4[3]) > 0.00001f) { /* avoid division by zero */ target[0] = winx / 2.0f + (winx / 2.0f) * pv4[0] / pv4[3]; diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c index 78d3d8dc64d..f3f985fa97d 100644 --- a/source/blender/editors/armature/editarmature_sketch.c +++ b/source/blender/editors/armature/editarmature_sketch.c @@ -644,7 +644,7 @@ static SK_Point *sk_snapPointStroke(bContext *C, SK_Stroke *stk, int mval[2], in short pval[2]; int pdist; - project_short_noclip(ar, stk->points[i].p, pval); + ED_view3d_project_short_noclip(ar, stk->points[i].p, pval); pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]); @@ -679,7 +679,7 @@ static SK_Point *sk_snapPointArmature(bContext *C, Object *ob, ListBase *ebones, { copy_v3_v3(vec, bone->head); mul_m4_v3(ob->obmat, vec); - project_short_noclip(ar, vec, pval); + ED_view3d_project_short_noclip(ar, vec, pval); pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]); @@ -695,7 +695,7 @@ static SK_Point *sk_snapPointArmature(bContext *C, Object *ob, ListBase *ebones, copy_v3_v3(vec, bone->tail); mul_m4_v3(ob->obmat, vec); - project_short_noclip(ar, vec, pval); + ED_view3d_project_short_noclip(ar, vec, pval); pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]); @@ -907,7 +907,7 @@ static void sk_interpolateDepth(bContext *C, SK_Stroke *stk, int start, int end, float delta = len_v3v3(stk->points[i].p, stk->points[i + 1].p); float pval[2]; - project_float(ar, stk->points[i].p, pval); + ED_view3d_project_float(ar, stk->points[i].p, pval); ED_view3d_win_to_ray(ar, v3d, pval, ray_start, ray_normal); mul_v3_fl(ray_normal, distance * progress / length); @@ -934,7 +934,7 @@ static void sk_projectDrawPoint(bContext *C, float vec[3], SK_Stroke *stk, SK_Dr initgrabz(ar->regiondata, fp[0], fp[1], fp[2]); /* method taken from editview.c - mouse_cursor() */ - project_short_noclip(ar, fp, cval); + ED_view3d_project_short_noclip(ar, fp, cval); VECSUB2D(mval_f, cval, dd->mval); ED_view3d_win_to_delta(ar, mval_f, dvec); sub_v3_v3v3(vec, fp, dvec); @@ -1453,8 +1453,8 @@ static int sk_getSelfIntersections(bContext *C, ListBase *list, SK_Stroke *gestu float s_p2[3] = {0, 0, 0}; int g_i; - project_float(ar, gesture->points[s_i].p, s_p1); - project_float(ar, gesture->points[s_i + 1].p, s_p2); + ED_view3d_project_float(ar, gesture->points[s_i].p, s_p1); + ED_view3d_project_float(ar, gesture->points[s_i + 1].p, s_p2); /* start checking from second next, because two consecutive cannot intersect */ for (g_i = s_i + 2; g_i < gesture->nb_points - 1; g_i++) { @@ -1463,8 +1463,8 @@ static int sk_getSelfIntersections(bContext *C, ListBase *list, SK_Stroke *gestu float vi[3]; float lambda; - project_float(ar, gesture->points[g_i].p, g_p1); - project_float(ar, gesture->points[g_i + 1].p, g_p2); + ED_view3d_project_float(ar, gesture->points[g_i].p, g_p1); + ED_view3d_project_float(ar, gesture->points[g_i + 1].p, g_p2); if (isect_line_line_strict_v3(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) { SK_Intersection *isect = MEM_callocN(sizeof(SK_Intersection), "Intersection"); @@ -1531,8 +1531,8 @@ static int sk_getIntersections(bContext *C, ListBase *list, SK_Sketch *sketch, S float s_p2[3] = {0, 0, 0}; int g_i; - project_float(ar, stk->points[s_i].p, s_p1); - project_float(ar, stk->points[s_i + 1].p, s_p2); + ED_view3d_project_float(ar, stk->points[s_i].p, s_p1); + ED_view3d_project_float(ar, stk->points[s_i + 1].p, s_p2); for (g_i = 0; g_i < gesture->nb_points - 1; g_i++) { float g_p1[3] = {0, 0, 0}; @@ -1540,8 +1540,8 @@ static int sk_getIntersections(bContext *C, ListBase *list, SK_Sketch *sketch, S float vi[3]; float lambda; - project_float(ar, gesture->points[g_i].p, g_p1); - project_float(ar, gesture->points[g_i + 1].p, g_p2); + ED_view3d_project_float(ar, gesture->points[g_i].p, g_p1); + ED_view3d_project_float(ar, gesture->points[g_i + 1].p, g_p2); if (isect_line_line_strict_v3(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) { SK_Intersection *isect = MEM_callocN(sizeof(SK_Intersection), "Intersection"); @@ -1784,8 +1784,8 @@ int sk_detectMergeGesture(bContext *C, SK_Gesture *gest, SK_Sketch *UNUSED(sketc short start_val[2], end_val[2]; short dist; - project_short_noclip(ar, gest->stk->points[0].p, start_val); - project_short_noclip(ar, sk_lastStrokePoint(gest->stk)->p, end_val); + ED_view3d_project_short_noclip(ar, gest->stk->points[0].p, start_val); + ED_view3d_project_short_noclip(ar, sk_lastStrokePoint(gest->stk)->p, end_val); dist = MAX2(ABS(start_val[0] - end_val[0]), ABS(start_val[1] - end_val[1])); diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 72a4037bf7d..8ba4985ffc4 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -278,7 +278,7 @@ static void gp_stroke_convertcoords(tGPsdata *p, const int mval[2], float out[3] gp_get_3d_reference(p, rvec); /* method taken from editview.c - mouse_cursor() */ - project_int_noclip(p->ar, rvec, mval_prj); + ED_view3d_project_int_noclip(p->ar, rvec, mval_prj); VECSUB2D(mval_f, mval_prj, mval); ED_view3d_win_to_delta(p->ar, mval_f, dvec); @@ -808,7 +808,7 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p, else if (gps->totpoints == 1) { /* get coordinates */ if (gps->flag & GP_STROKE_3DSPACE) { - project_int(p->ar, &gps->points->x, xyval); + ED_view3d_project_int(p->ar, &gps->points->x, xyval); x0 = xyval[0]; y0 = xyval[1]; } @@ -847,11 +847,11 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p, /* get coordinates */ if (gps->flag & GP_STROKE_3DSPACE) { - project_int(p->ar, &pt1->x, xyval); + ED_view3d_project_int(p->ar, &pt1->x, xyval); x0 = xyval[0]; y0 = xyval[1]; - project_int(p->ar, &pt2->x, xyval); + ED_view3d_project_int(p->ar, &pt2->x, xyval); x1 = xyval[0]; y1 = xyval[1]; } diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index b1bccfa32c5..9536dd76581 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -89,139 +89,45 @@ float *give_cursor(struct Scene *scene, struct View3D *v3d); int initgrabz(struct RegionView3D *rv3d, float x, float y, float z); -/** - * Calculate a 3d location from 2d window coordinates. - * \param ar The region (used for the window width and height). - * \param depth_pt The reference location used to calculate the Z depth. - * \param mval The area relative location (such as event->mval converted to floats). - * \param out The resulting world-space location. - */ void ED_view3d_win_to_3d(struct ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]); - -/** - * Calculate a 3d difference vector from 2d window offset. - * note that initgrabz() must be called first to determine - * the depth used to calculate the delta. - * \param ar The region (used for the window width and height). - * \param mval The area relative 2d difference (such as event->mval[0] - other_x). - * \param out The resulting world-space delta. - */ void ED_view3d_win_to_delta(struct ARegion *ar, 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. - * \param ar The region (used for the window width and height). - * \param mval The area relative 2d location (such as event->mval converted to floats). - * \param out The resulting normalized world-space direction vector. - */ void ED_view3d_win_to_vector(struct ARegion *ar, const float mval[2], float out[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 ray_start The world-space starting point of the segment. - * \param ray_end The world-space end point of the segment. - */ void ED_view3d_win_to_segment_clip(struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float 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. - * \param ar The region (used for the window width and height). - * \param v3d The 3d viewport (used for near clipping value). - * \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_normal The normalized world-space direction of towards mval. - */ void ED_view3d_win_to_ray(struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[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. - * \param rv3d The region (used for the window width and height). - * \param coord The world-space location. - * \param vec The resulting normalized vector. - */ void ED_view3d_global_to_vector(struct RegionView3D *rv3d, const float coord[3], float vec[3]); - -/** - * Calculate the view transformation matrix from RegionView3D input. - * The resulting matrix is equivalent to RegionView3D.viewinv - * \param mat The view 4x4 transformation matrix to calculate. - * \param ofs The view offset, normally from RegionView3D.ofs. - * \param quat The view rotation, quaternion normally from RegionView3D.viewquat. - * \param dist The view distance from ofs, normally from RegionView3D.dist. - */ void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], const float dist); - -/** - * Set the view transformation from a 4x4 matrix. - * \param mat The view 4x4 transformation matrix to assign. - * \param ofs The view offset, normally from RegionView3D.ofs. - * \param quat The view rotation, quaternion normally from RegionView3D.viewquat. - * \param dist The view distance from ofs, normally from RegionView3D.dist. - */ void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist); -/** - * Set the RegionView3D members from an objects transformation and optionally lens. - * \param ob The object to set the view to. - * \param ofs The view offset to be set, normally from RegionView3D.ofs. - * \param quat The view rotation to be set, quaternion normally from RegionView3D.viewquat. - * \param dist The view distance from ofs to be set, normally from RegionView3D.dist. - * \param lens The view lens angle set for cameras and lamps, normally from View3D.lens. - */ void ED_view3d_from_object(struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens); - -/** - * Set the object transformation from RegionView3D members. - * \param ob The object which has the transformation assigned. - * \param ofs The view offset, normally from RegionView3D.ofs. - * \param quat The view rotation, quaternion normally from RegionView3D.viewquat. - * \param dist The view distance from ofs, normally from RegionView3D.dist. - */ void ED_view3d_to_object(struct Object *ob, const float ofs[3], const float quat[4], const float dist); -//#if 0 /* UNUSED */ -void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z); -//#endif - /* Depth buffer */ -void ED_view3d_depth_update(struct ARegion *ar); +void ED_view3d_depth_update(struct ARegion *ar); float ED_view3d_depth_read_cached(struct ViewContext *vc, int x, int y); -void ED_view3d_depth_tag_update(struct RegionView3D *rv3d); +void ED_view3d_depth_tag_update(struct RegionView3D *rv3d); /* Projection */ #define IS_CLIPPED 12000 -void ED_view3d_calc_clipping(struct BoundBox *bb, float planes[4][4], struct bglMats *mats, const struct rcti *rect); - -void project_short(struct ARegion *ar, const float vec[3], short adr[2]); -void project_short_noclip(struct ARegion *ar, const float vec[3], short adr[2]); - -void project_int(struct ARegion *ar, const float vec[3], int adr[2]); -void project_int_noclip(struct ARegion *ar, const float vec[3], int adr[2]); - -void apply_project_float(float persmat[4][4], int winx, int winy, const float vec[], float adr[2]); -void project_float(struct ARegion *ar, const float vec[3], float adr[2]); -void project_float_noclip(struct ARegion *ar, const float vec[3], float adr[2]); - -int ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend); -int ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend); +/* TODO, these functions work quite differently, we should make them behave in a uniform way + * otherwise we can't be sure bugs are not added when we need to move from short->float types for eg + * - Campbell */ +void ED_view3d_project_short(struct ARegion *ar, const float co[3], short r_co[2]); +void ED_view3d_project_short_noclip(struct ARegion *ar, const float vec[3], short r_co[2]); +void ED_view3d_project_int(struct ARegion *ar, const float co[3], int r_co[2]); +void ED_view3d_project_int_noclip(struct ARegion *ar, const float co[3], int r_co[2]); +void ED_view3d_project_float(struct ARegion *ar, const float co[3], float r_co[2]); +void ED_view3d_project_float_noclip(struct ARegion *ar, const float co[3], float r_co[2]); +void ED_view3d_project_float_v2_m4(const struct ARegion *a, const float co[3], float r_co[2], float mat[4][4]); +void ED_view3d_project_float_v3_m4(struct ARegion *a, const float co[3], float r_co[3], float mat[4][4]); + +void ED_view3d_unproject(struct bglMats *mats, float out[3], const float x, const float y, const float z); + +int ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend); +int ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend); void ED_view3d_ob_project_mat_get(struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]); void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short no_shift); -void ED_view3d_project_float_v2(const struct ARegion *a, const float vec[3], float adr[2], float mat[4][4]); -void ED_view3d_project_float_v3(struct ARegion *a, const float vec[3], float adr[3], float mat[4][4]); void ED_view3d_calc_camera_border_size(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, float size_r[2]); /* drawobject.c iterators */ @@ -231,6 +137,7 @@ void mesh_foreachScreenFace(struct ViewContext *vc, void (*func)(void *userData, void nurbs_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct Nurb *nu, struct BPoint *bp, struct BezTriple *bezt, int beztindex, int x, int y), void *userData); void lattice_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct BPoint *bp, int x, int y), void *userData); +void ED_view3d_clipping_calc(struct BoundBox *bb, float planes[4][4], struct bglMats *mats, const struct rcti *rect); void ED_view3d_clipping_local(struct RegionView3D *rv3d, float mat[][4]); int ED_view3d_clipping_test(struct RegionView3D *rv3d, const float vec[3], const int is_local); void ED_view3d_clipping_set(struct RegionView3D *rv3d); diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index b6e0ffa865d..1dcbf574b44 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -224,7 +224,7 @@ static void knife_update_header(bContext *C, KnifeTool_OpData *kcd) static void knife_project_v3(KnifeTool_OpData *kcd, const float co[3], float sco[3]) { - ED_view3d_project_float_v3(kcd->ar, co, sco, kcd->projmat); + ED_view3d_project_float_v3_m4(kcd->ar, co, sco, kcd->projmat); } static void knife_pos_data_clear(KnifePosData *kpd) @@ -1205,7 +1205,7 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, } knife_project_v3(kcd, p, sp); - view3d_unproject(mats, view, sp[0], sp[1], 0.0f); + ED_view3d_unproject(mats, view, sp[0], sp[1], 0.0f); mul_m4_v3(kcd->ob->imat, view); if (kcd->cut_through) { @@ -1388,7 +1388,7 @@ static void knife_input_ray_cast(KnifeTool_OpData *kcd, const int mval_i[2], mval[1] = (float)mval_i[1]; /* unproject to find view ray */ - view3d_unproject(&mats, r_origin, mval[0], mval[1], 0.0f); + ED_view3d_unproject(&mats, r_origin, mval[0], mval[1], 0.0f); if (kcd->is_ortho) { negate_v3_v3(r_ray, kcd->vc.rv3d->viewinv[2]); diff --git a/source/blender/editors/mesh/editmesh_rip.c b/source/blender/editors/mesh/editmesh_rip.c index 4d4a890300f..53b877f2a6e 100644 --- a/source/blender/editors/mesh/editmesh_rip.c +++ b/source/blender/editors/mesh/editmesh_rip.c @@ -61,8 +61,8 @@ static float edbm_rip_rip_edgedist(ARegion *ar, float mat[][4], { float vec1[3], vec2[3]; - ED_view3d_project_float_v2(ar, co1, vec1, mat); - ED_view3d_project_float_v2(ar, co2, vec2, mat); + ED_view3d_project_float_v2_m4(ar, co1, vec1, mat); + ED_view3d_project_float_v2_m4(ar, co2, vec2, mat); /* TODO: use dist_squared_to_line_segment_v2() looks like we only ever use for comparison */ return dist_to_line_segment_v2(mvalf, vec1, vec2); @@ -97,11 +97,11 @@ static float edbm_rip_edge_side_measure(BMEdge *e, BMLoop *e_l, mid_v3_v3v3(cent, v1_other->co, v2_other->co); mid_v3_v3v3(mid, e->v1->co, e->v2->co); - ED_view3d_project_float_v2(ar, cent, cent, projectMat); - ED_view3d_project_float_v2(ar, mid, mid, projectMat); + ED_view3d_project_float_v2_m4(ar, cent, cent, projectMat); + ED_view3d_project_float_v2_m4(ar, mid, mid, projectMat); - ED_view3d_project_float_v2(ar, e->v1->co, e_v1_co, projectMat); - ED_view3d_project_float_v2(ar, e->v2->co, e_v2_co, projectMat); + ED_view3d_project_float_v2_m4(ar, e->v1->co, e_v1_co, projectMat); + ED_view3d_project_float_v2_m4(ar, e->v2->co, e_v2_co, projectMat); sub_v2_v2v2(vec, cent, mid); normalize_v2(vec); diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index e33b60c0ed5..4d4cc1e2ed1 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -1055,8 +1055,8 @@ static void mouse_mesh_loop(bContext *C, int mval[2], short extend, short ring) /* We can't be sure this has already been set... */ ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d); - project_float_noclip(vc.ar, eed->v1->co, v1_co); - project_float_noclip(vc.ar, eed->v2->co, v2_co); + ED_view3d_project_float_noclip(vc.ar, eed->v1->co, v1_co); + ED_view3d_project_float_noclip(vc.ar, eed->v2->co, v2_co); #if 0 printf("mouse to v1: %f\nmouse to v2: %f\n", len_squared_v2v2(mvalf, v1_co), len_squared_v2v2(mvalf, v2_co)); @@ -1084,7 +1084,7 @@ static void mouse_mesh_loop(bContext *C, int mval[2], short extend, short ring) float co[2], tdist; BM_face_calc_center_mean(f, cent); - project_float_noclip(vc.ar, cent, co); + ED_view3d_project_float_noclip(vc.ar, cent, co); tdist = len_squared_v2v2(mvalf, co); if (tdist < best_dist) { /* printf("Best face: %p (%f)\n", f, tdist);*/ diff --git a/source/blender/editors/mesh/editmesh_slide.c b/source/blender/editors/mesh/editmesh_slide.c index 86ea5bc8651..bd1d13f3528 100644 --- a/source/blender/editors/mesh/editmesh_slide.c +++ b/source/blender/editors/mesh/editmesh_slide.c @@ -388,10 +388,10 @@ static BMEdge *vtx_slide_nrst_in_frame(VertexSlideOp *vso, const float mval[2]) edge = vso->edge_frame[i]; mul_v3_m4v3(v1_proj, vso->obj->obmat, edge->v1->co); - project_float_noclip(vso->active_region, v1_proj, v1_proj); + ED_view3d_project_float_noclip(vso->active_region, v1_proj, v1_proj); mul_v3_m4v3(v2_proj, vso->obj->obmat, edge->v2->co); - project_float_noclip(vso->active_region, v2_proj, v2_proj); + ED_view3d_project_float_noclip(vso->active_region, v2_proj, v2_proj); dist = dist_to_line_segment_v2(mval, v1_proj, v2_proj); if (dist < min_dist) { @@ -455,10 +455,10 @@ static void vtx_slide_update(VertexSlideOp *vso, wmEvent *event) /* Project points onto screen and do interpolation in 2D */ mul_v3_m4v3(start_vtx_proj, vso->obj->obmat, vso->start_vtx->co); - project_float_noclip(vso->active_region, start_vtx_proj, start_vtx_proj); + ED_view3d_project_float_noclip(vso->active_region, start_vtx_proj, start_vtx_proj); mul_v3_m4v3(edge_other_proj, vso->obj->obmat, other->co); - project_float_noclip(vso->active_region, edge_other_proj, edge_other_proj); + ED_view3d_project_float_noclip(vso->active_region, edge_other_proj, edge_other_proj); closest_to_line_v2(closest_2d, mval_float, start_vtx_proj, edge_other_proj); diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 28f8064a38f..06d48d29f0e 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -163,7 +163,7 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, Object *obedit, BMEditMes float mval[2], vec[3], no_dummy[3]; int dist_dummy; mul_v3_m4v3(vec, obedit->obmat, eve->co); - project_float_noclip(ar, vec, mval); + ED_view3d_project_float_noclip(ar, vec, mval); if (snapObjectsContext(C, mval, &dist_dummy, vec, no_dummy, SNAP_NOT_OBEDIT)) { mul_v3_m4v3(eve->co, obedit->imat, vec); } @@ -761,8 +761,8 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent float co1[3], co2[3]; mul_v3_m4v3(co1, vc.obedit->obmat, eed->v1->co); mul_v3_m4v3(co2, vc.obedit->obmat, eed->v2->co); - project_float_noclip(vc.ar, co1, co1); - project_float_noclip(vc.ar, co2, co2); + ED_view3d_project_float_noclip(vc.ar, co1, co1); + ED_view3d_project_float_noclip(vc.ar, co2, co2); /* 2D rotate by 90d while adding. * (x, y) = (y, -x) @@ -2770,7 +2770,7 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) copy_v3_v3(co, bv->co); co[3] = 1.0f; mul_m4_v4(obedit->obmat, co); - project_float(ar, co, scr); + ED_view3d_project_float(ar, co, scr); BLI_ghash_insert(gh, bv, scr); } diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 191c831bd79..f2b7a2e9c22 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -1237,7 +1237,7 @@ int ED_mesh_pick_face_vert(bContext *C, Mesh *me, Object *ob, const int mval[2], const int v_idx = me->mloop[mp->loopstart + fidx].v; dm->getVertCo(dm, v_idx, co); mul_m4_v3(ob->obmat, co); - project_float_noclip(ar, co, sco); + ED_view3d_project_float_noclip(ar, co, sco); len = len_squared_v2v2(mval_f, sco); if (len < len_best) { len_best = len; diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index b7ce32aa10a..72bbcda2b5e 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -409,7 +409,7 @@ static int key_test_depth(PEData *data, const float co[3]) if ((v3d->drawtype<=OB_WIRE) || (v3d->flag & V3D_ZBUF_SELECT)==0) return 1; - project_short(data->vc.ar, co, wco); + ED_view3d_project_short(data->vc.ar, co, wco); if (wco[0] == IS_CLIPPED) return 0; @@ -447,7 +447,7 @@ static int key_inside_circle(PEData *data, float rad, const float co[3], float * float dx, dy, dist; int sco[2]; - project_int(data->vc.ar, co, sco); + ED_view3d_project_int(data->vc.ar, co, sco); if (sco[0] == IS_CLIPPED) return 0; @@ -473,7 +473,7 @@ static int key_inside_rect(PEData *data, const float co[3]) { int sco[2]; - project_int(data->vc.ar, co, sco); + ED_view3d_project_int(data->vc.ar, co, sco); if (sco[0] == IS_CLIPPED) return 0; @@ -1666,7 +1666,7 @@ int PE_lasso_select(bContext *C, int mcords[][2], short moves, short extend, sho LOOP_KEYS { copy_v3_v3(co, key->co); mul_m4_v3(mat, co); - project_int(ar, co, vertco); + ED_view3d_project_int(ar, co, vertco); if (BLI_lasso_is_point_inside(mcords, moves, vertco[0], vertco[1], IS_CLIPPED) && key_test_depth(&data, co)) { @@ -1686,7 +1686,7 @@ int PE_lasso_select(bContext *C, int mcords[][2], short moves, short extend, sho copy_v3_v3(co, key->co); mul_m4_v3(mat, co); - project_int(ar, co, vertco); + ED_view3d_project_int(ar, co, vertco); if (BLI_lasso_is_point_inside(mcords, moves, vertco[0], vertco[1], IS_CLIPPED) && key_test_depth(&data, co)) { @@ -2802,7 +2802,7 @@ static void brush_cut(PEData *data, int pa_index) cut=0; - project_int_noclip(ar, key->co, vertco); + ED_view3d_project_int_noclip(ar, key->co, vertco); x0= (float)vertco[0]; x1= (float)vertco[1]; @@ -2820,7 +2820,7 @@ static void brush_cut(PEData *data, int pa_index) else { /* calculate path time closest to root that was inside the circle */ for (k=1, key++; k<=keys; k++, key++) { - project_int_noclip(ar, key->co, vertco); + ED_view3d_project_int_noclip(ar, key->co, vertco); if (key_test_depth(data, key->co) == 0) { x0= (float)vertco[0]; diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index dec75aaa6ff..e14266c83a7 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -322,8 +322,8 @@ static int project_brush_radius(ViewContext *vc, add_v3_v3v3(offset, location, ortho); /* project the center of the brush, and the tangent point to the view onto the screen */ - project_float(vc->ar, location, p1); - project_float(vc->ar, offset, p2); + ED_view3d_project_float(vc->ar, location, p1); + ED_view3d_project_float(vc->ar, offset, p2); /* the distance between these points is the size of the projected brush in pixels */ return len_v2v2(p1, p2); diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c index e809267d076..25957157aa6 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.c +++ b/source/blender/editors/sculpt_paint/paint_hide.c @@ -251,7 +251,7 @@ static void clip_planes_from_rect(bContext *C, view3d_operator_needs_opengl(C); view3d_set_viewcontext(C, &vc); view3d_get_transformation(vc.ar, vc.rv3d, vc.obact, &mats); - ED_view3d_calc_clipping(&bb, clip_planes, &mats, rect); + ED_view3d_clipping_calc(&bb, clip_planes, &mats, rect); mul_m4_fl(clip_planes, -1.0f); } diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 3dc890de5c0..b8e365c4c8e 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -3136,7 +3136,7 @@ static void project_paint_begin(ProjPaintState *ps) ps->is_ortho = params.is_ortho; } - /* same as view3d_get_object_project_mat */ + /* same as #ED_view3d_ob_project_mat_get */ mult_m4_m4m4(vmat, viewmat, ps->ob->obmat); mult_m4_m4m4(ps->projectMat, winmat, vmat); } diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index df64e1c9d90..29a59651cf7 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -98,7 +98,7 @@ int paint_convert_bb_to_rect(rcti *rect, vec[1] = j ? bb_min[1] : bb_max[1]; vec[2] = k ? bb_min[2] : bb_max[2]; /* convert corner to screen space */ - ED_view3d_project_float_v2(ar, vec, proj, projection_mat); + ED_view3d_project_float_v2_m4(ar, vec, proj, projection_mat); /* expand 2D rectangle */ /* we could project directly to int? */ @@ -137,7 +137,7 @@ void paint_calc_redraw_planes(float planes[4][4], rect.ymin -= 2; rect.ymax += 2; - ED_view3d_calc_clipping(&bb, planes, &mats, &rect); + ED_view3d_clipping_calc(&bb, planes, &mats, &rect); mul_m4_fl(planes, -1.0f); } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 62bdb0ca063..bd6ddd1b99a 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -850,7 +850,7 @@ static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float vert_n float dist_squared; float vertco[2], delta[2]; - project_float_noclip(vc->ar, vert_nor, vertco); + ED_view3d_project_float_noclip(vc->ar, vert_nor, vertco); sub_v2_v2v2(delta, mval, vertco); dist_squared = dot_v2v2(delta, delta); /* len squared */ if (dist_squared > brush_size_pressure * brush_size_pressure) { diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index d8fb1e3aa59..2a778ada16a 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -771,7 +771,7 @@ static float tex_strength(SculptSession *ss, Brush *br, float point[3], if (ss->cache->radial_symmetry_pass) mul_m4_v3(ss->cache->symm_rot_mat_inv, symm_point); - ED_view3d_project_float_v2(ss->cache->vc->ar, symm_point, point_2d, ss->cache->projection_mat); + ED_view3d_project_float_v2_m4(ss->cache->vc->ar, symm_point, point_2d, ss->cache->projection_mat); if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) { /* keep coordinates relative to mouse */ diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 8da74787403..aab959949c6 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -2092,7 +2092,7 @@ static void mesh_foreachScreenVert__mapFunc(void *userData, int index, const flo else { float co2[2]; mul_v3_m4v3(co2, data->vc.obedit->obmat, co); - project_short_noclip(data->vc.ar, co2, s); + ED_view3d_project_short_noclip(data->vc.ar, co2, s); } if (s[0] != IS_CLIPPED) @@ -2169,8 +2169,8 @@ static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, const flo mul_v3_m4v3(v1_co, data->vc.obedit->obmat, v0co); mul_v3_m4v3(v2_co, data->vc.obedit->obmat, v1co); - project_short_noclip(data->vc.ar, v1_co, s[0]); - project_short_noclip(data->vc.ar, v2_co, s[1]); + ED_view3d_project_short_noclip(data->vc.ar, v1_co, s[0]); + ED_view3d_project_short_noclip(data->vc.ar, v2_co, s[1]); if (data->clipVerts == V3D_CLIP_TEST_REGION) { /* make an int copy */ @@ -2225,7 +2225,7 @@ static void mesh_foreachScreenFace__mapFunc(void *userData, int index, const flo short s[2]; mul_v3_m4v3(cent2, data->vc.obedit->obmat, cent); - project_short(data->vc.ar, cent2, s); + ED_view3d_project_short(data->vc.ar, cent2, s); if (s[0] != IS_CLIPPED) { data->func(data->userData, efa, s[0], s[1], index); @@ -6614,7 +6614,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short /* which wire color */ if ((dflag & DRAW_CONSTCOLOR) == 0) { - project_short(ar, ob->obmat[3], &base->sx); + ED_view3d_project_short(ar, ob->obmat[3], &base->sx); draw_object_wire_color(scene, base, _ob_wire_col, warning_recursive); ob_wire_col = _ob_wire_col; diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 8b1ecf437f3..025f420d976 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -559,7 +559,7 @@ static void drawcursor(Scene *scene, ARegion *ar, View3D *v3d) /* we don't want the clipping for cursor */ flag = v3d->flag; v3d->flag = 0; - project_int(ar, give_cursor(scene, v3d), co); + ED_view3d_project_int(ar, give_cursor(scene, v3d), co); v3d->flag = flag; mx = co[0]; @@ -1699,7 +1699,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, asp = ( (float)ibuf->y) / (float)ibuf->x; zero_v3(vec); - ED_view3d_project_float_v2(ar, vec, sco, rv3d->persmat); + ED_view3d_project_float_v2_m4(ar, vec, sco, rv3d->persmat); cx = sco[0]; cy = sco[1]; diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 726d95c31b9..430abef4934 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -3465,7 +3465,7 @@ static int view3d_clipping_exec(bContext *C, wmOperator *op) view3d_set_viewcontext(C, &vc); view3d_get_transformation(vc.ar, vc.rv3d, NULL, &mats); /* NULL because we don't want it in object space */ - ED_view3d_calc_clipping(rv3d->clipbb, rv3d->clip, &mats, &rect); + ED_view3d_clipping_calc(rv3d->clipbb, rv3d->clip, &mats, &rect); return OPERATOR_FINISHED; } @@ -3529,7 +3529,7 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *eve // if (obedit && ctrl) lr_click= 1; copy_v3_v3(oldcurs, fp); - project_int_noclip(ar, fp, mval); + ED_view3d_project_int_noclip(ar, fp, mval); flip = initgrabz(rv3d, fp[0], fp[1], fp[2]); /* reset the depth based on the view offset */ @@ -3537,7 +3537,7 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *eve negate_v3_v3(fp, rv3d->ofs); /* re initialize */ - project_int_noclip(ar, fp, mval); + ED_view3d_project_int_noclip(ar, fp, mval); flip = initgrabz(rv3d, fp[0], fp[1], fp[2]); (void)flip; } @@ -3837,10 +3837,12 @@ int ED_view3d_autodist_depth_seg(ARegion *ar, const int mval_sta[2], const int m } /** - * Gets the view transformation from a camera - * currently dosnt take camzoom into account + * Set the view transformation from a 4x4 matrix. * - * The dist is not modified for this function, if NULL its assumed zero + * \param mat The view 4x4 transformation matrix to assign. + * \param ofs The view offset, normally from RegionView3D.ofs. + * \param quat The view rotation, quaternion normally from RegionView3D.viewquat. + * \param dist The view distance from ofs, normally from RegionView3D.dist. */ void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist) { @@ -3871,6 +3873,14 @@ void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist) } } +/** + * Calculate the view transformation matrix from RegionView3D input. + * The resulting matrix is equivalent to RegionView3D.viewinv + * \param mat The view 4x4 transformation matrix to calculate. + * \param ofs The view offset, normally from RegionView3D.ofs. + * \param quat The view rotation, quaternion normally from RegionView3D.viewquat. + * \param dist The view distance from ofs, normally from RegionView3D.dist. + */ void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], const float dist) { float iviewquat[4] = {-quat[0], quat[1], quat[2], quat[3]}; @@ -3881,8 +3891,14 @@ void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], co sub_v3_v3v3(mat[3], dvec, ofs); } - -/* object -> view */ +/** + * Set the RegionView3D members from an objects transformation and optionally lens. + * \param ob The object to set the view to. + * \param ofs The view offset to be set, normally from RegionView3D.ofs. + * \param quat The view rotation to be set, quaternion normally from RegionView3D.viewquat. + * \param dist The view distance from ofs to be set, normally from RegionView3D.dist. + * \param lens The view lens angle set for cameras and lamps, normally from View3D.lens. + */ void ED_view3d_from_object(Object *ob, float ofs[3], float quat[4], float *dist, float *lens) { ED_view3d_from_m4(ob->obmat, ofs, quat, dist); @@ -3896,7 +3912,13 @@ void ED_view3d_from_object(Object *ob, float ofs[3], float quat[4], float *dist, } } -/* view -> object */ +/** + * Set the object transformation from RegionView3D members. + * \param ob The object which has the transformation assigned. + * \param ofs The view offset, normally from RegionView3D.ofs. + * \param quat The view rotation, quaternion normally from RegionView3D.viewquat. + * \param dist The view distance from ofs, normally from RegionView3D.dist. + */ void ED_view3d_to_object(Object *ob, const float ofs[3], const float quat[4], const float dist) { float mat[4][4]; diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index b16fc5a8b2d..e409ad4e81e 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -114,7 +114,7 @@ int view3d_get_view_aligned_coordinate(ViewContext *vc, float fp[3], const int m mval_cpy[0] = mval[0]; mval_cpy[1] = mval[1]; - project_int_noclip(vc->ar, fp, mval_cpy); + ED_view3d_project_int_noclip(vc->ar, fp, mval_cpy); initgrabz(vc->rv3d, fp[0], fp[1], fp[2]); @@ -334,9 +334,9 @@ static void do_lasso_select_pose(ViewContext *vc, Object *ob, int mcords[][2], s for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { if (PBONE_VISIBLE(arm, pchan->bone) && (pchan->bone->flag & BONE_UNSELECTABLE) == 0) { mul_v3_m4v3(vec, ob->obmat, pchan->pose_head); - project_int(vc->ar, vec, sco1); + ED_view3d_project_int(vc->ar, vec, sco1); mul_v3_m4v3(vec, ob->obmat, pchan->pose_tail); - project_int(vc->ar, vec, sco2); + ED_view3d_project_int(vc->ar, vec, sco2); if (BLI_lasso_is_edge_inside(mcords, moves, sco1[0], sco1[1], sco2[0], sco2[1], IS_CLIPPED)) { if (select) pchan->bone->flag |= BONE_SELECTED; @@ -371,7 +371,7 @@ static void do_lasso_select_objects(ViewContext *vc, int mcords[][2], short move for (base = vc->scene->base.first; base; base = base->next) { if (BASE_SELECTABLE(vc->v3d, base)) { /* use this to avoid un-needed lasso lookups */ - project_short(vc->ar, base->object->obmat[3], &base->sx); + ED_view3d_project_short(vc->ar, base->object->obmat[3], &base->sx); if (BLI_lasso_is_point_inside(mcords, moves, base->sx, base->sy, IS_CLIPPED)) { if (select) ED_base_object_select(base, BA_SELECT); @@ -578,9 +578,9 @@ static void do_lasso_select_armature(ViewContext *vc, int mcords[][2], short mov for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_UNSELECTABLE) == 0) { mul_v3_m4v3(vec, vc->obedit->obmat, ebone->head); - project_short(vc->ar, vec, sco1); + ED_view3d_project_short(vc->ar, vec, sco1); mul_v3_m4v3(vec, vc->obedit->obmat, ebone->tail); - project_short(vc->ar, vec, sco2); + ED_view3d_project_short(vc->ar, vec, sco2); didpoint = 0; if (BLI_lasso_is_point_inside(mcords, moves, sco1[0], sco1[1], IS_CLIPPED)) { @@ -632,7 +632,7 @@ static void do_lasso_select_meta(ViewContext *vc, int mcords[][2], short moves, for (ml = mb->editelems->first; ml; ml = ml->next) { mul_v3_m4v3(vec, vc->obedit->obmat, &ml->x); - project_short(vc->ar, vec, sco); + ED_view3d_project_short(vc->ar, vec, sco); if (BLI_lasso_is_point_inside(mcords, moves, sco[0], sco[1], IS_CLIPPED)) { if (select) ml->flag |= SELECT; @@ -1060,7 +1060,7 @@ static Base *object_mouse_select_menu(bContext *C, ViewContext *vc, unsigned int else { int temp, dist = 15; - project_short(vc->ar, base->object->obmat[3], &base->sx); + ED_view3d_project_short(vc->ar, base->object->obmat[3], &base->sx); temp = abs(base->sx - mval[0]) + abs(base->sy - mval[1]); if (temp < dist) @@ -1341,7 +1341,7 @@ static int mouse_select(bContext *C, const int mval[2], short extend, short dese base = startbase; while (base) { if (BASE_SELECTABLE(v3d, base)) { - project_short(ar, base->object->obmat[3], &base->sx); + ED_view3d_project_short(ar, base->object->obmat[3], &base->sx); temp = abs(base->sx - mval[0]) + abs(base->sy - mval[1]); if (base == BASACT) temp += 10; @@ -2378,11 +2378,11 @@ static void pose_circle_select(ViewContext *vc, int select, const int mval[2], f /* project head location to screenspace */ mul_v3_m4v3(vec, vc->obact->obmat, pchan->pose_head); - project_short(vc->ar, vec, sco1); + ED_view3d_project_short(vc->ar, vec, sco1); /* project tail location to screenspace */ mul_v3_m4v3(vec, vc->obact->obmat, pchan->pose_tail); - project_short(vc->ar, vec, sco2); + ED_view3d_project_short(vc->ar, vec, sco2); /* check if the head and/or tail is in the circle * - the call to check also does the selection already @@ -2446,11 +2446,11 @@ static void armature_circle_select(ViewContext *vc, int select, const int mval[2 /* project head location to screenspace */ mul_v3_m4v3(vec, vc->obedit->obmat, ebone->head); - project_short(vc->ar, vec, sco1); + ED_view3d_project_short(vc->ar, vec, sco1); /* project tail location to screenspace */ mul_v3_m4v3(vec, vc->obedit->obmat, ebone->tail); - project_short(vc->ar, vec, sco2); + ED_view3d_project_short(vc->ar, vec, sco2); /* check if the head and/or tail is in the circle * - the call to check also does the selection already @@ -2556,7 +2556,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) select = select ? BA_SELECT : BA_DESELECT; for (base = FIRSTBASE; base; base = base->next) { if (BASE_SELECTABLE(v3d, base)) { - project_short(ar, base->object->obmat[3], &base->sx); + ED_view3d_project_short(ar, base->object->obmat[3], &base->sx); if (base->sx != IS_CLIPPED) { int dx = base->sx - x; int dy = base->sy - y; diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index c25bb80bfde..ff518e6ce5b 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -520,7 +520,7 @@ void VIEW3D_OT_object_as_camera(wmOperatorType *ot) /* ********************************** */ -void ED_view3d_calc_clipping(BoundBox *bb, float planes[4][4], bglMats *mats, const rcti *rect) +void ED_view3d_clipping_calc(BoundBox *bb, float planes[4][4], bglMats *mats, const rcti *rect) { float modelview[4][4]; double xs, ys, p[3]; @@ -569,7 +569,18 @@ void ED_view3d_calc_clipping(BoundBox *bb, float planes[4][4], bglMats *mats, co } } -/* create intersection coordinates in view Z direction at mouse coordinates */ +/** + * 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 ray_start The world-space starting point of the segment. + * \param ray_end The world-space end point of the segment. + */ void ED_view3d_win_to_segment_clip(ARegion *ar, View3D *v3d, const float mval[2], float ray_start[3], float ray_end[3]) { RegionView3D *rv3d = ar->regiondata; @@ -604,7 +615,17 @@ void ED_view3d_win_to_segment_clip(ARegion *ar, View3D *v3d, const float mval[2] } } -/* create intersection ray in view Z direction at mouse coordinates */ +/** + * 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. + * \param ar The region (used for the window width and height). + * \param v3d The 3d viewport (used for near clipping value). + * \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_normal The normalized world-space direction of towards mval. + */ void ED_view3d_win_to_ray(ARegion *ar, View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3]) { float ray_end[3]; @@ -614,6 +635,13 @@ void ED_view3d_win_to_ray(ARegion *ar, View3D *v3d, const float mval[2], float r normalize_v3(ray_normal); } +/** + * Calculate a normalized 3d direction vector from the viewpoint towards a global location. + * In orthographic view the resulting vector will match the view vector. + * \param rv3d The region (used for the window width and height). + * \param coord The world-space location. + * \param vec The resulting normalized vector. + */ void ED_view3d_global_to_vector(RegionView3D *rv3d, const float coord[3], float vec[3]) { if (rv3d->is_persp) { @@ -660,6 +688,13 @@ int initgrabz(RegionView3D *rv3d, float x, float y, float z) return flip; } +/** + * Calculate a 3d location from 2d window coordinates. + * \param ar The region (used for the window width and height). + * \param depth_pt The reference location used to calculate the Z depth. + * \param mval The area relative location (such as event->mval converted to floats). + * \param out The resulting world-space location. + */ void ED_view3d_win_to_3d(ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]) { RegionView3D *rv3d = ar->regiondata; @@ -690,8 +725,14 @@ void ED_view3d_win_to_3d(ARegion *ar, const float depth_pt[3], const float mval[ } } -/* always call initgrabz */ -/* only to detect delta motion */ +/** + * Calculate a 3d difference vector from 2d window offset. + * note that initgrabz() must be called first to determine + * the depth used to calculate the delta. + * \param ar The region (used for the window width and height). + * \param mval The area relative 2d difference (such as event->mval[0] - other_x). + * \param out The resulting world-space delta. + */ void ED_view3d_win_to_delta(ARegion *ar, const float mval[2], float out[3]) { RegionView3D *rv3d = ar->regiondata; @@ -705,9 +746,19 @@ void ED_view3d_win_to_delta(ARegion *ar, const float mval[2], float out[3]) out[2] = (rv3d->persinv[0][2] * dx + rv3d->persinv[1][2] * dy); } -/* doesn't rely on initgrabz */ -/* for perspective view, get the vector direction to - * the mouse cursor as a normalized vector */ +/** + * 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 initgrabz + * for perspective view, get the vector direction to + * the mouse cursor as a normalized vector. + * + * \param ar The region (used for the window width and height). + * \param mval The area relative 2d location (such as event->mval converted to floats). + * \param out The resulting normalized world-space direction vector. + */ void ED_view3d_win_to_vector(ARegion *ar, const float mval[2], float out[3]) { RegionView3D *rv3d = ar->regiondata; @@ -754,7 +805,7 @@ void ED_view3d_ob_project_mat_get(RegionView3D *rv3d, Object *ob, float pmat[4][ /* Uses window coordinates (x,y) and depth component z to find a point in * modelspace */ -void view3d_unproject(bglMats *mats, float out[3], const short x, const short y, const float z) +void ED_view3d_unproject(bglMats *mats, float out[3], const float x, const float y, const float z) { double ux, uy, uz; @@ -766,44 +817,44 @@ void view3d_unproject(bglMats *mats, float out[3], const short x, const short y, out[2] = uz; } -/* use view3d_get_object_project_mat to get projecting mat */ -void ED_view3d_project_float_v2(const ARegion *ar, const float vec[3], float adr[2], float mat[4][4]) +/* use #ED_view3d_ob_project_mat_get to get projecting mat */ +void ED_view3d_project_float_v2_m4(const ARegion *ar, const float co[3], float r_co[2], float mat[4][4]) { float vec4[4]; - copy_v3_v3(vec4, vec); + copy_v3_v3(vec4, co); vec4[3] = 1.0; - /* adr[0]= IS_CLIPPED; */ /* always overwritten */ + /* r_co[0] = IS_CLIPPED; */ /* always overwritten */ mul_m4_v4(mat, vec4); if (vec4[3] > FLT_EPSILON) { - adr[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3]; - adr[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3]; + r_co[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3]; + r_co[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3]; } else { - adr[0] = adr[1] = 0.0f; + zero_v2(r_co); } } -/* use view3d_get_object_project_mat to get projecting mat */ -void ED_view3d_project_float_v3(ARegion *ar, const float vec[3], float adr[3], float mat[4][4]) +/* use #ED_view3d_ob_project_mat_get to get projecting mat */ +void ED_view3d_project_float_v3_m4(ARegion *ar, const float vec[3], float r_co[3], float mat[4][4]) { float vec4[4]; copy_v3_v3(vec4, vec); vec4[3] = 1.0; - /* adr[0]= IS_CLIPPED; */ /* always overwritten */ + /* r_co[0] = IS_CLIPPED; */ /* always overwritten */ mul_m4_v4(mat, vec4); if (vec4[3] > FLT_EPSILON) { - adr[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3]; - adr[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3]; - adr[2] = vec4[2] / vec4[3]; + r_co[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3]; + r_co[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3]; + r_co[2] = vec4[2] / vec4[3]; } else { - zero_v3(adr); + zero_v3(r_co); } } @@ -842,24 +893,24 @@ int ED_view3d_boundbox_clip(RegionView3D *rv3d, float obmat[][4], BoundBox *bb) return 0; } -void project_short(ARegion *ar, const float vec[3], short adr[2]) /* clips */ +void ED_view3d_project_short(ARegion *ar, const float co[3], short r_co[2]) /* clips */ { RegionView3D *rv3d = ar->regiondata; float fx, fy, vec4[4]; - adr[0] = IS_CLIPPED; + r_co[0] = IS_CLIPPED; if (rv3d->rflag & RV3D_CLIPPING) { - if (ED_view3d_clipping_test(rv3d, vec, FALSE)) { + if (ED_view3d_clipping_test(rv3d, co, FALSE)) { return; } } - copy_v3_v3(vec4, vec); + copy_v3_v3(vec4, co); vec4[3] = 1.0; mul_m4_v4(rv3d->persmat, vec4); - if (vec4[3] > (float)BL_NEAR_CLIP) { /* 0.001 is the NEAR clipping cutoff for picking */ + if (vec4[3] > (float)BL_NEAR_CLIP) { fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]); if (fx > 0 && fx < ar->winx) { @@ -867,44 +918,44 @@ void project_short(ARegion *ar, const float vec[3], short adr[2]) /* clips */ fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]); if (fy > 0.0f && fy < (float)ar->winy) { - adr[0] = (short)floor(fx); - adr[1] = (short)floor(fy); + r_co[0] = (short)floor(fx); + r_co[1] = (short)floor(fy); } } } } -void project_int(ARegion *ar, const float vec[3], int adr[2]) +void ED_view3d_project_int(ARegion *ar, const float co[3], int r_co[2]) { RegionView3D *rv3d = ar->regiondata; float fx, fy, vec4[4]; - copy_v3_v3(vec4, vec); + copy_v3_v3(vec4, co); vec4[3] = 1.0; - adr[0] = (int)2140000000.0f; + r_co[0] = (int)2140000000.0f; mul_m4_v4(rv3d->persmat, vec4); - if (vec4[3] > (float)BL_NEAR_CLIP) { /* 0.001 is the NEAR clipping cutoff for picking */ + if (vec4[3] > (float)BL_NEAR_CLIP) { fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]); if (fx > -2140000000.0f && fx < 2140000000.0f) { fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]); if (fy > -2140000000.0f && fy < 2140000000.0f) { - adr[0] = (int)floor(fx); - adr[1] = (int)floor(fy); + r_co[0] = (int)floor(fx); + r_co[1] = (int)floor(fy); } } } } -void project_int_noclip(ARegion *ar, const float vec[3], int adr[2]) +void ED_view3d_project_int_noclip(ARegion *ar, const float co[3], int r_co[2]) { RegionView3D *rv3d = ar->regiondata; float fx, fy, vec4[4]; - copy_v3_v3(vec4, vec); + copy_v3_v3(vec4, co); vec4[3] = 1.0; mul_m4_v4(rv3d->persmat, vec4); @@ -913,27 +964,27 @@ void project_int_noclip(ARegion *ar, const float vec[3], int adr[2]) fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]); fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]); - adr[0] = (int)floor(fx); - adr[1] = (int)floor(fy); + r_co[0] = (int)floor(fx); + r_co[1] = (int)floor(fy); } else { - adr[0] = ar->winx / 2; - adr[1] = ar->winy / 2; + r_co[0] = ar->winx / 2; + r_co[1] = ar->winy / 2; } } -void project_short_noclip(ARegion *ar, const float vec[3], short adr[2]) +void ED_view3d_project_short_noclip(ARegion *ar, const float co[3], short r_co[2]) { RegionView3D *rv3d = ar->regiondata; float fx, fy, vec4[4]; - copy_v3_v3(vec4, vec); + copy_v3_v3(vec4, co); vec4[3] = 1.0; - adr[0] = IS_CLIPPED; + r_co[0] = IS_CLIPPED; mul_m4_v4(rv3d->persmat, vec4); - if (vec4[3] > (float)BL_NEAR_CLIP) { /* 0.001 is the NEAR clipping cutoff for picking */ + if (vec4[3] > (float)BL_NEAR_CLIP) { fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]); if (fx > -32700 && fx < 32700) { @@ -941,53 +992,48 @@ void project_short_noclip(ARegion *ar, const float vec[3], short adr[2]) fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]); if (fy > -32700.0f && fy < 32700.0f) { - adr[0] = (short)floor(fx); - adr[1] = (short)floor(fy); + r_co[0] = (short)floor(fx); + r_co[1] = (short)floor(fy); } } } } -void apply_project_float(float persmat[4][4], int winx, int winy, const float vec[3], float adr[2]) +void ED_view3d_project_float(ARegion *ar, const float co[3], float r_co[2]) { + RegionView3D *rv3d = ar->regiondata; + float vec4[4]; - copy_v3_v3(vec4, vec); + copy_v3_v3(vec4, co); vec4[3] = 1.0; - adr[0] = IS_CLIPPED; + r_co[0] = IS_CLIPPED; - mul_m4_v4(persmat, vec4); + mul_m4_v4(rv3d->persmat, vec4); if (vec4[3] > (float)BL_NEAR_CLIP) { - adr[0] = (float)(winx / 2.0f) + (winx / 2.0f) * vec4[0] / vec4[3]; - adr[1] = (float)(winy / 2.0f) + (winy / 2.0f) * vec4[1] / vec4[3]; + r_co[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3]; + r_co[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3]; } } -void project_float(ARegion *ar, const float vec[3], float adr[2]) -{ - RegionView3D *rv3d = ar->regiondata; - - apply_project_float(rv3d->persmat, ar->winx, ar->winy, vec, adr); -} - -void project_float_noclip(ARegion *ar, const float vec[3], float adr[2]) +void ED_view3d_project_float_noclip(ARegion *ar, const float co[3], float r_co[2]) { RegionView3D *rv3d = ar->regiondata; float vec4[4]; - copy_v3_v3(vec4, vec); + copy_v3_v3(vec4, co); vec4[3] = 1.0; mul_m4_v4(rv3d->persmat, vec4); if (fabs(vec4[3]) > BL_NEAR_CLIP) { - adr[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3]; - adr[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3]; + r_co[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3]; + r_co[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3]; } else { - adr[0] = ar->winx / 2.0f; - adr[1] = ar->winy / 2.0f; + r_co[0] = ar->winx / 2.0f; + r_co[1] = ar->winy / 2.0f; } } diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 669e66686cb..07f98297c1c 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -226,7 +226,7 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2]) { if (t->spacetype == SPACE_VIEW3D) { if (t->ar->regiontype == RGN_TYPE_WINDOW) - project_int_noclip(t->ar, vec, adr); + ED_view3d_project_int_noclip(t->ar, vec, adr); } else if (t->spacetype == SPACE_IMAGE) { SpaceImage *sima = t->sa->spacedata.first; @@ -344,7 +344,7 @@ void projectFloatView(TransInfo *t, const float vec[3], float adr[2]) case SPACE_VIEW3D: { if (t->ar->regiontype == RGN_TYPE_WINDOW) { - project_float_noclip(t->ar, vec, adr); + ED_view3d_project_float_noclip(t->ar, vec, adr); return; } break; @@ -4765,7 +4765,7 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, SlideData *sld, const flo sv->edge_len = len_v3v3(dw_p, up_p); mul_v3_m4v3(v_proj, t->obedit->obmat, sv->v->co); - project_float_noclip(t->ar, v_proj, v_proj); + ED_view3d_project_float_noclip(t->ar, v_proj, v_proj); dist = len_squared_v2v2(mval, v_proj); if (dist < min_dist) { @@ -5031,19 +5031,19 @@ static int createSlideVerts(TransInfo *t) j = GET_INT_FROM_POINTER(BLI_smallhash_lookup(&table, (uintptr_t)v)); if (sv_array[j].down) { - ED_view3d_project_float_v3(ar, sv_array[j].down->co, vec1, projectMat); + ED_view3d_project_float_v3_m4(ar, sv_array[j].down->co, vec1, projectMat); } else { add_v3_v3v3(vec1, v->co, sv_array[j].downvec); - ED_view3d_project_float_v3(ar, vec1, vec1, projectMat); + ED_view3d_project_float_v3_m4(ar, vec1, vec1, projectMat); } if (sv_array[j].up) { - ED_view3d_project_float_v3(ar, sv_array[j].up->co, vec2, projectMat); + ED_view3d_project_float_v3_m4(ar, sv_array[j].up->co, vec2, projectMat); } else { add_v3_v3v3(vec2, v->co, sv_array[j].upvec); - ED_view3d_project_float_v3(ar, vec2, vec2, projectMat); + ED_view3d_project_float_v3_m4(ar, vec2, vec2, projectMat); } /* global direction */ diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 6e371e5e002..1d75be05534 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -315,7 +315,7 @@ void applyProject(TransInfo *t) copy_v3_v3(iloc, td->ob->obmat[3]); } - project_float(t->ar, iloc, mval); + ED_view3d_project_float(t->ar, iloc, mval); if (snapObjectsTransform(t, mval, &dist, loc, no, t->tsnap.modeSelect)) { // if (t->flag & (T_EDIT|T_POSE)) { @@ -601,7 +601,7 @@ int updateSelectedSnapPoint(TransInfo *t) int dx, dy; int dist; - project_int(t->ar, p->co, screen_loc); + ED_view3d_project_int(t->ar, p->co, screen_loc); dx = t->mval[0] - screen_loc[0]; dy = t->mval[1] - screen_loc[1]; @@ -1164,7 +1164,7 @@ static int snapFace(ARegion *ar, float v1co[3], float v2co[3], float v3co[3], fl new_depth = len_v3v3(location, ray_start); - project_int(ar, location, screen_loc); + ED_view3d_project_int(ar, location, screen_loc); new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]); if (new_dist <= *dist && new_depth < *depth) { @@ -1232,7 +1232,7 @@ static int snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], sh new_depth = len_v3v3(location, ray_start); - project_int(ar, location, screen_loc); + ED_view3d_project_int(ar, location, screen_loc); new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]); /* 10% threshold if edge is closer but a bit further @@ -1289,7 +1289,7 @@ static int snapVertex(ARegion *ar, float vco[3], short vno[3], float obmat[][4], new_depth = len_v3v3(location, ray_start); - project_int(ar, location, screen_loc); + ED_view3d_project_int(ar, location, screen_loc); new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]); if (new_dist <= *r_dist && new_depth < *r_depth) { |