forked from bartvdbraak/blender
Added getDistanceTo Python method (thanks Charlie C)
This commit is contained in:
parent
cb289b215f
commit
5fcf39d2a5
@ -621,7 +621,7 @@ PyMethodDef KX_GameObject::Methods[] = {
|
|||||||
{"getParent", (PyCFunction)KX_GameObject::sPyGetParent,METH_VARARGS},
|
{"getParent", (PyCFunction)KX_GameObject::sPyGetParent,METH_VARARGS},
|
||||||
{"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS},
|
{"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS},
|
||||||
{"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_VARARGS},
|
{"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_VARARGS},
|
||||||
|
KX_PYMETHODTABLE(KX_GameObject, getDistanceTo),
|
||||||
|
|
||||||
{NULL,NULL} //Sentinel
|
{NULL,NULL} //Sentinel
|
||||||
};
|
};
|
||||||
@ -1100,6 +1100,27 @@ PyObject* KX_GameObject::PyGetPhysicsId(PyObject* self,
|
|||||||
return PyInt_FromLong(physid);
|
return PyInt_FromLong(physid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KX_PYMETHODDEF_DOC(KX_GameObject, getDistanceTo,
|
||||||
|
"getDistanceTo(other): get distance to another point/KX_GameObject")
|
||||||
|
{
|
||||||
|
MT_Point3 b;
|
||||||
|
if (PyVecArgTo(args, b))
|
||||||
|
{
|
||||||
|
return PyFloat_FromDouble(NodeGetWorldPosition().distance(b));
|
||||||
|
}
|
||||||
|
PyErr_Clear();
|
||||||
|
|
||||||
|
PyObject *pyother;
|
||||||
|
if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &pyother))
|
||||||
|
{
|
||||||
|
KX_GameObject *other = static_cast<KX_GameObject*>(pyother);
|
||||||
|
return PyFloat_FromDouble(NodeGetWorldPosition().distance(other->NodeGetWorldPosition()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------
|
/* ---------------------------------------------------------------------
|
||||||
* Some stuff taken from the header
|
* Some stuff taken from the header
|
||||||
* --------------------------------------------------------------------- */
|
* --------------------------------------------------------------------- */
|
||||||
|
@ -613,6 +613,7 @@ public:
|
|||||||
KX_PYMETHOD(KX_GameObject,GetMesh);
|
KX_PYMETHOD(KX_GameObject,GetMesh);
|
||||||
KX_PYMETHOD(KX_GameObject,GetParent);
|
KX_PYMETHOD(KX_GameObject,GetParent);
|
||||||
KX_PYMETHOD(KX_GameObject,GetPhysicsId);
|
KX_PYMETHOD(KX_GameObject,GetPhysicsId);
|
||||||
|
KX_PYMETHOD_DOC(KX_GameObject,getDistanceTo);
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
|
@ -148,3 +148,11 @@ class KX_GameObject:
|
|||||||
"""
|
"""
|
||||||
Returns the user data object associated with this game object's physics controller.
|
Returns the user data object associated with this game object's physics controller.
|
||||||
"""
|
"""
|
||||||
|
def getDistanceTo(other):
|
||||||
|
"""
|
||||||
|
Returns the distance to another object or point.
|
||||||
|
|
||||||
|
@param other: a point or another L{KX_GameObject} to measure the distance to.
|
||||||
|
@type other: L{KX_GameObject} or list [x, y, z]
|
||||||
|
@rtype: float
|
||||||
|
"""
|
||||||
|
@ -5,6 +5,9 @@ New Python Functionality in this Version of Blender
|
|||||||
|
|
||||||
This document lists what has been changed in the Game Engine Python API.
|
This document lists what has been changed in the Game Engine Python API.
|
||||||
|
|
||||||
|
Blender CVS
|
||||||
|
- Added L{KX_GameObject}.getDistanceTo() method. (thanks Charlie C)
|
||||||
|
|
||||||
Blender 2.36
|
Blender 2.36
|
||||||
------------
|
------------
|
||||||
- Added L{KX_CameraActuator} methods (thanks snail)
|
- Added L{KX_CameraActuator} methods (thanks snail)
|
||||||
|
Loading…
Reference in New Issue
Block a user