diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2015-04-13 16:57:46 +0300 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2015-04-13 16:57:57 +0300 |
commit | 198ca57ae48fb6860fd82c04e5f1f0a41a5612da (patch) | |
tree | eed526c887e2d16c5356276bffc364a8c777ba62 /source/blender/editors/animation/anim_draw.c | |
parent | 8ad37b0d224fcf3eb09dd2b7def8bdcc386af1a1 (diff) |
Graph editor:
Normalization feature now uses the full range of the data instead of
just one semiaxis for the maximum size.
Diffstat (limited to 'source/blender/editors/animation/anim_draw.c')
-rw-r--r-- | source/blender/editors/animation/anim_draw.c | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c index ed294d7208f..6d0086ca459 100644 --- a/source/blender/editors/animation/anim_draw.c +++ b/source/blender/editors/animation/anim_draw.c @@ -267,19 +267,26 @@ short ANIM_get_normalization_flags(bAnimContext *ac) return 0; } -static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag) +static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag, float *r_offset) { - float factor = 1.0f; + float factor = 1.0f, offset = 0.0f; if (flag & ANIM_UNITCONV_RESTORE) { + if (r_offset) + *r_offset = fcu->prev_offset; + return 1.0f / fcu->prev_norm_factor; } if (flag & ANIM_UNITCONV_NORMALIZE_FREEZE) { + if (r_offset) + *r_offset = fcu->prev_offset; return fcu->prev_norm_factor; } if (G.moving & G_TRANSFORM_FCURVES) { + if (r_offset) + *r_offset = fcu->prev_offset; return fcu->prev_norm_factor; } @@ -288,6 +295,8 @@ static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag) BezTriple *bezt; int i; float max_coord = -FLT_MAX; + float min_coord = FLT_MAX; + float range; if (fcu->totvert < 1) { return 1.0f; @@ -296,35 +305,55 @@ static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag) if (PRVRANGEON) { for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) { if (IN_RANGE_INCL(bezt->vec[1][0], scene->r.psfra, scene->r.pefra)) { - max_coord = max_ff(max_coord, fabsf(bezt->vec[0][1])); - max_coord = max_ff(max_coord, fabsf(bezt->vec[1][1])); - max_coord = max_ff(max_coord, fabsf(bezt->vec[2][1])); + max_coord = max_ff(max_coord, bezt->vec[0][1]); + max_coord = max_ff(max_coord, bezt->vec[1][1]); + max_coord = max_ff(max_coord, bezt->vec[2][1]); + + min_coord = min_ff(min_coord, bezt->vec[0][1]); + min_coord = min_ff(min_coord, bezt->vec[1][1]); + min_coord = min_ff(min_coord, bezt->vec[2][1]); } } } else { for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) { - max_coord = max_ff(max_coord, fabsf(bezt->vec[0][1])); - max_coord = max_ff(max_coord, fabsf(bezt->vec[1][1])); - max_coord = max_ff(max_coord, fabsf(bezt->vec[2][1])); + max_coord = max_ff(max_coord, bezt->vec[0][1]); + max_coord = max_ff(max_coord, bezt->vec[1][1]); + max_coord = max_ff(max_coord, bezt->vec[2][1]); + + min_coord = min_ff(min_coord, bezt->vec[0][1]); + min_coord = min_ff(min_coord, bezt->vec[1][1]); + min_coord = min_ff(min_coord, bezt->vec[2][1]); } } - if (max_coord > FLT_EPSILON) { - factor = 1.0f / max_coord; + range = max_coord - min_coord; + + if (range > FLT_EPSILON) { + factor = 1.0f / range; } + offset = -min_coord - range / 2.0f; } + + if (r_offset) { + *r_offset = offset; + } + fcu->prev_norm_factor = factor; + fcu->prev_offset = offset; return factor; } /* Get unit conversion factor for given ID + F-Curve */ -float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag) +float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag, float *r_offset) { if (flag & ANIM_UNITCONV_NORMALIZE) { - return normalization_factor_get(scene, fcu, flag); + return normalization_factor_get(scene, fcu, flag, r_offset); } + if (r_offset) + *r_offset = 0.0f; + /* sanity checks */ if (id && fcu && fcu->rna_path) { PointerRNA ptr, id_ptr; |