获取从一个场景图内的绝对位置和旋转? [英] Getting absolute position and rotation from inside a scene graph?

查看:161
本文介绍了获取从一个场景图内的绝对位置和旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我已经跑了针对此问题的几次:

So I have run up against this problem a few times:

我在3D场景图的一些对象,它是其他对象的子项。让我们称他们为C(儿童)和P(母公司)。

I have some object in my 3D Scene Graph which is a child of some other object. Lets call them c (Child) and p (Parent).

C'S位置是相对于页。因而c可以有一个位置(1,0,0),但是当然,由于为p具有一些其他位置,说(1,2,3),它实际上不呈现在我们的世界的原,但在(2 ,2,3)。

c's position is defined relative to p. Thus c may have a position (1,0,0) but of course, due to p having some other position, say (1,2,3), it is not actually rendered at the original of our world, but at (2,2,3).

现在让我们说由于某种原因,我们想了解C在世界坐标的绝对位置(或旋转,问题是一样的),这是怎么常见的做?

Now lets say for some reason we want to know c's absolute position in world coordinates (or rotation, the problem is the same), how is this commonly done?

ç应该知道它的父,并能够查询的位置,并把它添加到它自己的最后返回一个绝对位置?

Should c know about it's parent and be able to query for that position and add it to it's own finally returning an absolute position?

推荐答案

孩子的坐标系中转换坐标到全局坐标系是是需要实际呈现的场景图的事情之一,所以这是一个合理的事情想。

Converting coordinates in a child's coordinate system to the global coordinate system is one of the things that is needed to actually render the scene graph, so this is a reasonable thing to want.

您如何做到这一点,将取决于你所使用的图形库。常在场景图的每个节点将包括一个矩阵,其将在该节点的坐标系到全局坐标。这个矩阵计算由矩阵与来自父坐标变换矩阵的父节点乘以到子坐标,或者反之亦然取决于如何事情定义

How you accomplish this will depend on the graphics library you are using. Often each node in the scene graph will include a matrix which transforms that node's coordinate system into the global coordinates. This matrix is calculated by multiplying the matrix from the parent node with the transformation matrix from the parent's coordinates to the child coordinates, or vice versa depending on how things are defined.

如果你有这样一个矩阵,你可以做你想要通过复接儿童的点坐标计算的节点矩阵。此外,为了在这里很重要。

If you have a matrix like this, you can do the calculation you want by multipling the point in child coordinates by the node's matrix. Again, order is important here.

这篇关于获取从一个场景图内的绝对位置和旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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