-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVec3.hpp
109 lines (82 loc) · 2.53 KB
/
Vec3.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
// System
#include <iostream>
#include <string>
#include <stdio.h>
#include <SDL2/SDL.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
class Vec3 {
public:
// Constuctor/destructor
Vec3() { x_ = 0; y_ = 0; z_ = 0;}
Vec3(float v) { x_ = v; y_ = v; z_ = v;}
Vec3(float x, float y, float z) { x_ = x; y_ = y; z_ = z;}
~Vec3() {};
// Arithmetic operators
Vec3 operator+(const Vec3& obj);
Vec3 operator-(const Vec3& obj);
Vec3 operator*(const Vec3& obj);
Vec3 operator/(const Vec3& obj);
Vec3 operator+(const float& v);
Vec3 operator-(const float& v);
Vec3 operator/(const float& v);
// Compound assignment
Vec3 operator+=(const Vec3& obj);
Vec3 operator-=(const Vec3& obj);
Vec3 operator*=(const Vec3& obj);
Vec3 operator/=(const Vec3& obj);
Vec3 operator+=(const float& v);
Vec3 operator-=(const float& v);
Vec3 operator*=(const float& v);
Vec3 operator/=(const float& v);
// Functions
float Length();
Vec3 Normalized();
float SquaredLength();
// Values
float x_;
float y_;
float z_;
private:
};
inline Vec3 operator*(const Vec3 &v1, const Vec3 &v2) {
return Vec3(v1.x_ * v2.x_, v1.y_ * v2.y_, v1.z_ * v2.z_);
}
inline Vec3 operator/(const Vec3 &v1, const Vec3 &v2) {
return Vec3(v1.x_ / v2.x_, v1.y_ / v2.y_, v1.z_ / v2.z_);
}
inline Vec3 operator+(const Vec3 &v1, const Vec3 &v2) {
return Vec3(v1.x_ + v2.x_, v1.y_ + v2.y_, v1.z_ + v2.z_);
}
inline Vec3 operator-(const Vec3 &v1, const Vec3 &v2) {
return Vec3(v1.x_ - v2.x_, v1.y_ - v2.y_, v1.z_ - v2.z_);
}
inline Vec3 operator*(const Vec3 &v1, float t) {
return Vec3(v1.x_ * t, v1.y_ * t, v1.z_ * t);
}
inline Vec3 operator*(float t, const Vec3 &v1) {
return Vec3(v1.x_ * t, v1.y_ * t, v1.z_ * t);
}
inline Vec3 operator/(const Vec3 &v1, float t) {
return Vec3(v1.x_ / t, v1.y_ / t, v1.z_ / t);
}
inline Vec3 operator/(float t, const Vec3 &v1) {
return Vec3(v1.x_ / t, v1.y_ / t, v1.z_ / t);
}
inline Vec3 operator+(const Vec3 &v1, float t) {
return Vec3(v1.x_ + t, v1.y_ + t, v1.z_ + t);
}
inline Vec3 operator+(float t, const Vec3 &v1) {
return Vec3(v1.x_ + t, v1.y_ + t, v1.z_ + t);
}
inline Vec3 operator-(const Vec3 &v1, float t) {
return Vec3(v1.x_ - t, v1.y_ - t, v1.z_ - t);
}
inline Vec3 operator-(float t, const Vec3 &v1) {
return Vec3(v1.x_ - t, v1.y_ - t, v1.z_ - t);
}
inline float Dot(const Vec3 v1, const Vec3 v2) {
return v1.x_ * v2.x_ + v1.y_ * v2.y_ + v1.z_ * v2.z_;
}