45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
/**
|
|
* Defines a mesh, ready to be OpenGL-rendered
|
|
**/
|
|
|
|
#pragma once
|
|
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include <cstddef> // size_t
|
|
#include "common_structures.hpp"
|
|
|
|
class Mesh {
|
|
public:
|
|
Mesh();
|
|
|
|
/// Adds a fresh vertice at `pt`, and returns its ID for further use
|
|
size_t add_vertice(const Point& pt);
|
|
|
|
/// Creates a new face out of the three given point IDs
|
|
void add_face(const Face& face);
|
|
void add_face(size_t f1, size_t f2, size_t f3);
|
|
|
|
/// Center manipulation
|
|
const Point& get_center() const;
|
|
void set_center(const Point& pt);
|
|
void translate(const Point& tr); ///< Translate by the vector `tr`
|
|
|
|
/** Translates the vertices to make (0, 0, 0) the mesh's barycenter.
|
|
* If `keep_position == true`, this also sets the center to the
|
|
* previous barycenter.
|
|
*/
|
|
void normalize_center(bool keep_position=false);
|
|
|
|
/// Gets the various vertices
|
|
const std::vector<Point>& get_vertices() const;
|
|
|
|
/// Gets the various faces
|
|
const std::vector<Face>& get_faces() const;
|
|
|
|
private:
|
|
std::vector<Point> vertices;
|
|
std::vector<Face> faces;
|
|
|
|
Point center;
|
|
};
|