shooter/engine/Vec3D.h

59 lines
1.5 KiB
C
Raw Normal View History

//
// Created by Иван Ильин on 09.10.2021.
//
#ifndef SHOOTER_VEC3D_H
#define SHOOTER_VEC3D_H
#include <array>
2021-10-31 11:39:08 +03:00
2021-10-28 16:58:02 +03:00
#include "Vec4D.h"
class Vec3D final {
private:
std::array<double, 3> _arr_point{};
public:
2021-10-31 11:39:08 +03:00
Vec3D() = default;
Vec3D(const Vec3D &vec);
explicit Vec3D(const Vec4D &vec);
explicit Vec3D(double x, double y = 0.0, double z = 0.0);
Vec3D &operator=(const Vec3D &) = default;
[[nodiscard]] double x() const { return _arr_point[0]; }
[[nodiscard]] double y() const { return _arr_point[1]; }
[[nodiscard]] double z() const { return _arr_point[2]; }
[[nodiscard]] Vec3D operator-() const;
// Boolean operations
2021-10-31 11:39:08 +03:00
bool operator==(const Vec3D &vec) const;
bool operator!=(const Vec3D &vec) const;
2021-10-28 16:58:02 +03:00
// Operations with Vec4D
2021-10-31 11:39:08 +03:00
[[nodiscard]] Vec3D operator+(const Vec3D &vec) const;
[[nodiscard]] Vec3D operator-(const Vec3D &vec) const;
2021-10-31 11:39:08 +03:00
[[nodiscard]] double dot(const Vec3D &vec) const; // Returns dot product
[[nodiscard]] Vec3D cross(const Vec3D &vec) const; // Returns cross product
// Operations with numbers
[[nodiscard]] Vec3D operator*(double number) const;
[[nodiscard]] Vec3D operator/(double number) const;
// Other useful methods
[[nodiscard]] double sqrAbs() const; // Returns squared vector length
[[nodiscard]] double abs() const; // Returns vector length
[[nodiscard]] Vec3D normalized() const; // Returns normalized vector without changing
2021-10-28 16:58:02 +03:00
[[nodiscard]] Vec4D makePoint4D() const;
2021-10-29 19:43:39 +03:00
static Vec3D Random();
};
#endif //SHOOTER_VEC3D_H