[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15941] trunk/blender/source/gameengine: BGE patch #17398 approved: implementation of BGE method getVectTo().

Benoit Bolsee benoit.bolsee at online.be
Sun Aug 3 23:59:36 CEST 2008


Revision: 15941
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15941
Author:   ben2610
Date:     2008-08-03 23:59:36 +0200 (Sun, 03 Aug 2008)

Log Message:
-----------
BGE patch #17398 approved: implementation of BGE method getVectTo().

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
    trunk/blender/source/gameengine/PyDoc/KX_GameObject.py

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2008-08-03 21:57:52 UTC (rev 15940)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2008-08-03 21:59:36 UTC (rev 15941)
@@ -914,6 +914,7 @@
 	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 @@
 	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)
 {
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h	2008-08-03 21:57:52 UTC (rev 15940)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h	2008-08-03 21:59:36 UTC (rev 15941)
@@ -756,6 +756,7 @@
 	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 :
 

Modified: trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/KX_GameObject.py	2008-08-03 21:57:52 UTC (rev 15940)
+++ trunk/blender/source/gameengine/PyDoc/KX_GameObject.py	2008-08-03 21:59:36 UTC (rev 15941)
@@ -253,6 +253,16 @@
 		@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.





More information about the Bf-blender-cvs mailing list