hi
can anyone help me?
I need Pyhon sc. witch is able add rotation to object by 90°.(in game engine)
(I’m trying post script by my self, but without goal in this time)
in this case I haven’t us IPO or Armature.
thanks jm
hi
can anyone help me?
I need Pyhon sc. witch is able add rotation to object by 90°.(in game engine)
(I’m trying post script by my self, but without goal in this time)
in this case I haven’t us IPO or Armature.
thanks jm
import GameLogic
from math import *
cont = GameLogic.getCurrentController()
own = cont.getOwner()
#---ANGLE
alpha = pi
#---CONDITIONS
def mulmat(a, b) :
m00 = a[0][0]*b[0][0]+a[0][1]*b[1][0]+a[0][2]*b[2][0]
m10 = a[1][0]*b[0][0]+a[1][1]*b[1][0]+a[1][2]*b[2][0]
m20 = a[2][0]*b[0][0]+a[2][1]*b[1][0]+a[2][2]*b[2][0]
m01 = a[0][0]*b[0][1]+a[0][1]*b[1][1]+a[0][2]*b[2][1]
m11 = a[1][0]*b[0][1]+a[1][1]*b[1][1]+a[1][2]*b[2][1]
m21 = a[2][0]*b[0][1]+a[2][1]*b[1][1]+a[2][2]*b[2][1]
m02 = a[0][0]*b[0][2]+a[0][1]*b[1][2]+a[0][2]*b[2][2]
m12 = a[1][0]*b[0][2]+a[1][1]*b[1][2]+a[1][2]*b[2][2]
m22 = a[2][0]*b[0][2]+a[2][1]*b[1][2]+a[2][2]*b[2][2]
m = [[m00,m01,m02],[m10,m11,m12],[m20,m21,m22]]
return m
#---MAIN
matx = own.getOrientation()
rotmatx = [[cos(alpha), 0, -sin(alpha)],[0,1, 0],[sin(alpha), 0, cos(alpha)]]
newori = mulmat(matx,rotmatx)
own.setOrientation(newori)
-this work for the x axe
import GameLogic
from math import *
cont=GameLogic.getCurrentController()
own=cont.getOwner()
######## Matrix2Euler ########
mat = own.getOrientation()
size = [1,1,1]
def mat2euler(mat, size):
scale = [0.0, 0.0, 0.0]
if size[0]!=0.0:
scale[0] = 1.0/size[0]
if size[1]!=0.0:
scale[1] = 1.0/size[1]
if size[2]!=0.0:
scale[2] = 1.0/size[2]
angle_y = -asin(mat[0][2] * scale[0])
C = cos(angle_y)
if abs(angle_y)>1.0e-10:
C = 1.0/C
angle_x = atan2((mat[1][2] * scale[1]) * C, (mat[2][2] * scale[2]) * C)
angle_z = atan2((mat[0][1] * scale[0]) * C, (mat[0][0] * scale[0]) * C)
else:
angle_x = 0.0
angle_z = -atan2((mat[1][0] * scale[1]), (mat[1][1] * scale[1]))
return (angle_x, angle_y, angle_z)
def euler2mat(rot_x,rot_y,rot_z):
A = cos(rot_x)
B = sin(rot_x)
C = cos(rot_y)
D = sin(rot_y)
E = sin(rot_z)
F = cos(rot_z)
AD = A * D
BD = B * D
ori = [[C*E,-C*F,-D],[-BD*E+A*F,BD*F+A*E,-B*C],[AD*E+B*F,-AD*F+B*E,A*C]]
return (ori)
rot = mat2euler(mat,size)
rot_x = rot[0]
rot_y = rot[1]
rot_z = rot[2]
######## Functions ########
#rotated by 90 degrees
rot_y = rot_y + pi #change the axes and the angle
ori = euler2mat(rot_x,rot_y,rot_z)
own.setOrientation(ori)
-this one in all axes by “changing the axes and value”
Ben
hi Ben
thanks alot for your script
your assistance is very helpfull for me.
thanks jm
am so sorry, but…
please can you tell me which data schould I change
thanks jm
-In the first example :
alpha = pi
by changing pi (pi/2, pi/4 etc) ,will have a different
angle of rotation.
-In the second one (third row from the end):
rot_y = rot_y + pi #change the axes and the angle
if you write instead:
rot_x = rot_x + pi /2
,will receive 90 degree rotation around x instead
of 180 degrees around y.
rot_z = rot_z + pi /2
90 degrees in z
aha
I can understand…am runinig try this help.
thanks jm
I don’t know why, but when I have an IPO in the object, the script not working. That’s no problem, I cancled the IPO and replaced with your script.
I should say Thak You again.
jm
-If, it’s a rotation IPO, has its own rotation
for each frame.So the script can’t work if the
IPO is active.