BGE patch #17398 approved: implementation of BGE method getVectTo().
This commit is contained in:
@@ -914,6 +914,7 @@ PyMethodDef KX_GameObject::Methods[] = {
|
||||
KX_PYMETHODTABLE(KX_GameObject, rayCastTo),
|
||||
KX_PYMETHODTABLE(KX_GameObject, rayCast),
|
||||
KX_PYMETHODTABLE(KX_GameObject, getDistanceTo),
|
||||
KX_PYMETHODTABLE(KX_GameObject, getVectTo),
|
||||
{NULL,NULL} //Sentinel
|
||||
};
|
||||
|
||||
@@ -1555,6 +1556,57 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getDistanceTo,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
KX_PYMETHODDEF_DOC(KX_GameObject, getVectTo,
|
||||
"getVectTo(other): get vector and the distance to another point/KX_GameObject\n"
|
||||
"Returns a 3-tuple with (distance,worldVector,localVector)\n")
|
||||
{
|
||||
MT_Point3 toPoint, fromPoint;
|
||||
MT_Vector3 toDir, locToDir;
|
||||
MT_Scalar distance;
|
||||
|
||||
PyObject *returnValue = PyTuple_New(3);
|
||||
PyObject *pyother;
|
||||
|
||||
if (!returnValue)
|
||||
{
|
||||
PyErr_SetString(PyExc_MemoryError, "PyTuple_New() failed");
|
||||
return NULL;
|
||||
}
|
||||
if (!PyVecArgTo(args, toPoint))
|
||||
{
|
||||
PyErr_Clear();
|
||||
if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &pyother))
|
||||
{
|
||||
KX_GameObject *other = static_cast<KX_GameObject*>(pyother);
|
||||
toPoint = other->NodeGetWorldPosition();
|
||||
}else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Invalid arguments");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
fromPoint = NodeGetWorldPosition();
|
||||
toDir = toPoint-fromPoint;
|
||||
distance = toDir.length();
|
||||
|
||||
if (MT_fuzzyZero(distance))
|
||||
{
|
||||
//cout << "getVectTo() Error: Null vector!\n";
|
||||
locToDir = toDir = MT_Vector3(0.0,0.0,0.0);
|
||||
distance = 0.0;
|
||||
} else {
|
||||
toDir.normalize();
|
||||
locToDir = toDir * NodeGetWorldOrientation();
|
||||
}
|
||||
|
||||
PyTuple_SET_ITEM(returnValue, 0, PyFloat_FromDouble(distance));
|
||||
PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(toDir));
|
||||
PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(locToDir));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
bool KX_GameObject::RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data)
|
||||
{
|
||||
|
||||
|
||||
@@ -756,6 +756,7 @@ public:
|
||||
KX_PYMETHOD_DOC(KX_GameObject,rayCastTo);
|
||||
KX_PYMETHOD_DOC(KX_GameObject,rayCast);
|
||||
KX_PYMETHOD_DOC(KX_GameObject,getDistanceTo);
|
||||
KX_PYMETHOD_DOC(KX_GameObject,getVectTo);
|
||||
|
||||
private :
|
||||
|
||||
|
||||
@@ -253,6 +253,16 @@ class KX_GameObject:
|
||||
@type other: L{KX_GameObject} or list [x, y, z]
|
||||
@rtype: float
|
||||
"""
|
||||
def getVectTo(other):
|
||||
"""
|
||||
Returns the vector and the distance to another object or point.
|
||||
The vector is normalized unless the distance is 0, in which a NULL vector is returned.
|
||||
|
||||
@param other: a point or another L{KX_GameObject} to get the vector and distance to.
|
||||
@type other: L{KX_GameObject} or list [x, y, z]
|
||||
@rtype: 3-tuple (float, 3-tuple (x,y,z), 3-tuple (x,y,z))
|
||||
@return: (distance, globalVector(3), localVector(3))
|
||||
"""
|
||||
def rayCastTo(other,dist,prop):
|
||||
"""
|
||||
Look towards another point/object and find first object hit within dist that matches prop.
|
||||
|
||||
Reference in New Issue
Block a user