IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
translate.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/math/vector.hxx>
6
7namespace ice::math
8{
9
10 constexpr auto translate(vec<2, f32> displacement) noexcept -> mat<3, 3, f32>;
11 constexpr auto translate(vec<3, f32> displacement) noexcept -> mat<4, 4, f32>;
12
13 constexpr auto translate(mat<3, 3, f32> left, vec<2, f32> right) noexcept -> mat<3, 3, f32>;
14 constexpr auto translate(mat<4, 4, f32> left, vec<3, f32> right) noexcept -> mat<4, 4, f32>;
15
16 constexpr auto translation(mat<3, 3, f32> const& matrix) noexcept -> vec<2, f32>;
17 constexpr auto translation(mat<4, 4, f32> const& matrix) noexcept -> vec<3, f32>;
18
19
20 constexpr auto translate(vec<2, f32> displacement) noexcept -> mat<3, 3, f32>
21 {
22 return translate(mat3x3_identity, displacement);
23 }
24
25 constexpr auto translate(vec<3, f32> displacement) noexcept -> mat<4, 4, f32>
26 {
27 return translate(mat4x4_identity, displacement);
28 }
29
30 constexpr auto translate(mat<3, 3, f32> left, vec<2, f32> right) noexcept -> mat<3, 3, f32>
31 {
32 left.v[2][0] += right.v[0][0];
33 left.v[2][1] += right.v[0][1];
34 return left;
35 }
36
37 constexpr auto translate(mat<4, 4, f32> left, vec<3, f32> right) noexcept -> mat<4, 4, f32>
38 {
39 left.v[3][0] += right.v[0][0];
40 left.v[3][1] += right.v[0][1];
41 left.v[3][2] += right.v[0][2];
42 return left;
43 }
44
45 constexpr auto translation(mat<3, 3, f32> const& matrix) noexcept -> vec<2, f32>
46 {
47 return { matrix.v[2][0], matrix.v[2][1] };
48 }
49
50 constexpr auto translation(mat<4, 4, f32> const& matrix) noexcept -> vec<3, f32>
51 {
52 return { matrix.v[3][0], matrix.v[3][1], matrix.v[3][2] };
53 }
54
55} // namespace ice::math
Definition algorithm.hxx:8
mat< Size, 1, T > vec
Definition vector.hxx:172
static constexpr auto mat3x3_identity
Definition matrix.hxx:78
static constexpr auto mat4x4_identity
Definition matrix.hxx:79
constexpr auto translation(mat< 3, 3, f32 > const &matrix) noexcept -> vec< 2, f32 >
Definition translate.hxx:45
constexpr auto translate(vec< 2, f32 > displacement) noexcept -> mat< 3, 3, f32 >
Definition translate.hxx:20
Definition matrix.hxx:12