vectozavr-shooter/engine/Triangle.h

50 lines
1.2 KiB
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 13.01.2021.
//
#ifndef ENGINE_TRIANGLE_H
#define ENGINE_TRIANGLE_H
2021-10-31 11:39:08 +03:00
#include <SFML/Graphics.hpp>
2021-10-28 16:58:02 +03:00
#include "Vec4D.h"
#include "Vec3D.h"
#include "Matrix4x4.h"
2021-09-13 15:53:43 +03:00
class Triangle final {
private:
sf::Color _color;
2021-10-28 16:58:02 +03:00
Vec4D _points[3];
Vec3D _normal;
void calculateNormal();
2021-09-13 15:53:43 +03:00
public:
Triangle() = default;
2021-09-13 15:53:43 +03:00
2021-10-31 11:39:08 +03:00
Triangle(const Triangle &triangle);
Triangle(const Vec4D &p1, const Vec4D &p2, const Vec4D &p3, sf::Color color = {0, 0, 0});
Triangle &operator=(const Triangle &) = default;
2021-11-04 04:30:58 +03:00
[[nodiscard]] const Vec4D& operator[](int i) const;
2021-10-31 11:39:08 +03:00
2022-02-23 17:29:42 +03:00
[[nodiscard]] Vec3D position() const { return Vec3D(_points[0] + _points[1] + _points[2])/3; }
[[nodiscard]] Vec3D norm() const;
2021-09-13 15:53:43 +03:00
// Operations with Matrix4x4
2021-10-31 11:39:08 +03:00
[[nodiscard]] Triangle operator*(const Matrix4x4 &matrix4X4) const;
2021-09-13 15:53:43 +03:00
2021-10-31 11:39:08 +03:00
[[nodiscard]] bool isPointInside(const Vec3D &point) const;
[[nodiscard]] sf::Color color() const { return _color; }
2022-02-23 07:51:53 +03:00
void setColor(sf::Color newColor) { _color = newColor; }
2021-10-31 11:39:08 +03:00
[[nodiscard]] double distance(const Vec3D &vec) const { return norm().dot(Vec3D(_points[0]) - vec); }
2021-09-13 15:53:43 +03:00
};
#endif //INC_3DZAVR_TRIANGLE_H