The Projection Matrix Does More than Scaling, Right?

不想你离开。 提交于 2019-12-02 09:41:44

问题


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.

Here is my matrix code:

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;
}

回答1:


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.

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.



来源:https://stackoverflow.com/questions/36505453/the-projection-matrix-does-more-than-scaling-right

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!