shooter/engine/Mesh.h

70 lines
1.9 KiB
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 13.01.2021.
//
#ifndef ENGINE_MESH_H
#define ENGINE_MESH_H
2021-10-28 16:58:02 +03:00
#include <utility>
2021-09-13 15:53:43 +03:00
#include <vector>
2021-10-31 11:39:08 +03:00
2021-09-13 15:53:43 +03:00
#include <SFML/Graphics.hpp>
2021-10-31 11:39:08 +03:00
#include "Triangle.h"
2021-09-13 15:53:43 +03:00
#include "Object.h"
2021-10-02 20:36:07 +03:00
class Mesh : public Object {
private:
std::vector<Triangle> _tris;
sf::Color _color = sf::Color(255, 245, 194);
2021-09-13 15:53:43 +03:00
bool _visible = true;
2021-10-31 11:39:08 +03:00
Mesh &operator*=(const Matrix4x4 &matrix4X4);
// OpenGL
mutable GLfloat* _geometry = nullptr;
2021-09-13 15:53:43 +03:00
public:
2021-10-28 16:58:02 +03:00
explicit Mesh(ObjectNameTag nameTag) : Object(std::move(nameTag)) {};
2021-09-13 15:53:43 +03:00
2021-10-31 11:39:08 +03:00
Mesh &operator=(const Mesh &mesh) = delete;
Mesh(const Mesh &mesh) = default;
explicit Mesh(ObjectNameTag nameTag, const std::vector<Triangle> &tries);
2021-09-13 15:53:43 +03:00
2021-10-31 11:39:08 +03:00
explicit Mesh(ObjectNameTag nameTag, const std::string &filename, const Vec3D &scale = Vec3D{1, 1, 1});
2021-09-13 15:53:43 +03:00
2021-10-31 11:39:08 +03:00
void loadObj(const std::string &filename, const Vec3D &scale = Vec3D{1, 1, 1});
2021-09-13 15:53:43 +03:00
2021-10-31 11:39:08 +03:00
[[nodiscard]] std::vector<Triangle> const &triangles() const { return _tris; }
void setTriangles(std::vector<Triangle>&& t);
2021-10-31 11:39:08 +03:00
[[nodiscard]] size_t 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-31 11:39:08 +03:00
void setColor(const sf::Color &c);
2021-09-13 15:53:43 +03:00
2022-02-23 07:51:53 +03:00
void setOpacity(double t);
2021-09-13 15:53:43 +03:00
void setVisible(bool visibility) { _visible = visibility; }
2021-10-31 11:39:08 +03:00
2021-09-13 15:53:43 +03:00
[[nodiscard]] bool isVisible() const { return _visible; }
2021-10-16 20:22:55 +03:00
~Mesh() override;
2022-07-07 13:14:00 +03:00
Mesh static Cube(ObjectNameTag tag, double size = 1.0, sf::Color color = sf::Color(0,0,0));
2021-10-31 11:39:08 +03:00
Mesh static LineTo(ObjectNameTag nameTag, const Vec3D &from, const Vec3D &to, double line_width = 0.1,
const sf::Color &color = {150, 150, 150, 100});
2022-02-23 07:51:53 +03:00
Mesh static ArrowTo(ObjectNameTag nameTag, const Vec3D& from, const Vec3D& to, double line_width = 0.1, sf::Color color = {150, 150, 150, 255});
// OpenGL functions
GLfloat *glFloatArray() const;
2021-11-10 14:14:10 +03:00
void glFreeFloatArray();
2021-09-13 15:53:43 +03:00
};
#endif //INC_3DZAVR_MESH_H