This argument is optional ; but if you really want to deal with linear transformation matrices, you have to understand how it works.
You could use matrices
in order to compute translation
, scale
and rotation
.
Here, the matrix is a rotational matrix, which expect some value according to the axis you choose given an angle t
(aka theta
) :
for the x axis, the matrix will be
(( 1, 0, 0), (0, cos(t), sin(t), (0, -sin(t), cos(t))
for the y axis, the matrix will be
(( cos(t), 0, -sin(t) ), (0, 1, 0), (sin(t), 0, cos(t))
and for the z axis, you will have ((cos(t), sin(t), 0), (-sin(t), cos(t), 0 ), (0, 0, 1))
If you select the default cube, you can see its transformation matrix:
>>> obj = bpy.context.active_object
>>> obj.matrix_world
Matrix(((1.0, 0.0, 0.0, 0.0),
(0.0, 1.0, 0.0, 0.0),
(0.0, 0.0, 1.0, 0.0),
(0.0, 0.0, 0.0, 1.0)))
Now, you can use a mathutils.Matrix
in order to rotate the object to 20° on the X
axis:
>>> rotation_mat = mathutils.Matrix.Rotation(math.radians(20), 4, 'X')
>>> obj.matrix_world @= rotation_mat
I use the @=
python operator that provide a matrix multiplication
Does anyone know how I am supposed to calculate this arg ?
Now you know how to calculate this arg ; but not how to use it !
The way bpy.ops.transform.rotate use the orient_matrix
argument is not clear ; it seems to have no effect here, because you have to provide the mandatory 1st argument which set the angle value and do the same thing. With the Blender Python API
, Some parameters are historical, some others for future use, and some others are not implemented at all but still documented. You could ask the team because I tried many way to use it without any effect.
Last but not least, playing with Maths is really easy if you read the right book: 3D Math Primer for Game Dev - Fletcher Dunn - 2cd Ed.- 2011 is definitively the best book for anybody having to play with math without any skills. You will find 3 chapters on Matrices, very well explained.