===Python API===

Allow object.setMatrix() to accept 3x3 matrices by extending to a 4x4
internally.  Also check the dimensions of the new matrix and throw an
exception if not a 3x3 or 4x4.
This commit is contained in:
Ken Hughes
2006-02-16 20:09:32 +00:00
parent fe036a0538
commit 7592c09c2b
2 changed files with 23 additions and 7 deletions

View File

@@ -2197,11 +2197,26 @@ static PyObject *Object_setMatrix( BPy_Object * self, PyObject * args )
( PyExc_TypeError,
"expected matrix object as argument" );
for( x = 0; x < 4; x++ ) {
for( y = 0; y < 4; y++ ) {
self->object->obmat[x][y] = mat->matrix[x][y];
if( mat->rowSize == 4 && mat->colSize == 4 ) {
for( x = 0; x < 4; x++ ) {
for( y = 0; y < 4; y++ ) {
self->object->obmat[x][y] = mat->matrix[x][y];
}
}
}
} else if( mat->rowSize == 3 && mat->colSize == 3 ) {
for( x = 0; x < 3; x++ ) {
for( y = 0; y < 3; y++ ) {
self->object->obmat[x][y] = mat->matrix[x][y];
}
}
/* if a 3x3 matrix, clear the fourth row/column */
for( x = 0; x < 3; x++ )
self->object->obmat[x][3] = self->object->obmat[3][x] = 0.0;
self->object->obmat[3][3] = 1.0;
} else
return EXPP_ReturnPyObjError ( PyExc_ValueError,
"expected 3x3 or 4x4 matrix" );
apply_obmat( self->object );
/* since we have messed with object, we need to flag for DAG recalc */

View File

@@ -696,9 +696,10 @@ class Object:
def setMatrix(matrix):
"""
Sets the object's matrix and updates it's transformation.
@type matrix: Py_Matrix 4x4
@param matrix: a python matrix 4x4.
Sets the object's matrix and updates its transformation.
@type matrix: Py_Matrix 3x3 or 4x4
@param matrix: a 3x3 or 4x4 Python matrix. If a 3x3 matrix is given,
it is extended to a 4x4 matrix.
"""
def setName(name):