-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvector.h
51 lines (43 loc) · 1.16 KB
/
vector.h
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
50
51
#pragma once
#include <numbers>
#include <cmath>
struct Vector3
{
// constructor
constexpr Vector3(
const float x = 0.f,
const float y = 0.f,
const float z = 0.f) noexcept :
x(x), y(y), z(z) { }
// operator overloads
constexpr const Vector3& operator-(const Vector3& other) const noexcept
{
return Vector3{ x - other.x, y - other.y, z - other.z };
}
constexpr const Vector3& operator+(const Vector3& other) const noexcept
{
return Vector3{ x + other.x, y + other.y, z + other.z };
}
constexpr const Vector3& operator/(const float factor) const noexcept
{
return Vector3{ x / factor, y / factor, z / factor };
}
constexpr const Vector3& operator*(const float factor) const noexcept
{
return Vector3{ x * factor, y * factor, z * factor };
}
// utils
constexpr const Vector3& ToAngle() const noexcept
{
return Vector3{
std::atan2(-z, std::hypot(x, y)) * (180.0f / std::numbers::pi_v<float>),
std::atan2(y, x) * (180.0f / std::numbers::pi_v<float>),
0.0f };
}
constexpr const bool IsZero() const noexcept
{
return x == 0.f && y == 0.f && z == 0.f;
}
// struct data
float x, y, z;
};