diff --git a/source/main.cpp b/source/main.cpp index d32379d..9f118ef 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -47,18 +47,17 @@ std::vector createVec3d(std::vector &t, int layers double ws = width + spacing; // Will be used later to determine the direction of the translation matrix. - // This is used to bypass needing to create a rotation matrix. - // Should consider doing so anyway to speed up process, use less memory, and add modularization. double angle = 0.0; CompFab::Vec3 *temp = new CompFab::Vec3(-ls, -ws, 0); // Vec3 to hold our current translation matrix. - CompFab::Vec3 *trans = new CompFab::Vec3(0, spacing, 0); + CompFab::Vec3 *trans = new CompFab::Vec3(ls, ws, 0); - //Vec3 to hold our current height multiplier. + //Vec3 to hold our current height multiplication materx. CompFab::Vec3 *mult = new CompFab::Vec3(1,1,1); + //push_back initial templat's mesh, multiplied by the height multiplication matrix. for(int i = 0; i < t.size(); i++) { output->push_back(mmult(*mult, t[i])); @@ -67,10 +66,11 @@ std::vector createVec3d(std::vector &t, int layers // cl for current layer. for(int cl = 1; cl < layers; cl++) { - // Constructor used to bypass needing to create a new operator override for multiplication. - // Should also consider doing so anyway to speed up process, use less memory, and add modularization. + // Constructor used to re-initialize temp. *temp = CompFab::Vec3(-ls*cl, -ws*cl, 0); - mult->m_z = 1.0 - (cl*1.0)/layers; + + // Used to change the multiplciation matrix per layer. + mult->m_z = 1.0/(cl +1); for(int c = 0; c < cl*8; c++) @@ -110,36 +110,44 @@ int main(int argc, char **argv) // Error checking. if(argc < 3) { - std::cout << "Usage: [executable] [template].obj output.obj [optional: -d for debugging output]" << std::endl; + std::cout << "Usage: [executable] [template].obj output.obj [mode (-g, etc.)] [optional: -d for debugging output]" << std::endl; std::exit(1); } - // TODO: Modularize these. - int layers = 10; - double spacing = 0.5; - - // Create Mesh object from file, output to manipulate from template Mesh. - Mesh *test = new Mesh(argv[1], false); - - double l = 0, w = 0; - double *length = &l, *width = &w; - - // Find the X and Y dimensions for the mesh. Assumes the mesh is facing upright. - findLW(*test, *length, *width); - - // Calculate the translation matrices needed and apply them. - std::vector vv = createVec3d(test->v, layers, spacing, *length, *width); - - // Copying needed triangle data. - std::vector tt = createVec3id(test->t, test->v, layers); - - // Using contructor to create new output Mesh. - Mesh *output = new Mesh(vv, tt); + // Initialization of needed output variables. + std::vector vv; + std::vector tt; + Mesh *output = new Mesh(); // Debugging if(argc > 3) { - if(strcmp(argv[3], "-d") == 0) + if(strcmp(argv[3], "-g") == 0 || strcmp(argv[3], "-d") == 0) + { + // TODO: Modularize these. + int layers = 10; + double spacing = 1; + + // Create Mesh object from file, output to manipulate from template Mesh. + Mesh *test = new Mesh(argv[1], false); + + double l = 0, w = 0; + double *length = &l, *width = &w; + + // Find the X and Y dimensions for the mesh. Assumes the mesh is facing upright. + findLW(*test, *length, *width); + + // Calculate the translation matrices needed and apply them. + vv = createVec3d(test->v, layers, spacing, *length, *width); + + // Copying needed triangle data. + tt = createVec3id(test->t, test->v, layers); + + // Using contructor to create new output Mesh. + *output = Mesh(vv, tt); + } + + if(strcmp(argv[argc - 1], "-d") == 0) { for(int j = 0; j < output->v.size(); j++) { @@ -151,10 +159,6 @@ int main(int argc, char **argv) std::cout << output->t[k].m_x << " " << output->t[k].m_y << " " << output->t[k].m_z << std::endl; } } - else - { - std::cout << "Usage: [executable] [template].obj output.obj [optional: -d for debugging output]" << std::endl; - } } output->save(argv[2]);