Skip to main content

camera.ixx File

Camera transform helpers. More...

Included Headers

#include <cmath> #include <helios.math.utils> #include <helios.math.types>

Namespaces Index

namespacehelios
namespacemath

Description

Camera transform helpers.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <cmath>
8
9export module helios.math.transform:camera;
10
11import helios.math.types;
12import helios.math.utils;
13
14
15export namespace helios::math {
16
35 inline mat4f perspective(float fovY, float aspect, float zNear, float zFar) noexcept {
36
37 float f = 1 / std::tan(fovY/2);
38
39 return mat4f{
40 f/aspect, 0.0f, 0.0f, 0.0f,
41 0.0f, f, 0.0f, 0.0f,
42 0.0f, 0.0f , -(zFar + zNear)/(zFar - zNear), -1.0f,
43 0.0f, 0.0f, -2 * (zFar * zNear) / (zFar - zNear), 0.0f
44 };
45 }
46
47
68 inline mat4f ortho(
69 const float left , const float right,
70 const float bottom, const float top,
71 const float zNear = 0.1f, const float zFar = 100.0f) noexcept {
72
73 return mat4f{
74 2.0f/(right - left), 0.0f,0.0f,0.0f,
75 0.0f, 2.0f/(top-bottom),0.0f,0.0f,
76 0.0f, 0.0f, -2.0f/(zFar - zNear),0.0f,
78 };
79 }
80
81
106 inline mat4f lookAt(const vec3f& eye, const vec3f& center, const vec3f& up) noexcept {
107 const auto z = (eye - center).normalize();
108 const auto x = cross(up, z).normalize();
109 const auto y = cross(z, x).normalize();
110
111 return mat4f{
112 x[0], y[0], z[0], 0.0f,
113 x[1], y[1], z[1], 0.0f,
114 x[2], y[2], z[2], 0.0f,
115 -dot(x, eye), -dot(y, eye), -dot(z, eye), 1.0f,
116 };
117 }
118
119}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.