OpenGL 转换(glScale、glTranslate 等)
我正在学习 openGL 以及如何进行转换,例如翻译和缩放。我知道你通常必须翻译到原点,然后做任何你想做的事情(比方说缩放),然后翻译回来。据我了解,这是手动完成的,但您可以使用 glScale() 执行相同的操作。
我的问题是,如果我使用 glScale 函数,是否还需要转换到原点并返回?
I'm learning about openGL and how to do transformations such as translating and scaling. I know you have to usually translate to the origin, then do whatever you want (lets say scale), then translate back. From my understanding this is done manually but you can do the same thing with glScale().
My question is do I still need to translate to the origin and back if I use the glScale function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能不需要对源进行任何转换并返回,只需按所需的顺序进行转换即可。请记住,最后应用的变换发生在前一个变换的变换空间中。例如:
与
在第二个示例中,平移和对象都缩放了 x10,因为它们是在缩放之后完成的。 (此方案允许 drawObject() 包含转换,并且仍然像单个单元一样运行。)
You probably don't need to do any translation to the origin and back, just do the transformations in the required order. Remember that the last transformation applied takes place in the transformed space of the previous ones. For example:
versus
In the second example, both the translation and the object are scaled x10, because they're done after the scale. (This scheme allows drawObject() to include transformations and still behave like a single unit.)
您必须考虑堆栈上发生的转换。换句话说,您指定的最后一个转换首先发生。因此,
首先将绕 x 轴旋转 45 度,然后将对象缩放到 (10,10,10),然后平移到 (1,2,3)。但是,您还必须记住,您应用的任何转换都会影响后续的转换。如果我们颠倒上述变换的顺序,则旋转将围绕不同的点旋转。
You have to think of the transformations taking place on a stack. In other words, the last transformation you specify takes place first. So,
will first rotate 45 degrees about the x axis, then scale the object to (10,10,10), then translate to (1,2,3). However, you also have to remember that any transformation you apply affects transformations further down the line. If we reverse the order of the above transformations, the rotation will then rotate about a different point.
glScale 所做的就是将当前矩阵乘以缩放矩阵。所以是的,对于听起来您想做的事情,您需要在应用翻译之前应用比例矩阵。
另请参阅 glScale 参考。
All
glScale
does is multiply the current matrix by a scale matrix. So yes, for what it sounds like you want to do, you would want to apply the scale matrix before applying a translation.See also glScale reference.