Add a structure representing an explicit mesh
This commit is contained in:
parent
016b0e1b6d
commit
003c50443e
3 changed files with 45 additions and 0 deletions
3
Mesh.cpp
Normal file
3
Mesh.cpp
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#include "Mesh.h"
|
||||||
|
|
||||||
|
|
28
Mesh.h
Normal file
28
Mesh.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
* Defines a mesh, ready to be OpenGL-rendered
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "common_structures.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
/// 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;
|
||||||
|
};
|
14
common_structures.h
Normal file
14
common_structures.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/**
|
||||||
|
* Defines a few widely used, widely spread structures. Imported pervasively.
|
||||||
|
**/
|
||||||
|
|
||||||
|
struct Point {
|
||||||
|
double x, y, z;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Face {
|
||||||
|
int vert[3];
|
||||||
|
int operator[](unsigned i) {
|
||||||
|
return vert[i % 3]; // dodge errors
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in a new issue