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:
Diffstat (limited to 'source/gameengine/Ketsji/KX_GameObject.cpp')
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp208
1 files changed, 189 insertions, 19 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index 8193aa8c37b..146b83abd17 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -464,7 +464,7 @@ void KX_GameObject::AddMeshUser()
double* fl = GetOpenGLMatrixPtr()->getPointer();
SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
-// RAS_MeshSlot* ms;
+ RAS_MeshSlot* ms;
for(mit.begin(); !mit.end(); ++mit)
{
(*mit)->m_OpenGLMatrix = fl;
@@ -1383,8 +1383,8 @@ PyMethodDef KX_GameObject::Methods[] = {
{"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS},
{"setOcclusion",(PyCFunction) KX_GameObject::sPySetOcclusion, METH_VARARGS},
{"removeParent", (PyCFunction)KX_GameObject::sPyRemoveParent,METH_NOARGS},
-
-
+ {"getChildren", (PyCFunction)KX_GameObject::sPyGetChildren,METH_NOARGS},
+ {"getChildrenRecursive", (PyCFunction)KX_GameObject::sPyGetChildrenRecursive,METH_NOARGS},
{"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_NOARGS},
{"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS},
{"replaceMesh",(PyCFunction) KX_GameObject::sPyReplaceMesh, METH_VARARGS},
@@ -1398,8 +1398,21 @@ PyMethodDef KX_GameObject::Methods[] = {
KX_PYMETHODTABLE(KX_GameObject, sendMessage),
// dict style access for props
+ {"has_key",(PyCFunction) KX_GameObject::sPyhas_key, METH_O},
{"get",(PyCFunction) KX_GameObject::sPyget, METH_VARARGS},
+ // deprecated
+ {"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_NOARGS},
+ {"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_O},
+ {"setWorldPosition", (PyCFunction) KX_GameObject::sPySetWorldPosition, METH_O},
+ {"getOrientation", (PyCFunction) KX_GameObject::sPyGetOrientation, METH_NOARGS},
+ {"setOrientation", (PyCFunction) KX_GameObject::sPySetOrientation, METH_O},
+ {"getState",(PyCFunction) KX_GameObject::sPyGetState, METH_NOARGS},
+ {"setState",(PyCFunction) KX_GameObject::sPySetState, METH_O},
+ {"getParent", (PyCFunction)KX_GameObject::sPyGetParent,METH_NOARGS},
+ {"getVisible",(PyCFunction) KX_GameObject::sPyGetVisible, METH_NOARGS},
+ {"getMass", (PyCFunction) KX_GameObject::sPyGetMass, METH_NOARGS},
+ {"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS},
{NULL,NULL} //Sentinel
};
@@ -1502,6 +1515,13 @@ PyObject* KX_GameObject::PyReinstancePhysicsMesh(PyObject* args)
Py_RETURN_FALSE;
}
+
+PyObject* KX_GameObject::PyGetPosition()
+{
+ ShowDeprecationWarning("getPosition()", "the position property");
+ return PyObjectFrom(NodeGetWorldPosition());
+}
+
static PyObject *Map_GetItem(PyObject *self_v, PyObject *item)
{
KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(self_v);
@@ -1797,10 +1817,10 @@ int KX_GameObject::pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *at
PyObject* KX_GameObject::pyattr_get_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
+ KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
#ifdef USE_MATHUTILS
- return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_GLOBAL);
+ return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_GLOBAL);
#else
- KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
return PyObjectFrom(self->NodeGetWorldPosition());
#endif
}
@@ -1819,10 +1839,10 @@ int KX_GameObject::pyattr_set_worldPosition(void *self_v, const KX_PYATTRIBUTE_D
PyObject* KX_GameObject::pyattr_get_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
+ KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
#ifdef USE_MATHUTILS
- return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_LOCAL);
+ return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_LOCAL);
#else
- KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
return PyObjectFrom(self->NodeGetLocalPosition());
#endif
}
@@ -1841,10 +1861,10 @@ int KX_GameObject::pyattr_set_localPosition(void *self_v, const KX_PYATTRIBUTE_D
PyObject* KX_GameObject::pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
+ KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
#ifdef USE_MATHUTILS
- return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_INERTIA_LOCAL);
+ return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_INERTIA_LOCAL);
#else
- KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
if (self->GetPhysicsController())
return PyObjectFrom(self->GetPhysicsController()->GetLocalInertia());
return Py_BuildValue("fff", 0.0f, 0.0f, 0.0f);
@@ -1854,7 +1874,7 @@ PyObject* KX_GameObject::pyattr_get_localInertia(void *self_v, const KX_PYATTRIB
PyObject* KX_GameObject::pyattr_get_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
#ifdef USE_MATHUTILS
- return newMatrixObject_cb(BGE_PROXY_FROM_REF(self_v), 3, 3, mathutils_kxgameob_matrix_cb_index, MATHUTILS_MAT_CB_ORI_GLOBAL);
+ return newMatrixObject_cb((PyObject *)self_v, 3, 3, mathutils_kxgameob_matrix_cb_index, MATHUTILS_MAT_CB_ORI_GLOBAL);
#else
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
return PyObjectFrom(self->NodeGetWorldOrientation());
@@ -1879,7 +1899,7 @@ int KX_GameObject::pyattr_set_worldOrientation(void *self_v, const KX_PYATTRIBUT
PyObject* KX_GameObject::pyattr_get_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
#ifdef USE_MATHUTILS
- return newMatrixObject_cb(BGE_PROXY_FROM_REF(self_v), 3, 3, mathutils_kxgameob_matrix_cb_index, MATHUTILS_MAT_CB_ORI_LOCAL);
+ return newMatrixObject_cb((PyObject *)self_v, 3, 3, mathutils_kxgameob_matrix_cb_index, MATHUTILS_MAT_CB_ORI_LOCAL);
#else
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
return PyObjectFrom(self->NodeGetLocalOrientation());
@@ -1902,20 +1922,20 @@ int KX_GameObject::pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUT
PyObject* KX_GameObject::pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
+ KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
#ifdef USE_MATHUTILS
- return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_GLOBAL);
+ return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_GLOBAL);
#else
- KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
return PyObjectFrom(self->NodeGetWorldScaling());
#endif
}
PyObject* KX_GameObject::pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
+ KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
#ifdef USE_MATHUTILS
- return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_LOCAL);
+ return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_LOCAL);
#else
- KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
return PyObjectFrom(self->NodeGetLocalScaling());
#endif
}
@@ -2181,6 +2201,41 @@ PyObject* KX_GameObject::PySetOcclusion(PyObject* args)
Py_RETURN_NONE;
}
+PyObject* KX_GameObject::PyGetVisible()
+{
+ ShowDeprecationWarning("getVisible()", "the visible property");
+ return PyLong_FromSsize_t(m_bVisible);
+}
+
+PyObject* KX_GameObject::PyGetState()
+{
+ ShowDeprecationWarning("getState()", "the state property");
+ int state = 0;
+ state |= GetState();
+ return PyLong_FromSsize_t(state);
+}
+
+PyObject* KX_GameObject::PySetState(PyObject* value)
+{
+ ShowDeprecationWarning("setState()", "the state property");
+ int state_i = PyLong_AsSsize_t(value);
+ unsigned int state = 0;
+
+ if (state_i == -1 && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError, "expected an int bit field");
+ return NULL;
+ }
+
+ state |= state_i;
+ if ((state & ((1<<30)-1)) == 0) {
+ PyErr_SetString(PyExc_AttributeError, "The state bitfield was not between 0 and 30 (1<<0 and 1<<29)");
+ return NULL;
+ }
+ SetState(state);
+
+ Py_RETURN_NONE;
+}
+
PyObject* KX_GameObject::PyGetVelocity(PyObject* args)
{
// only can get the velocity if we have a physics object connected to us...
@@ -2199,6 +2254,14 @@ PyObject* KX_GameObject::PyGetVelocity(PyObject* args)
}
}
+
+
+PyObject* KX_GameObject::PyGetMass()
+{
+ ShowDeprecationWarning("getMass()", "the mass property");
+ return PyFloat_FromDouble((GetPhysicsController() != NULL) ? GetPhysicsController()->GetMass() : 0.0f);
+}
+
PyObject* KX_GameObject::PyGetReactionForce()
{
// only can get the velocity if we have a physics object connected to us...
@@ -2235,6 +2298,18 @@ PyObject* KX_GameObject::PyDisableRigidBody()
}
+
+PyObject* KX_GameObject::PyGetParent()
+{
+ ShowDeprecationWarning("getParent()", "the parent property");
+ KX_GameObject* parent = this->GetParent();
+ if (parent) {
+ parent->Release(); /* self->GetParent() AddRef's */
+ return parent->GetProxy();
+ }
+ Py_RETURN_NONE;
+}
+
PyObject* KX_GameObject::PySetParent(PyObject* args)
{
KX_Scene *scene = KX_GetActiveScene();
@@ -2260,6 +2335,41 @@ PyObject* KX_GameObject::PyRemoveParent()
Py_RETURN_NONE;
}
+PyObject* KX_GameObject::PyGetChildren()
+{
+ ShowDeprecationWarning("getChildren()", "the children property");
+
+ return GetChildren()->NewProxy(true);
+}
+
+PyObject* KX_GameObject::PyGetChildrenRecursive()
+{
+ ShowDeprecationWarning("getChildrenRecursive()", "the childrenRecursive property");
+
+ return GetChildrenRecursive()->NewProxy(true);
+}
+
+PyObject* KX_GameObject::PyGetMesh(PyObject* args)
+{
+ ShowDeprecationWarning("getMesh()", "the meshes property (now a list of meshes)");
+
+ int mesh = 0;
+
+ if (!PyArg_ParseTuple(args, "|i:getMesh", &mesh))
+ return NULL; // python sets a simple error
+
+ if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0)
+ {
+ KX_MeshProxy* meshproxy = new KX_MeshProxy(m_meshes[mesh]);
+ return meshproxy->NewProxy(true); // XXX Todo Python own.
+ }
+
+ Py_RETURN_NONE;
+}
+
+
+
+
PyObject* KX_GameObject::PySetCollisionMargin(PyObject* value)
{
@@ -2323,6 +2433,29 @@ PyObject* KX_GameObject::PyRestoreDynamics()
}
+
+PyObject* KX_GameObject::PyGetOrientation() //keywords
+{
+ ShowDeprecationWarning("getOrientation()", "the orientation property");
+ return PyObjectFrom(NodeGetWorldOrientation());
+}
+
+
+
+PyObject* KX_GameObject::PySetOrientation(PyObject* value)
+{
+ ShowDeprecationWarning("setOrientation()", "the orientation property");
+ MT_Matrix3x3 rot;
+
+ /* if value is not a sequence PyOrientationTo makes an error */
+ if (!PyOrientationTo(value, rot, "gameOb.setOrientation(sequence): KX_GameObject, "))
+ return NULL;
+
+ NodeSetLocalOrientation(rot);
+ NodeUpdateGS(0.f);
+ Py_RETURN_NONE;
+}
+
PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* args)
{
PyObject* pyvect;
@@ -2355,6 +2488,33 @@ PyObject* KX_GameObject::PyGetAxisVect(PyObject* value)
return NULL;
}
+PyObject* KX_GameObject::PySetPosition(PyObject* value)
+{
+ ShowDeprecationWarning("setPosition()", "the localPosition property");
+ MT_Point3 pos;
+ if (PyVecTo(value, pos))
+ {
+ NodeSetLocalPosition(pos);
+ NodeUpdateGS(0.f);
+ Py_RETURN_NONE;
+ }
+
+ return NULL;
+}
+
+PyObject* KX_GameObject::PySetWorldPosition(PyObject* value)
+{
+ ShowDeprecationWarning("setWorldPosition()", "the worldPosition property");
+ MT_Point3 pos;
+ if (PyVecTo(value, pos))
+ {
+ NodeSetWorldPosition(pos);
+ NodeUpdateGS(0.f);
+ Py_RETURN_NONE;
+ }
+
+ return NULL;
+}
PyObject* KX_GameObject::PyGetPhysicsId()
{
@@ -2520,10 +2680,12 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
}
}
MT_Point3 fromPoint = NodeGetWorldPosition();
-
if (dist != 0.0f)
- toPoint = fromPoint + dist * (toPoint-fromPoint).safe_normalized();
-
+ {
+ MT_Vector3 toDir = toPoint-fromPoint;
+ toDir.normalize();
+ toPoint = fromPoint + (dist) * toDir;
+ }
PHY_IPhysicsEnvironment* pe = KX_GetActiveScene()->GetPhysicsEnvironment();
KX_IPhysicsController *spc = GetPhysicsController();
KX_GameObject *parent = GetParent();
@@ -2716,7 +2878,7 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage,
char* to = (char *)"";
const STR_String& from = GetName();
- if (!PyArg_ParseTuple(args, "s|ss:sendMessage", &subject, &body, &to))
+ if (!PyArg_ParseTuple(args, "s|sss:sendMessage", &subject, &body, &to))
return NULL;
scene->GetNetworkScene()->SendMessage(to, from, subject, body);
@@ -2757,6 +2919,14 @@ PyObject* KX_GameObject::Pyget(PyObject *args)
return def;
}
+/* Matches python dict.has_key() */
+PyObject* KX_GameObject::Pyhas_key(PyObject* value)
+{
+ // the ONLY error case is invalid data, this is checked by the macro'd static function
+ // that calls this one. but make sure Seq_Contains doesnt add extra errors later on.
+ return PyBool_FromLong(Seq_Contains((PyObject *)this, value));
+}
+
/* ---------------------------------------------------------------------
* Some stuff taken from the header
* --------------------------------------------------------------------- */