camera.ixx File
Camera transform helpers. More...
Included Headers
#include <cmath>
#include <array>
#include <utility>
#include <helios.math.utils>
#include <helios.math.TransformType>
#include <helios.math.types>
Namespaces Index
| namespace | helios |
| namespace | math |
Classes Index
| struct | FrustumPlane |
|
Struct for providing FrustumPlane information, i.e. it's normal (facing inward) and the distance of the plane to the origin. More... | |
Description
Camera transform helpers.
File Listing
The file content with the documentation metadata removed is:
18export namespace helios::math {
23 enum class FrustumPlanePosition : u_int8_t {
24 Near,
25 Far,
26 Left,
27 Right,
28 Top,
29 Bottom
36 struct FrustumPlane {
60 inline mat4f perspective(const float fovY, const float aspect, const float zNear, const float zFar) noexcept {
64 return mat4f{
100 return mat4f{
135 const auto x = cross(up, z).normalize();
136 const auto y = cross(z, x).normalize();
138 return mat4f{
159 inline std::array<FrustumPlane, 6> frustumPlanes(
160 const float fovY, const float aspect, const float zNear, const float zFar, const helios::math::mat4f& viewMatrix) noexcept {
168 const auto cameraRotation = viewMatrix.decompose(TransformType::Rotation).transpose();
171 const auto right = helios::math::vec3f{cameraRotation(0, 0), cameraRotation(1, 0), cameraRotation(2, 0)};
172 const auto up = helios::math::vec3f{cameraRotation(0, 1), cameraRotation(1, 1), cameraRotation(2, 1)};
173 const auto forward = helios::math::vec3f{cameraRotation(0, 2), cameraRotation(1, 2), cameraRotation(2, 2)};
175 static auto makePlane = [](helios::math::vec3f normal, const helios::math::vec3f& point) noexcept {
176 normal = normal.normalize();
177 return FrustumPlane{normal, dot(normal, point)};
180 arr[std::to_underlying(FrustumPlanePosition::Near)] = makePlane(forward, eye + forward * zNear);
181 arr[std::to_underlying(FrustumPlanePosition::Far)] = makePlane(forward * -1.0f, eye + forward * zFar);
182 arr[std::to_underlying(FrustumPlanePosition::Left)] = makePlane(g * right + s * forward, eye);
183 arr[std::to_underlying(FrustumPlanePosition::Right)] = makePlane(-g * right + s * forward, eye);
184 arr[std::to_underlying( FrustumPlanePosition::Bottom)] = makePlane(g * up + forward, eye);
185 arr[std::to_underlying(FrustumPlanePosition::Top)] = makePlane(-g * up + forward, eye);
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.