Revision: 14713
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14713
Author:   ben2610
Date:     2008-05-06 22:55:55 +0200 (Tue, 06 May 2008)

Log Message:
-----------
BGE patch #10492 approved: getLinearVelocity() now can provide local velocity 
as well.  This patch is harmless and backward compatible; it can go safely into 
2.46 release

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
    trunk/blender/source/gameengine/PyDoc/KX_GameObject.py

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2008-05-06 
20:52:26 UTC (rev 14712)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2008-05-06 
20:55:55 UTC (rev 14713)
@@ -581,16 +581,27 @@
 
 
 
-MT_Vector3 KX_GameObject::GetLinearVelocity()
+MT_Vector3 KX_GameObject::GetLinearVelocity(bool local)
 {
        MT_Vector3 velocity(0.0,0.0,0.0);
-       
+       MT_Matrix3x3 ori, locvel;
+       int i, j; 
        if (m_pPhysicsController1)
        {
                velocity = m_pPhysicsController1->GetLinearVelocity();
+               
+               if (local)
+               {
+                       ori = GetSGNode()->GetWorldOrientation();
+                       
+                       for(i=0; i < 3; i++)
+                               for(j=0; j < 3; j++)
+                                       locvel[i][j]= velocity[i]*ori[i][j];
+                       for(i=0; i < 3; i++)
+                               velocity[i] = locvel[0][i] + locvel[1][i] + 
locvel[2][i];
+               }
        }
-       return velocity;
-       
+       return velocity;        
 }
 
 
@@ -948,7 +959,15 @@
                                                                                
         PyObject* kwds)
 {
        // only can get the velocity if we have a physics object connected to 
us...
-       return PyObjectFrom(GetLinearVelocity());
+       int local = 0;
+       if (PyArg_ParseTuple(args,"|i",&local))
+       {
+               return PyObjectFrom(GetLinearVelocity((local!=0)));
+       }
+       else
+       {
+               return NULL;
+       }
 }
 
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h      2008-05-06 
20:52:26 UTC (rev 14712)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h      2008-05-06 
20:55:55 UTC (rev 14713)
@@ -252,8 +252,9 @@
        /** 
         * Return the linear velocity of the game object.
         */
-               MT_Vector3                      
+               MT_Vector3 
        GetLinearVelocity(
+               bool local=false
        );
 
        /** 

Modified: trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/KX_GameObject.py      2008-05-06 
20:52:26 UTC (rev 14712)
+++ trunk/blender/source/gameengine/PyDoc/KX_GameObject.py      2008-05-06 
20:55:55 UTC (rev 14713)
@@ -58,15 +58,16 @@
                @rtype: 3x3 rotation matrix
                @return: The game object's rotation matrix
                """
-       def getLinearVelocity():
+       def getLinearVelocity(local):
                """
                Gets the game object's linear velocity.
                
                This method returns the game object's velocity through it's 
centre of mass,
                ie no angular velocity component.
                
-               cf getVelocity()
-               
+               @type local: boolean
+               @param local: - False: you get the "global" velocity ie: 
relative to world orientation.
+                             - True: you get the "local" velocity ie: relative 
to object orientation.
                @rtype: list [vx, vy, vz]
                @return: the object's linear velocity.
                """
@@ -138,6 +139,9 @@
        def setParent(parent):
                """
                Sets this object's parent.
+               
+               @type parent: L{KX_GameObject}
+               @param parent: new parent object.
                """
        def removeParent():
                """


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

Reply via email to