I'm writing a very simple OBJ exporter in C++ (for VC6, as I am writing for an old project that only compiles there.)
Right now, I'm stuck on figuring out how to use an infinite amount of structs to make a vertices position line. That may sound a bit silly, but this is my first functioning program written in C++, so I don't know the concepts very well.
I'm assuming I'm doing it wrong, as there's nothing I can find on the Internet for what I'm trying to do.
Here's my header's struct code:
struct PointList {
float X;
float Y;
float Z;
};
..and the actual OBJ export function's code:
void OBJEXP::WriteOBJ(OBJEXP::PointList Points, std::string File) // Writes an OBJ.
{
ofstream output(File + ".obj");
for (int i = 0; i < sizeof(Points); i += 1)
{
output << "v " + to_string(Points.X) + " " + to_string(Points.Y) + " " + to_string(Points.Z) + "\n";
}
output.close();
cout << "All done\n";
}
My main file (meant to test the code out, this is going to be run every time I save a file otherwise:)
OBJEXP::PointList POINTZ;
int main()
{
POINTZ.X = 1.0f;
POINTZ.Y = 5.5f;
POINTZ.Z = 2.0f;
OBJEXP::WriteOBJ(POINTZ, "testobject");
std::cout << "Execution done\n";
}
My OBJ file looks like this:
v 1.000000 5.500000 2.000000
v 1.000000 5.500000 2.000000
v 1.000000 5.500000 2.000000
v 1.000000 5.500000 2.000000
v 1.000000 5.500000 2.000000
v 1.000000 5.500000 2.000000
v 1.000000 5.500000 2.000000
v 1.000000 5.500000 2.000000
v 1.000000 5.500000 2.000000
v 1.000000 5.500000 2.000000
v 1.000000 5.500000 2.000000
v 1.000000 5.500000 2.000000
which obviously isn't very correct.
I prefer to use vector :D
main code: