Revision: 15345
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15345
Author:   ben2610
Date:     2008-06-24 21:37:43 +0200 (Tue, 24 Jun 2008)

Log Message:
-----------
BGE patch: Add damping and clamping option to motion actuator.

This patch introduces two options for the motion actuator:

damping: number of frames to reach the target velocity. It takes
into account the startup velocityin the target velocity direction
and add 1/damping fraction of target velocity until the full 
velocity is reached. Works only with linear and angular velocity.
It will be extended to delta and force motion method in a future
release.

clamping: apply the force and torque as long as the target velocity
is not reached. If this option is set, the velocity specified 
in linV or angV are not applied to the object but used as target
velocity. You should also specify a force in force or torque field: 
the force will be applied as long as the velocity along the axis of
the vector set in linV or angV is not reached. Works best in low
friction environment.

Modified Paths:
--------------
    trunk/blender/source/blender/makesdna/DNA_actuator_types.h
    trunk/blender/source/blender/src/buttons_logic.c
    trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
    trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
    trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
    trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h
    trunk/blender/source/gameengine/Ketsji/KX_ObjectActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ObjectActuator.h
    trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.h

Modified: trunk/blender/source/blender/makesdna/DNA_actuator_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_actuator_types.h  2008-06-24 
17:38:03 UTC (rev 15344)
+++ trunk/blender/source/blender/makesdna/DNA_actuator_types.h  2008-06-24 
19:37:43 UTC (rev 15345)
@@ -98,7 +98,8 @@
 } bPropertyActuator;
 
 typedef struct bObjectActuator {
-       int flag, type;
+       short flag, type;
+       int   damping;
        float forceloc[3], forcerot[3];
        float loc[3], rot[3];
        float dloc[3], drot[3];
@@ -252,6 +253,7 @@
 #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

Modified: trunk/blender/source/blender/src/buttons_logic.c
===================================================================
--- trunk/blender/source/blender/src/buttons_logic.c    2008-06-24 17:38:03 UTC 
(rev 15344)
+++ trunk/blender/source/blender/src/buttons_logic.c    2008-06-24 19:37:43 UTC 
(rev 15345)
@@ -1613,7 +1613,7 @@
        {
        case ACT_OBJECT:
                {
-                       ysize= 129;
+                       ysize= 152;
                        
                        glRects(xco, yco-ysize, xco+width, yco);
                        uiEmboss((float)xco, (float)yco-ysize, 
(float)xco+width, (float)yco, 1);
@@ -1651,6 +1651,10 @@
                        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, "");
+                       uiDefButBitI(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");
+
                        uiDefButBitI(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");
                        uiDefButBitI(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");
                        uiDefButBitI(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");

Modified: trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp   
2008-06-24 17:38:03 UTC (rev 15344)
+++ trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp   
2008-06-24 19:37:43 UTC (rev 15345)
@@ -137,6 +137,7 @@
                                MT_Vector3 angvelvec ( 
KX_BLENDERTRUNC(obact->angularvelocity[0]),
                                        
KX_BLENDERTRUNC(obact->angularvelocity[1]),
                                        
KX_BLENDERTRUNC(obact->angularvelocity[2]));
+                               short damping = obact->damping;
                                
                                drotvec /=              BLENDER_HACK_DTIME;
                                //drotvec /=            BLENDER_HACK_DTIME;
@@ -157,7 +158,7 @@
                                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.AddOrSetLinV = bool((obact->flag & 
ACT_ADD_LIN_VEL)!=0);
                                
                                
@@ -168,6 +169,7 @@
                                        drotvec.getValue(),
                                        linvelvec.getValue(),
                                        angvelvec.getValue(),
+                                       damping,
                                        bitLocalFlag
                                        );
                                baseact = tmpbaseact;

Modified: trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp       
2008-06-24 17:38:03 UTC (rev 15344)
+++ trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp       
2008-06-24 19:37:43 UTC (rev 15345)
@@ -102,6 +102,13 @@
        
CcdPhysicsController::GetLinearVelocity(angVel[0],angVel[1],angVel[2]);//rcruiz
        return MT_Vector3(angVel[0],angVel[1],angVel[2]);
 }
+MT_Vector3 KX_BulletPhysicsController::GetAngularVelocity()
+{
+       float angVel[3];
+       
//CcdPhysicsController::GetAngularVelocity(angVel[0],angVel[1],angVel[2]);
+       
CcdPhysicsController::GetAngularVelocity(angVel[0],angVel[1],angVel[2]);//rcruiz
+       return MT_Vector3(angVel[0],angVel[1],angVel[2]);
+}
 MT_Vector3 KX_BulletPhysicsController::GetVelocity(const MT_Point3& pos)
 {
        float linVel[3];

Modified: trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h 
2008-06-24 17:38:03 UTC (rev 15344)
+++ trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h 
2008-06-24 19:37:43 UTC (rev 15345)
@@ -25,6 +25,7 @@
        virtual void    ApplyTorque(const MT_Vector3& torque,bool local);
        virtual void    ApplyForce(const MT_Vector3& force,bool local);
        virtual MT_Vector3 GetLinearVelocity();
+       virtual MT_Vector3 GetAngularVelocity();
        virtual MT_Vector3 GetVelocity(const MT_Point3& pos);
        virtual void    SetAngularVelocity(const MT_Vector3& ang_vel,bool 
local);
        virtual void    SetLinearVelocity(const MT_Vector3& lin_vel,bool local);

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2008-06-24 
17:38:03 UTC (rev 15344)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2008-06-24 
19:37:43 UTC (rev 15345)
@@ -664,7 +664,28 @@
        return velocity;        
 }
 
+MT_Vector3 KX_GameObject::GetAngularVelocity(bool local)
+{
+       MT_Vector3 velocity(0.0,0.0,0.0), locvel;
+       MT_Matrix3x3 ori;
+       int i, j; 
+       if (m_pPhysicsController1)
+       {
+               velocity = m_pPhysicsController1->GetAngularVelocity();
+               
+               if (local)
+               {
+                       ori = GetSGNode()->GetWorldOrientation();
+                       
+                       locvel = velocity * ori;
+                       return locvel;
+               }
+       }
+       return velocity;        
+}
 
+
+
 // scenegraph node stuff
 
 void KX_GameObject::NodeSetLocalPosition(const MT_Point3& trans)

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h      2008-06-24 
17:38:03 UTC (rev 15344)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h      2008-06-24 
19:37:43 UTC (rev 15345)
@@ -259,6 +259,14 @@
        );
 
        /** 
+        * Return the angular velocity of the game object.
+        */
+               MT_Vector3 
+       GetAngularVelocity(
+               bool local=false
+       );
+
+       /** 
         * Align the object to a given normal.
         */
                void 

Modified: trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h      
2008-06-24 17:38:03 UTC (rev 15344)
+++ trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h      
2008-06-24 19:37:43 UTC (rev 15345)
@@ -64,6 +64,7 @@
        virtual void    ApplyTorque(const MT_Vector3& torque,bool local)=0;
        virtual void    ApplyForce(const MT_Vector3& force,bool local)=0;
        virtual MT_Vector3 GetLinearVelocity()=0;
+       virtual MT_Vector3 GetAngularVelocity()=0;
        virtual MT_Vector3 GetVelocity(const MT_Point3& pos)=0;
        virtual void    SetAngularVelocity(const MT_Vector3& ang_vel,bool 
local)=0;
        virtual void    SetLinearVelocity(const MT_Vector3& lin_vel,bool 
local)=0;

Modified: trunk/blender/source/gameengine/Ketsji/KX_ObjectActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ObjectActuator.cpp        
2008-06-24 17:38:03 UTC (rev 15344)
+++ trunk/blender/source/gameengine/Ketsji/KX_ObjectActuator.cpp        
2008-06-24 19:37:43 UTC (rev 15345)
@@ -50,6 +50,7 @@
        const MT_Vector3& drot,
        const MT_Vector3& linV,
        const MT_Vector3& angV,
+       const short damping,
        const KX_LocalFlags& flag,
        PyTypeObject* T
 ) : 
@@ -60,9 +61,16 @@
        m_drot(drot),
        m_linear_velocity(linV),
        m_angular_velocity(angV),
+       m_linear_length2(0.0),
+       m_current_linear_factor(0.0),
+       m_current_angular_factor(0.0),
+       m_damping(damping),
        m_bitLocalFlag (flag),
-       m_active_combined_velocity (false)
+       m_active_combined_velocity (false),
+       m_linear_damping_active(false),
+       m_angular_damping_active(false)
 {
+       UpdateFuzzyFlags();
 }
 
 bool KX_ObjectActuator::Update()
@@ -87,42 +95,98 @@
                                );
                        m_active_combined_velocity = false;
                } 
+               m_linear_damping_active = false;
                return false; 
 
        } else 
        if (parent)
        {
-               /* Probably better to use some flags, so these MT_zero tests 
can be  */
-               /* skipped.                                                     
     */
-               if (!MT_fuzzyZero(m_force))
+               if (!m_bitLocalFlag.ZeroForce)
                {
-                       parent->ApplyForce(m_force,(m_bitLocalFlag.Force) != 0);
+                       if (m_bitLocalFlag.ClampVelocity && 
!m_bitLocalFlag.ZeroLinearVelocity)
+                       {
+                               // 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 
+                       {
+                               
parent->ApplyForce(m_force,(m_bitLocalFlag.Force) != 0);
+                       }
                }
-               if (!MT_fuzzyZero(m_torque))
+               if (!m_bitLocalFlag.ZeroTorque)
                {
-                       parent->ApplyTorque(m_torque,(m_bitLocalFlag.Torque) != 
0);
+                       if (m_bitLocalFlag.ClampVelocity && 
!m_bitLocalFlag.ZeroAngularVelocity)
+                       {
+                               // 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->ApplyTorque(m_torque,(m_bitLocalFlag.Torque) != 0);
+                       }
                }
-               if (!MT_fuzzyZero(m_dloc))
+               if (!m_bitLocalFlag.ZeroDLoc)
                {
                        parent->ApplyMovement(m_dloc,(m_bitLocalFlag.DLoc) != 
0);
                }
-               if (!MT_fuzzyZero(m_drot))
+               if (!m_bitLocalFlag.ZeroDRot)
                {
                        parent->ApplyRotation(m_drot,(m_bitLocalFlag.DRot) != 
0);
                }

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to