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:
authorJoshua Leung <aligorith@gmail.com>2010-01-26 06:16:14 +0300
committerJoshua Leung <aligorith@gmail.com>2010-01-26 06:16:14 +0300
commit14d4feca576e78d3707872bfb8b29c749bb20572 (patch)
tree1f9b6fa131a1011ea6d4f60876b3fccca2ca8e78 /source/blender/editors/space_graph/graph_draw.c
parente6a23762da3f6b88da21669b7ae30c834ace2f55 (diff)
Radians vs Degrees: The Second Attempt
F-Curves now internally store radians again instead of degrees. - This solves problems with inconsistencies when working with drivers. - No need to version patch old files, potentially screwing them up. As such, removed the version patching for F-Curves. - Is better suited to optionally showing radians throughout the UI instead or degrees. As a result, values are now converted on the fly in the Graph Editor for display and operators that operate on values. I've made the conversion system for this rather general, so that other unit type conversions can also be hooked up with the type conversion backend. Also, made some tweaks to F-Curve RNA wrapping to make it represent the data better. TODO: - Transform code currently still needs to be corrected to work with these changes. Currently moving keyframes for rotation curves will make them change too rapidly vertically when using degrees.
Diffstat (limited to 'source/blender/editors/space_graph/graph_draw.c')
-rw-r--r--source/blender/editors/space_graph/graph_draw.c70
1 files changed, 48 insertions, 22 deletions
diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c
index 9681d20c13b..553e52ae27e 100644
--- a/source/blender/editors/space_graph/graph_draw.c
+++ b/source/blender/editors/space_graph/graph_draw.c
@@ -163,7 +163,7 @@ static void draw_fcurve_modifier_controls_envelope (FCurve *fcu, FModifier *fcm,
/* Points ---------------- */
/* helper func - draw keyframe vertices only for an F-Curve */
-static void draw_fcurve_vertices_keyframes (FCurve *fcu, View2D *v2d, short edit, short sel)
+static void draw_fcurve_vertices_keyframes (bAnimContext *ac, FCurve *fcu, View2D *v2d, short edit, short sel)
{
BezTriple *bezt= fcu->bezt;
const float fac= 0.05f * (v2d->cur.xmax - v2d->cur.xmin);
@@ -235,7 +235,7 @@ static void draw_fcurve_handle_control (float x, float y, float xscale, float ys
}
/* helper func - draw handle vertices only for an F-Curve (if it is not protected) */
-static void draw_fcurve_vertices_handles (SpaceIpo *sipo, FCurve *fcu, View2D *v2d, short sel)
+static void draw_fcurve_vertices_handles (bAnimContext *ac, SpaceIpo *sipo, FCurve *fcu, View2D *v2d, short sel)
{
BezTriple *bezt= fcu->bezt;
BezTriple *prevbezt = NULL;
@@ -300,7 +300,7 @@ static void set_fcurve_vertex_color (SpaceIpo *sipo, FCurve *fcu, short sel)
}
-void draw_fcurve_vertices (SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
+void draw_fcurve_vertices (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
{
View2D *v2d= &ar->v2d;
@@ -318,18 +318,18 @@ void draw_fcurve_vertices (SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
(sipo->flag & SIPO_NOHANDLES)==0 && (fcu->totvert > 1))
{
set_fcurve_vertex_color(sipo, fcu, 0);
- draw_fcurve_vertices_handles(sipo, fcu, v2d, 0);
+ draw_fcurve_vertices_handles(ac, sipo, fcu, v2d, 0);
set_fcurve_vertex_color(sipo, fcu, 1);
- draw_fcurve_vertices_handles(sipo, fcu, v2d, 1);
+ draw_fcurve_vertices_handles(ac, sipo, fcu, v2d, 1);
}
/* draw keyframes over the handles */
set_fcurve_vertex_color(sipo, fcu, 0);
- draw_fcurve_vertices_keyframes(fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 0);
+ draw_fcurve_vertices_keyframes(ac, fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 0);
set_fcurve_vertex_color(sipo, fcu, 1);
- draw_fcurve_vertices_keyframes(fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 1);
+ draw_fcurve_vertices_keyframes(ac, fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 1);
glPointSize(1.0f);
}
@@ -337,7 +337,7 @@ void draw_fcurve_vertices (SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
/* Handles ---------------- */
/* draw lines for F-Curve handles only (this is only done in EditMode) */
-static void draw_fcurve_handles (SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
+static void draw_fcurve_handles (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
{
extern unsigned int nurbcol[];
int sel, b;
@@ -458,7 +458,7 @@ static void draw_fcurve_sample_control (float x, float y, float xscale, float ys
}
/* helper func - draw keyframe vertices only for an F-Curve */
-static void draw_fcurve_samples (SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
+static void draw_fcurve_samples (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
{
FPoint *first, *last;
float hsize, xscale, yscale;
@@ -497,16 +497,19 @@ static void draw_fcurve_samples (SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
#define MINGRIDSTEP 35
/* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */
-static void draw_fcurve_curve (FCurve *fcu, SpaceIpo *sipo, View2D *v2d, View2DGrid *grid)
+static void draw_fcurve_curve (bAnimContext *ac, ID *id, FCurve *fcu, SpaceIpo *sipo, View2D *v2d, View2DGrid *grid)
{
ChannelDriver *driver;
float samplefreq, ctime;
float stime, etime;
+ float unitFac;
/* disable any drivers temporarily */
driver= fcu->driver;
fcu->driver= NULL;
+ /* compute unit correction factor */
+ unitFac= ANIM_unit_mapping_get_factor(ac->scene, id, fcu, 0);
/* Note about sampling frequency:
* Ideally, this is chosen such that we have 1-2 pixels = 1 segment
@@ -532,11 +535,14 @@ static void draw_fcurve_curve (FCurve *fcu, SpaceIpo *sipo, View2D *v2d, View2DG
etime= v2d->cur.xmax;
- /* at each sampling interval, add a new vertex */
+ /* at each sampling interval, add a new vertex
+ * - apply the unit correction factor to the calculated values so that
+ * the displayed values appear correctly in the viewport
+ */
glBegin(GL_LINE_STRIP);
for (ctime= stime; ctime <= etime; ctime += samplefreq)
- glVertex2f( ctime, evaluate_fcurve(fcu, ctime) );
+ glVertex2f( ctime, evaluate_fcurve(fcu, ctime)*unitFac );
glEnd();
@@ -545,7 +551,7 @@ static void draw_fcurve_curve (FCurve *fcu, SpaceIpo *sipo, View2D *v2d, View2DG
}
/* helper func - draw a samples-based F-Curve */
-static void draw_fcurve_curve_samples (FCurve *fcu, View2D *v2d)
+static void draw_fcurve_curve_samples (bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d)
{
FPoint *prevfpt= fcu->fpt;
FPoint *fpt= prevfpt + 1;
@@ -554,6 +560,9 @@ static void draw_fcurve_curve_samples (FCurve *fcu, View2D *v2d)
glBegin(GL_LINE_STRIP);
+ /* apply unit mapping */
+ ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0, 0);
+
/* extrapolate to left? - left-side of view comes before first keyframe? */
if (prevfpt->vec[0] > v2d->cur.xmin) {
v[0]= v2d->cur.xmin;
@@ -612,11 +621,14 @@ static void draw_fcurve_curve_samples (FCurve *fcu, View2D *v2d)
glVertex2fv(v);
}
+ /* unapply unit mapping */
+ ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 1, 0);
+
glEnd();
}
/* helper func - draw one repeat of an F-Curve */
-static void draw_fcurve_curve_bezts (FCurve *fcu, View2D *v2d, View2DGrid *grid)
+static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid)
{
BezTriple *prevbezt= fcu->bezt;
BezTriple *bezt= prevbezt+1;
@@ -628,6 +640,9 @@ static void draw_fcurve_curve_bezts (FCurve *fcu, View2D *v2d, View2DGrid *grid)
glBegin(GL_LINE_STRIP);
+ /* apply unit mapping */
+ ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0, 0);
+
/* extrapolate to left? */
if (prevbezt->vec[1][0] > v2d->cur.xmin) {
/* left-side of view comes before first keyframe, so need to extend as not cyclic */
@@ -759,12 +774,17 @@ static void draw_fcurve_curve_bezts (FCurve *fcu, View2D *v2d, View2DGrid *grid)
glVertex2fv(v1);
}
+ /* unapply unit mapping */
+ ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 1, 0);
+
glEnd();
}
/* Public Curve-Drawing API ---------------- */
-/* Draw the 'ghost' F-Curves (i.e. snapshots of the curve) */
+/* Draw the 'ghost' F-Curves (i.e. snapshots of the curve)
+ * NOTE: unit mapping has already been applied to the values, so do not try and apply again
+ */
void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid *grid)
{
FCurve *fcu;
@@ -786,7 +806,7 @@ void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, Vie
glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], 0.5f);
/* simply draw the stored samples */
- draw_fcurve_curve_samples(fcu, &ar->v2d);
+ draw_fcurve_curve_samples(ac, NULL, fcu, &ar->v2d);
}
/* restore settings */
@@ -859,14 +879,14 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
/* draw a curve affected by modifiers or only allowed to have integer values
* by sampling it at various small-intervals over the visible region
*/
- draw_fcurve_curve(fcu, sipo, &ar->v2d, grid);
+ draw_fcurve_curve(ac, ale->id, fcu, sipo, &ar->v2d, grid);
}
else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) {
/* just draw curve based on defined data (i.e. no modifiers) */
if (fcu->bezt)
- draw_fcurve_curve_bezts(fcu, &ar->v2d, grid);
+ draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d, grid);
else if (fcu->fpt)
- draw_fcurve_curve_samples(fcu, &ar->v2d);
+ draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d);
}
/* restore settings */
@@ -891,18 +911,24 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
}
}
else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) {
+ /* apply unit mapping */
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, 0, 0);
+
if (fcu->bezt) {
/* only draw handles/vertices on keyframes */
glEnable(GL_BLEND);
- draw_fcurve_handles(sipo, ar, fcu);
+ draw_fcurve_handles(ac, sipo, ar, fcu);
glDisable(GL_BLEND);
- draw_fcurve_vertices(sipo, ar, fcu);
+ draw_fcurve_vertices(ac, sipo, ar, fcu);
}
else {
/* samples: only draw two indicators at either end as indicators */
- draw_fcurve_samples(sipo, ar, fcu);
+ draw_fcurve_samples(ac, sipo, ar, fcu);
}
+
+ /* unapply unit mapping */
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, 1, 0);
}
}