removed the unpopular 'ed' functions, and added .copy() to Mathutils vector and matrix

(inverted, normalized, transposed)

making an inverted copy of an objects matrix used to be.. (2.42)

  imat= Mathutils.Matrix(ob.matrixWorld)
  imat.invert()


# inverted.. I added but now removed

  imat= ob.matrixWorld.inverted()

# with copy (current functionality)...

  imat= ob.matrixWorld.copy().invert()
This commit is contained in:
2006-08-21 13:52:32 +00:00
parent 0dcfab3e32
commit 0925d80cfa
5 changed files with 55 additions and 79 deletions

View File

@@ -130,7 +130,7 @@ def PolyFill(polylines):
def CopyVec(vector):
"""
Create a copy of the Vector object.
@attention: B{DEPRECATED} use Vector(vector) instead.
@attention: B{DEPRECATED} use vector.copy() instead.
@type vector: Vector object.
@param vector: A 2d,3d or 4d vector to be copied.
@rtype: Vector object.
@@ -298,10 +298,9 @@ def CopyMat(matrix):
@param matrix: A 2d,3d or 4d matrix to be copied.
@rtype: Matrix object.
@return: A new matrix object which is a copy of the one passed in.
@attention: B{DEPRECATED} You should use the matrix constructor to create
a copy of a matrix
@attention: B{DEPRECATED} Use the matrix copy funtion to make a copy.
Example::
newMat = Matrix(myMat)
newMat = myMat.copy()
"""
def MatMultVec(mat, vec):
@@ -429,7 +428,7 @@ class Vector:
- vec * matrix
- vec * vec
- vec * quat
- -vec (this is shorthand for negate())
- -vec
@note: You can access a vector object like a sequence
- x = vector[0]
@attention: Vector data can be wrapped or non-wrapped. When a object is wrapped it
@@ -468,10 +467,16 @@ class Vector:
- (): An empty 3 dimensional vector.
"""
def copy():
"""
Returns a copy of this vector
@return: a copy of itself
"""
def zero():
"""
Set all values to zero.
@return: a copy of itself
@return: an instance of itself
"""
def normalize():
@@ -479,22 +484,13 @@ class Vector:
Normalize the vector, making the length of the vector always 1.0
@note: Normalize works for vectors of all sizes, however 4D Vectors w axis is left untouched.
@note: Normalizing a vector where all values are zero results in all axis having a nan value (not a number).
@return: None
"""
def normalized():
"""
Same as normalize except it returns a normalized copy of the vector, leaving the original intact.
@return: a normalized copy of the vector
@return: an instance of itself
"""
def negate():
"""
Set all values to their negative.
@return: a copy of itself
@attention: B{DEPRECATED} You can use -vector instead
Example::
negVector = -myVec
@return: an instance of its self
"""
def resize2D():
@@ -776,6 +772,13 @@ class Matrix:
def zero():
"""
Set all matrix values to 0.
@return: an instance of itself
"""
def copy():
"""
Returns a copy of this matrix
@return: a copy of itself
"""
@@ -785,7 +788,7 @@ class Matrix:
An object with zero location and rotation, a scale of 1, will have an identity matrix.
See U{http://en.wikipedia.org/wiki/Identity_matrix}
@return: a copy of itself
@return: an instance of itself
"""
def transpose():
@@ -796,12 +799,6 @@ class Matrix:
@return: None
"""
def transposed():
"""
Same as transpose() except a transposed copy of the matrix is returned leaving the original intact.
@return: a transposed copy of the matrix
"""
def determinant():
"""
Return the determinant of a matrix.
@@ -816,16 +813,10 @@ class Matrix:
Set the matrix to its inverse.
See U{http://en.wikipedia.org/wiki/Inverse_matrix}
@return: a copy of itself
@return: an instance of itself.
@raise ValueError: When matrix is singular.
"""
def inverted():
"""
Same as invert() except an inverted copy of the matrix is returned leaving the original intact.
@return: an inverted copy of the matrix
"""
def rotationPart():
"""
Return the 3d submatrix corresponding to the linear term of the
@@ -854,7 +845,7 @@ class Matrix:
def resize4x4():
"""
Resize the matrix to by 4x4
@return: a copy of itself
@return: an instance of itself.
"""
def toEuler():

View File

@@ -39,31 +39,30 @@
char Matrix_Zero_doc[] = "() - set all values in the matrix to 0";
char Matrix_Identity_doc[] = "() - set the square matrix to it's identity matrix";
char Matrix_Transpose_doc[] = "() - set the matrix to it's transpose";
char Matrix_Transposed_doc[] = "() - return a copy transposed copy of the matrix";
char Matrix_Determinant_doc[] = "() - return the determinant of the matrix";
char Matrix_Invert_doc[] = "() - set the matrix to it's inverse if an inverse is possible";
char Matrix_Inverted_doc[] = "() - set the matrix to it's inverse if an inverse is possible";
char Matrix_TranslationPart_doc[] = "() - return a vector encompassing the translation of the matrix";
char Matrix_RotationPart_doc[] = "() - return a vector encompassing the rotation of the matrix";
char Matrix_scalePart_doc[] = "() - convert matrix to a 3D vector";
char Matrix_Resize4x4_doc[] = "() - resize the matrix to a 4x4 square matrix";
char Matrix_toEuler_doc[] = "() - convert matrix to a euler angle rotation";
char Matrix_toQuat_doc[] = "() - convert matrix to a quaternion rotation";
char Matrix_copy_doc[] = "() - return a copy of the matrix";
/*-----------------------METHOD DEFINITIONS ----------------------*/
struct PyMethodDef Matrix_methods[] = {
{"zero", (PyCFunction) Matrix_Zero, METH_NOARGS, Matrix_Zero_doc},
{"identity", (PyCFunction) Matrix_Identity, METH_NOARGS, Matrix_Identity_doc},
{"transpose", (PyCFunction) Matrix_Transpose, METH_NOARGS, Matrix_Transpose_doc},
{"transposed", (PyCFunction) Matrix_Transposed, METH_NOARGS, Matrix_Transposed_doc},
{"determinant", (PyCFunction) Matrix_Determinant, METH_NOARGS, Matrix_Determinant_doc},
{"invert", (PyCFunction) Matrix_Invert, METH_NOARGS, Matrix_Invert_doc},
{"inverted", (PyCFunction) Matrix_Inverted, METH_NOARGS, Matrix_Inverted_doc},
{"translationPart", (PyCFunction) Matrix_TranslationPart, METH_NOARGS, Matrix_TranslationPart_doc},
{"rotationPart", (PyCFunction) Matrix_RotationPart, METH_NOARGS, Matrix_RotationPart_doc},
{"scalePart", (PyCFunction) Matrix_scalePart, METH_NOARGS, Matrix_scalePart_doc},
{"resize4x4", (PyCFunction) Matrix_Resize4x4, METH_NOARGS, Matrix_Resize4x4_doc},
{"toEuler", (PyCFunction) Matrix_toEuler, METH_NOARGS, Matrix_toEuler_doc},
{"toQuat", (PyCFunction) Matrix_toQuat, METH_NOARGS, Matrix_toQuat_doc},
{"copy", (PyCFunction) Matrix_copy, METH_NOARGS, Matrix_copy_doc},
{"__copy__", (PyCFunction) Matrix_copy, METH_NOARGS, Matrix_copy_doc},
{NULL, NULL, 0, NULL}
};
/*-----------------------------METHODS----------------------------*/
@@ -264,21 +263,10 @@ PyObject *Matrix_Invert(MatrixObject * self)
return EXPP_ReturnPyObjError(PyExc_ValueError,
"matrix does not have an inverse");
}
/*return EXPP_incr_ret((PyObject*)self);*/ /*Changed after 2.42 relerase */
Py_RETURN_NONE;
return EXPP_incr_ret((PyObject*)self);
}
/*---------------------------Matrix.inverted() ------------------*/
PyObject *Matrix_Inverted(MatrixObject * self)
{
MatrixObject *pymat;
/*copy the matrix*/
pymat= (MatrixObject*)newMatrixObject((float (*))*self->matrix, self->rowSize, self->colSize, Py_NEW);
Matrix_Invert(pymat);
return (PyObject*)pymat;
}
/*---------------------------Matrix.determinant() ----------------*/
PyObject *Matrix_Determinant(MatrixObject * self)
{
@@ -324,18 +312,7 @@ PyObject *Matrix_Transpose(MatrixObject * self)
Mat4Transp((float (*)[4])*self->matrix);
}
/*return EXPP_incr_ret((PyObject*)self);*/ /*Changed after 2.42 relerase */
Py_RETURN_NONE;
}
/*---------------------------Matrix.transposed() ------------------*/
PyObject *Matrix_Transposed(MatrixObject * self)
{
MatrixObject *pymat;
/*copy the matrix*/
pymat= (MatrixObject*)newMatrixObject((float (*))*self->matrix, self->rowSize, self->colSize, Py_NEW);
Matrix_Transpose(pymat);
return (PyObject*)pymat;
return EXPP_incr_ret((PyObject*)self);
}
@@ -372,6 +349,13 @@ PyObject *Matrix_Identity(MatrixObject * self)
return EXPP_incr_ret((PyObject*)self);
}
/*---------------------------Matrix.inverted() ------------------*/
PyObject *Matrix_copy(MatrixObject * self)
{
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)

View File

@@ -66,16 +66,15 @@ blender (stored in blend_data). This is an either/or struct not both*/
PyObject *Matrix_Zero( MatrixObject * self );
PyObject *Matrix_Identity( MatrixObject * self );
PyObject *Matrix_Transpose( MatrixObject * self );
PyObject *Matrix_Transposed( MatrixObject * self );
PyObject *Matrix_Determinant( MatrixObject * self );
PyObject *Matrix_Invert( MatrixObject * self );
PyObject *Matrix_Inverted( MatrixObject * self );
PyObject *Matrix_TranslationPart( MatrixObject * self );
PyObject *Matrix_RotationPart( MatrixObject * self );
PyObject *Matrix_scalePart( MatrixObject * self );
PyObject *Matrix_Resize4x4( MatrixObject * self );
PyObject *Matrix_toEuler( MatrixObject * self );
PyObject *Matrix_toQuat( MatrixObject * self );
PyObject *Matrix_copy( MatrixObject * self );
PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type);
#endif /* EXPP_matrix_H */

View File

@@ -39,24 +39,25 @@
/*-------------------------DOC STRINGS ---------------------------*/
char Vector_Zero_doc[] = "() - set all values in the vector to 0";
char Vector_Normalize_doc[] = "() - normalize the vector";
char Vector_Normalized_doc[] = "() - return a normalized copy of the vector";
char Vector_Negate_doc[] = "() - changes vector to it's additive inverse";
char Vector_Resize2D_doc[] = "() - resize a vector to [x,y]";
char Vector_Resize3D_doc[] = "() - resize a vector to [x,y,z]";
char Vector_Resize4D_doc[] = "() - resize a vector to [x,y,z,w]";
char Vector_toPoint_doc[] = "() - create a new Point Object from this vector";
char Vector_ToTrackQuat_doc[] = "(track, up) - extract a quaternion from the vector and the track and up axis";
char Vector_copy_doc[] = "() - return a copy of the vector";
/*-----------------------METHOD DEFINITIONS ----------------------*/
struct PyMethodDef Vector_methods[] = {
{"zero", (PyCFunction) Vector_Zero, METH_NOARGS, Vector_Zero_doc},
{"normalize", (PyCFunction) Vector_Normalize, METH_NOARGS, Vector_Normalize_doc},
{"normalized", (PyCFunction) Vector_Normalized, METH_NOARGS, Vector_Normalized_doc},
{"negate", (PyCFunction) Vector_Negate, METH_NOARGS, Vector_Negate_doc},
{"resize2D", (PyCFunction) Vector_Resize2D, METH_NOARGS, Vector_Resize2D_doc},
{"resize3D", (PyCFunction) Vector_Resize3D, METH_NOARGS, Vector_Resize2D_doc},
{"resize4D", (PyCFunction) Vector_Resize4D, METH_NOARGS, Vector_Resize2D_doc},
{"toPoint", (PyCFunction) Vector_toPoint, METH_NOARGS, Vector_toPoint_doc},
{"toTrackQuat", ( PyCFunction ) Vector_ToTrackQuat, METH_VARARGS, Vector_ToTrackQuat_doc},
{"copy", (PyCFunction) Vector_copy, METH_NOARGS, Vector_copy_doc},
{"__copy__", (PyCFunction) Vector_copy, METH_NOARGS, Vector_copy_doc},
{NULL, NULL, 0, NULL}
};
/*-----------------------------METHODS----------------------------
@@ -101,16 +102,7 @@ PyObject *Vector_Normalize(VectorObject * self)
for(x = 0; x < self->size; x++) {
self->vec[x] /= norm;
}
Py_RETURN_NONE;
}
/*----------------------------Vector.normalized() -----------------
return a normalized copy*/
PyObject *Vector_Normalized(VectorObject * self)
{
VectorObject *vec= (VectorObject*)newVectorObject(self->vec, self->size, Py_NEW);
Vector_Normalize(vec);
return (PyObject*)vec;
return EXPP_incr_ret((PyObject*)self);
}
@@ -289,6 +281,16 @@ PyObject *Vector_ToTrackQuat( VectorObject * self, PyObject * args )
return newQuaternionObject(vectoquat(vec, track, up), Py_NEW);
}
/*----------------------------Vector.copy() --------------------------------------
return a copy of the vector */
PyObject *Vector_copy(VectorObject * self)
{
return newVectorObject(self->vec, self->size, Py_NEW);
}
/*----------------------------dealloc()(internal) ----------------
free the py_object */
static void Vector_dealloc(VectorObject * self)
@@ -704,11 +706,12 @@ static PyObject *Vector_div(PyObject * v1, PyObject * v2)
static PyObject *Vector_neg(VectorObject *self)
{
int x;
float vec[4];
for(x = 0; x < self->size; x++){
self->vec[x] = -self->vec[x];
vec[x] = -self->vec[x];
}
return EXPP_incr_ret((PyObject *)self);
return newVectorObject(vec, self->size, Py_NEW);
}
/*------------------------coerce(obj, obj)-----------------------
coercion of unknown types to type VectorObject for numeric protocols
@@ -969,7 +972,7 @@ PyObject *Vector_Negate(VectorObject * self)
for(x = 0; x < self->size; x++) {
self->vec[x] = -(self->vec[x]);
}
printf("Vector.negate(): Deprecated: use -vector instead\n");
/*printf("Vector.negate(): Deprecated: use -vector instead\n");*/
return EXPP_incr_ret((PyObject*)self);
}
/*###################################################################

View File

@@ -62,14 +62,13 @@ blender (stored in blend_data). This is an either/or struct not both*/
//prototypes
PyObject *Vector_Zero( VectorObject * self );
PyObject *Vector_Normalize( VectorObject * self );
PyObject *Vector_Normalized( VectorObject * self );
PyObject *Vector_Negate( VectorObject * self );
PyObject *Vector_Negated( VectorObject * self );
PyObject *Vector_Resize2D( VectorObject * self );
PyObject *Vector_Resize3D( VectorObject * self );
PyObject *Vector_Resize4D( VectorObject * self );
PyObject *Vector_toPoint( VectorObject * self );
PyObject *Vector_ToTrackQuat( VectorObject * self, PyObject * args );
PyObject *Vector_copy( VectorObject * self );
PyObject *newVectorObject(float *vec, int size, int type);
#endif /* EXPP_vector_h */