Minor improvements

This commit is contained in:
Alexander Biryukov 2018-05-31 19:03:33 +05:00
parent bdef3aca47
commit c5b64370cc
3 changed files with 943 additions and 26 deletions

844
assets/lines.json Executable file
View File

@ -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
]
}
]
}

View File

@ -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<Vector3f> 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<Vector3f> threadCenters;
std::vector<std::vector<Vector4f>> threads;
for(auto i = 0; i < threadsCount; i++) {
@ -175,9 +194,35 @@ void TMyApplication::InnerInit()
threads.push_back(edges);
}
auto matrix = (Translation3f(translate) * AngleAxis<float>(angle, translate.normalized())).matrix();
auto rotateMatrix1 = (
Translation3f((r + R) * direction) *
AngleAxis<float>(
-pi / 8,
direction.cross(up).normalized()
) *
Translation3f(-(r + R) * direction)
).matrix();
auto matrix = (
Translation3f((r + R) * up) *
AngleAxis<float>(
angle,
direction
) *
Translation3f(-(r + R) * up) *
Translation3f(static_cast<int>(step) * direction)
).matrix();
auto rotateMatrix2 = (
Translation3f(static_cast<int>(step) * direction * iterationsCount) *
Translation3f((r + R) * direction) *
AngleAxis<float>(
-pi / 8,
direction.cross(up).normalized()
) *
Translation3f(-(r + R) * direction) *
Translation3f(-static_cast<int>(step) * direction * iterationsCount)
).matrix();
for(auto i = 0; i < iterationsCount; i++) {
for(int i = -4; i < static_cast<int>(iterationsCount) + 4; i++) {
std::vector<std::vector<Vector4f>> newThreads;
for(auto j = 0; j < threadsCount; j++) {
@ -185,14 +230,28 @@ void TMyApplication::InnerInit()
std::vector<Vector4f> 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<int> start;
std::vector<int> end;
for(auto value: line.second.get_child("start")) {
start.push_back(value.second.get_value<int>());
}
for (auto value : line.second.get_child("end")) {
end.push_back(value.second.get_value<int>());
}
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";

3
game/main_code.h Normal file → Executable file
View File

@ -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