The small3d library
Tiny C++ 3D game development library for Win/MacOS/Linux/FreeBSD
Loading...
Searching...
No Matches
include
small3d
Math.hpp
Go to the documentation of this file.
1
10
#pragma once
11
12
namespace
small3d
{
13
14
struct
Vec4;
15
21
struct
Vec3
{
22
float
x = 0.0f;
23
float
y = 0.0f;
24
float
z = 0.0f;
25
Vec3
();
26
Vec3
(
float
x,
float
y,
float
z);
27
explicit
Vec3
(
float
v);
28
explicit
Vec3
(
const
Vec4
& vec);
29
30
Vec3
& operator+=(
const
Vec3
& other);
31
Vec3
operator+(
const
Vec3
& other)
const
;
32
Vec3
& operator-=(
const
Vec3
& other);
33
Vec3
operator-(
const
Vec3
& other)
const
;
34
Vec3
operator*(
const
Vec3
& other)
const
;
35
Vec3
operator*(
const
float
v)
const
;
36
Vec3
operator/(
const
float
v)
const
;
37
Vec3
& operator/=(
const
float
v);
38
Vec3
& operator=(
const
Vec3
& other);
39
Vec3
& operator+=(
const
float
v);
40
bool
operator==(
const
Vec3
& other)
const
;
41
bool
operator!=(
const
Vec3
& other)
const
;
42
template
<
class
Archive>
43
void
serialize(Archive& archive) {
44
archive(x, y, z);
45
}
46
};
47
48
Vec3
operator*(
const
float
v,
const
Vec3
& vec);
49
55
struct
Vec3i
{
56
int
x = 0;
57
int
y = 0;
58
int
z = 0;
59
Vec3i
();
60
Vec3i
(
int
x,
int
y,
int
z);
61
};
62
68
struct
Vec4
{
69
float
x = 0.0f;
70
float
y = 0.0f;
71
float
z = 0.0f;
72
float
w = 0.0f;
73
Vec4
();
74
Vec4
(
float
x,
float
y,
float
z,
float
w);
75
Vec4
(
const
Vec3
& vec3,
float
w);
76
77
Vec4
& operator+=(
const
Vec4
& other);
78
Vec4
operator+(
const
Vec4
& other);
79
Vec4
operator-(
const
Vec4
& other);
80
Vec4
& operator*=(
const
float
v);
81
Vec4
operator*(
const
float
v)
const
;
82
Vec4
operator*(
const
Vec4
& other)
const
;
83
Vec4
& operator/=(
const
float
div);
84
float
& operator[](
int
idx);
85
Vec4
& operator=(
const
Vec4
& other);
86
template
<
class
Archive>
87
void
serialize(Archive& archive) {
88
archive(x, y, z, w);
89
}
90
};
91
97
struct
Vec4i
{
98
int
x = 0;
99
int
y = 0;
100
int
z = 0;
101
int
w = 0;
102
Vec4i
();
103
Vec4i
(
int
x,
int
y,
int
z,
int
w);
104
Vec4i
(
const
Vec3i
& vec3i,
float
w);
105
};
106
112
struct
Mat4
{
113
Vec4
data[4];
114
Mat4
();
115
explicit
Mat4
(
float
v);
116
Mat4
(
Vec4
r0,
Vec4
r1,
Vec4
r2,
Vec4
r3);
117
Mat4
(
float
r0x,
float
r0y,
float
r0z,
float
r0w,
118
float
r1x,
float
r1y,
float
r1z,
float
r1w,
119
float
r2x,
float
r2y,
float
r2z,
float
r2w,
120
float
r3x,
float
r3y,
float
r3z,
float
r3w );
121
Vec4
& operator[](
int
idx);
122
Mat4
operator-(
const
Mat4
& other)
const
;
123
Mat4
operator*(
const
Mat4
& other)
const
;
124
Vec4
operator*(
const
Vec4
& vec)
const
;
125
Mat4
& operator*=(
const
Mat4
& other);
126
Mat4
& operator*=(
const
float
v);
127
Mat4
operator*(
const
float
v)
const
;
128
Mat4
& operator/=(
const
float
div);
129
Mat4
& operator=(
const
Mat4
& other);
130
template
<
class
Archive>
131
void
serialize(Archive& archive) {
132
archive(data);
133
}
134
};
135
141
struct
Quat
{
142
143
144
float
x;
145
float
y;
146
float
z;
147
float
w;
148
149
Mat4
toMatrix()
const
;
150
Quat
operator*(
const
Quat
& other);
151
template
<
class
Archive>
152
void
serialize(Archive& archive) {
153
archive(w, x, y, z);
154
}
155
};
156
157
Mat4
translate(
const
Mat4
& mat,
const
Vec3
& vec);
158
159
Mat4
scale(
const
Mat4
& mat,
const
Vec3
& vec);
160
161
Mat4
rotate(
const
Mat4
& mat,
const
float
angle,
const
Vec3
& vec);
162
163
Mat4
ortho(
float
left,
float
right,
float
bottom,
float
top,
float
zNear,
float
zFar);
164
165
Mat4
perspective(
float
fovy,
float
aspect,
float
zNear,
float
zFar);
166
167
Mat4
inverse(
const
Mat4
& mat);
168
169
Vec3
clamp(
const
Vec3
& vec,
const
Vec3
& minv,
const
Vec3
& maxv);
170
171
float
dot(
const
Vec3
& vec1,
const
Vec3
& vec2);
172
173
Vec3
cross(
const
Vec3
& vec1,
const
Vec3
& vec2);
174
175
float
length(
const
Vec3
& vec);
176
177
float
* Value_ptr(
Mat4
& mat);
178
179
float
* Value_ptr(
Vec3
& vec);
180
181
float
* Value_ptr(
Vec4
& vec);
182
183
}
small3d
Definition
BinaryFile.hpp:15
small3d::Mat4
4x4 float matrix
Definition
Math.hpp:112
small3d::Quat
Quaternion.
Definition
Math.hpp:141
small3d::Vec3
3 component float vector
Definition
Math.hpp:21
small3d::Vec3i
3 component integer vector
Definition
Math.hpp:55
small3d::Vec4
4 component vector
Definition
Math.hpp:68
small3d::Vec4i
4 component integer vector
Definition
Math.hpp:97
Generated by
1.12.0