Thursday, December 1, 2022
HomeGame Development3d - How do I transfer an object alongside its native axis?

3d – How do I transfer an object alongside its native axis?


I’m new to laptop graphics and am attempting to make a easy little sport the place I can transfer a dice round with the keyboard. I’ve it so you possibly can rotate the dice with the arrow keys, and I wished to make it transfer ahead, again, left and proper based mostly on which manner it was rotated. I noticed an identical query on right here posted in 2012 (Translate alongside native axis).I attempted to do what they urged, and it solely works when the x, y, and z rotations are 0. If my dice is rotated, it appears to maneuver in a circle. I’m not positive if I misunderstood or if I applied it incorrect.

these are my rotation matrices. the x is the x rotation in levels transformed to radians, and so forth 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 reply of that by z (left to proper 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 these 3 matrices, with ztrans_mat on the left of the rotation matrix.

Lastly, I multiplied

pos= Gf.Vec3d(place.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 interpretation matrix.

Sorry to make this so lengthy, I simply tried to present as a lot info as potential. I’m caught and beginning to get a bit of annoyed, since I really feel so shut but to date.

In case you want any clarification or any further info, please let me know. Thanks upfront for any provide help to may give me!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments