diff options
author | Matt Ebb <matt@mke3.net> | 2010-01-25 09:24:05 +0300 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2010-01-25 09:24:05 +0300 |
commit | 0c5998e7998cba70d1dceacc5ed8109a5bba9e23 (patch) | |
tree | f9e250055d9de1647b283e7c493902bc51f0a9a5 /source/blender/blenkernel | |
parent | c94f385fce14fa5beb8637590ad4d4662cd733c6 (diff) |
Radians -> Degrees (in UI)
Rotations are now stored internally as radians, while exposing degrees in the UI -
in the graph editor and UI controls. This is done in two areas:
1) Using the unit system to convert RNA data to display as degrees in the UI controls
2) FCurves now use degrees for rotation, so you can edit in the graph editor what
you see in the UI.
All rotation data is consistently accessible in DNA and RNA as radians, degrees are only
used for the UI controls and graph editor.
This commit includes conversions will convert old files (stored data and also fcurve data)
to the new units, hopefully everything should go smoothly!
Part of this also changes a few properties that were hard-coded as degrees before (such
as IK pole angle and brush texture rotation) to also use the same consistent system of
radians (dna/rna) and degrees (ui).
Thanks to Joshua for hints and review here too.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/anim_sys.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/unit.c | 37 |
3 files changed, 34 insertions, 23 deletions
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index c617ca33e8a..46f569a5310 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -730,6 +730,11 @@ static short animsys_write_rna_setting (PointerRNA *ptr, char *path, int array_i /* set value - only for animatable numerical values */ if (RNA_property_animateable(&new_ptr, prop)) { + /* convert to radians */ + if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) { + value *= M_PI/180.0; + } + switch (RNA_property_type(prop)) { case PROP_BOOLEAN: @@ -1466,6 +1471,11 @@ void nladata_flush_channels (ListBase *channels) int array_index= nec->index; float value= nec->value; + /* convert to radians */ + if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) { + value *= M_PI/180.0; + } + /* write values - see animsys_write_rna_setting() to sync the code */ switch (RNA_property_type(prop)) { diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 4de148803f8..5338f1c96ba 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -1353,10 +1353,7 @@ static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t mat4_to_eulO( eul, cob->rotOrder,cob->matrix); - /* eulers: radians to degrees! */ - eul[0] = (float)(eul[0] / M_PI * 180); - eul[1] = (float)(eul[1] / M_PI * 180); - eul[2] = (float)(eul[2] / M_PI * 180); + /* constraint data uses radians internally */ /* limiting of euler values... */ if (data->flag & LIMIT_XROT) { @@ -1381,11 +1378,6 @@ static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t eul[2] = data->zmax; } - /* eulers: degrees to radians ! */ - eul[0] = (float)(eul[0] / 180 * M_PI); - eul[1] = (float)(eul[1] / 180 * M_PI); - eul[2] = (float)(eul[2] / 180 * M_PI); - loc_eulO_size_to_mat4(cob->matrix, loc, eul, size, cob->rotOrder); } diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index 1f72c894cc8..1025bee6b8e 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -119,11 +119,18 @@ static struct bUnitDef buNaturalTimeDef[] = { }; static struct bUnitCollection buNaturalTimeCollecton = {buNaturalTimeDef, 3, 0, sizeof(buNaturalTimeDef)/sizeof(bUnitDef)}; + +static struct bUnitDef buNaturalRotDef[] = { + {"degree", "degrees", "°", NULL, "Degrees", M_PI/180.f, 0.0, B_UNIT_DEF_NONE}, + {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} +}; +static struct bUnitCollection buNaturalRotCollection = {buNaturalRotDef, 0, 0, sizeof(buNaturalRotDef)/sizeof(bUnitDef)}; + #define UNIT_SYSTEM_MAX 3 static struct bUnitCollection *bUnitSystems[][8] = { - {0,0,0,0,0,0,0,0}, - {0,&buMetricLenCollecton, 0,0,0,0, &buNaturalTimeCollecton,0}, /* metric */ - {0,&buImperialLenCollecton, 0,0,0,0, &buNaturalTimeCollecton,0}, /* imperial */ + {0,0,0,0,0,&buNaturalRotCollection,&buNaturalTimeCollecton,0}, + {0,&buMetricLenCollecton, 0,0,0, &buNaturalRotCollection, &buNaturalTimeCollecton,0}, /* metric */ + {0,&buImperialLenCollecton, 0,0,0,&buNaturalRotCollection, &buNaturalTimeCollecton,0}, /* imperial */ {0,0,0,0,0,0,0,0} }; @@ -451,23 +458,25 @@ int bUnit_ReplaceString(char *str, int len_max, char *str_prev, double scale_pre bUnitCollection *usys_iter; int system_iter; - for(system_iter= 1; system_iter<UNIT_SYSTEM_MAX; system_iter++) { + for(system_iter= 0; system_iter<UNIT_SYSTEM_MAX; system_iter++) { if (system_iter != system) { usys_iter= unit_get_system(system_iter, type); - for(unit= usys_iter->units; unit->name; unit++) { - - if((unit->flag & B_UNIT_DEF_SUPPRESS) == 0) { - int ofs = 0; - /* incase there are multiple instances */ - while((ofs=unit_replace(str+ofs, len_max-ofs, str_tmp, scale_pref, unit))) - change= 1; + if (usys_iter) { + for(unit= usys_iter->units; unit->name; unit++) { + + if((unit->flag & B_UNIT_DEF_SUPPRESS) == 0) { + int ofs = 0; + /* incase there are multiple instances */ + while((ofs=unit_replace(str+ofs, len_max-ofs, str_tmp, scale_pref, unit))) + change= 1; + } } } } } } unit= NULL; - + if(change==0) { /* no units given so infer a unit from the previous string or default */ if(str_prev) { @@ -482,9 +491,10 @@ int bUnit_ReplaceString(char *str, int len_max, char *str_prev, double scale_pre } } - if(unit==NULL) + if(unit==NULL || unit->name == NULL) unit= unit_default(usys); + /* add the unit prefix and re-run, use brackets incase there was an expression given */ if(snprintf(str_tmp, sizeof(str_tmp), "(%s)%s", str, unit->name) < sizeof(str_tmp)) { strncpy(str, str_tmp, len_max); @@ -530,7 +540,6 @@ int bUnit_ReplaceString(char *str, int len_max, char *str_prev, double scale_pre } } - // printf("replace %s\n", str); return change; } |