mpri-graphics-project/Mesh.cpp

52 lines
1,009 B
C++

#include "Mesh.hpp"
Mesh::Mesh()
: center(Point(.0, .0, .0))
{
}
size_t Mesh::add_vertice(const Point& pt) {
vertices.push_back(pt);
return vertices.size() - 1;
}
void Mesh::add_face(const Face& face) {
faces.push_back(face);
}
void Mesh::add_face(size_t f1, size_t f2, size_t f3) {
add_face(Face(f1, f2, f3));
}
const Point& Mesh::get_center() const {
return center;
}
void Mesh::set_center(const Point& pt) {
center = pt;
}
void Mesh::translate(const Point& tr) {
center += tr;
}
void Mesh::normalize_center(bool keep_position) {
Point bary(0., 0., 0.);
for(const Point& vert: vertices)
bary += vert;
bary = (1. / ((double)vertices.size())) * bary;
for(Point& vert: vertices)
vert -= bary;
if(keep_position)
translate(bary);
else
set_center(Point(0, 0, 0));
}
const std::vector<Point>& Mesh::get_vertices() const {
return vertices;
}
const std::vector<Face>& Mesh::get_faces() const {
return faces;
}