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-09-29 09:15:55 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-09-29 09:15:55 +0400
commit7a950c287692dc44edc23eb9daf865de8e115307 (patch)
tree413a5b8330c0e7344a897c13ae2d6e309a0f91b1 /source/blender/python
parent2b59013490da8f60420c254d1c84d921c61e9c8c (diff)
patch from Dan Eicher with some edirts.
vec.rotate(axis, angle) equivalent to... vec[:] = vec * mathutils.Quaternion(axis, angle)
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/generic/mathutils_vector.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/python/generic/mathutils_vector.c b/source/blender/python/generic/mathutils_vector.c
index 7b73a7501bb..1fe2518c6ef 100644
--- a/source/blender/python/generic/mathutils_vector.c
+++ b/source/blender/python/generic/mathutils_vector.c
@@ -686,6 +686,45 @@ static PyObject *Vector_Lerp(VectorObject *self, PyObject *args)
return newVectorObject(vec, self->size, Py_NEW, NULL);
}
+/*---------------------------- Vector.rotate(angle, axis) ----------------------*/
+static char Vector_Rotate_doc[] =
+".. function:: rotate(axis, angle)\n"
+"\n"
+" Return vector rotated around axis by angle.\n"
+"\n"
+" :arg axis: rotation axis.\n"
+" :type axis: :class:`Vector`\n"
+" :arg angle: angle in radians.\n"
+" :type angle: float\n"
+" :return: an instance of itself\n"
+" :rtype: :class:`Vector`\n";
+
+static PyObject *Vector_Rotate(VectorObject *self, PyObject *args)
+{
+ VectorObject *axis_vec = NULL;
+ float angle, vec[3];
+
+ if(!PyArg_ParseTuple(args, "O!f", &vector_Type, &axis_vec, &angle)){
+ PyErr_SetString(PyExc_TypeError, "vec.rotate(angle, axis): expected angle (float) and 3D axis");
+ return NULL;
+ }
+
+ if(self->size != 3 || axis_vec->size != 3) {
+ PyErr_SetString(PyExc_AttributeError, "vec.rotate(angle, axis): expects both vectors to be 3D\n");
+ return NULL;
+ }
+
+ if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(axis_vec))
+ return NULL;
+
+ rotate_v3_v3v3fl(vec, self->vec, axis_vec->vec, angle);
+
+ copy_v3_v3(self->vec, vec);
+
+ Py_INCREF(self);
+ return (PyObject *)self;
+}
+
/*----------------------------Vector.copy() -------------------------------------- */
static char Vector_copy_doc[] =
".. function:: copy()\n"
@@ -2050,6 +2089,7 @@ static struct PyMethodDef Vector_methods[] = {
{"difference", ( PyCFunction ) Vector_Difference, METH_O, Vector_Difference_doc},
{"project", ( PyCFunction ) Vector_Project, METH_O, Vector_Project_doc},
{"lerp", ( PyCFunction ) Vector_Lerp, METH_VARARGS, Vector_Lerp_doc},
+ {"rotate", ( PyCFunction ) Vector_Rotate, METH_VARARGS, Vector_Rotate_doc},
{"copy", (PyCFunction) Vector_copy, METH_NOARGS, Vector_copy_doc},
{"__copy__", (PyCFunction) Vector_copy, METH_NOARGS, NULL},
{NULL, NULL, 0, NULL}