static int mathutils_matrix_vector_check(MatrixObject *self)
{
- return Matrix_ReadCallback(self);
+ return BaseMath_ReadCallback(self);
}
static int mathutils_matrix_vector_get(MatrixObject *self, int subtype, float *vec_from)
{
int i;
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return 0;
for(i=0; i<self->colSize; i++)
static int mathutils_matrix_vector_set(MatrixObject *self, int subtype, float *vec_to)
{
int i;
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return 0;
for(i=0; i<self->colSize; i++)
self->matrix[subtype][i]= vec_to[i];
- Matrix_WriteCallback(self);
+ BaseMath_WriteCallback(self);
return 1;
}
static int mathutils_matrix_vector_get_index(MatrixObject *self, int subtype, float *vec_from, int index)
{
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return 0;
vec_from[index]= self->matrix[subtype][index];
static int mathutils_matrix_vector_set_index(MatrixObject *self, int subtype, float *vec_to, int index)
{
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return 0;
self->matrix[subtype][index]= vec_to[index];
- Matrix_WriteCallback(self);
+ BaseMath_WriteCallback(self);
return 1;
}
argObject = PyTuple_GET_ITEM(args, 0);
if(MatrixObject_Check(argObject)){
mat = (MatrixObject*)argObject;
- if(!Matrix_ReadCallback(mat))
+ if(!BaseMath_ReadCallback(mat))
return NULL;
argSize = mat->rowSize; //rows
{
float quat[4];
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
/*must be 3-4 cols, 3-4 rows, square matrix*/
EulerObject *eul_compat = NULL;
int x;
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
if(!PyArg_ParseTuple(args, "|O!:toEuler", &euler_Type, &eul_compat))
return NULL;
if(eul_compat) {
+ if(!BaseMath_ReadCallback(eul_compat))
+ return NULL;
+
for(x = 0; x < 3; x++) {
eul_compatf[x] = eul_compat->eul[x] * ((float)Py_PI / 180);
}
{
float vec[4];
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
if(self->colSize < 3 || self->rowSize < 4){
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
if(self->colSize < 3 || self->rowSize < 3){
float scale[3], rot[3];
float mat[3][3], imat[3][3], tmat[3][3];
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
/*must be 3-4 cols, 3-4 rows, square matrix*/
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
if(self->rowSize != self->colSize){
return NULL;
}
- Matrix_WriteCallback(self);
+ BaseMath_WriteCallback(self);
Py_INCREF(self);
return (PyObject *)self;
}
{
float det = 0.0f;
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
if(self->rowSize != self->colSize){
{
float t = 0.0f;
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
if(self->rowSize != self->colSize){
Mat4Transp((float (*)[4])*self->matrix);
}
- Matrix_WriteCallback(self);
+ BaseMath_WriteCallback(self);
Py_INCREF(self);
return (PyObject *)self;
}
}
}
- if(!Matrix_WriteCallback(self))
+ if(!BaseMath_WriteCallback(self))
return NULL;
Py_INCREF(self);
/*---------------------------Matrix.identity(() ------------------*/
PyObject *Matrix_Identity(MatrixObject * self)
{
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
if(self->rowSize != self->colSize){
Mat4One((float (*)[4]) *self->matrix);
}
- if(!Matrix_WriteCallback(self))
+ if(!BaseMath_WriteCallback(self))
return NULL;
Py_INCREF(self);
/*---------------------------Matrix.inverted() ------------------*/
PyObject *Matrix_copy(MatrixObject * self)
{
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
return (PyObject*)(MatrixObject*)newMatrixObject((float (*))*self->matrix, self->rowSize, self->colSize, Py_NEW);
}
-/*----------------------------dealloc()(internal) ----------------*/
-/*free the py_object*/
-static void Matrix_dealloc(MatrixObject * self)
-{
- PyMem_Free(self->matrix);
- /*only free py_data*/
- if(self->wrapped==Py_WRAP)
- PyMem_Free(self->contigPtr);
-
- Py_XDECREF(self->cb_user);
- PyObject_DEL(self);
-}
-
/*----------------------------print object (internal)-------------*/
/*print the object to screen*/
static PyObject *Matrix_repr(MatrixObject * self)
int x, y;
char buffer[48], str[1024];
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
BLI_strncpy(str,"",1024);
matA = (MatrixObject*)objectA;
matB = (MatrixObject*)objectB;
- if(!Matrix_ReadCallback(matA) || !Matrix_ReadCallback(matB))
+ if(!BaseMath_ReadCallback(matA) || !BaseMath_ReadCallback(matB))
return NULL;
if (matA->colSize != matB->colSize || matA->rowSize != matB->rowSize){
the wrapped vector gives direct access to the matrix data*/
static PyObject *Matrix_item(MatrixObject * self, int i)
{
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
if(i < 0 || i >= self->rowSize) {
float vec[4];
PyObject *m, *f;
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return -1;
if(i >= self->rowSize || i < 0){
self->matrix[i][y] = vec[y];
}
- Matrix_WriteCallback(self);
+ BaseMath_WriteCallback(self);
return 0;
}else{
PyErr_SetString(PyExc_TypeError, "matrix[attribute] = x: expects a sequence of column size\n");
PyObject *list = NULL;
int count;
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
CLAMP(begin, 0, self->rowSize);
PyObject *subseq;
PyObject *m;
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return -1;
CLAMP(begin, 0, self->rowSize);
self->matrix[begin + (int)floor(x / self->colSize)][x % self->colSize] = mat[x];
}
- Matrix_WriteCallback(self);
+ BaseMath_WriteCallback(self);
return 0;
}else{
PyErr_SetString(PyExc_TypeError, "matrix[begin:end] = []: illegal argument type for built-in operation\n");
return NULL;
}
- if(!Matrix_ReadCallback(mat1) || !Matrix_ReadCallback(mat2))
+ if(!BaseMath_ReadCallback(mat1) || !BaseMath_ReadCallback(mat2))
return NULL;
if(mat1->rowSize != mat2->rowSize || mat1->colSize != mat2->colSize){
return NULL;
}
- if(!Matrix_ReadCallback(mat1) || !Matrix_ReadCallback(mat2))
+ if(!BaseMath_ReadCallback(mat1) || !BaseMath_ReadCallback(mat2))
return NULL;
if(mat1->rowSize != mat2->rowSize || mat1->colSize != mat2->colSize){
if(MatrixObject_Check(m1)) {
mat1 = (MatrixObject*)m1;
- if(!Matrix_ReadCallback(mat1))
+ if(!BaseMath_ReadCallback(mat1))
return NULL;
}
if(MatrixObject_Check(m2)) {
mat2 = (MatrixObject*)m2;
- if(!Matrix_ReadCallback(mat2))
+ if(!BaseMath_ReadCallback(mat2))
return NULL;
}
}
static PyObject* Matrix_inv(MatrixObject *self)
{
- if(!Matrix_ReadCallback(self))
+ if(!BaseMath_ReadCallback(self))
return NULL;
return Matrix_Invert(self);
return PyLong_FromLong((long) self->colSize);
}
-static PyObject *Matrix_getOwner( MatrixObject * self, void *type )
-{
- if(self->cb_user==NULL) {
- Py_RETURN_NONE;
- }
- else {
- Py_INCREF(self->cb_user);
- return self->cb_user;
- }
-}
-
-static PyObject *Matrix_getWrapped( MatrixObject * self, void *type )
-{
- if (self->wrapped == Py_WRAP)
- Py_RETURN_TRUE;
- else
- Py_RETURN_FALSE;
-}
-
/*****************************************************************************/
/* Python attributes get/set structure: */
/*****************************************************************************/
static PyGetSetDef Matrix_getseters[] = {
{"rowSize", (getter)Matrix_getRowSize, (setter)NULL, "", NULL},
{"colSize", (getter)Matrix_getColSize, (setter)NULL, "", NULL},
- {"wrapped", (getter)Matrix_getWrapped, (setter)NULL, "", NULL},
- {"__owner__",(getter)Matrix_getOwner, (setter)NULL, "Read only owner for vectors that depend on another object", NULL},
+ {"wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, "", NULL},
+ {"__owner__",(getter)BaseMathObject_getOwner, (setter)NULL, "",
+ NULL},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};
"matrix", /*tp_name*/
sizeof(MatrixObject), /*tp_basicsize*/
0, /*tp_itemsize*/
- (destructor)Matrix_dealloc, /*tp_dealloc*/
+ (destructor)BaseMathObject_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
double dot = 0.0f;
int x, y, z = 0;
- if(!Matrix_ReadCallback(mat) || !Vector_ReadCallback(vec))
+ if(!BaseMath_ReadCallback(mat) || !BaseMath_ReadCallback(vec))
return NULL;
if(mat->rowSize != vec->size){