Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ebb <matt@mke3.net>2010-01-25 09:24:05 +0300
committerMatt Ebb <matt@mke3.net>2010-01-25 09:24:05 +0300
commit0c5998e7998cba70d1dceacc5ed8109a5bba9e23 (patch)
treef9e250055d9de1647b283e7c493902bc51f0a9a5 /source/blender/blenkernel/intern/unit.c
parentc94f385fce14fa5beb8637590ad4d4662cd733c6 (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/intern/unit.c')
-rw-r--r--source/blender/blenkernel/intern/unit.c37
1 files changed, 23 insertions, 14 deletions
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;
}