1 #ifndef COMMON_VECMAT_H
2 #define COMMON_VECMAT_H
13 alignas(16) std::array
<float,4> mVals
;
16 Vector() noexcept
= default;
17 constexpr Vector(float a
, float b
, float c
, float d
) noexcept
21 float& operator[](size_t idx
) noexcept
{ return mVals
[idx
]; }
22 constexpr const float& operator[](size_t idx
) const noexcept
{ return mVals
[idx
]; }
24 Vector
& operator+=(const Vector
&rhs
) noexcept
26 mVals
[0] += rhs
.mVals
[0];
27 mVals
[1] += rhs
.mVals
[1];
28 mVals
[2] += rhs
.mVals
[2];
29 mVals
[3] += rhs
.mVals
[3];
35 const float length
{std::sqrt(mVals
[0]*mVals
[0] + mVals
[1]*mVals
[1] + mVals
[2]*mVals
[2])};
36 if(length
> std::numeric_limits
<float>::epsilon())
38 float inv_length
= 1.0f
/length
;
39 mVals
[0] *= inv_length
;
40 mVals
[1] *= inv_length
;
41 mVals
[2] *= inv_length
;
44 mVals
[0] = mVals
[1] = mVals
[2] = 0.0f
;
50 alignas(16) std::array
<std::array
<float,4>,4> mVals
;
53 Matrix() noexcept
= default;
54 constexpr Matrix(float aa
, float ab
, float ac
, float ad
,
55 float ba
, float bb
, float bc
, float bd
,
56 float ca
, float cb
, float cc
, float cd
,
57 float da
, float db
, float dc
, float dd
) noexcept
58 : mVals
{{{{aa
, ab
, ac
, ad
}}, {{ba
, bb
, bc
, bd
}}, {{ca
, cb
, cc
, cd
}}, {{da
, db
, dc
, dd
}}}}
61 std::array
<float,4>& operator[](size_t idx
) noexcept
{ return mVals
[idx
]; }
62 constexpr const std::array
<float,4>& operator[](size_t idx
) const noexcept
{ return mVals
[idx
]; }
64 void setRow(size_t idx
, float a
, float b
, float c
, float d
) noexcept
72 static const Matrix
&Identity() noexcept
74 static constexpr Matrix identity
{
75 1.0f
, 0.0f
, 0.0f
, 0.0f
,
76 0.0f
, 1.0f
, 0.0f
, 0.0f
,
77 0.0f
, 0.0f
, 1.0f
, 0.0f
,
78 0.0f
, 0.0f
, 0.0f
, 1.0f
86 #endif /* COMMON_VECMAT_H */