[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25531] trunk/blender/source/gameengine: BGE: fix more matrix transpose bugs in assignement to game object matrices .

Benoit Bolsee benoit.bolsee at online.be
Wed Dec 23 00:38:09 CET 2009


Revision: 25531
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25531
Author:   ben2610
Date:     2009-12-23 00:38:09 +0100 (Wed, 23 Dec 2009)

Log Message:
-----------
BGE: fix more matrix transpose bugs in assignement to game object matrices.

Assignment to KX_GameObject localOrientation and
worldOrientation matrices was assuming row-major matrix
although reading these matrices was returning a column-major
MathUtils object.

The faulty function (PyMatTo) is fixed and all matrices
in python are now assumed column-major.

This function is also used in the following methods:

BL_Shader.setUniformMatrix4()
BL_Shader.setUniformMatrix3()

(No change in scripts if you didn't specify the optional
transpose parameter: the default value is changed so
that column-major matrices are assumed as before.)

KX_Camera.projection_matrix

(assignement to this attribute now requires a column-major
matrix and you must fix your script if you were setting
a value to this attribute.)

Modified Paths:
--------------
    trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp
    trunk/blender/source/gameengine/Ketsji/BL_Shader.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PyMath.h

Modified: trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp	2009-12-22 22:03:57 UTC (rev 25530)
+++ trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp	2009-12-22 23:38:09 UTC (rev 25531)
@@ -525,7 +525,7 @@
 		if(!PyMatTo(pymat, mat))
 			return NULL;
 		
-		mat.setValue((const float *)matrix);
+		mat.getValue((float*)matrix);
 		
 		BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
 		

Modified: trunk/blender/source/gameengine/Ketsji/BL_Shader.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/BL_Shader.cpp	2009-12-22 22:03:57 UTC (rev 25530)
+++ trunk/blender/source/gameengine/Ketsji/BL_Shader.cpp	2009-12-22 23:38:09 UTC (rev 25531)
@@ -1276,7 +1276,7 @@
 
 	const char *uniform="";
 	PyObject *matrix=0;
-	int transp=1; // MT_ is row major so transpose by default....
+	int transp=0; // python use column major by default, so no transpose....
 	
 	if(!PyArg_ParseTuple(args, "sO|i:setUniformMatrix4",&uniform, &matrix,&transp))
 		return NULL;
@@ -1322,7 +1322,7 @@
 
 	const char *uniform="";
 	PyObject *matrix=0;
-	int transp=1; // MT_ is row major so transpose by default....
+	int transp=0; // python use column major by default, so no transpose....
 	if(!PyArg_ParseTuple(args, "sO|i:setUniformMatrix3",&uniform, &matrix,&transp))
 		return NULL;
 	

Modified: trunk/blender/source/gameengine/Ketsji/KX_PyMath.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PyMath.h	2009-12-22 22:03:57 UTC (rev 25530)
+++ trunk/blender/source/gameengine/Ketsji/KX_PyMath.h	2009-12-22 23:38:09 UTC (rev 25531)
@@ -56,7 +56,7 @@
 inline unsigned int Size(const MT_Tuple4&)                { return 4; }
 
 /**
- *  Converts the given python matrix to an MT class.
+ *  Converts the given python matrix (column-major) to an MT class (row-major).
  */
 template<class T>
 bool PyMatTo(PyObject* pymat, T& mat)
@@ -65,30 +65,30 @@
 	mat.setIdentity();
 	if (PySequence_Check(pymat))
 	{
-		unsigned int rows = PySequence_Size(pymat);
-		if (rows != Size(mat))
+		unsigned int cols = PySequence_Size(pymat);
+		if (cols != Size(mat))
 			return false;
 			
-		for (unsigned int y = 0; noerror && y < Size(mat); y++)
+		for (unsigned int x = 0; noerror && x < cols; x++)
 		{
-			PyObject *pyrow = PySequence_GetItem(pymat, y); /* new ref */
-			if (!PyErr_Occurred() && PySequence_Check(pyrow))
+			PyObject *pycol = PySequence_GetItem(pymat, x); /* new ref */
+			if (!PyErr_Occurred() && PySequence_Check(pycol))
 			{
-				unsigned int cols = PySequence_Size(pyrow);
-				if (cols != Size(mat))
+				unsigned int rows = PySequence_Size(pycol);
+				if (rows != Size(mat))
 					noerror = false;
 				else
 				{
-					for( unsigned int x = 0; x < Size(mat); x++)
+					for( unsigned int y = 0; y < rows; y++)
 					{
-						PyObject *item = PySequence_GetItem(pyrow, x); /* new ref */
+						PyObject *item = PySequence_GetItem(pycol, y); /* new ref */
 						mat[y][x] = PyFloat_AsDouble(item);
 						Py_DECREF(item);
 					}
 				}
 			} else 
 				noerror = false;
-			Py_DECREF(pyrow);
+			Py_DECREF(pycol);
 		}
 	} else 
 		noerror = false;





More information about the Bf-blender-cvs mailing list