Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-11-22 13:39:28 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-11-22 13:39:28 +0300
commitf781780cc043bc26f70c89d1292215f0491d30dc (patch)
tree38925182938b35a3821c6e906693b1aeff8e138f /source/blender/python
parent77dff3f9863638a5a95a1ee7e6fc2b0e9b3b8357 (diff)
- blend_m3_m3m3 and blend_m4_m4m4 now support matrices with negative scales.
- python/mathutils api matrix.lerp(other, factor) - new function mat3_to_rot_size(), like mat4_to_loc_rot_size but with no location.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/generic/mathutils_matrix.c45
-rw-r--r--source/blender/python/generic/mathutils_matrix.h5
-rw-r--r--source/blender/python/generic/mathutils_vector.c2
3 files changed, 48 insertions, 4 deletions
diff --git a/source/blender/python/generic/mathutils_matrix.c b/source/blender/python/generic/mathutils_matrix.c
index 232d24714c5..fc717b0013b 100644
--- a/source/blender/python/generic/mathutils_matrix.c
+++ b/source/blender/python/generic/mathutils_matrix.c
@@ -1043,6 +1043,50 @@ static PyObject *Matrix_decompose(MatrixObject * self)
}
+
+static char Matrix_Lerp_doc[] =
+".. function:: lerp(other, factor)\n"
+"\n"
+" Returns the interpolation of two matricies.\n"
+"\n"
+" :arg other: value to interpolate with.\n"
+" :type other: :class:`Matrix`\n"
+" :arg factor: The interpolation value in [0.0, 1.0].\n"
+" :type factor: float\n"
+" :return: The interpolated rotation.\n"
+" :rtype: :class:`Matrix`\n";
+
+static PyObject *Matrix_Lerp(MatrixObject *self, PyObject *args)
+{
+ MatrixObject *mat2 = NULL;
+ float fac, mat[MATRIX_MAX_DIM*MATRIX_MAX_DIM];
+
+ if(!PyArg_ParseTuple(args, "O!f:lerp", &matrix_Type, &mat2, &fac))
+ return NULL;
+
+ if(self->rowSize != mat2->rowSize || self->colSize != mat2->colSize) {
+ PyErr_SetString(PyExc_AttributeError, "matrix.lerp(): expects both matrix objects of the same dimensions");
+ return NULL;
+ }
+
+ if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(mat2))
+ return NULL;
+
+ /* TODO, different sized matrix */
+ if(self->rowSize==4 && self->colSize==4) {
+ blend_m4_m4m4((float (*)[4])mat, (float (*)[4])self->contigPtr, (float (*)[4])mat2->contigPtr, fac);
+ }
+ else if (self->rowSize==3 && self->colSize==3) {
+ blend_m3_m3m3((float (*)[3])mat, (float (*)[3])self->contigPtr, (float (*)[3])mat2->contigPtr, fac);
+ }
+ else {
+ PyErr_SetString(PyExc_AttributeError, "matrix.lerp(): only 3x3 and 4x4 matrices supported");
+ return NULL;
+ }
+
+ return (PyObject*)newMatrixObject(mat, self->rowSize, self->colSize, Py_NEW, Py_TYPE(self));
+}
+
/*---------------------------Matrix.determinant() ----------------*/
static char Matrix_Determinant_doc[] =
".. method:: determinant()\n"
@@ -1791,6 +1835,7 @@ static struct PyMethodDef Matrix_methods[] = {
{"zero", (PyCFunction) Matrix_Zero, METH_NOARGS, Matrix_Zero_doc},
{"identity", (PyCFunction) Matrix_Identity, METH_NOARGS, Matrix_Identity_doc},
{"transpose", (PyCFunction) Matrix_Transpose, METH_NOARGS, Matrix_Transpose_doc},
+ {"lerp", (PyCFunction) Matrix_Lerp, METH_VARARGS, Matrix_Lerp_doc},
{"determinant", (PyCFunction) Matrix_Determinant, METH_NOARGS, Matrix_Determinant_doc},
{"invert", (PyCFunction) Matrix_Invert, METH_NOARGS, Matrix_Invert_doc},
{"translation_part", (PyCFunction) Matrix_TranslationPart, METH_NOARGS, Matrix_TranslationPart_doc},
diff --git a/source/blender/python/generic/mathutils_matrix.h b/source/blender/python/generic/mathutils_matrix.h
index 21538f8168e..f1cce3a45a8 100644
--- a/source/blender/python/generic/mathutils_matrix.h
+++ b/source/blender/python/generic/mathutils_matrix.h
@@ -38,10 +38,9 @@ extern PyTypeObject matrix_Type;
typedef struct {
BASE_MATH_MEMBERS(contigPtr)
-
- unsigned char rowSize;
- unsigned int colSize;
float *matrix[MATRIX_MAX_DIM]; /* ptr to the contigPtr (accessor) */
+ unsigned short rowSize;
+ unsigned short colSize;
} MatrixObject;
/*struct data contains a pointer to the actual data that the
diff --git a/source/blender/python/generic/mathutils_vector.c b/source/blender/python/generic/mathutils_vector.c
index e4027d7a80e..4dd2e250804 100644
--- a/source/blender/python/generic/mathutils_vector.c
+++ b/source/blender/python/generic/mathutils_vector.c
@@ -670,7 +670,7 @@ static PyObject *Vector_Lerp(VectorObject *self, PyObject *args)
return NULL;
if(self->size != vec2->size) {
- PyErr_SetString(PyExc_AttributeError, "vector.lerp(): expects (2) vector objects of the same size");
+ PyErr_SetString(PyExc_AttributeError, "vector.lerp(): expects both vector objects to have the same size");
return NULL;
}