投影矩阵不仅仅是缩放,对吗? [英] The Projection Matrix Does More than Scaling, Right?

查看:173
本文介绍了投影矩阵不仅仅是缩放,对吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我所了解的那样,投影矩阵根据多边形离相机的距离或近距离来对多边形进行缩放。虽然我可能完全错了。 我的问题是,投影矩阵如何知道以显示以下多维数据集的各个方面,当相机移动时,矩阵只有比例多边形?

As I have it understood, a projection matrix scales a polygon depending on how far away or close it is from the camera. Though I might be completely wrong. My question is, how does the projection matrix "know" to show the sides of the following cube, as the camera moves, when the matrix is only supposed "scale" polygons?

注意图像中的立方体是关闭的通过将相机向左移动,屏幕右侧。如果相机向相反方向移动(向右)以使立方体居中,立方体的一侧将按预期消失。

Notice in the image, the cube is off to the right side of the screen, by moving the camera to the left. If the camera is moved in the opposite direction (to the right) in order to center the cube, the side of the cube will disappear as expected.

这是我的矩阵代码:

private void createProjectionMatrix(){
      float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();         
      float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV/2f))) * aspectRatio);         
      float x_scale = y_scale / aspectRatio;         
      float frustum_length = FAR_PLANE - NEAR_PLANE;                  
      projectionMatrix = new Matrix4f(); 
      projectionMatrix.m00 = x_scale;         
      projectionMatrix.m11 = y_scale;         
      projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);         
      projectionMatrix.m23 = -1;         
      projectionMatrix.m32 = -((2 * NEAR_PLANE * FAR_PLANE) / frustum_length);         
      projectionMatrix.m33 = 0;
}


推荐答案

投影矩阵的功能(在图形API的上下文中,例如OpenGL)是将顶点位置从视图空间转换为剪辑空间。

The function of a projection matrix (in the context of graphics APIs, such as OpenGL) is to transform vertex positions from view-space into clip-space.

剪辑空间通常是一个单位框(虽然在D3D中它是一个半单位框)。如果转换为剪辑空间后的顶点位置不在该单位框内,则会对其进行剪裁。这基本上是系统知道立方体在屏幕上可见的方式。

Clip space is generally a unit box (although in D3D it's a half-unit box). If a vertex position after being transformed into clip-space does not lie within that unit box, then it is clipped. This is essentially how the system "knows" the cube is visible on the screen.

这篇关于投影矩阵不仅仅是缩放,对吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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