|
libsc 2.8.7.187-a49fd
The SC library provides support for parallel scientific applications.
|
Camera data structure for computer graphic applications. More...
#include <sc_containers.h>
Go to the source code of this file.
Data Structures | |
| struct | sc_camera |
| Represents a camera with parameters for rendering a 3D scene. More... | |
Typedefs | |
| typedef double | sc_camera_coords_t |
| The data type of the coordinates for sc_camera. | |
| typedef sc_camera_coords_t | sc_camera_vec3_t[3] |
| Points in R^3 for sc_camera. | |
| typedef sc_camera_coords_t | sc_camera_vec4_t[4] |
| Points in R^4 for sc_camera. | |
| typedef sc_camera_coords_t | sc_camera_mat4x4_t[16] |
| 4 times 4 matrix for sc_camera. | |
| typedef sc_camera_coords_t | sc_camera_mat3x3_t[9] |
| 3 times 3 matrix for sc_camera. | |
| typedef enum sc_camera_plane | sc_camera_plane_t |
| Defines the order of the 6 planes of the camera's view frustum. | |
| typedef struct sc_camera | sc_camera_t |
| Represents a camera with parameters for rendering a 3D scene. | |
Enumerations | |
| enum | sc_camera_plane { SC_CAMERA_PLANE_NEAR , SC_CAMERA_PLANE_FAR , SC_CAMERA_PLANE_LEFT , SC_CAMERA_PLANE_RIGHT , SC_CAMERA_PLANE_TOP , SC_CAMERA_PLANE_BOTTOM } |
| Defines the order of the 6 planes of the camera's view frustum. More... | |
Functions | |
| sc_camera_t * | sc_camera_new (void) |
| Creates a new camera structure with the default values (see sc_camera_init). | |
| void | sc_camera_init (sc_camera_t *camera) |
| Initializes a camera with the default parameters. | |
| void | sc_camera_destroy (sc_camera_t *camera) |
| Destroys a camera structure. | |
| void | sc_camera_position (sc_camera_t *camera, const sc_camera_vec3_t position) |
| Sets the position. | |
| void | sc_camera_yaw (sc_camera_t *camera, double angle) |
| Rotating the camera around the up axis. | |
| void | sc_camera_pitch (sc_camera_t *camera, double angle) |
| Rotating the camera around the axis to the right. | |
| void | sc_camera_roll (sc_camera_t *camera, double angle) |
| Rotating the camera around the backward axis. | |
| void | sc_camera_walk (sc_camera_t *camera, double distance) |
| Move the camera backward/forward along the view direction. | |
| void | sc_camera_fov (sc_camera_t *camera, double angle) |
| Sets the horizontal field of view. | |
| void | sc_camera_aspect_ratio (sc_camera_t *camera, int width, int height) |
| Sets the aspect ratio. | |
| void | sc_camera_clipping_dist (sc_camera_t *camera, sc_camera_coords_t near_plane, sc_camera_coords_t far_plane) |
| Sets the clipping distances. | |
| void | sc_camera_look_at (sc_camera_t *camera, const sc_camera_vec3_t eye, const sc_camera_vec3_t center, const sc_camera_vec3_t up) |
| Sets the position and rotation of the camera object. | |
| void | sc_camera_view_transform (const sc_camera_t *camera, sc_array_t *points_in, sc_array_t *points_out) |
| Performs the view transformation from world space to view space. | |
| void | sc_camera_get_view_mat (const sc_camera_t *camera, sc_camera_mat4x4_t view_matrix) |
| Returns the view transformation matrix. | |
| void | sc_camera_get_projection_mat (const sc_camera_t *camera, sc_camera_mat4x4_t proj_matrix) |
| Returns the projection transformation matrix. | |
| void | sc_camera_projection_transform (const sc_camera_t *camera, sc_array_t *points_in, sc_array_t *points_out) |
| Performs the projection transformation from view space to normalized device coordinates. | |
| void | sc_camera_get_frustum (const sc_camera_t *camera, sc_array_t *planes) |
| Returns the 6 planes of the view frustum. | |
| void | sc_camera_clipping_pre (const sc_camera_t *camera, sc_array_t *points, sc_array_t *indices) |
| Determines the indices of points that are visible within the camera's view frustum. | |
| void | sc_camera_frustum_dist (const sc_camera_t *camera, const sc_camera_vec3_t point, sc_camera_coords_t distances[6]) |
| Computes the signed distances of a point to the 6 planes of the camera's view frustum. | |
| void | sc_camera_clipping_post (sc_array_t *points, sc_array_t *indices) |
| Performs clipping in normalized device coordinates (NDC) space. | |
| void | sc_camera_perspective_division (sc_array_t *points_in, sc_array_t *points_out) |
| Performs perspective division. | |
Camera data structure for computer graphic applications.
The camera module page provides a detailed example of the rendering workflow.
| typedef sc_camera_coords_t sc_camera_mat3x3_t[9] |
3 times 3 matrix for sc_camera.
The entries of the matrix are in column-major order.
| typedef sc_camera_coords_t sc_camera_mat4x4_t[16] |
4 times 4 matrix for sc_camera.
The entries of the matrix are in column-major order.
| typedef enum sc_camera_plane sc_camera_plane_t |
Defines the order of the 6 planes of the camera's view frustum.
The planes are enumerated as: near, far, left, right, top, bottom.
| typedef struct sc_camera sc_camera_t |
Represents a camera with parameters for rendering a 3D scene.
The sc_camera object stores essential properties of a camera, including its position, rotation, field of view, viewport dimensions, and clipping planes. These parameters define how the camera projects the 3D world onto the 2D image plane.
| enum sc_camera_plane |
Defines the order of the 6 planes of the camera's view frustum.
The planes are enumerated as: near, far, left, right, top, bottom.
| void sc_camera_aspect_ratio | ( | sc_camera_t * | camera, |
| int | width, | ||
| int | height | ||
| ) |
Sets the aspect ratio.
The aspect ratio is determined by the ratio of a width and a height value.
| [out] | camera | The camera object. |
| [in] | width | A width value for the view. |
| [in] | height | A height value for the view. |
| void sc_camera_clipping_dist | ( | sc_camera_t * | camera, |
| sc_camera_coords_t | near_plane, | ||
| sc_camera_coords_t | far_plane | ||
| ) |
Sets the clipping distances.
| [out] | camera | The camera object. |
| [in] | near_plane | The new distance from the camera to the near clipping plane. |
| [in] | far_plane | The new distance from the camera to the far clipping plane. |
| void sc_camera_clipping_post | ( | sc_array_t * | points, |
| sc_array_t * | indices | ||
| ) |
Performs clipping in normalized device coordinates (NDC) space.
This function identifies points that lie within the NDC cube ([-1,1]^3).
The input array must store points in homogeneuos coordinates as quadruples of coordinates, i.e.: points_in->elem_size = 4 * sizeof(sc_camera_coords_t)
Checks if x, y, z in [-w, w] for each point (x, y, z, w) in homogeneous coordinates.
(x,y,z,w) = (0,0,0,0) is not a valid homogeneous coordinate and will trigger an assertion failure.
| [in] | points | An array of points in homogeneous coordinates (4D). |
| [out] | indices | An array that will contain the indices of points that lie inside the NDC cube [-1, 1]^3. |
| void sc_camera_clipping_pre | ( | const sc_camera_t * | camera, |
| sc_array_t * | points, | ||
| sc_array_t * | indices | ||
| ) |
Determines the indices of points that are visible within the camera's view frustum.
This function takes an array of 3D points in world space (x, y, z) and performs clipping against the camera's view frustum. It returns the indices of the points that are inside the frustum and thus visible to the camera.
The input array points must store the 3D coordinates of the points, i.e.: points->elem_size = 3 * sizeof(sc_camera_coords_t)
The output array indices stores the indices of the points from points that are inside the view frustum. Each index is stored as a size_t value. Thus indices must be initialized sc_array with elem_size = sizeof(size_t).
| [in] | camera | The camera object. |
| [in] | points | An array of 3D points in world space (x, y, z). |
| [out] | indices | The indices (as size_t) of the points that are visible within the camera's view frustum. |
| void sc_camera_destroy | ( | sc_camera_t * | camera | ) |
Destroys a camera structure.
This function destroys a camera object allocated with sc_camera_new. It is not valid to call this function on stack-allocated camera objects.
| [in] | camera | The camera to be destroyed. |
| void sc_camera_fov | ( | sc_camera_t * | camera, |
| double | angle | ||
| ) |
Sets the horizontal field of view.
| [out] | camera | The camera object. |
| [in] | angle | The new horizontal field of view angle of the camera. |
| void sc_camera_frustum_dist | ( | const sc_camera_t * | camera, |
| const sc_camera_vec3_t | point, | ||
| sc_camera_coords_t | distances[6] | ||
| ) |
Computes the signed distances of a point to the 6 planes of the camera's view frustum.
For a point in world space, this function calculates its signed orthogonal distance to each frustum plane (near, far, left, right, top, bottom), stored in distances[0..5] in this order, which must be allocated by the user.
A positive distance means that a point lies on the outside side of this plane. If all values are negative the point lies in the view frustum.
| [in] | camera | The camera object. |
| [in] | point | A 3D point in world space. |
| [out] | distances | Six signed distances (sc_camera_coords_t) to the frustum planes. Must be allocated on input. |
| void sc_camera_get_frustum | ( | const sc_camera_t * | camera, |
| sc_array_t * | planes | ||
| ) |
Returns the 6 planes of the view frustum.
This function returns the bounding planes of the visible world space (the view frustum). The planes are ordered as: near, far, left, right, top, and bottom (see enum sc_camera_plane). The naming is from the perspective of the camera; for example, the left plane bounds the view to the left. The near and far planes bound the field of view so that objects, that are too close or too far, are not visible. The distances to these planes are defined by the user in the camera object.
The array planes contains 6 entries, each consisting of 4 values (a, b, c, d): planes->elem_count = 6 planes->elem_size = 4 * sizeof(sc_camera_coords_t)
Each plane is represented by its outward-facing normal vector (a, b, c) and offset d, such that the plane equation is: a*x + b*y + c*z + d = 0 Points (x, y, z) satisfying this equation lie on the plane.
| [in] | camera | The camera object. |
| [out] | planes | The 6 planes of the view frustum, in the order near, far, left, right, top, and bottom (see enum sc_camera_plane). |
| void sc_camera_get_projection_mat | ( | const sc_camera_t * | camera, |
| sc_camera_mat4x4_t | proj_matrix | ||
| ) |
Returns the projection transformation matrix.
The projection matrix transforms coordinates from view space into normalized device coordinates (NDC).
| [in] | camera | The camera object defining the projection. |
| [out] | proj_matrix | The resulting 4x4 projection transformation matrix in column-major order. Must be allocated by the user. |
| void sc_camera_get_view_mat | ( | const sc_camera_t * | camera, |
| sc_camera_mat4x4_t | view_matrix | ||
| ) |
Returns the view transformation matrix.
Let R ∈ ℝ^{3×3} be the rotation matrix corresponding to the camera's rotation quaternion, and p ∈ ℝ³ be the camera's position vector. Let I be the 3×3 identity matrix. view_matrix is defined as:
This matrix transforms coordinates from world space into the camera's local (view) coordinate system.
| [in] | camera | The camera object defining the view transformation. |
| [out] | view_matrix | The resulting 4×4 view transformation matrix in column-major order. Must be allocated by the user. |
| void sc_camera_init | ( | sc_camera_t * | camera | ) |
Initializes a camera with the default parameters.
As default the camera is positioned at (0, 0, 1) and looking at (0, 0, 0) with the upwards direction (0, 1, 0). The default horizontal field of view is Pi/2, the image has aspect ratio 1 (width = height) and near is set at 1/100 far at 100. The default is realised by the following values.
| [out] | camera | Camera that is initialized. |
| void sc_camera_look_at | ( | sc_camera_t * | camera, |
| const sc_camera_vec3_t | eye, | ||
| const sc_camera_vec3_t | center, | ||
| const sc_camera_vec3_t | up | ||
| ) |
Sets the position and rotation of the camera object.
The vectors (eye - center) and up have to be linear independent (thus also not zero).
| [out] | camera | Camera that is changed. |
| [in] | eye | Position of the camera. |
| [in] | center | Point that is in the center of the image. |
| [in] | up | Upward direction of the camera. |
| sc_camera_t * sc_camera_new | ( | void | ) |
Creates a new camera structure with the default values (see sc_camera_init).
The returned pointer must be eventually freed with sc_camera_destroy.
| void sc_camera_perspective_division | ( | sc_array_t * | points_in, |
| sc_array_t * | points_out | ||
| ) |
Performs perspective division.
This function converts points from homogeneous coordinates (4D) to normalized device coordinates (3D) by dividing the x, y, and z components by the w component.
The input array must store points in homogeneuos coordinates as quadruples of coordinates, i.e.: points_in->elem_size = 4 * sizeof(sc_camera_coords_t)
The output array will store points as triples of coordinates, i.e.: points_out->elem_size = 3 * sizeof(sc_camera_coords_t)
For each input point, the homogeneous component w must be non-zero and not too small in magnitude relative to the maximum absolute component of the 4D vector. In debug builds, this is enforced by a scale-invariant assertion.
| [in] | points_in | An array of points in homogeneous coordinates (4D). |
| [out] | points_out | An array that will contain the points in normalized device coordinates (3D) after perspective division. |
| void sc_camera_pitch | ( | sc_camera_t * | camera, |
| double | angle | ||
| ) |
Rotating the camera around the axis to the right.
The camera is rotated around the x-axis (right direction). The function rotates the camera about angle (radians) amount by the right hand rule. This means a positive angle rotates the camera up.
| [out] | camera | The camera object. |
| [in] | angle | The angle the camera is rotated. |
| void sc_camera_position | ( | sc_camera_t * | camera, |
| const sc_camera_vec3_t | position | ||
| ) |
Sets the position.
| [out] | camera | The camera object. |
| [in] | position | The new position of the camera object in world space. |
| void sc_camera_projection_transform | ( | const sc_camera_t * | camera, |
| sc_array_t * | points_in, | ||
| sc_array_t * | points_out | ||
| ) |
Performs the projection transformation from view space to normalized device coordinates.
This function transforms an array of points from view space into normalized device coordinates (NDC) as described in the example. Each input point is a 3D vector (x, y, z), and each output point is represented in homogeneous coordinates (x, y, z, w).
Note that this function maps to 4D since performing the perspective division can lead to numerical instabilties if the mapped point was not clipped before (cf. sc_camera_clipping_pre). Alternatively, one can apply sc_camera_clipping_post to the result of this function and then perform a safe perspective division.
The input array must store points as triples of coordinates, i.e.: points_in->elem_size = 3 * sizeof(sc_camera_coords_t)
The output array stores points as quadruples of coordinates, i.e.: points_out->elem_size = 4 * sizeof(sc_camera_coords_t)
| [in] | camera | The camera object defining the projection. |
| [in] | points_in | An array of points, each represented by 3 coordinates (x, y, z) to be transformed. |
| [out] | points_out | An array that will contain the transformed points in homogeneous coordinates (x, y, z, w). |
| void sc_camera_roll | ( | sc_camera_t * | camera, |
| double | angle | ||
| ) |
Rotating the camera around the backward axis.
The camera is rotated around the z-axis (backwards direction). The function rotates the camera about angle (radians) amount by the right hand rule. This means a positive angle tilts the camera counter clockwise.
| [out] | camera | The camera object. |
| [in] | angle | The angle the camera is rotated. |
| void sc_camera_view_transform | ( | const sc_camera_t * | camera, |
| sc_array_t * | points_in, | ||
| sc_array_t * | points_out | ||
| ) |
Performs the view transformation from world space to view space.
This function transforms an array of points from world coordinates into view space as defined by the given camera. Each input point is a 3D vector (x, y, z), and each output point is represented in the same way.
The input array must store points as triples of coordinates, i.e.: points_in->elem_size = 3 * sizeof(sc_camera_coords_t)
The output array stores points in the same format: points_out->elem_size = 3 * sizeof(sc_camera_coords_t)
| [in] | camera | The camera object defining the view transformation. |
| [in] | points_in | An array of points, each represented by 3 coordinates (x, y, z) in world space. |
| [out] | points_out | An array that will contain the transformed points in view space. |
| void sc_camera_walk | ( | sc_camera_t * | camera, |
| double | distance | ||
| ) |
Move the camera backward/forward along the view direction.
The camera position is translated parallel to the view direction. Since the camera looks down the negative z-axis, a positive walking distance moves the camera backwards.
| [out] | camera | The camera object. |
| [in] | distance | Distance to move the camera by. A positive value moves the camera backwards. |
| void sc_camera_yaw | ( | sc_camera_t * | camera, |
| double | angle | ||
| ) |
Rotating the camera around the up axis.
The camera is rotated around the y-axis (up direction). The function rotates the camera about angle (radians) amount by the right hand rule. This means a positive angle rotates the camera to the left.
| [out] | camera | The camera object. |
| [in] | angle | The angle the camera is rotated. |