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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 6 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 '14 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 '14 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.