Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / python / generic / matrix.c
index edb6fb7..be3e704 100644 (file)
@@ -598,18 +598,18 @@ static PyObject *Matrix_repr(MatrixObject * self)
                return NULL;
        
        BLI_strncpy(str,"",1024);
                return NULL;
        
        BLI_strncpy(str,"",1024);
-       for(x = 0; x < self->colSize; x++){
+       for(x = 0; x < self->rowSize; x++){
                sprintf(buffer, "[");
                strcat(str,buffer);
                sprintf(buffer, "[");
                strcat(str,buffer);
-               for(y = 0; y < (self->rowSize - 1); y++) {
-                       sprintf(buffer, "%.6f, ", self->matrix[y][x]);
+               for(y = 0; y < (self->colSize - 1); y++) {
+                       sprintf(buffer, "%.6f, ", self->matrix[x][y]);
                        strcat(str,buffer);
                }
                        strcat(str,buffer);
                }
-               if(x < (self->colSize-1)){
-                       sprintf(buffer, "%.6f](matrix [row %d])\n", self->matrix[y][x], x);
+               if(x < (self->rowSize-1)){
+                       sprintf(buffer, "%.6f](matrix [row %d])\n", self->matrix[x][y], x);
                        strcat(str,buffer);
                }else{
                        strcat(str,buffer);
                }else{
-                       sprintf(buffer, "%.6f](matrix [row %d])", self->matrix[y][x], x);
+                       sprintf(buffer, "%.6f](matrix [row %d])", self->matrix[x][y], x);
                        strcat(str,buffer);
                }
        }
                        strcat(str,buffer);
                }
        }
@@ -703,7 +703,7 @@ static int Matrix_ass_item(MatrixObject * self, int i, PyObject * ob)
                return -1;
        
        if(i >= self->rowSize || i < 0){
                return -1;
        
        if(i >= self->rowSize || i < 0){
-               PyErr_SetString(PyExc_TypeError, "matrix[attribute] = x: bad column\n");
+               PyErr_SetString(PyExc_TypeError, "matrix[attribute] = x: bad row\n");
                return -1;
        }
 
                return -1;
        }
 
@@ -933,21 +933,21 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
        }
 
        if(mat1 && mat2) { /*MATRIX * MATRIX*/
        }
 
        if(mat1 && mat2) { /*MATRIX * MATRIX*/
-               if(mat1->rowSize != mat2->colSize){
+               if(mat1->colSize != mat2->rowSize){
                        PyErr_SetString(PyExc_AttributeError,"Matrix multiplication: matrix A rowsize must equal matrix B colsize");
                        return NULL;
                }
                        PyErr_SetString(PyExc_AttributeError,"Matrix multiplication: matrix A rowsize must equal matrix B colsize");
                        return NULL;
                }
-               for(x = 0; x < mat2->rowSize; x++) {
-                       for(y = 0; y < mat1->colSize; y++) {
-                               for(z = 0; z < mat1->rowSize; z++) {
-                                       dot += (mat1->matrix[z][y] * mat2->matrix[x][z]);
+               for(x = 0; x < mat1->rowSize; x++) {
+                       for(y = 0; y < mat2->colSize; y++) {
+                               for(z = 0; z < mat1->colSize; z++) {
+                                       dot += (mat1->matrix[x][z] * mat2->matrix[z][y]);
                                }
                                }
-                               mat[((x * mat1->colSize) + y)] = (float)dot;
+                               mat[((x * mat1->rowSize) + y)] = (float)dot;
                                dot = 0.0f;
                        }
                }
                
                                dot = 0.0f;
                        }
                }
                
-               return newMatrixObject(mat, mat2->rowSize, mat1->colSize, Py_NEW, NULL);
+               return newMatrixObject(mat, mat1->rowSize, mat2->colSize, Py_NEW, NULL);
        }
        
        if(mat1==NULL){
        }
        
        if(mat1==NULL){
@@ -1288,9 +1288,9 @@ PyObject *newMatrixObject_cb(PyObject *cb_user, int rowSize, int colSize, int cb
 
 //----------------column_vector_multiplication (internal)---------
 //COLUMN VECTOR Multiplication (Matrix X Vector)
 
 //----------------column_vector_multiplication (internal)---------
 //COLUMN VECTOR Multiplication (Matrix X Vector)
-// [1][4][7]   [a]
-// [2][5][8] * [b]
-// [3][6][9]   [c]
+// [1][2][3]   [a]
+// [4][5][6] * [b]
+// [7][8][9]   [c]
 //vector/matrix multiplication IS NOT COMMUTATIVE!!!!
 static PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec)
 {
 //vector/matrix multiplication IS NOT COMMUTATIVE!!!!
 static PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec)
 {
@@ -1312,12 +1312,11 @@ static PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject*
 
        for(x = 0; x < vec->size; x++){
                vecCopy[x] = vec->vec[x];
 
        for(x = 0; x < vec->size; x++){
                vecCopy[x] = vec->vec[x];
-       }
-       vecNew[3] = 1.0f;
+               }
 
 
-       for(x = 0; x < mat->colSize; z++) {
-               for(y = 0; y < mat->rowSize; y++) {
-                       dot += mat->matrix[y][x] * vecCopy[y];
+       for(x = 0; x < mat->rowSize; x++) {
+               for(y = 0; y < mat->colSize; y++) {
+                       dot += mat->matrix[x][y] * vecCopy[y];
                }
                vecNew[z++] = (float)dot;
                dot = 0.0f;
                }
                vecNew[z++] = (float)dot;
                dot = 0.0f;