How to calculate the camera direction and up vector by the position and rotation?
7
$\begingroup$
$\endgroup$
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))
-
$\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
, callingnormalize
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