opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
camera.h
Go to the documentation of this file.
1#pragma once
2
11
12#include <optional>
13
14namespace osc { class Rect; }
15
16namespace osc
17{
21 class Camera {
22 public:
24
25 // resets the camera to default parameters
26 void reset();
27
28 // get/set the kind of projection that the camera should use when projecting view space
29 // vertices into clip space (ignored if `set_projection_matrix_override` is used)
32
33 // get/set the height of the orthographic projection plane that the camera will use
34 //
35 // undefined behavior if `projection() != CameraProjection::Orthographic`, or the
36 // projection matrix has been overridden with `set_projection_matrix_override`, the
37 // width of the orthographic plane is calculated from the aspect ratio of the render
38 // target at runtime.
39 float orthographic_size() const;
41
42 // get/set the vertical field-of-view angle of the viewer's projection camera
43 //
44 // undefined behavior if `projection() != CameraProjection::Perspective` or the projection matrix
45 // has been overridden with `set_projection_matrix_override`.
48
49 // returns the horizontal field-of-view angle of the viewer's projection camera, assuming
50 // it's rendering to a render target with the given `aspect_ratio`.
51 //
52 // undefined behavior if `projection() != CameraProjection::Perspective` or the projection matrix
53 // has been overridden with `set_projection_matrix_override`.
55
56 // get/set the distance, in world space units, between both the camera and the nearest
57 // clipping plane, and the camera and the farthest clipping plane
60
61 // get/set the distance, in world space units, between the camera and the nearest
62 // clipping plane
63 float near_clipping_plane() const;
65
66 // get/set the distance, in world space units, between the camera and the farthest
67 // clipping plane
68 float far_clipping_plane() const;
70
71 // get/set the world space position of this `Camera`
73 void set_position(const Vector3&);
74
75 // get/set the world space orientation of this `Camera` (normalized by
76 // the implementation).
79
80 // get/set the direction in which this `Camera` is pointing (normalized by
81 // the implementation).
83 void set_direction(const Vector3&);
84
85 // Returns the forward-facing unit vector of this `Camera` in world space.
87
88 // Sets the forward vector of this camera to `direction`.
89 //
90 // The implementation always internally normalizes `direction` and may
91 // store it differently. Therefore, it is not guaranteed that `forward()`
92 // returns `direction`.
94
95 // get/set the upwards direction of this camera (normalized by the implementation).
96 Vector3 up() const;
97 void set_up(const Vector3&);
98
99 // returns the principal ray of this camera in world space
100 //
101 // the principal ray originates at the camera's `position()` and travels
102 // straight down its optical axis (i.e. `direction()`).
104
105 // returns the matrix that this camera uses to transform world space points into
106 // view space
107 //
108 // world space and view space operate with the same units-of-measure, handedness, etc.
109 // but view space places the camera at `(0, 0, 0)`
111
112 // returns the equivalent of `inverse(view_matrix())`, i.e. a matrix that transforms
113 // view space points into world space points.
115
116 // get/set matrices that override the default view matrix that this `Camera` uses
117 //
118 // by default, `Camera` computes its view matrix from its position and rotation, but
119 // it's sometimes necessary/handy to override this default behavior.
120 std::optional<Matrix4x4> view_matrix_override() const;
121 void set_view_matrix_override(std::optional<Matrix4x4>);
122
123 // returns the matrix that this camera uses to transform view space points into
124 // clip space.
125 //
126 // clip space is defined such that there exists a unit cube in it that eventually
127 // projects onto screen space in the following way:
128 //
129 // - transformed points (affine, homogeneous) are divided by their `w` component (perspective
130 // divide) to yield their normalized device coordinates (NDC).
131 // - Anything outside of [{-1,-1,-1},{+1,+1,+1}] in NDC is discarded (clipping)
132 // - NDC `( 0, 0, 0)` maps to the midpoint of screen space (i.e. 0.5 * {w, h})
133 // - NDC `(-1, -1, -1)` maps to the bottom-left of screen space (z = -1 means 'closest')
134 // - NDC `(+1, +1, +1)` maps to the top-right of screen space (z = +1 means 'farthest')
135 // - Therefore, NDC is left-handed
136 //
137 // The XY component of fragments that land within clip space are transformed into screen
138 // space and drawn to the output pixel rectangle (assuming they also pass the scissor test).
139 // The Z component of things that land within the NDC cube are written to the depth buffer
140 // if the `Material` that's being drawn enables this behavior (and there's a depth buffer
141 // attached to the render target).
143 std::optional<Matrix4x4> projection_matrix_override() const;
144 void set_projection_matrix_override(std::optional<Matrix4x4>);
145
146 // returns the equivalent of `projection_matrix(aspect_ratio) * view_matrix()`
148
149 // returns the equivalent of `inverse(view_projection_matrix(aspect_ratio))`
151
152 // Returns a point in ui space where this `Camera` would project
153 // `world_position` (in world space) into `ui_rect` (in ui space).
154 //
155 // If the projection results in a negative `w` term (e.g. the point lies
156 // beind the camera) then the returned point will contain NaNs.
157 Vector2 world_to_ui(const Vector3& world_position, const Rect& ui_rect) const;
158
159 // Returns a `Ray` in world space that represents where `ui_position` (in
160 // ui space, Z unknown) would shoot along the view space's Z axis, assuming
161 // `ui_rect` represents the ui space viewport that this camera projects to.
163
164 // Returns the view volume's vertical extent in world units at a given depth
165 // from the camera origin.
167 private:
168 friend bool operator==(const Camera&, const Camera&);
169 class Impl;
171 };
172
173 bool operator==(const Camera&, const Camera&);
174}
Definition angle.h:26
Definition camera.h:21
Vector3 forward() const
void set_up(const Vector3 &)
void set_vertical_field_of_view(Radians)
void set_far_clipping_plane(float)
float near_clipping_plane() const
void set_clipping_planes(CameraClippingPlanes)
float view_volume_height_at_depth(float depth) const
void set_position(const Vector3 &)
Vector3 position() const
Matrix4x4 inverse_view_projection_matrix(float aspect_ratio) const
Vector3 up() const
Matrix4x4 inverse_view_matrix() const
friend bool operator==(const Camera &, const Camera &)
CameraProjection projection() const
float far_clipping_plane() const
Radians horizontal_field_of_view(float aspect_ratio) const
std::optional< Matrix4x4 > view_matrix_override() const
std::optional< Matrix4x4 > projection_matrix_override() const
Matrix4x4 view_matrix() const
CameraClippingPlanes clipping_planes() const
void set_projection_matrix_override(std::optional< Matrix4x4 >)
void set_direction(const Vector3 &)
void reset()
void set_projection(CameraProjection)
void set_orthographic_size(float)
Ray ui_to_world(const Vector2 &ui_position, const Rect &ui_rect) const
Radians vertical_field_of_view() const
Vector3 direction() const
Ray principal_ray() const
Matrix4x4 view_projection_matrix(float aspect_ratio) const
void set_forward(const Vector3 &direction)
void set_rotation(const Quaternion &)
void set_view_matrix_override(std::optional< Matrix4x4 >)
float orthographic_size() const
Matrix4x4 projection_matrix(float aspect_ratio) const
Quaternion rotation() const
void set_near_clipping_plane(float)
Vector2 world_to_ui(const Vector3 &world_position, const Rect &ui_rect) const
Definition copy_on_upd_shared_value.h:16
Definition rect.h:17
Definition custom_decoration_generator.h:5
CameraProjection
Definition camera_projection.h:8
bool operator==(const Class &, const Class &)
Definition camera_clipping_planes.h:7
Definition ray.h:17