* Added matrix module
* Moved the function EXPP_tuple_repr from vector.c to gen_utils.[ch] * Matrix functionality should work now in Object module. * Fixed compilation warning about implicit declaration of M_World_Init. Added the declaration to modules.h
This commit is contained in:
@@ -669,8 +669,13 @@ static PyObject *Object_getEuler (C_Object *self)
|
|||||||
|
|
||||||
static PyObject *Object_getInverseMatrix (C_Object *self)
|
static PyObject *Object_getInverseMatrix (C_Object *self)
|
||||||
{
|
{
|
||||||
return (PythonReturnErrorObject (PyExc_NotImplementedError,
|
Object * ob;
|
||||||
"getInverseMatrix: not yet implemented"));
|
float inverse[4][4];
|
||||||
|
|
||||||
|
ob = self->object->data;
|
||||||
|
Mat4Invert (inverse, ob->obmat);
|
||||||
|
|
||||||
|
return (newMatrixObject (inverse));
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *Object_getLocation (C_Object *self, PyObject *args)
|
static PyObject *Object_getLocation (C_Object *self, PyObject *args)
|
||||||
@@ -695,8 +700,11 @@ static PyObject *Object_getMaterials (C_Object *self)
|
|||||||
|
|
||||||
static PyObject *Object_getMatrix (C_Object *self)
|
static PyObject *Object_getMatrix (C_Object *self)
|
||||||
{
|
{
|
||||||
return (PythonReturnErrorObject (PyExc_NotImplementedError,
|
Object * ob;
|
||||||
"getMatrix: not yet implemented"));
|
|
||||||
|
ob = self->object->data;
|
||||||
|
|
||||||
|
return (newMatrixObject (ob->obmat));
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *Object_getParent (C_Object *self)
|
static PyObject *Object_getParent (C_Object *self)
|
||||||
@@ -1285,10 +1293,7 @@ static PyObject* ObjectGetAttr (C_Object *obj, char *name)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
if (StringEqual (name, "matrix"))
|
if (StringEqual (name, "matrix"))
|
||||||
{
|
return (Object_getMatrix (obj));
|
||||||
printf ("This is not implemented yet. (matrix)\n");
|
|
||||||
return (Py_None);
|
|
||||||
}
|
|
||||||
if (StringEqual (name, "colbits"))
|
if (StringEqual (name, "colbits"))
|
||||||
return (Py_BuildValue ("h", object->colbits));
|
return (Py_BuildValue ("h", object->colbits));
|
||||||
if (StringEqual (name, "drawType"))
|
if (StringEqual (name, "drawType"))
|
||||||
@@ -1430,13 +1435,17 @@ static int ObjectSetAttr (C_Object *obj, char *name, PyObject *value)
|
|||||||
}
|
}
|
||||||
if (StringEqual (name, "mat"))
|
if (StringEqual (name, "mat"))
|
||||||
{
|
{
|
||||||
printf ("This is not implemented yet. (matrix)\n");
|
/* This is not allowed. */
|
||||||
return (1);
|
PythonReturnErrorObject (PyExc_AttributeError,
|
||||||
|
"Setting the matrix is not allowed.");
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
if (StringEqual (name, "matrix"))
|
if (StringEqual (name, "matrix"))
|
||||||
{
|
{
|
||||||
printf ("This is not implemented yet. (matrix)\n");
|
/* This is not allowed. */
|
||||||
return (1);
|
PythonReturnErrorObject (PyExc_AttributeError,
|
||||||
|
"Setting the matrix is not allowed.");
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
if (StringEqual (name, "colbits"))
|
if (StringEqual (name, "colbits"))
|
||||||
return (!PyArg_Parse (value, "h", &(object->colbits)));
|
return (!PyArg_Parse (value, "h", &(object->colbits)));
|
||||||
|
@@ -55,6 +55,7 @@
|
|||||||
|
|
||||||
#include "gen_utils.h"
|
#include "gen_utils.h"
|
||||||
#include "modules.h"
|
#include "modules.h"
|
||||||
|
#include "vector.h"
|
||||||
|
|
||||||
/* The Object PyType Object defined in Object.c */
|
/* The Object PyType Object defined in Object.c */
|
||||||
extern PyTypeObject Object_Type;
|
extern PyTypeObject Object_Type;
|
||||||
|
@@ -188,3 +188,34 @@ int EXPP_check_sequence_consistency(PyObject *seq, PyTypeObject *against)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject *EXPP_tuple_repr(PyObject *self, int size)
|
||||||
|
{
|
||||||
|
PyObject *repr, *comma, *item;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/*@ note: a value must be built because the list is decrefed!
|
||||||
|
* otherwise we have nirvana pointers inside python.. */
|
||||||
|
|
||||||
|
repr = PyString_FromString("(");
|
||||||
|
if (!repr) return 0;
|
||||||
|
|
||||||
|
item = PySequence_GetItem(self, 0);
|
||||||
|
PyString_ConcatAndDel(&repr, PyObject_Repr(item));
|
||||||
|
Py_DECREF(item);
|
||||||
|
|
||||||
|
comma = PyString_FromString(", ");
|
||||||
|
|
||||||
|
for (i = 1; i < size; i++) {
|
||||||
|
PyString_Concat(&repr, comma);
|
||||||
|
item = PySequence_GetItem(self, i);
|
||||||
|
PyString_ConcatAndDel(&repr, PyObject_Repr(item));
|
||||||
|
Py_DECREF(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyString_ConcatAndDel(&repr, PyString_FromString(")"));
|
||||||
|
Py_DECREF(comma);
|
||||||
|
|
||||||
|
return repr;
|
||||||
|
|
||||||
|
}
|
||||||
|
@@ -61,6 +61,7 @@ PyObject *EXPP_ReturnPyObjError (PyObject * type, char * error_msg);
|
|||||||
int EXPP_ReturnIntError (PyObject *type, char *error_msg);
|
int EXPP_ReturnIntError (PyObject *type, char *error_msg);
|
||||||
|
|
||||||
int EXPP_check_sequence_consistency (PyObject *seq, PyTypeObject *against);
|
int EXPP_check_sequence_consistency (PyObject *seq, PyTypeObject *against);
|
||||||
|
PyObject *EXPP_tuple_repr(PyObject *self, int size);
|
||||||
|
|
||||||
/* The following functions may need to be moved to the respective BKE or */
|
/* The following functions may need to be moved to the respective BKE or */
|
||||||
/* DNA modules. */
|
/* DNA modules. */
|
||||||
|
154
source/blender/python/api2_2x/matrix.c
Normal file
154
source/blender/python/api2_2x/matrix.c
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* ***** BEGIN GPL/BL DUAL 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. The Blender
|
||||||
|
* Foundation also sells licenses for use in proprietary software under
|
||||||
|
* the Blender License. See http://www.blender.org/BL/ for information
|
||||||
|
* about this.
|
||||||
|
*
|
||||||
|
* 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,
|
||||||
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s): Michel Selten
|
||||||
|
*
|
||||||
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This file is the old bpython opy_matrix.c with minor modifications */
|
||||||
|
|
||||||
|
#include "vector.h"
|
||||||
|
#include "BLI_arithb.h"
|
||||||
|
|
||||||
|
static void Matrix_dealloc (MatrixObject *self)
|
||||||
|
{
|
||||||
|
Py_DECREF (self->rows[0]);
|
||||||
|
Py_DECREF (self->rows[1]);
|
||||||
|
Py_DECREF (self->rows[2]);
|
||||||
|
Py_DECREF (self->rows[3]);
|
||||||
|
|
||||||
|
PyMem_DEL (self);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject * Matrix_getattr (MatrixObject *self, char *name)
|
||||||
|
{
|
||||||
|
PyObject * list;
|
||||||
|
float val[3];
|
||||||
|
float mat3[3][3];
|
||||||
|
|
||||||
|
if (strcmp (name, "rot") == 0)
|
||||||
|
{
|
||||||
|
Mat3CpyMat4 (mat3, self->mat);
|
||||||
|
Mat3ToEul (mat3, val);
|
||||||
|
}
|
||||||
|
else if (strcmp (name, "size") == 0)
|
||||||
|
{
|
||||||
|
Mat4ToSize (self->mat, val);
|
||||||
|
}
|
||||||
|
else if (strcmp (name, "loc") == 0)
|
||||||
|
{
|
||||||
|
VECCOPY (val, (float *)(self->mat)[3]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||||
|
"expected 'rot', 'size' or 'loc'"));
|
||||||
|
}
|
||||||
|
|
||||||
|
list = PyList_New (3);
|
||||||
|
PyList_SetItem (list, 0, PyFloat_FromDouble (val[0]));
|
||||||
|
PyList_SetItem (list, 1, PyFloat_FromDouble (val[1]));
|
||||||
|
PyList_SetItem (list, 2, PyFloat_FromDouble (val[2]));
|
||||||
|
|
||||||
|
return (list);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Matrix_setattr (MatrixObject *self, char *name, PyObject *v)
|
||||||
|
{
|
||||||
|
/* This is not supported. */
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject * Matrix_repr (MatrixObject *self)
|
||||||
|
{
|
||||||
|
return (EXPP_tuple_repr ((PyObject *) self, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject * Matrix_item (MatrixObject *self, int i)
|
||||||
|
{
|
||||||
|
if ((i<0) || (i>=4))
|
||||||
|
{
|
||||||
|
return (EXPP_ReturnPyObjError (PyExc_IndexError,
|
||||||
|
"array index out of range"));
|
||||||
|
}
|
||||||
|
return (EXPP_incr_ret (self->rows[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PySequenceMethods Matrix_SeqMethods =
|
||||||
|
{
|
||||||
|
(inquiry) 0, /*sq_length*/
|
||||||
|
(binaryfunc) 0, /*sq_concat*/
|
||||||
|
(intargfunc) 0, /*sq_repeat*/
|
||||||
|
(intargfunc) Matrix_item, /*sq_item*/
|
||||||
|
(intintargfunc) 0, /*sq_slice*/
|
||||||
|
(intobjargproc) 0, /*sq_ass_item*/
|
||||||
|
(intintobjargproc) 0, /*sq_ass_slice*/
|
||||||
|
};
|
||||||
|
|
||||||
|
PyTypeObject Matrix_Type =
|
||||||
|
{
|
||||||
|
PyObject_HEAD_INIT(NULL)
|
||||||
|
0, /*ob_size*/
|
||||||
|
"Matrix", /*tp_name*/
|
||||||
|
sizeof(MatrixObject), /*tp_basicsize*/
|
||||||
|
0, /*tp_itemsize*/
|
||||||
|
/* methods */
|
||||||
|
(destructor) Matrix_dealloc, /*tp_dealloc*/
|
||||||
|
(printfunc) 0, /*tp_print*/
|
||||||
|
(getattrfunc) Matrix_getattr, /*tp_getattr*/
|
||||||
|
(setattrfunc) Matrix_setattr, /*tp_setattr*/
|
||||||
|
0, /*tp_compare*/
|
||||||
|
(reprfunc) Matrix_repr, /*tp_repr*/
|
||||||
|
0, /*tp_as_number*/
|
||||||
|
&Matrix_SeqMethods, /*tp_as_sequence*/
|
||||||
|
};
|
||||||
|
|
||||||
|
PyObject * newMatrixObject (Matrix4Ptr mat)
|
||||||
|
{
|
||||||
|
MatrixObject * self;
|
||||||
|
|
||||||
|
self = PyObject_NEW (MatrixObject, &Matrix_Type);
|
||||||
|
self->mat = mat;
|
||||||
|
|
||||||
|
self->rows[0] = newVectorObject ((float *)(self->mat[0]), 4);
|
||||||
|
self->rows[1] = newVectorObject ((float *)(self->mat[1]), 4);
|
||||||
|
self->rows[2] = newVectorObject ((float *)(self->mat[2]), 4);
|
||||||
|
self->rows[3] = newVectorObject ((float *)(self->mat[3]), 4);
|
||||||
|
if ((self->rows[0] == NULL) ||
|
||||||
|
(self->rows[1] == NULL) ||
|
||||||
|
(self->rows[2] == NULL) ||
|
||||||
|
(self->rows[3] == NULL))
|
||||||
|
{
|
||||||
|
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||||
|
"Something wrong with creating a matrix object"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((PyObject *)self);
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_py_matrix (void)
|
||||||
|
{
|
||||||
|
Matrix_Type.ob_type = &PyType_Type;
|
||||||
|
}
|
@@ -133,5 +133,6 @@ PyObject * M_Window_Init (void);
|
|||||||
PyObject * M_Draw_Init (void);
|
PyObject * M_Draw_Init (void);
|
||||||
PyObject * M_BGL_Init (void);
|
PyObject * M_BGL_Init (void);
|
||||||
PyObject * M_Text_Init (void);
|
PyObject * M_Text_Init (void);
|
||||||
|
PyObject * M_World_Init (void);
|
||||||
|
|
||||||
#endif /* EXPP_modules_h */
|
#endif /* EXPP_modules_h */
|
||||||
|
@@ -144,37 +144,6 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *se
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *EXPP_tuple_repr(PyObject *self, int size)
|
|
||||||
{
|
|
||||||
PyObject *repr, *comma, *item;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/*@ note: a value must be built because the list is decrefed!
|
|
||||||
* otherwise we have nirvana pointers inside python.. */
|
|
||||||
|
|
||||||
repr = PyString_FromString("(");
|
|
||||||
if (!repr) return 0;
|
|
||||||
|
|
||||||
item = PySequence_GetItem(self, 0);
|
|
||||||
PyString_ConcatAndDel(&repr, PyObject_Repr(item));
|
|
||||||
Py_DECREF(item);
|
|
||||||
|
|
||||||
comma = PyString_FromString(", ");
|
|
||||||
|
|
||||||
for (i = 1; i < size; i++) {
|
|
||||||
PyString_Concat(&repr, comma);
|
|
||||||
item = PySequence_GetItem(self, i);
|
|
||||||
PyString_ConcatAndDel(&repr, PyObject_Repr(item));
|
|
||||||
Py_DECREF(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyString_ConcatAndDel(&repr, PyString_FromString(")"));
|
|
||||||
Py_DECREF(comma);
|
|
||||||
|
|
||||||
return repr;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *Vector_repr (VectorObject *self)
|
static PyObject *Vector_repr (VectorObject *self)
|
||||||
{
|
{
|
||||||
return EXPP_tuple_repr((PyObject *) self, self->size);
|
return EXPP_tuple_repr((PyObject *) self, self->size);
|
||||||
|
Reference in New Issue
Block a user