OpenGl旋转和对象移动 [英] OpenGl rotations and object movement

查看:91
本文介绍了OpenGl旋转和对象移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个非常基本的行星运动(太阳,地球月亮表示为立方体).

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?

我使用简单的操作ex使它们运动.在x轴上移动:

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

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

其中d是距中心或投影的距离(不知道我是否正确使用了该术语). 我曾考虑过通过计算已经旋转的立方体的距离并添加一些参数来放置卫星",但不知道如何使该行星像旋转中心的参考"一样.

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...

推荐答案

您可以通过创建转换组合来实现.假设您想绕一颗中心恒星绕行星运行.首先,行星进入x方向的平移,进入轨道:

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

然后绕着中心旋转.

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.

在3维空间中,所有线性变换都可以通过4维同构坐标集中的线性方程来描述. IE.您可以使用4×4矩阵表示各种线性几何变换.

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

这篇关于OpenGl旋转和对象移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆