Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_utils.c
| Show First 20 Lines • Show All 429 Lines • ▼ Show 20 Lines | |||||
| * \param mval The current screen-space coordinates (midpoint) of the brush | * \param mval The current screen-space coordinates (midpoint) of the brush | ||||
| * \param mvalo The previous screen-space coordinates (midpoint) of the brush (NOT CURRENTLY USED) | * \param mvalo The previous screen-space coordinates (midpoint) of the brush (NOT CURRENTLY USED) | ||||
| * \param rad The radius of the brush | * \param rad The radius of the brush | ||||
| * | * | ||||
| * \param x0, y0 The screen-space x and y coordinates of the start of the stroke segment | * \param x0, y0 The screen-space x and y coordinates of the start of the stroke segment | ||||
| * \param x1, y1 The screen-space x and y coordinates of the end of the stroke segment | * \param x1, y1 The screen-space x and y coordinates of the end of the stroke segment | ||||
| */ | */ | ||||
| bool gp_stroke_inside_circle( | bool gp_stroke_inside_circle( | ||||
| const int mval[2], const int UNUSED(mvalo[2]), | const float mval[2], const float UNUSED(mvalo[2]), | ||||
| int rad, int x0, int y0, int x1, int y1) | int rad, int x0, int y0, int x1, int y1) | ||||
| { | { | ||||
| /* simple within-radius check for now */ | /* simple within-radius check for now */ | ||||
| const float mval_fl[2] = {mval[0], mval[1]}; | |||||
| const float screen_co_a[2] = {x0, y0}; | const float screen_co_a[2] = {x0, y0}; | ||||
| const float screen_co_b[2] = {x1, y1}; | const float screen_co_b[2] = {x1, y1}; | ||||
| if (edge_inside_circle(mval_fl, rad, screen_co_a, screen_co_b)) { | if (edge_inside_circle(mval, rad, screen_co_a, screen_co_b)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* not inside */ | /* not inside */ | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* ******************************************************** */ | /* ******************************************************** */ | ||||
| ▲ Show 20 Lines • Show All 316 Lines • ▼ Show 20 Lines | |||||
| */ | */ | ||||
| void gp_stroke_convertcoords_tpoint( | void gp_stroke_convertcoords_tpoint( | ||||
| Scene *scene, ARegion *ar, | Scene *scene, ARegion *ar, | ||||
| Object *ob, bGPDlayer *gpl, | Object *ob, bGPDlayer *gpl, | ||||
| const tGPspoint *point2D, float *depth, | const tGPspoint *point2D, float *depth, | ||||
| float r_out[3]) | float r_out[3]) | ||||
| { | { | ||||
| ToolSettings *ts = scene->toolsettings; | ToolSettings *ts = scene->toolsettings; | ||||
| const int mval[2] = {point2D->x, point2D->y}; | |||||
| if ((depth != NULL) && (ED_view3d_autodist_simple(ar, mval, r_out, 0, depth))) { | int mval_i[2]; | ||||
| round_v2i_v2fl(mval_i, &point2D->x); | |||||
| if ((depth != NULL) && (ED_view3d_autodist_simple(ar, mval_i, r_out, 0, depth))) { | |||||
| /* projecting onto 3D-Geometry | /* projecting onto 3D-Geometry | ||||
| * - nothing more needs to be done here, since view_autodist_simple() has already done it | * - nothing more needs to be done here, since view_autodist_simple() has already done it | ||||
| */ | */ | ||||
| } | } | ||||
| else { | else { | ||||
| float mval_f[2] = {(float)point2D->x, (float)point2D->y}; | |||||
| float mval_prj[2]; | |||||
| float rvec[3], dvec[3]; | |||||
| float zfac; | |||||
| /* Current method just converts each point in screen-coordinates to | |||||
| * 3D-coordinates using the 3D-cursor as reference. | |||||
| */ | |||||
| ED_gp_get_drawing_reference(scene, ob, gpl, ts->gpencil_v3d_align, rvec); | |||||
| zfac = ED_view3d_calc_zfac(ar->regiondata, rvec, NULL); | |||||
| if (ED_view3d_project_float_global(ar, rvec, mval_prj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { | |||||
| sub_v2_v2v2(mval_f, mval_prj, mval_f); | |||||
| ED_view3d_win_to_delta(ar, mval_f, dvec, zfac); | |||||
| sub_v3_v3v3(r_out, rvec, dvec); | |||||
| } | |||||
| else { | |||||
| zero_v3(r_out); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Convert primitive tPGPspoint (temporary 2D/screenspace point data used by GP primitive operators) | |||||
| * to 3D coordinates. | |||||
| * | |||||
| * See: D4030 | |||||
| */ | |||||
| void gp_stroke_convertcoords_tpoint_primitive( | |||||
| Scene *scene, ARegion *ar, | |||||
| Object *ob, bGPDlayer *gpl, | |||||
| const tPGPspoint *point2D, | |||||
| float r_out[3]) | |||||
| { | |||||
| ToolSettings *ts = scene->toolsettings; | |||||
| float mval_f[2] = { point2D->x, point2D->y }; | float mval_f[2] = {point2D->x, point2D->y}; | ||||
| float mval_prj[2]; | float mval_prj[2]; | ||||
| float rvec[3], dvec[3]; | float rvec[3], dvec[3]; | ||||
| float zfac; | float zfac; | ||||
| /* Current method just converts each point in screen-coordinates to | /* Current method just converts each point in screen-coordinates to | ||||
| * 3D-coordinates using the 3D-cursor as reference. | * 3D-coordinates using the 3D-cursor as reference. | ||||
| */ | */ | ||||
| ED_gp_get_drawing_reference(scene, ob, gpl, ts->gpencil_v3d_align, rvec); | ED_gp_get_drawing_reference(scene, ob, gpl, ts->gpencil_v3d_align, rvec); | ||||
| zfac = ED_view3d_calc_zfac(ar->regiondata, rvec, NULL); | zfac = ED_view3d_calc_zfac(ar->regiondata, rvec, NULL); | ||||
| if (ED_view3d_project_float_global(ar, rvec, mval_prj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { | if (ED_view3d_project_float_global(ar, rvec, mval_prj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { | ||||
| sub_v2_v2v2(mval_f, mval_prj, mval_f); | sub_v2_v2v2(mval_f, mval_prj, mval_f); | ||||
| ED_view3d_win_to_delta(ar, mval_f, dvec, zfac); | ED_view3d_win_to_delta(ar, mval_f, dvec, zfac); | ||||
| sub_v3_v3v3(r_out, rvec, dvec); | sub_v3_v3v3(r_out, rvec, dvec); | ||||
| } | } | ||||
| else { | else { | ||||
| zero_v3(r_out); | zero_v3(r_out); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| /** | /** | ||||
| * Get drawing reference point for conversion or projection of the stroke | * Get drawing reference point for conversion or projection of the stroke | ||||
| * \param[out] r_vec : Reference point found | * \param[out] r_vec : Reference point found | ||||
| */ | */ | ||||
| void ED_gp_get_drawing_reference( | void ED_gp_get_drawing_reference( | ||||
| const Scene *scene, const Object *ob, bGPDlayer *UNUSED(gpl), | const Scene *scene, const Object *ob, bGPDlayer *UNUSED(gpl), | ||||
| char align_flag, float r_vec[3]) | char align_flag, float r_vec[3]) | ||||
| ▲ Show 20 Lines • Show All 1,084 Lines • Show Last 20 Lines | |||||