Hello and sorry if my question is repetitive, Im building my first 3D engine using python and pygame for the graphics. the main 3D transformation is:
def param(x,y,z):
vec_rx = rotate_x((x,y,z), angle_x)
vec_ry = rotate_y(vec_rx , angle_y)
vec = rotate_z(vec_ry , angle_z)
return ((zoom * vec[0])/(70-vec[2]) + win_width/2,( (zoom * vec[1])/(70-vec[2]) ) + win_height/2)
70 is for the distance from the origin. the rotation is by multiplying matrices:
def rotate_x(vec,angle):
a = vec[0]
b = vec[1]*math.cos(angle) - vec[2]*math.sin(angle)
c = vec[1]*math.sin(angle) + vec[2]*math.cos(angle)
return (a,b,c)
def rotate_y(vec,angle):
a = vec[0]*math.cos(angle) + vec[2]*math.sin(angle)
b = vec[1]
c = -vec[0]*math.sin(angle) + vec[2]*math.cos(angle)
return (a,b,c)
def rotate_z(vec,angle):
a = vec[0]*math.cos(angle) - vec[1]*math.sin(angle)
b = vec[0]*math.sin(angle) + vec[1]*math.cos(angle)
c = vec[2]
return (a,b,c)
the angles are 3 global parameters changing with keyboard/mouse input. when the angles are zero the rotation is perfect around each axis but when not zero the object is not rotating around the axis but some weird offset. that might be gimbal lock though im not sure.
here is an example of the 3d engine in my project made in desmos: https://www.desmos.com/calculator/8by2wg0cek you can play with the angles and see a similar effect.
is there anything im missing in order to make perfect rotations around the axis?
thank you very much!