F-Modifiers (in Nla branch):
authorJoshua Leung <aligorith@gmail.com>
Wed, 10 Jun 2009 05:03:27 +0000 (05:03 +0000)
committerJoshua Leung <aligorith@gmail.com>
Wed, 10 Jun 2009 05:03:27 +0000 (05:03 +0000)
For fun, added 'sinc' (i.e. y = sin(pi*x)/(pi*x)) as a type of builtin function usable through the generator modifier. This makes a nice 'jolt' which tapers off.

source/blender/blenkernel/intern/fcurve.c
source/blender/editors/space_graph/graph_buttons.c
source/blender/makesdna/DNA_anim_types.h
source/blender/makesrna/intern/rna_fcurve.c

index 6a3870f8f31a8dfc695b331e6383762da6f9e536..5820761234cd9749c5475b4aafb8ccd8ddf598c8 100644 (file)
@@ -1410,6 +1410,18 @@ static void fcm_generator_verify (FModifier *fcm)
        }
 }
 
+/* Unary 'normalised sine' function
+ *     y = sin(PI + x) / (PI * x),
+ * except for x = 0 when y = 1.
+ */
+static double sinc (double x)
+{
+    if (fabs(x) < 0.0001)
+        return 1.0;
+    else
+        return sin(M_PI * x) / (M_PI * x);
+}
+
 static void fcm_generator_evaluate (FCurve *fcu, FModifier *fcm, float *cvalue, float evaltime)
 {
        FMod_Generator *data= (FMod_Generator *)fcm->data;
@@ -1490,6 +1502,9 @@ static void fcm_generator_evaluate (FCurve *fcu, FModifier *fcm, float *cvalue,
                                case FCM_GENERATOR_FN_COS: /* cosine wave */
                                        fn= cos;
                                        break;
+                               case FCM_GENERATOR_FN_SINC: /* normalised sine wave */
+                                       fn= sinc;
+                                       break;
                                        
                                /* validation required */
                                case FCM_GENERATOR_FN_TAN: /* tangent wave */
@@ -1527,7 +1542,7 @@ static void fcm_generator_evaluate (FCurve *fcu, FModifier *fcm, float *cvalue,
                                        }
                                }
                                        break;
-                                       
+                               
                                default:
                                        printf("Invalid Function-Generator for F-Modifier - %d \n", data->func_type);
                        }
index a4babaad74c8e035f6d68d45172de08d50ea227b..5b00205b5d068f0708bd65006b6a253a48d8c0c7 100644 (file)
@@ -405,7 +405,7 @@ static void draw_modifier__generator(uiBlock *block, FCurve *fcu, FModifier *fcm
 {
        FMod_Generator *data= (FMod_Generator *)fcm->data;
        char gen_mode[]="Generator Type%t|Expanded Polynomial%x0|Factorised Polynomial%x1|Built-In Function%x2|Expression%x3";
-       char fn_type[]="Built-In Function%t|Sin%x0|Cos%x1|Tan%x2|Square Root%x3|Natural Log%x4";
+       char fn_type[]="Built-In Function%t|Sin%x0|Cos%x1|Tan%x2|Square Root%x3|Natural Log%x4|Normalised Sin%x5";
        int cy= *yco - 30;
        uiBut *but;
        
@@ -555,6 +555,9 @@ static void draw_modifier__generator(uiBlock *block, FCurve *fcu, FModifier *fcm
                                        case FCM_GENERATOR_FN_SQRT: /* square root */
                                                sprintf(func_name, "sqrt(");
                                                break;
+                                       case FCM_GENERATOR_FN_SINC: /* normalised sine wave */
+                                               sprintf(func_name, "sinc(");
+                                               break;
                                        default: /* unknown */
                                                sprintf(func_name, "<fn?>(");
                                                break;
index c19318629f6dcba98be652e03a5d179e1b4ba815..a784adaf35fce8c9168139af8976d1f77c8594cc 100644 (file)
@@ -108,6 +108,7 @@ enum {
        FCM_GENERATOR_FN_TAN,
        FCM_GENERATOR_FN_SQRT,
        FCM_GENERATOR_FN_LN,
+       FCM_GENERATOR_FN_SINC,
 } eFMod_Generator_Functions;
 
 
index ea26118f267a507ac9a3d2b0274eb753c09db8f3..691035363108c044e7290404859e54d663817db9 100644 (file)
@@ -284,6 +284,7 @@ static void rna_def_fmodifier_generator_function(BlenderRNA *brna)
                {2, "TAN", "Tangent", ""},
                {3, "SQRT", "Square Root", ""},
                {4, "LN", "Natural Logarithm", ""},
+               {5, "SINC", "Normalised Sine", "sin(x) / x"},
                {0, NULL, NULL, NULL}};