如何将多个对象分组以将它们作为一个单元旋转? [英] How to group multiple objects for purpose of rotating them as a unit?

查看:26
本文介绍了如何将多个对象分组以将它们作为一个单元旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些有关在 OpenGL 中执行旋转任务的最佳方法的指示.我知道如何使用四元数在 3D 空间中旋转对象,我可以很好地翻译它们.

I need some pointers on the best approach for a rotation task in OpenGL. I know how to rotate objects in 3D space using quaternions, I can translate them, all well and good.

但我想知道将不同对象的集合视为单个实体以进行旋转的最佳方法.例如,假设您有一张桌子,上面放着物品.每个都有自己的平移和旋转,但现在我想旋转整个桌子和上面的所有东西,同时保持房间里的其他物体到位.这意味着桌子外边缘的物体将旋转并围绕桌子中心平移,而中心的物体可能只是旋转但否则会保持原位,或者根本不会平移那么多,具体取决于它们与桌子的距离旋转轴.

But I want to know the best way to treat a collection of different objects as a single entity for the purpose of rotation. For example, suppose you have a desk with objects on it. Each has its own translation and rotation, but now I want to rotate the entire desk and everything on it, while keeping other objects in the room in place. This means objects on the outer edge of the desk will rotate and also translate around the center of the desk, while objects at the center might just rotate but otherwise stay in place, or simply not translate by as much, depending on their distance from the axis of rotation.

这样做的一种相当不优雅的方法是单独旋转和平移桌子上的每个对象,以及桌子本身,知道旋转轴的位置.也许这是唯一的好方法,但是有没有一种技术可以为此目的分组"不同的对象?

It seems that a rather inelegant way to do this is to individually rotate and translate each object on the desk, as well as the desk itself, knowing where the axis of rotation is. Perhaps this is the only good way to do it, but is there a technique to "group" disparate objects for this purpose?

推荐答案

您正在寻找的是转换层次结构.桌子上的对象相对于桌子定位,或者换句话说,在桌子的坐标系中.所以让我们指定 M_Desk 作为定义桌子位置和它的局部坐标系的转换.接下来是 M_Pencilbox 立在桌子上的铅笔盒相对于桌子的变换.铅笔盒中的铅笔将相对于铅笔盒放置.

What you're looking for are transformation hierachies. The objects on your desk are positioned relative to the desk, or in other words in the coordinate system of the desk. So lets designate M_Desk as the transformation defining the placement of the desk and the local coordinate system of it. Next let be M_Pencilbox the transformation of the pencil box standing on the desk in relation to the desk. And a pencil in the pencil box would be placed in relation to the pencil box.

所以铅笔经历了一系列的变换.请记住,在 OpenGL 使用的列主要符号中,事物从最后一个转换到第一个(或写下时从右到左)通过转换链流动".

So the pencil goes through a hierachy of transformations. Remember that in the column major notation used by OpenGL things "flow" through the transformation chain from last transformation to first (or right to left when written down).

每个变换,例如 M_Desk,都是一个 4×4 的矩阵,可以用通常的方式构造:旋转、平移、缩放等.

Each transformation, like M_Desk for example, is a 4×4 matrix that can be constructed the usual way: Rotations, translations, scalings, etc.

因此要变换铅笔的顶点,您需要应用以下变换

So to transform the vertices of a pencil you'd apply the following transformation

… · M_Desk · M_Pencilbox · v_Pencil

当然,桌子本身可能与不同的东西有关,例如房间.在该转换链的最开始将是视图转换.因此,我们在这里构建了一个模型视图矩阵.

Of course the desk itself may be in relation to something different, like a room. At the very beginning of that transformation chain would be the view transformation. So effectively we're building a modelview matrix here.

就现代 OpenGL 而言,每次遇到转换层次结构中的分支(想想文件系统中的目录)时,您都会创建迄今为止构建的转换链的副本,这样您就不必每个分支从头开始.

In terms of modern OpenGL, everytime you encounter a branch in the transformation hierachy (think of directories in a file system), you'd create a copy of the transformation chain built so far, so that you don't have to restart from scratch for each branch.

如果您需要进一步澄清,请告诉我.

Let me know if you need further clearification.

这篇关于如何将多个对象分组以将它们作为一个单元旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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