diff --git a/Release/Skeleton.iobj b/Release/Skeleton.iobj new file mode 100644 index 0000000000000000000000000000000000000000..e571ac5c83b90e6a8902f0fa0edd721833a739f2 Binary files /dev/null and b/Release/Skeleton.iobj differ diff --git a/Release/Skeleton.ipdb b/Release/Skeleton.ipdb new file mode 100644 index 0000000000000000000000000000000000000000..9da25f2880633d1e51615cdbd9778f34b0abce4e Binary files /dev/null and b/Release/Skeleton.ipdb differ diff --git a/Release/Skeleton.log b/Release/Skeleton.log index d7e0f621cb3b5f59b2052762813ec6a2d8a0a0c9..212e8d4eeece5d7ce386ea700b99238b4c94250d 100644 --- a/Release/Skeleton.log +++ b/Release/Skeleton.log @@ -1,16 +1,14 @@ Skeleton.cpp D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\framework.h(167,17): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. -D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(130,39): warning C4244: 'return': conversion from 'double' to 'float', possible loss of data -D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(168,1): warning C4305: 'initializing': truncation from 'double' to 'float' -D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(201,106): warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data -D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(202,107): warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data -D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(207,107): warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data -D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(208,109): warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data -D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(254,30): warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data -D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(255,30): warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data -D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(296,21): warning C4018: '<': signed/unsigned mismatch +D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(100,39): warning C4244: 'return': conversion from 'double' to 'float', possible loss of data +D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(209,1): warning C4305: 'initializing': truncation from 'double' to 'float' +D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(274,22): warning C4018: '<': signed/unsigned mismatch +D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(285,22): warning C4018: '<': signed/unsigned mismatch +D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(372,21): warning C4018: '<': signed/unsigned mismatch +D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(379,21): warning C4018: '<': signed/unsigned mismatch +D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\Skeleton\Skeleton.cpp(425,21): warning C4018: '<': signed/unsigned mismatch Generating code - 1 of 299 functions ( 0.3%) were compiled, the rest were copied from previous compilation. + 2 of 355 functions ( 0.6%) were compiled, the rest were copied from previous compilation. 0 functions were new in current compilation 1 functions had inline decision re-evaluated but remain unchanged Finished generating code diff --git a/Release/Skeleton.obj b/Release/Skeleton.obj index 54645b15e621aaf0a9bdb3f96930a236ed5a6bde..859a97819b021f8837d210371c29890f457de942 100644 Binary files a/Release/Skeleton.obj and b/Release/Skeleton.obj differ diff --git a/Release/Skeleton.tlog/CL.read.1.tlog b/Release/Skeleton.tlog/CL.read.1.tlog index 773ae93637e7795132fe19eb879e6fbefaaad207..cfaeba8b7ab4e0b1b607ce25fc4c5641f041c534 100644 Binary files a/Release/Skeleton.tlog/CL.read.1.tlog and b/Release/Skeleton.tlog/CL.read.1.tlog differ diff --git a/Release/Skeleton.tlog/Skeleton.lastbuildstate b/Release/Skeleton.tlog/Skeleton.lastbuildstate index aa63995dd5792d334569c52d79b1a6c6cc3f0b66..3b5cd14efc7c9397b7cb8dd82260105e6ce45afe 100644 --- a/Release/Skeleton.tlog/Skeleton.lastbuildstate +++ b/Release/Skeleton.tlog/Skeleton.lastbuildstate @@ -1,2 +1,2 @@ -PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.28.29333:TargetPlatformVersion=10.0.18362.0: +PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.28.29910:TargetPlatformVersion=10.0.18362.0: Release|Win32|D:\Grafika\GrafikaHaziCsomag\Programs\Skeleton\| diff --git a/Release/Skeleton.tlog/Skeleton.write.1u.tlog b/Release/Skeleton.tlog/Skeleton.write.1u.tlog index d56888fa59d987c916051c6ca3903c32bb743af2..630d328eec2b9f4d2ebbd6dbee193f1297bf25b9 100644 Binary files a/Release/Skeleton.tlog/Skeleton.write.1u.tlog and b/Release/Skeleton.tlog/Skeleton.write.1u.tlog differ diff --git a/Release/Skeleton.tlog/link.command.1.tlog b/Release/Skeleton.tlog/link.command.1.tlog index 23d73059d8eff6554bdf0c8aa2c19f9bc2c7111d..6e167410c09be97f6df86020dc51e296211d6be7 100644 Binary files a/Release/Skeleton.tlog/link.command.1.tlog and b/Release/Skeleton.tlog/link.command.1.tlog differ diff --git a/Release/Skeleton.tlog/link.read.1.tlog b/Release/Skeleton.tlog/link.read.1.tlog index 6f128485175f1960b8731413ff44ef6a69600137..1f39c1f35334d9a64c8df9960f8122c7290b2d0c 100644 Binary files a/Release/Skeleton.tlog/link.read.1.tlog and b/Release/Skeleton.tlog/link.read.1.tlog differ diff --git a/Release/Skeleton.tlog/link.write.1.tlog b/Release/Skeleton.tlog/link.write.1.tlog index 21e4a9755ded0237b4daf42127212de2d9eb5ef1..7e5d6ef855d5e05b21d27c66614c281be8c58000 100644 Binary files a/Release/Skeleton.tlog/link.write.1.tlog and b/Release/Skeleton.tlog/link.write.1.tlog differ diff --git a/Release/framework.obj b/Release/framework.obj index cf290412d8a7ec94f08493b697fdd0c6a61b7ef5..2fe8cbc69ff63ee3595df2c2937b4ecb68a82d48 100644 Binary files a/Release/framework.obj and b/Release/framework.obj differ diff --git a/Release/vc142.pdb b/Release/vc142.pdb index c4165ab41ebe9884ca89c8aadddf697d5e071116..3361c42ccd828524e52c405b676b8d4c7cbabc90 100644 Binary files a/Release/vc142.pdb and b/Release/vc142.pdb differ diff --git a/Skeleton.cpp b/Skeleton.cpp index 5bc740994082ad6d9367bb0d2c0c0e86866d1fd6..fee95f5bc141915606d1157af40901be980552cb 100644 --- a/Skeleton.cpp +++ b/Skeleton.cpp @@ -60,10 +60,20 @@ const char* const fragmentSource = R"( } )"; +// +// Global variables +// + const int CIRCLESEG = 25; //how many triangle the base stands from GPUProgram gpuProgram; // vertex and fragment shaders +unsigned int vao; + + +// +// Global structs +// struct Color { float r, g, b; @@ -77,20 +87,34 @@ struct Color { } }; +// +//Global functions +// + void setBackgroundColor(Color color) { glClearColor(color.r, color.g, color.b, 1); // background color glClear(GL_COLOR_BUFFER_BIT); // clear frame buffer } -unsigned int vao; +float degToRad(float courrentTriangleAngle) { + return (courrentTriangleAngle * M_PI / 180.0); +} + +// +//Global classes +// class drawableBase { protected: - unsigned int vbo; //vertex buffer obj std::vector<vec2> points; Color color; public: + + //drawableBase() { + // init(); + //} + void MVPInit() { float MVPtransf[4][4] = { 1, 0, 0, 0, // MVP matrix, @@ -103,8 +127,6 @@ public: &MVPtransf[0][0]); // Load a 4x4 row-major float matrix to the specified location } - virtual void draw() = 0; - virtual void setColor(Color newColor) = 0; void init() { @@ -126,29 +148,48 @@ public: } }; -float degToRad(float courrentTriangleAngle){ - return (courrentTriangleAngle * M_PI / 180.0); -} - - +int cntr = 0; // TODO: remove this cntr class GraphPoint : drawableBase { vec3 p3D; //center of the point in hyperbolic splace float r = 20.0f; vec2 p; // center on the base disk + std::vector<GraphPoint*> neighbours; + bool Drawn; public: GraphPoint() { - p = vec2((((float)rand() / (float)(RAND_MAX))*8)-4, (((float)rand() / (float)(RAND_MAX)) * 8) - 4); //4* majd megszorozni + p = vec2((((float)rand() / (float)(RAND_MAX))*4)-2, (((float)rand() / (float)(RAND_MAX)) * 4) - 2); //4* majd megszorozni p3D = Vec2ToVec3(p); placeCircleToNewCoordinates(); setColor(Color(244, 164, 96)); + Drawn = false; + } + + bool getDrawn() { + return Drawn; + } + + void setDrawn(bool _d) { + Drawn = _d; + } + + void addNeighbour(GraphPoint *gp){ + neighbours.push_back(gp); + } + + int getNeighboursSize() { + return neighbours.size(); } vec2 getPoint() { return p; } + vec3 getPoint3D() { + return p3D; + } + void setCoordinates(vec2 _p) { p = _p; p3D = Vec2ToVec3(p); @@ -166,7 +207,7 @@ public: void placeCircleToNewCoordinates() { points.clear(); float piece = 360.0 / CIRCLESEG; - float courrentTriangleAngle = 0; + float courrentTriangleAngle = 0.0f; vec3 gradient = grad(p3D); float iranymentiderivaltX = gradient.x * r/p3D.z; float iranymentiderivaltY = gradient.y * r/p3D.z; @@ -175,41 +216,38 @@ public: points.push_back(vec2(p3D.x / p3D.z, p3D.y / p3D.z)); // points.push_back(vec2(p.x +(cos(courrentTriangleAngle * M_PI / 180.0) /30),p.y + (sin(courrentTriangleAngle * M_PI / 180.0) /30))); alap volt ami kort rajzolt a pontokba - //points.push_back(vec2( // p3D.x + (cos(degToRad(courrentTriangleAngle)) / 30) * (cos((abs(p3D.x) * abs(p3D.x) * abs(p3D.x)) / 3 + (abs(p3D.x) * abs(p3D.y) * abs(p3D.y)) + abs(p3D.x) * abs(p3D.z) * abs(p3D.z) + abs(p3D.x)) /30 ), // p3D.y + (sin(degToRad(courrentTriangleAngle)) / 30) * (sin((abs(p3D.y) * abs(p3D.y) * abs(p3D.y)) / 3 + (abs(p3D.y) * abs(p3D.x) * abs(p3D.x)) + abs(p3D.y) * abs(p3D.z) * abs(p3D.z) + abs(p3D.y)) /30 ))); - //points.push_back(vec2( // p3D.x + (cos(degToRad(courrentTriangleAngle)) / 20) * (cos(degToRad(90 - abs(1/tan(8 * p3D.x + 8 * p3D.y - 8 * p3D.z))))), // p3D.y + (sin(degToRad(courrentTriangleAngle)) / 20) * (sin(degToRad(90 - abs(1/tan(8 * p3D.x + 8 * p3D.y - 8 * p3D.z))))))); - //points.push_back(vec2( // p3D.x / p3D.z + (cos(degToRad(courrentTriangleAngle)) / 20) / p3D.z * (sin(M_PI/2 - abs(1 / tan(2 * p3D.x + 2 * p3D.y - 2 * p3D.z)))), // p3D.y / p3D.z + (sin(degToRad(courrentTriangleAngle)) / 20) / p3D.z * (cos(M_PI/2 - abs(1 / tan(2 * p3D.x + 2 * p3D.y - 2 * p3D.z)))))); - //points.push_back(vec2( // p3D.x / p3D.z + (cos(degToRad(courrentTriangleAngle)) / r) / p3D.z * (sin(M_PI / 2 - abs(1 / tan(p3D.z / (sqrt(p3D.x * p3D.x + p3D.y * p3D.y)))))), // p3D.y / p3D.z + (sin(degToRad(courrentTriangleAngle)) / r) / p3D.z * (cos(M_PI / 2 - abs(1 / tan(abs(p3D.y) / (sqrt(p3D.x * p3D.x + p3D.z * p3D.z)))))))); - - //points.push_back(vec2( // p3D.x / p3D.z + (cosf(degToRad(courrentTriangleAngle)) / r) / p3D.z * (sinf(M_PI / 2 - (atanf(abs(iranymentiderivaltX))))), // p3D.y / p3D.z + (sinf(degToRad(courrentTriangleAngle)) / r) / p3D.z * (-sinf(M_PI / 2 - (atanf(abs(iranymentiderivaltY))))))); + //points.push_back(vec2( + // p3D.x / p3D.z + (cosf(degToRad(courrentTriangleAngle)) / r) / p3D.z * sinf(atanf(p3D.z/p3D.x) * M_PI / 4), + // p3D.y / p3D.z + (sinf(degToRad(courrentTriangleAngle)) / r) / p3D.z * -sinf(atanf(p3D.z/p3D.y) * M_PI / 4))); points.push_back(vec2( - p3D.x / p3D.z + (cosf(degToRad(courrentTriangleAngle)) / r) / p3D.z * sinf(atanf(p3D.z/p3D.x) * M_PI / 4), - p3D.y / p3D.z + (sinf(degToRad(courrentTriangleAngle)) / r) / p3D.z * -sinf(atanf(p3D.z/p3D.y) * M_PI / 4))); + p3D.x / p3D.z + (cosf(degToRad(courrentTriangleAngle)) / r) / p3D.z * cosf(atanf(2 * abs(p3D.x))), + p3D.y / p3D.z + (sinf(degToRad(courrentTriangleAngle)) / r) / p3D.z * -cosf(atanf(2 * abs(p3D.y))))); courrentTriangleAngle += piece; points.push_back(vec2( - p3D.x / p3D.z + (cosf(degToRad(courrentTriangleAngle)) / r) / p3D.z * sinf(atanf(p3D.z / p3D.x) * M_PI/4), - p3D.y / p3D.z + (sinf(degToRad(courrentTriangleAngle)) / r) / p3D.z * -sinf(atanf(p3D.z / p3D.y) * M_PI /4))); + p3D.x / p3D.z + (cosf(degToRad(courrentTriangleAngle)) / r) / p3D.z * cosf(atanf(2 * abs(p3D.x))), + p3D.y / p3D.z + (sinf(degToRad(courrentTriangleAngle)) / r) / p3D.z * -cosf(atanf(2 * abs(p3D.y))))); } - //printf("x=%f, y=%f xALPHA=%f yALPHA=%f \n", p3D.x, p3D.y, 1/tanf(iranymentiderivaltX), 1/tanf(iranymentiderivaltY)); + //printf("x=%f, y=%f xALPHA=%f \n", p3D.x, p3D.y, sinf(atanf(2 * abs(p3D.x) + 2 * abs(p3D.y)))); } vec2 vec3tovec2(vec3 c) { @@ -228,31 +266,69 @@ public: color = newColor; } + void gpNeighbourAlgorithm(float angle) { + try { + float deg = 360.0f / neighbours.size(); + float currAngle = angle + 180.0f - deg; + + for (int i = 0; i < neighbours.size(); i++) { + if (neighbours[i]->getDrawn() == false) { + + printf("kirajzolva: %d \n", ++cntr); + neighbours[i]->setCoordinates(vec2(p.x + cosf(degToRad(currAngle)), p.y + sinf(degToRad(currAngle)))); + currAngle += deg; + } + } + - void draw() override + currAngle = angle - 180 + deg; + for (int i = 0; i < neighbours.size(); i++) { + if (neighbours[i]->getDrawn() == false) { + neighbours[i]->setDrawn(true); + neighbours[i]->gpNeighbourAlgorithm(currAngle + deg); + currAngle += deg; + } + } + } + catch (...) { + printf("Somethings wrong here"); + } + } + + void draw() { + Drawn = true; + MVPInit(); init(); reColor(); - MVPInit(); glBindVertexArray(vao); // Draw call glDrawArrays(GL_TRIANGLES, 0, points.size() /*# Elements*/); } }; +//Can't put it to the structs, becouse GraphPoint not declared there struct pairs { - GraphPoint p1; - GraphPoint p2; + GraphPoint* p1; + GraphPoint* p2; }; class Line : drawableBase { - + GraphPoint* p1; + GraphPoint* p2; public: - Line(vec2 _p1, vec2 _p2) { + Line(GraphPoint *_p1, GraphPoint *_p2) { setColor(Color(254, 254, 0)); - points.push_back(_p1 / sqrt(_p1.x * _p1.x + _p1.y * _p1.y + 1)); - points.push_back(_p2 / sqrt(_p2.x * _p2.x + _p2.y * _p2.y + 1)); + p2 = _p2; + p1 = _p1; + } + + void set() { + vec3 temp = p1->getPoint3D(); + points.push_back(vec2(temp.x / temp.z, temp.y/ temp.z)); + temp = p2->getPoint3D(); + points.push_back(vec2(temp.x / temp.z, temp.y / temp.z)); } void reColor() const { @@ -263,7 +339,8 @@ public: color = newColor; } - void draw() override { + void draw() { + set(); init(); reColor(); MVPInit(); @@ -285,27 +362,80 @@ public: for (int j = i+1; j < 50; j++) { int rndm = rand() % 100; if (rndm < 5) { - pairs p; p.p1 = gps[i]; p.p2 = gps[j]; + pairs p; p.p1 = &gps[i]; p.p2 = &gps[j]; + gps[i].addNeighbour(&gps[j]); + gps[j].addNeighbour(&gps[i]); pair.push_back(p); } } } + for (int i = 0; i < pair.size(); i++) { + Line temp(pair[i].p1, pair[i].p2); + line.push_back(temp); + } } void draw() { - for (int i = 0; i < pair.size(); i++) { - Line temp(pair[i].p1.getPoint(), pair[i].p2.getPoint()); - temp.draw(); - line.push_back(temp); + for (int i = 0; i < line.size(); i++) { + line[i].draw(); } for (int i = 0; i < 50; i++) { gps[i].draw(); } } -}; + void sortGraph() { + // + //Select the graphpoint with the most pair + // + GraphPoint biggest = gps[0]; + gps[0].setDrawn(false); + for (int i = 1; i < 50; i++) { + if (gps[i].getNeighboursSize() > biggest.getNeighboursSize()) + biggest = gps[i]; + gps[i].setDrawn(false); + } + + biggest.setCoordinates(vec2()); + + //milyen fokban kell elhelyezni a szomszedokat + float deg = 360.0f / biggest.getNeighboursSize(); + float currAngle = 0.0f; + + //kirajzolja az elsot + biggest.setDrawn(true); + biggest.gpNeighbourAlgorithm(currAngle); + currAngle += deg; + + //vegigiteral az osszesen + for (int i = 0; i < 50; i++) { + //ha meg nics felrajzolva + if (gps[i].getDrawn() == false) { + // beallitja a koordinatat ay elsohoz kepest + gps[i].setCoordinates(vec2(biggest.getPoint3D().x + cosf(degToRad(currAngle)) /0.9f, biggest.getPoint3D().y + sinf(degToRad(currAngle))/0.9f)); + gps[i].setDrawn(true); + gps[i].gpNeighbourAlgorithm(currAngle); + currAngle += deg; + } + } + // Delete previous graph from buffer + glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_DEPTH_BUFFER_BIT); + for (int i = 0; i < line.size(); i++) { + line[i].draw(); + } + for (int i = 0; i < 50; i++) { + gps[i].draw(); + } + glutSwapBuffers(); + } +}; graphManager gm; +// +//OpenGL skeleton +// + // Initialization, create an OpenGL context void onInitialization() { glViewport(0, 0, windowWidth, windowHeight); @@ -325,6 +455,7 @@ void onDisplay() { // Key of ASCII code pressed void onKeyboard(unsigned char key, int pX, int pY) { if (key == 'd') glutPostRedisplay(); // if d, invalidate display, i.e. redraw + if (key == ' ') gm.sortGraph(); } // Key of ASCII code released