libsc 2.8.7.187-a49fd
The SC library provides support for parallel scientific applications.
Loading...
Searching...
No Matches
Files

A camera data structure for maintaining the position, orientation and view frustum of the camera. More...

Collaboration diagram for Camera:

Files

file  sc_camera.h
 Camera data structure for computer graphic applications.
 

Detailed Description

A camera data structure for maintaining the position, orientation and view frustum of the camera.

Example Workflow: Rendering a point p with sc_camera

  1. World Space: Initially, p lies in the right-handed world coordinate system.
  2. View Transformation: p is transformed into the right-handed view coordinate system. In this system:

    • The camera is at the origin, looking down the negative z-axis.
    • The x-axis points to the right, and the y-axis points upwards.

    Transformation steps:

    • Translate p by the camera position.
    • Rotate p by the camera rotation.

    The camera rotation is stored as a unit quaternion q = (q_x, q_y, q_z, q_w), where (q_x, q_y, q_z) are the imaginary parts (i, j, k) and q_w is the real part.

    To rotate a point p = (p_x, p_y, p_z), treat it as a pure quaternion (p_x i + p_y j + p_z k), and compute the conjugation: p' = q * p * q^{-1}

    Explicitly: p' = (q_x i + q_y j + q_z k + q_w) * (p_x i + p_y j + p_z k) * (-q_x i - q_y j - q_z k + q_w) where quaternion multiplication rules apply (i.e., i^2 = j^2 = k^2 = ijk = -1). The camera rotation is defined such that it rotates the world space so that the camera looks along the negative z-axis. It is the inverse of the rotation that would align the default camera orientation with the preferred camera direction.

    In summary, the view transformation is:

    p_view = q * (p - camera->position) * q^-1

  3. Projection to Normalized Device Coordinates (NDC): After the view transformation, p is projected into normalized device coordinates (NDC):

    • The x- and y-coordinates represent the 2D position of the point in the image.
    • The z-coordinate represents depth information, which is used for visibility and rendering order.

    The NDC space is left-handed, as in OpenGL:

    • The visible region is the cube [-1, 1]^3.
    • (x, y) = (-1, -1) is the bottom-left corner of the image.
    • (x, y) = (1, 1) is the top-right corner of the image.
    • Increasing x moves to the right, increasing y moves upwards.
    • For the z-axis:
      • z = -1 corresponds to the near clipping plane (closest to the camera),
      • z = 1 corresponds to the far clipping plane (farthest from the camera).

    The projection is defined by:

    • The horizontal field of view (FOV): the opening angle in radians in the x-direction.
    • The aspect ratio: the ratio of image width to height, which determines the vertical field of view.
    • The near_plane and far_plane values: the positive distances from the camera to the near and far clipping planes.

    Points closer than the near plane or farther than the far plane are clipped, meaning they are not mapped inside the visible cube [-1, 1]^3.