[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19600] trunk/blender/source/gameengine: BGE patch #18051: add localInertia attribute to GameObject.
Benoit Bolsee
benoit.bolsee at online.be
Wed Apr 8 18:25:00 CEST 2009
Revision: 19600
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19600
Author: ben2610
Date: 2009-04-08 18:25:00 +0200 (Wed, 08 Apr 2009)
Log Message:
-----------
BGE patch #18051: add localInertia attribute to GameObject.
Modified Paths:
--------------
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_SumoPhysicsController.cpp
trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.h
trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
Modified: trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp 2009-04-08 15:06:20 UTC (rev 19599)
+++ trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp 2009-04-08 16:25:00 UTC (rev 19600)
@@ -162,6 +162,20 @@
}
+MT_Vector3 KX_BulletPhysicsController::GetLocalInertia()
+{
+ MT_Vector3 inertia(0.f, 0.f, 0.f);
+ btVector3 inv_inertia;
+ if (GetRigidBody()) {
+ inv_inertia = GetRigidBody()->getInvInertiaDiagLocal();
+ if (!btFuzzyZero(inv_inertia.getX()) &&
+ !btFuzzyZero(inv_inertia.getY()) &&
+ !btFuzzyZero(inv_inertia.getZ()))
+ inertia = MT_Vector3(1.f/inv_inertia.getX(), 1.f/inv_inertia.getY(), 1.f/inv_inertia.getZ());
+ }
+ return inertia;
+}
+
MT_Scalar KX_BulletPhysicsController::GetRadius()
{
return MT_Scalar(CcdPhysicsController::GetRadius());
Modified: trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h 2009-04-08 15:06:20 UTC (rev 19599)
+++ trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h 2009-04-08 16:25:00 UTC (rev 19600)
@@ -42,6 +42,7 @@
virtual void setScaling(const MT_Vector3& scaling);
virtual MT_Scalar GetMass();
virtual void SetMass(MT_Scalar newmass);
+ virtual MT_Vector3 GetLocalInertia();
virtual MT_Vector3 getReactionForce();
virtual void setRigidBody(bool rigid);
virtual void AddCompoundChild(KX_IPhysicsController* child);
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-04-08 15:06:20 UTC (rev 19599)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-04-08 16:25:00 UTC (rev 19600)
@@ -772,6 +772,16 @@
return 0.0;
}
+MT_Vector3 KX_GameObject::GetLocalInertia()
+{
+ MT_Vector3 local_inertia(0.0,0.0,0.0);
+ if (m_pPhysicsController1)
+ {
+ local_inertia = m_pPhysicsController1->GetLocalInertia();
+ }
+ return local_inertia;
+}
+
MT_Vector3 KX_GameObject::GetLinearVelocity(bool local)
{
MT_Vector3 velocity(0.0,0.0,0.0), locvel;
@@ -1050,6 +1060,7 @@
KX_PYATTRIBUTE_RW_FUNCTION("mass", KX_GameObject, pyattr_get_mass, pyattr_set_mass),
KX_PYATTRIBUTE_RW_FUNCTION("visible", KX_GameObject, pyattr_get_visible, pyattr_set_visible),
KX_PYATTRIBUTE_RW_FUNCTION("position", KX_GameObject, pyattr_get_position, pyattr_set_position),
+ KX_PYATTRIBUTE_RO_FUNCTION("localInertia", KX_GameObject, pyattr_get_localInertia),
KX_PYATTRIBUTE_RW_FUNCTION("orientation",KX_GameObject,pyattr_get_orientation,pyattr_set_orientation),
KX_PYATTRIBUTE_RW_FUNCTION("scaling", KX_GameObject, pyattr_get_scaling, pyattr_set_scaling),
KX_PYATTRIBUTE_RW_FUNCTION("timeOffset",KX_GameObject, pyattr_get_timeOffset,pyattr_set_timeOffset),
@@ -1305,6 +1316,15 @@
return 0;
}
+PyObject* KX_GameObject::pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
+ if (self->GetPhysicsController())
+ {
+ return PyObjectFrom(self->GetPhysicsController()->GetLocalInertia());
+ }
+ Py_RETURN_NONE;
+}
PyObject* KX_GameObject::pyattr_get_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
@@ -1722,8 +1742,6 @@
return PyFloat_FromDouble((GetPhysicsController() != NULL) ? GetPhysicsController()->GetMass() : 0.0f);
}
-
-
PyObject* KX_GameObject::PyGetReactionForce(PyObject* self)
{
// only can get the velocity if we have a physics object connected to us...
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-04-08 15:06:20 UTC (rev 19599)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-04-08 16:25:00 UTC (rev 19600)
@@ -281,6 +281,12 @@
MT_Scalar
GetMass();
+ /**
+ * Return the local inertia vector of the object
+ */
+ MT_Vector3
+ GetLocalInertia();
+
/**
* Return the angular velocity of the game object.
*/
@@ -820,6 +826,8 @@
static int pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject* pyattr_get_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+ static PyObject* pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static int pyattr_set_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject* pyattr_get_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject* pyattr_get_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
Modified: trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h 2009-04-08 15:06:20 UTC (rev 19599)
+++ trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h 2009-04-08 16:25:00 UTC (rev 19600)
@@ -79,6 +79,7 @@
virtual void setScaling(const MT_Vector3& scaling)=0;
virtual MT_Scalar GetMass()=0;
virtual void SetMass(MT_Scalar newmass)=0;
+ virtual MT_Vector3 GetLocalInertia()=0;
virtual MT_Vector3 getReactionForce()=0;
virtual void setRigidBody(bool rigid)=0;
virtual void AddCompoundChild(KX_IPhysicsController* child) = 0;
Modified: trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp 2009-04-08 15:06:20 UTC (rev 19599)
+++ trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp 2009-04-08 16:25:00 UTC (rev 19600)
@@ -209,6 +209,11 @@
{
}
+MT_Vector3 KX_SumoPhysicsController::GetLocalInertia()
+{
+ return MT_Vector3(0.f, 0.f, 0.f); // \todo
+}
+
MT_Scalar KX_SumoPhysicsController::GetRadius()
{
return SumoPhysicsController::GetRadius();
Modified: trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.h 2009-04-08 15:06:20 UTC (rev 19599)
+++ trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.h 2009-04-08 16:25:00 UTC (rev 19600)
@@ -88,6 +88,7 @@
virtual void setScaling(const MT_Vector3& scaling);
virtual MT_Scalar GetMass();
virtual void SetMass(MT_Scalar newmass);
+ virtual MT_Vector3 GetLocalInertia();
virtual MT_Scalar GetRadius();
virtual MT_Vector3 getReactionForce();
virtual void setRigidBody(bool rigid);
Modified: trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/KX_GameObject.py 2009-04-08 15:06:20 UTC (rev 19599)
+++ trunk/blender/source/gameengine/PyDoc/KX_GameObject.py 2009-04-08 16:25:00 UTC (rev 19600)
@@ -16,8 +16,10 @@
@ivar name: The object's name. (Read only)
- note: Currently (Blender 2.49) the prefix "OB" is added to all objects name. This may change in blender 2.5.
@type name: string.
- @ivar mass: The object's mass (provided the object has a physics controller). Read only.
+ @ivar mass: The object's mass (provided the object has a physics controller).
@type mass: float
+ @ivar localInertia: the object's inertia vector in local coordinates. Read only.
+ @type localInertia: list [ix, iy, iz]
@ivar parent: The object's parent object. (Read only)
@type parent: L{KX_GameObject} or None
@ivar visible: visibility flag.
More information about the Bf-blender-cvs
mailing list