| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-06-23 00:09:26 +00:00
										 |  |  |  * $Id$ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |  * Contributor(s): Joseph Gilbert | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:10:08 +00:00
										 |  |  | /** \file blender/python/generic/mathutils_Euler.c
 | 
					
						
							|  |  |  |  *  \ingroup pygen | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 04:15:25 +00:00
										 |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 12:05:27 +00:00
										 |  |  | #include "mathutils.h"
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | #define EULER_SIZE 3
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 14:22:27 +00:00
										 |  |  | //----------------------------------mathutils.Euler() -------------------
 | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | //makes a new euler for you to play with
 | 
					
						
							| 
									
										
										
										
											2010-11-28 06:03:30 +00:00
										 |  |  | static PyObject *Euler_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  | 	PyObject *seq= NULL; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	const char *order_str= NULL; | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	float eul[EULER_SIZE]= {0.0f, 0.0f, 0.0f}; | 
					
						
							|  |  |  | 	short order= EULER_ORDER_XYZ; | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | 	if(kwds && PyDict_Size(kwds)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  | 		                "mathutils.Euler(): " | 
					
						
							|  |  |  | 		                "takes no keyword args"); | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  | 	if(!PyArg_ParseTuple(args, "|Os:mathutils.Euler", &seq, &order_str)) | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  | 	switch(PyTuple_GET_SIZE(args)) { | 
					
						
							|  |  |  | 	case 0: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case 2: | 
					
						
							|  |  |  | 		if((order=euler_order_from_string(order_str, "mathutils.Euler()")) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  | 		/* intentionally pass through */ | 
					
						
							|  |  |  | 	case 1: | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		if (mathutils_array_parse(eul, EULER_SIZE, EULER_SIZE, seq, "mathutils.Euler()") == -1) | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-11-28 06:03:30 +00:00
										 |  |  | 	return newEulerObject(eul, order, Py_NEW, type); | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | /* internal use, assuem read callback is done */ | 
					
						
							|  |  |  | static const char *euler_order_str(EulerObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static const char order[][4] = {"XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"}; | 
					
						
							|  |  |  | 	return order[self->order-EULER_ORDER_XYZ]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | short euler_order_from_string(const char *str, const char *error_prefix) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if((str[0] && str[1] && str[2] && str[3]=='\0')) { | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | 		switch(*((PY_INT32_T *)str)) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			case 'X'|'Y'<<8|'Z'<<16:	return EULER_ORDER_XYZ; | 
					
						
							|  |  |  | 			case 'X'|'Z'<<8|'Y'<<16:	return EULER_ORDER_XZY; | 
					
						
							|  |  |  | 			case 'Y'|'X'<<8|'Z'<<16:	return EULER_ORDER_YXZ; | 
					
						
							|  |  |  | 			case 'Y'|'Z'<<8|'X'<<16:	return EULER_ORDER_YZX; | 
					
						
							|  |  |  | 			case 'Z'|'X'<<8|'Y'<<16:	return EULER_ORDER_ZXY; | 
					
						
							|  |  |  | 			case 'Z'|'Y'<<8|'X'<<16:	return EULER_ORDER_ZYX; | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  | 	PyErr_Format(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 	             "%s: invalid euler order '%s'", | 
					
						
							|  |  |  | 	             error_prefix, str); | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 	return -1; | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | /* note: BaseMath_ReadCallback must be called beforehand */ | 
					
						
							|  |  |  | static PyObject *Euler_ToTupleExt(EulerObject *self, int ndigits) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *ret; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	ret= PyTuple_New(EULER_SIZE); | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(ndigits >= 0) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		for(i= 0; i < EULER_SIZE; i++) { | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 			PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->eul[i], ndigits))); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		for(i= 0; i < EULER_SIZE; i++) { | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 			PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->eul[i])); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | //-----------------------------METHODS----------------------------
 | 
					
						
							|  |  |  | //return a quaternion representation of the euler
 | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Euler_to_quaternion_doc, | 
					
						
							| 
									
										
										
										
											2011-02-06 10:18:20 +00:00
										 |  |  | ".. method:: to_quaternion()\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | "\n" | 
					
						
							|  |  |  | "   Return a quaternion representation of the euler.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :return: Quaternion representation of the euler.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | "   :rtype: :class:`Quaternion`\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Euler_to_quaternion(EulerObject * self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-30 00:42:17 +00:00
										 |  |  | 	float quat[4]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_ReadCallback(self) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 	eulO_to_quat(quat, self->eul, self->order); | 
					
						
							| 
									
										
										
										
											2009-06-25 20:47:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-30 00:42:17 +00:00
										 |  |  | 	return newQuaternionObject(quat, Py_NEW, NULL); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | //return a matrix representation of the euler
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Euler_to_matrix_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | ".. method:: to_matrix()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Return a matrix representation of the euler.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :return: A 3x3 roation matrix representation of the euler.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | "   :rtype: :class:`Matrix`\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Euler_to_matrix(EulerObject * self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	float mat[9]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_ReadCallback(self) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 	eulO_to_mat3((float (*)[3])mat, self->eul, self->order); | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-30 00:42:17 +00:00
										 |  |  | 	return newMatrixObject(mat, 3, 3 , Py_NEW, NULL); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Euler_zero_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | ".. method:: zero()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Set all values to zero.\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Euler_zero(EulerObject * self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	zero_v3(self->eul); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_WriteCallback(self) == -1) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Euler_rotate_axis_doc, | 
					
						
							| 
									
										
										
										
											2010-09-29 08:07:58 +00:00
										 |  |  | ".. method:: rotate_axis(axis, angle)\n" | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  | "   Rotates the euler a certain amount and returning a unique euler rotation\n" | 
					
						
							|  |  |  | "   (no 720 degree pitches).\n" | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | "\n" | 
					
						
							|  |  |  | "   :arg axis: single character in ['X, 'Y', 'Z'].\n" | 
					
						
							|  |  |  | "   :type axis: string\n" | 
					
						
							| 
									
										
										
										
											2010-09-29 08:07:58 +00:00
										 |  |  | "   :arg angle: angle in radians.\n" | 
					
						
							|  |  |  | "   :type angle: float\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2010-09-29 08:07:58 +00:00
										 |  |  | static PyObject *Euler_rotate_axis(EulerObject * self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float angle = 0.0f; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	const char *axis; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-29 08:07:58 +00:00
										 |  |  | 	if(!PyArg_ParseTuple(args, "sf:rotate", &axis, &angle)){ | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  | 		                "euler.rotate(): " | 
					
						
							|  |  |  | 		                "expected angle (float) and axis (x, y, z)"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-08-30 08:37:35 +00:00
										 |  |  | 	if(!(ELEM3(*axis, 'X', 'Y', 'Z') && axis[1]=='\0')){ | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  | 		PyErr_SetString(PyExc_ValueError, "euler.rotate(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		                "expected axis to be 'X', 'Y' or 'Z'"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_ReadCallback(self) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	rotate_eulO(self->eul, self->order, *axis, angle); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  | 	(void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Euler_rotate_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | ".. method:: rotate(other)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Rotates the euler a by another mathutils value.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :arg other: rotation component of mathutils value\n" | 
					
						
							|  |  |  | "   :type other: :class:`Euler`, :class:`Quaternion` or :class:`Matrix`\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | static PyObject *Euler_rotate(EulerObject * self, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float self_rmat[3][3], other_rmat[3][3], rmat[3][3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_ReadCallback(self) == -1) | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(mathutils_any_to_rotmat(other_rmat, value, "euler.rotate(value)") == -1) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	eulO_to_mat3(self_rmat, self->eul, self->order); | 
					
						
							|  |  |  | 	mul_m3_m3m3(rmat, self_rmat, other_rmat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mat3_to_compatible_eulO(self->eul, self->eul, self->order, rmat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	(void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Euler_make_compatible_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | ".. method:: make_compatible(other)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  | "   Make this euler compatible with another,\n" | 
					
						
							|  |  |  | "   so interpolating between them works as intended.\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | "   .. note:: the rotation order is not taken into account for this function.\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Euler_make_compatible(EulerObject * self, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	float teul[EULER_SIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_ReadCallback(self) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	if(mathutils_array_parse(teul, EULER_SIZE, EULER_SIZE, value, "euler.make_compatible(other), invalid 'other' arg") == -1) | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	compatible_eul(self->eul, teul); | 
					
						
							| 
									
										
										
										
											2009-06-25 20:47:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  | 	(void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //----------------------------Euler.rotate()-----------------------
 | 
					
						
							|  |  |  | // return a copy of the euler
 | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Euler_copy_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | ".. function:: copy()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Returns a copy of this euler.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :return: A copy of the euler.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  | "   :rtype: :class:`Euler`\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  | "   .. note:: use this to get a copy of a wrapped euler with\n" | 
					
						
							|  |  |  | "      no reference to the original data.\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | static PyObject *Euler_copy(EulerObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_ReadCallback(self) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 	return newEulerObject(self->eul, self->order, Py_NEW, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //----------------------------print object (internal)--------------
 | 
					
						
							|  |  |  | //print the object to screen
 | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | static PyObject *Euler_repr(EulerObject * self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 	PyObject *ret, *tuple; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_ReadCallback(self) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 	tuple= Euler_ToTupleExt(self, -1); | 
					
						
							| 
									
										
										
										
											2010-04-19 22:02:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 	ret= PyUnicode_FromFormat("Euler(%R, '%s')", tuple, euler_order_str(self)); | 
					
						
							| 
									
										
										
										
											2010-04-19 22:02:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 	Py_DECREF(tuple); | 
					
						
							| 
									
										
										
										
											2010-04-19 22:02:53 +00:00
										 |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | static PyObject* Euler_richcmpr(PyObject *a, PyObject *b, int op) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 	PyObject *res; | 
					
						
							|  |  |  | 	int ok= -1; /* zero is true */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 	if (EulerObject_Check(a) && EulerObject_Check(b)) { | 
					
						
							|  |  |  | 		EulerObject *eulA= (EulerObject*)a; | 
					
						
							|  |  |  | 		EulerObject *eulB= (EulerObject*)b; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 		if(BaseMath_ReadCallback(eulA) == -1 || BaseMath_ReadCallback(eulB) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 		ok= ((eulA->order == eulB->order) && EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1)) ? 0 : -1; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch (op) { | 
					
						
							|  |  |  | 	case Py_NE: | 
					
						
							|  |  |  | 		ok = !ok; /* pass through */ | 
					
						
							|  |  |  | 	case Py_EQ: | 
					
						
							|  |  |  | 		res = ok ? Py_False : Py_True; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case Py_LT: | 
					
						
							|  |  |  | 	case Py_LE: | 
					
						
							|  |  |  | 	case Py_GT: | 
					
						
							|  |  |  | 	case Py_GE: | 
					
						
							|  |  |  | 		res = Py_NotImplemented; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		PyErr_BadArgument(); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return Py_INCREF(res), res; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-30 00:42:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | //---------------------SEQUENCE PROTOCOLS------------------------
 | 
					
						
							|  |  |  | //----------------------------len(object)------------------------
 | 
					
						
							|  |  |  | //sequence length
 | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | static int Euler_len(EulerObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	return EULER_SIZE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | //----------------------------object[]---------------------------
 | 
					
						
							|  |  |  | //sequence accessor (get)
 | 
					
						
							|  |  |  | static PyObject *Euler_item(EulerObject * self, int i) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	if(i<0) i= EULER_SIZE-i; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	if(i < 0 || i >= EULER_SIZE) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_SetString(PyExc_IndexError, | 
					
						
							|  |  |  | 		                "euler[attribute]: " | 
					
						
							|  |  |  | 		                "array index out of range"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_ReadIndexCallback(self, i) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	return PyFloat_FromDouble(self->eul[i]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //----------------------------object[]-------------------------
 | 
					
						
							|  |  |  | //sequence accessor (set)
 | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | static int Euler_ass_item(EulerObject * self, int i, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float f = PyFloat_AsDouble(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(f == -1 && PyErr_Occurred()) { // parsed item not a number
 | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  | 		                "euler[attribute] = x: " | 
					
						
							|  |  |  | 		                "argument not a number"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	if(i<0) i= EULER_SIZE-i; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	if(i < 0 || i >= EULER_SIZE){ | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_SetString(PyExc_IndexError, | 
					
						
							|  |  |  | 		                "euler[attribute] = x: " | 
					
						
							|  |  |  | 		                "array assignment index out of range"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	self->eul[i] = f; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_WriteIndexCallback(self, i) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //----------------------------object[z:y]------------------------
 | 
					
						
							|  |  |  | //sequence slice (get)
 | 
					
						
							|  |  |  | static PyObject *Euler_slice(EulerObject * self, int begin, int end) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  | 	PyObject *tuple; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	int count; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_ReadCallback(self) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	CLAMP(begin, 0, EULER_SIZE); | 
					
						
							|  |  |  | 	if (end<0) end= (EULER_SIZE + 1) + end; | 
					
						
							|  |  |  | 	CLAMP(end, 0, EULER_SIZE); | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  | 	begin= MIN2(begin, end); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  | 	tuple= PyTuple_New(end - begin); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	for(count = begin; count < end; count++) { | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  | 		PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->eul[count])); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  | 	return tuple; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | //----------------------------object[z:y]------------------------
 | 
					
						
							|  |  |  | //sequence slice (set)
 | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  | static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	int i, size; | 
					
						
							|  |  |  | 	float eul[EULER_SIZE]; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_ReadCallback(self) == -1) | 
					
						
							| 
									
										
										
										
											2009-06-28 13:27:06 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	CLAMP(begin, 0, EULER_SIZE); | 
					
						
							|  |  |  | 	if (end<0) end= (EULER_SIZE + 1) + end; | 
					
						
							|  |  |  | 	CLAMP(end, 0, EULER_SIZE); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  | 	begin = MIN2(begin, end); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	if((size=mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1) | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	if(size != (end - begin)){ | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		                "euler[begin:end] = []: " | 
					
						
							|  |  |  | 		                "size mismatch in slice assignment"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	for(i= 0; i < EULER_SIZE; i++) | 
					
						
							|  |  |  | 		self->eul[begin + i] = eul[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  | 	(void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Euler_subscript(EulerObject *self, PyObject *item) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (PyIndex_Check(item)) { | 
					
						
							|  |  |  | 		Py_ssize_t i; | 
					
						
							|  |  |  | 		i = PyNumber_AsSsize_t(item, PyExc_IndexError); | 
					
						
							|  |  |  | 		if (i == -1 && PyErr_Occurred()) | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		if (i < 0) | 
					
						
							|  |  |  | 			i += EULER_SIZE; | 
					
						
							|  |  |  | 		return Euler_item(self, i); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (PySlice_Check(item)) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		Py_ssize_t start, stop, step, slicelength; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-18 21:39:50 +00:00
										 |  |  | 		if (PySlice_GetIndicesEx((void *)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (slicelength <= 0) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:39:06 +00:00
										 |  |  | 			return PyTuple_New(0); | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if (step == 1) { | 
					
						
							|  |  |  | 			return Euler_slice(self, start, stop); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  | 			PyErr_SetString(PyExc_IndexError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 			                "slice steps not supported with eulers"); | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "euler indices must be integers, not %.200s", | 
					
						
							|  |  |  | 		             Py_TYPE(item)->tp_name); | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (PyIndex_Check(item)) { | 
					
						
							|  |  |  | 		Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); | 
					
						
							|  |  |  | 		if (i == -1 && PyErr_Occurred()) | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		if (i < 0) | 
					
						
							|  |  |  | 			i += EULER_SIZE; | 
					
						
							|  |  |  | 		return Euler_ass_item(self, i, value); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (PySlice_Check(item)) { | 
					
						
							|  |  |  | 		Py_ssize_t start, stop, step, slicelength; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-18 21:39:50 +00:00
										 |  |  | 		if (PySlice_GetIndicesEx((void *)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			return -1; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		if (step == 1) | 
					
						
							|  |  |  | 			return Euler_ass_slice(self, start, stop, value); | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  | 			PyErr_SetString(PyExc_IndexError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 			                "slice steps not supported with euler"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "euler indices must be integers, not %.200s", | 
					
						
							|  |  |  | 		             Py_TYPE(item)->tp_name); | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | //-----------------PROTCOL DECLARATIONS--------------------------
 | 
					
						
							|  |  |  | static PySequenceMethods Euler_SeqMethods = { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	(lenfunc) Euler_len,					/* sq_length */ | 
					
						
							| 
									
										
										
										
											2010-05-16 10:09:07 +00:00
										 |  |  | 	(binaryfunc) NULL,						/* sq_concat */ | 
					
						
							|  |  |  | 	(ssizeargfunc) NULL,					/* sq_repeat */ | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	(ssizeargfunc) Euler_item,				/* sq_item */ | 
					
						
							|  |  |  | 	(ssizessizeargfunc) NULL,				/* sq_slice, deprecated  */ | 
					
						
							|  |  |  | 	(ssizeobjargproc) Euler_ass_item,		/* sq_ass_item */ | 
					
						
							|  |  |  | 	(ssizessizeobjargproc) NULL,			/* sq_ass_slice, deprecated */ | 
					
						
							| 
									
										
										
										
											2010-05-16 10:09:07 +00:00
										 |  |  | 	(objobjproc) NULL,						/* sq_contains */ | 
					
						
							|  |  |  | 	(binaryfunc) NULL,						/* sq_inplace_concat */ | 
					
						
							|  |  |  | 	(ssizeargfunc) NULL,					/* sq_inplace_repeat */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | static PyMappingMethods Euler_AsMapping = { | 
					
						
							|  |  |  | 	(lenfunc)Euler_len, | 
					
						
							|  |  |  | 	(binaryfunc)Euler_subscript, | 
					
						
							|  |  |  | 	(objobjargproc)Euler_ass_subscript | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2010-04-11 14:22:27 +00:00
										 |  |  |  * euler axis, euler.x/y/z | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  | static PyObject *Euler_getAxis(EulerObject *self, void *type) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	return Euler_item(self, GET_INT_FROM_POINTER(type)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | static int Euler_setAxis(EulerObject *self, PyObject *value, void *type) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	return Euler_ass_item(self, GET_INT_FROM_POINTER(type), value); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | /* rotation order */ | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | static PyObject *Euler_getOrder(EulerObject *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 	if(BaseMath_ReadCallback(self) == -1) /* can read order too */ | 
					
						
							| 
									
										
										
										
											2010-04-26 21:04:42 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 	return PyUnicode_FromString(euler_order_str(self)); | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | static int Euler_setOrder(EulerObject *self, PyObject *value, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	const char *order_str= _PyUnicode_AsString(value); | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 	short order= euler_order_from_string(order_str, "euler.order"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	if(order == -1) | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self->order= order; | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  | 	(void)BaseMath_WriteCallback(self); /* order can be written back */ | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python attributes get/set structure:                                      */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyGetSetDef Euler_getseters[] = { | 
					
						
							| 
									
										
										
										
											2010-12-03 17:05:21 +00:00
										 |  |  | 	{(char *)"x", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler X axis in radians.\n\n:type: float", (void *)0}, | 
					
						
							|  |  |  | 	{(char *)"y", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler Y axis in radians.\n\n:type: float", (void *)1}, | 
					
						
							|  |  |  | 	{(char *)"z", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler Z axis in radians.\n\n:type: float", (void *)2}, | 
					
						
							|  |  |  | 	{(char *)"order", (getter)Euler_getOrder, (setter)Euler_setOrder, (char *)"Euler rotation order.\n\n:type: string in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']", (void *)NULL}, | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-03 17:05:21 +00:00
										 |  |  | 	{(char *)"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, (char *)BaseMathObject_Wrapped_doc, NULL}, | 
					
						
							|  |  |  | 	{(char *)"owner", (getter)BaseMathObject_getOwner, (setter)NULL, (char *)BaseMathObject_Owner_doc, NULL}, | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  | 	{NULL, NULL, NULL, NULL, NULL}  /* Sentinel */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //-----------------------METHOD DEFINITIONS ----------------------
 | 
					
						
							|  |  |  | static struct PyMethodDef Euler_methods[] = { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	{"zero", (PyCFunction) Euler_zero, METH_NOARGS, Euler_zero_doc}, | 
					
						
							|  |  |  | 	{"to_matrix", (PyCFunction) Euler_to_matrix, METH_NOARGS, Euler_to_matrix_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	{"to_quaternion", (PyCFunction) Euler_to_quaternion, METH_NOARGS, Euler_to_quaternion_doc}, | 
					
						
							| 
									
										
										
										
											2010-09-29 08:07:58 +00:00
										 |  |  | 	{"rotate_axis", (PyCFunction) Euler_rotate_axis, METH_VARARGS, Euler_rotate_axis_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 	{"rotate", (PyCFunction) Euler_rotate, METH_O, Euler_rotate_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	{"make_compatible", (PyCFunction) Euler_make_compatible, METH_O, Euler_make_compatible_doc}, | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | 	{"__copy__", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc}, | 
					
						
							|  |  |  | 	{"copy", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc}, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | //------------------PY_OBECT DEFINITION--------------------------
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(euler_doc, | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | "This object gives access to Eulers in Blender." | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | PyTypeObject euler_Type = { | 
					
						
							|  |  |  | 	PyVarObject_HEAD_INIT(NULL, 0) | 
					
						
							| 
									
										
										
										
											2011-02-13 10:52:18 +00:00
										 |  |  | 	"mathutils.Euler",				//tp_name
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	sizeof(EulerObject),			//tp_basicsize
 | 
					
						
							|  |  |  | 	0,								//tp_itemsize
 | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	(destructor)BaseMathObject_dealloc,		//tp_dealloc
 | 
					
						
							| 
									
										
										
										
											2011-02-13 10:52:18 +00:00
										 |  |  | 	NULL,							//tp_print
 | 
					
						
							|  |  |  | 	NULL,							//tp_getattr
 | 
					
						
							|  |  |  | 	NULL,							//tp_setattr
 | 
					
						
							|  |  |  | 	NULL,							//tp_compare
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	(reprfunc) Euler_repr,			//tp_repr
 | 
					
						
							| 
									
										
										
										
											2011-02-13 10:52:18 +00:00
										 |  |  | 	NULL,							//tp_as_number
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	&Euler_SeqMethods,				//tp_as_sequence
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	&Euler_AsMapping,				//tp_as_mapping
 | 
					
						
							| 
									
										
										
										
											2011-02-13 10:52:18 +00:00
										 |  |  | 	NULL,							//tp_hash
 | 
					
						
							|  |  |  | 	NULL,							//tp_call
 | 
					
						
							|  |  |  | 	NULL,							//tp_str
 | 
					
						
							|  |  |  | 	NULL,							//tp_getattro
 | 
					
						
							|  |  |  | 	NULL,							//tp_setattro
 | 
					
						
							|  |  |  | 	NULL,							//tp_as_buffer
 | 
					
						
							| 
									
										
										
										
											2011-02-24 04:58:51 +00:00
										 |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, //tp_flags
 | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  | 	euler_doc, //tp_doc
 | 
					
						
							| 
									
										
										
										
											2011-02-24 04:58:51 +00:00
										 |  |  | 	(traverseproc)BaseMathObject_traverse,	//tp_traverse
 | 
					
						
							|  |  |  | 	(inquiry)BaseMathObject_clear,	//tp_clear
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	(richcmpfunc)Euler_richcmpr,	//tp_richcompare
 | 
					
						
							|  |  |  | 	0,								//tp_weaklistoffset
 | 
					
						
							| 
									
										
										
										
											2011-02-13 10:52:18 +00:00
										 |  |  | 	NULL,							//tp_iter
 | 
					
						
							|  |  |  | 	NULL,							//tp_iternext
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	Euler_methods,					//tp_methods
 | 
					
						
							| 
									
										
										
										
											2011-02-13 10:52:18 +00:00
										 |  |  | 	NULL,							//tp_members
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	Euler_getseters,				//tp_getset
 | 
					
						
							| 
									
										
										
										
											2011-02-13 10:52:18 +00:00
										 |  |  | 	NULL,							//tp_base
 | 
					
						
							|  |  |  | 	NULL,							//tp_dict
 | 
					
						
							|  |  |  | 	NULL,							//tp_descr_get
 | 
					
						
							|  |  |  | 	NULL,							//tp_descr_set
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	0,								//tp_dictoffset
 | 
					
						
							| 
									
										
										
										
											2011-02-13 10:52:18 +00:00
										 |  |  | 	NULL,							//tp_init
 | 
					
						
							|  |  |  | 	NULL,							//tp_alloc
 | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | 	Euler_new,						//tp_new
 | 
					
						
							| 
									
										
										
										
											2011-02-13 10:52:18 +00:00
										 |  |  | 	NULL,							//tp_free
 | 
					
						
							|  |  |  | 	NULL,							//tp_is_gc
 | 
					
						
							|  |  |  | 	NULL,							//tp_bases
 | 
					
						
							|  |  |  | 	NULL,							//tp_mro
 | 
					
						
							|  |  |  | 	NULL,							//tp_cache
 | 
					
						
							|  |  |  | 	NULL,							//tp_subclasses
 | 
					
						
							|  |  |  | 	NULL,							//tp_weaklist
 | 
					
						
							|  |  |  | 	NULL							//tp_del
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | //------------------------newEulerObject (internal)-------------
 | 
					
						
							|  |  |  | //creates a new euler object
 | 
					
						
							|  |  |  | /*pass Py_WRAP - if vector is a WRAPPER for data allocated by BLENDER
 | 
					
						
							|  |  |  |  (i.e. it was allocated elsewhere by MEM_mallocN()) | 
					
						
							|  |  |  |   pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON | 
					
						
							|  |  |  |  (i.e. it must be created here with PyMEM_malloc())*/ | 
					
						
							| 
									
										
										
										
											2011-02-24 04:58:51 +00:00
										 |  |  | PyObject *newEulerObject(float *eul, short order, int type, PyTypeObject *base_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	EulerObject *self; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self= base_type ?	(EulerObject *)base_type->tp_alloc(base_type, 0) : | 
					
						
							|  |  |  | 						(EulerObject *)PyObject_GC_New(EulerObject, &euler_Type); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  | 	if(self) { | 
					
						
							|  |  |  | 		/* init callbacks as NULL */ | 
					
						
							|  |  |  | 		self->cb_user= NULL; | 
					
						
							|  |  |  | 		self->cb_type= self->cb_subtype= 0; | 
					
						
							| 
									
										
										
										
											2011-02-24 04:58:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  | 		if(type == Py_WRAP) { | 
					
						
							|  |  |  | 			self->eul = eul; | 
					
						
							|  |  |  | 			self->wrapped = Py_WRAP; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if (type == Py_NEW) { | 
					
						
							|  |  |  | 			self->eul = PyMem_Malloc(EULER_SIZE * sizeof(float)); | 
					
						
							|  |  |  | 			if(eul) { | 
					
						
							|  |  |  | 				copy_v3_v3(self->eul, eul); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				zero_v3(self->eul); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			self->wrapped = Py_NEW; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  | 			Py_FatalError("Euler(): invalid type!"); | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		self->order= order; | 
					
						
							| 
									
										
										
										
											2011-02-24 04:58:51 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	return (PyObject *)self; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | PyObject *newEulerObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  | 	EulerObject *self= (EulerObject *)newEulerObject(NULL, order, Py_NEW, NULL); | 
					
						
							|  |  |  | 	if(self) { | 
					
						
							|  |  |  | 		Py_INCREF(cb_user); | 
					
						
							|  |  |  | 		self->cb_user=			cb_user; | 
					
						
							|  |  |  | 		self->cb_type=			(unsigned char)cb_type; | 
					
						
							|  |  |  | 		self->cb_subtype=		(unsigned char)cb_subtype; | 
					
						
							| 
									
										
										
										
											2011-03-03 06:01:31 +00:00
										 |  |  | 		PyObject_GC_Track(self); | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-28 13:27:06 +00:00
										 |  |  | 	return (PyObject *)self; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | } |