IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
lookat.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/math.hxx>
6
7namespace ice::math
8{
9
10 inline auto lookat(
11 vec<3, f32> pos,
12 vec<3, f32> target,
14 ) noexcept -> mat<4, 4, f32>;
15
16 inline auto lookat(
17 vec<3, f32> pos,
18 vec<3, f32> target,
20 ) noexcept -> mat<4, 4, f32>
21 {
22 vec<3, f32> const dir = normalize(pos - target);
23 vec<3, f32> const right = normalize(cross(up, dir));
24 vec<3, f32> const view_up = cross(dir, right);
25
26 mat<4, 4, f32> const temp {
27 right.v[0][0], view_up.v[0][0], dir.v[0][0], 0.0f,
28 right.v[0][1], view_up.v[0][1], dir.v[0][1], 0.0f,
29 right.v[0][2], view_up.v[0][2], dir.v[0][2], 0.0f,
30 0.0f, 0.0f, 0.0f, 1.0f,
31 };
32 return temp * translate(-pos);
33 }
34
35} // namespace core::math
Definition algorithm.hxx:8
mat< Size, 1, T > vec
Definition vector.hxx:172
auto normalize(vec< Size, T > value) noexcept -> vec< Size, T >
Definition vector_operations.hxx:137
auto lookat(vec< 3, f32 > pos, vec< 3, f32 > target, vec< 3, f32 > up) noexcept -> mat< 4, 4, f32 >
Definition lookat.hxx:16
constexpr auto translate(vec< 2, f32 > displacement) noexcept -> mat< 3, 3, f32 >
Definition translate.hxx:20
constexpr auto cross(vec< 3, f32 > left, vec< 3, f32 > right) noexcept -> vec< 3, f32 >
Definition vector_operations.hxx:115
Definition matrix.hxx:12
T v[count_columns][count_rows]
Definition matrix.hxx:17