diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2008-05-07 00:55:55 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2008-05-07 00:55:55 +0400 |
commit | 881802d8a385228a3b8af3b1b7ccb8512c96490b (patch) | |
tree | 8e135fc24150735428fcf1547d6ac174dad70fb0 /source/gameengine/Ketsji | |
parent | 917865b5049acaa2e13b7d40ebf879121c7e2148 (diff) |
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
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 29 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 3 |
2 files changed, 26 insertions, 6 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 4c6ba448ebf..fb636b23082 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -581,16 +581,27 @@ void KX_GameObject::SetObjectColor(const MT_Vector4& rgbavec) -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* KX_GameObject::PyGetLinearVelocity(PyObject* self, 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; + } } diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index da0cd69e129..b83d63e26bf 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -252,8 +252,9 @@ public: /** * Return the linear velocity of the game object. */ - MT_Vector3 + MT_Vector3 GetLinearVelocity( + bool local=false ); /** |