#include "math/vector.h" #include 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 }; }