I am new to computer graphics and am trying to make a simple little game where I can move a cube around with the keyboard. I have it so you can rotate the cube with the arrow keys, and I wanted to make it move forward, back, left and right based on which way it was rotated. I saw a similar question on here posted in 2012 (Translate along local axis).I tried to do what they suggested, and it only works when the x, y, and z rotations are 0. If my cube is rotated, it seems to move in a circle. I am not sure if I misunderstood or if I implemented it wrong.
these are my rotation matrices. the x is the x rotation in degrees converted to radians, and so on for y and z.
xrot_mat = [[1,0,0,0],[0,np.cos(x*CONVERT),np.sin(x*CONVERT),0],[0,-np.sin(x*CONVERT),np.cos(x*CONVERT),0],[0,0,0,1]]
xrot_mat = np.array(xrot_mat)
yrot_mat = [[np.cos(y*CONVERT),0,-np.sin(y*CONVERT),0],[0,1,0,0],[np.sin(y*CONVERT),0,np.cos(y*CONVERT),0],[0,0,0,1]]
yrot_mat = np.array(yrot_mat)
zrot_mat = [[np.cos(z*CONVERT),np.sin(z*CONVERT),0,0],[-np.sin(z*CONVERT),np.cos(z*CONVERT),0,0],[0,0,1,0],[0,0,0,1]]
zrot_mat = np.array(zrot_mat)
I multiplied the x by the y and the answer of that by z (left to right order: x,y,z).
I then multiplied
ztrans_mat = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,1,1]] ztrans_mat = np.array(ztrans_mat)
by the product of those 3 matrices, with ztrans_mat on the left of the rotation matrix.
Finally, I multiplied
pos= Gf.Vec3d(position.Get())
fourd= Gf.Vec4d(pos[0],pos[1],pos[2],1)
with fourd (the cubes x, y, and z coordinate) on the left of the rotation matrix multiplied by the translation matrix.
Sorry to make this so long, I just tried to give as much information as possible. I am stuck and starting to get a little frustrated, since I feel so close yet so far.
If you need any clarification or any additional information, please let me know. Thank you in advance for any help you can give me!