From 762a894dc70abeb238368d41151d777fdd74353b Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 27 Nov 2016 03:18:51 -0600 Subject: [PATCH 1/6] A test. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index eba2e03..8ab08d2 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,5 @@ A C++ engine for procedural city generation by manipulating .obj models and outp Use cmake file included to generate project. Usage: [executable] [template].obj output.obj [optional: -d for debugging output] + +testing. From cdd2472f0f10348c3f36f3b1852cf004dfe89b77 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 27 Nov 2016 03:19:43 -0600 Subject: [PATCH 2/6] Reverting. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 8ab08d2..eba2e03 100644 --- a/README.md +++ b/README.md @@ -4,5 +4,3 @@ A C++ engine for procedural city generation by manipulating .obj models and outp Use cmake file included to generate project. Usage: [executable] [template].obj output.obj [optional: -d for debugging output] - -testing. From 71ffe9df12086e13486ebbf026589ae426d0fd5c Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 28 Nov 2016 18:50:39 -0600 Subject: [PATCH 3/6] Clean up and optimization. Changed debugging output. --- include/CompFab.h | 5 +++- source/CompFab.cpp | 18 +++++++++++++ source/main.cpp | 64 ++++++++++++++++++++++++++-------------------- 3 files changed, 58 insertions(+), 29 deletions(-) diff --git a/include/CompFab.h b/include/CompFab.h index 8d51c50..8246431 100644 --- a/include/CompFab.h +++ b/include/CompFab.h @@ -49,6 +49,7 @@ namespace CompFab Vec3iStruct(); Vec3iStruct(int x, int y, int z); + Vec3iStruct(int i); union { int m_pos[3]; @@ -104,7 +105,9 @@ namespace CompFab //Compute v1 - v2 Vec3 operator-(const Vec3 &v1, const Vec3 &v2); - Vec3 operator+(const Vec3 &v1, const Vec3 &v2); + Vec3 operator+(const Vec3 & v1, const Vec3 & v2); + + Vec3i operator+(const Vec3i & v1, const Vec3i & v2); //Cross Product Vec3 operator%(const Vec3 &v1, const Vec3 &v2); diff --git a/source/CompFab.cpp b/source/CompFab.cpp index 2dec946..4c293a6 100644 --- a/source/CompFab.cpp +++ b/source/CompFab.cpp @@ -48,6 +48,14 @@ CompFab::Vec3iStruct::Vec3iStruct(int x, int y, int z) m_z = z; } +CompFab::Vec3iStruct::Vec3iStruct(int i) +{ + m_x = i; + m_y = i; + m_z = i; +} + + CompFab::Vec2fStruct::Vec2fStruct() { m_x = m_y = 0.0; @@ -99,6 +107,16 @@ CompFab::Vec3 CompFab::operator+(const Vec3 &v1, const Vec3 &v2) return v3; } +CompFab::Vec3i CompFab::operator+(const Vec3i &v1, const Vec3i &v2) +{ + Vec3i v3i; + v3i[0] = v1[0] + v2[0]; + v3i[1] = v1[1] + v2[1]; + v3i[2] = v1[2] + v2[2]; + + return v3i; +} + //Cross Product Vec3 CompFab::operator%(const Vec3 &v1, const Vec3 &v2) diff --git a/source/main.cpp b/source/main.cpp index df403bb..c242ebf 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -39,7 +39,7 @@ void findLW(Mesh &m, double &l, double &w) } // Calculate translation matrices and output them as a vector of Vec3s. -std::vector createVec3d(int layers, double spacing, double length, double width) +std::vector createVec3d(std::vector &t, int layers, double spacing, double length, double width) { std::vector *output = new std::vector(); @@ -55,6 +55,7 @@ std::vector createVec3d(int layers, double spacing, double length // Vec3 to hold our current translation matrix. CompFab::Vec3 *trans = new CompFab::Vec3(0, spacing, 0); + *output = t; // cl for current layer. for(int cl = 1; cl < layers; cl++) @@ -67,9 +68,27 @@ std::vector createVec3d(int layers, double spacing, double length { angle = (c/(2*cl))*(0.5*PI); *trans = CompFab::Vec3(ls*cos(angle), ws*sin(angle), 0); - *temp = *temp + *trans; - - output->push_back(*temp); + *temp += *trans; + for(int j = 0; j < t.size(); j++) + { + output->push_back(t[j] + *temp); + } + } + } + + return *output; +} +std::vector createVec3id(std::vector &t, std::vector &v, int layers) +{ + std::vector *output = new std::vector(); + *output = t; + + for(int n = 1; n < pow((2*layers - 1), 2); n++) + { + CompFab::Vec3i *offset = new CompFab::Vec3i(v.size()*n); + for(int k = 0; k < t.size(); k++) + { + output->push_back(t[k] + *offset); } } @@ -87,12 +106,11 @@ int main(int argc, char **argv) } // TODO: Modularize these. - int layers = 10; - double spacing = 1.0; + int layers = 5; + double spacing = 1; // Create Mesh object from file, output to manipulate from template Mesh. Mesh *test = new Mesh(argv[1], false); - Mesh *output = new Mesh(test->v, test->t); double l = 0, w = 0; double *length = &l, *width = &w; @@ -100,27 +118,14 @@ int main(int argc, char **argv) // Find the X and Y dimensions for the mesh. Assumes the mesh is facing upright. findLW(*test, *length, *width); - // Calculate the translation matrices needed. - std::vector d = createVec3d(layers, spacing, *length, *width); - - // Duplicating template, will later be replaced with a much more robust procedural generation function. - for(int i = 0; i < d.size(); i++) - { - for(int j = 0; j < test->v.size(); j++) - { - output->v.push_back(CompFab::Vec3(test->v[j] + d[i])); - } - } + // Calculate the translation matrices needed and apply them. + std::vector vv = createVec3d(test->v, layers, spacing, *length, *width); // Copying needed triangle data. - for(int n = 1; n < pow((2*layers - 1), 2); n++) - { - int offset = test->v.size()*n; - for(int k = 0; k < test->t.size(); k++) - { - output->t.push_back(CompFab::Vec3i(test->t[k].m_x +offset, test->t[k].m_y + offset, test->t[k].m_z + offset)); - } - } + std::vector tt = createVec3id(test->t, test->v, layers); + + // Using contructor to create new output Mesh. + Mesh *output = new Mesh(vv, tt); // Debugging if(argc > 3) @@ -130,8 +135,11 @@ int main(int argc, char **argv) for(int j = 0; j < output->v.size(); j++) { std::cout << output->v[j].m_x << " " << output->v[j].m_y << " " << output->v[j].m_z << std::endl; - std::cout << output->t[j].m_x << " " << output->t[j].m_y << " " << output->t[j].m_z << std::endl; - std::cout << std::endl; + } + std::cout << std::endl; + for(int k = 0; k < output->t.size(); k++) + { + std::cout << output->t[k].m_x << " " << output->t[k].m_y << " " << output->t[k].m_z << std::endl; } } else From db17de29f4c398aa22b411d2ab6e565c267eaf6d Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 28 Nov 2016 19:49:37 -0600 Subject: [PATCH 4/6] Added matrix and scalar multiplications and height modification. --- include/CompFab.h | 6 ++++++ source/CompFab.cpp | 13 ++++++++++++- source/main.cpp | 17 +++++++++++++---- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/CompFab.h b/include/CompFab.h index 8246431..bbbdf01 100644 --- a/include/CompFab.h +++ b/include/CompFab.h @@ -109,6 +109,12 @@ namespace CompFab Vec3i operator+(const Vec3i & v1, const Vec3i & v2); + //Matrix multiplication + Vec3 mmult(const Vec3 & v1, const Vec3 & v2); + + //Scalar multiplication + Vec3 smult(double s, const Vec3 & v); + //Cross Product Vec3 operator%(const Vec3 &v1, const Vec3 &v2); diff --git a/source/CompFab.cpp b/source/CompFab.cpp index 4c293a6..6759705 100644 --- a/source/CompFab.cpp +++ b/source/CompFab.cpp @@ -117,9 +117,20 @@ CompFab::Vec3i CompFab::operator+(const Vec3i &v1, const Vec3i &v2) return v3i; } +//Matrix multiplication +CompFab::Vec3 CompFab::mmult(const Vec3& v1, const Vec3& v2) +{ + return Vec3(v1.m_x*v2.m_x, v1.m_y*v2.m_y, v1.m_z*v2.m_z); +} + +//Scalar multiplication +CompFab::Vec3 CompFab::smult(double s, const Vec3 & v) +{ + return mmult(CompFab::Vec3(s,s,s), v); +} //Cross Product -Vec3 CompFab::operator%(const Vec3 &v1, const Vec3 &v2) +CompFab::Vec3 CompFab::operator%(const Vec3 &v1, const Vec3 &v2) { Vec3 v3; v3[0] = v1[1]*v2[2] - v1[2]*v2[1]; diff --git a/source/main.cpp b/source/main.cpp index c242ebf..d32379d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -55,7 +55,14 @@ std::vector createVec3d(std::vector &t, int layers // Vec3 to hold our current translation matrix. CompFab::Vec3 *trans = new CompFab::Vec3(0, spacing, 0); - *output = t; + + //Vec3 to hold our current height multiplier. + CompFab::Vec3 *mult = new CompFab::Vec3(1,1,1); + + for(int i = 0; i < t.size(); i++) + { + output->push_back(mmult(*mult, t[i])); + } // cl for current layer. for(int cl = 1; cl < layers; cl++) @@ -63,6 +70,8 @@ std::vector createVec3d(std::vector &t, int layers // 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. *temp = CompFab::Vec3(-ls*cl, -ws*cl, 0); + mult->m_z = 1.0 - (cl*1.0)/layers; + for(int c = 0; c < cl*8; c++) { @@ -71,7 +80,7 @@ std::vector createVec3d(std::vector &t, int layers *temp += *trans; for(int j = 0; j < t.size(); j++) { - output->push_back(t[j] + *temp); + output->push_back(mmult(*mult, t[j]) + *temp); } } } @@ -106,8 +115,8 @@ int main(int argc, char **argv) } // TODO: Modularize these. - int layers = 5; - double spacing = 1; + 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); From 59a9be347e37426353fa7b26a645536b1b8375a1 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 30 Nov 2016 16:21:08 -0600 Subject: [PATCH 5/6] Modularized grid mode. Updated help dialogue. --- source/main.cpp | 72 ++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 34 deletions(-) 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]); From d42961b86f04259d6c84659538b1c00c70bbc1fb Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 5 Dec 2016 11:33:50 -0600 Subject: [PATCH 6/6] PN mapped to duplication grid. Initialized as random seed. --- source/PerlinNoise.cpp | 2 +- source/main.cpp | 32 ++++++++------------------------ source/ppm.cpp | 2 +- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/source/PerlinNoise.cpp b/source/PerlinNoise.cpp index f07795d..c5e9350 100644 --- a/source/PerlinNoise.cpp +++ b/source/PerlinNoise.cpp @@ -1,4 +1,4 @@ -#include "PerlinNoise.h" +#include "../include/PerlinNoise.h" #include #include #include diff --git a/source/main.cpp b/source/main.cpp index 7be8a1a..9c06442 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -76,7 +76,6 @@ std::vector createVec3d(std::vector &t, int layers CompFab::Vec3 *temp = new CompFab::Vec3(-ls, -ws, 0); // Vec3 to hold our current translation matrix. -<<<<<<< HEAD CompFab::Vec3 *trans = new CompFab::Vec3(ls, ws, 0); //Vec3 to hold our current height multiplication materx. @@ -87,11 +86,10 @@ std::vector createVec3d(std::vector &t, int layers { output->push_back(mmult(*mult, t[i])); } -======= - CompFab::Vec3 *trans = new CompFab::Vec3(0, spacing, 0); CompFab::Vec3 *coord = new CompFab::Vec3(0.5,0.5,0); ->>>>>>> master + + PerlinNoise *p = new PerlinNoise(); // cl for current layer. for(int cl = 1; cl < layers; cl++) @@ -99,16 +97,17 @@ std::vector createVec3d(std::vector &t, int layers // Constructor used to re-initialize temp. *temp = CompFab::Vec3(-ls*cl, -ws*cl, 0); - // Used to change the multiplciation matrix per layer. - mult->m_z = 1.0/(cl +1); - - for(int c = 0; c < cl*8; c++) { angle = (c/(2*cl))*(0.5*PI); *trans = CompFab::Vec3(ls*cos(angle), ws*sin(angle), 0); -<<<<<<< HEAD *temp += *trans; + + *coord = *coord + mmult(*trans, CompFab::Vec3((1/(layers*2.0-1)/2.0), (1/(layers*2.0-1)/2.0), 0)); + + // Used to change the multiplciation matrix per layer. + mult->m_z = jerfunc(coord->m_x, coord->m_y, *p); + for(int j = 0; j < t.size(); j++) { output->push_back(mmult(*mult, t[j]) + *temp); @@ -129,16 +128,6 @@ std::vector createVec3id(std::vector &t, std::ve for(int k = 0; k < t.size(); k++) { output->push_back(t[k] + *offset); -======= - *temp = *temp + *trans; - - output->push_back(*temp); - - *coord = *coord + mmult(trans, Vec3(1/(layers*2-1)/2),1/(layers*2-1)/2,0); - - - *temp=mmult(temp,Vec3(1,1,n)); ->>>>>>> master } } @@ -163,7 +152,6 @@ int main(int argc, char **argv) // Debugging if(argc > 3) { -<<<<<<< HEAD if(strcmp(argv[3], "-g") == 0 || strcmp(argv[3], "-d") == 0) { // TODO: Modularize these. @@ -191,10 +179,6 @@ int main(int argc, char **argv) if(strcmp(argv[argc - 1], "-d") == 0) { -======= - - // { ->>>>>>> master for(int j = 0; j < output->v.size(); j++) { std::cout << output->v[j].m_x << " " << output->v[j].m_y << " " << output->v[j].m_z << std::endl; diff --git a/source/ppm.cpp b/source/ppm.cpp index 60ba6d8..ac029a8 100644 --- a/source/ppm.cpp +++ b/source/ppm.cpp @@ -3,7 +3,7 @@ #include #include -#include "ppm.h" +#include "../include/ppm.h" //init with default values