BGE Patch: [#27425] Allow to change the damping of the camera actuator
authorDalai Felinto <dfelinto@gmail.com>
Mon, 13 Jun 2011 17:08:33 +0000 (17:08 +0000)
committerDalai Felinto <dfelinto@gmail.com>
Mon, 13 Jun 2011 17:08:33 +0000 (17:08 +0000)
##########
original name: "Allow to change the strenght of the "go behind" constraint of the camera actuator"

The camera actuator is an actuator that drive the camera to follow an object, with a set of constraint.
Currently, when the object followed rotate on himself (like a person, or an helicopter), the camera is really slow to go behind (at least 10 seconds).

This patch gives the UI to tweak the strenght of the 'go behind'[named damping] constraint.
###########

epydocs (rst) updated too

doc/python_api/rst/bge.types.rst
source/blender/blenkernel/intern/sca.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/space_logic/logic_window.c
source/blender/makesdna/DNA_actuator_types.h
source/blender/makesrna/intern/rna_actuator.c
source/gameengine/Converter/KX_ConvertActuators.cpp
source/gameengine/Ketsji/KX_CameraActuator.cpp
source/gameengine/Ketsji/KX_CameraActuator.h

index b54eca07e552f0cbc471182208d377d28d13ff6c..e42b362c771df5d2eb39368e5c3f7dc926f64819 100644 (file)
@@ -710,6 +710,12 @@ Game Engine  bge.types Module
 
    Applies changes to a camera.
 
+   .. attribute:: damping
+
+      strength of of the camera following movement.
+
+      :type: float
+   
    .. attribute:: min
 
       minimum distance to the target object maintained by the actuator.
index 16cef67ea6d2c098c67435e2a193ff573cf9864f..0d5235995984b38372a37f1bad723084d6a2ac09 100644 (file)
@@ -430,6 +430,7 @@ void init_actuator(bActuator *act)
                act->data= MEM_callocN(sizeof(bCameraActuator), "camact");
                ca = act->data;
                ca->axis = ACT_CAMERA_X;
+               ca->damping = 1.0/32.0;
                break;
        case ACT_EDIT_OBJECT:
                act->data= MEM_callocN(sizeof(bEditObjectActuator), "editobact");
index 9d3035057ba3fcc38aa15197c9f1c0d60be76927..1e604c45772fa884eccbf7a63ddf54363133e2ef 100644 (file)
@@ -11647,6 +11647,21 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                }
                        }
                }
+
+               {
+                       /* add default value for behind strength of camera actuator */
+                       Object *ob;
+                       bActuator *act;
+                       for(ob = main->object.first; ob; ob= ob->id.next) {
+                               for(act= ob->actuators.first; act; act= act->next) {
+                                       if (act->type == ACT_CAMERA) {
+                                               bCameraActuator *ba= act->data;
+
+                                               ba->damping = 1.0/32.0;
+                                       }
+                               }
+                       }
+               }
        }
        
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
index bce492f5a040ae4e1ade57cc7330407599d40960..019ce2a714a55d9e22dfd4b1dc31f7cbf2abf909 100644 (file)
@@ -3786,6 +3786,8 @@ static void draw_actuator_camera(uiLayout *layout, PointerRNA *ptr)
        row = uiLayoutRow(layout, 1);
        uiItemR(row, ptr, "min", 0, NULL, ICON_NONE);
        uiItemR(row, ptr, "max", 0, NULL, ICON_NONE);
+
+       uiItemR(layout, ptr, "damping", 0, NULL, ICON_NONE);
 }
 
 static void draw_actuator_constraint(uiLayout *layout, PointerRNA *ptr, bContext *C)
index 683d8142cc90a1c015ac118f38b45b0283abe32d..887a0300ee2e79d4c2475ea74a146dc90071cd35 100644 (file)
@@ -133,7 +133,7 @@ typedef struct bIpoActuator {
 typedef struct bCameraActuator {
        struct Object *ob;
        float height, min, max;
-       float pad;
+       float damping;
        short pad1, axis;
        float pad2;
 } bCameraActuator ;
index c7cf511d5c7991f21c2f2c15e05485d5ccd72dac..cddba59f9798e56f6e8d2c038d40c71857a5dea5 100644 (file)
@@ -922,6 +922,13 @@ static void rna_def_camera_actuator(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Max", "");
        RNA_def_property_update(prop, NC_LOGIC, NULL);
 
+       prop= RNA_def_property(srna, "damping", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "damping");
+       RNA_def_property_range(prop, 0, 10.0);
+       RNA_def_property_ui_range(prop, 0, 5.0, 1, 2);
+       RNA_def_property_ui_text(prop, "Damping", "Specify the strength of the constraint that drive the camera behind the target");
+       RNA_def_property_update(prop, NC_LOGIC, NULL);
+
        /* x/y */
        prop= RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "axis");
index 87d6c619229199d74f4b14e0c8128963552344df..7da474241a027597667fadd6fce547be6f4e2ed6 100644 (file)
@@ -287,7 +287,8 @@ void BL_ConvertActuators(char* maggiename,
                                                camact->height,
                                                camact->min,
                                                camact->max,
-                                               camact->axis=='x');
+                                               camact->axis=='x',
+                                               camact->damping);
                                        baseact = tmpcamact;
                                }
                                break;
index d68cb453fe8427f2613dfb9332f9e5aa1f5377dd..ebb291b2284b193f0ba089de06bc308b14471a50 100644 (file)
@@ -54,14 +54,16 @@ KX_CameraActuator::KX_CameraActuator(
        float hght,
        float minhght,
        float maxhght,
-       bool  xytog
+       bool  xytog,
+       float damping
 ): 
        SCA_IActuator(gameobj, KX_ACT_CAMERA),
        m_ob (obj),
        m_height (hght),
        m_minHeight (minhght),
        m_maxHeight (maxhght),
-       m_x (xytog)
+       m_x (xytog),
+       m_damping (damping)
 {
        if (m_ob)
                m_ob->RegisterActuator(this);
@@ -283,7 +285,7 @@ bool KX_CameraActuator::Update(double curtime, bool frame)
        }
        
        inp= fp1[0]*fp2[0] + fp1[1]*fp2[1] + fp1[2]*fp2[2];
-       fac= (-1.0 + inp)/32.0;
+       fac= (-1.0 + inp) * m_damping;
 
        from[0]+= fac*fp1[0];
        from[1]+= fac*fp1[1];
@@ -390,6 +392,7 @@ PyAttributeDef KX_CameraActuator::Attributes[] = {
        KX_PYATTRIBUTE_FLOAT_RW("height",-FLT_MAX,FLT_MAX,KX_CameraActuator,m_height),
        KX_PYATTRIBUTE_BOOL_RW("useXY",KX_CameraActuator,m_x),
        KX_PYATTRIBUTE_RW_FUNCTION("object", KX_CameraActuator, pyattr_get_object,      pyattr_set_object),
+       KX_PYATTRIBUTE_FLOAT_RW("damping",0.f,10.f,KX_CameraActuator,m_damping),
        {NULL}
 };
 
index d59fcff9370075347815d50e19550a2ddddc70c5..f844f6418b8d2c5dc4ea08fa6d6f89dcdc85114b 100644 (file)
@@ -73,6 +73,9 @@ private :
        
        /** xy toggle (pick one): true == x, false == y */
        bool m_x;
+       
+       /** damping (float), */
+       float m_damping;
 
        /* get the KX_IGameObject with this name */
        CValue *findObject(char *obName);
@@ -95,7 +98,8 @@ private :
                float hght,
                float minhght,
                float maxhght,
-               bool xytog
+               bool xytog,
+               float damping
        );