2012-04-30 14:24:11 +00:00
|
|
|
/*
|
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
|
|
|
*
|
|
|
|
* Contributor(s): Joseph Gilbert
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2011-10-23 17:52:20 +00:00
|
|
|
*/
|
2011-02-27 20:10:08 +00:00
|
|
|
|
2012-04-30 14:24:11 +00:00
|
|
|
#ifndef __MATHUTILS_H__
|
|
|
|
#define __MATHUTILS_H__
|
|
|
|
|
2011-11-05 01:48:10 +00:00
|
|
|
/** \file blender/python/mathutils/mathutils.h
|
|
|
|
* \ingroup pymathutils
|
2011-02-27 20:10:08 +00:00
|
|
|
*/
|
|
|
|
|
2009-06-25 10:11:37 +00:00
|
|
|
/* Can cast different mathutils types to this, use for generic funcs */
|
|
|
|
|
2015-01-04 17:03:54 +11:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
2011-12-20 03:37:55 +00:00
|
|
|
struct DynStr;
|
|
|
|
|
2011-12-24 04:58:01 +00:00
|
|
|
extern char BaseMathObject_is_wrapped_doc[];
|
2015-02-15 11:26:31 +11:00
|
|
|
extern char BaseMathObject_is_frozen_doc[];
|
2011-12-24 04:58:01 +00:00
|
|
|
extern char BaseMathObject_owner_doc[];
|
2010-01-27 21:33:39 +00:00
|
|
|
|
2015-01-04 17:03:54 +11:00
|
|
|
#define BASE_MATH_NEW(struct_name, root_type, base_type) \
|
|
|
|
(struct_name *)((base_type ? (base_type)->tp_alloc(base_type, 0) : _PyObject_GC_New(&(root_type))));
|
|
|
|
|
|
|
|
|
|
|
|
/* BaseMathObject.flag */
|
|
|
|
enum {
|
|
|
|
BASE_MATH_FLAG_IS_WRAP = (1 << 0),
|
2015-02-15 11:26:31 +11:00
|
|
|
BASE_MATH_FLAG_IS_FROZEN = (1 << 1),
|
2015-01-04 17:03:54 +11:00
|
|
|
};
|
|
|
|
#define BASE_MATH_FLAG_DEFAULT 0
|
|
|
|
|
2011-11-29 20:22:35 +00:00
|
|
|
#define BASE_MATH_MEMBERS(_data) \
|
|
|
|
PyObject_VAR_HEAD \
|
|
|
|
float *_data; /* array of data (alias), wrapped status depends on wrapped status */ \
|
|
|
|
PyObject *cb_user; /* if this vector references another object, otherwise NULL, \
|
|
|
|
* *Note* this owns its reference */ \
|
|
|
|
unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */ \
|
|
|
|
unsigned char cb_subtype; /* subtype: location, rotation... \
|
|
|
|
* to avoid defining many new functions for every attribute of the same type */ \
|
2015-01-04 17:03:54 +11:00
|
|
|
unsigned char flag /* wrapped data type? */ \
|
2010-04-16 08:17:13 +00:00
|
|
|
|
2009-06-25 10:11:37 +00:00
|
|
|
typedef struct {
|
2011-11-29 20:22:35 +00:00
|
|
|
BASE_MATH_MEMBERS(data);
|
2009-06-25 10:11:37 +00:00
|
|
|
} BaseMathObject;
|
|
|
|
|
2011-11-29 10:28:52 +00:00
|
|
|
/* types */
|
2011-02-14 04:15:25 +00:00
|
|
|
#include "mathutils_Vector.h"
|
|
|
|
#include "mathutils_Matrix.h"
|
|
|
|
#include "mathutils_Quaternion.h"
|
|
|
|
#include "mathutils_Euler.h"
|
|
|
|
#include "mathutils_Color.h"
|
2011-11-29 10:28:52 +00:00
|
|
|
|
2013-03-26 07:29:01 +00:00
|
|
|
PyObject *BaseMathObject_owner_get(BaseMathObject *self, void *);
|
2012-03-16 21:39:56 +00:00
|
|
|
PyObject *BaseMathObject_is_wrapped_get(BaseMathObject *self, void *);
|
2015-02-15 11:26:31 +11:00
|
|
|
PyObject *BaseMathObject_is_frozen_get(BaseMathObject *self, void *);
|
|
|
|
|
|
|
|
extern char BaseMathObject_freeze_doc[];
|
|
|
|
PyObject *BaseMathObject_freeze(BaseMathObject *self);
|
2011-02-24 04:58:51 +00:00
|
|
|
|
|
|
|
int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg);
|
|
|
|
int BaseMathObject_clear(BaseMathObject *self);
|
2013-03-26 07:29:01 +00:00
|
|
|
void BaseMathObject_dealloc(BaseMathObject *self);
|
2009-06-25 10:11:37 +00:00
|
|
|
|
2011-07-15 04:01:47 +00:00
|
|
|
PyMODINIT_FUNC PyInit_mathutils(void);
|
2009-06-17 20:33:34 +00:00
|
|
|
|
|
|
|
int EXPP_FloatsAreEqual(float A, float B, int floatSteps);
|
2012-12-02 04:51:15 +00:00
|
|
|
int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps);
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2009-06-22 04:26:48 +00:00
|
|
|
typedef struct Mathutils_Callback Mathutils_Callback;
|
2009-07-10 18:09:53 +00:00
|
|
|
|
2011-11-29 20:22:35 +00:00
|
|
|
typedef int (*BaseMathCheckFunc)(BaseMathObject *); /* checks the user is still valid */
|
|
|
|
typedef int (*BaseMathGetFunc)(BaseMathObject *, int); /* gets the vector from the user */
|
|
|
|
typedef int (*BaseMathSetFunc)(BaseMathObject *, int); /* sets the users vector values once its modified */
|
|
|
|
typedef int (*BaseMathGetIndexFunc)(BaseMathObject *, int, int); /* same as above but only for an index */
|
|
|
|
typedef int (*BaseMathSetIndexFunc)(BaseMathObject *, int, int); /* same as above but only for an index */
|
2009-07-10 18:09:53 +00:00
|
|
|
|
2009-06-22 04:26:48 +00:00
|
|
|
struct Mathutils_Callback {
|
2010-04-26 21:04:42 +00:00
|
|
|
BaseMathCheckFunc check;
|
|
|
|
BaseMathGetFunc get;
|
|
|
|
BaseMathSetFunc set;
|
|
|
|
BaseMathGetIndexFunc get_index;
|
|
|
|
BaseMathSetIndexFunc set_index;
|
2009-06-22 04:26:48 +00:00
|
|
|
};
|
|
|
|
|
2012-03-17 10:46:02 +00:00
|
|
|
unsigned char Mathutils_RegisterCallback(Mathutils_Callback *cb);
|
2009-06-22 04:26:48 +00:00
|
|
|
|
2009-06-25 10:11:37 +00:00
|
|
|
int _BaseMathObject_ReadCallback(BaseMathObject *self);
|
|
|
|
int _BaseMathObject_WriteCallback(BaseMathObject *self);
|
|
|
|
int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index);
|
|
|
|
int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index);
|
2009-06-23 13:34:45 +00:00
|
|
|
|
2015-02-15 11:26:31 +11:00
|
|
|
void _BaseMathObject_RaiseFrozenExc(const BaseMathObject *self);
|
2015-02-15 10:46:14 +11:00
|
|
|
void _BaseMathObject_RaiseNotFrozenExc(const BaseMathObject *self);
|
2015-02-15 11:26:31 +11:00
|
|
|
|
2009-06-23 13:34:45 +00:00
|
|
|
/* since this is called so often avoid where possible */
|
2011-11-29 20:22:35 +00:00
|
|
|
#define BaseMath_ReadCallback(_self) \
|
|
|
|
(((_self)->cb_user ? _BaseMathObject_ReadCallback((BaseMathObject *)_self):0))
|
|
|
|
#define BaseMath_WriteCallback(_self) \
|
|
|
|
(((_self)->cb_user ?_BaseMathObject_WriteCallback((BaseMathObject *)_self):0))
|
|
|
|
#define BaseMath_ReadIndexCallback(_self, _index) \
|
|
|
|
(((_self)->cb_user ? _BaseMathObject_ReadIndexCallback((BaseMathObject *)_self, _index):0))
|
|
|
|
#define BaseMath_WriteIndexCallback(_self, _index) \
|
|
|
|
(((_self)->cb_user ? _BaseMathObject_WriteIndexCallback((BaseMathObject *)_self, _index):0))
|
2009-06-22 04:26:48 +00:00
|
|
|
|
2015-02-15 11:26:31 +11:00
|
|
|
/* support BASE_MATH_FLAG_IS_FROZEN */
|
|
|
|
#define BaseMath_ReadCallback_ForWrite(_self) \
|
|
|
|
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
|
|
|
|
(_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : (BaseMath_ReadCallback(_self)))
|
|
|
|
|
|
|
|
#define BaseMath_ReadIndexCallback_ForWrite(_self, _index) \
|
|
|
|
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
|
|
|
|
(_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : (BaseMath_ReadIndexCallback(_self, _index)))
|
|
|
|
|
|
|
|
#define BaseMath_Prepare_ForWrite(_self) \
|
|
|
|
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
|
|
|
|
(_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : 0)
|
|
|
|
|
2015-02-15 10:46:14 +11:00
|
|
|
#define BaseMathObject_Prepare_ForHash(_self) \
|
|
|
|
(UNLIKELY(((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) == 0) ? \
|
|
|
|
(_BaseMathObject_RaiseNotFrozenExc((BaseMathObject *)_self), -1) : 0)
|
|
|
|
|
2010-04-25 19:27:59 +00:00
|
|
|
/* utility func */
|
|
|
|
int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix);
|
2011-12-18 07:27:11 +00:00
|
|
|
int mathutils_array_parse_alloc(float **array, int array_min, PyObject *value, const char *error_prefix);
|
2012-04-22 10:19:24 +00:00
|
|
|
int mathutils_array_parse_alloc_v(float **array, int array_dim, PyObject *value, const char *error_prefix);
|
2011-02-05 09:57:02 +00:00
|
|
|
int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix);
|
2010-04-25 19:27:59 +00:00
|
|
|
|
2015-02-15 10:46:14 +11:00
|
|
|
Py_hash_t mathutils_array_hash(const float *float_array, size_t array_len);
|
|
|
|
|
2014-12-30 21:50:47 +11:00
|
|
|
/* zero remaining unused elements of the array */
|
|
|
|
#define MU_ARRAY_ZERO (1 << 30)
|
|
|
|
/* ignore larger py sequences than requested (just use first elements),
|
|
|
|
* handy when using 3d vectors as 2d */
|
|
|
|
#define MU_ARRAY_SPILL (1 << 31)
|
|
|
|
|
2014-12-30 22:47:56 +11:00
|
|
|
#define MU_ARRAY_FLAGS (MU_ARRAY_ZERO | MU_ARRAY_SPILL)
|
|
|
|
|
2011-07-25 01:44:19 +00:00
|
|
|
int column_vector_multiplication(float rvec[4], VectorObject *vec, MatrixObject *mat);
|
|
|
|
|
2012-12-08 01:16:59 +00:00
|
|
|
#ifndef MATH_STANDALONE
|
2011-12-20 03:37:55 +00:00
|
|
|
/* dynstr as python string utility funcions */
|
|
|
|
PyObject *mathutils_dynstr_to_py(struct DynStr *ds);
|
2012-12-08 01:16:59 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-30 11:35:58 +00:00
|
|
|
int mathutils_deepcopy_args_check(PyObject *args);
|
2011-12-20 03:37:55 +00:00
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#endif /* __MATHUTILS_H__ */
|