Results 1 to 5 of 5

Thread: Euler Angle / Camera Rotation / Camera Direction

  1. #1

    Euler Angle / Camera Rotation / Camera Direction

    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,
    Last edited by ROm222; 31-Mar-07 at 18:33.



  2. #2
    Member Crouch's Avatar
    Join Date
    Oct 2004
    Location
    the Netherlands
    Posts
    1,414
    *bump*
    I'm quite curious for a solution to this 'problem' as well, so perhaps an enlightened mind can reply?



  3. #3
    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()
    Last edited by ROm222; 14-Apr-07 at 05:07.



  4. #4
    Member ideasman42's Avatar
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    5,338
    You could use the cameras transformation matrix to work it out.
    camera_view = (Vector(0,0,-1) * ob.matrixWorld).toEuler()
    Podcast * dotfiles * My Wiki * Blender/Stackexchange
    ideasman42<at>gmail.com



  5. #5
    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,



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •