IceShard
1
A personal game engine project, with development focused on 2D/2.5D games.
Toggle main menu visibility
Loading...
Searching...
No Matches
math
public
ice
math
matrix.hxx
Go to the documentation of this file.
1
3
4
#pragma once
5
#include <
ice/math/constants.hxx
>
6
7
namespace
ice::math
8
{
9
10
template
<u32 Rows, u32 Cols,
typename
T>
11
struct
mat
12
{
13
using
value_type
= T;
14
static
constexpr
u32
count_rows
= Rows;
15
static
constexpr
u32
count_columns
= Cols;
16
17
T
v
[
count_columns
][
count_rows
];
18
};
19
20
template
<
typename
T>
21
struct
mat
<2, 2, T>
22
{
23
using
value_type
= T;
24
static
constexpr
u32
count_rows
= 3;
25
static
constexpr
u32
count_columns
= 3;
26
27
T
v
[
count_columns
][
count_rows
];
28
29
template
<
typename
U>
30
constexpr
operator
mat<3, 3, U>
() noexcept;
31
};
32
33
34
template<typename Mat>
35
constexpr auto
identity
() noexcept;
36
37
38
using
mat2x2
=
mat
<2, 2,
f32
>;
39
using
mat2
=
mat2x2
;
40
41
using
mat3x3
=
mat
<3, 3,
f32
>;
42
using
mat3
=
mat3x3
;
43
44
using
mat4x4
=
mat
<4, 4,
f32
>;
45
using
mat4
=
mat4x4
;
46
47
template<typename T>
48
template<typename U>
49
constexpr
mat
<2, 2, T>::operator
mat
<3, 3, U>() noexcept
50
{
51
mat<3, 3, U>
result;
52
result.
v
[0][0] =
v
[0][0];
53
result.
v
[0][1] =
v
[0][1];
54
result.
v
[1][0] =
v
[1][0];
55
result.
v
[1][1] =
v
[1][1];
56
result.
v
[2][2] = 1;
57
return
result;
58
}
59
60
template
<
typename
Mat>
61
constexpr
auto
identity
() noexcept
62
{
63
static_assert
(
64
Mat::count_columns == Mat::count_rows,
65
"Only even martices can be used with 'core::math::identity()'"
66
);
67
68
Mat result{ };
69
for
(
u32
col = 0; col < Mat::count_columns; ++col)
70
{
71
result.v[col][col] =
typename
Mat::value_type{ 1 };
72
}
73
return
result;
74
}
75
76
77
static
constexpr
auto
mat2x2_identity
=
identity<mat<2, 2, f32>
>();
78
static
constexpr
auto
mat3x3_identity
=
identity<mat<3, 3, f32>
>();
79
static
constexpr
auto
mat4x4_identity
=
identity<mat<4, 4, f32>
>();
80
81
}
// namespace ice::math
constants.hxx
ice::math
Definition
algorithm.hxx:8
ice::math::mat2x2_identity
static constexpr auto mat2x2_identity
Definition
matrix.hxx:77
ice::math::mat3x3
mat< 3, 3, f32 > mat3x3
Definition
matrix.hxx:41
ice::math::identity
constexpr auto identity() noexcept
Definition
matrix.hxx:61
ice::math::mat2
mat2x2 mat2
Definition
matrix.hxx:39
ice::math::mat3x3_identity
static constexpr auto mat3x3_identity
Definition
matrix.hxx:78
ice::math::mat2x2
mat< 2, 2, f32 > mat2x2
Definition
matrix.hxx:38
ice::math::mat4x4_identity
static constexpr auto mat4x4_identity
Definition
matrix.hxx:79
ice::math::mat4x4
mat< 4, 4, f32 > mat4x4
Definition
matrix.hxx:44
ice::math::mat3
mat3x3 mat3
Definition
matrix.hxx:42
ice::math::mat4
mat4x4 mat4
Definition
matrix.hxx:45
ice::math::mat
mat(T(&)[Size]) -> mat< Size, 1, T >
ice::u32
std::uint32_t u32
Definition
types.hxx:26
ice::f32
float f32
Definition
types.hxx:16
ice::math::mat< 2, 2, T >::count_rows
static constexpr u32 count_rows
Definition
matrix.hxx:24
ice::math::mat< 2, 2, T >::count_columns
static constexpr u32 count_columns
Definition
matrix.hxx:25
ice::math::mat< 2, 2, T >::value_type
T value_type
Definition
matrix.hxx:23
ice::math::mat< 2, 2, T >::v
T v[count_columns][count_rows]
Definition
matrix.hxx:27
ice::math::mat
Definition
matrix.hxx:12
ice::math::mat::value_type
T value_type
Definition
matrix.hxx:13
ice::math::mat< 2, 2, f32 >::count_rows
static constexpr u32 count_rows
Definition
matrix.hxx:14
ice::math::mat< 2, 2, f32 >::count_columns
static constexpr u32 count_columns
Definition
matrix.hxx:15
ice::math::mat< 2, 2, f32 >::v
f32 v[count_columns][count_rows]
Definition
matrix.hxx:17
Generated by
1.18.0