I have a camera with an object constraint to track an empty plain axes. I want to get the camera's current rotation, since when the axes move, or when the camera changes location, the camera rotates in order to track the axes.

however, when I read the value using C.scene.camera.rotation_euler, the values never change, even though the camera clearly has rotated in order to follow the axes.

>>> C.scene.camera.rotation_euler
Euler((-0.2408553957939148, -0.0, 0.0), 'XYZ')

How do I get the correct values of the camera rotation? tracking axes, original position

axes move, camera rotation values are unchanged


Use the matrices

Use the cameras matrices to get the visual transform. For global transform use ob.matrix_world

>>> C.scene.camera.matrix_world.to_euler()
Euler((1.1093189716339111, -0.0, 0.8149281740188599), 'XYZ')

>>> C.scene.camera.matrix_local.to_euler()
Euler((1.1093189716339111, -0.0, 0.8149281740188599), 'XYZ')

The matrix can be decomposed to location, rotation and scale. The quaternion rotation can be converted to Euler if need be.

>>> loc, rot, scale = C.scene.camera.matrix_world.decompose()
>>> rot
Quaternion((0.7804827094078064, 0.483536034822464, 0.20870360732078552, 0.33687159419059753))

>>> rot.to_euler()
Euler((1.1093189716339111, 4.011331711240018e-09, 0.8149281740188599), 'XYZ')
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.