 # Euler Angle / Camera Rotation / Camera Direction

I am trying to determine the target position (view position) of a Blender Camera so I do this:

cam = Blender.Object.Get(“Camera”)
loc = cam.loc # Camera Position
rot = cam.rot # Camera Rotation in Euler Angle

# Then I calculate the camera view position by doing this:

loc = loc + (1.0 - math.cos( rot ) )
loc = loc + (1.0 - math.cos( rot ) )
loc = loc + (1.0 - math.cos( rot ) )

The result obviously doesn’t seems to work… what Im doing wrong!?

Cheers,

bump
I’m quite curious for a solution to this ‘problem’ as well, so perhaps an enlightened mind can reply?

Ok, in order to reply to my own post… there’s the code to get the target position…

It’s working fine if the camera rotX is about 45 degree but every other value the calculation is wrong… can someone point me out why?

Cheers,

import math
import Blender
import Blender.NMesh

cam = Blender.Object.Get(“Camera”)
loc = cam.loc
rot = cam.rot

obj = Blender.Object.GetSelected()
me = Blender.NMesh.GetRawFromObject( obj.name )

dd = 1.0
x = loc - dd * math.cos(rot) * math.sin(rot)
y = loc + dd * math.cos(rot) * math.cos(rot)
z = loc - dd * math.sin(rot)

obj.LocX = x
obj.LocY = y
obj.LocZ = z

me.transform( obj.matrix )
me.update()

Blender.Redraw()

You could use the cameras transformation matrix to work it out.
camera_view = (Vector(0,0,-1) * ob.matrixWorld).toEuler()

My god I was far fetched with that one… finally it turns out that just:

t_pos = ( Blender.Mathutils.Vector(0, 0, -1) * cam.matrixWorld )

it’s alright

Cheers ideasman42,