[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45317] trunk/blender/source/blender: Fix for is_orthogonal check which in fact was checking for orthonormal matrix .

Sergey Sharybin sergey.vfx at gmail.com
Sun Apr 1 02:14:42 CEST 2012


Revision: 45317
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45317
Author:   nazgul
Date:     2012-04-01 00:14:41 +0000 (Sun, 01 Apr 2012)
Log Message:
-----------
Fix for is_orthogonal check which in fact was checking for orthonormal matrix.
Separated it into two functions so now it'll be clear if check happens for
orthonormal or just orthogonal.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_matrix.h
    trunk/blender/source/blender/blenlib/intern/math_matrix.c
    trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_matrix.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_matrix.h	2012-03-31 22:09:43 UTC (rev 45316)
+++ trunk/blender/source/blender/blenlib/BLI_math_matrix.h	2012-04-01 00:14:41 UTC (rev 45317)
@@ -123,6 +123,8 @@
 
 int is_orthogonal_m3(float mat[3][3]);
 int is_orthogonal_m4(float mat[4][4]);
+int is_orthonormal_m3(float mat[3][3]);
+int is_orthonormal_m4(float mat[4][4]);
 
 void adjoint_m3_m3(float R[3][3], float A[3][3]);
 void adjoint_m4_m4(float R[4][4], float A[4][4]);

Modified: trunk/blender/source/blender/blenlib/intern/math_matrix.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_matrix.c	2012-03-31 22:09:43 UTC (rev 45316)
+++ trunk/blender/source/blender/blenlib/intern/math_matrix.c	2012-04-01 00:14:41 UTC (rev 45317)
@@ -816,9 +816,6 @@
 			if (fabsf(dot_v3v3(m[i], m[j])) > 1.5f * FLT_EPSILON)
 				return 0;
 		}
-
-		if (fabsf(dot_v3v3(m[i], m[i]) - 1) > 1.5f * FLT_EPSILON)
-			return 0;
 	}
 
 	return 1;
@@ -834,13 +831,41 @@
 				return 0;
 		}
 
-		if (fabsf(dot_vn_vn(m[i], m[i], 4) - 1) > 1.5f * FLT_EPSILON)
-			return 0;
 	}
 
 	return 1;
 }
 
+int is_orthonormal_m3(float m[][3])
+{
+	if (is_orthogonal_m3(m)) {
+		int i;
+
+		for (i = 0; i < 3; i++)
+			if (fabsf(dot_v3v3(m[i], m[i]) - 1) > 1.5f * FLT_EPSILON)
+				return 0;
+
+		return 1;
+	}
+
+	return 0;
+}
+
+int is_orthonormal_m4(float m[][4])
+{
+	if (is_orthogonal_m4(m)) {
+		int i;
+
+		for (i = 0; i < 4; i++)
+			if (fabsf(dot_vn_vn(m[i], m[i], 4) - 1) > 1.5f * FLT_EPSILON)
+				return 0;
+
+		return 1;
+	}
+
+	return 0;
+}
+
 void normalize_m3(float mat[][3])
 {
 	normalize_v3(mat[0]);

Modified: trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c	2012-03-31 22:09:43 UTC (rev 45316)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c	2012-04-01 00:14:41 UTC (rev 45317)
@@ -2230,6 +2230,27 @@
 	}
 }
 
+PyDoc_STRVAR(Matrix_is_orthonormal_doc,
+"True if this matrix is orthonormal, 3x3 and 4x4 only, (read-only).\n\n:type: bool"
+);
+static PyObject *Matrix_is_orthonormal_get(MatrixObject *self, void *UNUSED(closure))
+{
+	if (BaseMath_ReadCallback(self) == -1)
+		return NULL;
+
+	/*must be 3-4 cols, 3-4 rows, square matrix*/
+	if (self->num_row == 4 && self->num_col == 4)
+		return PyBool_FromLong(is_orthonormal_m4((float (*)[4])self->matrix));
+	else if (self->num_row == 3 && self->num_col == 3)
+		return PyBool_FromLong(is_orthonormal_m3((float (*)[3])self->matrix));
+	else {
+		PyErr_SetString(PyExc_AttributeError,
+		                "Matrix.is_orthonormal: "
+		                "inappropriate matrix size - expects 3x3 or 4x4 matrix");
+		return NULL;
+	}
+}
+
 /*****************************************************************************/
 /* Python attributes get/set structure:                                      */
 /*****************************************************************************/
@@ -2240,6 +2261,7 @@
 	{(char *)"col", (getter)Matrix_col_get, (setter)NULL, Matrix_col_doc, NULL},
 	{(char *)"is_negative", (getter)Matrix_is_negative_get, (setter)NULL, Matrix_is_negative_doc, NULL},
 	{(char *)"is_orthogonal", (getter)Matrix_is_orthogonal_get, (setter)NULL, Matrix_is_orthogonal_doc, NULL},
+	{(char *)"is_orthonormal", (getter)Matrix_is_orthonormal_get, (setter)NULL, Matrix_is_orthonormal_doc, NULL},
 	{(char *)"is_wrapped", (getter)BaseMathObject_is_wrapped_get, (setter)NULL, BaseMathObject_is_wrapped_doc, NULL},
 	{(char *)"owner", (getter)BaseMathObject_owner_get, (setter)NULL, BaseMathObject_owner_doc, NULL},
 	{NULL, NULL, NULL, NULL, NULL}  /* Sentinel */




More information about the Bf-blender-cvs mailing list