Blender V2.61 - r43446

mathutils.h

Go to the documentation of this file.
00001 /* 
00002  *
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * This is a new part of Blender.
00023  *
00024  * Contributor(s): Joseph Gilbert
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00033 //Include this file for access to vector, quat, matrix, euler, etc...
00034 
00035 #ifndef MATHUTILS_H
00036 #define MATHUTILS_H
00037 
00038 /* Can cast different mathutils types to this, use for generic funcs */
00039 
00040 struct DynStr;
00041 
00042 extern char BaseMathObject_is_wrapped_doc[];
00043 extern char BaseMathObject_owner_doc[];
00044 
00045 #define BASE_MATH_MEMBERS(_data)                                                                                 \
00046     PyObject_VAR_HEAD                                                                                            \
00047     float *_data;               /* array of data (alias), wrapped status depends on wrapped status */            \
00048     PyObject *cb_user;          /* if this vector references another object, otherwise NULL,                     \
00049                                  * *Note* this owns its reference */                                             \
00050     unsigned char cb_type;      /* which user funcs do we adhere to, RNA, GameObject, etc */                     \
00051     unsigned char cb_subtype;   /* subtype: location, rotation...                                                \
00052                                  * to avoid defining many new functions for every attribute of the same type */  \
00053     unsigned char wrapped       /* wrapped data type? */                                                         \
00054 
00055 typedef struct {
00056     BASE_MATH_MEMBERS(data);
00057 } BaseMathObject;
00058 
00059 /* types */
00060 #include "mathutils_Vector.h"
00061 #include "mathutils_Matrix.h"
00062 #include "mathutils_Quaternion.h"
00063 #include "mathutils_Euler.h"
00064 #include "mathutils_Color.h"
00065 
00066 /* utility submodules */
00067 #include "mathutils_geometry.h"
00068 #include "mathutils_noise.h"
00069 
00070 PyObject *BaseMathObject_owner_get( BaseMathObject * self, void * );
00071 PyObject *BaseMathObject_is_wrapped_get( BaseMathObject *self, void * );
00072 
00073 int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg);
00074 int BaseMathObject_clear(BaseMathObject *self);
00075 void BaseMathObject_dealloc(BaseMathObject * self);
00076 
00077 PyMODINIT_FUNC PyInit_mathutils(void);
00078 
00079 int EXPP_FloatsAreEqual(float A, float B, int floatSteps);
00080 int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);
00081 
00082 #define Py_NEW  1
00083 #define Py_WRAP 2
00084 
00085 typedef struct Mathutils_Callback Mathutils_Callback;
00086 
00087 typedef int (*BaseMathCheckFunc)(BaseMathObject *);               /* checks the user is still valid */
00088 typedef int (*BaseMathGetFunc)(BaseMathObject *, int);            /* gets the vector from the user */
00089 typedef int (*BaseMathSetFunc)(BaseMathObject *, int);            /* sets the users vector values once its modified */
00090 typedef int (*BaseMathGetIndexFunc)(BaseMathObject *, int, int);  /* same as above but only for an index */
00091 typedef int (*BaseMathSetIndexFunc)(BaseMathObject *, int, int);  /* same as above but only for an index */
00092 
00093 struct Mathutils_Callback {
00094     BaseMathCheckFunc       check;
00095     BaseMathGetFunc         get;
00096     BaseMathSetFunc         set;
00097     BaseMathGetIndexFunc    get_index;
00098     BaseMathSetIndexFunc    set_index;
00099 };
00100 
00101 int Mathutils_RegisterCallback(Mathutils_Callback *cb);
00102 
00103 int _BaseMathObject_ReadCallback(BaseMathObject *self);
00104 int _BaseMathObject_WriteCallback(BaseMathObject *self);
00105 int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index);
00106 int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index);
00107 
00108 /* since this is called so often avoid where possible */
00109 #define BaseMath_ReadCallback(_self) \
00110     (((_self)->cb_user ?    _BaseMathObject_ReadCallback((BaseMathObject *)_self):0))
00111 #define BaseMath_WriteCallback(_self) \
00112     (((_self)->cb_user ?_BaseMathObject_WriteCallback((BaseMathObject *)_self):0))
00113 #define BaseMath_ReadIndexCallback(_self, _index) \
00114     (((_self)->cb_user ?    _BaseMathObject_ReadIndexCallback((BaseMathObject *)_self, _index):0))
00115 #define BaseMath_WriteIndexCallback(_self, _index) \
00116     (((_self)->cb_user ?    _BaseMathObject_WriteIndexCallback((BaseMathObject *)_self, _index):0))
00117 
00118 /* utility func */
00119 int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix);
00120 int mathutils_array_parse_alloc(float **array, int array_min, PyObject *value, const char *error_prefix);
00121 int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix);
00122 
00123 int column_vector_multiplication(float rvec[4], VectorObject *vec, MatrixObject *mat);
00124 
00125 /* dynstr as python string utility funcions */
00126 PyObject *mathutils_dynstr_to_py(struct DynStr *ds);
00127 
00128 #endif /* MATHUTILS_H */