From 81a7bf2db9beacf664588acddfe458ed216269f8 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Tue, 22 Dec 2009 23:38:09 +0000 Subject: 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.) --- source/gameengine/Ketsji/KX_PyMath.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source/gameengine/Ketsji/KX_PyMath.h') diff --git a/source/gameengine/Ketsji/KX_PyMath.h b/source/gameengine/Ketsji/KX_PyMath.h index 0ad91799983..8e0cce7f4a4 100644 --- a/source/gameengine/Ketsji/KX_PyMath.h +++ b/source/gameengine/Ketsji/KX_PyMath.h @@ -56,7 +56,7 @@ inline unsigned int Size(const MT_Tuple3&) { return 3; } 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 bool PyMatTo(PyObject* pymat, T& mat) @@ -65,30 +65,30 @@ bool PyMatTo(PyObject* pymat, T& mat) 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; -- cgit v1.2.3