Results 1 to 13 of 13

Thread: getOrientation() => RotX, RotY, RotZ

  1. #1

    getOrientation() => RotX, RotY, RotZ

    Hi,

    I want to get X, Y, Z orientation from getOrientation() matrix.
    With only 2 axis i understand how to manage it, but with Z axis, i swim ...

    So Could you help me to get values like in blender 3D viewport in the Popup Transofmr properties (N key)

    Thx
    Adrien



  2. #2
    Hello,

    i hope i dont misunderstand but in walkthrough demo use an orientation matrix and u go where u look if u in fly mode. for me works only in sumo physics.


    http://www.blender3d.org/_media/gall...alkthrough.zip

    Regards,

    tL



  3. #3
    Member blendenzo's Avatar
    Join Date
    Apr 2006
    Location
    Michigan, USA
    Posts
    2,702
    I believe [a]drien is looking for a way to get the euler angles from the orientation matrix. I remember reading about a way to do this before, but I don't remember where I read it or how it was done. If I come across it, I will let you know.
    "From somewhere, a transmission..."
    Game Engine tutorials: TutorialsForBlender3D - blendenzo.com - blending-online
    My Projects: Escape the Room - Brought2Life - UpRight - Solomon's Treasure - Sokoban - Marble Labyrinth



  4. #4
    Member Social's Avatar
    Join Date
    Nov 2005
    Location
    New Jersey, USA
    Posts
    3,596
    Originally Posted by blendenzo View Post
    I believe [a]drien is looking for a way to get the euler angles from the orientation matrix. I remember reading about a way to do this before, but I don't remember where I read it or how it was done. If I come across it, I will let you know.
    I believe you are reffering to the PDF by herman.

    You can find it in this thread, but you better have a good backing in basic matrix math and trigonometry. The document is very usefull for it's python examples/methods, but it assumes quite a bit of knowledge on the readers end.
    It is in the nature of powerless people to vicariously enjoy the exercise of arbitrary power by others.

    - Dmitry Orlov



  5. #5
    Yeah, he has a python function in there for getting euler angles but you'll have to retype it because it's in the 2 column pdf format. I would definately download it. It has about 3 blend files with rotation examples plus some functions in the pdf that are very valuable. The explanations are a little technical, but just take your time and you'll be fine, or you can just use the python code and remain blissfully ignorant.
    Last edited by fireside; 07-Sep-06 at 01:55.



  6. #6
    Member IzE_Design's Avatar
    Join Date
    Jul 2006
    Location
    Italy (Cesena)
    Posts
    37
    i have a similar problem... i must rotate an object on only 1 axis... X or Y or Z but i dont have understand how to do to use setOrientation... if i use
    Code:
    setOrientation(Quaternion([0,0,1],Angle_Degree))
    all work right BUT only in BLENDER, out, in stand alone dont work....
    i see this code in example:
    Code:
    #---------------------------------------------
    # Flips the conected object so that it's
    # z-axes point up and the y-axis point in 
    # the same direction (viewed from the top).
    #---------------------------------------------
    
    from GameLogic import *
    from math import *
    
    controller = getCurrentController()
    owner = controller.getOwner()
    
    R = owner.getOrientation()
    
    #Take the second column (we do not need R[2][1])
    R01 = R[0][1]
    R11 = R[1][1]
    
    S = sqrt(R11*R11 + R01*R01)
    
    #Construct the new matrix
    R1 = [[R11/S, R01/S, 0], [-R01/S, R11/S, 0], [0, 0, 1]]
    
    owner.setOrientation(R1)
    but where i must Edit this code for insert the value in Degree of 1 Axis for rotate this object in that axis??? the other axis is equal zero...
    POWER OF BLENDER!
    www.izedesign.it




  7. #7
    I use this code for rotation:
    Code:
    def degrees(alpha,beta,gamma):
        alpha = -alpha * math.pi/180
        beta = beta * math.pi/180
        gamma = -gamma * math.pi/180
        a = math.cos(alpha)
        b = math.sin(alpha)
        c = math.cos(beta)
        d = math.sin(beta)
        e = math.cos(gamma)
        f = math.sin(gamma)
        ad = a*d
        bd = b*d
        mat = [[c*e, -a*f+b*d*e, b*f+a*d*e],
        [c*f, a*e+b*d*f, -b*e+a*d*f],[-d, b*c, a*c]]
        return mat
    That's on an absolute type rotation. If you want a local rotation you have to multiply it by the objects orientation. alpha is the x plane, beta is the y plane, gamma is the z plane, it changes the degree values to radians and builds the matrix. I have it set so the rotations are clockwise in the blender 1,3,7 views. That was typed from Herman's tutorial and edited a little bit. So if you object.setOrientation(degrees(0,0,90)). It will rotate it on the z plane 90 degrees absolute.
    Last edited by fireside; 08-Sep-06 at 13:45.



  8. #8
    and the inverse ( Matrix > degres ) ???



  9. #9
    You can try this one. I haven't used it so I can't say anything about it.
    Code:
    def matToEuler():
        ori = GCC().getOwner().getOrientation()
        J = -asin(ori[0][2])
        cJ = cos(J)
        if cJ!=0.0:
            cJ = 1.0/cJ
            I = atan2(ori[1][2] * cJ , ori[2][2] * cJ)
            K = atan2(ori[0][1] * cJ , ori[0][0] * cJ)
            return (degrees(I) , degrees(J) , degrees(K))
    You'd have to change that orientation variable to fit your aplication. I don't have the degree function, but it's just a conversion from radian to degree. See the other def. Basicly, multiply by pi and divide by 180. No that's degree to radian, I think it's mult by 180 and divide by pi, you'll have to look it up. I'd be more inclined to use the one in Herman's tutorial, though, but you'll have to type it out from his pdf.
    Last edited by fireside; 08-Sep-06 at 15:06.



  10. #10
    well, i've already try this script and it's not working or i don't use it correctly



  11. #11

    Is it too late?

    Hello, I know it has been a while since someone posted this thread, but I was looking for the same answer and after suffering a bit I got it.

    To get just one axis angle I converted my rotation matrix that I got from KX_GameObject.getOrientation() to euler.
    How to do this? simple (not to discover how )

    if you look at blenders documentation on KX_GameObject.getOrientation() it says: "Note: When using this matrix with Blender.Mathutils.Matrix() types, it will need to be transposed." here is the trick!
    First you have to create a matrix, otherwise you won't be able to simply convert it to euler.
    So do this:

    Code:
    # creates matrix from KX_GameObject obj
    tempMatrix = Matrix(obj.getOrientation()[0],obj.getOrientation()[1],obj.getOrientation()[2])
    
    # transpose matrix and convert it to euler
    euler = tempMatrix.transpose().toEuler()
    
    # get the angle in Y axis (you can choose your prefered axis
    print euler.x
    Quite easy, huh?

    Regards,
    lk0



  12. #12
    Member
    Join Date
    Jun 2007
    Location
    Philadelphia, PA, USA
    Posts
    21
    I just spent two days looking for this kind of answer.
    Right now, over a year later, you are my best friend.

    Thank you.



  13. #13
    Lalala. Don't really know how old this thread is, but if anyone needs help, you can check these links out.

    http://www.luma.co.za/labs/blender_o...on_matrix.html
    http://sites.google.com/site/socials...nmatrix-basics

    Both of those links are amazing.
    Check out my website! Whole new look! | I am also in the midst of building this site | My blog
    I love Blender because it has giving me so much that even a commercial product like Flash could not.
    PlantPerson is my hero.



Similar Threads

  1. Scripted Effect Workshop
    By Gabio in forum Python Support
    Replies: 26
    Last Post: 18-Dec-05, 17:30
  2. Rotx, Roty, Rotz
    By anonyme7 in forum Animation and Rigging
    Replies: 4
    Last Post: 15-Oct-05, 13:10
  3. panorama tutorial made
    By macouno in forum Blender and CG Discussions
    Replies: 56
    Last Post: 03-May-05, 08:21
  4. globubot animation
    By macouno in forum Works in Progress
    Replies: 9
    Last Post: 24-Dec-04, 12:45

Posting Permissions

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