Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2009-04-08 20:25:00 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2009-04-08 20:25:00 +0400
commit370850146f5ab1af11ec3a28abd1bad2f60314a4 (patch)
tree9559a67412bb0d78ef47bf05e19850357007fc19
parent2074128fadbfd58ea13a68cbccaa1f6771bbd710 (diff)
BGE patch #18051: add localInertia attribute to GameObject.
-rw-r--r--source/gameengine/Ketsji/KX_BulletPhysicsController.cpp14
-rw-r--r--source/gameengine/Ketsji/KX_BulletPhysicsController.h1
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp22
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.h8
-rw-r--r--source/gameengine/Ketsji/KX_IPhysicsController.h1
-rw-r--r--source/gameengine/Ketsji/KX_SumoPhysicsController.cpp5
-rw-r--r--source/gameengine/Ketsji/KX_SumoPhysicsController.h1
-rw-r--r--source/gameengine/PyDoc/KX_GameObject.py4
8 files changed, 53 insertions, 3 deletions
diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
index 435b2b5db19..c621f11994a 100644
--- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
+++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
@@ -162,6 +162,20 @@ MT_Scalar KX_BulletPhysicsController::GetMass()
}
+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());
diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.h b/source/gameengine/Ketsji/KX_BulletPhysicsController.h
index 44fbde7054e..9821b3fd253 100644
--- a/source/gameengine/Ketsji/KX_BulletPhysicsController.h
+++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.h
@@ -42,6 +42,7 @@ public:
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);
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index 339a955702a..ea53ffea48f 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -772,6 +772,16 @@ MT_Scalar KX_GameObject::GetMass()
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 @@ PyAttributeDef KX_GameObject::Attributes[] = {
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 @@ int KX_GameObject::pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *a
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 @@ PyObject* KX_GameObject::PyGetMass(PyObject* self)
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...
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h
index 9c7dda5e394..08cc3031479 100644
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ b/source/gameengine/Ketsji/KX_GameObject.h
@@ -281,6 +281,12 @@ public:
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 @@ public:
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);
diff --git a/source/gameengine/Ketsji/KX_IPhysicsController.h b/source/gameengine/Ketsji/KX_IPhysicsController.h
index 13501f1fbbd..b7603203241 100644
--- a/source/gameengine/Ketsji/KX_IPhysicsController.h
+++ b/source/gameengine/Ketsji/KX_IPhysicsController.h
@@ -79,6 +79,7 @@ public:
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;
diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp
index 7631ee05b0b..fc053f05e63 100644
--- a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp
+++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp
@@ -209,6 +209,11 @@ void KX_SumoPhysicsController::SetMass(MT_Scalar newmass)
{
}
+MT_Vector3 KX_SumoPhysicsController::GetLocalInertia()
+{
+ return MT_Vector3(0.f, 0.f, 0.f); // \todo
+}
+
MT_Scalar KX_SumoPhysicsController::GetRadius()
{
return SumoPhysicsController::GetRadius();
diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.h b/source/gameengine/Ketsji/KX_SumoPhysicsController.h
index 46c8ba6df45..8762612eca2 100644
--- a/source/gameengine/Ketsji/KX_SumoPhysicsController.h
+++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.h
@@ -88,6 +88,7 @@ public:
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);
diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py
index 97f6dab52bf..42656503384 100644
--- a/source/gameengine/PyDoc/KX_GameObject.py
+++ b/source/gameengine/PyDoc/KX_GameObject.py
@@ -16,8 +16,10 @@ class KX_GameObject: # (SCA_IObject)
@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.