Page MenuHome

localpatch.txt

File Metadata

Author
José Ignacio Romero (cyborgar)
Created
Nov 13 2013, 1:34 PM

localpatch.txt

Index: source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- source/gameengine/Ketsji/KX_GameObject.cpp (revisión: 14651)
+++ source/gameengine/Ketsji/KX_GameObject.cpp (copia de trabajo)
@@ -61,6 +61,7 @@
#include "KX_RayCast.h"
#include "KX_PythonInit.h"
#include "KX_PyMath.h"
+#include "BLI_arithb.h" /*i'm not sure if it's necessary*/
// This file defines relationships between parents and children
// in the game engine.
@@ -581,16 +582,41 @@
-MT_Vector3 KX_GameObject::GetLinearVelocity()
+MT_Vector3 KX_GameObject::GetLinearVelocity(bool local)
{
MT_Vector3 velocity(0.0,0.0,0.0);
-
+ MT_Matrix3x3 ori;
+ MT_Matrix3x3 vel;
+ MT_Matrix3x3 locvel;
if (m_pPhysicsController1)
{
velocity = m_pPhysicsController1->GetLinearVelocity();
+
+ if (local)
+ {
+ ori = GetSGNode()->GetWorldOrientation();
+ vel[0][0]=velocity[0];
+ vel[1][1]=velocity[1];
+ vel[2][2]=velocity[2];
+
+ locvel[0][0]= vel[0][0]*ori[0][0] + vel[0][1]*ori[1][0] + vel[0][2]*ori[2][0];
+ locvel[0][1]= vel[0][0]*ori[0][1] + vel[0][1]*ori[1][1] + vel[0][2]*ori[2][1];
+ locvel[0][2]= vel[0][0]*ori[0][2] + vel[0][1]*ori[1][2] + vel[0][2]*ori[2][2];
+
+ locvel[1][0]= vel[1][0]*ori[0][0] + vel[1][1]*ori[1][0] + vel[1][2]*ori[2][0];
+ locvel[1][1]= vel[1][0]*ori[0][1] + vel[1][1]*ori[1][1] + vel[1][2]*ori[2][1];
+ locvel[1][2]= vel[1][0]*ori[0][2] + vel[1][1]*ori[1][2] + vel[1][2]*ori[2][2];
+
+ locvel[2][0]= vel[2][0]*ori[0][0] + vel[2][1]*ori[1][0] + vel[2][2]*ori[2][0];
+ locvel[2][1]= vel[2][0]*ori[0][1] + vel[2][1]*ori[1][1] + vel[2][2]*ori[2][1];
+ locvel[2][2]= vel[2][0]*ori[0][2] + vel[2][1]*ori[1][2] + vel[2][2]*ori[2][2];
+
+ velocity[0] = locvel[0][0] + locvel[1][0] + locvel[2][0];
+ velocity[1] = locvel[0][1] + locvel[1][1] + locvel[2][1];
+ velocity[2] = locvel[0][2] + locvel[1][2] + locvel[2][2];
+ }
}
- return velocity;
-
+ return velocity;
}
@@ -948,7 +974,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;
+ }
}
Index: source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- source/gameengine/Ketsji/KX_GameObject.h (revisión: 14651)
+++ source/gameengine/Ketsji/KX_GameObject.h (copia de trabajo)
@@ -252,8 +252,9 @@
/**
* Return the linear velocity of the game object.
*/
- MT_Vector3
+ MT_Vector3
GetLinearVelocity(
+ bool local=false
);
/**

Event Timeline