BGE logic update: new servo control motion actuator, new distance constraint actuator...
authorBenoit Bolsee <benoit.bolsee@online.be>
Fri, 4 Jul 2008 08:14:50 +0000 (08:14 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Fri, 4 Jul 2008 08:14:50 +0000 (08:14 +0000)
General
=======
- Removal of Damp option in motion actuator (replaced by
  Servo control motion).
- No PyDoc at present, will be added soon.

Generalization of the Lvl option
================================
A sensor with the Lvl option selected will always produce an
event at the start of the game or when entering a state or at
object creation. The event will be positive or negative
depending of the sensor condition. A negative pulse makes
sense when used with a NAND controller: it will be converted
into an actuator activation.

Servo control motion
====================
A new variant of the motion actuator allows to control speed
with force. The control if of type "PID" (Propotional, Integral,
Derivate): the force is automatically adapted to achieve the
target speed. All the parameters of the servo controller are
configurable. The result is a great variety of motion style:
anysotropic friction, flying, sliding, pseudo Dloc...
This actuator should be used in preference to Dloc and LinV
as it produces more fluid movements and avoids the collision
problem with Dloc.
LinV : target speed as (X,Y,Z) vector in local or world
       coordinates (mostly useful in local coordinates).
Limit: the force can be limited along each axis (in the same
       coordinates of LinV). No limitation means that the force
       will grow as large as necessary to achieve the target
       speed along that axis. Set a max value to limit the
       accelaration along an axis (slow start) and set a min
       value (negative) to limit the brake force.
P:     Proportional coefficient of servo controller, don't set
       directly unless you know what you're doing.
I:     Integral coefficient of servo controller. Use low value
       (<0.1) for slow reaction (sliding), high values (>0.5)
       for hard control. The P coefficient will be automatically
       set to 60 times the I coefficient (a reasonable value).
D:     Derivate coefficient. Leave to 0 unless you know what
       you're doing. High values create instability.

Notes: - This actuator works perfectly in zero friction
         environment: the PID controller will simulate friction
         by applying force as needed.
       - This actuator is compatible with simple Drot motion
         actuator but not with LinV and Dloc motion.
       - (0,0,0) is a valid target speed.
       - All parameters are accessible through Python.

Distance constraint actuator
============================
A new variant of the constraint actuator allows to set the
distance and orientation relative to a surface. The controller
uses a ray to detect the surface (or any object) and adapt the
distance and orientation parallel to the surface.
Damp:  Time constant (in nb of frames) of distance and
       orientation control.
Dist:  Select to enable distance control and set target
       distance. The object will be position at the given
       distance of surface along the ray direction.
Direction: chose a local axis as the ray direction.
Range: length of ray. Objecgt within this distance will be
       detected.
N    : Select to enable orientation control. The actuator will
       change the orientation and the location of the object
       so that it is parallel to the surface at the vertical
       of the point of contact of the ray.
M/P  : Select to enable material detection. Default is property
       detection.
Property/Material: name of property/material that the target of
       ray must have to be detected. If not set, property/
       material filter is disabled and any collisioning object
       within range will be detected.
PER  : Select to enable persistent operation. Normally the
       actuator disables itself automatically if the ray does
       not reach a valid target.
time : Maximum activation time of actuator.
       0 : unlimited.
       >0: number of frames before automatic deactivation.
rotDamp: Time constant (in nb of frame) of orientation control.
       0 : use Damp parameter.
       >0: use a different time constant for orientation.

Notes: - If neither N nor Dist options are set, the actuator
         does not change the position and orientation of the
         object; it works as a ray sensor.
       - The ray has no "X-ray" capability: if the first object
         hit does not have the required property/material, it
         returns no hit and the actuator disables itself unless
         PER option is enabled.
       - This actuator changes the position and orientation but
         not the speed of the object. This has an important
         implication in a gravity environment: the gravity will
         cause the speed to increase although the object seems
         to stay still (it is repositioned at each frame).
         The gravity must be compensated in one way or another.
         the new servo control motion actuator is the simplest
         way: set the target speed along the ray axis to 0
         and the servo control will automatically compensate
         the gravity.
       - This actuator changes the orientation of the object
         and will conflict with Drot motion unless it is
         placed BEFORE the Drot motion actuator (the order of
         actuator is important)
       - All parameters are accessible through Python.

Orientation constraint
======================
A new variant of the constraint actuator allows to align an
object axis along a global direction.
Damp : Time constant (in nb of frames) of orientation control.
X,Y,Z: Global coordinates of reference direction.
time : Maximum activation time of actuator.
       0 : unlimited.
       >0: number of frames before automatic deactivation.

Notes: - (X,Y,Z) = (0,0,0) is not a valid direction
       - This actuator changes the orientation of the object
         and will conflict with Drot motion unless it is placed
         BEFORE the Drot motion actuator (the order of
         actuator is important).
       - This actuator doesn't change the location and speed.
         It is compatible with gravity.
       - All parameters are accessible through Python.

Actuator sensor
===============
This sensor detects the activation and deactivation of actuators
of the same object. The sensor generates a positive pulse when
the corresponding sensor is activated and a negative pulse when
it is deactivated (the contrary if the Inv option is selected).
This is mostly useful to chain actions and to detect the loss of
contact of the distance motion actuator.

Notes: - Actuators are disabled at the start of the game; if you
         want to detect the On-Off transition of an actuator
         after it has been activated at least once, unselect the
         Lvl and Inv options and use a NAND controller.
       - Some actuators deactivates themselves immediately after
         being activated. The sensor detects this situation as
         an On-Off transition.
       - The actuator name can be set through Python.

35 files changed:
projectfiles_vc7/blender/render/BRE_render.vcproj
projectfiles_vc7/gameengine/gamelogic/SCA_GameLogic.vcproj
source/blender/blenkernel/intern/sca.c
source/blender/blenloader/intern/writefile.c
source/blender/makesdna/DNA_actuator_types.h
source/blender/makesdna/DNA_sensor_types.h
source/blender/render/intern/source/convertblender.c
source/blender/src/buttons_logic.c
source/gameengine/Converter/KX_ConvertActuators.cpp
source/gameengine/Converter/KX_ConvertSensors.cpp
source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp [new file with mode: 0644]
source/gameengine/GameLogic/SCA_ActuatorEventManager.h [new file with mode: 0644]
source/gameengine/GameLogic/SCA_ActuatorSensor.cpp [new file with mode: 0644]
source/gameengine/GameLogic/SCA_ActuatorSensor.h [new file with mode: 0644]
source/gameengine/GameLogic/SCA_EventManager.cpp
source/gameengine/GameLogic/SCA_EventManager.h
source/gameengine/GameLogic/SCA_IObject.cpp
source/gameengine/GameLogic/SCA_ISensor.cpp
source/gameengine/GameLogic/SCA_ISensor.h
source/gameengine/GameLogic/SCA_JoystickSensor.cpp
source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
source/gameengine/GameLogic/SCA_LogicManager.cpp
source/gameengine/GameLogic/SCA_MouseSensor.cpp
source/gameengine/GameLogic/SCA_PropertySensor.cpp
source/gameengine/Ketsji/KX_ConstraintActuator.cpp
source/gameengine/Ketsji/KX_ConstraintActuator.h
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
source/gameengine/Ketsji/KX_NearSensor.cpp
source/gameengine/Ketsji/KX_ObjectActuator.cpp
source/gameengine/Ketsji/KX_ObjectActuator.h
source/gameengine/Ketsji/KX_RaySensor.cpp
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_TouchSensor.cpp

index 4869dd606f1702976081ad49390f9e9b44e23687..4331d6e15793a32ecd14e6294c22ca43921665f6 100644 (file)
@@ -74,7 +74,7 @@
                                Name="VCCLCompilerTool"
                                Optimization="0"
                                AdditionalIncludeDirectories="..\..\..\..\lib\windows\sdl\include;..\..\..\..\build\msvc_7\intern\guardedalloc\include;..\..\..\source\blender;..\..\..\source\blender\misc;..\..\..\source\blender\imbuf;..\..\..\source\blender\yafray;..\..\..\source\blender\blenlib;..\..\..\source\blender\include;..\..\..\source\blender\python;..\..\..\source\blender\blenkernel;..\..\..\source\blender\quicktime;..\..\..\source\blender\blenloader;..\..\..\source\blender\makesdna;..\..\..\source\blender\radiosity\extern\include;..\..\..\source\blender\render\intern\include;..\..\..\source\blender\render\extern\include;..\..\..\source\kernel;..\..\..\source\kernel\gen_messaging"
-                               PreprocessorDefinitions="_DEBUG;WIN32;_LIB;WITH_QUICKTIME;WITH_OPENEXR"
+                               PreprocessorDefinitions="_DEBUG;WIN32;_LIB;WITH_QUICKTIME;WITH_OPENEXR;_USE_MATH_DEFINES"
                                BasicRuntimeChecks="3"
                                RuntimeLibrary="1"
                                DefaultCharIsUnsigned="TRUE"
                        <File
                                RelativePath="..\..\..\source\blender\render\intern\source\strand.c">
                        </File>
+                       <File
+                               RelativePath="..\..\..\source\blender\render\intern\source\sunsky.c">
+                       </File>
                        <File
                                RelativePath="..\..\..\source\blender\render\intern\source\texture.c">
                        </File>
                        <File
                                RelativePath="..\..\..\source\blender\render\intern\include\strand.h">
                        </File>
+                       <File
+                               RelativePath="..\..\..\source\blender\render\intern\include\sunsky.h">
+                       </File>
                        <File
                                RelativePath="..\..\..\source\blender\render\intern\include\texture.h">
                        </File>
index e0405b4d7c73e420d6fa411aacde7897a3b2bbf1..7e2db4f564fbd99f9abfa38a84ad80f83a0c026f 100644 (file)
                        <File
                                RelativePath="..\..\..\source\gameengine\GameLogic\SCA_2DFilterActuator.cpp">
                        </File>
+                       <File
+                               RelativePath="..\..\..\source\gameengine\GameLogic\SCA_ActuatorEventManager.cpp">
+                       </File>
+                       <File
+                               RelativePath="..\..\..\source\gameengine\GameLogic\SCA_ActuatorSensor.cpp">
+                       </File>
                        <File
                                RelativePath="..\..\..\source\gameengine\GameLogic\SCA_AlwaysEventManager.cpp">
                        </File>
                        <File
                                RelativePath="..\..\..\source\gameengine\GameLogic\SCA_2DFilterActuator.h">
                        </File>
+                       <File
+                               RelativePath="..\..\..\source\gameengine\GameLogic\SCA_ActuatorEventManager.h">
+                       </File>
+                       <File
+                               RelativePath="..\..\..\source\gameengine\GameLogic\SCA_ActuatorSensor.h">
+                       </File>
                        <File
                                RelativePath="..\..\..\source\gameengine\GameLogic\SCA_AlwaysEventManager.h">
                        </File>
index 16ca5d7542db42169204d9b9a537e333c3a03b66..fcf1c7ce311fcc3aabba5be136efe7b9e9755e41 100644 (file)
@@ -150,6 +150,9 @@ void init_sensor(bSensor *sens)
        case SENS_PROPERTY:
                sens->data= MEM_callocN(sizeof(bPropertySensor), "propsens");
                break;
+       case SENS_ACTUATOR:
+               sens->data= MEM_callocN(sizeof(bActuatorSensor), "actsens");
+               break;
        case SENS_MOUSE:
                ms=sens->data= MEM_callocN(sizeof(bMouseSensor), "mousesens");
                ms->type= LEFTMOUSE;
index 9f28e13ff7b9d7991f085accc015dc7e76e91f7e..ca91f1dc3461f7bcd4dc7d33737cde89f0d786ea 100644 (file)
@@ -603,6 +603,9 @@ static void write_sensors(WriteData *wd, ListBase *lb)
                case SENS_PROPERTY:
                        writestruct(wd, DATA, "bPropertySensor", 1, sens->data);
                        break;
+               case SENS_ACTUATOR:
+                       writestruct(wd, DATA, "bActuatorSensor", 1, sens->data);
+                       break;
                case SENS_COLLISION:
                        writestruct(wd, DATA, "bCollisionSensor", 1, sens->data);
                        break;
index 51f03a676e487fefc6f87ad51b1d8c5d15bd6c3c..3cf80a4efa616605308b2f631f4800a8a55db4b3 100644 (file)
@@ -98,8 +98,8 @@ typedef struct bPropertyActuator {
 } bPropertyActuator;
 
 typedef struct bObjectActuator {
-       short flag, type;
-       int   damping;
+       short flag, type, otype;
+       short damping;
        float forceloc[3], forcerot[3];
        float loc[3], rot[3];
        float dloc[3], drot[3];
@@ -124,10 +124,13 @@ typedef struct bCameraActuator {
 } bCameraActuator ;
 
 typedef struct bConstraintActuator {
+       short type, mode;
        short flag, damp;
-       float slow;
+       short time, rotdamp;
+       int pad;
        float minloc[3], maxloc[3];
        float minrot[3], maxrot[3];
+       char matprop[32];
 } bConstraintActuator;
 
 typedef struct bGroupActuator {
@@ -249,20 +252,19 @@ typedef struct FreeCamera {
 /* objectactuator->flag */
 #define ACT_FORCE_LOCAL                        1
 #define ACT_TORQUE_LOCAL               2
+#define ACT_SERVO_LIMIT_X              2
 #define ACT_DLOC_LOCAL                 4
+#define ACT_SERVO_LIMIT_Y              4
 #define ACT_DROT_LOCAL                 8
+#define ACT_SERVO_LIMIT_Z              8
 #define ACT_LIN_VEL_LOCAL              16
 #define ACT_ANG_VEL_LOCAL              32
 //#define ACT_ADD_LIN_VEL_LOCAL        64
 #define ACT_ADD_LIN_VEL                        64
-#define ACT_CLAMP_VEL                  128
 
-#define ACT_OBJECT_FORCE       0
-#define ACT_OBJECT_TORQUE      1
-#define ACT_OBJECT_DLOC                2
-#define ACT_OBJECT_DROT                3
-#define ACT_OBJECT_LINV                4
-#define ACT_OBJECT_ANGV                5
+/* objectactuator->type */
+#define ACT_OBJECT_NORMAL      0
+#define ACT_OBJECT_SERVO       1
 
 /* actuator->type */
 #define ACT_OBJECT             0
@@ -358,6 +360,22 @@ typedef struct FreeCamera {
 #define ACT_CONST_ROTX         8
 #define ACT_CONST_ROTY         16
 #define ACT_CONST_ROTZ         32
+#define ACT_CONST_NORMAL       64
+#define ACT_CONST_MATERIAL     128
+#define ACT_CONST_PERMANENT 256
+#define ACT_CONST_DISTANCE     512
+/* constraint mode */
+#define ACT_CONST_DIRPX                1
+#define ACT_CONST_DIRPY                2
+#define ACT_CONST_DIRPZ                4
+#define ACT_CONST_DIRMX                8
+#define ACT_CONST_DIRMY                16
+#define ACT_CONST_DIRMZ                32
+
+/* constraint type */
+#define ACT_CONST_TYPE_LOC     0
+#define ACT_CONST_TYPE_DIST    1
+#define ACT_CONST_TYPE_ORI     2
 
 /* editObjectActuator->type */
 #define ACT_EDOB_ADD_OBJECT            0
index ae7b92bb06c90199a20af376ac801362c708cf72..c0306f4373067180a52405affcb19f46222d3fce 100644 (file)
@@ -82,6 +82,12 @@ typedef struct bPropertySensor {
     char maxvalue[32];
 } bPropertySensor;
 
+typedef struct bActuatorSensor {
+    int type;
+    int pad;
+       char name[32];
+} bActuatorSensor;
+
 typedef struct bCollisionSensor {
        char name[32];          /* property name */
        char materialName[32];  /* material      */
@@ -197,6 +203,7 @@ typedef struct bJoystickSensor {
 #define SENS_RAY        9
 #define SENS_MESSAGE   10
 #define SENS_JOYSTICK  11
+#define SENS_ACTUATOR  12
 /* sensor->flag */
 #define SENS_SHOW              1
 #define SENS_DEL               2
index daee892ad9af7fbc3a3bc76ecb9e475816587ca5..f9ec0e9d8437c0ea861b1d09052393d0116218d0 100644 (file)
 #include "sss.h"
 #include "strand.h"
 #include "zbuf.h"
+#include "sunsky.h"
 
 #ifndef DISABLE_YAFRAY /* disable yafray */
 
index 5065ba1fc2a4abd922ba807b68073af56035f85d..be8483b7e0490a34752249f9ab259dbfa52b3f57 100644 (file)
@@ -681,6 +681,8 @@ static char *sensor_name(int type)
                return "Keyboard";
        case SENS_PROPERTY:
                return "Property";
+       case SENS_ACTUATOR:
+               return "Actuator";
        case SENS_MOUSE:
                return "Mouse";
        case SENS_COLLISION:
@@ -704,7 +706,7 @@ static char *sensor_pup(void)
        /* the number needs to match defines in game.h */
        return "Sensors %t|Always %x0|Keyboard %x3|Mouse %x5|"
                "Touch %x1|Collision %x6|Near %x2|Radar %x7|"
-               "Property %x4|Random %x8|Ray %x9|Message %x10|Joystick %x11";
+               "Property %x4|Random %x8|Ray %x9|Message %x10|Joystick %x11|Actuator %x12";
 }
 
 static char *controller_name(int type)
@@ -1003,6 +1005,7 @@ static int get_col_sensor(int type)
        case SENS_NEAR:                 return TH_BUT_SETTING1; 
        case SENS_KEYBOARD:             return TH_BUT_SETTING2;
        case SENS_PROPERTY:             return TH_BUT_NUM;
+       case SENS_ACTUATOR:             return TH_BUT_NUM;
        case SENS_MOUSE:                return TH_BUT_TEXTFIELD;
        case SENS_RADAR:                return TH_BUT_POPUP;
        case SENS_RANDOM:               return TH_BUT_NEUTRAL;
@@ -1067,6 +1070,7 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short
        bRaySensor       *raySens      = NULL;
        bMessageSensor   *mes          = NULL;
        bJoystickSensor  *joy              = NULL;
+       bActuatorSensor  *as          = NULL;
 
        short ysize;
        char *str;
@@ -1277,6 +1281,22 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short
                        yco-= ysize;
                        break;
                }
+       case SENS_ACTUATOR:
+               {
+                       ysize= 48;
+                       
+                       glRects(xco, yco-ysize, xco+width, yco);
+                       uiEmboss((float)xco, (float)yco-ysize,
+                               (float)xco+width, (float)yco, 1);
+                       
+                       draw_default_sensor_header(sens, block, xco, yco, width);
+                       as= sens->data;
+                       
+                       uiDefBut(block, TEX, 1, "Act: ",                        xco+30,yco-44,width-60, 19,
+                                       as->name, 0, 31, 0, 0,  "Actuator name, actuator active state modifications will be detected");
+                       yco-= ysize;
+                       break;
+               }
        case SENS_MOUSE:
                {
                        ms= sens->data;
@@ -1537,6 +1557,37 @@ static void set_col_actuator(int item, int medium)
        
 }
 
+static void change_object_actuator(void *act, void *arg)
+{
+       bObjectActuator *oa = act;
+       int i;
+
+       if (oa->type != oa->otype) {
+               switch (oa->type) {
+               case ACT_OBJECT_NORMAL:
+                       memset(oa, 0, sizeof(bObjectActuator));
+                       oa->flag = ACT_FORCE_LOCAL|ACT_TORQUE_LOCAL|ACT_DLOC_LOCAL|ACT_DROT_LOCAL;
+                       oa->type = ACT_OBJECT_NORMAL;
+                       break;
+
+               case ACT_OBJECT_SERVO:
+                       memset(oa, 0, sizeof(bObjectActuator));
+                       oa->flag = ACT_LIN_VEL_LOCAL;
+                       oa->type = ACT_OBJECT_SERVO;
+                       oa->forcerot[0] = 30.0f;
+                       oa->forcerot[1] = 0.5f;
+                       oa->forcerot[2] = 0.0f;
+                       break;
+               }
+       }
+}
+
+void update_object_actuator_PID(void *act, void *arg)
+{
+       bObjectActuator *oa = act;
+       oa->forcerot[0] = 60.0f*oa->forcerot[1];
+}
+
 char *get_state_name(Object *ob, short bit)
 {
        bController *cont;
@@ -1578,6 +1629,7 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
        short ysize = 0, wval;
        char *str;
        int myline, stbit;
+       uiBut *but;
 
        /* yco is at the top of the rect, draw downwards */
        uiBlockSetEmboss(block, UI_EMBOSSM);
@@ -1587,57 +1639,100 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
        {
        case ACT_OBJECT:
                {
-                       ysize= 152;
-                       
-                       glRects(xco, yco-ysize, xco+width, yco);
-                       uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
-                       
                        oa = act->data;
                        wval = (width-100)/3;
-                       
-                       uiDefBut(block, LABEL, 0, "Force",      xco, yco-22, 55, 19, NULL, 0, 0, 0, 0, "Sets the force");
-                       uiDefButF(block, NUM, 0, "",            xco+45, yco-22, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-22, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-22, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, "");
-                       
-                       uiDefBut(block, LABEL, 0, "Torque", xco, yco-41, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque");
-                       uiDefButF(block, NUM, 0, "",            xco+45, yco-41, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-41, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-41, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, "");
-                       
-                       uiDefBut(block, LABEL, 0, "dLoc",       xco, yco-64, 45, 19, NULL, 0, 0, 0, 0, "Sets the dLoc");
-                       uiDefButF(block, NUM, 0, "",            xco+45, yco-64, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-64, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-64, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
-                       
-                       uiDefBut(block, LABEL, 0, "dRot",       xco, yco-83, 45, 19, NULL, 0, 0, 0, 0, "Sets the dRot");
-                       uiDefButF(block, NUM, 0, "",            xco+45, yco-83, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-83, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-83, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
-                       
-                       uiDefBut(block, LABEL, 0, "linV",       xco, yco-106, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity");
-                       uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
-                       
-                       uiDefBut(block, LABEL, 0, "angV",       xco, yco-125, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity");
-                       uiDefButF(block, NUM, 0, "",            xco+45, yco-125, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-125, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, "");
-                       uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-125, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, "");
-                       
-                       uiDefBut(block, LABEL, 0, "damp",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Number of frames to reach the target velocity");
-                       uiDefButI(block, NUM, 0, "",            xco+45, yco-148, wval, 19, &oa->damping, 0.0, 1000.0, 100, 0, "");
-                       uiDefButBitS(block, TOG, ACT_CLAMP_VEL, 0, "clamp",xco+45+wval, yco-148, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Toggles between SET and CLAMP Velocity");
-
-                       uiDefButBitS(block, TOG, ACT_FORCE_LOCAL, 0, "L",               xco+45+3*wval, yco-22, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
-                       uiDefButBitS(block, TOG, ACT_TORQUE_LOCAL, 0, "L",              xco+45+3*wval, yco-41, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
-                       uiDefButBitS(block, TOG, ACT_DLOC_LOCAL, 0, "L",                xco+45+3*wval, yco-64, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
-                       uiDefButBitS(block, TOG, ACT_DROT_LOCAL, 0, "L",                xco+45+3*wval, yco-83, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
-                       uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-106, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
-                       uiDefButBitS(block, TOG, ACT_ANG_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-125, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
-                       
-                       uiDefButBitS(block, TOG, ACT_ADD_LIN_VEL, 0, "add",xco+45+3*wval+15, yco-106, 35, 19, &oa->flag, 0.0, 0.0, 0, 0, "Toggles between ADD and SET linV");
-                       
+                       if (oa->type == ACT_OBJECT_NORMAL)
+                       {
+                               ysize= 175;
+                               
+                               glRects(xco, yco-ysize, xco+width, yco);
+                               uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
+                               
+                               uiDefBut(block, LABEL, 0, "Force",      xco, yco-45, 55, 19, NULL, 0, 0, 0, 0, "Sets the force");
+                               uiDefButF(block, NUM, 0, "",            xco+45, yco-45, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-45, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-45, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, "");
+                               
+                               uiDefBut(block, LABEL, 0, "Torque", xco, yco-64, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque");
+                               uiDefButF(block, NUM, 0, "",            xco+45, yco-64, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-64, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-64, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, "");
+                               
+                               uiDefBut(block, LABEL, 0, "dLoc",       xco, yco-87, 45, 19, NULL, 0, 0, 0, 0, "Sets the dLoc");
+                               uiDefButF(block, NUM, 0, "",            xco+45, yco-87, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-87, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-87, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
+                               
+                               uiDefBut(block, LABEL, 0, "dRot",       xco, yco-106, 45, 19, NULL, 0, 0, 0, 0, "Sets the dRot");
+                               uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
+                               
+                               uiDefBut(block, LABEL, 0, "linV",       xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity");
+                               uiDefButF(block, NUM, 0, "",            xco+45, yco-129, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-129, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-129, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
+                               
+                               uiDefBut(block, LABEL, 0, "angV",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity");
+                               uiDefButF(block, NUM, 0, "",            xco+45, yco-148, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-148, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-148, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, "");
+                               
+                               uiDefBut(block, LABEL, 0, "damp",       xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Number of frames to reach the target velocity");
+                               uiDefButI(block, NUM, 0, "",            xco+45, yco-171, wval, 19, &oa->damping, 0.0, 1000.0, 100, 0, "");
+
+                               uiDefButBitS(block, TOG, ACT_FORCE_LOCAL, 0, "L",               xco+45+3*wval, yco-45, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
+                               uiDefButBitS(block, TOG, ACT_TORQUE_LOCAL, 0, "L",              xco+45+3*wval, yco-64, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
+                               uiDefButBitS(block, TOG, ACT_DLOC_LOCAL, 0, "L",                xco+45+3*wval, yco-87, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
+                               uiDefButBitS(block, TOG, ACT_DROT_LOCAL, 0, "L",                xco+45+3*wval, yco-106, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
+                               uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-129, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
+                               uiDefButBitS(block, TOG, ACT_ANG_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-148, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
+                               
+                               uiDefButBitS(block, TOG, ACT_ADD_LIN_VEL, 0, "add",xco+45+3*wval+15, yco-129, 35, 19, &oa->flag, 0.0, 0.0, 0, 0, "Toggles between ADD and SET linV");
+                               
+                       } else if (oa->type == ACT_OBJECT_SERVO)
+                       {
+                               ysize= 172;
+                               
+                               glRects(xco, yco-ysize, xco+width, yco);
+                               uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
+                               
+                               uiDefBut(block, LABEL, 0, "linV",       xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "Sets the target linear velocity, it will be achieve by automatic application of force. Null velocity is a valid target");
+                               uiDefButF(block, NUM, 0, "",            xco+45, yco-45, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-45, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-45, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
+                               uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-45, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Velocity is defined in local coordinates");
+
+                               uiDefBut(block, LABEL, 0, "Limit",      xco, yco-68, 45, 19, NULL, 0, 0, 0, 0, "Select if the force need to be limited along certain axis (local or global depending on LinV Local flag)");
+                               uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_X, B_REDR, "X",                xco+45, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the X axis");
+                               uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Y, B_REDR, "Y",                xco+45+wval, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Y axis");
+                               uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Z, B_REDR, "Z",                xco+45+2*wval, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Z axis");
+                               uiDefBut(block, LABEL, 0, "Max",        xco, yco-87, 45, 19, NULL, 0, 0, 0, 0, "Set the upper limit for force");
+                               uiDefBut(block, LABEL, 0, "Min",        xco, yco-106, 45, 19, NULL, 0, 0, 0, 0, "Set the lower limit for force");
+                               if (oa->flag & ACT_SERVO_LIMIT_X) {
+                                       uiDefButF(block, NUM, 0, "",            xco+45, yco-87, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
+                                       uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
+                               }
+                               if (oa->flag & ACT_SERVO_LIMIT_Y) {
+                                       uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-87, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
+                                       uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
+                               }
+                               if (oa->flag & ACT_SERVO_LIMIT_Z) {
+                                       uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-87, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
+                                       uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
+                               }
+                               uiDefBut(block, LABEL, 0, "Servo",      xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Coefficients of the PID servo controller");
+                               uiDefButF(block, NUMSLI, B_REDR, "P: ",         xco+45, yco-129, wval*3, 19, oa->forcerot, 0.00, 200.0, 100, 0, "Proportional coefficient, typical value is 60x Integral coefficient");
+                               uiDefBut(block, LABEL, 0, "Slow",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Low value of I coefficient correspond to slow response");
+                               but = uiDefButF(block, NUMSLI, B_REDR, " I : ",         xco+45, yco-148, wval*3, 19, oa->forcerot+1, 0.0, 3.0, 1, 0, "Integral coefficient, low value (0.01) for slow response, high value (0.5) for fast response");
+                               uiButSetFunc(but, update_object_actuator_PID, oa, NULL);
+                               uiDefBut(block, LABEL, 0, "Fast",       xco+45+3*wval, yco-148, 45, 19, NULL, 0, 0, 0, 0, "High value of I coefficient correspond to fast response");
+                               uiDefButF(block, NUMSLI, B_REDR, "D: ",         xco+45, yco-167, wval*3, 19, oa->forcerot+2, -100.0, 100.0, 100, 0, "Derivate coefficient, not required, high values can cause instability");
+                       }
+                       str= "Motion Type %t|Simple motion %x0|Servo Control %x1";
+                       but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &oa->type, 0.0, 0.0, 0, 0, "");
+                       oa->otype = oa->type;
+                       uiButSetFunc(but, change_object_actuator, oa, NULL);
                        yco-= ysize;
                        break;
                }
@@ -1930,34 +2025,97 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
         break;
  
        case ACT_CONSTRAINT:
+               coa= act->data;
        
-               ysize= 44;
+               if (coa->type == ACT_CONST_TYPE_LOC) {
+                       ysize= 69;
         
-               glRects(xco, yco-ysize, xco+width, yco);
-               uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
+                       glRects(xco, yco-ysize, xco+width, yco);
+                       uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
+                       
+       /*              str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4|Rot X %x8|Rot Y %x16|Rot Z %x32"; */
+       /*                      coa->flag &= ~(63); */
+                       str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4";
+                       coa->flag &= ~(7);
+                       coa->time = 0;
+                       uiDefButS(block, MENU, 1, str,          xco+10, yco-65, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, "");
                
-               coa= act->data;
+                       uiDefButS(block, NUM,           0, "Damp:",     xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "");
+                       uiDefBut(block, LABEL,                  0, "Min",       xco+80, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
+                       uiDefBut(block, LABEL,                  0, "Max",       xco+80+(width-90)/2, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
+
+                       if(coa->flag & ACT_CONST_LOCX) fp= coa->minloc;
+                       else if(coa->flag & ACT_CONST_LOCY) fp= coa->minloc+1;
+                       else if(coa->flag & ACT_CONST_LOCZ) fp= coa->minloc+2;
+                       else if(coa->flag & ACT_CONST_ROTX) fp= coa->minrot;
+                       else if(coa->flag & ACT_CONST_ROTY) fp= coa->minrot+1;
+                       else fp= coa->minrot+2;
+                       
+                       uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-90)/2, 19, fp, -2000.0, 2000.0, 10, 0, "");
+                       uiDefButF(block, NUM, 0, "",            xco+80+(width-90)/2, yco-65, (width-90)/2, 19, fp+3, -2000.0, 2000.0, 10, 0, "");
+               } else if (coa->type == ACT_CONST_TYPE_DIST) {
+                       ysize= 106;
+
+                       glRects(xco, yco-ysize, xco+width, yco);
+                       uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
+                       
+                       str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32";
+                       uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Set the direction of the ray");
                
-/*             str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4|Rot X %x8|Rot Y %x16|Rot Z %x32"; */
-               str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4";
-               uiDefButS(block, MENU, 1, str,          xco+10, yco-40, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, "");
-       
-               uiDefButS(block, NUM,           0, "Damp:",     xco+10, yco-20, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "");
-               uiDefBut(block, LABEL,                  0, "Min",       xco+80, yco-20, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
-               uiDefBut(block, LABEL,                  0, "Max",       xco+80+(width-90)/2, yco-20, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
-
-               if(coa->flag & ACT_CONST_LOCX) fp= coa->minloc;
-               else if(coa->flag & ACT_CONST_LOCY) fp= coa->minloc+1;
-               else if(coa->flag & ACT_CONST_LOCZ) fp= coa->minloc+2;
-               else if(coa->flag & ACT_CONST_ROTX) fp= coa->minrot;
-               else if(coa->flag & ACT_CONST_ROTY) fp= coa->minrot+1;
-               else fp= coa->minrot+2;
+                       uiDefButS(block, NUM,           0, "Damp:",     xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "");
+                       uiDefBut(block, LABEL,                  0, "Range",     xco+80, yco-45, (width-115)/2, 19, NULL, 0.0, 0.0, 0, 0, "Set the maximum length of ray");
+                       uiDefButBitS(block, TOG, ACT_CONST_DISTANCE, B_REDR, "Dist",    xco+80+(width-115)/2, yco-45, (width-115)/2, 19, &coa->flag, 0.0, 0.0, 0, 0, "Force distance of object to point of impact of ray");
+
+                       if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRMX)) fp= coa->minloc;
+                       else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRMY)) fp= coa->minloc+1;
+                       else fp= coa->minloc+2;
+
+                       uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-115)/2, 19, fp+3, 0.0, 2000.0, 10, 0, "Maximum length of ray");
+                       if (coa->flag & ACT_CONST_DISTANCE)
+                               uiDefButF(block, NUM, 0, "",            xco+80+(width-115)/2, yco-65, (width-115)/2, 19, fp, -2000.0, 2000.0, 10, 0, "Keep this distance to target");
+                       uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
+                                        &coa->flag, 0.0, 0.0, 0, 0, "Set object axis along the normal at hit position");
+                       uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
+                                        &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
+                       if (coa->flag & ACT_CONST_MATERIAL)
+                       {
+                               uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
+                                       coa->matprop, 0, 31, 0, 0,
+                                       "Ray detects only Objects with this material");
+                       }
+                       else
+                       {
+                               uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
+                                       coa->matprop, 0, 31, 0, 0,
+                                       "Ray detect only Objects with this property");
+                       }
+                       uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
+                               &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
+                       uiDefButS(block, NUM, 0, "time", xco+50, yco-103, (width-60)/2, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited");
+                       uiDefButS(block, NUM, 0, "rotDamp", xco+50+(width-60)/2, yco-103, (width-60)/2, 19, &(coa->rotdamp), 0.0, 100.0, 0, 0, "Use a different damping for orientation");
+               } else if (coa->type == ACT_CONST_TYPE_ORI) {
+                       ysize= 87;
+
+                       glRects(xco, yco-ysize, xco+width, yco);
+                       uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
+                       
+                       str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4";
+                       uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Select the axis to be aligned along the reference direction");
                
-               uiDefButF(block, NUM, 0, "",            xco+80, yco-40, (width-90)/2, 19, fp, -2000.0, 2000.0, 10, 0, "");
-               uiDefButF(block, NUM, 0, "",            xco+80+(width-90)/2, yco-40, (width-90)/2, 19, fp+3, -2000.0, 2000.0, 10, 0, "");
+                       uiDefButS(block, NUM,           0, "Damp:",     xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "");
+                       uiDefBut(block, LABEL,                  0, "X", xco+80, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
+                       uiDefBut(block, LABEL,                  0, "Y", xco+80+(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
+                       uiDefBut(block, LABEL,                  0, "Z", xco+80+2*(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
+
+                       uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-115)/3, 19, &coa->maxrot[0], -2000.0, 2000.0, 10, 0, "X component of reference direction");
+                       uiDefButF(block, NUM, 0, "",            xco+80+(width-115)/3, yco-65, (width-115)/3, 19, &coa->maxrot[1], -2000.0, 2000.0, 10, 0, "Y component of reference direction");
+                       uiDefButF(block, NUM, 0, "",            xco+80+2*(width-115)/3, yco-65, (width-115)/3, 19, &coa->maxrot[2], -2000.0, 2000.0, 10, 0, "Z component of reference direction");
 
+                       uiDefButS(block, NUM, 0, "time", xco+10, yco-84, 70+(width-115)/3, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited");
+               }
+               str= "Constraint Type %t|Location %x0|Distance %x1|Orientation %x2";
+               but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &coa->type, 0.0, 0.0, 0, 0, "");
                yco-= ysize;
-        
         break;
  
        case ACT_SCENE:
index ea26c55a44e44344e41383da42378e3900637258..6e05ea31fe81a2ec86c6f5eef1b7a5213b3f83ea 100644 (file)
@@ -159,7 +159,7 @@ void BL_ConvertActuators(char* maggiename,
                                bitLocalFlag.DRot = bool((obact->flag & ACT_DROT_LOCAL)!=0);
                                bitLocalFlag.LinearVelocity = bool((obact->flag & ACT_LIN_VEL_LOCAL)!=0);
                                bitLocalFlag.AngularVelocity = bool((obact->flag & ACT_ANG_VEL_LOCAL)!=0);
-                               bitLocalFlag.ClampVelocity = bool((obact->flag & ACT_CLAMP_VEL)!=0);
+                               bitLocalFlag.ServoControl = bool(obact->type == ACT_OBJECT_SERVO);
                                bitLocalFlag.AddOrSetLinV = bool((obact->flag & ACT_ADD_LIN_VEL)!=0);
                                
                                
@@ -619,51 +619,105 @@ void BL_ConvertActuators(char* maggiename,
                case ACT_CONSTRAINT:
                        {
                                float min = 0.0, max = 0.0;
+                               char *prop = NULL;
                                KX_ConstraintActuator::KX_CONSTRAINTTYPE locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF;
                                bConstraintActuator *conact 
                                        = (bConstraintActuator*) bact->data;
                                /* convert settings... degrees in the ui become radians  */ 
                                /* internally                                            */ 
-                               switch (conact->flag) {
-                               case ACT_CONST_LOCX:
-                                       locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX; 
-                                       min = conact->minloc[0];
-                                       max = conact->maxloc[0];
-                                       break;
-                               case ACT_CONST_LOCY:
-                                       locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY; 
-                                       min = conact->minloc[1];
-                                       max = conact->maxloc[1];
-                                       break;
-                               case ACT_CONST_LOCZ:
-                                       locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ;
-                                       min = conact->minloc[2];
-                                       max = conact->maxloc[2];
-                                       break;
-                               case ACT_CONST_ROTX:
-                                       locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX;
-                                       min = MT_2_PI * conact->minrot[0] / 360.0;
-                                       max = MT_2_PI * conact->maxrot[0] / 360.0;
-                                       break;
-                               case ACT_CONST_ROTY:
-                                       locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY;
-                                       min = MT_2_PI * conact->minrot[1] / 360.0;
-                                       max = MT_2_PI * conact->maxrot[1] / 360.0;
-                                       break;
-                               case ACT_CONST_ROTZ:
-                                       locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ;
-                                       min = MT_2_PI * conact->minrot[2] / 360.0;
-                                       max = MT_2_PI * conact->maxrot[2] / 360.0;
-                                       break;
-                               default:
-                                       ; /* error */ 
+                               if (conact->type == ACT_CONST_TYPE_ORI) {
+                                       switch (conact->mode) {
+                                       case ACT_CONST_DIRPX:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX;
+                                               break;
+                                       case ACT_CONST_DIRPY:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY;
+                                               break;
+                                       case ACT_CONST_DIRPZ:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ;
+                                               break;
+                                       }
+                               } else if (conact->type == ACT_CONST_TYPE_DIST) {
+                                       switch (conact->mode) {
+                                       case ACT_CONST_DIRPX:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX;
+                                               min = conact->minloc[0];
+                                               max = conact->maxloc[0];
+                                               break;
+                                       case ACT_CONST_DIRPY:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY;
+                                               min = conact->minloc[1];
+                                               max = conact->maxloc[1];
+                                               break;
+                                       case ACT_CONST_DIRPZ:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ;
+                                               min = conact->minloc[2];
+                                               max = conact->maxloc[2];
+                                               break;
+                                       case ACT_CONST_DIRMX:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRMX;
+                                               min = conact->minloc[0];
+                                               max = conact->maxloc[0];
+                                               break;
+                                       case ACT_CONST_DIRMY:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRMY;
+                                               min = conact->minloc[1];
+                                               max = conact->maxloc[1];
+                                               break;
+                                       case ACT_CONST_DIRMZ:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRMZ;
+                                               min = conact->minloc[2];
+                                               max = conact->maxloc[2];
+                                               break;
+                                       }
+                                       prop = conact->matprop;
+                               } else {
+                                       switch (conact->flag) {
+                                       case ACT_CONST_LOCX:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX; 
+                                               min = conact->minloc[0];
+                                               max = conact->maxloc[0];
+                                               break;
+                                       case ACT_CONST_LOCY:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY; 
+                                               min = conact->minloc[1];
+                                               max = conact->maxloc[1];
+                                               break;
+                                       case ACT_CONST_LOCZ:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ;
+                                               min = conact->minloc[2];
+                                               max = conact->maxloc[2];
+                                               break;
+                                       case ACT_CONST_ROTX:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX;
+                                               min = MT_2_PI * conact->minrot[0] / 360.0;
+                                               max = MT_2_PI * conact->maxrot[0] / 360.0;
+                                               break;
+                                       case ACT_CONST_ROTY:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY;
+                                               min = MT_2_PI * conact->minrot[1] / 360.0;
+                                               max = MT_2_PI * conact->maxrot[1] / 360.0;
+                                               break;
+                                       case ACT_CONST_ROTZ:
+                                               locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ;
+                                               min = MT_2_PI * conact->minrot[2] / 360.0;
+                                               max = MT_2_PI * conact->maxrot[2] / 360.0;
+                                               break;
+                                       default:
+                                               ; /* error */ 
+                                       }
                                }
                                KX_ConstraintActuator *tmpconact 
                                        = new KX_ConstraintActuator(gameobj,
-                                       conact->damp,
-                                       min,
-                                       max,
-                                       locrot);
+                                               conact->damp,
+                                               conact->rotdamp,
+                                               min,
+                                               max,
+                                               conact->maxrot,
+                                               locrot,
+                                               conact->time,
+                                               conact->flag,
+                                               prop);
                                baseact = tmpconact;
                                break;
                        }
index e7e4eeae7d2a801cb23e3325fc76429027ce6187..7c9df688d45ca4819915b8071b2b5cdb4db09b47 100644 (file)
@@ -64,6 +64,7 @@ probably misplaced */
 #include "KX_MouseFocusSensor.h"
 #include "SCA_JoystickSensor.h"
 #include "KX_NetworkMessageSensor.h"
+#include "SCA_ActuatorSensor.h"
 
 
 #include "SCA_PropertySensor.h"
@@ -538,6 +539,19 @@ void BL_ConvertSensors(struct Object* blenderobject,
                                
                                break;
                        }
+               case SENS_ACTUATOR:
+                       {
+                               bActuatorSensor* blenderactsensor = (bActuatorSensor*) sens->data;
+                               // we will reuse the property event manager, there is nothing special with this sensor
+                               SCA_EventManager* eventmgr 
+                                       = logicmgr->FindEventManager(SCA_EventManager::ACTUATOR_EVENTMGR);
+                               if (eventmgr)
+                               {
+                                       STR_String propname=blenderactsensor->name;
+                                       gamesensor = new SCA_ActuatorSensor(eventmgr,gameobj,propname);
+                               }
+                               break;
+                       }
                        
                case SENS_RADAR:
                        {
diff --git a/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp b/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp
new file mode 100644 (file)
index 0000000..28ca1fd
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+ * $Id$
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "SCA_ISensor.h"
+#include "SCA_ActuatorEventManager.h"
+#include "SCA_ActuatorSensor.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+SCA_ActuatorEventManager::SCA_ActuatorEventManager(class SCA_LogicManager* logicmgr)
+       : SCA_EventManager(ACTUATOR_EVENTMGR),
+       m_logicmgr(logicmgr)
+{
+}
+
+
+
+SCA_ActuatorEventManager::~SCA_ActuatorEventManager()
+{
+
+}
+
+
+
+void SCA_ActuatorEventManager::RegisterSensor(SCA_ISensor* sensor)
+{
+       m_sensors.push_back(sensor);
+}
+
+
+
+void SCA_ActuatorEventManager::NextFrame()
+{
+       // check for changed actuator
+       for (vector<SCA_ISensor*>::const_iterator it = m_sensors.begin();!(it==m_sensors.end());it++)
+       {
+               (*it)->Activate(m_logicmgr,NULL);
+       }
+}
+
+void SCA_ActuatorEventManager::UpdateFrame()
+{
+       // update the state of actuator before executing them
+       for (vector<SCA_ISensor*>::const_iterator it = m_sensors.begin();!(it==m_sensors.end());it++)
+       {
+               ((SCA_ActuatorSensor*)(*it))->Update();
+       }
+}
\ No newline at end of file
diff --git a/source/gameengine/GameLogic/SCA_ActuatorEventManager.h b/source/gameengine/GameLogic/SCA_ActuatorEventManager.h
new file mode 100644 (file)
index 0000000..b510876
--- /dev/null
@@ -0,0 +1,52 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef __KX_ACTUATOREVENTMANAGER
+#define __KX_ACTUATOREVENTMANAGER
+
+#include "SCA_EventManager.h"
+
+#include <vector>
+
+using namespace std;
+
+class SCA_ActuatorEventManager : public SCA_EventManager
+{
+       class SCA_LogicManager* m_logicmgr;
+
+public:
+       SCA_ActuatorEventManager(class SCA_LogicManager* logicmgr);
+       virtual ~SCA_ActuatorEventManager();
+       virtual void NextFrame();
+       virtual void UpdateFrame();
+       virtual void    RegisterSensor(SCA_ISensor* sensor);
+       //SCA_LogicManager* GetLogicManager() { return m_logicmgr;}
+};
+
+#endif //__KX_ACTUATOREVENTMANAGER
+
diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
new file mode 100644 (file)
index 0000000..9645bfb
--- /dev/null
@@ -0,0 +1,196 @@
+/**
+ * Actuator sensor
+ *
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <iostream>
+#include "SCA_ActuatorSensor.h"
+#include "SCA_EventManager.h"
+#include "SCA_LogicManager.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+SCA_ActuatorSensor::SCA_ActuatorSensor(SCA_EventManager* eventmgr,
+                                                                        SCA_IObject* gameobj,
+                                                                        const STR_String& actname,
+                                                                        PyTypeObject* T )
+       : SCA_ISensor(gameobj,eventmgr,T),
+         m_checkactname(actname)
+{
+       m_actuator = GetParent()->FindActuator(m_checkactname);
+       Init();
+}
+
+void SCA_ActuatorSensor::Init()
+{
+       m_lastresult = m_invert?true:false;
+       m_midresult = m_lastresult;
+       m_reset = true;
+}
+
+CValue* SCA_ActuatorSensor::GetReplica()
+{
+       SCA_ActuatorSensor* replica = new SCA_ActuatorSensor(*this);
+       // m_range_expr must be recalculated on replica!
+       CValue::AddDataToReplica(replica);
+       replica->Init();
+
+       return replica;
+}
+
+void SCA_ActuatorSensor::ReParent(SCA_IObject* parent)
+{
+       m_actuator = parent->FindActuator(m_checkactname);
+       SCA_ISensor::ReParent(parent);
+}
+
+bool SCA_ActuatorSensor::IsPositiveTrigger()
+{
+       bool result = m_lastresult;
+       if (m_invert)
+               result = !result;
+
+       return result;
+}
+
+
+
+SCA_ActuatorSensor::~SCA_ActuatorSensor()
+{
+}
+
+
+
+bool SCA_ActuatorSensor::Evaluate(CValue* event)
+{
+       if (m_actuator)
+       {
+               bool result = m_actuator->IsActive();
+               bool reset = m_reset && m_level;
+               
+               m_reset = false;
+               if (m_lastresult != result || m_midresult != result)
+               {
+                       m_lastresult = m_midresult = result;
+                       return true;
+               }
+               return (reset) ? true : false;
+       }
+       return false;
+}
+
+void SCA_ActuatorSensor::Update()
+{
+       if (m_actuator)
+       {
+               m_midresult = m_actuator->IsActive();
+       }
+}
+
+
+/* ------------------------------------------------------------------------- */
+/* Python functions                                                          */
+/* ------------------------------------------------------------------------- */
+
+/* Integration hooks ------------------------------------------------------- */
+PyTypeObject SCA_ActuatorSensor::Type = {
+       PyObject_HEAD_INIT(&PyType_Type)
+       0,
+       "SCA_ActuatorSensor",
+       sizeof(SCA_ActuatorSensor),
+       0,
+       PyDestructor,
+       0,
+       __getattr,
+       __setattr,
+       0, //&MyPyCompare,
+       __repr,
+       0, //&cvalue_as_number,
+       0,
+       0,
+       0,
+       0
+};
+
+PyParentObject SCA_ActuatorSensor::Parents[] = {
+       &SCA_ActuatorSensor::Type,
+       &SCA_ISensor::Type,
+       &SCA_ILogicBrick::Type,
+       &CValue::Type,
+       NULL
+};
+
+PyMethodDef SCA_ActuatorSensor::Methods[] = {
+       {"getActuator", (PyCFunction) SCA_ActuatorSensor::sPyGetActuator, METH_VARARGS, GetActuator_doc},
+       {"setActuator", (PyCFunction) SCA_ActuatorSensor::sPySetActuator, METH_VARARGS, SetActuator_doc},
+       {NULL,NULL} //Sentinel
+};
+
+PyObject* SCA_ActuatorSensor::_getattr(const STR_String& attr) {
+       _getattr_up(SCA_ISensor); /* implicit return! */
+}
+
+/* 3. getActuator */
+char SCA_ActuatorSensor::GetActuator_doc[] = 
+"getActuator()\n"
+"\tReturn the Actuator with which the sensor operates.\n";
+PyObject* SCA_ActuatorSensor::PyGetActuator(PyObject* self, PyObject* args, PyObject* kwds) 
+{
+       return PyString_FromString(m_checkactname);
+}
+
+/* 4. setActuator */
+char SCA_ActuatorSensor::SetActuator_doc[] = 
+"setActuator(name)\n"
+"\t- name: string\n"
+"\tSets the Actuator with which to operate. If there is no Actuator\n"
+"\tof this name, the call is ignored.\n";
+PyObject* SCA_ActuatorSensor::PySetActuator(PyObject* self, PyObject* args, PyObject* kwds) 
+{
+       /* We should query whether the name exists. Or should we create a prop   */
+       /* on the fly?                                                           */
+       char *actNameArg = NULL;
+
+       if (!PyArg_ParseTuple(args, "s", &actNameArg)) {
+               return NULL;
+       }
+
+       SCA_IActuator* act = GetParent()->FindActuator(STR_String(actNameArg));
+       if (act) {
+               m_checkactname = actNameArg;
+               m_actuator = act;
+       } else {
+               ; /* error: bad actuator name */
+       }
+       Py_Return;
+}
+
+/* eof */
diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.h b/source/gameengine/GameLogic/SCA_ActuatorSensor.h
new file mode 100644 (file)
index 0000000..6086c5b
--- /dev/null
@@ -0,0 +1,74 @@
+/**
+ * Actuator sensor
+ *
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __KX_ACTUATORSENSOR
+#define __KX_ACTUATORSENSOR
+
+#include "SCA_ISensor.h"
+#include "SCA_IActuator.h"
+
+class SCA_ActuatorSensor : public SCA_ISensor
+{
+       Py_Header;
+       STR_String              m_checkactname;
+       bool                    m_lastresult;
+       bool                    m_midresult;
+ protected:
+       SCA_IActuator*  m_actuator;
+public:
+       SCA_ActuatorSensor(class SCA_EventManager* eventmgr,
+                                         SCA_IObject* gameobj,
+                                         const STR_String& actname,
+                                         PyTypeObject* T=&Type );
+       
+       virtual ~SCA_ActuatorSensor();
+       virtual CValue* GetReplica();
+       virtual void Init();
+       virtual bool Evaluate(CValue* event);
+       virtual bool    IsPositiveTrigger();
+       virtual void    ReParent(SCA_IObject* parent);
+       void Update();
+
+       /* --------------------------------------------------------------------- */
+       /* Python interface ---------------------------------------------------- */
+       /* --------------------------------------------------------------------- */
+
+       virtual PyObject* _getattr(const STR_String& attr);
+
+       /* 3. setProperty */
+       KX_PYMETHOD_DOC(SCA_ActuatorSensor,SetActuator);
+       /* 4. getProperty */
+       KX_PYMETHOD_DOC(SCA_ActuatorSensor,GetActuator);
+       
+};
+
+#endif
+
index 1ca88182ddc7eb5bfeeffb95aca231c0cf171fd7..0169864a1338ff42f4c92b5692b1f32222653acc 100644 (file)
@@ -72,7 +72,9 @@ void SCA_EventManager::EndFrame()
 {
 }
 
-
+void SCA_EventManager::UpdateFrame()
+{
+}
 
 int SCA_EventManager::GetType()
 {
index 89731497f6f10b3cf95c5daa1fc0aedd22c658f1..9cc1718cd1e4a7af1090cf91561bcd9910645a1d 100644 (file)
@@ -49,7 +49,8 @@ public:
                RAY_EVENTMGR,
                RADAR_EVENTMGR,
                NETWORK_EVENTMGR,
-               JOY_EVENTMGR
+               JOY_EVENTMGR,
+               ACTUATOR_EVENTMGR
        };
 
        SCA_EventManager(EVENT_MANAGER_TYPE mgrtype);
@@ -58,6 +59,7 @@ public:
        virtual void    RemoveSensor(class SCA_ISensor* sensor);
        virtual void    NextFrame(double curtime, double fixedtime);
        virtual void    NextFrame();
+       virtual void    UpdateFrame();
        virtual void    EndFrame();
        virtual void    RegisterSensor(class SCA_ISensor* sensor)=0;
        int             GetType();
index 826e7bbdf0e28f7ee4415a1a5d5e75b67dff9ad9..27e7d5faadab05f8bebcb73e3246379862b3e754 100644 (file)
@@ -157,15 +157,15 @@ bool SCA_IObject::GetIgnoreActivityCulling()
 
 void SCA_IObject::ReParentLogic()
 {
-       SCA_SensorList& oldsensors = GetSensors();
-       
-       int sen = 0;
-       SCA_SensorList::iterator its;
-       for (its = oldsensors.begin(); !(its==oldsensors.end()); ++its)
+       SCA_ActuatorList& oldactuators  = GetActuators();
+       int act = 0;
+       SCA_ActuatorList::iterator ita;
+       for (ita = oldactuators.begin(); !(ita==oldactuators.end()); ++ita)
        {
-               SCA_ISensor* newsensor = (SCA_ISensor*)(*its)->GetReplica();
-               newsensor->ReParent(this);
-               oldsensors[sen++] = newsensor;
+               SCA_IActuator* newactuator = (SCA_IActuator*) (*ita)->GetReplica();
+               newactuator->ReParent(this);
+               newactuator->SetActive(false);
+               oldactuators[act++] = newactuator;
        }
 
        SCA_ControllerList& oldcontrollers = GetControllers();
@@ -178,17 +178,17 @@ void SCA_IObject::ReParentLogic()
                oldcontrollers[con++]=newcontroller;
 
        }
-       SCA_ActuatorList& oldactuators  = GetActuators();
-       
-       int act = 0;
-       SCA_ActuatorList::iterator ita;
-       for (ita = oldactuators.begin(); !(ita==oldactuators.end()); ++ita)
+       // convert sensors last so that actuators are already available for Actuator sensor
+       SCA_SensorList& oldsensors = GetSensors();
+       int sen = 0;
+       SCA_SensorList::iterator its;
+       for (its = oldsensors.begin(); !(its==oldsensors.end()); ++its)
        {
-               SCA_IActuator* newactuator = (SCA_IActuator*) (*ita)->GetReplica();
-               newactuator->ReParent(this);
-               newactuator->SetActive(false);
-               oldactuators[act++] = newactuator;
+               SCA_ISensor* newsensor = (SCA_ISensor*)(*its)->GetReplica();
+               newsensor->ReParent(this);
+               oldsensors[sen++] = newsensor;
        }
+
        // a new object cannot be client of any actuator
        m_registeredActuators.clear();
                
index 1b163deb7bbdb7e190a3fe703e7e89f8c1bf4178..68341b5743590a29207348f96c0b42a295fb464c 100644 (file)
@@ -56,6 +56,7 @@ SCA_ISensor::SCA_ISensor(SCA_IObject* gameobj,
        m_suspended = false;
        m_invert = false;
        m_level = false;
+       m_reset = false;
        m_pos_ticks = 0;
        m_neg_ticks = 0;
        m_pos_pulsemode = false;
index 3527b87ebdb502e784bee0e651f3916d4c08a3df..f2ed6a803c2a145d5fcb2a5771d0da7ad62dd729 100644 (file)
@@ -64,6 +64,9 @@ class SCA_ISensor : public SCA_ILogicBrick
        /** detect level instead of edge*/
        bool m_level;
 
+       /** sensor has been reset */
+       bool m_reset;
+
        /** Sensor must ignore updates? */
        bool m_suspended;
 
index 8668c22f04484323b5a00222a654eeecdac58fa3..3fb439eb25bf91ae201e7f069ea0f871a66fb3dd 100644 (file)
@@ -70,6 +70,7 @@ std::cout << " hat flag "     << m_hatf               << std::endl;
 void SCA_JoystickSensor::Init()
 {
        m_istrig=(m_invert)?1:0;
+       m_reset = true;
 }
 
 SCA_JoystickSensor::~SCA_JoystickSensor()
@@ -79,9 +80,10 @@ SCA_JoystickSensor::~SCA_JoystickSensor()
 
 CValue* SCA_JoystickSensor::GetReplica()
 {
-       CValue* replica = new SCA_JoystickSensor(*this);
+       SCA_JoystickSensor* replica = new SCA_JoystickSensor(*this);
        // this will copy properties and so on...
        CValue::AddDataToReplica(replica);
+       replica->Init();
        return replica;
 }
 
@@ -99,7 +101,9 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
 {
        SCA_Joystick *js = m_pJoystickMgr->GetJoystickDevice();
        bool result = false;
+       bool reset = m_reset && m_level;
        
+       m_reset = false;
        switch(m_joymode)
        {
        case KX_JOYSENSORMODE_AXIS:
@@ -240,6 +244,8 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
        if(!js->IsTrig()){
                m_istrig = 0;
        }
+       if (reset)
+               result = true;
        return result;
 }
 
index 43ce25f94dffaf3c02c0e25b75b1c596e620c9f9..a7a6fa93db46f3c778f9bb7e2dff450760b805eb 100644 (file)
@@ -78,14 +78,15 @@ void SCA_KeyboardSensor::Init()
        // However, if the target key is pressed when the sensor is reactivated, it
        // will not generated an event (see remark in Evaluate()).
        m_val = (m_invert)?1:0;
+       m_reset = true;
 }
 
 CValue* SCA_KeyboardSensor::GetReplica()
 {
-       CValue* replica = new SCA_KeyboardSensor(*this);
+       SCA_KeyboardSensor* replica = new SCA_KeyboardSensor(*this);
        // this will copy properties and so on...
        CValue::AddDataToReplica(replica);
-
+       replica->Init();
        return replica;
 }
 
@@ -120,8 +121,8 @@ bool SCA_KeyboardSensor::TriggerOnAllKeys()
 bool SCA_KeyboardSensor::Evaluate(CValue* eventval)
 {
        bool result    = false;
+       bool reset     = m_reset && m_level;
        SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
-       
        //      cerr << "SCA_KeyboardSensor::Eval event, sensing for "<< m_hotkey << " at device " << inputdev << "\n";
 
        /* See if we need to do logging: togPropState exists and is
@@ -134,7 +135,7 @@ bool SCA_KeyboardSensor::Evaluate(CValue* eventval)
                LogKeystrokes();
        }
 
-
+       m_reset = false;
 
        /* Now see whether events must be bounced. */
        if (m_bAllKeys)
@@ -176,8 +177,8 @@ bool SCA_KeyboardSensor::Evaluate(CValue* eventval)
                                {
                                        if (m_val == 0)
                                        {
+                                               m_val = 1;
                                                if (m_level) {
-                                                       m_val = 1;
                                                        result = true;
                                                }
                                        }
@@ -229,9 +230,9 @@ bool SCA_KeyboardSensor::Evaluate(CValue* eventval)
                                        {
                                                if (m_val == 0)
                                                {
+                                                       m_val = 1;
                                                        if (m_level) 
                                                        {
-                                                               m_val = 1;
                                                                result = true;
                                                        }
                                                }
@@ -240,7 +241,9 @@ bool SCA_KeyboardSensor::Evaluate(CValue* eventval)
                        }
                }
        }
-
+       if (reset)
+               // force an event
+               result = true;
        return result;
 
 }
index fb1a2c29eb67a3e54745c892fad0f22a4cb35031..f50161cbecba7bea178d017b33784f02bdbd9033 100644 (file)
@@ -271,6 +271,10 @@ void SCA_LogicManager::UpdateFrame(double curtime, bool frame)
        }
        m_removedActuators.clear();
        
+       // About to run actuators, but before update the sensors for those which depends on actuators
+       for (vector<SCA_EventManager*>::const_iterator ie=m_eventmanagers.begin(); !(ie==m_eventmanagers.end()); ie++)
+               (*ie)->UpdateFrame();
+
        for (set<SmartActuatorPtr>::iterator ia = m_activeActuators.begin();!(ia==m_activeActuators.end());ia++)
        {
                //SCA_IActuator* actua = *ia;
index 42d35837489a501fea9bb180c2565d2768829b48..2298ddb07434cef2f84729bda053466ee187187c 100644 (file)
@@ -84,6 +84,7 @@ SCA_MouseSensor::SCA_MouseSensor(SCA_MouseManager* eventmgr,
 void SCA_MouseSensor::Init()
 {
        m_val = (m_invert)?1:0; /* stores the latest attribute */
+       m_reset = true;
 }
 
 SCA_MouseSensor::~SCA_MouseSensor() 
@@ -95,9 +96,10 @@ SCA_MouseSensor::~SCA_MouseSensor()
 
 CValue* SCA_MouseSensor::GetReplica()
 {
-       CValue* replica = new SCA_MouseSensor(*this);
+       SCA_MouseSensor* replica = new SCA_MouseSensor(*this);
        // this will copy properties and so on...
        CValue::AddDataToReplica(replica);
+       replica->Init();
 
        return replica;
 }
@@ -132,6 +134,7 @@ SCA_IInputDevice::KX_EnumInputs SCA_MouseSensor::GetHotKey()
 bool SCA_MouseSensor::Evaluate(CValue* event)
 {
        bool result = false;
+       bool reset = m_reset && m_level;
        SCA_IInputDevice* mousedev = m_pMouseMgr->GetInputDevice();
 
 
@@ -143,7 +146,7 @@ bool SCA_MouseSensor::Evaluate(CValue* event)
        /* both MOUSEX and MOUSEY. Treat all of these as key-presses.            */
        /* So, treat KX_MOUSESENSORMODE_POSITION as                              */
        /* KX_MOUSESENSORMODE_POSITIONX || KX_MOUSESENSORMODE_POSITIONY          */
-
+       m_reset = false;
        switch (m_mousemode) {
        case KX_MOUSESENSORMODE_LEFTBUTTON:
        case KX_MOUSESENSORMODE_MIDDLEBUTTON:
@@ -168,9 +171,9 @@ bool SCA_MouseSensor::Evaluate(CValue* event)
                                        {
                                                if (m_val == 0)
                                                {
+                                                       m_val = 1;
                                                        if (m_level)
                                                        {
-                                                               m_val = 1;
                                                                result = true;
                                                        }
                                                }
@@ -222,6 +225,9 @@ bool SCA_MouseSensor::Evaluate(CValue* event)
                ; /* error */
        }
 
+       if (reset)
+               // force an event
+               result = true;
        return result;
 }
 
index 655e906023898425aa86b36457576b52f251c786..c50c011cc63f353583f0b8654dd9b3df7c48413e 100644 (file)
@@ -78,6 +78,7 @@ void SCA_PropertySensor::Init()
 {
        m_recentresult = false;
        m_lastresult = m_invert?true:false;
+       m_reset = true;
 }
 
 void SCA_PropertySensor::PrecalculateRangeExpression()
@@ -111,6 +112,7 @@ CValue* SCA_PropertySensor::GetReplica()
        SCA_PropertySensor* replica = new SCA_PropertySensor(*this);
        // m_range_expr must be recalculated on replica!
        CValue::AddDataToReplica(replica);
+       replica->Init();
 
        replica->m_range_expr = NULL;
        if (replica->m_checktype==KX_PROPSENSOR_INTERVAL)
@@ -153,14 +155,15 @@ SCA_PropertySensor::~SCA_PropertySensor()
 bool SCA_PropertySensor::Evaluate(CValue* event)
 {
        bool result = CheckPropertyCondition();
+       bool reset = m_reset && m_level;
        
+       m_reset = false;
        if (m_lastresult!=result)
        {
                m_lastresult = result;
                return true;
        }
-
-       return false;
+       return (reset) ? true : false;
 }
 
 
index bd843d971996f92901320cdf2e70b4bfa1904a0e..80288a7248594b22570e9bff527ed25613adc897 100644 (file)
@@ -35,6 +35,7 @@
 #include "MT_Point3.h"
 #include "MT_Matrix3x3.h"
 #include "KX_GameObject.h"
+#include "KX_RayCast.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 /* ------------------------------------------------------------------------- */
 
 KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj, 
-                                                                                        int dampTime,
+                                                                                        int posDampTime,
+                                                                                        int rotDampTime,
                                                                                         float minBound,
                                                                                         float maxBound,
+                                                                                        float refDir[3],
                                                                                         int locrotxyz,
-                                                                                        PyTypeObject* T)
-       : SCA_IActuator(gameobj, T)
+                                                                                        int time,
+                                                                                        int option,
+                                                                                        char *property,
+                                                                                        PyTypeObject* T) : 
+       m_refDirection(refDir),
+       m_currentTime(0),
+       SCA_IActuator(gameobj, T)
 {
-       m_dampTime = dampTime;
+       m_posDampTime = posDampTime;
+       m_rotDampTime = rotDampTime;
        m_locrot   = locrotxyz;
+       m_option = option;
+       m_activeTime = time;
+       if (property) {
+               strncpy(m_property, property, sizeof(m_property));
+               m_property[sizeof(m_property)-1] = 0;
+       } else {
+               m_property[0] = 0;
+       }
        /* The units of bounds are determined by the type of constraint. To      */
        /* make the constraint application easier and more transparent later on, */
        /* I think converting the bounds to the applicable domain makes more     */
        /* sense.                                                                */
        switch (m_locrot) {
-       case KX_ACT_CONSTRAINT_LOCX:
-       case KX_ACT_CONSTRAINT_LOCY:
-       case KX_ACT_CONSTRAINT_LOCZ:
+       case KX_ACT_CONSTRAINT_ORIX:
+       case KX_ACT_CONSTRAINT_ORIY:
+       case KX_ACT_CONSTRAINT_ORIZ:
+               {
+                       MT_Scalar len = m_refDirection.length();
+                       if (MT_fuzzyZero(len)) {
+                               // missing a valid direction
+                               std::cout << "WARNING: Constraint actuator " << GetName() << ":  There is no valid reference direction!" << std::endl;
+                               m_locrot = KX_ACT_CONSTRAINT_NODEF;
+                       } else {
+                               m_refDirection /= len;
+                       }
+               }
+               break;
+       default:
                m_minimumBound = minBound;
                m_maximumBound = maxBound;
                break;
-       case KX_ACT_CONSTRAINT_ROTX:
-       case KX_ACT_CONSTRAINT_ROTY:
-       case KX_ACT_CONSTRAINT_ROTZ:
-               /* The user interface asks for degrees, we are radian.               */ 
-               m_minimumBound = MT_radians(minBound);
-               m_maximumBound = MT_radians(maxBound);
-               break;
-       default:
-               ; /* error */
        }
 
 } /* End of constructor */
@@ -83,77 +103,239 @@ KX_ConstraintActuator::~KX_ConstraintActuator()
        // there's nothing to be done here, really....
 } /* end of destructor */
 
-bool KX_ConstraintActuator::Update(double curtime, bool frame)
+bool KX_ConstraintActuator::RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data)
 {
 
-       bool result = false;    
-       bool bNegativeEvent = IsNegativeEvent();
-       RemoveAllEvents();
-
-       if (bNegativeEvent)
-               return false; // do nothing on negative events
-
-       /* Constraint clamps the values to the specified range, with a sort of    */
-       /* low-pass filtered time response, if the damp time is unequal to 0.     */
-
-       /* Having to retrieve location/rotation and setting it afterwards may not */
-       /* be efficient enough... Somthing to look at later.                      */
-       KX_GameObject  *parent = (KX_GameObject*) GetParent();
-       MT_Point3    position = parent->NodeGetWorldPosition();
-       MT_Matrix3x3 rotation = parent->NodeGetWorldOrientation();
-//     MT_Vector3      eulerrot = rotation.getEuler();
+       KX_GameObject* hitKXObj = client->m_gameobject;
        
-       switch (m_locrot) {
-       case KX_ACT_CONSTRAINT_LOCX:
-               Clamp(position[0], m_minimumBound, m_maximumBound);
-               result = true;
-               break;
-       case KX_ACT_CONSTRAINT_LOCY:
-               Clamp(position[1], m_minimumBound, m_maximumBound);
-               result = true;
-               break;
-       case KX_ACT_CONSTRAINT_LOCZ:
-               Clamp(position[2], m_minimumBound, m_maximumBound);
-               result = true;
-               break;
-       
-//     case KX_ACT_CONSTRAINT_ROTX:
-//             /* The angles are Euler angles (I think that's what they are called) */
-//             /* but we need to convert from/to the MT_Matrix3x3.                  */
-//             Clamp(eulerrot[0], m_minimumBound, m_maximumBound);
-//             break;
-//     case KX_ACT_CONSTRAINT_ROTY:
-//             Clamp(eulerrot[1], m_minimumBound, m_maximumBound);
-//             break;
-//     case KX_ACT_CONSTRAINT_ROTZ:
-//             Clamp(eulerrot[2], m_minimumBound, m_maximumBound);
-//             break;
-//     default:
-//             ; /* error */
+       if (client->m_type > KX_ClientObjectInfo::ACTOR)
+       {
+               // false hit
+               return false;
        }
+       bool bFound = false;
 
-       /* Will be replaced by a filtered clamp. */
-       
+       if (m_property[0] == 0)
+       {
+               bFound = true;
+       }
+       else
+       {
+               if (m_option & KX_ACT_CONSTRAINT_MATERIAL)
+               {
+                       if (client->m_auxilary_info)
+                       {
+                               bFound = !strcmp(m_property, ((char*)client->m_auxilary_info));
+                       }
+               }
+               else
+               {
+                       bFound = hitKXObj->GetProperty(m_property) != NULL;
+               }
+       }
 
-       switch (m_locrot) {
-       case KX_ACT_CONSTRAINT_LOCX:
-       case KX_ACT_CONSTRAINT_LOCY:
-       case KX_ACT_CONSTRAINT_LOCZ:
-               parent->NodeSetLocalPosition(position);
-               break;
+       return bFound;
+}
 
+bool KX_ConstraintActuator::Update(double curtime, bool frame)
+{
 
-//     case KX_ACT_CONSTRAINT_ROTX:
-//     case KX_ACT_CONSTRAINT_ROTY:
-//     case KX_ACT_CONSTRAINT_ROTZ:
-//             rotation.setEuler(eulerrot);
-//             parent->NodeSetLocalOrientation(rotation);
-               break;
+       bool result = false;    
+       bool bNegativeEvent = IsNegativeEvent();
+       RemoveAllEvents();
 
-       default:
-               ; /* error */
+       if (!bNegativeEvent) {
+               /* Constraint clamps the values to the specified range, with a sort of    */
+               /* low-pass filtered time response, if the damp time is unequal to 0.     */
+
+               /* Having to retrieve location/rotation and setting it afterwards may not */
+               /* be efficient enough... Somthing to look at later.                      */
+               KX_GameObject  *obj = (KX_GameObject*) GetParent();
+               MT_Point3    position = obj->NodeGetWorldPosition();
+               MT_Point3    newposition;
+               MT_Vector3   direction;
+               MT_Matrix3x3 rotation = obj->NodeGetWorldOrientation();
+               MT_Scalar    filter, newdistance;
+               int axis, sign;
+
+               if (m_posDampTime) {
+                       filter = m_posDampTime/(1.0+m_posDampTime);
+               }
+               switch (m_locrot) {
+               case KX_ACT_CONSTRAINT_ORIX:
+               case KX_ACT_CONSTRAINT_ORIY:
+               case KX_ACT_CONSTRAINT_ORIZ:
+                       switch (m_locrot) {
+                       case KX_ACT_CONSTRAINT_ORIX:
+                               direction[0] = rotation[0][0];
+                               direction[1] = rotation[1][0];
+                               direction[2] = rotation[2][0];
+                               axis = 0;
+                               break;
+                       case KX_ACT_CONSTRAINT_ORIY:
+                               direction[0] = rotation[0][1];
+                               direction[1] = rotation[1][1];
+                               direction[2] = rotation[2][1];
+                               axis = 1;
+                               break;
+                       case KX_ACT_CONSTRAINT_ORIZ:
+                               direction[0] = rotation[0][2];
+                               direction[1] = rotation[1][2];
+                               direction[2] = rotation[2][2];
+                               axis = 2;
+                               break;
+                       }
+                       // apply damping on the direction
+                       if (m_posDampTime) {
+                               direction = filter*direction + (1.0-filter)*m_refDirection;
+                       }
+                       obj->AlignAxisToVect(direction, axis);
+                       result = true;
+                       goto CHECK_TIME;
+               case KX_ACT_CONSTRAINT_DIRPX:
+               case KX_ACT_CONSTRAINT_DIRPY:
+               case KX_ACT_CONSTRAINT_DIRPZ:
+               case KX_ACT_CONSTRAINT_DIRMX:
+               case KX_ACT_CONSTRAINT_DIRMY:
+               case KX_ACT_CONSTRAINT_DIRMZ:
+                       switch (m_locrot) {
+                       case KX_ACT_CONSTRAINT_DIRPX:
+                               direction[0] = rotation[0][0];
+                               direction[1] = rotation[1][0];
+                               direction[2] = rotation[2][0];
+                               axis = 0;               // axis according to KX_GameObject::AlignAxisToVect()
+                               sign = 1;               // X axis will be anti parrallel to normal
+                               break;
+                       case KX_ACT_CONSTRAINT_DIRPY:
+                               direction[0] = rotation[0][1];
+                               direction[1] = rotation[1][1];
+                               direction[2] = rotation[2][1];
+                               axis = 1;
+                               sign = 1;
+                               break;
+                       case KX_ACT_CONSTRAINT_DIRPZ:
+                               direction[0] = rotation[0][2];
+                               direction[1] = rotation[1][2];
+                               direction[2] = rotation[2][2];
+                               axis = 2;
+                               sign = 1;
+                               break;
+                       case KX_ACT_CONSTRAINT_DIRMX:
+                               direction[0] = -rotation[0][0];
+                               direction[1] = -rotation[1][0];
+                               direction[2] = -rotation[2][0];
+                               axis = 0;
+                               sign = 0;
+                               break;
+                       case KX_ACT_CONSTRAINT_DIRMY:
+                               direction[0] = -rotation[0][1];
+                               direction[1] = -rotation[1][1];
+                               direction[2] = -rotation[2][1];
+                               axis = 1;
+                               sign = 0;
+                               break;
+                       case KX_ACT_CONSTRAINT_DIRMZ:
+                               direction[0] = -rotation[0][2];
+                               direction[1] = -rotation[1][2];
+                               direction[2] = -rotation[2][2];
+                               axis = 2;
+                               sign = 0;
+                               break;
+                       }
+                       direction.normalize();
+                       {
+                               MT_Point3 topoint = position + (m_maximumBound) * direction;
+                               MT_Point3 resultpoint;
+                               MT_Vector3 resultnormal;
+                               PHY_IPhysicsEnvironment* pe = obj->GetPhysicsEnvironment();
+                               KX_IPhysicsController *spc = obj->GetPhysicsController();
+
+                               if (!pe) {
+                                       std::cout << "WARNING: Constraint actuator " << GetName() << ":  There is no physics environment!" << std::endl;
+                                       goto CHECK_TIME;
+                               }        
+                               if (!spc) {
+                                       // the object is not physical, we probably want to avoid hitting its own parent
+                                       KX_GameObject *parent = obj->GetParent();
+                                       if (parent) {
+                                               spc = parent->GetPhysicsController();
+                                               parent->Release();
+                                       }
+                               }
+                               result = KX_RayCast::RayTest(spc, pe, position, topoint, resultpoint, resultnormal, KX_RayCast::Callback<KX_ConstraintActuator>(this));
+
+                               if (result)     {
+                                       // compute new position & orientation
+                                       if ((m_option & (KX_ACT_CONSTRAINT_NORMAL|KX_ACT_CONSTRAINT_DISTANCE)) == 0) {
+                                               // if none option is set, the actuator does nothing but detect ray 
+                                               // (works like a sensor)
+                                               goto CHECK_TIME;
+                                       }
+                                       if (m_option & KX_ACT_CONSTRAINT_NORMAL) {
+                                               // the new orientation must be so that the axis is parallel to normal
+                                               if (sign)
+                                                       resultnormal = -resultnormal;
+                                               // apply damping on the direction
+                                               if (m_rotDampTime) {
+                                                       MT_Scalar rotFilter = 1.0/(1.0+m_rotDampTime);
+                                                       resultnormal = (-m_rotDampTime*rotFilter)*direction + rotFilter*resultnormal;
+                                               } else if (m_posDampTime) {
+                                                       resultnormal = -filter*direction + (1.0-filter)*resultnormal;
+                                               }
+                                               obj->AlignAxisToVect(resultnormal, axis);
+                                               direction = -resultnormal;
+                                       }
+                                       if (m_option & KX_ACT_CONSTRAINT_DISTANCE) {
+                                               if (m_posDampTime) {
+                                                       newdistance = filter*(position-resultpoint).length()+(1.0-filter)*m_minimumBound;
+                                               } else {
+                                                       newdistance = m_minimumBound;
+                                               }
+                                       } else {
+                                               newdistance = (position-resultpoint).length();
+                                       }
+                                       newposition = resultpoint-newdistance*direction;
+                               } else if (m_option & KX_ACT_CONSTRAINT_PERMANENT) {
+                                       // no contact but still keep running
+                                       result = true;
+                                       goto CHECK_TIME;
+                               }
+                       }
+                       break; 
+               case KX_ACT_CONSTRAINT_LOCX:
+               case KX_ACT_CONSTRAINT_LOCY:
+               case KX_ACT_CONSTRAINT_LOCZ:
+                       newposition = position;
+                       switch (m_locrot) {
+                       case KX_ACT_CONSTRAINT_LOCX:
+                               Clamp(newposition[0], m_minimumBound, m_maximumBound);
+                               break;
+                       case KX_ACT_CONSTRAINT_LOCY:
+                               Clamp(newposition[1], m_minimumBound, m_maximumBound);
+                               break;
+                       case KX_ACT_CONSTRAINT_LOCZ:
+                               Clamp(newposition[2], m_minimumBound, m_maximumBound);
+                               break;
+                       }
+                       result = true;
+                       if (m_posDampTime) {
+                               newposition = filter*position + (1.0-filter)*newposition;
+                       }
+                       break;
+               }
+               if (result) {
+                       // set the new position but take into account parent if any
+                       obj->NodeSetWorldPosition(newposition);
+               }
+       CHECK_TIME:
+               if (result && m_activeTime > 0 ) {
+                       if (++m_currentTime >= m_activeTime)
+                               result = false;
+               }
+       }
+       if (!result) {
+               m_currentTime = 0;
        }
-
        return result;
 } /* end of KX_ConstraintActuator::Update(double curtime,double deltatime)   */
 
@@ -214,10 +396,24 @@ PyParentObject KX_ConstraintActuator::Parents[] = {
 PyMethodDef KX_ConstraintActuator::Methods[] = {
        {"setDamp", (PyCFunction) KX_ConstraintActuator::sPySetDamp, METH_VARARGS, SetDamp_doc},
        {"getDamp", (PyCFunction) KX_ConstraintActuator::sPyGetDamp, METH_VARARGS, GetDamp_doc},
+       {"setRotDamp", (PyCFunction) KX_ConstraintActuator::sPySetRotDamp, METH_VARARGS, SetRotDamp_doc},
+       {"getRotDamp", (PyCFunction) KX_ConstraintActuator::sPyGetRotDamp, METH_VARARGS, GetRotDamp_doc},
+       {"setDirection", (PyCFunction) KX_ConstraintActuator::sPySetDirection, METH_VARARGS, SetDirection_doc},
+       {"getDirection", (PyCFunction) KX_ConstraintActuator::sPyGetDirection, METH_VARARGS, GetDirection_doc},
+       {"setOption", (PyCFunction) KX_ConstraintActuator::sPySetOption, METH_VARARGS, SetOption_doc},
+       {"getOption", (PyCFunction) KX_ConstraintActuator::sPyGetOption, METH_VARARGS, GetOption_doc},
+       {"setTime", (PyCFunction) KX_ConstraintActuator::sPySetTime, METH_VARARGS, SetTime_doc},
+       {"getTime", (PyCFunction) KX_ConstraintActuator::sPyGetTime, METH_VARARGS, GetTime_doc},
+       {"setProperty", (PyCFunction) KX_ConstraintActuator::sPySetProperty, METH_VARARGS, SetProperty_doc},
+       {"getProperty", (PyCFunction) KX_ConstraintActuator::sPyGetProperty, METH_VARARGS, GetProperty_doc},
        {"setMin", (PyCFunction) KX_ConstraintActuator::sPySetMin, METH_VARARGS, SetMin_doc},
        {"getMin", (PyCFunction) KX_ConstraintActuator::sPyGetMin, METH_VARARGS, GetMin_doc},
+       {"setDistance", (PyCFunction) KX_ConstraintActuator::sPySetMin, METH_VARARGS, SetDistance_doc},
+       {"getDistance", (PyCFunction) KX_ConstraintActuator::sPyGetMin, METH_VARARGS, GetDistance_doc},
        {"setMax", (PyCFunction) KX_ConstraintActuator::sPySetMax, METH_VARARGS, SetMax_doc},
        {"getMax", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_VARARGS, GetMax_doc},
+       {"setRayLength", (PyCFunction) KX_ConstraintActuator::sPySetMax, METH_VARARGS, SetRayLength_doc},
+       {"getRayLength", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_VARARGS, GetRayLength_doc},
        {"setLimit", (PyCFunction) KX_ConstraintActuator::sPySetLimit, METH_VARARGS, SetLimit_doc},
        {"getLimit", (PyCFunction) KX_ConstraintActuator::sPyGetLimit, METH_VARARGS, GetLimit_doc},
        {NULL,NULL} //Sentinel
@@ -231,7 +427,7 @@ PyObject* KX_ConstraintActuator::_getattr(const STR_String& attr) {
 char KX_ConstraintActuator::SetDamp_doc[] = 
 "setDamp(duration)\n"
 "\t- duration: integer\n"
-"\tSets the time with which the constraint application is delayed.\n"
+"\tSets the time constant of the orientation and distance constraint.\n"
 "\tIf the duration is negative, it is set to 0.\n";
 PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, 
                                                                                   PyObject* args, 
@@ -241,21 +437,192 @@ PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self,
                return NULL;            
        }
        
-       m_dampTime = dampArg;
-       if (m_dampTime < 0) m_dampTime = 0;
+       m_posDampTime = dampArg;
+       if (m_posDampTime < 0) m_posDampTime = 0;
 
        Py_Return;
 }
 /* 3. getDamp                                                                */
 char KX_ConstraintActuator::GetDamp_doc[] = 
-"GetDamp()\n"
-"\tReturns the damping time for application of the constraint.\n";
+"getDamp()\n"
+"\tReturns the damping parameter.\n";
 PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self, 
                                                                                   PyObject* args, 
                                                                                   PyObject* kwds){
-       return PyInt_FromLong(m_dampTime);
+       return PyInt_FromLong(m_posDampTime);
 }
 
+/* 2. setRotDamp                                                                */
+char KX_ConstraintActuator::SetRotDamp_doc[] = 
+"setRotDamp(duration)\n"
+"\t- duration: integer\n"
+"\tSets the time constant of the orientation constraint.\n"
+"\tIf the duration is negative, it is set to 0.\n";
+PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, 
+                                                                                     PyObject* args, 
+                                                                                     PyObject* kwds) {
+       int dampArg;
+       if(!PyArg_ParseTuple(args, "i", &dampArg)) {
+               return NULL;            
+       }
+       
+       m_rotDampTime = dampArg;
+       if (m_rotDampTime < 0) m_rotDampTime = 0;
+
+       Py_Return;
+}
+/* 3. getRotDamp                                                                */
+char KX_ConstraintActuator::GetRotDamp_doc[] = 
+"getRotDamp()\n"
+"\tReturns the damping time for application of the constraint.\n";
+PyObject* KX_ConstraintActuator::PyGetRotDamp(PyObject* self, 
+                                                                                     PyObject* args, 
+                                                                                     PyObject* kwds){
+       return PyInt_FromLong(m_rotDampTime);
+}
+
+/* 2. setDirection                                                                */
+char KX_ConstraintActuator::SetDirection_doc[] = 
+"setDirection(vector)\n"
+"\t- vector: 3-tuple\n"
+"\tSets the reference direction in world coordinate for the orientation constraint.\n";
+PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, 
+                                                                                       PyObject* args, 
+                                                                                       PyObject* kwds) {
+       float x, y, z;
+       MT_Scalar len;
+       MT_Vector3 dir;
+
+       if(!PyArg_ParseTuple(args, "(fff)", &x, &y, &z)) {
+               return NULL;            
+       }
+       dir[0] = x;
+       dir[1] = y;
+       dir[2] = z;
+       len = dir.length();
+       if (MT_fuzzyZero(len)) {
+               std::cout << "Invalid direction" << std::endl;
+               return NULL;
+       }
+       m_refDirection = dir/len;
+
+       Py_Return;
+}
+/* 3. getDirection                                                                */
+char KX_ConstraintActuator::GetDirection_doc[] = 
+"getDirection()\n"
+"\tReturns the reference direction of the orientation constraint as a 3-tuple.\n";
+PyObject* KX_ConstraintActuator::PyGetDirection(PyObject* self, 
+                                                                                       PyObject* args, 
+                                                                                       PyObject* kwds){
+       PyObject *retVal = PyList_New(3);
+
+       PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_refDirection[0]));
+       PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_refDirection[1]));
+       PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_refDirection[2]));
+       return retVal;
+}
+
+/* 2. setOption                                                                */
+char KX_ConstraintActuator::SetOption_doc[] = 
+"setOption(option)\n"
+"\t- option: integer\n"
+"\tSets several options of the distance  constraint.\n"
+"\tBinary combination of the following values:\n"
+"\t\t 64 : Activate alignment to surface\n"
+"\t\t128 : Detect material rather than property\n"
+"\t\t256 : No deactivation if ray does not hit target\n"
+"\t\t512 : Activate distance control\n";
+PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, 
+                                                                                    PyObject* args, 
+                                                                                    PyObject* kwds) {
+       int option;
+       if(!PyArg_ParseTuple(args, "i", &option)) {
+               return NULL;            
+       }
+       
+       m_option = option;
+
+       Py_Return;
+}
+/* 3. getOption                                                              */
+char KX_ConstraintActuator::GetOption_doc[] = 
+"getOption()\n"
+"\tReturns the option parameter.\n";
+PyObject* KX_ConstraintActuator::PyGetOption(PyObject* self, 
+                                                                                    PyObject* args, 
+                                                                                    PyObject* kwds){
+       return PyInt_FromLong(m_option);
+}
+
+/* 2. setTime                                                                */
+char KX_ConstraintActuator::SetTime_doc[] = 
+"setTime(duration)\n"
+"\t- duration: integer\n"
+"\tSets the activation time of the actuator.\n"
+"\tThe actuator disables itself after this many frame.\n"
+"\tIf set to 0 or negative, the actuator is not limited in time.\n";
+PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, 
+                                                                                  PyObject* args, 
+                                                                                  PyObject* kwds) {
+       int t;
+       if(!PyArg_ParseTuple(args, "i", &t)) {
+               return NULL;            
+       }
+       
+       if (t < 0)
+               t = 0;
+       m_activeTime = t;
+
+       Py_Return;
+}
+/* 3. getTime                                                                */
+char KX_ConstraintActuator::GetTime_doc[] = 
+"getTime()\n"
+"\tReturns the time parameter.\n";
+PyObject* KX_ConstraintActuator::PyGetTime(PyObject* self, 
+                                                                                  PyObject* args, 
+                                                                                  PyObject* kwds){
+       return PyInt_FromLong(m_activeTime);
+}
+
+/* 2. setProperty                                                                */
+char KX_ConstraintActuator::SetProperty_doc[] = 
+"setProperty(property)\n"
+"\t- property: string\n"
+"\tSets the name of the property or material for the ray detection of the distance constraint.\n"
+"\tIf empty, the ray will detect any collisioning object.\n";
+PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, 
+                                                                                      PyObject* args, 
+                                                                                      PyObject* kwds) {
+       char *property;
+       if (!PyArg_ParseTuple(args, "s", &property)) {
+               return NULL;
+       }
+       if (property == NULL) {
+               m_property[0] = 0;
+       } else {
+               strncpy(m_property, property, sizeof(m_property));
+               m_property[sizeof(m_property)-1] = 0;
+       }
+
+       Py_Return;
+}
+/* 3. getProperty                                                                */
+char KX_ConstraintActuator::GetProperty_doc[] = 
+"getProperty()\n"
+"\tReturns the property parameter.\n";
+PyObject* KX_ConstraintActuator::PyGetProperty(PyObject* self, 
+                                                                                      PyObject* args, 
+                                                                                      PyObject* kwds){
+       return PyString_FromString(m_property);
+}
+
+/* 4. setDistance                                                                 */
+char KX_ConstraintActuator::SetDistance_doc[] = 
+"setDistance(distance)\n"
+"\t- distance: float\n"
+"\tSets the target distance in distance constraint\n";
 /* 4. setMin                                                                 */
 char KX_ConstraintActuator::SetMin_doc[] = 
 "setMin(lower_bound)\n"
@@ -271,9 +638,7 @@ PyObject* KX_ConstraintActuator::PySetMin(PyObject* self,
        }
 
        switch (m_locrot) {
-       case KX_ACT_CONSTRAINT_LOCX:
-       case KX_ACT_CONSTRAINT_LOCY:
-       case KX_ACT_CONSTRAINT_LOCZ:
+       default:
                m_minimumBound = minArg;
                break;
        case KX_ACT_CONSTRAINT_ROTX:
@@ -281,12 +646,14 @@ PyObject* KX_ConstraintActuator::PySetMin(PyObject* self,
        case KX_ACT_CONSTRAINT_ROTZ:
                m_minimumBound = MT_radians(minArg);
                break;
-       default:
-               ; /* error */
        }
 
        Py_Return;
 }
+/* 5. getDistance                                                                 */
+char KX_ConstraintActuator::GetDistance_doc[] = 
+"getDistance()\n"
+"\tReturns the distance parameter \n";
 /* 5. getMin                                                                 */
 char KX_ConstraintActuator::GetMin_doc[] = 
 "getMin()\n"
@@ -298,6 +665,11 @@ PyObject* KX_ConstraintActuator::PyGetMin(PyObject* self,
        return PyFloat_FromDouble(m_minimumBound);
 }
 
+/* 6. setRayLength                                                                 */
+char KX_ConstraintActuator::SetRayLength_doc[] = 
+"setRayLength(length)\n"
+"\t- length: float\n"
+"\tSets the maximum ray length of the distance constraint\n";
 /* 6. setMax                                                                 */
 char KX_ConstraintActuator::SetMax_doc[] = 
 "setMax(upper_bound)\n"
@@ -313,9 +685,7 @@ PyObject* KX_ConstraintActuator::PySetMax(PyObject* self,
        }
 
        switch (m_locrot) {
-       case KX_ACT_CONSTRAINT_LOCX:
-       case KX_ACT_CONSTRAINT_LOCY:
-       case KX_ACT_CONSTRAINT_LOCZ:
+       default:
                m_maximumBound = maxArg;
                break;
        case KX_ACT_CONSTRAINT_ROTX:
@@ -323,12 +693,14 @@ PyObject* KX_ConstraintActuator::PySetMax(PyObject* self,
        case KX_ACT_CONSTRAINT_ROTZ:
                m_maximumBound = MT_radians(maxArg);
                break;
-       default:
-               ; /* error */
        }
 
        Py_Return;
 }
+/* 7. getRayLength                                                                 */
+char KX_ConstraintActuator::GetRayLength_doc[] = 
+"getRayLength()\n"
+"\tReturns the length of the ray\n";
 /* 7. getMax                                                                 */
 char KX_ConstraintActuator::GetMax_doc[] = 
 "getMax()\n"
@@ -345,9 +717,19 @@ PyObject* KX_ConstraintActuator::PyGetMax(PyObject* self,
 /* 8. setLimit                                                               */
 char KX_ConstraintActuator::SetLimit_doc[] = 
 "setLimit(type)\n"
-"\t- type: KX_CONSTRAINTACT_LOCX, KX_CONSTRAINTACT_LOCY,\n"
-"\t        KX_CONSTRAINTACT_LOCZ, KX_CONSTRAINTACT_ROTX,\n"
-"\t        KX_CONSTRAINTACT_ROTY, or KX_CONSTRAINTACT_ROTZ.\n"
+"\t- type: integer\n"
+"\t  1  : LocX\n"
+"\t  2  : LocY\n"
+"\t  3  : LocZ\n"
+"\t  7  : Distance along +X axis\n"
+"\t  8  : Distance along +Y axis\n"
+"\t  9  : Distance along +Z axis\n"
+"\t  10 : Distance along -X axis\n"
+"\t  11 : Distance along -Y axis\n"
+"\t  12 : Distance along -Z axis\n"
+"\t  13 : Align X axis\n"
+"\t  14 : Align Y axis\n"
+"\t  15 : Align Z axis\n"
 "\tSets the type of constraint.\n";
 PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, 
                                                                                        PyObject* args, 
@@ -363,7 +745,7 @@ PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self,
 }
 /* 9. getLimit                                                               */
 char KX_ConstraintActuator::GetLimit_doc[] = 
-"getLimit(type)\n"
+"getLimit()\n"
 "\tReturns the type of constraint.\n";
 PyObject* KX_ConstraintActuator::PyGetLimit(PyObject* self, 
                                                                                        PyObject* args, 
index a21a5f30de64be808d4de12a21f710409f76dd93..5a1d4d23217551b4db9c36f1a2e794aa14694e0f 100644 (file)
 
 #include "SCA_IActuator.h"
 #include "MT_Scalar.h"
+#include "MT_Vector3.h"
+#include "KX_ClientObjectInfo.h"
 
 class KX_ConstraintActuator : public SCA_IActuator
 {
        Py_Header;
 protected:     
        // Damp time (int),
-       int m_dampTime;
-       // min (float),
+       int m_posDampTime;
+       int m_rotDampTime;
+       // min (float) 
        float m_minimumBound;
-       // max (float),
+       // max (float)
        float m_maximumBound;
+       // reference direction
+       MT_Vector3 m_refDirection;
        // locrotxyz choice (pick one): only one choice allowed at a time!
        int m_locrot;
+       // active time of actuator
+       int m_activeTime;
+       int m_currentTime;
+       // option
+       int m_option;
+       // property to check
+       char m_property[32];
 
        /**
         * Clamp <var> to <min>, <max>. Borders are included (in as far as
@@ -56,6 +68,7 @@ protected:
 
        
  public:
+        //  m_locrot
        enum KX_CONSTRAINTTYPE {
                KX_ACT_CONSTRAINT_NODEF = 0,
                KX_ACT_CONSTRAINT_LOCX,
@@ -64,16 +77,37 @@ protected:
                KX_ACT_CONSTRAINT_ROTX,
                KX_ACT_CONSTRAINT_ROTY,
                KX_ACT_CONSTRAINT_ROTZ,
+               KX_ACT_CONSTRAINT_DIRPX,
+               KX_ACT_CONSTRAINT_DIRPY,
+               KX_ACT_CONSTRAINT_DIRPZ,
+               KX_ACT_CONSTRAINT_DIRMX,
+               KX_ACT_CONSTRAINT_DIRMY,
+               KX_ACT_CONSTRAINT_DIRMZ,
+               KX_ACT_CONSTRAINT_ORIX,
+               KX_ACT_CONSTRAINT_ORIY,
+               KX_ACT_CONSTRAINT_ORIZ,
                KX_ACT_CONSTRAINT_MAX
        };
-
+       // match ACT_CONST_... values from BIF_interface.h
+       enum KX_CONSTRAINTOPT {
+               KX_ACT_CONSTRAINT_NORMAL = 64,
+               KX_ACT_CONSTRAINT_MATERIAL = 128,
+               KX_ACT_CONSTRAINT_PERMANENT = 256,
+               KX_ACT_CONSTRAINT_DISTANCE = 512
+       };
        bool IsValidMode(KX_CONSTRAINTTYPE m); 
+       bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
 
        KX_ConstraintActuator(SCA_IObject* gameobj,
-                                                 int damptime,
+                                                 int posDamptime,
+                                                 int rotDampTime,
                                                  float min,
                                                  float max,
+                                                 float refDir[3],
                                                  int locrot,
+                                                 int time,
+                                                 int option,
+                                                 char *property,
                                                  PyTypeObject* T=&Type);
        virtual ~KX_ConstraintActuator();
        virtual CValue* GetReplica() {
@@ -94,13 +128,26 @@ protected:
 
        KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDamp);
        KX_PYMETHOD_DOC(KX_ConstraintActuator,GetDamp);
+       KX_PYMETHOD_DOC(KX_ConstraintActuator,SetRotDamp);
+       KX_PYMETHOD_DOC(KX_ConstraintActuator,GetRotDamp);
+       KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDirection);
+       KX_PYMETHOD_DOC(KX_ConstraintActuator,GetDirection);
+       KX_PYMETHOD_DOC(KX_ConstraintActuator,SetOption);
+       KX_PYMETHOD_DOC(KX_ConstraintActuator,GetOption);
+       KX_PYMETHOD_DOC(KX_ConstraintActuator,SetTime);
+       KX_PYMETHOD_DOC(KX_ConstraintActuator,GetTime);
+       KX_PYMETHOD_DOC(KX_ConstraintActuator,SetProperty);
+       KX_PYMETHOD_DOC(KX_ConstraintActuator,GetProperty);
        KX_PYMETHOD_DOC(KX_ConstraintActuator,SetMin);
        KX_PYMETHOD_DOC(KX_ConstraintActuator,GetMin);
+       static char SetDistance_doc[];
+       static char GetDistance_doc[];
        KX_PYMETHOD_DOC(KX_ConstraintActuator,SetMax);
        KX_PYMETHOD_DOC(KX_ConstraintActuator,GetMax);
+       static char SetRayLength_doc[];
+       static char GetRayLength_doc[];
        KX_PYMETHOD_DOC(KX_ConstraintActuator,SetLimit);
        KX_PYMETHOD_DOC(KX_ConstraintActuator,GetLimit);
-
 };
 
 #endif //__KX_CONSTRAINTACTUATOR
index c4925cb772cc82aaf2d26f420efc9cb3c83d2546..d6d2254850a81d970a2437af4b0813ccf3e06993 100644 (file)
@@ -644,6 +644,15 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis)
                NodeSetLocalOrientation(orimat);
 }
 
+MT_Scalar KX_GameObject::GetMass()
+{
+       if (m_pPhysicsController1)
+       {
+               return m_pPhysicsController1->GetMass();
+       }
+       return 0.0;
+}
+
 MT_Vector3 KX_GameObject::GetLinearVelocity(bool local)
 {
        MT_Vector3 velocity(0.0,0.0,0.0), locvel;
@@ -735,6 +744,31 @@ void KX_GameObject::NodeSetRelativeScale(const MT_Vector3& scale)
                GetSGNode()->RelativeScale(scale);
 }
 
+void KX_GameObject::NodeSetWorldPosition(const MT_Point3& trans)
+{
+       SG_Node* parent = m_pSGNode->GetSGParent();
+       if (parent != NULL)
+       {
+               // Make sure the objects have some scale
+               MT_Vector3 scale = parent->GetWorldScaling();
+               if (fabs(scale[0]) < FLT_EPSILON || 
+                       fabs(scale[1]) < FLT_EPSILON || 
+                       fabs(scale[2]) < FLT_EPSILON)
+               { 
+                       return; 
+               }
+               scale[0] = 1.0/scale[0];
+               scale[1] = 1.0/scale[1];
+               scale[2] = 1.0/scale[2];
+               MT_Matrix3x3 invori = parent->GetWorldOrientation().inverse();
+               MT_Vector3 newpos = invori*(trans-parent->GetWorldPosition())*scale;
+               NodeSetLocalPosition(MT_Point3(newpos[0],newpos[1],newpos[2]));
+       }
+       else 
+       {
+               NodeSetLocalPosition(trans);
+       }
+}
 
 
 void KX_GameObject::NodeUpdateGS(double time,bool bInitiator)
index 31b56df5368c60993cc166dd5c28c21bd172356d..5e44a36515d92ad02ae9753af077ade4fca52939 100644 (file)
@@ -258,6 +258,12 @@ public:
                bool local=false
        );
 
+       /**
+        * Return the mass of the object
+        */
+               MT_Scalar       
+       GetMass();
+
        /** 
         * Return the angular velocity of the game object.
         */
@@ -332,6 +338,9 @@ public:
 
        void    NodeSetRelativeScale(   const MT_Vector3& scale );
 
+       // adapt local position so that world position is set to desired position
+       void    NodeSetWorldPosition(const MT_Point3& trans);
+
                void                                            
        NodeUpdateGS(
                double time,
index f89d32bbe667465c1db857d9248645398ef423a4..db0bef8b7e1d504f4d6910c4cc2b91697ffb4d70 100644 (file)
@@ -77,15 +77,17 @@ void KX_MouseFocusSensor::Init()
        m_mouse_over_in_previous_frame = (m_invert)?true:false;
        m_positive_event = false;
        m_hitObject = 0;
+       m_reset = true;
 }
 
 bool KX_MouseFocusSensor::Evaluate(CValue* event)
 {
        bool result = false;
        bool obHasFocus = false;
+       bool reset = m_reset && m_level;
 
 //     cout << "evaluate focus mouse sensor "<<endl;
-
+       m_reset = false;
        if (m_focusmode) {
                /* Focus behaviour required. Test mouse-on. The rest is
                 * equivalent to handling a key. */
@@ -102,6 +104,10 @@ bool KX_MouseFocusSensor::Evaluate(CValue* event)
                                result = true;
                        } 
                } 
+               if (reset) {
+                       // force an event 
+                       result = true;
+               }
        } else {
                /* No focus behaviour required: revert to the basic mode. This
          * mode is never used, because the converter never makes this
index 4086ac53f2a9c46c0f666a4ba951b92ff9c03266..d69871275b97bb7a255b61a4dfb16323a3664af3 100644 (file)
@@ -102,10 +102,7 @@ CValue* KX_NearSensor::GetReplica()
 {
        KX_NearSensor* replica = new KX_NearSensor(*this);
        replica->m_colliders = new CListValue();
-       replica->m_bCollision = false;
-       replica->m_bTriggered= false;
-       replica->m_hitObject = NULL;
-       replica->m_bLastTriggered = false;
+       replica->Init();
        // this will copy properties and so on...
        CValue::AddDataToReplica(replica);
        
index 03ae14997aba93f81e95d66fa01095ec39c7dcbd..9ac0b4d47038855b92bfed9efc8424c8fc387b08 100644 (file)
@@ -68,8 +68,15 @@ KX_ObjectActuator(
        m_bitLocalFlag (flag),
        m_active_combined_velocity (false),
        m_linear_damping_active(false),
-       m_angular_damping_active(false)
+       m_angular_damping_active(false),
+       m_error_accumulator(0.0,0.0,0.0),
+       m_previous_error(0.0,0.0,0.0)
 {
+       if (m_bitLocalFlag.ServoControl)
+       {
+               // in servo motion, the force is local if the target velocity is local
+               m_bitLocalFlag.Force = m_bitLocalFlag.LinearVelocity;
+       }
        UpdateFuzzyFlags();
 }
 
@@ -87,105 +94,151 @@ bool KX_ObjectActuator::Update()
                // it should reconcile the externally set velocity with it's 
                // own velocity.
                if (m_active_combined_velocity) {
-                       parent->ResolveCombinedVelocities(
-                                       m_linear_velocity,
-                                       m_angular_velocity,
-                                       (m_bitLocalFlag.LinearVelocity) != 0,
-                                       (m_bitLocalFlag.AngularVelocity) != 0
-                               );
+                       if (parent)
+                               parent->ResolveCombinedVelocities(
+                                               m_linear_velocity,
+                                               m_angular_velocity,
+                                               (m_bitLocalFlag.LinearVelocity) != 0,
+                                               (m_bitLocalFlag.AngularVelocity) != 0
+                                       );
                        m_active_combined_velocity = false;
                } 
                m_linear_damping_active = false;
+               m_angular_damping_active = false;
+               m_error_accumulator.setValue(0.0,0.0,0.0);
+               m_previous_error.setValue(0.0,0.0,0.0);
                return false; 
 
-       } else 
-       if (parent)
+       } else if (parent)
        {
-               if (!m_bitLocalFlag.ZeroForce)
+               if (m_bitLocalFlag.ServoControl) 
                {
-                       if (m_bitLocalFlag.ClampVelocity && !m_bitLocalFlag.ZeroLinearVelocity)
+                       // In this mode, we try to reach a target speed using force
+                       // As we don't know the friction, we must implement a generic 
+                       // servo control to achieve the speed in a configurable
+                       // v = current velocity
+                       // V = target velocity
+                       // e = V-v = speed error
+                       // dt = time interval since previous update
+                       // I = sum(e(t)*dt)
+                       // dv = e(t) - e(t-1)
+                       // KP, KD, KI : coefficient
+                       // F = KP*e+KI*I+KD*dv
+                       MT_Scalar mass = parent->GetMass();
+                       if (mass < MT_EPSILON)
+                               return false;
+                       MT_Vector3 v = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity);
+                       MT_Vector3 e = m_linear_velocity - v;
+                       MT_Vector3 dv = e - m_previous_error;
+                       MT_Vector3 I = m_error_accumulator + e;
+
+                       m_force = m_torque.x()*e+m_torque.y()*I+m_torque.z()*dv;
+                       // to automatically adapt the PID coefficient to mass;
+                       m_force *= mass;
+                       if (m_bitLocalFlag.Torque) 
                        {
-                               // The user is requesting not to exceed the velocity set in m_linear_velocity
-                               // The verification is done by projecting the actual speed along the linV direction
-                               // and comparing it with the linV vector length
-                               MT_Vector3 linV;
-                               linV = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity);
-                               if (linV.dot(m_linear_velocity) < m_linear_length2)
-                                       parent->ApplyForce(m_force,(m_bitLocalFlag.Force) != 0);
-                       } else 
+                               if (m_force[0] > m_dloc[0])
+                               {
+                                       m_force[0] = m_dloc[0];
+                                       I[0] = m_error_accumulator[0];
+                               } else if (m_force[0] < m_drot[0])
+                               {
+                                       m_force[0] = m_drot[0];
+                                       I[0] = m_error_accumulator[0];
+                               }
+                       }
+                       if (m_bitLocalFlag.DLoc) 
                        {
-                               parent->ApplyForce(m_force,(m_bitLocalFlag.Force) != 0);
+                               if (m_force[1] > m_dloc[1])
+                               {
+                                       m_force[1] = m_dloc[1];
+                                       I[1] = m_error_accumulator[1];
+                               } else if (m_force[1] < m_drot[1])
+                               {
+                                       m_force[1] = m_drot[1];
+                                       I[1] = m_error_accumulator[1];
+                               }
                        }
-               }
-               if (!m_bitLocalFlag.ZeroTorque)
+                       if (m_bitLocalFlag.DRot) 
+                       {
+                               if (m_force[2] > m_dloc[2])
+                               {
+                                       m_force[2] = m_dloc[2];
+                                       I[2] = m_error_accumulator[2];
+                               } else if (m_force[2] < m_drot[2])
+                               {
+                                       m_force[2] = m_drot[2];
+                                       I[2] = m_error_accumulator[2];
+                               }
+                       }
+                       m_previous_error = e;
+                       m_error_accumulator = I;
+                       parent->ApplyForce(m_force,(m_bitLocalFlag.LinearVelocity) != 0);
+               } else
                {
-                       if (m_bitLocalFlag.ClampVelocity && !m_bitLocalFlag.ZeroAngularVelocity)
+                       if (!m_bitLocalFlag.ZeroForce)
                        {
-                               // The user is requesting not to exceed the velocity set in m_angular_velocity
-                               // The verification is done by projecting the actual speed in the 
-                               MT_Vector3 angV;
-                               angV = parent->GetAngularVelocity(m_bitLocalFlag.AngularVelocity);
-                               if (angV.dot(m_angular_velocity) < m_angular_velocity.length2())
-                                       parent->ApplyTorque(m_torque,(m_bitLocalFlag.Torque) != 0);
-                       } else
+                               parent->ApplyForce(m_force,(m_bitLocalFlag.Force) != 0);
+                       }
+                       if (!m_bitLocalFlag.ZeroTorque)
                        {
                                parent->ApplyTorque(m_torque,(m_bitLocalFlag.Torque) != 0);
                        }
-               }
-               if (!m_bitLocalFlag.ZeroDLoc)
-               {
-                       parent->ApplyMovement(m_dloc,(m_bitLocalFlag.DLoc) != 0);
-               }
-               if (!m_bitLocalFlag.ZeroDRot)
-               {
-                       parent->ApplyRotation(m_drot,(m_bitLocalFlag.DRot) != 0);
-               }
-               if (!m_bitLocalFlag.ZeroLinearVelocity && !m_bitLocalFlag.ClampVelocity)
-               {
-                       if (m_bitLocalFlag.AddOrSetLinV) {
-                               parent->addLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0);
-                       } else {
+                       if (!m_bitLocalFlag.ZeroDLoc)
+                       {
+                               parent->ApplyMovement(m_dloc,(m_bitLocalFlag.DLoc) != 0);
+                       }
+                       if (!m_bitLocalFlag.ZeroDRot)
+                       {
+                               parent->ApplyRotation(m_drot,(m_bitLocalFlag.DRot) != 0);
+                       }
+                       if (!m_bitLocalFlag.ZeroLinearVelocity)
+                       {
+                               if (m_bitLocalFlag.AddOrSetLinV) {
+                                       parent->addLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0);
+                               } else {
+                                       m_active_combined_velocity = true;
+                                       if (m_damping > 0) {
+                                               MT_Vector3 linV;
+                                               if (!m_linear_damping_active) {
+                                                       // delta and the start speed (depends on the existing speed in that direction)
+                                                       linV = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity);
+                                                       // keep only the projection along the desired direction
+                                                       m_current_linear_factor = linV.dot(m_linear_velocity)/m_linear_length2;
+                                                       m_linear_damping_active = true;
+                                               }
+                                               if (m_current_linear_factor < 1.0)
+                                                       m_current_linear_factor += 1.0/m_damping;
+                                               if (m_current_linear_factor > 1.0)
+                                                       m_current_linear_factor = 1.0;
+                                               linV = m_current_linear_factor * m_linear_velocity;
+                                               parent->setLinearVelocity(linV,(m_bitLocalFlag.LinearVelocity) != 0);
+                                       } else {
+                                               parent->setLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0);
+                                       }
+                               }
+                       }
+                       if (!m_bitLocalFlag.ZeroAngularVelocity)
+                       {
                                m_active_combined_velocity = true;
                                if (m_damping > 0) {
-                                       MT_Vector3 linV;
-                                       if (!m_linear_damping_active) {
+                                       MT_Vector3 angV;
+                                       if (!m_angular_damping_active) {
                                                // delta and the start speed (depends on the existing speed in that direction)
-                                               linV = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity);
+                                               angV = parent->GetAngularVelocity(m_bitLocalFlag.AngularVelocity);
                                                // keep only the projection along the desired direction
-                                               m_current_linear_factor = linV.dot(m_linear_velocity)/m_linear_length2;
-                                               m_linear_damping_active = true;
+                                               m_current_angular_factor = angV.dot(m_angular_velocity)/m_angular_length2;
+                                               m_angular_damping_active = true;
                                        }
-                                       if (m_current_linear_factor < 1.0)
-                                               m_current_linear_factor += 1.0/m_damping;
-                                       if (m_current_linear_factor > 1.0)
-                                               m_current_linear_factor = 1.0;
-                                       linV = m_current_linear_factor * m_linear_velocity;
-                                       parent->setLinearVelocity(linV,(m_bitLocalFlag.LinearVelocity) != 0);
+                                       if (m_current_angular_factor < 1.0)
+                                               m_current_angular_factor += 1.0/m_damping;
+                                       if (m_current_angular_factor > 1.0)
+                                               m_current_angular_factor = 1.0;
+                                       angV = m_current_angular_factor * m_angular_velocity;
+                                       parent->setAngularVelocity(angV,(m_bitLocalFlag.AngularVelocity) != 0);
                                } else {
-                                       parent->setLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0);
-                               }
-                       }
-               }
-               if (!m_bitLocalFlag.ZeroAngularVelocity && !m_bitLocalFlag.ClampVelocity)
-               {
-                       m_active_combined_velocity = true;
-                       if (m_damping > 0) {
-                               MT_Vector3 angV;
-                               if (!m_angular_damping_active) {
-                                       // delta and the start speed (depends on the existing speed in that direction)
-                                       angV = parent->GetAngularVelocity(m_bitLocalFlag.AngularVelocity);
-                                       // keep only the projection along the desired direction
-                                       m_current_angular_factor = angV.dot(m_angular_velocity)/m_angular_length2;
-                                       m_angular_damping_active = true;
+                                       parent->setAngularVelocity(m_angular_velocity,(m_bitLocalFlag.AngularVelocity) != 0);
                                }
-                               if (m_current_angular_factor < 1.0)
-                                       m_current_angular_factor += 1.0/m_damping;
-                               if (m_current_angular_factor > 1.0)
-                                       m_current_angular_factor = 1.0;
-                               angV = m_current_angular_factor * m_angular_velocity;
-                               parent->setAngularVelocity(angV,(m_bitLocalFlag.AngularVelocity) != 0);
-                       } else {
-                               parent->setAngularVelocity(m_angular_velocity,(m_bitLocalFlag.AngularVelocity) != 0);
                        }
                }
                
@@ -263,8 +316,17 @@ PyMethodDef KX_ObjectActuator::Methods[] = {
        {"setLinearVelocity", (PyCFunction) KX_ObjectActuator::sPySetLinearVelocity, METH_VARARGS},
        {"getAngularVelocity", (PyCFunction) KX_ObjectActuator::sPyGetAngularVelocity, METH_VARARGS},
        {"setAngularVelocity", (PyCFunction) KX_ObjectActuator::sPySetAngularVelocity, METH_VARARGS},
-       {"setVelocityDamping", (PyCFunction) KX_ObjectActuator::sPySetVelocityDamping, METH_VARARGS},
-       {"getVelocityDamping", (PyCFunction) KX_ObjectActuator::sPyGetVelocityDamping, METH_VARARGS},
+       {"setDamping", (PyCFunction) KX_ObjectActuator::sPySetDamping, METH_VARARGS},
+       {"getDamping", (PyCFunction) KX_ObjectActuator::sPyGetDamping, METH_VARARGS},
+       {"setForceLimitX", (PyCFunction) KX_ObjectActuator::sPySetForceLimitX, METH_VARARGS},
+       {"getForceLimitX", (PyCFunction) KX_ObjectActuator::sPyGetForceLimitX, METH_VARARGS},
+       {"setForceLimitY", (PyCFunction) KX_ObjectActuator::sPySetForceLimitY, METH_VARARGS},
+       {"getForceLimitY", (PyCFunction) KX_ObjectActuator::sPyGetForceLimitY, METH_VARARGS},
+       {"setForceLimitZ", (PyCFunction) KX_ObjectActuator::sPySetForceLimitZ, METH_VARARGS},
+       {"getForceLimitZ", (PyCFunction) KX_ObjectActuator::sPyGetForceLimitZ, METH_VARARGS},
+       {"setPID", (PyCFunction) KX_ObjectActuator::sPyGetPID, METH_VARARGS},
+       {"getPID", (PyCFunction) KX_ObjectActuator::sPySetPID, METH_VARARGS},
+
 
 
        {NULL,NULL} //Sentinel
@@ -411,7 +473,6 @@ PyObject* KX_ObjectActuator::PyGetLinearVelocity(PyObject* self,
        PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_linear_velocity[1]));
        PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_linear_velocity[2]));
        PyList_SetItem(retVal, 3, BoolToPyArg(m_bitLocalFlag.LinearVelocity));
-       PyList_SetItem(retVal, 4, BoolToPyArg(m_bitLocalFlag.ClampVelocity));
        
        return retVal;
 }
@@ -422,14 +483,12 @@ PyObject* KX_ObjectActuator::PySetLinearVelocity(PyObject* self,
                                                                                                 PyObject* kwds) {
        float vecArg[3];
        int bToggle = 0;
-       int bClamp = 0;
-       if (!PyArg_ParseTuple(args, "fffi|i", &vecArg[0], &vecArg[1], 
-                                                 &vecArg[2], &bToggle, &bClamp)) {
+       if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], 
+                                                 &vecArg[2], &bToggle)) {
                return NULL;
        }
        m_linear_velocity.setValue(vecArg);
        m_bitLocalFlag.LinearVelocity = PyArgToBool(bToggle);
-       m_bitLocalFlag.ClampVelocity = PyArgToBool(bClamp);
        UpdateFuzzyFlags();
        Py_Return;
 }
@@ -445,7 +504,6 @@ PyObject* KX_ObjectActuator::PyGetAngularVelocity(PyObject* self,
        PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_angular_velocity[1]));
        PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_angular_velocity[2]));
        PyList_SetItem(retVal, 3, BoolToPyArg(m_bitLocalFlag.AngularVelocity));
-       PyList_SetItem(retVal, 4, BoolToPyArg(m_bitLocalFlag.ClampVelocity));
        
        return retVal;
 }
@@ -455,22 +513,20 @@ PyObject* KX_ObjectActuator::PySetAngularVelocity(PyObject* self,
                                                                                                  PyObject* kwds) {
        float vecArg[3];
        int bToggle = 0;
-       int bClamp = 0;
-       if (!PyArg_ParseTuple(args, "fffi|i", &vecArg[0], &vecArg[1], 
-                                                 &vecArg[2], &bToggle, &bClamp)) {
+       if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], 
+                                                 &vecArg[2], &bToggle)) {
                return NULL;
        }
        m_angular_velocity.setValue(vecArg);
        m_bitLocalFlag.AngularVelocity = PyArgToBool(bToggle);
-       m_bitLocalFlag.ClampVelocity = PyArgToBool(bClamp);
        UpdateFuzzyFlags();
        Py_Return;
 }
 
-/* 13. setVelocityDamping                                                */
-PyObject* KX_ObjectActuator::PySetVelocityDamping(PyObject* self, 
-                                                                                                 PyObject* args, 
-                                                                                                 PyObject* kwds) {
+/* 13. setDamping                                                */
+PyObject* KX_ObjectActuator::PySetDamping(PyObject* self, 
+                                                                                 PyObject* args, 
+                                                                                 PyObject* kwds) {
        int damping = 0;
        if (!PyArg_ParseTuple(args, "i", &damping) || damping < 0 || damping > 1000) {
                return NULL;
@@ -480,11 +536,124 @@ PyObject* KX_ObjectActuator::PySetVelocityDamping(PyObject* self,
 }
 
 /* 13. getVelocityDamping                                                */
-PyObject* KX_ObjectActuator::PyGetVelocityDamping(PyObject* self, 
-                                                                                                 PyObject* args, 
-                                                                                                 PyObject* kwds) {
+PyObject* KX_ObjectActuator::PyGetDamping(PyObject* self, 
+                                                                                 PyObject* args, 
+                                                                                 PyObject* kwds) {
        return Py_BuildValue("i",m_damping);
 }
+/* 6. getForceLimitX                                                                */
+PyObject* KX_ObjectActuator::PyGetForceLimitX(PyObject* self, 
+                                                                                         PyObject* args, 
+                                                                                         PyObject* kwds)
+{
+       PyObject *retVal = PyList_New(3);
+
+       PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_drot[0]));
+       PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_dloc[0]));
+       PyList_SetItem(retVal, 2, BoolToPyArg(m_bitLocalFlag.Torque));
+       
+       return retVal;
+}
+/* 7. setForceLimitX                                                         */
+PyObject* KX_ObjectActuator::PySetForceLimitX(PyObject* self, 
+                                                                                         PyObject* args, 
+                                                                                         PyObject* kwds)
+{
+       float vecArg[2];
+       int bToggle = 0;
+       if(!PyArg_ParseTuple(args, "ffi", &vecArg[0], &vecArg[1], &bToggle)) {
+               return NULL;
+       }
+       m_drot[0] = vecArg[0];
+       m_dloc[0] = vecArg[1];
+       m_bitLocalFlag.Torque = PyArgToBool(bToggle);
+       Py_Return;
+}
+
+/* 6. getForceLimitY                                                                */
+PyObject* KX_ObjectActuator::PyGetForceLimitY(PyObject* self, 
+                                                                                         PyObject* args, 
+                                                                                         PyObject* kwds)
+{
+       PyObject *retVal = PyList_New(3);
+
+       PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_drot[1]));
+       PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_dloc[1]));
+       PyList_SetItem(retVal, 2, BoolToPyArg(m_bitLocalFlag.DLoc));
+       
+       return retVal;
+}
+/* 7. setForceLimitY                                                                */
+PyObject* KX_ObjectActuator::PySetForceLimitY(PyObject* self, 
+                                                                                         PyObject* args, 
+                                                                                         PyObject* kwds)
+{
+       float vecArg[2];
+       int bToggle = 0;
+       if(!PyArg_ParseTuple(args, "ffi", &vecArg[0], &vecArg[1], &bToggle)) {
+               return NULL;
+       }
+       m_drot[1] = vecArg[0];
+       m_dloc[1] = vecArg[1];
+       m_bitLocalFlag.DLoc = PyArgToBool(bToggle);
+       Py_Return;
+}
+
+/* 6. getForceLimitZ                                                                */
+PyObject* KX_ObjectActuator::PyGetForceLimitZ(PyObject* self, 
+                                                                                         PyObject* args, 
+                                                                                         PyObject* kwds)
+{
+       PyObject *retVal = PyList_New(3);
+
+       PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_drot[2]));
+       PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_dloc[2]));
+       PyList_SetItem(retVal, 2, BoolToPyArg(m_bitLocalFlag.DRot));
+       
+       return retVal;
+}
+/* 7. setForceLimitZ                                                                */
+PyObject* KX_ObjectActuator::PySetForceLimitZ(PyObject* self, 
+                                                                                         PyObject* args, 
+                                                                                         PyObject* kwds)
+{
+       float vecArg[2];
+       int bToggle = 0;
+       if(!PyArg_ParseTuple(args, "ffi", &vecArg[0], &vecArg[1], &bToggle)) {
+               return NULL;
+       }
+       m_drot[2] = vecArg[0];
+       m_dloc[2] = vecArg[1];
+       m_bitLocalFlag.DRot = PyArgToBool(bToggle);
+       Py_Return;
+}
+
+/* 4. getPID                                                              */
+PyObject* KX_ObjectActuator::PyGetPID(PyObject* self, 
+                                                                         PyObject* args, 
+                                                                         PyObject* kwds)
+{
+       PyObject *retVal = PyList_New(3);
+
+       PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_torque[0]));
+       PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_torque[1]));
+       PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_torque[2]));
+       
+       return retVal;
+}
+/* 5. setPID                                                              */
+PyObject* KX_ObjectActuator::PySetPID(PyObject* self, 
+                                                                         PyObject* args, 
+                                                                         PyObject* kwds)
+{
+       float vecArg[3];
+       if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2])) {
+               return NULL;
+       }
+       m_torque.setValue(vecArg);
+       Py_Return;
+}
+
 
 
 
index ec6dab5cd4843714c7dde7b30d581f04161f8ef9..bb74756551f0cd88454bef55a4bbb845b929b44d 100644 (file)
@@ -47,7 +47,6 @@ struct KX_LocalFlags {
                LinearVelocity(false),
                AngularVelocity(false),
                AddOrSetLinV(false),
-               ClampVelocity(false),
                ZeroForce(false),
                ZeroDRot(false),
                ZeroDLoc(false),
@@ -63,7 +62,7 @@ struct KX_LocalFlags {
        unsigned short LinearVelocity : 1;
        unsigned short AngularVelocity : 1;
        unsigned short AddOrSetLinV : 1;
-       unsigned short ClampVelocity : 1;
+       unsigned short ServoControl : 1;
        unsigned short ZeroForce : 1;
        unsigned short ZeroTorque : 1;
        unsigned short ZeroDRot : 1;
@@ -84,9 +83,13 @@ class KX_ObjectActuator : public SCA_IActuator
        MT_Vector3              m_angular_velocity;     
        MT_Scalar               m_linear_length2;
        MT_Scalar               m_angular_length2;
+       // used in damping
        MT_Scalar               m_current_linear_factor;
        MT_Scalar               m_current_angular_factor;
        short                   m_damping;
+       // used in servo control
+       MT_Vector3              m_previous_error;
+       MT_Vector3              m_error_accumulator;
        KX_LocalFlags   m_bitLocalFlag;
 
        // A hack bool -- oh no sorry everyone
@@ -164,8 +167,16 @@ public:
        KX_PYMETHOD(KX_ObjectActuator,SetLinearVelocity);
        KX_PYMETHOD(KX_ObjectActuator,GetAngularVelocity);
        KX_PYMETHOD(KX_ObjectActuator,SetAngularVelocity);
-       KX_PYMETHOD(KX_ObjectActuator,SetVelocityDamping);
-       KX_PYMETHOD(KX_ObjectActuator,GetVelocityDamping);
+       KX_PYMETHOD(KX_ObjectActuator,SetDamping);
+       KX_PYMETHOD(KX_ObjectActuator,GetDamping);
+       KX_PYMETHOD(KX_ObjectActuator,GetForceLimitX);
+       KX_PYMETHOD(KX_ObjectActuator,SetForceLimitX);
+       KX_PYMETHOD(KX_ObjectActuator,GetForceLimitY);
+       KX_PYMETHOD(KX_ObjectActuator,SetForceLimitY);
+       KX_PYMETHOD(KX_ObjectActuator,GetForceLimitZ);
+       KX_PYMETHOD(KX_ObjectActuator,SetForceLimitZ);
+       KX_PYMETHOD(KX_ObjectActuator,GetPID);
+       KX_PYMETHOD(KX_ObjectActuator,SetPID);
 };
 
 #endif //__KX_OBJECTACTUATOR
index e847c59bae1a5917a6052eb884211f77be690e01..a416c8c9f89bd5d7cadcb8f148fe6938bcd2ceb3 100644 (file)
@@ -72,6 +72,7 @@ void KX_RaySensor::Init()
        m_bTriggered = (m_invert)?true:false;
        m_rayHit = false;
        m_hitObject = NULL;
+       m_reset = true;
 }
 
 KX_RaySensor::~KX_RaySensor() 
@@ -83,9 +84,10 @@ KX_RaySensor::~KX_RaySensor()
 
 CValue* KX_RaySensor::GetReplica()
 {
-       CValue* replica = new KX_RaySensor(*this);
+       KX_RaySensor* replica = new KX_RaySensor(*this);
        // this will copy properties and so on...
        CValue::AddDataToReplica(replica);
+       replica->Init();
 
        return replica;
 }
@@ -151,6 +153,7 @@ bool KX_RaySensor::RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_
 bool KX_RaySensor::Evaluate(CValue* event)
 {
        bool result = false;
+       bool reset = m_reset && m_level;
        m_rayHit = false; 
        m_hitObject = NULL;
        m_hitPosition = MT_Vector3(0,0,0);
@@ -162,6 +165,7 @@ bool KX_RaySensor::Evaluate(CValue* event)
        MT_Matrix3x3 invmat = matje.inverse();
        
        MT_Vector3 todir;
+       m_reset = false;
        switch (m_axis)
        {
        case 1: // X
@@ -263,7 +267,9 @@ bool KX_RaySensor::Evaluate(CValue* event)
                }
        
       }
-    
+    if (reset)
+               // force an event
+               result = true;
 
        return result;
 }
index a7e91e27df342626dd9d22c4138095ff28050fa2..337b1af6df7c8e386916b8ba41721facc5090993 100644 (file)
@@ -48,6 +48,7 @@
 #include "SCA_KeyboardManager.h"
 #include "SCA_MouseManager.h"
 #include "SCA_PropertyEventManager.h"
+#include "SCA_ActuatorEventManager.h"
 #include "KX_Camera.h"
 #include "SCA_JoystickManager.h"
 
@@ -143,6 +144,7 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice,
        
        SCA_AlwaysEventManager* alwaysmgr = new SCA_AlwaysEventManager(m_logicmgr);
        SCA_PropertyEventManager* propmgr = new SCA_PropertyEventManager(m_logicmgr);
+       SCA_ActuatorEventManager* actmgr = new SCA_ActuatorEventManager(m_logicmgr);
        SCA_RandomEventManager* rndmgr = new SCA_RandomEventManager(m_logicmgr);
        KX_RayEventManager* raymgr = new KX_RayEventManager(m_logicmgr);
 
@@ -152,6 +154,7 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice,
 
        m_logicmgr->RegisterEventManager(alwaysmgr);
        m_logicmgr->RegisterEventManager(propmgr);
+       m_logicmgr->RegisterEventManager(actmgr);
        m_logicmgr->RegisterEventManager(m_keyboardmgr);
        m_logicmgr->RegisterEventManager(m_mousemgr);
        m_logicmgr->RegisterEventManager(m_timemgr);
index 5311f059f0391d7253fbbb6355a30567512c896a..ce3aa1de2ef63db400926eb2b2b0713707cbfa34 100644 (file)
@@ -61,7 +61,9 @@ void KX_TouchSensor::EndFrame() {
 bool KX_TouchSensor::Evaluate(CValue* event)
 {
        bool result = false;
+       bool reset = m_reset && m_level;
 
+       m_reset = false;
        if (m_bTriggered != m_bLastTriggered)
        {
                m_bLastTriggered = m_bTriggered;
@@ -69,7 +71,9 @@ bool KX_TouchSensor::Evaluate(CValue* event)
                        m_hitObject = NULL;
                result = true;
        }
-       
+       if (reset)
+               // force an event
+               result = true;
        return result;
 }
 
@@ -103,6 +107,7 @@ void KX_TouchSensor::Init()
        m_bTriggered = false;
        m_bLastTriggered = (m_invert)?true:false;
        m_hitObject =  NULL;
+       m_reset = true;
 }
 
 KX_TouchSensor::~KX_TouchSensor()
@@ -115,10 +120,7 @@ CValue* KX_TouchSensor::GetReplica()
 {
        KX_TouchSensor* replica = new KX_TouchSensor(*this);
        replica->m_colliders = new CListValue();
-       replica->m_bCollision = false;
-       replica->m_bTriggered= false;
-       replica->m_hitObject = NULL;
-       replica->m_bLastTriggered = false;
+       replica->Init();
        // this will copy properties and so on...
        CValue::AddDataToReplica(replica);
        return replica;