Add simple Vec3 header file
This commit is contained in:
parent
311a93cdd6
commit
24d7efc977
15 changed files with 321 additions and 137 deletions
33
include/vec3.h
Normal file
33
include/vec3.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef VEC3_H
|
||||
#define VEC3_H
|
||||
|
||||
template <typename T> struct Vec3 {
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
|
||||
inline Vec3<T> operator+(Vec3<T> other) const {
|
||||
return {x + other.x, y + other.y, z + other.z};
|
||||
};
|
||||
|
||||
inline Vec3<T> operator-(Vec3<T> other) const {
|
||||
return {x - other.x, y - other.y, z - other.z};
|
||||
};
|
||||
|
||||
inline void scale(T scalar) {
|
||||
x *= scalar;
|
||||
y *= scalar;
|
||||
z *= scalar;
|
||||
};
|
||||
|
||||
inline T dot(Vec3<T> other) {
|
||||
return x * other.x + y * other.y + z * other.z;
|
||||
}
|
||||
|
||||
inline Vec3<T> cross(Vec3<T> other) {
|
||||
return {y * other.z - z * other.y, z * other.x - x * other.z,
|
||||
x * other.y - y * other.x};
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue