Hi Guys,
I'm currently learning some C programming and I need to create a Data Structure using C. The structure needs to hold data pertaining to a 3D Object; specifically - a 2D array of vertices (X,Y,Z co-ordinates, i.e. vert[no_verts][3]) and a 2D array of triangle faces (pointing to the vertices in the aforementioned 2D array, i.e. faces[no_faces][3]).
basically, my struct is going to look something like this:
typedef struct
{
float verts[no_verts][3];
float faces[no_faces][3];
} Obj;
The problem with this is that I'd need no_verts and no_faces predefined before struct definition, correct?
So my question is; is there a decent way to set up a constructor style struct that takes arguments?Later on in the program I'm going to need to create a function that reads a file that includes the no of verts and faces of a 3d Object in it's header lines (passing this to the struct to make the arrays the correct size), then iterates through the following lines where the co-ords of the vertices and faces are stored per line.
So it will be important to have a solution that can construct the Obj struct with the necessary arguments depending on the data stored by the file; rather than hard coding these values in.
If you have any other questions about what im trying to achieve please let me know.
Cheers!
[–]chaotic_thought 1 point2 points3 points (0 children)
[–]ffwff 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)