Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 5 down vote accepted
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

share|improve this answer
    
Nice. Thank you pink vertex! I've also added a cam_direction.normalize() and up.normalize(). Works like a charm. –  poor Jul 3 at 18:47
    
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. –  pink vertex Jul 4 at 15:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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