| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * 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
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup pymathutils | 
					
						
							| 
									
										
										
										
											2011-02-27 20:10:08 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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"
 | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | #include "../generic/python_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-26 09:26:52 +02:00
										 |  |  | #include "../generic/py_capi_utils.h"
 | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							|  |  |  | #  include "BLI_dynstr.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | #define QUAT_SIZE 4
 | 
					
						
							| 
									
										
										
										
											2011-01-07 19:18:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObject *self); | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | static void      quat__axis_angle_sanitize(float axis[3], float *angle); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Quaternion_copy(QuaternionObject *self); | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  | static PyObject *Quaternion_deepcopy(QuaternionObject *self, PyObject *args); | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* -----------------------------METHODS------------------------------ */ | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* note: BaseMath_ReadCallback must be called beforehand */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Quaternion_to_tuple_ext(QuaternionObject *self, int ndigits) | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	PyObject *ret; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	ret = PyTuple_New(QUAT_SIZE); | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (ndigits >= 0) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 		for (i = 0; i < QUAT_SIZE; i++) { | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 			PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->quat[i], ndigits))); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 		for (i = 0; i < QUAT_SIZE; i++) { | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 			PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->quat[i])); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_to_euler_doc, | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | ".. method:: to_euler(order, euler_compat)\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 Euler representation of the quaternion.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  | "   :arg order: Optional rotation order argument in\n" | 
					
						
							|  |  |  | "      ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'].\n" | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | "   :type order: string\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  | "   :arg euler_compat: Optional euler argument the new euler will be made\n" | 
					
						
							|  |  |  | "      compatible with (no axis flipping between them).\n" | 
					
						
							|  |  |  | "      Useful for converting a series of matrices to animation curves.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  | "   :type euler_compat: :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
										 |  |  | "   :return: Euler representation of the quaternion.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | "   :rtype: :class:`Euler`\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Quaternion_to_euler(QuaternionObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-07 01:38:42 +00:00
										 |  |  | 	float tquat[4]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	float eul[3]; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	const char *order_str = NULL; | 
					
						
							|  |  |  | 	short order = EULER_ORDER_XYZ; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	EulerObject *eul_compat = NULL; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat)) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (order_str) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 		order = euler_order_from_string(order_str, "Matrix.to_euler()"); | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (order == -1) { | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-07 01:38:42 +00:00
										 |  |  | 	normalize_qt_qt(tquat, self->quat); | 
					
						
							| 
									
										
										
										
											2010-02-20 19:49:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (eul_compat) { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (BaseMath_ReadCallback(eul_compat) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (order == EULER_ORDER_XYZ) { | 
					
						
							|  |  |  | 			quat_to_compatible_eul(eul, eul_compat->eul, tquat); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			quat_to_compatible_eulO(eul, eul_compat->eul, order, tquat); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (order == EULER_ORDER_XYZ) { | 
					
						
							|  |  |  | 			quat_to_eul(eul, tquat); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			quat_to_eulO(eul, order, tquat); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Euler_CreatePyObject(eul, order, NULL); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_to_matrix_doc, | 
					
						
							| 
									
										
										
										
											2010-08-16 12:14:09 +00:00
										 |  |  | ".. method:: to_matrix()\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 matrix representation of the quaternion.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :return: A 3x3 rotation matrix representation of the quaternion.\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 *Quaternion_to_matrix(QuaternionObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-25 20:47:41 +00:00
										 |  |  | 	float mat[9]; /* all values are set */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  | 	quat_to_mat3((float (*)[3])mat, self->quat); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Matrix_CreatePyObject(mat, 3, 3, NULL); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_to_axis_angle_doc, | 
					
						
							|  |  |  | ".. method:: to_axis_angle()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Return the axis, angle representation of the quaternion.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :return: axis, angle.\n" | 
					
						
							|  |  |  | "   :rtype: (:class:`Vector`, float) pair\n" | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | static PyObject *Quaternion_to_axis_angle(QuaternionObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float tquat[4]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float axis[3]; | 
					
						
							|  |  |  | 	float angle; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	normalize_qt_qt(tquat, self->quat); | 
					
						
							|  |  |  | 	quat_to_axis_angle(axis, &angle, tquat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	quat__axis_angle_sanitize(axis, &angle); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	ret = PyTuple_New(2); | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 	PyTuple_SET_ITEMS(ret, | 
					
						
							|  |  |  | 	        Vector_CreatePyObject(axis, 3, NULL), | 
					
						
							|  |  |  | 	        PyFloat_FromDouble(angle)); | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-01 11:58:10 +01:00
										 |  |  | PyDoc_STRVAR(Quaternion_to_exponential_map_doc, | 
					
						
							|  |  |  | ".. method:: to_exponential_map()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Return the exponential map representation of the quaternion.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   This representation consist of the rotation axis multiplied by the rotation angle." | 
					
						
							|  |  |  | "   Such a representation is useful for interpolation between multiple orientations.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :return: exponential map.\n" | 
					
						
							|  |  |  | "   :rtype: :class:`Vector` of size 3\n" | 
					
						
							| 
									
										
										
										
											2015-02-01 16:06:32 +01:00
										 |  |  | "\n" | 
					
						
							|  |  |  | "   To convert back to a quaternion, pass it to the :class:`Quaternion` constructor.\n" | 
					
						
							| 
									
										
										
										
											2015-02-01 11:58:10 +01:00
										 |  |  | ); | 
					
						
							|  |  |  | static PyObject *Quaternion_to_exponential_map(QuaternionObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float expmap[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2015-02-01 11:58:10 +01:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-02-01 11:58:10 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	quat_to_expmap(expmap, self->quat); | 
					
						
							|  |  |  | 	return Vector_CreatePyObject(expmap, 3, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_cross_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:: cross(other)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Return the cross product of this quaternion and another.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :arg other: The other quaternion to perform the cross product with.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  | "   :type other: :class:`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
										 |  |  | "   :return: The cross product.\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 *Quaternion_cross(QuaternionObject *self, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	float quat[QUAT_SIZE], tquat[QUAT_SIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  | 	if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, | 
					
						
							| 
									
										
										
										
											2012-05-20 19:49:27 +00:00
										 |  |  | 	                          "Quaternion.cross(other), invalid 'other' arg") == -1) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	mul_qt_qtqt(quat, self->quat, tquat); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Quaternion_CreatePyObject(quat, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_dot_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:: dot(other)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Return the dot product of this quaternion and another.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :arg other: The other quaternion to perform the dot product with.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  | "   :type other: :class:`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
										 |  |  | "   :return: The dot product.\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 *Quaternion_dot(QuaternionObject *self, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	float tquat[QUAT_SIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +00:00
										 |  |  | 	if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, | 
					
						
							|  |  |  | 	                          "Quaternion.dot(other), invalid 'other' arg") == -1) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	return PyFloat_FromDouble(dot_qtqt(self->quat, tquat)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_rotation_difference_doc, | 
					
						
							| 
									
										
										
										
											2011-10-10 01:14:49 +00:00
										 |  |  | ".. function:: rotation_difference(other)\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" | 
					
						
							|  |  |  | "   Returns a quaternion representing the rotational difference.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :arg other: second quaternion.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  | "   :type other: :class:`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
										 |  |  | "   :return: the rotational difference between the two quat rotations.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | "   :rtype: :class:`Quaternion`\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-04-04 05:17:23 +00:00
										 |  |  | static PyObject *Quaternion_rotation_difference(QuaternionObject *self, PyObject *value) | 
					
						
							| 
									
										
										
											
												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-02-04 03:06:23 +00:00
										 |  |  | 	float tquat[QUAT_SIZE], quat[QUAT_SIZE]; | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11: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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +00:00
										 |  |  | 	if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, | 
					
						
							|  |  |  | 	                          "Quaternion.difference(other), invalid 'other' arg") == -1) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	rotation_between_quats_to_quat(quat, self->quat, tquat); | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Quaternion_CreatePyObject(quat, Py_TYPE(self)); | 
					
						
							| 
									
										
										
											
												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(Quaternion_slerp_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:: slerp(other, factor)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Returns the interpolation of two quaternions.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :arg other: value to interpolate with.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  | "   :type other: :class:`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
										 |  |  | "   :arg factor: The interpolation value in [0.0, 1.0].\n" | 
					
						
							|  |  |  | "   :type factor: float\n" | 
					
						
							|  |  |  | "   :return: The interpolated rotation.\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 *Quaternion_slerp(QuaternionObject *self, PyObject *args) | 
					
						
							| 
									
										
										
											
												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-02-04 03:06:23 +00:00
										 |  |  | 	PyObject *value; | 
					
						
							|  |  |  | 	float tquat[QUAT_SIZE], quat[QUAT_SIZE], fac; | 
					
						
							| 
									
										
										
											
												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-10-13 01:29:08 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "Of:slerp", &value, &fac)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  | 		                "quat.slerp(): " | 
					
						
							|  |  |  | 		                "expected Quaternion types and float"); | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +00:00
										 |  |  | 	if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, | 
					
						
							|  |  |  | 	                          "Quaternion.slerp(other), invalid 'other' arg") == -1) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (fac > 1.0f || fac < 0.0f) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		                "quat.slerp(): " | 
					
						
							|  |  |  | 		                "interpolation factor must be between 0.0 and 1.0"); | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	interp_qt_qtqt(quat, self->quat, tquat, fac); | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Quaternion_CreatePyObject(quat, Py_TYPE(self)); | 
					
						
							| 
									
										
										
											
												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(Quaternion_rotate_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | ".. method:: rotate(other)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  | "   Rotates the quaternion by another mathutils value.\n" | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | "\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 *Quaternion_rotate(QuaternionObject *self, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float self_rmat[3][3], other_rmat[3][3], rmat[3][3]; | 
					
						
							|  |  |  | 	float tquat[4], length; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (mathutils_any_to_rotmat(other_rmat, value, "Quaternion.rotate(value)") == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	length = normalize_qt_qt(tquat, self->quat); | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 	quat_to_mat3(self_rmat, tquat); | 
					
						
							| 
									
										
										
										
											2011-11-24 19:36:12 +00:00
										 |  |  | 	mul_m3_m3m3(rmat, other_rmat, self_rmat); | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mat3_to_quat(self->quat, rmat); | 
					
						
							|  |  |  | 	mul_qt_fl(self->quat, length); /* maintain length after rotating */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	(void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ----------------------------Quaternion.normalize()---------------- */ | 
					
						
							| 
									
										
										
										
											2015-01-31 14:34:27 +01:00
										 |  |  | /* Normalize the quaternion. This may change the angle as well as the
 | 
					
						
							|  |  |  |  * rotation axis, as all of (w, x, y, z) are scaled. */ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_normalize_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:: normalize()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Normalize the quaternion.\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Quaternion_normalize(QuaternionObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 	normalize_qt(self->quat); | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  | 	(void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_normalized_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | ".. function:: normalized()\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-05 06:14:50 +00:00
										 |  |  | "   Return a new normalized 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" | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | "   :return: a normalized copy.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | "   :rtype: :class:`Quaternion`\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Quaternion_normalized(QuaternionObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 	return quat__apply_to_copy((PyNoArgsFunction)Quaternion_normalize, self); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_invert_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | ".. function:: invert()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Set the quaternion to its inverse.\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Quaternion_invert(QuaternionObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 	invert_qt(self->quat); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  | 	(void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_inverted_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | ".. function:: inverted()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Return a new, inverted quaternion.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :return: the inverted value.\n" | 
					
						
							|  |  |  | "   :rtype: :class:`Quaternion`\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Quaternion_inverted(QuaternionObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 	return quat__apply_to_copy((PyNoArgsFunction)Quaternion_invert, self); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_identity_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:: identity()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Set the quaternion to an identity quaternion.\n" | 
					
						
							|  |  |  | "\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 *Quaternion_identity(QuaternionObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 	unit_qt(self->quat); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  | 	(void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_negate_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:: negate()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Set the quaternion to its negative.\n" | 
					
						
							|  |  |  | "\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 *Quaternion_negate(QuaternionObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 	mul_qt_fl(self->quat, -1.0f); | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  | 	(void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_conjugate_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:: conjugate()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Set the quaternion to its conjugate (negate x, y, z).\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Quaternion_conjugate(QuaternionObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 	conjugate_qt(self->quat); | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  | 	(void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_conjugated_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | ".. function:: conjugated()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Return a new conjugated quaternion.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :return: a new quaternion.\n" | 
					
						
							|  |  |  | "   :rtype: :class:`Quaternion`\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Quaternion_conjugated(QuaternionObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 	return quat__apply_to_copy((PyNoArgsFunction)Quaternion_conjugate, self); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_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 quaternion.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :return: A copy of the quaternion.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  | "   :rtype: :class:`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" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  | "   .. note:: use this to get a copy of a wrapped quaternion 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 *Quaternion_copy(QuaternionObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Quaternion_CreatePyObject(self->quat, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  | static PyObject *Quaternion_deepcopy(QuaternionObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-06-26 09:26:52 +02:00
										 |  |  | 	if (!PyC_CheckArgs_DeepCopy(args)) { | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2018-06-26 09:26:52 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  | 	return Quaternion_copy(self); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* print the object to screen */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Quaternion_repr(QuaternionObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 	PyObject *ret, *tuple; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	tuple = Quaternion_to_tuple_ext(self, -1); | 
					
						
							| 
									
										
										
										
											2010-04-19 22:02:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	ret = PyUnicode_FromFormat("Quaternion(%R)", tuple); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | static PyObject *Quaternion_str(QuaternionObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	DynStr *ds; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	ds = BLI_dynstr_new(); | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  | 	BLI_dynstr_appendf(ds, "<Quaternion (w=%.4f, x=%.4f, y=%.4f, z=%.4f)>", | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | 	                   self->quat[0], self->quat[1], self->quat[2], self->quat[3]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return mathutils_dynstr_to_py(ds); /* frees ds */ | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *Quaternion_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; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	int ok = -1; /* zero is true */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 	if (QuaternionObject_Check(a) && QuaternionObject_Check(b)) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 		QuaternionObject *quatA = (QuaternionObject *)a; | 
					
						
							|  |  |  | 		QuaternionObject *quatB = (QuaternionObject *)b; | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (BaseMath_ReadCallback(quatA) == -1 || BaseMath_ReadCallback(quatB) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 		ok = (EXPP_VectorsAreEqual(quatA->quat, quatB->quat, QUAT_SIZE, 1)) ? 0 : -1; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 10:40:42 +00:00
										 |  |  | 	switch (op) { | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | 		case Py_NE: | 
					
						
							| 
									
										
										
										
											2013-07-21 08:16:37 +00:00
										 |  |  | 			ok = !ok; | 
					
						
							| 
									
										
										
										
											2017-05-20 14:01:03 +10:00
										 |  |  | 			ATTR_FALLTHROUGH; | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | 		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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 	return Py_INCREF_RET(res); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-30 00:42:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | static Py_hash_t Quaternion_hash(QuaternionObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMathObject_Prepare_ForHash(self) == -1) { | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return mathutils_array_hash(self->quat, QUAT_SIZE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ---------------------SEQUENCE PROTOCOLS------------------------ */ | 
					
						
							|  |  |  | /* ----------------------------len(object)------------------------ */ | 
					
						
							|  |  |  | /* sequence length */ | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | static int Quaternion_len(QuaternionObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	return QUAT_SIZE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ----------------------------object[]--------------------------- */ | 
					
						
							|  |  |  | /* sequence accessor (get) */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Quaternion_item(QuaternionObject *self, int i) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (i < 0) { | 
					
						
							|  |  |  | 		i = QUAT_SIZE - i; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (i < 0 || i >= QUAT_SIZE) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_SetString(PyExc_IndexError, | 
					
						
							|  |  |  | 		                "quaternion[attribute]: " | 
					
						
							|  |  |  | 		                "array index out of range"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadIndexCallback(self, i) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	return PyFloat_FromDouble(self->quat[i]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ----------------------------object[]------------------------- */ | 
					
						
							|  |  |  | /* sequence accessor (set) */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static int Quaternion_ass_item(QuaternionObject *self, int i, PyObject *ob) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | 	float f; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_Prepare_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	f = (float)PyFloat_AsDouble(ob); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (f == -1.0f && PyErr_Occurred()) { /* parsed item not a number */ | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  | 		                "quaternion[index] = x: " | 
					
						
							| 
									
										
										
										
											2014-01-30 16:45:20 +11:00
										 |  |  | 		                "assigned value not a number"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (i < 0) { | 
					
						
							|  |  |  | 		i = QUAT_SIZE - i; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (i < 0 || i >= QUAT_SIZE) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_SetString(PyExc_IndexError, | 
					
						
							|  |  |  | 		                "quaternion[attribute] = x: " | 
					
						
							|  |  |  | 		                "array assignment index out of range"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | 	self->quat[i] = f; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_WriteIndexCallback(self, i) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ----------------------------object[z:y]------------------------ */ | 
					
						
							|  |  |  | /* sequence slice (get) */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Quaternion_slice(QuaternionObject *self, int begin, int end) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  | 	PyObject *tuple; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	int count; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	CLAMP(begin, 0, QUAT_SIZE); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (end < 0) { | 
					
						
							|  |  |  | 		end = (QUAT_SIZE + 1) + end; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	CLAMP(end, 0, QUAT_SIZE); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	begin = MIN2(begin, end); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	tuple = PyTuple_New(end - begin); | 
					
						
							|  |  |  | 	for (count = begin; count < end; count++) { | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  | 		PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->quat[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
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ----------------------------object[z:y]------------------------ */ | 
					
						
							|  |  |  | /* sequence slice (set) */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static int Quaternion_ass_slice(QuaternionObject *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 quat[QUAT_SIZE]; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	CLAMP(begin, 0, QUAT_SIZE); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (end < 0) { | 
					
						
							|  |  |  | 		end = (QUAT_SIZE + 1) + end; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	CLAMP(end, 0, QUAT_SIZE); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  | 	begin = MIN2(begin, end); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if ((size = mathutils_array_parse(quat, 0, QUAT_SIZE, seq, "mathutils.Quaternion[begin:end] = []")) == -1) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +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
										 |  |  | 		                "quaternion[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
										 |  |  | 	/* parsed well - now set in vector */ | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	for (i = 0; i < size; i++) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		self->quat[begin + i] = quat[i]; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  | 	(void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Quaternion_subscript(QuaternionObject *self, PyObject *item) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (PyIndex_Check(item)) { | 
					
						
							|  |  |  | 		Py_ssize_t i; | 
					
						
							|  |  |  | 		i = PyNumber_AsSsize_t(item, PyExc_IndexError); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (i == -1 && PyErr_Occurred()) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (i < 0) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			i += QUAT_SIZE; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		return Quaternion_item(self, i); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (PySlice_Check(item)) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		Py_ssize_t start, stop, step, slicelength; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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 Quaternion_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 quaternions"); | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "quaternion indices must be integers, not %.200s", | 
					
						
							|  |  |  | 		             Py_TYPE(item)->tp_name); | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | static int Quaternion_ass_subscript(QuaternionObject *self, PyObject *item, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (PyIndex_Check(item)) { | 
					
						
							|  |  |  | 		Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (i == -1 && PyErr_Occurred()) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 			return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (i < 0) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			i += QUAT_SIZE; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 		return Quaternion_ass_item(self, i, value); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	else if (PySlice_Check(item)) { | 
					
						
							|  |  |  | 		Py_ssize_t start, stop, step, slicelength; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (step == 1) { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			return Quaternion_ass_slice(self, start, stop, value); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11: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 quaternion"); | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "quaternion 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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ------------------------NUMERIC PROTOCOLS---------------------- */ | 
					
						
							|  |  |  | /* ------------------------obj + obj------------------------------ */ | 
					
						
							|  |  |  | /* addition */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Quaternion_add(PyObject *q1, PyObject *q2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	float quat[QUAT_SIZE]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	QuaternionObject *quat1 = NULL, *quat2 = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (!QuaternionObject_Check(q1) || !QuaternionObject_Check(q2)) { | 
					
						
							| 
									
										
										
										
											2011-11-13 09:20:04 +00:00
										 |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "Quaternion addition: (%s + %s) " | 
					
						
							|  |  |  | 		             "invalid type for this operation", | 
					
						
							|  |  |  | 		             Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 	quat1 = (QuaternionObject *)q1; | 
					
						
							|  |  |  | 	quat2 = (QuaternionObject *)q2; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 	add_qt_qtqt(quat, quat1->quat, quat2->quat, 1.0f); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Quaternion_CreatePyObject(quat, Py_TYPE(q1)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ------------------------obj - obj------------------------------ */ | 
					
						
							|  |  |  | /* subtraction */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Quaternion_sub(PyObject *q1, PyObject *q2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int x; | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 	float quat[QUAT_SIZE]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	QuaternionObject *quat1 = NULL, *quat2 = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (!QuaternionObject_Check(q1) || !QuaternionObject_Check(q2)) { | 
					
						
							| 
									
										
										
										
											2011-11-13 09:20:04 +00:00
										 |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "Quaternion subtraction: (%s - %s) " | 
					
						
							|  |  |  | 		             "invalid type for this operation", | 
					
						
							|  |  |  | 		             Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 	quat1 = (QuaternionObject *)q1; | 
					
						
							|  |  |  | 	quat2 = (QuaternionObject *)q2; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	for (x = 0; x < QUAT_SIZE; x++) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		quat[x] = quat1->quat[x] - quat2->quat[x]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Quaternion_CreatePyObject(quat, Py_TYPE(q1)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject *quat_mul_float(QuaternionObject *quat, const float scalar) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float tquat[4]; | 
					
						
							|  |  |  | 	copy_qt_qt(tquat, quat->quat); | 
					
						
							|  |  |  | 	mul_qt_fl(tquat, scalar); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Quaternion_CreatePyObject(tquat, Py_TYPE(quat)); | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-26 20:05:38 +00:00
										 |  |  | /*------------------------obj * obj------------------------------
 | 
					
						
							|  |  |  |  * multiplication */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	float scalar; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	QuaternionObject *quat1 = NULL, *quat2 = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (QuaternionObject_Check(q1)) { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 		quat1 = (QuaternionObject *)q1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (BaseMath_ReadCallback(quat1) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (QuaternionObject_Check(q2)) { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 		quat2 = (QuaternionObject *)q2; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (BaseMath_ReadCallback(quat2) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	if (quat1 && quat2) { /* QUAT * QUAT (element-wise product) */ | 
					
						
							|  |  |  | #ifdef USE_MATHUTILS_ELEM_MUL
 | 
					
						
							|  |  |  | 		float quat[QUAT_SIZE]; | 
					
						
							|  |  |  | 		mul_vn_vnvn(quat, quat1->quat, quat2->quat, QUAT_SIZE); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 		return Quaternion_CreatePyObject(quat, Py_TYPE(q1)); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | 	/* the only case this can happen (for a supported type is "FLOAT * QUAT") */ | 
					
						
							|  |  |  | 	else if (quat2) { /* FLOAT * QUAT */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 		if (((scalar = PyFloat_AsDouble(q1)) == -1.0f && PyErr_Occurred()) == 0) { | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  | 			return quat_mul_float(quat2, scalar); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	else if (quat1) { /* QUAT * FLOAT */ | 
					
						
							|  |  |  | 		if ((((scalar = PyFloat_AsDouble(q2)) == -1.0f && PyErr_Occurred()) == 0)) { | 
					
						
							|  |  |  | 			return quat_mul_float(quat1, scalar); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  | 	             "Element-wise multiplication: " | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	             "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  | 	             Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /*------------------------obj *= obj------------------------------
 | 
					
						
							|  |  |  |  * inplace multiplication */ | 
					
						
							|  |  |  | static PyObject *Quaternion_imul(PyObject *q1, PyObject *q2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float scalar; | 
					
						
							|  |  |  | 	QuaternionObject *quat1 = NULL, *quat2 = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (QuaternionObject_Check(q1)) { | 
					
						
							|  |  |  | 		quat1 = (QuaternionObject *)q1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (BaseMath_ReadCallback(quat1) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (QuaternionObject_Check(q2)) { | 
					
						
							|  |  |  | 		quat2 = (QuaternionObject *)q2; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (BaseMath_ReadCallback(quat2) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (quat1 && quat2) { /* QUAT *= QUAT (inplace element-wise product) */ | 
					
						
							|  |  |  | #ifdef USE_MATHUTILS_ELEM_MUL
 | 
					
						
							|  |  |  | 		mul_vn_vn(quat1->quat, quat2->quat, QUAT_SIZE); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  | 		             "Inplace element-wise multiplication: " | 
					
						
							|  |  |  | 		             "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  | 		             Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (quat1 && (((scalar = PyFloat_AsDouble(q2)) == -1.0f && PyErr_Occurred()) == 0)) { | 
					
						
							|  |  |  | 		/* QUAT *= FLOAT */ | 
					
						
							|  |  |  | 		mul_qt_fl(quat1->quat, scalar); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  | 		             "Element-wise multiplication: " | 
					
						
							|  |  |  | 		             "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  | 		             Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	(void)BaseMath_WriteCallback(quat1); | 
					
						
							|  |  |  | 	Py_INCREF(q1); | 
					
						
							|  |  |  | 	return q1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /*------------------------obj @ obj------------------------------
 | 
					
						
							|  |  |  |  * quaternion multiplication */ | 
					
						
							|  |  |  | static PyObject *Quaternion_matmul(PyObject *q1, PyObject *q2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float quat[QUAT_SIZE]; | 
					
						
							|  |  |  | 	QuaternionObject *quat1 = NULL, *quat2 = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (QuaternionObject_Check(q1)) { | 
					
						
							|  |  |  | 		quat1 = (QuaternionObject *)q1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (BaseMath_ReadCallback(quat1) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (QuaternionObject_Check(q2)) { | 
					
						
							|  |  |  | 		quat2 = (QuaternionObject *)q2; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (BaseMath_ReadCallback(quat2) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (quat1 && quat2) { /* QUAT @ QUAT (cross product) */ | 
					
						
							|  |  |  | 		mul_qt_qtqt(quat, quat1->quat, quat2->quat); | 
					
						
							|  |  |  | 		return Quaternion_CreatePyObject(quat, Py_TYPE(q1)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-07-25 01:44:19 +00:00
										 |  |  | 	else if (quat1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 		/* QUAT @ VEC */ | 
					
						
							| 
									
										
										
										
											2011-07-25 01:44:19 +00:00
										 |  |  | 		if (VectorObject_Check(q2)) { | 
					
						
							|  |  |  | 			VectorObject *vec2 = (VectorObject *)q2; | 
					
						
							|  |  |  | 			float tvec[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 			if (vec2->size != 3) { | 
					
						
							| 
									
										
										
										
											2011-07-25 01:44:19 +00:00
										 |  |  | 				PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  | 				                "Vector multiplication: " | 
					
						
							|  |  |  | 				                "only 3D vector rotations (with quats) " | 
					
						
							|  |  |  | 				                "currently supported"); | 
					
						
							| 
									
										
										
										
											2011-07-25 01:44:19 +00:00
										 |  |  | 				return NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 			if (BaseMath_ReadCallback(vec2) == -1) { | 
					
						
							| 
									
										
										
										
											2011-07-25 01:44:19 +00:00
										 |  |  | 				return NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			copy_v3_v3(tvec, vec2->vec); | 
					
						
							|  |  |  | 			mul_qt_v3(quat1->quat, tvec); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 			return Vector_CreatePyObject(tvec, 3, Py_TYPE(vec2)); | 
					
						
							| 
									
										
										
										
											2011-07-25 01:44:19 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 	PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  | 	             "Quaternion multiplication: " | 
					
						
							|  |  |  | 	             "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  | 	             Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | /*------------------------obj @= obj------------------------------
 | 
					
						
							|  |  |  |  * inplace quaternion multiplication */ | 
					
						
							|  |  |  | static PyObject *Quaternion_imatmul(PyObject *q1, PyObject *q2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float quat[QUAT_SIZE]; | 
					
						
							|  |  |  | 	QuaternionObject *quat1 = NULL, *quat2 = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (QuaternionObject_Check(q1)) { | 
					
						
							|  |  |  | 		quat1 = (QuaternionObject *)q1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (BaseMath_ReadCallback(quat1) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (QuaternionObject_Check(q2)) { | 
					
						
							|  |  |  | 		quat2 = (QuaternionObject *)q2; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		if (BaseMath_ReadCallback(quat2) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (quat1 && quat2) { /* QUAT @ QUAT (cross product) */ | 
					
						
							|  |  |  | 		mul_qt_qtqt(quat, quat1->quat, quat2->quat); | 
					
						
							|  |  |  | 		copy_qt_qt(quat1->quat, quat); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  | 		             "Inplace quaternion multiplication: " | 
					
						
							|  |  |  | 		             "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  | 		             Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	(void)BaseMath_WriteCallback(quat1); | 
					
						
							|  |  |  | 	Py_INCREF(q1); | 
					
						
							|  |  |  | 	return q1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-08 03:37:49 +00:00
										 |  |  | /* -obj
 | 
					
						
							| 
									
										
										
										
											2012-03-03 20:36:09 +00:00
										 |  |  |  * returns the negative of this object*/ | 
					
						
							| 
									
										
										
										
											2011-02-08 03:37:49 +00:00
										 |  |  | static PyObject *Quaternion_neg(QuaternionObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float tquat[QUAT_SIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-08 03:37:49 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-08 03:37:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	negate_v4_v4(tquat, self->quat); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Quaternion_CreatePyObject(tquat, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2011-02-08 03:37:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* -----------------PROTOCOL DECLARATIONS-------------------------- */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | static PySequenceMethods Quaternion_SeqMethods = { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 	(lenfunc) Quaternion_len,               /* sq_length */ | 
					
						
							|  |  |  | 	(binaryfunc) NULL,                      /* sq_concat */ | 
					
						
							|  |  |  | 	(ssizeargfunc) NULL,                    /* sq_repeat */ | 
					
						
							|  |  |  | 	(ssizeargfunc) Quaternion_item,         /* sq_item */ | 
					
						
							|  |  |  | 	(ssizessizeargfunc) NULL,               /* sq_slice, deprecated */ | 
					
						
							|  |  |  | 	(ssizeobjargproc) Quaternion_ass_item,  /* sq_ass_item */ | 
					
						
							|  |  |  | 	(ssizessizeobjargproc) NULL,            /* sq_ass_slice, deprecated */ | 
					
						
							|  |  |  | 	(objobjproc) NULL,                      /* sq_contains */ | 
					
						
							|  |  |  | 	(binaryfunc) NULL,                      /* sq_inplace_concat */ | 
					
						
							|  |  |  | 	(ssizeargfunc) NULL,                    /* sq_inplace_repeat */ | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMappingMethods Quaternion_AsMapping = { | 
					
						
							|  |  |  | 	(lenfunc)Quaternion_len, | 
					
						
							|  |  |  | 	(binaryfunc)Quaternion_subscript, | 
					
						
							| 
									
										
										
										
											2019-01-19 13:21:18 +11:00
										 |  |  | 	(objobjargproc)Quaternion_ass_subscript, | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-06-28 13:27:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyNumberMethods Quaternion_NumMethods = { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 	(binaryfunc)    Quaternion_add, /*nb_add*/ | 
					
						
							|  |  |  | 	(binaryfunc)    Quaternion_sub, /*nb_subtract*/ | 
					
						
							|  |  |  | 	(binaryfunc)    Quaternion_mul, /*nb_multiply*/ | 
					
						
							|  |  |  | 	NULL,                           /*nb_remainder*/ | 
					
						
							|  |  |  | 	NULL,                           /*nb_divmod*/ | 
					
						
							|  |  |  | 	NULL,                           /*nb_power*/ | 
					
						
							|  |  |  | 	(unaryfunc)     Quaternion_neg, /*nb_negative*/ | 
					
						
							| 
									
										
										
										
											2012-08-27 13:40:19 +00:00
										 |  |  | 	(unaryfunc)     Quaternion_copy,/*tp_positive*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 	(unaryfunc)     0,  /*tp_absolute*/ | 
					
						
							|  |  |  | 	(inquiry)   0,      /*tp_bool*/ | 
					
						
							|  |  |  | 	(unaryfunc) 0,      /*nb_invert*/ | 
					
						
							|  |  |  | 	NULL,               /*nb_lshift*/ | 
					
						
							|  |  |  | 	(binaryfunc)0,      /*nb_rshift*/ | 
					
						
							|  |  |  | 	NULL,               /*nb_and*/ | 
					
						
							|  |  |  | 	NULL,               /*nb_xor*/ | 
					
						
							|  |  |  | 	NULL,               /*nb_or*/ | 
					
						
							|  |  |  | 	NULL,               /*nb_int*/ | 
					
						
							|  |  |  | 	NULL,               /*nb_reserved*/ | 
					
						
							|  |  |  | 	NULL,               /*nb_float*/ | 
					
						
							|  |  |  | 	NULL,               /* nb_inplace_add */ | 
					
						
							|  |  |  | 	NULL,               /* nb_inplace_subtract */ | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	(binaryfunc) Quaternion_imul,  /* nb_inplace_multiply */ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 	NULL,               /* nb_inplace_remainder */ | 
					
						
							|  |  |  | 	NULL,               /* nb_inplace_power */ | 
					
						
							|  |  |  | 	NULL,               /* nb_inplace_lshift */ | 
					
						
							|  |  |  | 	NULL,               /* nb_inplace_rshift */ | 
					
						
							|  |  |  | 	NULL,               /* nb_inplace_and */ | 
					
						
							|  |  |  | 	NULL,               /* nb_inplace_xor */ | 
					
						
							|  |  |  | 	NULL,               /* nb_inplace_or */ | 
					
						
							|  |  |  | 	NULL,               /* nb_floor_divide */ | 
					
						
							|  |  |  | 	NULL,               /* nb_true_divide */ | 
					
						
							|  |  |  | 	NULL,               /* nb_inplace_floor_divide */ | 
					
						
							|  |  |  | 	NULL,               /* nb_inplace_true_divide */ | 
					
						
							|  |  |  | 	NULL,               /* nb_index */ | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | 	(binaryfunc) Quaternion_matmul,  /* nb_matrix_multiply */ | 
					
						
							|  |  |  | 	(binaryfunc) Quaternion_imatmul, /* nb_inplace_matrix_multiply */ | 
					
						
							| 
									
										
										
										
											2009-06-28 13:27:06 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_axis_doc, | 
					
						
							|  |  |  | "Quaternion axis value.\n\n:type: float" | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static PyObject *Quaternion_axis_get(QuaternionObject *self, void *type) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 12:05:58 +10:00
										 |  |  | 	return Quaternion_item(self, POINTER_AS_INT(type)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static int Quaternion_axis_set(QuaternionObject *self, PyObject *value, void *type) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 12:05:58 +10:00
										 |  |  | 	return Quaternion_ass_item(self, POINTER_AS_INT(type), value); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_magnitude_doc, | 
					
						
							| 
									
										
										
										
											2012-02-24 06:44:04 +00:00
										 |  |  | "Size of the quaternion (read-only).\n\n:type: float" | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static PyObject *Quaternion_magnitude_get(QuaternionObject *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 14:11:37 +10:00
										 |  |  | 	return PyFloat_FromDouble(sqrtf(dot_qtqt(self->quat, self->quat))); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_angle_doc, | 
					
						
							|  |  |  | "Angle of the quaternion.\n\n:type: float" | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static PyObject *Quaternion_angle_get(QuaternionObject *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-07 01:38:42 +00:00
										 |  |  | 	float tquat[4]; | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 	float angle; | 
					
						
							| 
									
										
										
										
											2010-12-07 01:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-07 01:38:42 +00:00
										 |  |  | 	normalize_qt_qt(tquat, self->quat); | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	angle = 2.0f * saacos(tquat[0]); | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	quat__axis_angle_sanitize(NULL, &angle); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return PyFloat_FromDouble(angle); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static int Quaternion_angle_set(QuaternionObject *self, PyObject *value, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-07 01:38:42 +00:00
										 |  |  | 	float tquat[4]; | 
					
						
							|  |  |  | 	float len; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-11 09:41:26 +00:00
										 |  |  | 	float axis[3], angle_dummy; | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 	float angle; | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	len = normalize_qt_qt(tquat, self->quat); | 
					
						
							| 
									
										
										
										
											2011-01-11 09:41:26 +00:00
										 |  |  | 	quat_to_axis_angle(axis, &angle_dummy, tquat); | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	angle = PyFloat_AsDouble(value); | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	if (angle == -1.0f && PyErr_Occurred()) { /* parsed item not a number */ | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  | 		                "Quaternion.angle = value: float expected"); | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-04-25 23:33:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	angle = angle_wrap_rad(angle); | 
					
						
							| 
									
										
										
										
											2011-01-11 09:41:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 	quat__axis_angle_sanitize(axis, &angle); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 	axis_angle_to_quat(self->quat, axis, angle); | 
					
						
							| 
									
										
										
										
											2010-12-07 01:38:42 +00:00
										 |  |  | 	mul_qt_fl(self->quat, len); | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_WriteCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | PyDoc_STRVAR(Quaternion_axis_vector_doc, | 
					
						
							|  |  |  | "Quaternion axis as a vector.\n\n:type: :class:`Vector`" | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static PyObject *Quaternion_axis_vector_get(QuaternionObject *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-07 01:38:42 +00:00
										 |  |  | 	float tquat[4]; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 	float axis[3]; | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 	float angle_dummy; | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-12-07 01:38:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	normalize_qt_qt(tquat, self->quat); | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 	quat_to_axis_angle(axis, &angle_dummy, tquat); | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 	quat__axis_angle_sanitize(axis, NULL); | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Vector_CreatePyObject(axis, 3, NULL); | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static int Quaternion_axis_vector_set(QuaternionObject *self, PyObject *value, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-07 01:38:42 +00:00
										 |  |  | 	float tquat[4]; | 
					
						
							|  |  |  | 	float len; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 	float axis[3]; | 
					
						
							|  |  |  | 	float angle; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	len = normalize_qt_qt(tquat, self->quat); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	quat_to_axis_angle(axis, &angle, tquat); /* axis value is unused */ | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (mathutils_array_parse(axis, 3, 3, value, "quat.axis = other") == -1) { | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 	quat__axis_angle_sanitize(axis, &angle); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	axis_angle_to_quat(self->quat, axis, angle); | 
					
						
							| 
									
										
										
										
											2010-12-07 01:38:42 +00:00
										 |  |  | 	mul_qt_fl(self->quat, len); | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (BaseMath_WriteCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-07-25 02:56:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ----------------------------------mathutils.Quaternion() -------------- */ | 
					
						
							| 
									
										
										
										
											2010-11-28 06:03:30 +00:00
										 |  |  | static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | 
					
						
							| 
									
										
										
											
												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-12-24 13:26:30 +00:00
										 |  |  | 	PyObject *seq = NULL; | 
					
						
							| 
									
										
										
										
											2011-01-11 09:41:26 +00:00
										 |  |  | 	double angle = 0.0f; | 
					
						
							| 
									
										
										
										
											2018-07-16 09:37:24 +02:00
										 |  |  | 	float quat[QUAT_SIZE]; | 
					
						
							|  |  |  | 	unit_qt(quat); | 
					
						
							| 
									
										
										
											
												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-10-13 01:29:08 +00:00
										 |  |  | 	if (kwds && PyDict_Size(kwds)) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  | 		PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  | 		                "mathutils.Quaternion(): " | 
					
						
							|  |  |  | 		                "takes no keyword args"); | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "|Od:mathutils.Quaternion", &seq, &angle)) { | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11: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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 08:50:06 +00:00
										 |  |  | 	switch (PyTuple_GET_SIZE(args)) { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 		case 0: | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 1: | 
					
						
							| 
									
										
										
										
											2015-02-01 11:58:10 +01:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			int size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if ((size = mathutils_array_parse(quat, 3, QUAT_SIZE, seq, "mathutils.Quaternion()")) == -1) { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 				return NULL; | 
					
						
							| 
									
										
										
										
											2015-02-01 11:58:10 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (size == 4) { | 
					
						
							|  |  |  | 				/* 4d: Quaternion (common case) */ | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				/* 3d: Interpret as exponential map */ | 
					
						
							|  |  |  | 				BLI_assert(size == 3); | 
					
						
							|  |  |  | 				expmap_to_quat(quat, quat); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2015-02-01 11:58:10 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 		case 2: | 
					
						
							| 
									
										
										
										
											2012-07-25 16:46:46 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			float axis[3]; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 			if (mathutils_array_parse(axis, 3, 3, seq, "mathutils.Quaternion()") == -1) { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 				return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 			angle = angle_wrap_rad(angle); /* clamp because of precision issues */ | 
					
						
							| 
									
										
										
										
											2012-07-25 16:46:46 +00:00
										 |  |  | 			axis_angle_to_quat(quat, axis, angle); | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2013-04-07 15:09:06 +00:00
										 |  |  | 			/* PyArg_ParseTuple assures no more than 2 */ | 
					
						
							| 
									
										
										
										
											2012-07-25 16:46:46 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	return Quaternion_CreatePyObject(quat, type); | 
					
						
							| 
									
										
										
											
												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-02-09 09:20:17 +00:00
										 |  |  | static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 	PyObject *ret = Quaternion_copy(self); | 
					
						
							|  |  |  | 	PyObject *ret_dummy = quat_func(ret); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (ret_dummy) { | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 		Py_DECREF(ret_dummy); | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +00:00
										 |  |  | 		return ret; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { /* error */ | 
					
						
							|  |  |  | 		Py_DECREF(ret); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-13 01:11:08 +00:00
										 |  |  | /* axis vector suffers from precision errors, use this function to ensure */ | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | static void quat__axis_angle_sanitize(float axis[3], float *angle) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (axis) { | 
					
						
							| 
									
										
										
										
											2012-03-20 23:37:54 +00:00
										 |  |  | 		if (is_zero_v3(axis) || | 
					
						
							| 
									
										
										
										
											2016-05-16 00:48:02 +02:00
										 |  |  | 		    !isfinite(axis[0]) || | 
					
						
							|  |  |  | 		    !isfinite(axis[1]) || | 
					
						
							|  |  |  | 		    !isfinite(axis[2])) | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 			axis[0] = 1.0f; | 
					
						
							|  |  |  | 			axis[1] = 0.0f; | 
					
						
							|  |  |  | 			axis[2] = 0.0f; | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | 		else if (EXPP_FloatsAreEqual(axis[0], 0.0f, 10) && | 
					
						
							|  |  |  | 		         EXPP_FloatsAreEqual(axis[1], 0.0f, 10) && | 
					
						
							|  |  |  | 		         EXPP_FloatsAreEqual(axis[2], 0.0f, 10)) | 
					
						
							| 
									
										
										
										
											2011-12-18 08:50:06 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 			axis[0] = 1.0f; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (angle) { | 
					
						
							| 
									
										
										
										
											2016-05-16 00:48:02 +02:00
										 |  |  | 		if (!isfinite(*angle)) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 			*angle = 0.0f; | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* -----------------------METHOD DEFINITIONS ---------------------- */ | 
					
						
							| 
									
										
										
											
												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
										 |  |  | static struct PyMethodDef Quaternion_methods[] = { | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	/* in place only */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	{"identity", (PyCFunction) Quaternion_identity, METH_NOARGS, Quaternion_identity_doc}, | 
					
						
							|  |  |  | 	{"negate", (PyCFunction) Quaternion_negate, METH_NOARGS, Quaternion_negate_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* operate on original or copy */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	{"conjugate", (PyCFunction) Quaternion_conjugate, METH_NOARGS, Quaternion_conjugate_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	{"conjugated", (PyCFunction) Quaternion_conjugated, METH_NOARGS, Quaternion_conjugated_doc}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	{"invert", (PyCFunction) Quaternion_invert, METH_NOARGS, Quaternion_invert_doc}, | 
					
						
							|  |  |  | 	{"inverted", (PyCFunction) Quaternion_inverted, METH_NOARGS, Quaternion_inverted_doc}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	{"normalize", (PyCFunction) Quaternion_normalize, METH_NOARGS, Quaternion_normalize_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 	{"normalized", (PyCFunction) Quaternion_normalized, METH_NOARGS, Quaternion_normalized_doc}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* return converted representation */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	{"to_euler", (PyCFunction) Quaternion_to_euler, METH_VARARGS, Quaternion_to_euler_doc}, | 
					
						
							|  |  |  | 	{"to_matrix", (PyCFunction) Quaternion_to_matrix, METH_NOARGS, Quaternion_to_matrix_doc}, | 
					
						
							| 
									
										
										
										
											2011-11-02 09:13:04 +00:00
										 |  |  | 	{"to_axis_angle", (PyCFunction) Quaternion_to_axis_angle, METH_NOARGS, Quaternion_to_axis_angle_doc}, | 
					
						
							| 
									
										
										
										
											2015-02-01 11:58:10 +01:00
										 |  |  | 	{"to_exponential_map", (PyCFunction) Quaternion_to_exponential_map, METH_NOARGS, Quaternion_to_exponential_map_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* operation between 2 or more types  */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	{"cross", (PyCFunction) Quaternion_cross, METH_O, Quaternion_cross_doc}, | 
					
						
							|  |  |  | 	{"dot", (PyCFunction) Quaternion_dot, METH_O, Quaternion_dot_doc}, | 
					
						
							| 
									
										
										
										
											2011-04-04 05:17:23 +00:00
										 |  |  | 	{"rotation_difference", (PyCFunction) Quaternion_rotation_difference, METH_O, Quaternion_rotation_difference_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 	{"slerp", (PyCFunction) Quaternion_slerp, METH_VARARGS, Quaternion_slerp_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-16 02:05:36 +00:00
										 |  |  | 	{"rotate", (PyCFunction) Quaternion_rotate, METH_O, Quaternion_rotate_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | 	/* base-math methods */ | 
					
						
							|  |  |  | 	{"freeze", (PyCFunction)BaseMathObject_freeze, METH_NOARGS, BaseMathObject_freeze_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
										 |  |  | 	{"copy", (PyCFunction) Quaternion_copy, METH_NOARGS, Quaternion_copy_doc}, | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  | 	{"__copy__", (PyCFunction) Quaternion_copy, METH_NOARGS, Quaternion_copy_doc}, | 
					
						
							|  |  |  | 	{"__deepcopy__", (PyCFunction) Quaternion_deepcopy, METH_VARARGS, Quaternion_copy_doc}, | 
					
						
							| 
									
										
										
										
											2019-02-03 14:01:45 +11:00
										 |  |  | 	{NULL, NULL, 0, NULL}, | 
					
						
							| 
									
										
										
											
												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
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python attributes get/set structure:                                      */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyGetSetDef Quaternion_getseters[] = { | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | 	{(char *)"w", (getter)Quaternion_axis_get, (setter)Quaternion_axis_set, Quaternion_axis_doc, (void *)0}, | 
					
						
							|  |  |  | 	{(char *)"x", (getter)Quaternion_axis_get, (setter)Quaternion_axis_set, Quaternion_axis_doc, (void *)1}, | 
					
						
							|  |  |  | 	{(char *)"y", (getter)Quaternion_axis_get, (setter)Quaternion_axis_set, Quaternion_axis_doc, (void *)2}, | 
					
						
							|  |  |  | 	{(char *)"z", (getter)Quaternion_axis_get, (setter)Quaternion_axis_set, Quaternion_axis_doc, (void *)3}, | 
					
						
							|  |  |  | 	{(char *)"magnitude", (getter)Quaternion_magnitude_get, (setter)NULL, Quaternion_magnitude_doc, NULL}, | 
					
						
							|  |  |  | 	{(char *)"angle", (getter)Quaternion_angle_get, (setter)Quaternion_angle_set, Quaternion_angle_doc, NULL}, | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  | 	{(char *)"axis", (getter)Quaternion_axis_vector_get, (setter)Quaternion_axis_vector_set, Quaternion_axis_vector_doc, NULL}, | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | 	{(char *)"is_wrapped", (getter)BaseMathObject_is_wrapped_get, (setter)NULL, BaseMathObject_is_wrapped_doc, NULL}, | 
					
						
							| 
									
										
										
										
											2015-02-15 14:10:46 +11:00
										 |  |  | 	{(char *)"is_frozen",  (getter)BaseMathObject_is_frozen_get,  (setter)NULL, BaseMathObject_is_frozen_doc, NULL}, | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | 	{(char *)"owner", (getter)BaseMathObject_owner_get, (setter)NULL, 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
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ------------------PY_OBECT DEFINITION-------------------------- */ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(quaternion_doc, | 
					
						
							| 
									
										
										
										
											2015-02-01 16:06:32 +01:00
										 |  |  | ".. class:: Quaternion([seq, [angle]])\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   This object gives access to Quaternions in Blender.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :param seq: size 3 or 4\n" | 
					
						
							|  |  |  | "   :type seq: :class:`Vector`\n" | 
					
						
							|  |  |  | "   :param angle: rotation angle, in radians\n" | 
					
						
							|  |  |  | "   :type angle: float\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   The constructor takes arguments in various forms:\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   (), *no args*\n" | 
					
						
							| 
									
										
										
										
											2018-11-14 09:04:24 +11:00
										 |  |  | "      Create an identity quaternion\n" | 
					
						
							| 
									
										
										
										
											2015-02-01 16:06:32 +01:00
										 |  |  | "   (*wxyz*)\n" | 
					
						
							| 
									
										
										
										
											2018-11-14 09:04:24 +11:00
										 |  |  | "      Create a quaternion from a ``(w, x, y, z)`` vector.\n" | 
					
						
							| 
									
										
										
										
											2015-02-01 16:06:32 +01:00
										 |  |  | "   (*exponential_map*)\n" | 
					
						
							| 
									
										
										
										
											2018-11-14 09:04:24 +11:00
										 |  |  | "      Create a quaternion from a 3d exponential map vector.\n" | 
					
						
							| 
									
										
										
										
											2015-02-01 16:06:32 +01:00
										 |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2018-11-14 09:04:24 +11:00
										 |  |  | "      .. seealso:: :meth:`to_exponential_map`\n" | 
					
						
							| 
									
										
										
										
											2015-02-01 16:06:32 +01:00
										 |  |  | "   (*axis, angle*)\n" | 
					
						
							| 
									
										
										
										
											2018-11-14 09:04:24 +11:00
										 |  |  | "      Create a quaternion representing a rotation of *angle* radians over *axis*.\n" | 
					
						
							| 
									
										
										
										
											2015-02-01 16:06:32 +01:00
										 |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2018-11-14 09:04:24 +11:00
										 |  |  | "      .. seealso:: :meth:`to_axis_angle`\n" | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | PyTypeObject quaternion_Type = { | 
					
						
							|  |  |  | 	PyVarObject_HEAD_INIT(NULL, 0) | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | 	"Quaternion",                       /* tp_name */ | 
					
						
							|  |  |  | 	sizeof(QuaternionObject),           /* tp_basicsize */ | 
					
						
							|  |  |  | 	0,                                  /* tp_itemsize */ | 
					
						
							|  |  |  | 	(destructor)BaseMathObject_dealloc, /* tp_dealloc */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_print */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_getattr */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_setattr */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_compare */ | 
					
						
							|  |  |  | 	(reprfunc) Quaternion_repr,         /* tp_repr */ | 
					
						
							|  |  |  | 	&Quaternion_NumMethods,             /* tp_as_number */ | 
					
						
							|  |  |  | 	&Quaternion_SeqMethods,             /* tp_as_sequence */ | 
					
						
							|  |  |  | 	&Quaternion_AsMapping,              /* tp_as_mapping */ | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 	(hashfunc)Quaternion_hash,          /* tp_hash */ | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | 	NULL,                               /* tp_call */ | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | 	(reprfunc) Quaternion_str,          /* tp_str */ | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	NULL,                               /* tp_str */ | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | 	NULL,                               /* tp_getattro */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_setattro */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_as_buffer */ | 
					
						
							|  |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ | 
					
						
							|  |  |  | 	quaternion_doc, /* tp_doc */ | 
					
						
							|  |  |  | 	(traverseproc)BaseMathObject_traverse,  /* tp_traverse */ | 
					
						
							|  |  |  | 	(inquiry)BaseMathObject_clear,  /* tp_clear */ | 
					
						
							|  |  |  | 	(richcmpfunc)Quaternion_richcmpr,   /* tp_richcompare */ | 
					
						
							|  |  |  | 	0,                                  /* tp_weaklistoffset */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_iter */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_iternext */ | 
					
						
							|  |  |  | 	Quaternion_methods,                 /* tp_methods */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_members */ | 
					
						
							|  |  |  | 	Quaternion_getseters,               /* tp_getset */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_base */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_dict */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_descr_get */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_descr_set */ | 
					
						
							|  |  |  | 	0,                                  /* tp_dictoffset */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_init */ | 
					
						
							|  |  |  | 	NULL,                               /* tp_alloc */ | 
					
						
							|  |  |  | 	Quaternion_new,                     /* tp_new */ | 
					
						
							|  |  |  | 	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
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | PyObject *Quaternion_CreatePyObject( | 
					
						
							|  |  |  |         const float quat[4], | 
					
						
							|  |  |  |         PyTypeObject *base_type) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	QuaternionObject *self; | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	float *quat_alloc; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	quat_alloc = PyMem_Malloc(QUAT_SIZE * sizeof(float)); | 
					
						
							|  |  |  | 	if (UNLIKELY(quat_alloc == NULL)) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_MemoryError, | 
					
						
							|  |  |  | 		                "Quaternion(): " | 
					
						
							|  |  |  | 		                "problem allocating data"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-24 04:58:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	self = BASE_MATH_NEW(QuaternionObject, quaternion_Type, base_type); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (self) { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 		self->quat = quat_alloc; | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  | 		/* init callbacks as NULL */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | 		self->cb_user = NULL; | 
					
						
							|  |  |  | 		self->cb_type = self->cb_subtype = 0; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 		/* NEW */ | 
					
						
							|  |  |  | 		if (!quat) {  /* new empty */ | 
					
						
							|  |  |  | 			unit_qt(self->quat); | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 			copy_qt_qt(self->quat, quat); | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 		self->flag = BASE_MATH_FLAG_DEFAULT; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		PyMem_Free(quat_alloc); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (PyObject *)self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject *Quaternion_CreatePyObject_wrap( | 
					
						
							|  |  |  |         float quat[4], | 
					
						
							|  |  |  |         PyTypeObject *base_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QuaternionObject *self; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self = BASE_MATH_NEW(QuaternionObject, quaternion_Type, base_type); | 
					
						
							|  |  |  | 	if (self) { | 
					
						
							|  |  |  | 		/* init callbacks as NULL */ | 
					
						
							|  |  |  | 		self->cb_user = NULL; | 
					
						
							|  |  |  | 		self->cb_type = self->cb_subtype = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* WRAP */ | 
					
						
							|  |  |  | 		self->quat = quat; | 
					
						
							|  |  |  | 		self->flag = BASE_MATH_FLAG_DEFAULT | BASE_MATH_FLAG_IS_WRAP; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return (PyObject *) self; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-17 22:31:57 +00:00
										 |  |  | PyObject *Quaternion_CreatePyObject_cb(PyObject *cb_user, | 
					
						
							|  |  |  |                                        unsigned char cb_type, unsigned char cb_subtype) | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 	QuaternionObject *self = (QuaternionObject *)Quaternion_CreatePyObject(NULL, NULL); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (self) { | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  | 		Py_INCREF(cb_user); | 
					
						
							| 
									
										
										
										
											2012-03-17 22:31:57 +00:00
										 |  |  | 		self->cb_user         = cb_user; | 
					
						
							|  |  |  | 		self->cb_type         = cb_type; | 
					
						
							|  |  |  | 		self->cb_subtype      = cb_subtype; | 
					
						
							| 
									
										
										
										
											2011-03-03 06:01:31 +00:00
										 |  |  | 		PyObject_GC_Track(self); | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (PyObject *)self; | 
					
						
							|  |  |  | } |