[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26343] trunk/blender/source/blender: py api - utility function for vectors.

Campbell Barton ideasman42 at gmail.com
Wed Jan 27 16:29:21 CET 2010


Revision: 26343
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26343
Author:   campbellbarton
Date:     2010-01-27 16:29:21 +0100 (Wed, 27 Jan 2010)

Log Message:
-----------
py api - utility function for vectors.
 quat = vec.difference(other)

also pedantic change with enum names.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_object.c
    trunk/blender/source/blender/python/generic/vector.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_object.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_object.c	2010-01-27 15:09:34 UTC (rev 26342)
+++ trunk/blender/source/blender/makesrna/intern/rna_object.c	2010-01-27 15:29:21 UTC (rev 26343)
@@ -1378,12 +1378,12 @@
 		{0, NULL, 0, NULL, NULL}};
 	
 	static EnumPropertyItem track_items[] = {
-		{OB_POSX, "POSX", 0, "+X", ""},
-		{OB_POSY, "POSY", 0, "+Y", ""},
-		{OB_POSZ, "POSZ", 0, "+Z", ""},
-		{OB_NEGX, "NEGX", 0, "-X", ""},
-		{OB_NEGY, "NEGY", 0, "-Y", ""},
-		{OB_NEGZ, "NEGZ", 0, "-Z", ""},
+		{OB_POSX, "POS_X", 0, "+X", ""},
+		{OB_POSY, "POS_Y", 0, "+Y", ""},
+		{OB_POSZ, "POS_Z", 0, "+Z", ""},
+		{OB_NEGX, "NEG_X", 0, "-X", ""},
+		{OB_NEGY, "NEG_Y", 0, "-Y", ""},
+		{OB_NEGZ, "NEG_Z", 0, "-Z", ""},
 		{0, NULL, 0, NULL, NULL}};
 
 	static EnumPropertyItem up_items[] = {

Modified: trunk/blender/source/blender/python/generic/vector.c
===================================================================
--- trunk/blender/source/blender/python/generic/vector.c	2010-01-27 15:09:34 UTC (rev 26342)
+++ trunk/blender/source/blender/python/generic/vector.c	2010-01-27 15:29:21 UTC (rev 26343)
@@ -560,6 +560,38 @@
 #endif
 }
 
+static char Vector_Difference_doc[] =
+".. function:: difference(other)\n"
+"\n"
+"   Returns a quaternion representing the rotational difference between this vector and another.\n"
+"\n"
+"   :arg other: second vector.\n"
+"   :type other: Vector\n"
+"   :return: the rotational difference between the two vectors.\n"
+"   :rtype: Quaternion\n";
+
+static PyObject *Vector_Difference( VectorObject * self, VectorObject * value )
+{
+	float quat[4];
+
+	if (!VectorObject_Check(value)) {
+		PyErr_SetString( PyExc_TypeError, "vec.difference(value): expected a vector argument" );
+		return NULL;
+	}
+
+	if(self->size < 3 || value->size < 3) {
+		PyErr_SetString(PyExc_AttributeError, "vec.difference(value): expects both vectors to be size 3 or 4\n");
+		return NULL;
+	}
+
+	if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(value))
+		return NULL;
+
+	rotation_between_vecs_to_quat(quat, self->vec, value->vec);
+
+	return newQuaternionObject(quat, Py_NEW, NULL);
+}
+
 static char Vector_Project_doc[] =
 ".. function:: project(other)\n"
 "\n"
@@ -2076,6 +2108,7 @@
 	{"cross", ( PyCFunction ) Vector_Cross, METH_O, Vector_Cross_doc},
 	{"dot", ( PyCFunction ) Vector_Dot, METH_O, Vector_Dot_doc},
 	{"angle", ( PyCFunction ) Vector_Angle, METH_O, Vector_Angle_doc},
+	{"difference", ( PyCFunction ) Vector_Difference, METH_O, Vector_Difference_doc},
 	{"project", ( PyCFunction ) Vector_Project, METH_O, Vector_Project_doc},
 	{"lerp", ( PyCFunction ) Vector_Lerp, METH_VARARGS, Vector_Lerp_doc},
 	{"copy", (PyCFunction) Vector_copy, METH_NOARGS, Vector_copy_doc},





More information about the Bf-blender-cvs mailing list