diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-09-07 11:55:36 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-09-07 11:55:36 +0400 |
commit | 8a11629602990a8c3a793d2509eb20ec6394d0e5 (patch) | |
tree | 46252cc7ed4e66259315b8237ebfb6bf74e2d03f /source | |
parent | 0ba5295404dd1c2ee04a9e7823eafc664562f4eb (diff) |
matrix to scale fixes from stable
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/api2_2x/Object.c | 31 | ||||
-rw-r--r-- | source/blender/python/api2_2x/matrix.c | 19 |
2 files changed, 36 insertions, 14 deletions
diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 0c2f9ed9634..b02a932aa39 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -1368,29 +1368,40 @@ static int Object_setParentBoneName( BPy_Object * self, PyObject *value ) static PyObject *Object_getSize( BPy_Object * self, PyObject * args ) { char *space = "localspace"; /* default to local */ - + PyObject *attr; if( !PyArg_ParseTuple( args, "|s", &space ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, "expected a string or nothing" ); if( BLI_streq( space, "worldspace" ) ) { /* Worldspace matrix */ - float scale[3]; + float rot[3]; + float mat[3][3], imat[3][3], tmat[3][3]; disable_where_script( 1 ); where_is_object( self->object ); - Mat4ToSize(self->object->obmat, scale); - return Py_BuildValue( "fff", - self->object->size[0], - self->object->size[1], - self->object->size[2] ); + + Mat3CpyMat4(mat, self->object->obmat); + + /* functionality copied from editobject.c apply_obmat */ + Mat3ToEul(mat, rot); + EulToMat3(rot, tmat); + Mat3Inv(imat, tmat); + Mat3MulMat3(tmat, imat, mat); + + attr = Py_BuildValue( "fff", + tmat[0][0], + tmat[1][1], + tmat[2][2] ); disable_where_script( 0 ); } else if( BLI_streq( space, "localspace" ) ) { /* Localspace matrix */ - return Py_BuildValue( "fff", + attr = Py_BuildValue( "fff", self->object->size[0], self->object->size[1], self->object->size[2] ); - } - return EXPP_ReturnPyObjError( PyExc_ValueError, + } else { + return EXPP_ReturnPyObjError( PyExc_ValueError, "expected either nothing, 'localspace' (default) or 'worldspace'" ); + } + return attr; } static PyObject *Object_getTimeOffset( BPy_Object * self ) diff --git a/source/blender/python/api2_2x/matrix.c b/source/blender/python/api2_2x/matrix.c index 6a427bfe7f6..fadadbb5c6a 100644 --- a/source/blender/python/api2_2x/matrix.c +++ b/source/blender/python/api2_2x/matrix.c @@ -202,16 +202,27 @@ PyObject *Matrix_RotationPart(MatrixObject * self) /*---------------------------Matrix.scalePart() --------------------*/ PyObject *Matrix_scalePart(MatrixObject * self) { - float scale[3]; - + float scale[3], rot[3]; + float mat[3][3], imat[3][3], tmat[3][3]; + /*must be 3-4 cols, 3-4 rows, square matrix*/ if(self->colSize == 4 && self->rowSize == 4) - Mat4ToSize((float (*)[4])*self->matrix, scale); + Mat3CpyMat4(mat, (float (*)[4])*self->matrix); else if(self->colSize == 3 && self->rowSize == 3) - Mat3ToSize((float (*)[3])*self->matrix, scale); + Mat3CpyMat3(mat, (float (*)[3])*self->matrix); else return EXPP_ReturnPyObjError(PyExc_AttributeError, "Matrix.scalePart(): inappropriate matrix size - expects 3x3 or 4x4 matrix\n"); + + /* functionality copied from editobject.c apply_obmat */ + Mat3ToEul(mat, rot); + EulToMat3(rot, tmat); + Mat3Inv(imat, tmat); + Mat3MulMat3(tmat, imat, mat); + + scale[0]= tmat[0][0]; + scale[1]= tmat[1][1]; + scale[2]= tmat[2][2]; return newVectorObject(scale, 3, Py_NEW); } /*---------------------------Matrix.invert() ---------------------*/ |