ndof sensitivity operator follows power curve and respects min/max
authorMike Erwin <significant.bit@gmail.com>
Fri, 29 Jul 2011 21:07:51 +0000 (21:07 +0000)
committerMike Erwin <significant.bit@gmail.com>
Fri, 29 Jul 2011 21:07:51 +0000 (21:07 +0000)
source/blender/windowmanager/intern/wm_operators.c

index 1b48e36d2b7de4a8dd03de7521734fe6d7a94379..d813fd913ab29561e7d21db8046682baba9a64c0 100644 (file)
@@ -3435,16 +3435,36 @@ static void WM_OT_memory_statistics(wmOperatorType *ot)
 
 static int wm_ndof_sensitivity_exec(bContext *UNUSED(C), wmOperator *op)
 {
 
 static int wm_ndof_sensitivity_exec(bContext *UNUSED(C), wmOperator *op)
 {
-       float change = 0.1f;
-       int dir = 1;
-       if(RNA_boolean_get(op->ptr, "decrease"))
-               dir = -1;
+       const float min = 0.25f, max = 4.f; // TODO: get these from RNA property
+       float change;
+       float sensitivity = U.ndof_sensitivity;
+
        if(RNA_boolean_get(op->ptr, "fast"))
        if(RNA_boolean_get(op->ptr, "fast"))
-               change = 1.0f;
+               change = 0.5f; // 50% change
+       else
+               change = 0.1f; // 10%
 
 
+       if(RNA_boolean_get(op->ptr, "decrease"))
+               {
+               sensitivity -= sensitivity * change; 
+               if (sensitivity < min)
+                       sensitivity = min;
+               }
+       else
+               {
+               sensitivity += sensitivity * change; 
+               if (sensitivity > max)
+                       sensitivity = max;
+               }
+
+       if (sensitivity != U.ndof_sensitivity)
+               {
+               U.ndof_sensitivity = sensitivity;
+               printf("new sensitivity: %f\n", U.ndof_sensitivity);
+               }
+       else
+               printf("same sensitivity: %f\n", U.ndof_sensitivity);
 
 
-       U.ndof_sensitivity += (dir * change);
-       printf("new sensitivity: %f\n", U.ndof_sensitivity);
        return OPERATOR_FINISHED;
 }
 
        return OPERATOR_FINISHED;
 }
 
@@ -3457,8 +3477,9 @@ static void WM_OT_ndof_sensitivity_change(wmOperatorType *ot)
        ot->exec= wm_ndof_sensitivity_exec;
 
        RNA_def_boolean(ot->srna, "decrease", 1, "Decrease NDOF sensitivity", "If true then action decreases NDOF sensitivity instead of increasing");
        ot->exec= wm_ndof_sensitivity_exec;
 
        RNA_def_boolean(ot->srna, "decrease", 1, "Decrease NDOF sensitivity", "If true then action decreases NDOF sensitivity instead of increasing");
-       RNA_def_boolean(ot->srna, "fast", 0, "Fast NDOF sensitivity change", "If true then action change with factor 1.0, otherwise 0.1");
+       RNA_def_boolean(ot->srna, "fast", 0, "Fast NDOF sensitivity change", "If true then sensitivity changes 50%, otherwise 10%");
 } 
 } 
+
 /* ******************************************************* */
 /* called on initialize WM_exit() */
 void wm_operatortype_free(void)
 /* ******************************************************* */
 /* called on initialize WM_exit() */
 void wm_operatortype_free(void)