Original Post
I am developing a mesh class. I am in two minds of how to implement the triangle class. I have two different ideas on how I want to develop it. I dont know if I should implement a triangle class with it containing the three vertex points, or a triangle with the three indices values. This is just a rundown on the two approaches I am considering working with (this is C++ pseudocode, not the total final solution, just a single brief idea on how i am implementing). This is a quick run-through as it is late :) Once I have generated a list of triangles from my model loader, I will place the data inside a list container full of triangles(would a vector container make a difference!). I will send that container object to the mesh class object (see below) The triangle class inside the mesh class will be independent from the points vertex data.(see below)I am looking for suggestion on how I should implement the triangle and mesh class. The pseudocode shown is just the simplified idea of what i'm working on. I also am looking on working on which one would be futureproof for functions i am including later for example animation and bone rigging, vertex welding, etc.
Approach Plan A
class Triangle
{
public:
Triangle(Point _A,Point _B Point _C)
{
Points[0] = _A;
Points[1] = _B;
Points[2] = _C;
}
Point Points[3]; //where the three vertices are stored
};
class Mesh
{
public:
Mesh(list<Triangle> _tri)
{
triangles = _tri;
}
list<Triangle> triangles;// stores the triangles that make the mesh
};
Approach Plan B
I am creating a class which stores the indices inside the triangle class. This article gave me a few ideas on how to do a indices in a triangle.class Triangle
{
public:
Triangle(unsigned short _A,unsigned short _B unsigned short _C)
{
indices[0] = _A;
indices[1] = _B;
indices[2] = _C;
}
unsigned short indices[3]; //where the three vertices are stored
};
class Mesh
{
public:
Mesh(list<Triangle> _tri, vector<Point> _points)
{
triangles = _tri;
points = _points;
}
list<Triangle> triangles; // stores the triangles that make the mesh
vector<Point> points;
};