diff options
author | vimene <vincent.menegaux@gmail.com> | 2024-12-31 03:40:14 +0100 |
---|---|---|
committer | vimene <vincent.menegaux@gmail.com> | 2024-12-31 03:40:14 +0100 |
commit | cc6fb8c33637566a7b116d46440e6063f016deea (patch) | |
tree | 5cc83f84525507994add57df7dd974e6611d675a /src/math/vector.cpp | |
parent | 6b765a85cf81bf4b7162e4c9280dd4054581c611 (diff) | |
download | engine-cc6fb8c33637566a7b116d46440e6063f016deea.tar.gz |
various improvements
- added quaternions and rewrote all rotations to use them
- added transforms to put all object transforms in a single place
- added Wavefront .obj file parser
- removed frame buffer's abstract class
- improved vectors, matrices, triangles, vertices and vertices data by putting all code in header file
- added vector's operations
- changed from NULL to nullptr
- miscellaneous improvements
Diffstat (limited to 'src/math/vector.cpp')
-rw-r--r-- | src/math/vector.cpp | 175 |
1 files changed, 0 insertions, 175 deletions
diff --git a/src/math/vector.cpp b/src/math/vector.cpp deleted file mode 100644 index 306fc3d..0000000 --- a/src/math/vector.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#include "math/vector.h" -#include <cmath> - -using namespace engine::math; - -Vector2::Vector2() { -} - -Vector2::Vector2(float x, float y) : x{x}, y{y} { -} - -bool Vector2::operator==(Vector2 other) const { - return x == other.x && y == other.y; -} - -bool Vector2::operator!=(Vector2 other) const { - return !(*this == other); -} - -Vector2 Vector2::operator+() const { - return *this; -} - -Vector2 Vector2::operator-() const { - return { -x, -y }; -} - -Vector2 Vector2::operator+(Vector2 other) const { - return { x + other.x, y + other.y }; -} - -Vector2 Vector2::operator-(Vector2 other) const { - return *this + (-other); -} - -float Vector2::det(Vector2 other) const { - return this->x * other.y - other.x * this->y; -} - -Vector2 Vector2::round() const { - return { std::round(x), std::round(y) }; -} - -Vector2 engine::math::operator*(float n, Vector2 other) { - return { n * other.x, n * other.y }; -} - -Vector2 engine::math::operator*(Vector2 other, float n) { - return n * other; -} - -Vector2 engine::math::operator/(Vector2 other, float n) { - return { other.x / n, other.y / n }; -} - -Vector3::Vector3() { -} - -Vector3::Vector3(float x, float y, float z) : x{x}, y{y}, z{z} { -} - -bool Vector3::operator==(Vector3 other) const { - return x == other.x && y == other.y && z == other.z; -} - -bool Vector3::operator!=(Vector3 other) const { - return !(*this == other); -} - -Vector3 Vector3::operator+() const { - return *this; -} - -Vector3 Vector3::operator-() const { - return { -x, -y, -z }; -} - -Vector3 Vector3::operator+(Vector3 other) const { - return { x + other.x, y + other.y, z + other.z }; -} - -Vector3 Vector3::operator-(Vector3 other) const { - return *this + (-other); -} - -Vector3 Vector3::round() const { - return { std::round(x), std::round(y), std::round(z) }; -} - -Vector3 Vector3::cross(Vector3 other) const { - return { - y * other.z - z * other.y, - z * other.x - x * other.z, - x * other.y - y * other.x - }; -} - -Vector3 engine::math::operator*(float n, Vector3 other) { - return { n * other.x, n * other.y, n * other.z }; -} - -Vector3 engine::math::operator*(Vector3 other, float n) { - return n * other; -} - -Vector3 engine::math::operator/(Vector3 other, float n) { - return { other.x / n, other.y / n, other.z / n }; -} - -Vector4::Vector4() { -} - -Vector4::Vector4(float x, float y, float z, float w) : x{x}, y{y}, z{z}, w{w} { -} - -Vector4::Vector4(float x, float y, float z) : x{x}, y{y}, z{z}, w{1.f} { -} - -Vector4::Vector4(Vector3 v, float w) : x{v.x}, y{v.y}, z{v.z}, w{w} { -} - -Vector4::Vector4(Vector3 v) : x{v.x}, y{v.y}, z{v.z}, w{1.f} { -} - -bool Vector4::operator==(Vector4 other) const { - return x == other.x && y == other.y && z == other.z && w == other.w; -} - -bool Vector4::operator!=(Vector4 other) const { - return !(*this == other); -} - -Vector4 Vector4::operator+() const { - return *this; -} - -Vector4 Vector4::operator-() const { - return { -x, -y, -z, -w }; -} - -Vector4 Vector4::operator+(Vector4 other) const { - return { x + other.x, y + other.y, z + other.z, w + other.w }; -} - -Vector4 Vector4::operator-(Vector4 other) const { - return *this + (-other); -} - -Vector4 Vector4::round() const { - return { std::round(x), std::round(y), std::round(z), std::round(w) }; -} - -Vector2 Vector4::xy() const { - return { x, y }; -} - -Vector3 Vector4::xyz() const { - return { x, y, z }; -} - -Vector4 Vector4::div_by_w() const { - return {x / w, y / w, z / w, w}; -} - -Vector4 engine::math::operator*(float n, Vector4 other) { - return { n * other.x, n * other.y, n * other.z, n * other.w }; -} - -Vector4 engine::math::operator*(Vector4 other, float n) { - return n * other; -} - -Vector4 engine::math::operator/(Vector4 other, float n) { - return { other.x / n, other.y / n, other.z / n, other.w / n }; -} |