For a long time i used this piece of code for rotation:
function global_rotate_x(obj,ang)
EZro_SetEuler OBJECT ANGLE X(obj),OBJECT ANGLE Y(obj),OBJECT ANGLE Z(obj)
EZro_SetPos OBJECT POSITION X(obj),OBJECT POSITION Y(obj),OBJECT POSITION Z(obj)
EZro_Orbit 1,-90,0,0,90,0,0,ang
EZro_FindEuler
rotate object obj,EZro_GetEulerX(),EZro_GetEulerY(),EZro_GetEulerZ()
position object obj,EZro_GetPosX(),EZro_GetPosY(),EZro_GetPosZ()
endfunction
function global_rotate_y(obj,ang)
EZro_SetEuler OBJECT ANGLE X(obj),OBJECT ANGLE Y(obj),OBJECT ANGLE Z(obj)
EZro_SetPos OBJECT POSITION X(obj),OBJECT POSITION Y(obj),OBJECT POSITION Z(obj)
EZro_Orbit 1,0,-90,0,0,90,0,ang
EZro_FindEuler
rotate object obj,EZro_GetEulerX(),EZro_GetEulerY(),EZro_GetEulerZ()
position object obj,EZro_GetPosX(),EZro_GetPosY(),EZro_GetPosZ()
endfunction
function global_rotate_z(obj,ang)
EZro_SetEuler OBJECT ANGLE X(obj),OBJECT ANGLE Y(obj),OBJECT ANGLE Z(obj)
EZro_SetPos OBJECT POSITION X(obj),OBJECT POSITION Y(obj),OBJECT POSITION Z(obj)
EZro_Orbit 1,0,0,-90,0,0,90,ang
EZro_FindEuler
rotate object obj,EZro_GetEulerX(),EZro_GetEulerY(),EZro_GetEulerZ()
position object obj,EZro_GetPosX(),EZro_GetPosY(),EZro_GetPosZ()
endfunction
Which does the job almost perfectly.Sometimes it does add up fractions of an angle and mess up everything.
For real precission i found out that i need to add or substract from
EZro_GetEulerX(),
EZro_GetEulerY() and
EZro_GetEulerZ(), because when it reach certain point it shift with 1 degree.
Correct code:
function global_rotate_x(obj,ang)
EZro_SetEuler OBJECT ANGLE X(obj),OBJECT ANGLE Y(obj),OBJECT ANGLE Z(obj)
EZro_SetPos OBJECT POSITION X(obj),OBJECT POSITION Y(obj),OBJECT POSITION Z(obj)
EZro_Orbit 1,-90,0,0,90,0,0,ang
EZro_FindEuler
eulerx = EZro_GetEulerX()
eulery = EZro_GetEulerY()
eulerz = EZro_GetEulerZ()
if EZro_GetEulerX() < 0
eulerx = EZro_GetEulerX() -0.5
endif
if EZro_GetEulerX() > 0
eulerx = EZro_GetEulerX() +0.5
endif
if EZro_GetEulerY() < 0
eulery = EZro_GetEulerY() -0.5
endif
if EZro_GetEulerY() > 0
eulery = EZro_GetEulerY() +0.5
endif
if EZro_GetEulerZ() < 0
eulerz = EZro_GetEulerZ() -0.5
endif
if EZro_GetEulerZ() > 0
eulerz = EZro_GetEulerZ() +0.5
endif
rotate object obj,eulerx,eulery,eulerz
position object obj,EZro_GetPosX(),EZro_GetPosY(),EZro_GetPosZ()
endfunction
function global_rotate_y(obj,ang)
EZro_SetEuler OBJECT ANGLE X(obj),OBJECT ANGLE Y(obj),OBJECT ANGLE Z(obj)
EZro_SetPos OBJECT POSITION X(obj),OBJECT POSITION Y(obj),OBJECT POSITION Z(obj)
EZro_Orbit 1,0,-90,0,0,90,0,ang
EZro_FindEuler
eulerx = EZro_GetEulerX()
eulery = EZro_GetEulerY()
eulerz = EZro_GetEulerZ()
if EZro_GetEulerX() < 0
eulerx = EZro_GetEulerX() -0.5
endif
if EZro_GetEulerX() > 0
eulerx = EZro_GetEulerX() +0.5
endif
if EZro_GetEulerY() < 0
eulery = EZro_GetEulerY() -0.5
endif
if EZro_GetEulerY() > 0
eulery = EZro_GetEulerY() +0.5
endif
if EZro_GetEulerZ() < 0
eulerz = EZro_GetEulerZ() -0.5
endif
if EZro_GetEulerZ() > 0
eulerz = EZro_GetEulerZ() +0.5
endif
rotate object obj,eulerx,eulery,eulerz
position object obj,EZro_GetPosX(),EZro_GetPosY(),EZro_GetPosZ()
endfunction
function global_rotate_z( obj,ang)
EZro_SetEuler OBJECT ANGLE X(obj),OBJECT ANGLE Y(obj),OBJECT ANGLE Z(obj)
EZro_SetPos OBJECT POSITION X(obj),OBJECT POSITION Y(obj),OBJECT POSITION Z(obj)
EZro_Orbit 1,0,0,-90,0,0,90,ang
EZro_FindEuler
eulerx = EZro_GetEulerX()
eulery = EZro_GetEulerY()
eulerz = EZro_GetEulerZ()
if EZro_GetEulerX() < 0
eulerx = EZro_GetEulerX() -0.5
endif
if EZro_GetEulerX() > 0
eulerx = EZro_GetEulerX() +0.5
endif
if EZro_GetEulerY() < 0
eulery = EZro_GetEulerY() -0.5
endif
if EZro_GetEulerY() > 0
eulery = EZro_GetEulerY() +0.5
endif
if EZro_GetEulerZ() < 0
eulerz = EZro_GetEulerZ() -0.5
endif
if EZro_GetEulerZ() > 0
eulerz = EZro_GetEulerZ() +0.5
endif
rotate object obj,eulerx,eulery,eulerz
position object obj,EZro_GetPosX(),EZro_GetPosY(),EZro_GetPosZ()
endfunction
Coding is My Kung Fu!
And My Kung Fu is better than Yours!