OpenGl rotations and object movement

我怕爱的太早我们不能终老 提交于 2019-12-25 18:24:01

问题


I'm trying to create a very basic planet movement (sun, earth moon represented as cubes).

As for now i managed to move one cube around another, but I have the following question... What will be the best way to move another cube (ex. the moon) around an already moving one?

I put them in motion using simple operations ex. for movement on x axis:

d * Math.sin(x * Math.PI / 180.0)

Where d is the distance from center or projection (dont know if i used this term right). I thought about putting the "satellite" by calulating the distance of the already rotating cube and adding some parameter, but don't know how to make that planet like a "reference" for center of rotation...


回答1:


You do this by creating a composition of transformations. Say you want to orbit a planet around a central star. First the planet is moved into orbit, a translation, in say the x direction:

orbit_distance = translation_orbit · planet_center

followed by a rotation around the center.

orbit_position = rotation_orbit · orbit_distance

Or, you can write this in one line

orbit_position = rotation_orbit · translation_orbit · planet_center

It is important, that the order of operations matter, rotating first and then translating is not the same as first translating and then rotating. Or, in mathematical terms, geometrical transformations are not commutative.

In a 3 dimensional space all linear transformations can be described by linear equations in a 4 dimensional homogenous set of coordinates. I.e. you can use 4×4 matrices to express all kinds of linear geometrical transformations.

A rotatng moon orbiting a planet orbiting a sun:

R_orbit_planet · T_orbit_planet · R_orbit_moon · T_orbit_moon · R_rotation_moon


来源:https://stackoverflow.com/questions/13444111/opengl-rotations-and-object-movement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!