diff options
Diffstat (limited to 'source/blender/python/mathutils/mathutils_Vector.c')
-rw-r--r-- | source/blender/python/mathutils/mathutils_Vector.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index bd121b6177f..c31835cf7b5 100644 --- a/source/blender/python/mathutils/mathutils_Vector.c +++ b/source/blender/python/mathutils/mathutils_Vector.c @@ -1540,6 +1540,7 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2) { VectorObject *vec1 = NULL, *vec2 = NULL; float scalar; + int vec_size; if VectorObject_Check(v1) { vec1= (VectorObject *)v1; @@ -1576,7 +1577,14 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2) return NULL; } - return Vector_CreatePyObject(tvec, vec1->size, Py_NEW, Py_TYPE(vec1)); + if (((MatrixObject *)v2)->num_row == 4 && vec1->size == 3) { + vec_size = 3; + } + else { + vec_size = ((MatrixObject *)v2)->num_col; + } + + return Vector_CreatePyObject(tvec, vec_size, Py_NEW, Py_TYPE(vec1)); } else if (QuaternionObject_Check(v2)) { /* VEC * QUAT */ @@ -2603,7 +2611,7 @@ if len(unique) != len(items): */ /* ROW VECTOR Multiplication - Vector X Matrix - * [x][y][z] * [1][4][7] + * [x][y][z] * [1][4][7] * [2][5][8] * [3][6][9] * vector/matrix multiplication IS NOT COMMUTATIVE!!!! */ @@ -2611,18 +2619,18 @@ static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *v { float vec_cpy[MAX_DIMENSIONS]; double dot = 0.0f; - int x, y, z= 0, vec_size= vec->size; + int row, col, z= 0, vec_size= vec->size; if (mat->num_row != vec_size) { - if (mat->num_row == 4 && vec_size != 3) { + if (mat->num_row == 4 && vec_size == 3) { + vec_cpy[3] = 1.0f; + } + else { PyErr_SetString(PyExc_ValueError, "vector * matrix: matrix column size " "and the vector size must be the same"); return -1; } - else { - vec_cpy[3] = 1.0f; - } } if (BaseMath_ReadCallback(vec) == -1 || BaseMath_ReadCallback(mat) == -1) @@ -2632,9 +2640,9 @@ static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *v rvec[3] = 1.0f; //muliplication - for (x = 0; x < mat->num_col; x++) { - for (y = 0; y < mat->num_row; y++) { - dot += MATRIX_ITEM(mat, y, x) * vec_cpy[y]; + for (col = 0; col < mat->num_col; col++) { + for (row = 0; row < mat->num_row; row++) { + dot += MATRIX_ITEM(mat, row, col) * vec_cpy[row]; } rvec[z++] = (float)dot; dot = 0.0f; |