2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
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
|
|
|
*/
|
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2009-06-17 20:33:34 +00:00
|
|
|
|
|
|
|
|
extern PyTypeObject matrix_Type;
|
2011-12-24 07:03:19 +00:00
|
|
|
extern PyTypeObject matrix_access_Type;
|
2017-11-29 16:09:46 +11:00
|
|
|
|
2020-02-20 10:28:15 +01:00
|
|
|
typedef unsigned short ushort;
|
|
|
|
|
|
2017-11-29 16:09:46 +11:00
|
|
|
#define MatrixObject_Check(v) PyObject_TypeCheck((v), &matrix_Type)
|
|
|
|
|
#define MatrixObject_CheckExact(v) (Py_TYPE(v) == &matrix_Type)
|
|
|
|
|
|
2010-04-16 08:17:13 +00:00
|
|
|
#define MATRIX_MAX_DIM 4
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2011-12-19 05:23:52 +00:00
|
|
|
/* matrix[row][col] == MATRIX_ITEM_INDEX(matrix, row, col) */
|
2011-12-19 03:12:10 +00:00
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-12-20 05:48:35 +00:00
|
|
|
# define MATRIX_ITEM_ASSERT(_mat, _row, _col) \
|
2022-03-28 11:06:01 +11:00
|
|
|
(BLI_assert(_row < (_mat)->row_num && _col < (_mat)->col_num))
|
2011-12-19 03:12:10 +00:00
|
|
|
#else
|
2011-12-19 05:23:52 +00:00
|
|
|
# define MATRIX_ITEM_ASSERT(_mat, _row, _col) (void)0
|
2011-12-19 03:12:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
2016-06-01 00:19:01 +10:00
|
|
|
#define MATRIX_ITEM_INDEX_NUMROW(_totrow, _row, _col) (((_totrow) * (_col)) + (_row))
|
2011-12-20 05:48:35 +00:00
|
|
|
#define MATRIX_ITEM_INDEX(_mat, _row, _col) \
|
2022-03-28 11:06:01 +11:00
|
|
|
(MATRIX_ITEM_ASSERT(_mat, _row, _col), (((_mat)->row_num * (_col)) + (_row)))
|
2011-12-20 04:11:23 +00:00
|
|
|
#define MATRIX_ITEM_PTR(_mat, _row, _col) ((_mat)->matrix + MATRIX_ITEM_INDEX(_mat, _row, _col))
|
|
|
|
|
#define MATRIX_ITEM(_mat, _row, _col) ((_mat)->matrix[MATRIX_ITEM_INDEX(_mat, _row, _col)])
|
2011-12-19 03:12:10 +00:00
|
|
|
|
2011-12-20 05:48:35 +00:00
|
|
|
#define MATRIX_COL_INDEX(_mat, _col) (MATRIX_ITEM_INDEX(_mat, 0, _col))
|
|
|
|
|
#define MATRIX_COL_PTR(_mat, _col) ((_mat)->matrix + MATRIX_COL_INDEX(_mat, _col))
|
2011-12-19 03:12:10 +00:00
|
|
|
|
2010-04-16 08:17:13 +00:00
|
|
|
typedef struct {
|
2011-12-20 04:11:23 +00:00
|
|
|
BASE_MATH_MEMBERS(matrix);
|
2022-03-28 11:06:01 +11:00
|
|
|
ushort col_num;
|
|
|
|
|
ushort row_num;
|
2009-06-17 20:33:34 +00:00
|
|
|
} MatrixObject;
|
|
|
|
|
|
2011-12-19 05:23:52 +00:00
|
|
|
/* struct data contains a pointer to the actual data that the
|
|
|
|
|
* object uses. It can use either PyMem allocated data (which will
|
|
|
|
|
* be stored in py_data) or be a wrapper for data allocated through
|
|
|
|
|
* blender (stored in blend_data). This is an either/or struct not both */
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2011-12-19 05:23:52 +00:00
|
|
|
/* prototypes */
|
2015-01-04 17:03:54 +11:00
|
|
|
PyObject *Matrix_CreatePyObject(const float *mat,
|
2022-03-28 11:06:01 +11:00
|
|
|
ushort col_num,
|
|
|
|
|
ushort row_num,
|
2015-01-04 17:03:54 +11:00
|
|
|
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
|
PyObject *Matrix_CreatePyObject_wrap(float *mat,
|
2022-03-28 11:06:01 +11:00
|
|
|
ushort col_num,
|
|
|
|
|
ushort row_num,
|
2015-01-04 17:03:54 +11:00
|
|
|
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
|
|
|
|
|
ATTR_NONNULL(1);
|
|
|
|
|
PyObject *Matrix_CreatePyObject_cb(PyObject *user,
|
2022-03-28 11:06:01 +11:00
|
|
|
unsigned short col_num,
|
|
|
|
|
unsigned short row_num,
|
2015-01-04 17:03:54 +11:00
|
|
|
unsigned char cb_type,
|
|
|
|
|
unsigned char cb_subtype) ATTR_WARN_UNUSED_RESULT;
|
2009-06-23 13:34:45 +00:00
|
|
|
|
2021-12-02 17:24:04 +11:00
|
|
|
/**
|
|
|
|
|
* \param mat: Initialized matrix value to use in-place, allocated with #PyMem_Malloc
|
|
|
|
|
*/
|
2020-02-20 15:09:44 +11:00
|
|
|
PyObject *Matrix_CreatePyObject_alloc(float *mat,
|
2022-03-28 11:06:01 +11:00
|
|
|
ushort col_num,
|
|
|
|
|
ushort row_num,
|
2020-02-20 15:09:44 +11:00
|
|
|
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
|
|
2017-08-19 21:36:50 +10:00
|
|
|
/* PyArg_ParseTuple's "O&" formatting helpers. */
|
|
|
|
|
int Matrix_ParseAny(PyObject *o, void *p);
|
2020-02-20 13:57:32 +11:00
|
|
|
int Matrix_Parse2x2(PyObject *o, void *p);
|
2017-08-19 21:36:50 +10:00
|
|
|
int Matrix_Parse3x3(PyObject *o, void *p);
|
|
|
|
|
int Matrix_Parse4x4(PyObject *o, void *p);
|
|
|
|
|
|
2012-03-17 10:46:02 +00:00
|
|
|
extern unsigned char mathutils_matrix_row_cb_index; /* default */
|
|
|
|
|
extern unsigned char mathutils_matrix_col_cb_index;
|
|
|
|
|
extern unsigned char mathutils_matrix_translation_cb_index;
|
2011-12-26 00:05:41 +00:00
|
|
|
|
2011-12-24 06:13:58 +00:00
|
|
|
extern struct Mathutils_Callback mathutils_matrix_row_cb; /* default */
|
|
|
|
|
extern struct Mathutils_Callback mathutils_matrix_col_cb;
|
2011-12-26 00:05:41 +00:00
|
|
|
extern struct Mathutils_Callback mathutils_matrix_translation_cb;
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2011-02-05 09:57:02 +00:00
|
|
|
void matrix_as_3x3(float mat[3][3], MatrixObject *self);
|