[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43658] trunk/blender/source/blender/ python/mathutils/mathutils_Matrix.c: Add the .Identity() classmethod to mathutils matrices.

Andrew Hale TrumanBlending at gmail.com
Tue Jan 24 02:56:48 CET 2012


Revision: 43658
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43658
Author:   trumanblending
Date:     2012-01-24 01:56:44 +0000 (Tue, 24 Jan 2012)
Log Message:
-----------
Add the .Identity() classmethod to mathutils matrices. This allows the user
to create an identity matrix of a specific size without having to specify
all the values in the matrix and then use the .identity() method.

Modified Paths:
--------------
    trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c

Modified: trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c	2012-01-24 01:21:43 UTC (rev 43657)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c	2012-01-24 01:56:44 UTC (rev 43658)
@@ -411,6 +411,34 @@
 /*-----------------------CLASS-METHODS----------------------------*/
 
 //mat is a 1D array of floats - row[0][0], row[0][1], row[1][0], etc.
+PyDoc_STRVAR(C_Matrix_Identity_doc,
+".. classmethod:: Identity(size)\n"
+"\n"
+"   Create an identity matrix.\n"
+"\n"
+"   :arg size: The size of the identity matrix to construct [2, 4].\n"
+"   :type size: int\n"
+"   :return: A new identity matrix.\n"
+"   :rtype: :class:`Matrix`\n"
+);
+static PyObject *C_Matrix_Identity(PyObject *cls, PyObject *args)
+{
+	int matSize;
+
+	if (!PyArg_ParseTuple(args, "i:Matrix.Identity", &matSize)) {
+		return NULL;
+	}
+
+	if (matSize < 2 || matSize > 4) {
+		PyErr_SetString(PyExc_RuntimeError,
+						"Matrix.Identity(): "
+						"size must be between 2 and 4");
+		return NULL;
+	}
+
+	return Matrix_CreatePyObject(NULL, matSize, matSize, Py_NEW, (PyTypeObject *)cls);
+}
+
 PyDoc_STRVAR(C_Matrix_Rotation_doc,
 ".. classmethod:: Rotation(angle, size, axis)\n"
 "\n"
@@ -2246,6 +2274,7 @@
 	{"__copy__", (PyCFunction) Matrix_copy, METH_NOARGS, Matrix_copy_doc},
 
 	/* class methods */
+	{"Identity", (PyCFunction) C_Matrix_Identity, METH_VARARGS | METH_CLASS, C_Matrix_Identity_doc},
 	{"Rotation", (PyCFunction) C_Matrix_Rotation, METH_VARARGS | METH_CLASS, C_Matrix_Rotation_doc},
 	{"Scale", (PyCFunction) C_Matrix_Scale, METH_VARARGS | METH_CLASS, C_Matrix_Scale_doc},
 	{"Shear", (PyCFunction) C_Matrix_Shear, METH_VARARGS | METH_CLASS, C_Matrix_Shear_doc},



More information about the Bf-blender-cvs mailing list