1#ifndef NNGN_MATH_CAMERA_H
2#define NNGN_MATH_CAMERA_H
93 static constexpr float NEAR = 0.01f;
95 static constexpr float FAR = 2048;
113 static constexpr float fov(
float z,
float w);
115 bool dash(
void)
const;
235 return 2.0f * std::atan(
w / 2.0f / z);
251 this->
flags.
set(Flag::PERSPECTIVE, b);
256 this->
flags.
set(Flag::IGNORE_LIMITS, b);
273 return {2.0f * (sp /
static_cast<vec2>(this->
screen)) -
vec2{1} , 0};
285 return static_cast<float>(this->
screen.
y)
287 / std::tan(this->
fov_y / 2);
316 this->
flags.
set(Flag::SCREEN_UPDATED);
static constexpr T pi(void)
Definition math.h:186
static vec3_base< T > perspective_transform(const mat4_base< T > &m, vec3_base< T > v)
Definition math.h:333
local r
Definition gamma.lua:7
update
Definition img_common.lua:42
set_limits
Definition img_common.lua:33
pos
Definition lua_audio.cpp:17
std::uint8_t u8
Definition def.h:12
set_perspective
Definition camera.lua:51
local w
Definition strict.lua:12
Abstract orthographic/perspective camera.
Definition camera.h:69
float fov_y
Field of view in perspective mode.
Definition camera.h:209
float fov_z
Enable auto-adjustment of the field-of-view angle.
Definition camera.h:216
vec3 tr_limit
Top right point of the limit for p.
Definition camera.h:195
void set_perspective(bool b)
Definition camera.h:250
vec3 rot_a
Rotational acceleration.
Definition camera.h:191
float damp
Damping factor when not accelerating.
Definition camera.h:218
vec3 up(void) const
The "up" vector for the view direction.
Definition camera.cpp:27
void set_fov_y(float f)
Definition camera.h:309
mat4 screen_proj
Projection matrix for screen coordinates.
Definition camera.h:224
vec3 clip_to_view(vec3 p) const
Projects a point from clip to view space.
Definition camera.h:276
void set_screen(uvec2 s)
Definition camera.h:314
static constexpr float NEAR
Perspective projection near plane.
Definition camera.h:93
vec3 bl_limit
Bottom left point of the limit for p.
Definition camera.h:193
bool dash(void) const
Definition camera.h:238
float zoom_a
Scaling factor acceleration.
Definition camera.h:201
float z_for_fov(void) const
Derives Z coordinate from the camera's screen size and field of view.
Definition camera.h:284
void set_zoom(float z)
Definition camera.h:304
float zoom
Scaling factor.
Definition camera.h:197
bool perspective(void) const
Definition camera.h:242
uvec2 screen
Screen size.
Definition camera.h:220
vec3 a
Acceleration.
Definition camera.h:185
mat4 view
View matrix.
Definition camera.h:226
mat4 inv_view
Inverse matrix of view.
Definition camera.h:230
void set_fov_z(float z)
Definition camera.h:174
vec3 v
Velocity.
Definition camera.h:183
float max_rot_v
Maximum value for rot_v.
Definition camera.h:205
float max_zoom_v
Maximum value for zoom_v.
Definition camera.h:207
void set_limits(vec3 bl, vec3 tr)
Definition camera.h:319
static constexpr float fov(float z, float w)
Calculates field of view based on screen size and distance.
Definition camera.h:234
vec3 view_to_clip(vec3 p) const
Projects a point from view to clip space.
Definition camera.h:264
vec2 clip_to_screen(vec3 p)
Projects a point from clip to screen space.
Definition camera.h:268
float zoom_v
Scaling factor velocity.
Definition camera.h:199
vec3 rot_v
Rotational velocity.
Definition camera.h:189
vec3 center(void) const
p added to a unit vector in the view direction.
Definition camera.cpp:23
static constexpr float FAR
Perspective projection far plane.
Definition camera.h:95
Flag
State flags and configuration.
Definition camera.h:71
@ DASH
Increases the speed of displacement/rotation/etc.
Definition camera.h:86
@ PERSPECTIVE
Chooses between orthographic/perspective mode.
Definition camera.h:88
@ UPDATED
Parameters of the camera have changed.
Definition camera.h:77
@ SCREEN_UPDATED
The screen size has changed.
Definition camera.h:84
@ IGNORE_LIMITS
The camera limits do not restrict movement when set.
Definition camera.h:90
void set_pos(vec3 p)
Definition camera.h:294
mat4 inv_proj
Inverse matrix of proj.
Definition camera.h:228
void set_ignore_limits(bool b)
Definition camera.h:255
void set_rot(vec3 r)
Definition camera.h:299
vec3 screen_to_clip(vec2 p)
Projects a point from screen to clip space.
Definition camera.h:272
vec3 world_to_view(vec3 p) const
Projects a point from world to view space.
Definition camera.h:260
vec3 view_to_world(vec3 p) const
Projects a point from view to world space.
Definition camera.h:280
void set_dash(bool b)
Definition camera.h:246
float max_v
Maximum value for v.
Definition camera.h:203
vec3 rot
Rotational Euler angles (ZYX).
Definition camera.h:187
void look_at(vec3 center, vec3 pos, vec3 up)
Definition camera.cpp:33
vec3 p
Position.
Definition camera.h:181
Flags< Flag > flags
Definition camera.h:231
static constexpr float FOVY
Perspective projection field of view along the Y axis (default).
Definition camera.h:97
float scale_for_fov(void) const
Derives orthographic scaling factor from camera parameters.
Definition camera.h:290
mat4 proj
Projection matrix (orthographic/perspective).
Definition camera.h:222
Wrapper for a small unsigned integral representing flags.
Definition flags.h:18
constexpr bool is_set(AT a) const
Definition flags.h:45
constexpr Flags & set(AT a)
Definition flags.h:47
constexpr vec2_base< T > xy() const
Definition vec3.h:26
static constexpr nngn::vec2 tr
Definition collision.cpp:8
static constexpr nngn::vec2 bl
Definition collision.cpp:8
std::chrono::seconds s
Definition timing.cpp:6