From c5b64370ccbeba12a41416bba45aca9e5cc51061 Mon Sep 17 00:00:00 2001 From: Alexander Biryukov Date: Thu, 31 May 2018 19:03:33 +0500 Subject: [PATCH] Minor improvements --- assets/lines.json | 844 +++++++++++++++++++++++++++++++++++++++++++++ game/main_code.cpp | 122 +++++-- game/main_code.h | 3 + 3 files changed, 943 insertions(+), 26 deletions(-) create mode 100755 assets/lines.json mode change 100644 => 100755 game/main_code.h diff --git a/assets/lines.json b/assets/lines.json new file mode 100755 index 0000000..d5948e6 --- /dev/null +++ b/assets/lines.json @@ -0,0 +1,844 @@ +{ + "lines": [ + { + "start": [ + -500, + -500 + ], + "end": [ + 500, + -500 + ] + }, + { + "start": [ + -500, + -488 + ], + "end": [ + 500, + -488 + ] + }, + { + "start": [ + -500, + -476 + ], + "end": [ + 500, + -476 + ] + }, + { + "start": [ + -500, + -464 + ], + "end": [ + 500, + -464 + ] + }, + { + "start": [ + -500, + -452 + ], + "end": [ + 500, + -452 + ] + }, + { + "start": [ + -500, + -440 + ], + "end": [ + 500, + -440 + ] + }, + { + "start": [ + -500, + -428 + ], + "end": [ + 500, + -428 + ] + }, + { + "start": [ + -500, + -416 + ], + "end": [ + 500, + -416 + ] + }, + { + "start": [ + -500, + -404 + ], + "end": [ + 500, + -404 + ] + }, + { + "start": [ + -500, + -392 + ], + "end": [ + 500, + -392 + ] + }, + { + "start": [ + -500, + -380 + ], + "end": [ + 500, + -380 + ] + }, + { + "start": [ + -500, + -368 + ], + "end": [ + 500, + -368 + ] + }, + { + "start": [ + -500, + -356 + ], + "end": [ + 500, + -356 + ] + }, + { + "start": [ + -500, + -344 + ], + "end": [ + 500, + -344 + ] + }, + { + "start": [ + -500, + -332 + ], + "end": [ + 500, + -332 + ] + }, + { + "start": [ + -500, + -320 + ], + "end": [ + 500, + -320 + ] + }, + { + "start": [ + -500, + -308 + ], + "end": [ + 500, + -308 + ] + }, + { + "start": [ + -500, + -296 + ], + "end": [ + 500, + -296 + ] + }, + { + "start": [ + -500, + -284 + ], + "end": [ + 500, + -284 + ] + }, + { + "start": [ + -500, + -272 + ], + "end": [ + 500, + -272 + ] + }, + { + "start": [ + -500, + -260 + ], + "end": [ + 500, + -260 + ] + }, + { + "start": [ + -500, + -248 + ], + "end": [ + 500, + -248 + ] + }, + { + "start": [ + -500, + -236 + ], + "end": [ + 500, + -236 + ] + }, + { + "start": [ + -500, + -224 + ], + "end": [ + 500, + -224 + ] + }, + { + "start": [ + -500, + -212 + ], + "end": [ + 500, + -212 + ] + }, + { + "start": [ + -500, + -200 + ], + "end": [ + 500, + -200 + ] + }, + { + "start": [ + -500, + -188 + ], + "end": [ + 500, + -188 + ] + }, + { + "start": [ + -500, + -176 + ], + "end": [ + 500, + -176 + ] + }, + { + "start": [ + -500, + -164 + ], + "end": [ + 500, + -164 + ] + }, + { + "start": [ + -500, + -152 + ], + "end": [ + 500, + -152 + ] + }, + { + "start": [ + -500, + -140 + ], + "end": [ + 500, + -140 + ] + }, + { + "start": [ + -500, + -128 + ], + "end": [ + 500, + -128 + ] + }, + { + "start": [ + -500, + -116 + ], + "end": [ + 500, + -116 + ] + }, + { + "start": [ + -500, + -104 + ], + "end": [ + 500, + -104 + ] + }, + { + "start": [ + -500, + -92 + ], + "end": [ + 500, + -92 + ] + }, + { + "start": [ + -500, + -80 + ], + "end": [ + 500, + -80 + ] + }, + { + "start": [ + -500, + -68 + ], + "end": [ + 500, + -68 + ] + }, + { + "start": [ + -500, + -56 + ], + "end": [ + 500, + -56 + ] + }, + { + "start": [ + -500, + -44 + ], + "end": [ + 500, + -44 + ] + }, + { + "start": [ + -500, + -32 + ], + "end": [ + 500, + -32 + ] + }, + { + "start": [ + -500, + -20 + ], + "end": [ + 500, + -20 + ] + }, + { + "start": [ + -500, + -8 + ], + "end": [ + 500, + -8 + ] + }, + { + "start": [ + -500, + 4 + ], + "end": [ + 500, + 4 + ] + }, + { + "start": [ + -500, + 16 + ], + "end": [ + 500, + 16 + ] + }, + { + "start": [ + -500, + 28 + ], + "end": [ + 500, + 28 + ] + }, + { + "start": [ + -500, + 40 + ], + "end": [ + 500, + 40 + ] + }, + { + "start": [ + -500, + 52 + ], + "end": [ + 500, + 52 + ] + }, + { + "start": [ + -500, + 64 + ], + "end": [ + 500, + 64 + ] + }, + { + "start": [ + -500, + 76 + ], + "end": [ + 500, + 76 + ] + }, + { + "start": [ + -500, + 88 + ], + "end": [ + 500, + 88 + ] + }, + { + "start": [ + -500, + 100 + ], + "end": [ + 500, + 100 + ] + }, + { + "start": [ + -500, + 112 + ], + "end": [ + 500, + 112 + ] + }, + { + "start": [ + -500, + 124 + ], + "end": [ + 500, + 124 + ] + }, + { + "start": [ + -500, + 136 + ], + "end": [ + 500, + 136 + ] + }, + { + "start": [ + -500, + 148 + ], + "end": [ + 500, + 148 + ] + }, + { + "start": [ + -500, + 160 + ], + "end": [ + 500, + 160 + ] + }, + { + "start": [ + -500, + 172 + ], + "end": [ + 500, + 172 + ] + }, + { + "start": [ + -500, + 184 + ], + "end": [ + 500, + 184 + ] + }, + { + "start": [ + -500, + 196 + ], + "end": [ + 500, + 196 + ] + }, + { + "start": [ + -500, + 208 + ], + "end": [ + 500, + 208 + ] + }, + { + "start": [ + -500, + 220 + ], + "end": [ + 500, + 220 + ] + }, + { + "start": [ + -500, + 232 + ], + "end": [ + 500, + 232 + ] + }, + { + "start": [ + -500, + 244 + ], + "end": [ + 500, + 244 + ] + }, + { + "start": [ + -500, + 256 + ], + "end": [ + 500, + 256 + ] + }, + { + "start": [ + -500, + 268 + ], + "end": [ + 500, + 268 + ] + }, + { + "start": [ + -500, + 280 + ], + "end": [ + 500, + 280 + ] + }, + { + "start": [ + -500, + 292 + ], + "end": [ + 500, + 292 + ] + }, + { + "start": [ + -500, + 304 + ], + "end": [ + 500, + 304 + ] + }, + { + "start": [ + -500, + 316 + ], + "end": [ + 500, + 316 + ] + }, + { + "start": [ + -500, + 328 + ], + "end": [ + 500, + 328 + ] + }, + { + "start": [ + -500, + 340 + ], + "end": [ + 500, + 340 + ] + }, + { + "start": [ + -500, + 352 + ], + "end": [ + 500, + 352 + ] + }, + { + "start": [ + -500, + 364 + ], + "end": [ + 500, + 364 + ] + }, + { + "start": [ + -500, + 376 + ], + "end": [ + 500, + 376 + ] + }, + { + "start": [ + -500, + 388 + ], + "end": [ + 500, + 388 + ] + }, + { + "start": [ + -500, + 400 + ], + "end": [ + 500, + 400 + ] + }, + { + "start": [ + -500, + 412 + ], + "end": [ + 500, + 412 + ] + }, + { + "start": [ + -500, + 424 + ], + "end": [ + 500, + 424 + ] + }, + { + "start": [ + -500, + 436 + ], + "end": [ + 500, + 436 + ] + }, + { + "start": [ + -500, + 448 + ], + "end": [ + 500, + 448 + ] + }, + { + "start": [ + -500, + 460 + ], + "end": [ + 500, + 460 + ] + }, + { + "start": [ + -500, + 472 + ], + "end": [ + 500, + 472 + ] + }, + { + "start": [ + -500, + 484 + ], + "end": [ + 500, + 484 + ] + }, + { + "start": [ + -500, + 496 + ], + "end": [ + 500, + 496 + ] + } + ] +} \ No newline at end of file diff --git a/game/main_code.cpp b/game/main_code.cpp index 27e176e..2b5fbfe 100755 --- a/game/main_code.cpp +++ b/game/main_code.cpp @@ -82,6 +82,7 @@ void TMyApplication::InnerInit() ResourceManager->TexList.AddTexture("console_bkg.bmp"); ResourceManager->TexList.AddTexture("background.jpg"); + ResourceManager->TexList.AddTexture("pimgpsh.jpg"); ResourceManager->TexList.AddTexture("HeightMap.png"); ResourceManager->TexList.AddTexture("NormalMap.png"); ResourceManager->TexList.AddTexture("linesAll.png"); @@ -137,8 +138,23 @@ void TMyApplication::InnerInit() auto findPlaneBasis = [] (const Vector3f &normal) { std::vector result; - Vector3f e0 = Vector3f(1, 0, -normal.x() / normal.z()).normalized(); - Vector3f e1 = Vector3f(0, 1, -normal.y() / normal.z()); + Vector3f e0, e1; + if(normal.z() != 0) + { + e0 = Vector3f(1, 0, -normal.x() / normal.z()).normalized(); + e1 = Vector3f(0, 1, -normal.y() / normal.z()); + } + else if(normal.y() != 0) + { + e0 = Vector3f(1, -normal.x() / normal.y(), 0).normalized(); + e1 = Vector3f(0, -normal.z() / normal.y(), 1); + } + else + { + e0 = Vector3f(-normal.y() / normal.x(), 1, 0).normalized(); + e1 = Vector3f(-normal.z() / normal.x(), 0, 1); + } + e1 = (e1 - (e1.dot(e0) / e0.dot(e0)) * e0).normalized(); result.push_back(e0); @@ -148,18 +164,21 @@ void TMyApplication::InnerInit() }; { - float const R = 5; - float const r = 6; - size_t const threadsCount = 5; + float const R = 3; + float const r = 4; + size_t const threadsCount = 3; size_t const edgesCount = 6; float const angle = pi / 6; - size_t const iterationsCount = 20; - Vector3f up(0, 1, 0); - auto g = [this, findPlaneBasis, R, r, threadsCount, edgesCount, up, angle, iterationsCount] (const Vector3f &start, const Vector3f &end) { - Vector3f translate = (end - start) / iterationsCount; - auto e = findPlaneBasis(translate); + size_t const iterationsCount = 60; + Vector3f up(0, 1, 0); up.normalize(); + size_t const step = 5; + auto g = [this, findPlaneBasis, R, r, threadsCount, edgesCount, up, angle, step] (Vector3f start, Vector3f end) { + size_t iterationsCount = (end - start).norm() / step; + Vector3f direction = (end - start).normalized(); + start = start + (r + R) * direction; + end = end - (r + R) * direction; + auto e = findPlaneBasis(up); - // create thread edges std::vector threadCenters; std::vector> threads; for(auto i = 0; i < threadsCount; i++) { @@ -174,10 +193,36 @@ void TMyApplication::InnerInit() threads.push_back(edges); } - - auto matrix = (Translation3f(translate) * AngleAxis(angle, translate.normalized())).matrix(); - - for(auto i = 0; i < iterationsCount; i++) { + + auto rotateMatrix1 = ( + Translation3f((r + R) * direction) * + AngleAxis( + -pi / 8, + direction.cross(up).normalized() + ) * + Translation3f(-(r + R) * direction) + ).matrix(); + auto matrix = ( + Translation3f((r + R) * up) * + AngleAxis( + angle, + direction + ) * + Translation3f(-(r + R) * up) * + Translation3f(static_cast(step) * direction) + ).matrix(); + auto rotateMatrix2 = ( + Translation3f(static_cast(step) * direction * iterationsCount) * + Translation3f((r + R) * direction) * + AngleAxis( + -pi / 8, + direction.cross(up).normalized() + ) * + Translation3f(-(r + R) * direction) * + Translation3f(-static_cast(step) * direction * iterationsCount) + ).matrix(); + + for(int i = -4; i < static_cast(iterationsCount) + 4; i++) { std::vector> newThreads; for(auto j = 0; j < threadsCount; j++) { @@ -185,14 +230,28 @@ void TMyApplication::InnerInit() std::vector newEdges; for(auto k = 0; k < edgesCount; k++) { - newEdges.push_back(matrix * edges[k]); + if(i < 0) { + newEdges.push_back(rotateMatrix1 * edges[k]); + } else if(i < iterationsCount) { + newEdges.push_back(matrix * edges[k]); + } else { + newEdges.push_back(rotateMatrix2 * edges[k]); + } } newThreads.push_back(newEdges); auto threadCenter_ = Vector4f(threadCenters[j].x(), threadCenters[j].y(), threadCenters[j].z(), 1); auto threadCenter = threadCenter_.head(3); - auto newThreadCenter = (matrix * threadCenter_).head(3); + + Vector3f newThreadCenter; + if (i < 0) { + newThreadCenter = (rotateMatrix1 * threadCenter_).head(3); + } else if (i < iterationsCount) { + newThreadCenter = (matrix * threadCenter_).head(3); + } else { + newThreadCenter = (rotateMatrix2 * threadCenter_).head(3); + } threadCenters[j] = newThreadCenter; @@ -232,15 +291,26 @@ void TMyApplication::InnerInit() } }; - Vector3f const stepDirection(18, 0, 0); - Vector3f p1(bottomLeft[0], 100, -bottomLeft[1]); - Vector3f p2 = p1 - Vector3f(0, 0, W); - - while(p1[0] < bottomLeft[0] + W) { - g(p1, p2); - p1 += stepDirection; - p2 += stepDirection; + namespace pt = boost::property_tree; + pt::ptree root; + pt::read_json(ST::PathToResources + "lines.json", root); + + for(auto line: root.get_child("lines")) { + std::vector start; + std::vector end; + + for(auto value: line.second.get_child("start")) { + start.push_back(value.second.get_value()); + } + + for (auto value : line.second.get_child("end")) { + end.push_back(value.second.get_value()); + } + + g(Vector3f(start[0], 0, start[1]), Vector3f(end[0], 0, end[1])); + } + } } @@ -252,7 +322,7 @@ void TMyApplication::InnerInit() */ std::string const CONST_STRING_HEIGHTMAP_UNIFORM = "HeightMap"; - background.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "background.jpg"; + background.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "pimgpsh.jpg"; fabricRender.first.SamplerMap[CONST_STRING_NORMALMAP_UNIFORM] = "NormalMap.png"; fabricRender.first.SamplerMap[CONST_STRING_HEIGHTMAP_UNIFORM] = "HeightMap.png"; diff --git a/game/main_code.h b/game/main_code.h old mode 100644 new mode 100755 index fd197e6..d2b7c70 --- a/game/main_code.h +++ b/game/main_code.h @@ -20,6 +20,9 @@ #include "boost/assign.hpp" #include "boost/bind.hpp" +#include "boost/property_tree/ptree.hpp" +#include "boost/property_tree/json_parser.hpp" + #include "include/Engine.h" #include "boost/signals2.hpp"//Signal must be included after asio