glLoadIdentity()在OpenGL中做什么? [英] What does glLoadIdentity() do in OpenGL?

查看:120
本文介绍了glLoadIdentity()在OpenGL中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OpenGL的新手,我对代码中的所有随机函数有点不知所措。他们的工作,我知道何时使用它们,但我不知道为什么我需要他们或他们实际上做了什么。



我知道 glLoadIdentity()用当前矩阵替换当前矩阵,但究竟做了什么?如果每个程序都需要它,为什么默认情况下不是单位矩阵,除非另有说明?除非我知道他们做了什么,否则我不喜欢在我的代码中具有功能。我应该注意到,我使用OpenGL专门用于丰富的2D客户端,所以如果这对于3D来说非常明显,那么请原谅我的无知。

$也有点困惑 glMatrixMode(GL_PROJECTION) VS glMatrixMode(GL_MODELVIEW)

解决方案根据投影和模型视图矩阵,单位矩阵基本上将矩阵重置为默认状态。



正如你所希望的那样, glTranslate glRotate 总是相对于矩阵的当前状态。因此,例如,如果您调用 glTranslate ,您将从矩阵的当前'位置'转换,而不是从原点转换。但是如果你想从原点开始,那就是当你调用 glLoadIdentity(),然后你可以 glTranslate 从现在位于原点的矩阵,或从现在以默认方向定向的矩阵中 glRotate



我认为恩恩的答案,它等于1,并不完全正确。矩阵实际上是这样的:

  1 0 0 0 
0 1 0 0
0 0 1 0
0 0 0 1

这就是单位矩阵。在数学上,恩赐是正确的,即任何矩阵与该矩阵相乘(或者看起来像这样的矩阵;对角矩阵,其他所有0)都将产生原始矩阵,但我不相信他解释了为什么这很重要。 / p>

这一点很重要的原因是因为OpenGL将所有位置和旋转乘以每个矩阵;所以当你绘制一个多边形( glBegin(GL_FACE),某些点, glEnd())时,它会翻译它通过将它乘以MODELVIEW到世界空间,然后通过将其与PROJECT矩阵相乘,将其从3D转换为2D,并将其与屏幕上的2D点一起提供给深度(从屏幕'摄像头' ),它用来绘制像素。但是当这些矩阵中的一个是单位矩阵时,这些点与单位矩阵相乘,因此不会改变,所以矩阵不起作用;它不会转换点,它不旋转它们,它保留原样。



我希望这个更清楚一点!


I'm new to OpenGL and I'm a little overwhelmed with all of the random functions that I have my in code. They work and I know when to use them, but I don't know why I need them or what they actually do.

I know that glLoadIdentity() replaces the current matrix with the identity matrix, but what exactly does that do? If every program requires it, why isn't the identity matrix by default unless otherwise specified? I don't like to have functions in my code unless I know what they do. I should note that I am using OpenGL exclusively for rich 2D clients so excuse my ignorance if this is something very obvious for 3D.

Also a little confused about glMatrixMode(GL_PROJECTION) VS glMatrixMode(GL_MODELVIEW).

解决方案

The identity matrix, in terms of the projection and modelview matrices, essentially resets the matrix back to its default state.

As you hopefully know, glTranslate and glRotate are always relative to the matrix's current state. So for instance, if you call glTranslate, you are translating from the matrix's current 'position', not from the origin. But if you want to start over at the origin, that's when you call glLoadIdentity(), and then you can glTranslate from the matrix which is now located at the origin, or glRotate from the matrix which is now oriented in the default direction.

I think Boon's answer, that it is the equivalent of 1, is not exactly correct. The matrix actually looks like this:

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

That is the identity matrix. Boon is correct, mathematically, that any matrix multiplied with that matrix (or a matrix that looks like that; diagonal ones, all else 0s) will result in the original matrix, but I don't believe he explained why this is important.

The reason why this is important is because OpenGL multiplies all positions and rotations through each matrix; so when for instance you draw a polygon (glBegin(GL_FACE), some points, glEnd()), it translates it to "world space" by multiplying it with the MODELVIEW, and then translates it from 3D to 2D by multiplying it with the PROJECT matrix, and that gives it the 2D points on screen, along with the depth (from the screen 'camera'), which it uses to draw pixels. But when one of these matrices are the identity matrix, the points are multiplied with the identity matrix and therefore are not changed, so the matrix has no effect; it does not translate the points, it does not rotate them, it leaves them as-is.

I hope this clarifies a bit more!

这篇关于glLoadIdentity()在OpenGL中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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