vectozavr-shooter/engine/Plane.h

34 lines
1012 B
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 19.01.2021.
//
#ifndef ENGINE_PLANE_H
#define ENGINE_PLANE_H
2021-10-28 16:58:02 +03:00
#include "Vec4D.h"
2021-09-13 15:53:43 +03:00
#include "Triangle.h"
class Plane final {
2021-09-13 15:53:43 +03:00
private:
2021-10-28 16:58:02 +03:00
const Vec3D _normal;
const Vec3D _point;
2021-09-13 15:53:43 +03:00
public:
2021-10-28 16:58:02 +03:00
Plane() = delete;
Plane(const Plane& plane) = default;
2021-10-28 16:58:02 +03:00
// You can define plane by defining the points in 3D space
2021-09-13 15:53:43 +03:00
explicit Plane(const Triangle& tri);
2021-10-28 16:58:02 +03:00
// Or by defining normal vector and one val laying on the plane
Plane(const Vec3D& N, const Vec3D& P);
2021-09-13 15:53:43 +03:00
[[nodiscard]] double distance(const Vec3D& point4D) const;
2021-10-28 16:58:02 +03:00
// Vec4D in space where line ('start' to 'end') intersects plain with normal vector '_n' and val '_p' lays on the plane
[[nodiscard]] std::pair<Vec3D, double> intersection(const Vec3D& start, const Vec3D& end) const;
[[nodiscard]] std::vector<Triangle> clip(const Triangle& tri) const;
2021-09-13 15:53:43 +03:00
2021-10-28 16:58:02 +03:00
[[nodiscard]] Vec3D N() const { return _normal; }
[[nodiscard]] Vec3D P() const { return _point; }
2021-09-13 15:53:43 +03:00
};
#endif //INC_3DZAVR_PLANE_H