diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-07-21 06:00:29 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-07-21 06:00:29 +0400 |
commit | 314fdb941e28d5f1fbe2acace6133d6216f4e36c (patch) | |
tree | 45decdfa61bac4e86913aeaf82530865e04ff29b /source/blender/python | |
parent | c608288d76472856a0a0f7d1f1f0be4eebe15b88 (diff) |
revert recent matrix multiplication patch:
[#28032] Python Mathutils: Matrix Multiplication Error
Since they ended up reversing the order we better keep old code unless its proven to be incorrect.
also change Matrix.__repr__ function args to evaluate correctly (need to be inside a tuple).
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/mathutils/mathutils_Matrix.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index a7ed63776a5..76a0994c3aa 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -1318,21 +1318,20 @@ static PyObject *Matrix_repr(MatrixObject *self) } } switch(self->row_size) { - case 2: return PyUnicode_FromFormat("Matrix(%R,\n" - " %R)", rows[0], rows[1]); + case 2: return PyUnicode_FromFormat("Matrix((%R,\n" + " %R))", rows[0], rows[1]); - case 3: return PyUnicode_FromFormat("Matrix(%R,\n" - " %R,\n" - " %R)", rows[0], rows[1], rows[2]); + case 3: return PyUnicode_FromFormat("Matrix((%R,\n" + " %R,\n" + " %R))", rows[0], rows[1], rows[2]); - case 4: return PyUnicode_FromFormat("Matrix(%R,\n" - " %R,\n" - " %R,\n" - " %R)", rows[0], rows[1], rows[2], rows[3]); + case 4: return PyUnicode_FromFormat("Matrix((%R,\n" + " %R,\n" + " %R,\n" + " %R))", rows[0], rows[1], rows[2], rows[3]); } - PyErr_SetString(PyExc_RuntimeError, - "internal error!"); + Py_FatalError("Matrix(): invalid row size!"); return NULL; } @@ -1587,26 +1586,24 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) if(mat1 && mat2) { /*MATRIX * MATRIX*/ - if(mat2->row_size != mat1->col_size){ - PyErr_SetString(PyExc_ValueError, - "Matrix multiplication: " - "matrix A rowsize must equal matrix B colsize"); - return NULL; - } - else { - float mat[16]= {0.0f}; - int x, y, z; - - for(x = 0; x < mat2->row_size; x++) { - for(y = 0; y < mat1->col_size; y++) { - for(z = 0; z < mat1->row_size; z++) { - mat[x * mat2->col_size + y] += (mat2->matrix[x][z] * mat1->matrix[z][y]); - } + float mat[16]= {0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f}; + double dot = 0.0f; + int x, y, z; + + for(x = 0; x < mat2->row_size; x++) { + for(y = 0; y < mat1->col_size; y++) { + for(z = 0; z < mat1->row_size; z++) { + dot += (mat1->matrix[z][y] * mat2->matrix[x][z]); } + mat[((x * mat1->col_size) + y)] = (float)dot; + dot = 0.0f; } - - return newMatrixObject(mat, mat1->row_size, mat2->col_size, Py_NEW, Py_TYPE(mat1)); } + + return newMatrixObject(mat, mat2->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1)); } else if(mat2) { /*FLOAT/INT * MATRIX */ |