2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 13.01.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_MESH_H
|
|
|
|
#define ENGINE_MESH_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include "Triangle.h"
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
#include "Object.h"
|
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
class Mesh : public Object {
|
2021-09-14 13:47:53 +03:00
|
|
|
private:
|
2021-09-19 11:25:10 +03:00
|
|
|
std::vector<Triangle> _tris;
|
|
|
|
sf::Color _color = sf::Color(255, 245, 194);
|
2021-09-13 15:53:43 +03:00
|
|
|
bool _visible = true;
|
|
|
|
|
2021-09-19 11:25:10 +03:00
|
|
|
Mesh& operator*=(const Matrix4x4& matrix4X4);
|
2021-09-13 15:53:43 +03:00
|
|
|
public:
|
|
|
|
Mesh() = default;
|
2021-10-12 17:12:47 +03:00
|
|
|
Mesh& operator=(const Mesh& mesh) = delete;
|
2021-09-13 15:53:43 +03:00
|
|
|
Mesh(const Mesh& mesh);
|
|
|
|
|
|
|
|
explicit Mesh(const std::vector<Triangle>& tries);
|
2021-10-12 17:12:47 +03:00
|
|
|
explicit Mesh(const std::string& filename, const std::string &materials = "", const Vec3D& scale = Vec3D{1, 1, 1});
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
Mesh& loadObj(const std::string& filename, const std::string &materials = "", const Vec3D& scale = Vec3D{1, 1, 1});
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-09-19 11:25:10 +03:00
|
|
|
[[nodiscard]] std::vector<Triangle>const &triangles() const { return _tris; }
|
2021-10-02 20:36:07 +03:00
|
|
|
[[nodiscard]] std::vector<Triangle>& triangles() { return _tris; }
|
2021-10-12 17:12:47 +03:00
|
|
|
void setTriangles(const std::vector<Triangle>& t);
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-09-19 11:25:10 +03:00
|
|
|
// Translate body
|
|
|
|
// Rotate body around XYZ axes
|
2021-10-12 17:12:47 +03:00
|
|
|
void rotate(const Vec3D& r) override;
|
2021-09-19 11:25:10 +03:00
|
|
|
// Rotate body around normalised vector 'v' by 'r' radians
|
2021-10-12 17:12:47 +03:00
|
|
|
void rotate(const Vec3D& v, double r) override;
|
2021-10-03 07:47:05 +03:00
|
|
|
// Rotate body around XYZ by (r._x, r._y, r.z) radians relative val 'point4D'
|
2021-10-12 17:12:47 +03:00
|
|
|
void rotateRelativePoint(const Vec3D& point, const Vec3D& r) override;
|
2021-09-19 11:25:10 +03:00
|
|
|
// Rotate body around normalised vector 'v' by 'r' radians relative val 'point4D'
|
2021-10-12 17:12:47 +03:00
|
|
|
void rotateRelativePoint(const Vec3D& point4D, const Vec3D& v, double r) override;
|
|
|
|
void scale(const Vec3D& s) override;
|
2021-10-16 16:14:51 +03:00
|
|
|
[[nodiscard]] int size() const { return _tris.size()*3; }
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
[[nodiscard]] sf::Color color() const { return _color; }
|
2021-10-12 17:12:47 +03:00
|
|
|
void setColor(const sf::Color& c);
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
void setVisible(bool visibility) { _visible = visibility; }
|
|
|
|
[[nodiscard]] bool isVisible() const { return _visible; }
|
|
|
|
|
2021-10-03 07:52:30 +03:00
|
|
|
Mesh static Obj(const std::string& filename);
|
2021-10-12 17:12:47 +03:00
|
|
|
std::vector<std::shared_ptr<Mesh>> static LoadObjects(const std::string& filename, const std::string &materials = "", const Vec3D& scale = Vec3D{1, 1, 1});
|
|
|
|
Mesh static LineTo(const Vec3D& from, const Vec3D& to, double line_width = 0.1, const sf::Color& color = {150, 150, 150, 255});
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //INC_3DZAVR_MESH_H
|