SGCT master (487fac4)
Simple Graphics Cluster Toolkit
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1/*****************************************************************************************
2 * SGCT *
3 * Simple Graphics Cluster Toolkit *
4 * *
5 * Copyright (c) 2012-2026 *
6 * For conditions of distribution and use, see copyright notice in LICENSE.md *
7 ****************************************************************************************/
8
9#ifndef __SGCT__MATH_H__
10#define __SGCT__MATH_H__
11
12#include <sgct/sgctexports.h>
13#include <array>
14
15namespace sgct {
16
17struct SGCT_EXPORT ivec2 {
18 constexpr ivec2() = default;
19 constexpr ivec2(int x_, int y_) : x(x_), y(y_) {}
20 bool operator==(const ivec2&) const noexcept = default;
21
22 int x = 0;
23 int y = 0;
24};
25
26struct SGCT_EXPORT ivec3 {
27 constexpr ivec3() = default;
28 constexpr ivec3(int x_, int y_, int z_) : x(x_), y(y_), z(z_) {}
29 bool operator==(const ivec3&) const noexcept = default;
30
31 int x = 0;
32 int y = 0;
33 int z = 0;
34};
35
36struct SGCT_EXPORT ivec4 {
37 constexpr ivec4() = default;
38 constexpr ivec4(int x_, int y_, int z_, int w_) : x(x_), y(y_), z(z_), w(w_) {}
39 bool operator==(const ivec4&) const noexcept = default;
40
41 int x = 0;
42 int y = 0;
43 int z = 0;
44 int w = 0;
45};
46
47struct SGCT_EXPORT vec2 {
48 constexpr vec2() = default;
49 constexpr vec2(float x_, float y_) : x(x_), y(y_) {}
50 bool operator==(const vec2&) const noexcept = default;
51
52 float x = 0.f;
53 float y = 0.f;
54};
55
56struct SGCT_EXPORT vec3 {
57 constexpr vec3() = default;
58 constexpr vec3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) {}
59 bool operator==(const vec3&) const noexcept = default;
60
61 float x = 0.f;
62 float y = 0.f;
63 float z = 0.f;
64};
65
66struct SGCT_EXPORT vec4 {
67 constexpr vec4() = default;
68 constexpr vec4(float x_, float y_, float z_, float w_) : x(x_), y(y_), z(z_), w(w_) {}
69 bool operator==(const vec4&) const noexcept = default;
70
71 float x = 0.f;
72 float y = 0.f;
73 float z = 0.f;
74 float w = 0.f;
75};
76
77struct SGCT_EXPORT quat {
78 constexpr quat() = default;
79 constexpr quat(float x_, float y_, float z_, float w_) : x(x_), y(y_), z(z_), w(w_) {}
80 bool operator==(const quat&) const noexcept = default;
81
82 float x = 0.f;
83 float y = 0.f;
84 float z = 0.f;
85 float w = 0.f;
86};
87
88// Column-major order matrix
89struct SGCT_EXPORT mat4 {
90 constexpr mat4() = default;
91 constexpr mat4(float v) {
92 values[0 * 4 + 0] = v;
93 values[0 * 4 + 1] = 0.f;
94 values[0 * 4 + 2] = 0.f;
95 values[0 * 4 + 3] = 0.f;
96 values[1 * 4 + 0] = 0.f;
97 values[1 * 4 + 1] = v;
98 values[1 * 4 + 2] = 0.f;
99 values[1 * 4 + 3] = 0.f;
100 values[2 * 4 + 0] = 0.f;
101 values[2 * 4 + 1] = 0.f;
102 values[2 * 4 + 2] = v;
103 values[2 * 4 + 3] = 0.f;
104 values[3 * 4 + 0] = 0.f;
105 values[3 * 4 + 1] = 0.f;
106 values[3 * 4 + 2] = 0.f;
107 values[3 * 4 + 3] = v;
108 }
109 bool operator==(const mat4&) const noexcept = default;
110
111 std::array<float, 16> values;
112};
113
114SGCT_EXPORT mat4 operator*(const mat4& m1, const mat4& m2);
115SGCT_EXPORT vec4 operator*(const mat4& m, const vec4& v);
116SGCT_EXPORT vec3 operator*(const quat& q, const vec3& v);
117
118} // namespace sgct
119
120#endif // __SGCT__MATH_H__
Definition actions.h:16
mat4 operator*(const mat4 &m1, const mat4 &m2)
int x
Definition math.h:22
int y
Definition math.h:23
bool operator==(const ivec2 &) const noexcept=default
constexpr ivec2()=default
constexpr ivec2(int x_, int y_)
Definition math.h:19
bool operator==(const ivec3 &) const noexcept=default
int z
Definition math.h:33
constexpr ivec3(int x_, int y_, int z_)
Definition math.h:28
constexpr ivec3()=default
int y
Definition math.h:32
int x
Definition math.h:31
int x
Definition math.h:41
int y
Definition math.h:42
int z
Definition math.h:43
constexpr ivec4()=default
bool operator==(const ivec4 &) const noexcept=default
int w
Definition math.h:44
constexpr ivec4(int x_, int y_, int z_, int w_)
Definition math.h:38
Definition math.h:89
std::array< float, 16 > values
Definition math.h:111
bool operator==(const mat4 &) const noexcept=default
constexpr mat4(float v)
Definition math.h:91
constexpr mat4()=default
Definition math.h:77
float w
Definition math.h:85
bool operator==(const quat &) const noexcept=default
constexpr quat()=default
float y
Definition math.h:83
constexpr quat(float x_, float y_, float z_, float w_)
Definition math.h:79
float z
Definition math.h:84
float x
Definition math.h:82
bool operator==(const vec2 &) const noexcept=default
float x
Definition math.h:52
constexpr vec2()=default
float y
Definition math.h:53
constexpr vec2(float x_, float y_)
Definition math.h:49
Definition math.h:56
constexpr vec3(float x_, float y_, float z_)
Definition math.h:58
float x
Definition math.h:61
float y
Definition math.h:62
bool operator==(const vec3 &) const noexcept=default
constexpr vec3()=default
float z
Definition math.h:63
Definition math.h:66
constexpr vec4()=default
float z
Definition math.h:73
float y
Definition math.h:72
float x
Definition math.h:71
constexpr vec4(float x_, float y_, float z_, float w_)
Definition math.h:68
float w
Definition math.h:74
bool operator==(const vec4 &) const noexcept=default