View space

is a fundamental concept in graphics programming. It is the coordinate system that provides a perspective on a 3D scene from the viewpoint of a camera.

In view space, each vertex is defined relative to the camera's position and orientation and not the world space. This means that the camera becomes the new origin, and all objects in the scene are positioned with respect to the camera. Achieving this transformation from the world space (where objects exist in their absolute positions) to view space involves the use of a view matrix.

The view matrix encapsulates the camera's position, direction, right vector (defining the x-axis), and up vector.

  • Camera Position: the location of the camera in world space. The view matrix needs this information to position the view space correctly.
  • Direction: The direction vector specifies where the camera is looking in world space. It defines the center of the view and is used to calculate the view matrix.
  • Right Vector: vector pointing to the right side of the camera, defining the positive x-axis in view space. It is determined by taking the cross product of the camera's direction and the up vector.
  • Up Vector: the up vector points upward relative to the camera. is calculated using the cross product of the camera's direction and the right vector.
    • The transformation process from world space to view space can be summarized in the following:

      
      projection * view * model * vec4(pos, 1.0)
      
      • pos is the position of a vertex in world space.
      • model: the model matrix that transforms the vertex from model space to world space.
      • view: the view matrix that transforms the vertex from world space to view space.
      • projection: the projection matrix responsible for mapping 3D coordinates to 2D screen space.

      By combining these matrices and applying them to the vertex position, you effectively move the vertex into view space. This process allows the renderer to produce a scene from the camera's perspective.