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/Converter/BL_ActionActuator.cpp | 2 +- source/gameengine/Ketsji/BL_Shader.cpp | 4 ++-- source/gameengine/Ketsji/KX_PyMath.h | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 1325c80a6d4..dd051d74944 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -525,7 +525,7 @@ KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel, if(!PyMatTo(pymat, mat)) return NULL; - mat.setValue((const float *)matrix); + mat.getValue((float*)matrix); BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent(); diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index 35eb5dc124a..55be606378d 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -1276,7 +1276,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformMatrix4, 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 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformMatrix3, 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; 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