I apologize for the silly title, but I couldn't come up with a more meaningful one without an actual example.
So, here is my situation: let's say I want to model a triangle. A triangle is made up of three vertices, and each vertex has coordinates and data (things like material, this is a part of a pathtracer).
struct vertex
{
vector3 coords;
vertex_data data;
vertex() = default;
vertex(const vector3&, const vertex_data&);
};
class triangle
{
private:
vertex a, b, c;
public:
triangle() = default;
triangle(const vertex&, const vertex&, const vertex&);
...
};
At some point in the pathtracer, I calculate the normals (vectors normal to the surface of the triangle) in each of the vertices. Obviously, this is something that requires multiple vertices, i.e. the triangle already needs to be constructed. Currently, this is not a problem. However, I think it would make sense that the normal is encapsulated in the vertex
object. So now I kind of have this catch-22 situation in which, in order to create a vertex, I need the normal, which requires the entire triangle to already exist. However, the triangle can only be constructed if all the vertices are already constructed.
I just want to clarify that I can come up with many ways to do this, it's just that I find them formally incorrect, violating OOP or just ugly.
Aucun commentaire:
Enregistrer un commentaire