opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
camera_v2.h
Go to the documentation of this file.
1#pragma once
2
9
10#include <optional>
11
12namespace osc
13{
17 public:
19
20 // resets the camera to default parameters
21 void reset();
22
23 // get/set the kind of projection that the camera should use when projecting view space
24 // vertices into clip space (ignored if `set_projection_matrix_override` is used)
27
28 // get/set the height of the orthographic projection plane that the camera will use
29 //
30 // undefined behavior if `projection() != CameraProjection::Orthographic`, or the
31 // projection matrix has been overridden with `set_projection_matrix_override`, the
32 // width of the orthographic plane is calculated from the aspect ratio of the render
33 // target at runtime.
34 float orthographic_size() const;
36
37 // get/set the vertical field-of-view angle of the viewer's projection camera
38 //
39 // undefined behavior if `projection() != CameraProjection::Perspective` or the projection matrix
40 // has been overridden with `set_projection_matrix_override`.
43
44 // returns the horizontal field-of-view angle of the viewer's projection camera, assuming
45 // it's rendering to a render target with the given `aspect_ratio`.
46 //
47 // undefined behavior if `projection() != CameraProjection::Perspective` or the projection matrix
48 // has been overridden with `set_projection_matrix_override`.
50
51 // get/set the distance, in world space units, between both the camera and the nearest
52 // clipping plane, and the camera and the farthest clipping plane
55
56 // get/set the distance, in world space units, between the camera and the nearest
57 // clipping plane
58 float near_clipping_plane() const;
60
61 // get/set the distance, in world space units, between the camera and the farthest
62 // clipping plane
63 float far_clipping_plane() const;
65
66 // get/set the world space position of this `Camera`
68 void set_position(const Vector3&);
69
70 // get/set the direction in which this `Camera` is pointing
72 void set_direction(const Vector3&);
73
74 // returns the upwards direction of this camera
75 Vector3 up() const;
76 void set_up(const Vector3&);
77
78 // returns the matrix that this camera uses to transform world space points into
79 // view space
80 //
81 // world space and view space operate with the same units-of-measure, handedness, etc.
82 // but view space places the camera at `(0, 0, 0)`
84
85 // returns the equivalent of `inverse(view_matrix())`, i.e. a matrix that transforms
86 // view space points into world space points.
88
89 // get/set matrices that override the default view matrix that this `Camera` uses
90 //
91 // by default, `Camera` computes its view matrix from its position and rotation, but
92 // it's sometimes necessary/handy to override this default behavior.
93 std::optional<Matrix4x4> view_matrix_override() const;
94 void set_view_matrix_override(std::optional<Matrix4x4>);
95
96 // returns the matrix that this camera uses to transform view space points into
97 // clip space.
98 //
99 // clip space is defined such that there exists a unit cube in it that eventually
100 // projects onto screen space in the following way:
101 //
102 // - transformed points (affine, homogeneous) are divided by their `w` component (perspective
103 // divide) to yield their normalized device coordinates (NDC).
104 // - Anything outside of [{-1,-1,-1},{+1,+1,+1}] in NDC is discarded (clipping)
105 // - NDC `( 0, 0, 0)` maps to the midpoint of screen space (i.e. 0.5 * {w, h})
106 // - NDC `(-1, -1, -1)` maps to the bottom-left of screen space (z = -1 means 'closest')
107 // - NDC `(+1, +1, +1)` maps to the top-right of screen space (z = +1 means 'farthest')
108 // - Therefore, NDC is left-handed
109 //
110 // The XY component of fragments that land within clip space are transformed into screen
111 // space and drawn to the output pixel rectangle (assuming they also pass the scissor test).
112 // The Z component of things that land within the NDC cube are written to the depth buffer
113 // if the `Material` that's being drawn enables this behavior (and there's a depth buffer
114 // attached to the render target).
116 std::optional<Matrix4x4> projection_matrix_override() const;
117 void set_projection_matrix_override(std::optional<Matrix4x4>);
118
119 // returns the equivalent of `projection_matrix(aspect_ratio) * view_matrix()`
121
122 // returns the equivalent of `inverse(view_projection_matrix(aspect_ratio))`
124
125 private:
126 friend bool operator==(const CameraV2&, const CameraV2&);
127 class Impl;
129 };
130
131 bool operator==(const CameraV2&, const CameraV2&);
132}
Definition angle.h:26
Definition camera_v2.h:16
void set_near_clipping_plane(float)
Vector3 direction() const
float near_clipping_plane() const
std::optional< Matrix4x4 > projection_matrix_override() const
void set_view_matrix_override(std::optional< Matrix4x4 >)
void set_clipping_planes(CameraClippingPlanes)
Matrix4x4 view_projection_matrix(float aspect_ratio) const
Matrix4x4 inverse_view_projection_matrix(float aspect_ratio) const
void set_projection_matrix_override(std::optional< Matrix4x4 >)
Vector3 up() const
void set_projection(CameraProjection)
CameraClippingPlanes clipping_planes() const
void set_direction(const Vector3 &)
Matrix4x4 view_matrix() const
void set_orthographic_size(float)
Matrix4x4 inverse_view_matrix() const
float orthographic_size() const
Radians horizontal_field_of_view(float aspect_ratio) const
void set_position(const Vector3 &)
std::optional< Matrix4x4 > view_matrix_override() const
Matrix4x4 projection_matrix(float aspect_ratio) const
float far_clipping_plane() const
Radians vertical_field_of_view() const
void set_up(const Vector3 &)
Vector3 position() const
CameraProjection projection() const
friend bool operator==(const CameraV2 &, const CameraV2 &)
void set_vertical_field_of_view(Radians)
void set_far_clipping_plane(float)
Definition copy_on_upd_shared_value.h:16
Definition custom_decoration_generator.h:5
CameraProjection
Definition camera_projection.h:8
bool operator==(const Class &, const Class &)
constexpr U to(T &&value)
Definition conversion.h:56
Definition camera_clipping_planes.h:7