3
$\begingroup$

How to calculate the camera direction and up vector by the position and rotation?

$\endgroup$
7
$\begingroup$
import bpy
from mathutils import Vector

cam = bpy.data.objects['Camera']
up = cam.matrix_world.to_quaternion() * Vector((0.0, 1.0, 0.0))
cam_direction = cam.matrix_world.to_quaternion() * Vector((0.0, 0.0, -1.0))

cam coordinates

$\endgroup$
  • $\begingroup$ Nice. Thank you pink vertex! I've also added a cam_direction.normalize() and up.normalize(). Works like a charm. $\endgroup$ – p2or Jul 3 '14 at 18:47
  • $\begingroup$ Since it uses .to_quaternion, calling normalize should be unnecessary because a pure rotation preserves the length of a vector, which equals 1.0 in both of these cases. $\endgroup$ – pink vertex Jul 4 '14 at 15:32

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.