All pastes #48760 Raw Edit

Something

public text v1 · immutable
#48760 ·published 2006-04-09 16:04 UTC
rendered paste body
################################################
##   Simple use of setOrientation()
##  by Spike1907
##  March 11th, 2006
################################################

from GameLogic import getCurrentController as GCC
from math import atan2, asin, sin, cos, radians, degrees

o = GCC().getOwner()

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))

def eulerToMat(I, J, K):
    A , B = sin(I), cos(I)
    C , D = sin(J), cos(J)
    E , F = sin(K), cos(K)
    AC, BC = A*C, B*C
    return [[D*F     , D*E       , -C],
          [AC*F-B*E, AC*E+B*F, A*D],
          [BC*F+A*E, BC*E-A*F, B*D]]
      
o.setOrientation( eulerToMat(45,0,0) )