4#ifndef GREM_GRAPHICS_2D_CAMERA_2D_HPP
5#define GREM_GRAPHICS_2D_CAMERA_2D_HPP
143 : parameterBuffer(device)
160 setProjectionWithoutFlush(newProjection);
176 setViewWithoutFlush(newView);
191 options = newOptions;
208 setProjectionWithoutFlush(newProjection);
209 setViewWithoutFlush(newView);
226 setViewWithoutFlush(newView);
227 options = newOptions;
247 setProjectionWithoutFlush(newProjection);
248 setViewWithoutFlush(newView);
249 options = newOptions;
259 return parameterBuffer;
268 return projectionMatrix;
290 void setProjectionWithoutFlush(
const Projection2D& newProjection) {
293 projectionMatrix = newProjectionMatrix;
296 GREM_CASE(
const OrthographicProjection2D& newOrthographicProjection) {
297 projectionMatrix =
scale(2.0f / newOrthographicProjection.size) *
translate(newOrthographicProjection.size * -0.5f - newOrthographicProjection.offset);
303 void setViewWithoutFlush(
const View2D& newView) {
306 viewMatrix = newViewMatrix;
309 GREM_CASE(
const WorldView2D& newWorldView) {
311 const vec2 inversePosition = inverseBasis * -newWorldView.position;
313 vec3{inverseBasis[0], 0.0f},
314 vec3{inverseBasis[1], 0.0f},
315 vec3{inversePosition, 1.0f},
324 const vec2 position = basis * -
vec2{viewMatrix[2]};
326 .cameraProjectionMatrix = projectionMatrix,
327 .cameraViewMatrix = viewMatrix,
328 .cameraViewProjectionMatrix = projectionMatrix * viewMatrix,
329 .cameraPosition = position,
330 .cameraBasis = basis,
335 mat3 projectionMatrix{1.0f};
336 mat3 viewMatrix{1.0f};
337 [[no_unique_address]] Camera2DOptions options;
#define GREM_MATCH(...)
Definition Variant.hpp:1997
#define GREM_CASE(...)
Definition Variant.hpp:1998
friend class Variant
JSON value type using the default allocator.
Definition Variant.hpp:1402
Camera2DOptions getOptions() const noexcept
Get the configuration options of the camera.
Definition Camera2D.hpp:285
const mat3 & getViewMatrix() const noexcept
Get the view matrix of the camera.
Definition Camera2D.hpp:276
void setProjectionAndViewAndOptions(const Projection2D &newProjection, const View2D &newView, const Camera2DOptions &newOptions)
Set both the projection and view of the camera, as well as its configuration options.
Definition Camera2D.hpp:246
void setProjection(const Projection2D &newProjection)
Set the projection of the camera.
Definition Camera2D.hpp:159
Camera2D(Device &device, const Projection2D &projection=mat3{1.0f}, const View2D &view=mat3{1.0f}, const Camera2DOptions &options={})
Construct a camera.
Definition Camera2D.hpp:142
void setViewAndOptions(const View2D &newView, const Camera2DOptions &newOptions)
Set both the view and configuration options of the camera.
Definition Camera2D.hpp:225
void setView(const View2D &newView)
Set the view of the camera.
Definition Camera2D.hpp:175
void setOptions(const Camera2DOptions &newOptions)
Set the configuration options of the camera.
Definition Camera2D.hpp:190
const ParameterBuffer & getParameterBuffer() const noexcept
Get the parameter buffer of the camera.
Definition Camera2D.hpp:258
UniformBuffer< Parameters, "Camera2DParameters"> ParameterBuffer
Shader buffer for 2D camera parameters.
Definition Camera2D.hpp:125
const mat3 & getProjectionMatrix() const noexcept
Get the projection matrix of the camera.
Definition Camera2D.hpp:267
void setProjectionAndView(const Projection2D &newProjection, const View2D &newView)
Set both the projection and view of the camera.
Definition Camera2D.hpp:207
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
Definition buffer_layouts.hpp:20
GREM_ALWAYS_INLINE constexpr mat< 3, 3, T > GREM_VECTORCALL translate(vec< 2, T > translation)
Create a translation matrix describing a 2D translation.
Definition math.hpp:2631
vec< 2, float > vec2
Definition math.hpp:438
GREM_ALWAYS_INLINE constexpr mat< R, C, T > transpose(const mat< C, R, T > &a)
Definition math.hpp:2247
vec< 3, float > vec3
Definition math.hpp:439
mat< 3, 3, float > mat3
Definition math.hpp:805
GREM_ALWAYS_INLINE mat< 3, 3, T > GREM_VECTORCALL rotateScale(T rotation, vec< 2, T > scale)
Create a combined rotation and scale matrix describing a 2D transformation.
Definition math.hpp:2765
mat< 2, 2, float > mat2
Definition math.hpp:804
GREM_ALWAYS_INLINE constexpr mat< 3, 3, T > GREM_VECTORCALL scale(vec< 2, T > scale)
Create a scale matrix describing a 2D scale.
Definition math.hpp:2665
Configuration options for a Camera2D.
Definition Camera2D.hpp:95
constexpr bool operator==(const Camera2DOptions &other) const noexcept=default
Compare these options to another set of options for equality.
Struct of shader parameters representing the state of a Camera2D.
Definition Camera2D.hpp:114
mat3 cameraViewMatrix
Current view matrix of the camera.
Definition Camera2D.hpp:116
mat2 cameraBasis
Current right and up direction vectors (local X and Y axes) of the camera.
Definition Camera2D.hpp:119
mat3 cameraViewProjectionMatrix
Current combined view-projection matrix of the camera.
Definition Camera2D.hpp:117
vec2 cameraPosition
Current position of the camera in world space.
Definition Camera2D.hpp:118
mat3 cameraProjectionMatrix
Current projection matrix of the camera.
Definition Camera2D.hpp:115
Configuration of an orthographic projection in 2D.
Definition Camera2D.hpp:21
vec2 size
Size of the orthographic projection, in render target coordinates.
Definition Camera2D.hpp:31
constexpr bool operator==(const OrthographicProjection2D &other) const =default
Compare these options to another set of options for equality.
vec2 offset
Bottom left corner of the orthographic projection, in render target coordinates.
Definition Camera2D.hpp:26
Projection matrix or configuration of a projection in 2D.
Definition Camera2D.hpp:46
constexpr Variant() noexcept(std::is_nothrow_default_constructible_v< variant_alternative_t< 0, Variant > >)
Default-construct a variant with the first variant alternative, if it is default-constructible.
Definition Variant.hpp:351
View matrix or configuration of a view in 2D.
Definition Camera2D.hpp:88
constexpr Variant() noexcept(std::is_nothrow_default_constructible_v< variant_alternative_t< 0, Variant > >)
Default-construct a variant with the first variant alternative, if it is default-constructible.
Definition Variant.hpp:351
Configuration of a world-space view in 2D.
Definition Camera2D.hpp:53
vec2 scale
World-space scale of the view.
Definition Camera2D.hpp:82
vec2 position
World-space position of the view origin.
Definition Camera2D.hpp:62
float angle
World-space orientation of the view around its origin, in radians.
Definition Camera2D.hpp:72