diff options
author | Andrew Hale <TrumanBlending@gmail.com> | 2012-01-24 05:56:44 +0400 |
---|---|---|
committer | Andrew Hale <TrumanBlending@gmail.com> | 2012-01-24 05:56:44 +0400 |
commit | e634cb26074ca3950fe00c1266e87d7d7689be09 (patch) | |
tree | d0afefbaa0e62ecf9fc3349d00b6910dd8b5dbb7 /source/blender | |
parent | d7e30369f8799d31a81a5b0e87122263d164ec16 (diff) |
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.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/mathutils/mathutils_Matrix.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index 7fe4b5ba5dd..efd73bf8c04 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -411,6 +411,34 @@ static void matrix_3x3_as_4x4(float mat[16]) /*-----------------------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 @@ static struct PyMethodDef Matrix_methods[] = { {"__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}, |