generated from 32blit/32blit-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vec4.hpp
49 lines (39 loc) · 1.52 KB
/
vec4.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "types/mat4.hpp"
#include "fixed-mat4.hpp"
class Vec4
{
public:
Vec4(){}
Vec4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w){}
float x, y, z, w;
};
inline Vec4 operator*(const blit::Mat4 &mat, const Vec4 &vec)
{
Vec4 out;
out.x = (vec.x * mat.v00) + (vec.y * mat.v01) + (vec.z * mat.v02) + (vec.w * mat.v03);
out.y = (vec.x * mat.v10) + (vec.y * mat.v11) + (vec.z * mat.v12) + (vec.w * mat.v13);
out.z = (vec.x * mat.v20) + (vec.y * mat.v21) + (vec.z * mat.v22) + (vec.w * mat.v23);
out.w = (vec.x * mat.v30) + (vec.y * mat.v31) + (vec.z * mat.v32) + (vec.w * mat.v33);
return out;
}
template <class T = int32_t, int frac_bits = sizeof(T) * 4>
class FixedVec4
{
public:
using FixedT = Fixed<T, frac_bits>;
FixedVec4(){}
FixedVec4(FixedT x, FixedT y, FixedT z, FixedT w) : x(x), y(y), z(z), w(w){}
FixedVec4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w){}
FixedT x, y, z, w;
};
template <class T, int frac_bits>
inline FixedVec4<T, frac_bits> operator*(const FixedMat4<T, frac_bits> &mat, const FixedVec4<T, frac_bits> &vec)
{
FixedVec4<T, frac_bits> out;
out.x = (vec.x * mat.v00) + (vec.y * mat.v01) + (vec.z * mat.v02) + (vec.w * mat.v03);
out.y = (vec.x * mat.v10) + (vec.y * mat.v11) + (vec.z * mat.v12) + (vec.w * mat.v13);
out.z = (vec.x * mat.v20) + (vec.y * mat.v21) + (vec.z * mat.v22) + (vec.w * mat.v23);
out.w = (vec.x * mat.v30) + (vec.y * mat.v31) + (vec.z * mat.v32) + (vec.w * mat.v33);
return out;
}