Revision: 36797 http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36797 Author: campbellbarton Date: 2011-05-20 13:09:34 +0000 (Fri, 20 May 2011) Log Message: ----------- function rename to give clearer meaning that they change from window to 3d coordinates. some functions had vague names, I even ended up re-writing some of these functions by accident! also added doxy comments.
* ED_view3d_win_to_3d (was window_to_3d) * ED_view3d_win_to_delta (was window_to_3d_delta) * ED_view3d_win_to_vector (was window_to_3d_vector / viewvector) * ED_view3d_win_to_segment_clip (was viewline) * ED_view3d_win_to_ray (was viewray) Modified Paths: -------------- trunk/blender/source/blender/editors/armature/editarmature.c trunk/blender/source/blender/editors/armature/editarmature_sketch.c trunk/blender/source/blender/editors/gpencil/gpencil_edit.c trunk/blender/source/blender/editors/gpencil/gpencil_paint.c trunk/blender/source/blender/editors/include/ED_view3d.h trunk/blender/source/blender/editors/physics/particle_edit.c trunk/blender/source/blender/editors/sculpt_paint/paint_image.c trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c trunk/blender/source/blender/editors/sculpt_paint/sculpt.c trunk/blender/source/blender/editors/space_view3d/view3d_draw.c trunk/blender/source/blender/editors/space_view3d/view3d_edit.c trunk/blender/source/blender/editors/space_view3d/view3d_select.c trunk/blender/source/blender/editors/space_view3d/view3d_view.c trunk/blender/source/blender/editors/transform/transform.c trunk/blender/source/blender/editors/transform/transform_manipulator.c trunk/blender/source/blender/editors/transform/transform_snap.c Modified: trunk/blender/source/blender/editors/armature/editarmature.c =================================================================== --- trunk/blender/source/blender/editors/armature/editarmature.c 2011-05-20 13:06:19 UTC (rev 36796) +++ trunk/blender/source/blender/editors/armature/editarmature.c 2011-05-20 13:09:34 UTC (rev 36797) @@ -2501,7 +2501,7 @@ copy_v3_v3(oldcurs, fp); - window_to_3d(ar, tvec, fp, event->mval[0], event->mval[1]); + ED_view3d_win_to_3d(ar, fp, event->mval[0], event->mval[1], tvec); copy_v3_v3(fp, tvec); /* extrude to the where new cursor is and store the operation result */ Modified: trunk/blender/source/blender/editors/armature/editarmature_sketch.c =================================================================== --- trunk/blender/source/blender/editors/armature/editarmature_sketch.c 2011-05-20 13:06:19 UTC (rev 36796) +++ trunk/blender/source/blender/editors/armature/editarmature_sketch.c 2011-05-20 13:09:34 UTC (rev 36797) @@ -1005,7 +1005,7 @@ float pval[2]; project_float(ar, stk->points[i].p, pval); - viewray(ar, v3d, pval, ray_start, ray_normal); + ED_view3d_win_to_ray(ar, v3d, pval, ray_start, ray_normal); mul_v3_fl(ray_normal, distance * progress / length); add_v3_v3(stk->points[i].p, ray_normal); @@ -1032,7 +1032,7 @@ /* method taken from editview.c - mouse_cursor() */ project_short_noclip(ar, fp, cval); - window_to_3d_delta(ar, dvec, cval[0] - dd->mval[0], cval[1] - dd->mval[1]); + ED_view3d_win_to_delta(ar, cval[0] - dd->mval[0], cval[1] - dd->mval[1], dvec); sub_v3_v3v3(vec, fp, dvec); } @@ -1721,7 +1721,7 @@ mval[0] = vi[0]; mval[1] = vi[1]; - viewline(ar, v3d, mval, ray_start, ray_end); + ED_view3d_win_to_segment_clip(ar, v3d, mval, ray_start, ray_end); isect_line_line_v3( stk->points[s_i].p, stk->points[s_i + 1].p, Modified: trunk/blender/source/blender/editors/gpencil/gpencil_edit.c =================================================================== --- trunk/blender/source/blender/editors/gpencil/gpencil_edit.c 2011-05-20 13:06:19 UTC (rev 36796) +++ trunk/blender/source/blender/editors/gpencil/gpencil_edit.c 2011-05-20 13:09:34 UTC (rev 36797) @@ -401,7 +401,7 @@ /* convert screen coordinate to 3d coordinates * - method taken from editview.c - mouse_cursor() */ - window_to_3d(ar, p3d, fp, mx, my); + ED_view3d_win_to_3d(ar, fp, mx, my, p3d); } } Modified: trunk/blender/source/blender/editors/gpencil/gpencil_paint.c =================================================================== --- trunk/blender/source/blender/editors/gpencil/gpencil_paint.c 2011-05-20 13:06:19 UTC (rev 36796) +++ trunk/blender/source/blender/editors/gpencil/gpencil_paint.c 2011-05-20 13:09:34 UTC (rev 36797) @@ -245,7 +245,7 @@ /* in 3d-space - pt->x/y/z are 3 side-by-side floats */ if (gpd->sbuffer_sflag & GP_STROKE_3DSPACE) { - if (gpencil_project_check(p) && (view_autodist_simple(p->ar, mval, out, 0, depth))) { + if (gpencil_project_check(p) && (ED_view3d_autodist_simple(p->ar, mval, out, 0, depth))) { /* projecting onto 3D-Geometry * - nothing more needs to be done here, since view_autodist_simple() has already done it */ @@ -267,7 +267,7 @@ /* method taken from editview.c - mouse_cursor() */ project_int_noclip(p->ar, rvec, mval); - window_to_3d_delta(p->ar, dvec, mval[0]-mx, mval[1]-my); + ED_view3d_win_to_delta(p->ar, mval[0]-mx, mval[1]-my, dvec); sub_v3_v3v3(out, rvec, dvec); } } @@ -583,8 +583,8 @@ for (i=0, ptc=gpd->sbuffer; i < gpd->sbuffer_size; i++, ptc++, pt++) { mval[0]= ptc->x; mval[1]= ptc->y; - if ((view_autodist_depth(p->ar, mval, depth_margin, depth_arr+i) == 0) && - (i && (view_autodist_depth_segment(p->ar, mval, mval_prev, depth_margin + 1, depth_arr+i) == 0)) + if ((ED_view3d_autodist_depth(p->ar, mval, depth_margin, depth_arr+i) == 0) && + (i && (ED_view3d_autodist_depth_seg(p->ar, mval, mval_prev, depth_margin + 1, depth_arr+i) == 0)) ) { interp_depth= TRUE; } @@ -1228,7 +1228,7 @@ /* need to restore the original projection settings before packing up */ view3d_region_operator_needs_opengl(p->win, p->ar); - view_autodist_init(p->scene, p->ar, v3d, (p->gpd->flag & GP_DATA_DEPTH_STROKE) ? 1:0); + ED_view3d_autodist_init(p->scene, p->ar, v3d, (p->gpd->flag & GP_DATA_DEPTH_STROKE) ? 1:0); } /* check if doing eraser or not */ Modified: trunk/blender/source/blender/editors/include/ED_view3d.h =================================================================== --- trunk/blender/source/blender/editors/include/ED_view3d.h 2011-05-20 13:06:19 UTC (rev 36796) +++ trunk/blender/source/blender/editors/include/ED_view3d.h 2011-05-20 13:09:34 UTC (rev 36797) @@ -80,9 +80,76 @@ float *give_cursor(struct Scene *scene, struct View3D *v3d); int initgrabz(struct RegionView3D *rv3d, float x, float y, float z); -void window_to_3d(struct ARegion *ar, float out[3], const float depth_pt[3], const float mx, const float my); -void window_to_3d_delta(struct ARegion *ar, float out[3], const float mx, const float my); -void window_to_3d_vector(struct ARegion *ar, float out[3], const float mx, const float my); + +/** + * 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 mx The area relative X location (such as event->mval[0]). + * @param my The area relative Y location (such as event->mval[1]). + * @param out The resulting world-space location. + */ +void ED_view3d_win_to_3d(struct ARegion *ar, const float depth_pt[3], const float mx, const float my, 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 mx The area relative X difference (such as event->mval[0] - other_x). + * @param my The area relative Y difference (such as event->mval[1] - other_y). + * @param out The resulting world-space delta. + */ +void ED_view3d_win_to_delta(struct ARegion *ar, const float mx, const float my, 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 mx The area relative X difference (such as event->mval[0]). + * @param my The area relative Y difference (such as event->mval[1]). + * @param out The resulting normalized world-space direction vector. + */ +void ED_view3d_win_to_vector(struct ARegion *ar, const float mx, const float my, 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 out The resulting normalized world-space direction vector. + * @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 ar 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]); + void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z); /* Depth buffer */ @@ -104,11 +171,6 @@ 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]); -void viewvector(struct RegionView3D *rv3d, const float coord[3], float vec[3]); - -void viewline(struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_end[3]); -void viewray(struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3]); - void get_object_clip_range(struct Object *ob, float *lens, float *clipsta, float *clipend); int get_view3d_cliprange(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend); int get_view3d_viewplane(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend, float *pixsize); @@ -138,13 +200,13 @@ unsigned int view3d_sample_backbuf(struct ViewContext *vc, int x, int y); /* draws and does a 4x4 sample */ -int view_autodist(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, const int mval[2], float mouse_worldloc[3]); @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs