缩放矩阵和平移矩阵相关问题
嗨
我正在为 3D 中的实体(例如实体 1)设置单向缩放矩阵。现在,我有另一个实体(实体 2 )跟随该实体,该实体应该具有统一的缩放比例。我应用于这两个实体的矩阵序列如下...
- 将实体1从其原始世界位置翻译到原点
- 缩放单向
- 将实体翻译回其在世界中的位置。
这有效。但是,如果我对实体 2 遵循相同的顺序,则它不起作用。我正在世界坐标系中进行所有矩阵变换。
这是我进入计算机图形学神奇世界的第一步。如果有人可以通过一些了解各种坐标系(世界,模型,本地)和 指导我如何计算从模型坐标系到世界坐标系的矩阵,反之亦然。
预先感谢,
阿图尔
Hi
I am setting a Unidirectional Scaling Matrix to an entity (say Entity 1) in 3D. Now, I have another entity (Entity 2 ) that follows this entity which is supposed to have uniform Scaling. The sequence of Matrix that I apply to both these entities is as follows ...
- Translate entity1 from it's original world position to origin
- Scale Unidirectionally
- Translate entity back to it's position in world.
This works. However, if I follow the same sequence for Entity 2, it does not work. I am doing all the Matrix Transformation in World coordinate system.
This is my first step in the amazing world of Computer Graphics. I would appreciate, if some one can through some light on to various Coordinate systems (World, Model, Local) and
guide me as to how to compute matrices from model coordinate system to world coordinate system and vice versa.
Thanks in advance,
Atul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“世界”坐标系使用完全未修改的矩阵来表示世界上的所有物体。这是查看所有对象在总体方案中的位置的最简单方法。
“模型”坐标系与“局部”坐标系的概念非常相似。 “局部”坐标系根据局部对象定义坐标系,因此,例如,(0,0) 可以是该局部坐标系中对象的中心,正 Z 轴可以向下看对象视图。 “模型”坐标系本质上与此相同,但如果您与 OpenGL 混淆,因此您有一个 MODELVIEW 矩阵,则该矩阵基本上是当前使用的“本地”坐标系。您可以对此“模型”矩阵执行操作,以从世界坐标系到局部坐标系、另一个局部坐标系、另一个局部坐标系等等。
我认为 这是一篇非常棒的文章,如果您有兴趣直接进行转换,它可能会对您有所帮助从“世界”坐标系到对象的任何“本地”坐标系。为了使用此解决方案,您需要拥有要为其查找“本地”坐标系的对象的前向、上向和侧向矢量(以“世界”坐标术语表示)。
我希望这有助于澄清一些事情! :)
The "World" coordinate system uses a completely unmodified matrix to represent all the objects in the world. This is the easiest way of looking at the positions of all your objects in the grand scheme of things.
The "Model" coordinate system is very similar to the idea of a "Local" coordinate system. A "Local" coordinate system defines a coordinate system in terms of a local object, so, for example, (0,0) could be the centre of the object in this local coordinate system, and the positive Z axis may be looking down the objects view. The "Model" coordinate system is en essence the same as this, but if you're getting mixed up with OpenGL, whereby you have a MODELVIEW matrix, this matrix is basically the currently used "Local" coordinate system. You can perform manipulations on this "Model" matrix to get from the world coordinate system to a local coordinate system, to another local coordinate system, to another local coordinate system etc. etc.
I thought that this was a really great article which might help you out if you're interested in transforming directly from the "World" coordinate system to any "Local" coordinate system of an object. In order to use this solution, it is required that you have the forward, up, and side vectors (in "World" coordinate terms) for the object that you wish to find the "Local" coordinate system for.
I hope this helps clear things up a bit! :)
我将首先尝试回答你的最后一个问题,希望它能让事情变得更清楚。
每当图形艺术家创建建筑物、怪物或景观时,她都需要定义一个坐标系。它由一个原点(0,0 在哪里)和一些轴(x 和 y 方向在哪里?)组成。该选择完全是任意的并且没有真正的重要性,但为了简单起见(并且在一定程度上是为了减少由于缺乏精度而导致的错误),原点通常要么靠近物体的中心,要么位于参考点(例如树的根)。
现在,如果艺术家将怪物和建筑物收集到景观中,坐标可能会不匹配。她本来可以把建筑和景观一起创造出来,虽然这并不总是可行,更不用说方便了,但对于怪物来说,追赶一些可怜的MMO玩家,那是不可能的。
因此,我们需要一种方法来知道当怪物奔跑时,手臂、腿、牙齿、触手和其他任何你不想看到的东西最终会出现在世界的哪里。相对于怪物来说,他们的位置是非常清楚的。这就是我们所说的怪物坐标。更一般地说,我们称之为本地坐标,意思是怪物的本地坐标。
那么什么是世界坐标?通常,它们将最有意义的元素作为参考,即被认为不会围绕其他元素移动的元素。这里,风景。
这就是矩阵发挥作用的地方。 什么是矩阵? 矩阵是一个运算符,允许在不同的坐标系中表达坐标。它是坐标系统从一个系统到另一个系统的投影:从怪物到场景,从场景到相机,从相机到屏幕......
矩阵可以表达从一个系统到另一个系统的任何变换:平移、旋转、缩放、剪切、展平……或者同时进行所有这些操作。 单位矩阵是不改变任何东西的矩阵。矩阵也可以组合:通过将平移矩阵和旋转矩阵相乘,我们得到平移和旋转的变换矩阵。这样做几次,只需组合每个关节的矩阵,就可以得到汽车工厂机器人关节臂尖端的位置。
然后我们遇到您的问题可能所在:平移然后旋转与旋转然后平移不同。如果您不相信,请自己尝试:步行然后转弯或转弯然后步行,看看您如何不会在同一个位置结束。所以最终这意味着矩阵必须以特定的顺序应用,这仅取决于您想要做什么。
从你给出的解释来看,我怀疑这就是你出了问题的地方,因为如果你先缩放,翻译会给出不同的结果。
I will try to answer your last question first, hopefully it will make things clearer.
Whenever a graphic artist creates a building, a monster or a landscape, she will need to define a coordinate system. It consists in an origin (where is the 0,0) and some axises (where are the x and y directions?). The choice is completely arbitrary and has no real importance, but for the sake of simplicity (and to an extend, to reduce errors due to lack of precision), the origin usually is either close to the center of the object or at a reference point (the root of a tree for instance).
Now should the artist gather the monster and building within the landscape, the coordinates will likely not match. She could have created the building altogether with the landscape, although this is not always feasible, let alone handy, but for the monster to run after some pitiful MMO player, that is just not possible.
So we need a way to know where the arms, legs, teeth, tentacles and whatever else you would prefer not see, will end up in the world while the monster is running. Their position is very well know relatively to the monster. This is what we might call, say, the monster coordinate. More generally, we would call the local coordinates, meaning local to the monster.
So what are the world coordinates? Usually they refer to what makes most sense as a reference, the element considered to be not moving around something else. Here, the landscape.
This is where matrices come to play. What is the matrix? The matrix is an operator that allows to express coordinates in a different coordinate system. It is a projection of the coordinates system from a system to another: from monster to scene, from scene to camera, from camera to screen...
A matrix can express any transformation from one system to another: translation, rotation, scaling, shearing, flattening... Or all of them a the same time. The identity matrix is the matrix that does not change anything. Matrices can also be combined: by multiplying a translation matrix and a rotation matrix, we get the resulting transformation matrix of both translating then rotating. Do this a couple of times and you get the position of the tip of the articulated arm of a robot in a car factory by just combining the matrices of each joint.
Then we run into where your problem may lie: translating then rotating is not the same as rotating then translating. If you are not convinced about it try by yourself: walk then turn or turn then walk, and see how you do not end in the same location. So in the end it means matrices have to be applied in a specific order, which depends only on what you want to do.
From the explanations you give, I suspect this is where things are going wrong for you, since translating will give a different result if you scale first.