| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /* 
 | 
					
						
							| 
									
										
										
										
											2009-06-23 00:09:26 +00:00
										 |  |  |  * $Id$ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This is a new part of Blender. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Joseph Gilbert, Campbell Barton | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												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
										 |  |  | /* Note: Changes to Mathutils since 2.4x
 | 
					
						
							|  |  |  |  * use radians rather then degrees | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |  * - Mathutils.Vector/Euler/Quaternion(), now only take single sequence arguments. | 
					
						
							| 
									
										
										
											
												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
										 |  |  |  * - 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-08-02 00:08:01 +00:00
										 |  |  |  * - Quaternion * Quaternion --> cross product (not dot product) | 
					
						
							| 
									
										
										
										
											2010-09-29 08:07:58 +00:00
										 |  |  |  * - Euler.rotate(angle, axis) --> Euler.rotate_axis(axis, angle) | 
					
						
							| 
									
										
										
											
												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
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2010-08-11 16:40:36 +00:00
										 |  |  |  * moved into class functions. | 
					
						
							|  |  |  |  * - Mathutils.RotationMatrix -> mathutils.Matrix.Rotation | 
					
						
							|  |  |  |  * - Mathutils.ScaleMatrix -> mathutils.Matrix.Scale | 
					
						
							|  |  |  |  * - Mathutils.ShearMatrix -> mathutils.Matrix.Shear | 
					
						
							|  |  |  |  * - Mathutils.TranslationMatrix -> mathutils.Matrix.Translation | 
					
						
							|  |  |  |  * - Mathutils.OrthoProjectionMatrix -> mathutils.Matrix.OrthoProjection | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
											
												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
										 |  |  |  * Moved to Geometry module: Intersect, TriangleArea, TriangleNormal, QuadNormal, LineIntersect | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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"
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-13 23:25:08 +00:00
										 |  |  | #include "BKE_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | //-------------------------DOC STRINGS ---------------------------
 | 
					
						
							| 
									
										
										
										
											2010-01-31 21:52:26 +00:00
										 |  |  | static char M_Mathutils_doc[] = | 
					
						
							| 
									
										
										
										
											2010-02-28 13:45:08 +00:00
										 |  |  | "This module provides access to matrices, eulers, quaternions and vectors."; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  | /* helper functionm returns length of the 'value', -1 on error */ | 
					
						
							|  |  |  | int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *value_fast= NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int i, size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* non list/tuple cases */ | 
					
						
							|  |  |  | 	if(!(value_fast=PySequence_Fast(value, error_prefix))) { | 
					
						
							|  |  |  | 		/* PySequence_Fast sets the error */ | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	size= PySequence_Fast_GET_SIZE(value_fast); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(size > array_max || size < array_min) { | 
					
						
							|  |  |  | 		if (array_max == array_min)	PyErr_Format(PyExc_ValueError, "%.200s: sequence size is %d, expected %d", error_prefix, size, array_max); | 
					
						
							|  |  |  | 		else						PyErr_Format(PyExc_ValueError, "%.200s: sequence size is %d, expected [%d - %d]", error_prefix, size, array_min, array_max); | 
					
						
							|  |  |  | 		Py_DECREF(value_fast); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	i= size; | 
					
						
							|  |  |  | 	do { | 
					
						
							|  |  |  | 		i--; | 
					
						
							|  |  |  | 		if(((array[i]= PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i))) == -1.0) && PyErr_Occurred()) { | 
					
						
							|  |  |  | 			PyErr_Format(PyExc_ValueError, "%.200s: sequence index %d is not a float", error_prefix, i); | 
					
						
							|  |  |  | 			Py_DECREF(value_fast); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} while(i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Py_XDECREF(value_fast); | 
					
						
							|  |  |  | 	return size; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | //----------------------------------MATRIX FUNCTIONS--------------------
 | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 
 | 
					
						
							|  |  |  | /* Utility functions */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-28 19:27:06 +00:00
										 |  |  | // LomontRRDCompare4, Ever Faster Float Comparisons by Randy Dillon
 | 
					
						
							|  |  |  | #define SIGNMASK(i) (-(int)(((unsigned int)(i))>>31))
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int EXPP_FloatsAreEqual(float af, float bf, int maxDiff) | 
					
						
							|  |  |  | {	// solid, fast routine across all platforms
 | 
					
						
							|  |  |  | 	// with constant time behavior
 | 
					
						
							|  |  |  | 	int ai = *(int *)(&af); | 
					
						
							|  |  |  | 	int bi = *(int *)(&bf); | 
					
						
							|  |  |  | 	int test = SIGNMASK(ai^bi); | 
					
						
							|  |  |  | 	int diff, v1, v2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	assert((0 == test) || (0xFFFFFFFF == test)); | 
					
						
							|  |  |  | 	diff = (ai ^ (test & 0x7fffffff)) - bi; | 
					
						
							|  |  |  | 	v1 = maxDiff + diff; | 
					
						
							|  |  |  | 	v2 = maxDiff - diff; | 
					
						
							|  |  |  | 	return (v1|v2) >= 0; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-02-28 19:27:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*---------------------- EXPP_VectorsAreEqual -------------------------
 | 
					
						
							|  |  |  |   Builds on EXPP_FloatsAreEqual to test vectors */ | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 	int x; | 
					
						
							|  |  |  | 	for (x=0; x< size; x++){ | 
					
						
							|  |  |  | 		if (EXPP_FloatsAreEqual(vecA[x], vecB[x], floatSteps) == 0) | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | /* Mathutils Callbacks */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* for mathutils internal use only, eventually should re-alloc but to start with we only have a few users */ | 
					
						
							|  |  |  | Mathutils_Callback *mathutils_callbacks[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int Mathutils_RegisterCallback(Mathutils_Callback *cb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* find the first free slot */ | 
					
						
							|  |  |  | 	for(i= 0; mathutils_callbacks[i]; i++) { | 
					
						
							| 
									
										
										
										
											2010-07-17 18:08:14 +00:00
										 |  |  | 		if(mathutils_callbacks[i]==cb) /* already registered? */ | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | 			return i; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	mathutils_callbacks[i] = cb; | 
					
						
							|  |  |  | 	return i; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | /* use macros to check for NULL */ | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | int _BaseMathObject_ReadCallback(BaseMathObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Mathutils_Callback *cb= mathutils_callbacks[self->cb_type]; | 
					
						
							| 
									
										
										
										
											2010-04-27 19:21:36 +00:00
										 |  |  | 	if(cb->get(self, self->cb_subtype)) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-14 01:41:43 +00:00
										 |  |  | 	if(!PyErr_Occurred()) | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | int _BaseMathObject_WriteCallback(BaseMathObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Mathutils_Callback *cb= mathutils_callbacks[self->cb_type]; | 
					
						
							| 
									
										
										
										
											2010-04-27 19:21:36 +00:00
										 |  |  | 	if(cb->set(self, self->cb_subtype)) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-14 01:41:43 +00:00
										 |  |  | 	if(!PyErr_Occurred()) | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Mathutils_Callback *cb= mathutils_callbacks[self->cb_type]; | 
					
						
							| 
									
										
										
										
											2010-04-27 19:21:36 +00:00
										 |  |  | 	if(cb->get_index(self, self->cb_subtype, index)) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-14 01:41:43 +00:00
										 |  |  | 	if(!PyErr_Occurred()) | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Mathutils_Callback *cb= mathutils_callbacks[self->cb_type]; | 
					
						
							| 
									
										
										
										
											2010-04-27 19:21:36 +00:00
										 |  |  | 	if(cb->set_index(self, self->cb_subtype, index)) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-14 01:41:43 +00:00
										 |  |  | 	if(!PyErr_Occurred()) | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | /* BaseMathObject generic functions for all mathutils types */ | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  | char BaseMathObject_Owner_doc[] = "The item this is wrapping or None  (readonly)."; | 
					
						
							| 
									
										
										
										
											2010-10-16 02:40:31 +00:00
										 |  |  | PyObject *BaseMathObject_getOwner(BaseMathObject *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 	PyObject *ret= self->cb_user ? self->cb_user : Py_None; | 
					
						
							|  |  |  | 	Py_INCREF(ret); | 
					
						
							|  |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-08 16:22:29 +00:00
										 |  |  | char BaseMathObject_Wrapped_doc[] = "True when this object wraps external data (readonly).\n\n:type: boolean"; | 
					
						
							| 
									
										
										
										
											2010-10-16 02:40:31 +00:00
										 |  |  | PyObject *BaseMathObject_getWrapped(BaseMathObject *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-28 13:27:06 +00:00
										 |  |  | 	return PyBool_FromLong((self->wrapped == Py_WRAP) ? 1:0); | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void BaseMathObject_dealloc(BaseMathObject * self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* only free non wrapped */ | 
					
						
							|  |  |  | 	if(self->wrapped != Py_WRAP) | 
					
						
							|  |  |  | 		PyMem_Free(self->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Py_XDECREF(self->cb_user); | 
					
						
							| 
									
										
										
										
											2009-06-30 00:42:17 +00:00
										 |  |  | 	Py_TYPE(self)->tp_free(self); // PyObject_DEL(self); // breaks subtypes
 | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +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
										 |  |  | /*----------------------------MODULE INIT-------------------------*/ | 
					
						
							|  |  |  | struct PyMethodDef M_Mathutils_methods[] = { | 
					
						
							|  |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct PyModuleDef M_Mathutils_module_def = { | 
					
						
							|  |  |  | 	PyModuleDef_HEAD_INIT, | 
					
						
							| 
									
										
										
										
											2010-04-11 14:22:27 +00:00
										 |  |  | 	"mathutils",  /* m_name */ | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 	M_Mathutils_doc,  /* m_doc */ | 
					
						
							|  |  |  | 	0,  /* m_size */ | 
					
						
							|  |  |  | 	M_Mathutils_methods,  /* m_methods */ | 
					
						
							|  |  |  | 	0,  /* m_reload */ | 
					
						
							|  |  |  | 	0,  /* m_traverse */ | 
					
						
							|  |  |  | 	0,  /* m_clear */ | 
					
						
							|  |  |  | 	0,  /* m_free */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-29 22:59:39 +00:00
										 |  |  | PyMODINIT_FUNC BPyInit_mathutils(void) | 
					
						
							| 
									
										
										
											
												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
										 |  |  | { | 
					
						
							|  |  |  | 	PyObject *submodule; | 
					
						
							| 
									
										
										
										
											2010-10-31 13:17:39 +00:00
										 |  |  | 	PyObject *item; | 
					
						
							| 
									
										
										
										
											2010-10-29 22:59:39 +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
										 |  |  | 	if( PyType_Ready( &vector_Type ) < 0 ) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	if( PyType_Ready( &matrix_Type ) < 0 ) | 
					
						
							|  |  |  | 		return NULL;	 | 
					
						
							|  |  |  | 	if( PyType_Ready( &euler_Type ) < 0 ) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	if( PyType_Ready( &quaternion_Type ) < 0 ) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2010-04-11 14:22:27 +00:00
										 |  |  | 	if( PyType_Ready( &color_Type ) < 0 ) | 
					
						
							|  |  |  | 		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
										 |  |  | 	submodule = PyModule_Create(&M_Mathutils_module_def); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* each type has its own new() function */ | 
					
						
							|  |  |  | 	PyModule_AddObject( submodule, "Vector",		(PyObject *)&vector_Type ); | 
					
						
							|  |  |  | 	PyModule_AddObject( submodule, "Matrix",		(PyObject *)&matrix_Type ); | 
					
						
							|  |  |  | 	PyModule_AddObject( submodule, "Euler",			(PyObject *)&euler_Type ); | 
					
						
							|  |  |  | 	PyModule_AddObject( submodule, "Quaternion",	(PyObject *)&quaternion_Type ); | 
					
						
							| 
									
										
										
										
											2010-04-11 14:22:27 +00:00
										 |  |  | 	PyModule_AddObject( submodule, "Color",			(PyObject *)&color_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
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-10-25 22:44:01 +00:00
										 |  |  | 	/* submodule */ | 
					
						
							| 
									
										
										
										
											2010-10-31 13:17:39 +00:00
										 |  |  | 	PyModule_AddObject( submodule, "geometry",		(item=BPyInit_mathutils_geometry())); | 
					
						
							|  |  |  | 	/* XXX, python doesnt do imports with this usefully yet
 | 
					
						
							|  |  |  | 	 * 'from mathutils.geometry import PolyFill' | 
					
						
							|  |  |  | 	 * ...fails without this. */ | 
					
						
							|  |  |  | 	PyDict_SetItemString(PyThreadState_GET()->interp->modules, "mathutils.geometry", item); | 
					
						
							|  |  |  | 	Py_INCREF(item); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												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
										 |  |  | 	mathutils_matrix_vector_cb_index= Mathutils_RegisterCallback(&mathutils_matrix_vector_cb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-29 22:59:39 +00:00
										 |  |  | 	return submodule; | 
					
						
							| 
									
										
										
											
												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
										 |  |  | } |