PDA

View Full Version : Euler Angle / Camera Rotation / Camera Direction



ROm222
28-Mar-07, 19:21
Please help!

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


# rot[0] = rot[0] * RAD_TO_DEG # Convert Euler To Degree
# rot[1] = rot[1] * RAD_TO_DEG # Convert Euler To Degree
# rot[2] = rot[2] * RAD_TO_DEG # Convert Euler To Degree


# Then I calculate the camera view position by doing this:
loc[0] = loc[0] + (1.0 - math.cos( rot[0] ) )
loc[1] = loc[1] + (1.0 - math.cos( rot[1] ) )
loc[2] = loc[2] + (1.0 - math.cos( rot[2] ) )


The result obviously doesn't seems to work.... what Im doing wrong!?

Tks in advance,

Cheers,

Crouch
02-Apr-07, 02:07
*bump*
I'm quite curious for a solution to this 'problem' as well, so perhaps an enlightened mind can reply?

ROm222
14-Apr-07, 03:58
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()[0]
me = Blender.NMesh.GetRawFromObject( obj.name )

dd = 1.0
x = loc[0] - dd * math.cos(rot[0]) * math.sin(rot[2])
y = loc[1] + dd * math.cos(rot[0]) * math.cos(rot[2])
z = loc[2] - dd * math.sin(rot[0])

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

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

Blender.Redraw()

ideasman42
14-Apr-07, 06:49
You could use the cameras transformation matrix to work it out.
camera_view = (Vector(0,0,-1) * ob.matrixWorld).toEuler()

ROm222
14-Apr-07, 17:40
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,