diff options
Diffstat (limited to 'source/blender/blenkernel/intern/paint.c')
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 96fff339521..5f3b9f04bf2 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -477,19 +477,48 @@ float paint_grid_paint_mask(const GridPaintMask *gpm, unsigned level, /* threshold to move before updating the brush rotation */ #define RAKE_THRESHHOLD 20 -void paint_calculate_rake_rotation(UnifiedPaintSettings *ups, const float mouse_pos[2]) +static void update_brush_rake_rotation(UnifiedPaintSettings *ups, Brush *brush, float rotation) { - const float u = 0.5f; - const float r = RAKE_THRESHHOLD; + if (brush->mtex.brush_angle_mode & MTEX_ANGLE_RAKE) + ups->brush_rotation = rotation; + else + ups->brush_rotation = 0.0f; - float dpos[2]; - sub_v2_v2v2(dpos, ups->last_rake, mouse_pos); + if (brush->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE) + /* here, translation contains the mouse coordinates. */ + ups->brush_rotation_sec = rotation; + else + ups->brush_rotation_sec = 0.0f; +} + +void paint_calculate_rake_rotation(UnifiedPaintSettings *ups, Brush *brush, const float mouse_pos[2]) +{ + if ((brush->mtex.brush_angle_mode & MTEX_ANGLE_RAKE) || (brush->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) { + const float u = 0.5f; + const float r = RAKE_THRESHHOLD; + float rotation; + + float dpos[2]; + sub_v2_v2v2(dpos, ups->last_rake, mouse_pos); + + if (len_squared_v2(dpos) >= r * r) { + rotation = atan2f(dpos[0], dpos[1]); + + interp_v2_v2v2(ups->last_rake, ups->last_rake, + mouse_pos, u); - if (len_squared_v2(dpos) >= r * r) { - ups->brush_rotation = atan2f(dpos[0], dpos[1]); + ups->last_rake_angle = rotation; - interp_v2_v2v2(ups->last_rake, ups->last_rake, - mouse_pos, u); + update_brush_rake_rotation(ups, brush, rotation); + } + /* make sure we reset here to the last rotation to avoid accumulating + * values in case a random rotation is also added */ + else { + update_brush_rake_rotation(ups, brush, ups->last_rake_angle); + } + } + else { + ups->brush_rotation = ups->brush_rotation_sec =0.0f; } } |