[Bf-python] Mathutils.

Joseph Gilbert models at paposo.com
Sun Feb 15 14:25:41 CET 2004


Doh!  All values passed to EulToMat3 and EulToQuat need to be in radians not
in degrees. :p  So you would do this:
static PyObject *Euler_ToMatrix(EulerObject *self, PyObject *args)
{
	float *mat;
	int x;

	for(x = 0; x < 3; x++){
		self->eul[x] *= (Py_PI/180);
	}
	mat = PyMem_Malloc(3*3*sizeof(float));
	EulToMat3(self->eul, mat);
	for(x = 0; x < 3; x++){
		self->eul[x] *= (180/Py_PI);
	}
	return newMatrixObject(mat,3,3);
}

which returns the correct result. Yea! You can fix the toQuat() and
toMatrix() now in the Euler class.

There is one other problem though.
Mathutils.RotateEuler() still has problems. I figured out why though. Let's
say do this:

eul = Euler([90,0,0])
eul[2] += 50

print eul
(output) [90,0,50]

This is equivalent to adding a 50 degree rotation around the 'z' right?
If we do this though:

RotateEuler(eul, 90, 'z')
print eul
(output) [90, -50, 0]

which is not an equivalent rotation. I was trying to figure out why and I
found the problem. In the function euler_rot() in arthrib.c there is a line:

...
Mat3MulMat3(totmat, mat2, mat1);
....

if you change the multiplication order to:
...
Mat3MulMat3(totmat, mat1, mat2);
....

Everything works out o.k. This will even return unique euler rotations.
Example:

eul = Euler([90,0,0])
eul[1] += 567;
eul[2] += 789;
eul.unique()
print eul

(output) [-90, -27, -111]

You can also do the same with the (fixed) RotateEuler function.

eul = Euler([90,0,0])
RotateEuler(eul, 567, 'y')
RotateEuler(eul, 789, 'z')
print eul

(output) [-90, -27, -111]

However if you leave the multiplication order as 2:1 (as it is now) you get

(output) [90, -69, -153]

I'll attach the modified files for the fix to mathutils and euler.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eulerFix.zip
Type: application/x-zip-compressed
Size: 9255 bytes
Desc: not available
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20040215/ea87badd/attachment.bin>


More information about the Bf-python mailing list