Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-12-16 08:05:16 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-12-16 08:05:16 +0400
commit1886ae38b4240a7a25c8256c70b794932d45a667 (patch)
treeab7ccaaba39071569b591c1ff344d587e9825ffb /source/blender
parent48935ac3b5ad1c11b6492018cff50eb97cb28cfb (diff)
add Matrix.normalized(), handy for transforming normals.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/python/mathutils/mathutils_Matrix.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c
index 05306f230d1..44f06fe4eda 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.c
+++ b/source/blender/python/mathutils/mathutils_Matrix.c
@@ -1533,6 +1533,53 @@ static PyObject *Matrix_transposed(MatrixObject *self)
return matrix__apply_to_copy((PyNoArgsFunction)Matrix_transpose, self);
}
+/*---------------------------matrix.normalize() ------------------*/
+PyDoc_STRVAR(Matrix_normalize_doc,
+".. method:: normalize()\n"
+"\n"
+" Normalize each of the columns of the matrix (useful for transforming unit length normals).\n"
+);
+static PyObject *Matrix_normalize(MatrixObject *self)
+{
+ if (BaseMath_ReadCallback(self) == -1)
+ return NULL;
+
+ if (self->num_col != self->num_row) {
+ PyErr_SetString(PyExc_ValueError,
+ "Matrix.normalize(): "
+ "only square matrices are supported");
+ return NULL;
+ }
+
+ if (self->num_col == 3) {
+ normalize_m3((float (*)[3])self->matrix);
+ }
+ else if (self->num_col == 4) {
+ normalize_m4((float (*)[4])self->matrix);
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "Matrix.normalize(): "
+ "can only use a 3x3 or 4x4 matrix");
+ }
+
+ (void)BaseMath_WriteCallback(self);
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(Matrix_normalized_doc,
+".. method:: normalized()\n"
+"\n"
+" Return a row normalized matrix\n"
+"\n"
+" :return: a row normalized matrix\n"
+" :rtype: :class:`Matrix`\n"
+);
+static PyObject *Matrix_normalized(MatrixObject *self)
+{
+ return matrix__apply_to_copy((PyNoArgsFunction)Matrix_normalize, self);
+}
+
/*---------------------------matrix.zero() -----------------------*/
PyDoc_STRVAR(Matrix_zero_doc,
".. method:: zero()\n"
@@ -2371,6 +2418,8 @@ static struct PyMethodDef Matrix_methods[] = {
/* operate on original or copy */
{"transpose", (PyCFunction) Matrix_transpose, METH_NOARGS, Matrix_transpose_doc},
{"transposed", (PyCFunction) Matrix_transposed, METH_NOARGS, Matrix_transposed_doc},
+ {"normalize", (PyCFunction) Matrix_normalize, METH_NOARGS, Matrix_normalize_doc},
+ {"normalized", (PyCFunction) Matrix_normalized, METH_NOARGS, Matrix_normalized_doc},
{"invert", (PyCFunction) Matrix_invert, METH_NOARGS, Matrix_invert_doc},
{"inverted", (PyCFunction) Matrix_inverted, METH_NOARGS, Matrix_inverted_doc},
{"adjugate", (PyCFunction) Matrix_adjugate, METH_NOARGS, Matrix_adjugate_doc},