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

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

问题描述

所以我遇到过几次这个问题:

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 的位置是相对于 p 定义的.因此 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?

c 是否应该知道它的父级并能够查询该位置并将其添加到它自己的位置,最终返回一个绝对位置?

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天全站免登陆