Update Mathutils for py3k
* removed coercing types which has been removed from py3. * matrix uses getset's rather then getset items. * removed deprecated functions.
This commit is contained in:
@@ -41,27 +41,16 @@ static char M_Mathutils_Matrix_doc[] = "() - create a new matrix object from a l
|
||||
static char M_Mathutils_Quaternion_doc[] = "() - create a quaternion from a list or an axis of rotation and an angle";
|
||||
static char M_Mathutils_Euler_doc[] = "() - create and return a new euler object";
|
||||
static char M_Mathutils_Rand_doc[] = "() - return a random number";
|
||||
static char M_Mathutils_CrossVecs_doc[] = "() - returns a vector perpedicular to the 2 vectors crossed";
|
||||
static char M_Mathutils_CopyVec_doc[] = "() - create a copy of vector";
|
||||
static char M_Mathutils_DotVecs_doc[] = "() - return the dot product of two vectors";
|
||||
static char M_Mathutils_AngleBetweenVecs_doc[] = "() - returns the angle between two vectors in degrees";
|
||||
static char M_Mathutils_MidpointVecs_doc[] = "() - return the vector to the midpoint between two vectors";
|
||||
static char M_Mathutils_MatMultVec_doc[] = "() - multiplies a matrix by a column vector";
|
||||
static char M_Mathutils_VecMultMat_doc[] = "() - multiplies a row vector by a matrix";
|
||||
static char M_Mathutils_ProjectVecs_doc[] = "() - returns the projection vector from the projection of vecA onto vecB";
|
||||
static char M_Mathutils_RotationMatrix_doc[] = "() - construct a rotation matrix from an angle and axis of rotation";
|
||||
static char M_Mathutils_ScaleMatrix_doc[] = "() - construct a scaling matrix from a scaling factor";
|
||||
static char M_Mathutils_OrthoProjectionMatrix_doc[] = "() - construct a orthographic projection matrix from a selected plane";
|
||||
static char M_Mathutils_ShearMatrix_doc[] = "() - construct a shearing matrix from a plane of shear and a shear factor";
|
||||
static char M_Mathutils_CopyMat_doc[] = "() - create a copy of a matrix";
|
||||
static char M_Mathutils_TranslationMatrix_doc[] = "(vec) - create a translation matrix from a vector";
|
||||
static char M_Mathutils_CopyQuat_doc[] = "() - copy quatB to quatA";
|
||||
static char M_Mathutils_CopyEuler_doc[] = "() - copy eulB to eultA";
|
||||
static char M_Mathutils_CrossQuats_doc[] = "() - return the mutliplication of two quaternions";
|
||||
static char M_Mathutils_DotQuats_doc[] = "() - return the dot product of two quaternions";
|
||||
static char M_Mathutils_Slerp_doc[] = "() - returns the interpolation between two quaternions";
|
||||
static char M_Mathutils_DifferenceQuats_doc[] = "() - return the angular displacment difference between two quats";
|
||||
static char M_Mathutils_RotateEuler_doc[] = "() - rotate euler by an axis and angle";
|
||||
static char M_Mathutils_Intersect_doc[] = "(v1, v2, v3, ray, orig, clip=1) - returns the intersection between a ray and a triangle, if possible, returns None otherwise";
|
||||
static char M_Mathutils_TriangleArea_doc[] = "(v1, v2, v3) - returns the area size of the 2D or 3D triangle defined";
|
||||
static char M_Mathutils_TriangleNormal_doc[] = "(v1, v2, v3) - returns the normal of the 3D triangle defined";
|
||||
@@ -71,30 +60,19 @@ static char M_Mathutils_LineIntersect_doc[] = "(v1, v2, v3, v4) - returns a tupl
|
||||
struct PyMethodDef M_Mathutils_methods[] = {
|
||||
{"Rand", (PyCFunction) M_Mathutils_Rand, METH_VARARGS, M_Mathutils_Rand_doc},
|
||||
{"Vector", (PyCFunction) M_Mathutils_Vector, METH_VARARGS, M_Mathutils_Vector_doc},
|
||||
{"CrossVecs", (PyCFunction) M_Mathutils_CrossVecs, METH_VARARGS, M_Mathutils_CrossVecs_doc},
|
||||
{"DotVecs", (PyCFunction) M_Mathutils_DotVecs, METH_VARARGS, M_Mathutils_DotVecs_doc},
|
||||
{"AngleBetweenVecs", (PyCFunction) M_Mathutils_AngleBetweenVecs, METH_VARARGS, M_Mathutils_AngleBetweenVecs_doc},
|
||||
{"MidpointVecs", (PyCFunction) M_Mathutils_MidpointVecs, METH_VARARGS, M_Mathutils_MidpointVecs_doc},
|
||||
{"VecMultMat", (PyCFunction) M_Mathutils_VecMultMat, METH_VARARGS, M_Mathutils_VecMultMat_doc},
|
||||
{"ProjectVecs", (PyCFunction) M_Mathutils_ProjectVecs, METH_VARARGS, M_Mathutils_ProjectVecs_doc},
|
||||
{"CopyVec", (PyCFunction) M_Mathutils_CopyVec, METH_VARARGS, M_Mathutils_CopyVec_doc},
|
||||
{"Matrix", (PyCFunction) M_Mathutils_Matrix, METH_VARARGS, M_Mathutils_Matrix_doc},
|
||||
{"RotationMatrix", (PyCFunction) M_Mathutils_RotationMatrix, METH_VARARGS, M_Mathutils_RotationMatrix_doc},
|
||||
{"ScaleMatrix", (PyCFunction) M_Mathutils_ScaleMatrix, METH_VARARGS, M_Mathutils_ScaleMatrix_doc},
|
||||
{"ShearMatrix", (PyCFunction) M_Mathutils_ShearMatrix, METH_VARARGS, M_Mathutils_ShearMatrix_doc},
|
||||
{"TranslationMatrix", (PyCFunction) M_Mathutils_TranslationMatrix, METH_O, M_Mathutils_TranslationMatrix_doc},
|
||||
{"CopyMat", (PyCFunction) M_Mathutils_CopyMat, METH_VARARGS, M_Mathutils_CopyMat_doc},
|
||||
{"OrthoProjectionMatrix", (PyCFunction) M_Mathutils_OrthoProjectionMatrix, METH_VARARGS, M_Mathutils_OrthoProjectionMatrix_doc},
|
||||
{"MatMultVec", (PyCFunction) M_Mathutils_MatMultVec, METH_VARARGS, M_Mathutils_MatMultVec_doc},
|
||||
{"Quaternion", (PyCFunction) M_Mathutils_Quaternion, METH_VARARGS, M_Mathutils_Quaternion_doc},
|
||||
{"CopyQuat", (PyCFunction) M_Mathutils_CopyQuat, METH_VARARGS, M_Mathutils_CopyQuat_doc},
|
||||
{"CrossQuats", (PyCFunction) M_Mathutils_CrossQuats, METH_VARARGS, M_Mathutils_CrossQuats_doc},
|
||||
{"DotQuats", (PyCFunction) M_Mathutils_DotQuats, METH_VARARGS, M_Mathutils_DotQuats_doc},
|
||||
{"DifferenceQuats", (PyCFunction) M_Mathutils_DifferenceQuats, METH_VARARGS,M_Mathutils_DifferenceQuats_doc},
|
||||
{"Slerp", (PyCFunction) M_Mathutils_Slerp, METH_VARARGS, M_Mathutils_Slerp_doc},
|
||||
{"Euler", (PyCFunction) M_Mathutils_Euler, METH_VARARGS, M_Mathutils_Euler_doc},
|
||||
{"CopyEuler", (PyCFunction) M_Mathutils_CopyEuler, METH_VARARGS, M_Mathutils_CopyEuler_doc},
|
||||
{"RotateEuler", (PyCFunction) M_Mathutils_RotateEuler, METH_VARARGS, M_Mathutils_RotateEuler_doc},
|
||||
{"Intersect", ( PyCFunction ) M_Mathutils_Intersect, METH_VARARGS, M_Mathutils_Intersect_doc},
|
||||
{"TriangleArea", ( PyCFunction ) M_Mathutils_TriangleArea, METH_VARARGS, M_Mathutils_TriangleArea_doc},
|
||||
{"TriangleNormal", ( PyCFunction ) M_Mathutils_TriangleNormal, METH_VARARGS, M_Mathutils_TriangleNormal_doc},
|
||||
@@ -356,49 +334,6 @@ PyObject *M_Mathutils_Vector(PyObject * self, PyObject * args)
|
||||
Py_DECREF(listObject);
|
||||
return newVectorObject(vec, size, Py_NEW);
|
||||
}
|
||||
//----------------------------------Mathutils.CrossVecs() ---------------
|
||||
//finds perpendicular vector - only 3D is supported
|
||||
PyObject *M_Mathutils_CrossVecs(PyObject * self, PyObject * args)
|
||||
{
|
||||
PyObject *vecCross = NULL;
|
||||
VectorObject *vec1 = NULL, *vec2 = NULL;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec1, &vector_Type, &vec2)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.CrossVecs(): expects (2) 3D vector objects\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(vec1->size != 3 || vec2->size != 3) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Mathutils.CrossVecs(): expects (2) 3D vector objects\n");
|
||||
return NULL;
|
||||
}
|
||||
vecCross = newVectorObject(NULL, 3, Py_NEW);
|
||||
Crossf(((VectorObject*)vecCross)->vec, vec1->vec, vec2->vec);
|
||||
return vecCross;
|
||||
}
|
||||
//----------------------------------Mathutils.DotVec() -------------------
|
||||
//calculates the dot product of two vectors
|
||||
PyObject *M_Mathutils_DotVecs(PyObject * self, PyObject * args)
|
||||
{
|
||||
VectorObject *vec1 = NULL, *vec2 = NULL;
|
||||
double dot = 0.0f;
|
||||
int x;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec1, &vector_Type, &vec2)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.DotVecs(): expects (2) vector objects of the same size\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(vec1->size != vec2->size) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Mathutils.DotVecs(): expects (2) vector objects of the same size\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(x = 0; x < vec1->size; x++) {
|
||||
dot += vec1->vec[x] * vec2->vec[x];
|
||||
}
|
||||
return PyFloat_FromDouble(dot);
|
||||
}
|
||||
//----------------------------------Mathutils.AngleBetweenVecs() ---------
|
||||
//calculates the angle between 2 vectors
|
||||
PyObject *M_Mathutils_AngleBetweenVecs(PyObject * self, PyObject * args)
|
||||
@@ -1100,39 +1035,7 @@ PyObject *M_Mathutils_Quaternion(PyObject * self, PyObject * args)
|
||||
Py_DECREF(listObject);
|
||||
return newQuaternionObject(quat, Py_NEW);
|
||||
}
|
||||
//----------------------------------Mathutils.CrossQuats() ----------------
|
||||
//quaternion multiplication - associate not commutative
|
||||
PyObject *M_Mathutils_CrossQuats(PyObject * self, PyObject * args)
|
||||
{
|
||||
QuaternionObject *quatU = NULL, *quatV = NULL;
|
||||
float quat[4];
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!", &quaternion_Type, &quatU, &quaternion_Type, &quatV)) {
|
||||
PyErr_SetString(PyExc_TypeError,"Mathutils.CrossQuats(): expected Quaternion types");
|
||||
return NULL;
|
||||
}
|
||||
QuatMul(quat, quatU->quat, quatV->quat);
|
||||
|
||||
return newQuaternionObject(quat, Py_NEW);
|
||||
}
|
||||
//----------------------------------Mathutils.DotQuats() ----------------
|
||||
//returns the dot product of 2 quaternions
|
||||
PyObject *M_Mathutils_DotQuats(PyObject * self, PyObject * args)
|
||||
{
|
||||
QuaternionObject *quatU = NULL, *quatV = NULL;
|
||||
double dot = 0.0f;
|
||||
int x;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!", &quaternion_Type, &quatU, &quaternion_Type, &quatV)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.DotQuats(): expected Quaternion types");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(x = 0; x < 4; x++) {
|
||||
dot += quatU->quat[x] * quatV->quat[x];
|
||||
}
|
||||
return PyFloat_FromDouble(dot);
|
||||
}
|
||||
//----------------------------------Mathutils.DifferenceQuats() ---------
|
||||
//returns the difference between 2 quaternions
|
||||
PyObject *M_Mathutils_DifferenceQuats(PyObject * self, PyObject * args)
|
||||
@@ -1533,145 +1436,6 @@ PyObject *M_Mathutils_TriangleArea( PyObject * self, PyObject * args )
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
//#############################DEPRECATED################################
|
||||
//#######################################################################
|
||||
//----------------------------------Mathutils.CopyMat() -----------------
|
||||
//copies a matrix into a new matrix
|
||||
PyObject *M_Mathutils_CopyMat(PyObject * self, PyObject * args)
|
||||
{
|
||||
PyObject *matrix = NULL;
|
||||
static char warning = 1;
|
||||
|
||||
if( warning ) {
|
||||
printf("Mathutils.CopyMat(): deprecated :use Mathutils.Matrix() to copy matrices\n");
|
||||
--warning;
|
||||
}
|
||||
|
||||
matrix = M_Mathutils_Matrix(self, args);
|
||||
if(matrix == NULL)
|
||||
return NULL; //error string already set if we get here
|
||||
else
|
||||
return matrix;
|
||||
}
|
||||
//----------------------------------Mathutils.CopyVec() -----------------
|
||||
//makes a new vector that is a copy of the input
|
||||
PyObject *M_Mathutils_CopyVec(PyObject * self, PyObject * args)
|
||||
{
|
||||
PyObject *vec = NULL;
|
||||
static char warning = 1;
|
||||
|
||||
if( warning ) {
|
||||
printf("Mathutils.CopyVec(): Deprecated: use Mathutils.Vector() to copy vectors\n");
|
||||
--warning;
|
||||
}
|
||||
|
||||
vec = M_Mathutils_Vector(self, args);
|
||||
if(vec == NULL)
|
||||
return NULL; //error string already set if we get here
|
||||
else
|
||||
return vec;
|
||||
}
|
||||
//----------------------------------Mathutils.CopyQuat() --------------
|
||||
//Copies a quaternion to a new quat
|
||||
PyObject *M_Mathutils_CopyQuat(PyObject * self, PyObject * args)
|
||||
{
|
||||
PyObject *quat = NULL;
|
||||
static char warning = 1;
|
||||
|
||||
if( warning ) {
|
||||
printf("Mathutils.CopyQuat(): Deprecated: use Mathutils.Quaternion() to copy vectors\n");
|
||||
--warning;
|
||||
}
|
||||
|
||||
quat = M_Mathutils_Quaternion(self, args);
|
||||
if(quat == NULL)
|
||||
return NULL; //error string already set if we get here
|
||||
else
|
||||
return quat;
|
||||
}
|
||||
//----------------------------------Mathutils.CopyEuler() ---------------
|
||||
//copies a euler to a new euler
|
||||
PyObject *M_Mathutils_CopyEuler(PyObject * self, PyObject * args)
|
||||
{
|
||||
PyObject *eul = NULL;
|
||||
static char warning = 1;
|
||||
|
||||
if( warning ) {
|
||||
printf("Mathutils.CopyEuler(): deprecated:use Mathutils.Euler() to copy vectors\n");
|
||||
--warning;
|
||||
}
|
||||
|
||||
eul = M_Mathutils_Euler(self, args);
|
||||
if(eul == NULL)
|
||||
return NULL; //error string already set if we get here
|
||||
else
|
||||
return eul;
|
||||
}
|
||||
//----------------------------------Mathutils.RotateEuler() ------------
|
||||
//rotates a euler a certain amount and returns the result
|
||||
//should return a unique euler rotation (i.e. no 720 degree pitches :)
|
||||
PyObject *M_Mathutils_RotateEuler(PyObject * self, PyObject * args)
|
||||
{
|
||||
EulerObject *Eul = NULL;
|
||||
float angle;
|
||||
char *axis;
|
||||
static char warning = 1;
|
||||
|
||||
if( warning ) {
|
||||
printf("Mathutils.RotateEuler(): Deprecated:use Euler.rotate() to rotate a euler\n");
|
||||
--warning;
|
||||
}
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!fs", &euler_Type, &Eul, &angle, &axis)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.RotateEuler(): expected euler type & float & string");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Euler_Rotate(Eul, Py_BuildValue("fs", angle, axis));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
//----------------------------------Mathutils.MatMultVec() --------------
|
||||
//COLUMN VECTOR Multiplication (Matrix X Vector)
|
||||
PyObject *M_Mathutils_MatMultVec(PyObject * self, PyObject * args)
|
||||
{
|
||||
MatrixObject *mat = NULL;
|
||||
VectorObject *vec = NULL;
|
||||
static char warning = 1;
|
||||
|
||||
if( warning ) {
|
||||
printf("Mathutils.MatMultVec(): Deprecated: use matrix * vec to perform column vector multiplication\n");
|
||||
--warning;
|
||||
}
|
||||
|
||||
//get pyObjects
|
||||
if(!PyArg_ParseTuple(args, "O!O!", &matrix_Type, &mat, &vector_Type, &vec)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.MatMultVec(): MatMultVec() expects a matrix and a vector object - in that order\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return column_vector_multiplication(mat, vec);
|
||||
}
|
||||
//----------------------------------Mathutils.VecMultMat() ---------------
|
||||
//ROW VECTOR Multiplication - Vector X Matrix
|
||||
PyObject *M_Mathutils_VecMultMat(PyObject * self, PyObject * args)
|
||||
{
|
||||
MatrixObject *mat = NULL;
|
||||
VectorObject *vec = NULL;
|
||||
static char warning = 1;
|
||||
|
||||
if( warning ) {
|
||||
printf("Mathutils.VecMultMat(): Deprecated: use vec * matrix to perform row vector multiplication\n");
|
||||
--warning;
|
||||
}
|
||||
|
||||
//get pyObjects
|
||||
if(!PyArg_ParseTuple(args, "O!O!", &vector_Type, &vec, &matrix_Type, &mat)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.VecMultMat(): VecMultMat() expects a vector and matrix object - in that order\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return row_vector_multiplication(vec, mat);
|
||||
}
|
||||
|
||||
/* Utility functions */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user