Reputation: 148
Let`s create three classes:
Class Vector3d:
class Vector3d{
int a,b,c;
}
Class Face, every Face contains 3 vector:
class Face{
Vector3d *a, *b, *c;
}
And class Mesh(3d object): in class mesh i can just get vector of faces, but most object of Vector3d class will be shared between many Faces so I`d like to store Vector3d in Mesh class and store only pointer in Face object;
class Mesh{
std::vector<Vector3d> points;
std::vector<Face> faces;
}
Problem is, that i don`t understand when should I delete pointer in Face class, should I use something else instead of this?
Edit: 3 int are just to explain my concept, in final verison there will be more data in Vector3d class
Upvotes: 3
Views: 123
Reputation: 4727
Face
should store indices, not pointers.
I.e. Face
should have three members:
unsigned a,b,c;
Indices are safe if you add/remove/resize the Vector3d
vector.
It also allows you to share points between faces in a more convenient way.
It also means you can copy the conents of your faces
vector directly into a Graphics API buffer (taking granted types match).
Upvotes: 6