This commit is contained in:
Alexander Biryukov 2018-05-30 18:09:27 +05:00
parent 3f2572eaa5
commit 46b7b28b2b
5 changed files with 103 additions and 43 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

131
game/main_code.cpp Normal file → Executable file
View File

@ -54,7 +54,8 @@ void TMyApplication::InnerInit()
#ifdef TARGET_WIN32
#ifdef NDEBUG
ST::PathToResources = "resources/";
//ST::PathToResources = "resources/";
ST::PathToResources = "../../../assets/";
#else
ST::PathToResources = "../../../assets/";
#endif
@ -83,6 +84,9 @@ void TMyApplication::InnerInit()
ResourceManager->TexList.AddTexture("HeightMap.png");
ResourceManager->TexList.AddTexture("NormalMap.png");
ResourceManager->TexList.AddTexture("linesAll.png");
ResourceManager->TexList.AddTexture("clean-fabric-texture-4-780x585.jpg");
ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512);
@ -137,49 +141,97 @@ void TMyApplication::InnerInit()
float const step = 12;
float const thick = 10;
auto f = [this, texW, texH, thick, W, H] (const Vector3f &p1, const Vector3f &p2) {
auto pv = p2 - p1;
Vector3f ortho(pv[2], 0, pv[0]);
ortho.normalize();
auto p3 = p2 + ortho * thick;
auto p4 = p1 + ortho * thick;
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1);
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p2);
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3);
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3);
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p4);
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1);
float const R = 5;
float const r = 6;
size_t const threadsCount = 3;
size_t const verticesCount = 6;
float const angle = pi / 18;
size_t const iterationsCount = 50;
auto g = [this, R, r, threadsCount, verticesCount, angle, iterationsCount, texW, texH, thick, H, W] (const Vector3f &start, const Vector3f &end) {
Vector3f direction = end - start;
Vector3f translate = direction / iterationsCount;
direction.normalize();
auto texThick = thick / texW;
auto m = (p1[0] + p2[0]) / 2 / texW;
auto y = H / texH;
auto e0 = Vector3f(1, 0, -direction.x() / direction.z());
auto e1 = Vector3f(0, 1, -direction.y() / direction.z());
e1 = e1 - (e1.dot(e0) / e0.dot(e0)) * e0;
e0.normalize();
e1.normalize();
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, 0));
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, y));
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, y));
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, y));
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, 0));
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, 0));
std::vector<std::vector<Vector4f>> threads;
for(auto i = 0; i < threadsCount; i++) {
std::vector<Vector4f> vertices;
Vector3f threadCenter = R * (e0 * cosf(i * 2 * pi / threadsCount) + e1 * sinf(i * 2 * pi / threadsCount));
for(auto j = 0; j < verticesCount; j++) {
auto verticeCenter = threadCenter + r * (e0 * cosf(j * 2 * pi / verticesCount) + e1 * sinf(j * 2 * pi / verticesCount));
vertices.push_back(Vector4f(verticeCenter.x(), verticeCenter.y(), verticeCenter.z(), 1));
}
threads.push_back(vertices);
}
auto transform = Translation3f(translate) * AngleAxis<float>(angle, direction);
auto matrix = transform.matrix();
for(auto i = 0; i < iterationsCount; i++) {
std::vector<std::vector<Vector4f>> newThreads;
for(auto j = 0; j < threadsCount; j++) {
auto vertices = threads[j];
std::vector<Vector4f> newVertices;
for(auto k = 0; k < verticesCount; k++) {
newVertices.push_back(matrix * vertices[k]);
}
newThreads.push_back(newVertices);
for(auto k = 0; k < verticesCount; k++) {
auto vk = vertices[k];
auto vk1 = vertices[(k + 1) % verticesCount];
auto nvk = newVertices[k];
auto nvk1 = newVertices[(k + 1) % verticesCount];
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + vk.head(3));
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + vk1.head(3));
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + nvk.head(3));
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + vk1.head(3));
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + nvk1.head(3));
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + nvk.head(3));
auto texThick = thick / texW;
auto m = (start[0] + end[0]) / 2 / texW;
auto y = H / texH;
auto texPiece = texH / iterationsCount;
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0));
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.01, 0));
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0.01));
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.01, 0));
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.01, 0.01));
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0.01));
}
}
threads = newThreads;
}
};
Vector3f const stepDirection(1, 0, 0);
Vector3f const stepDirection(18, 0, 0);
Vector3f p1(bottomLeft[0], 0, -bottomLeft[1]);
Vector3f p2 = p1 - Vector3f(0, 0, W);
while (p1[0] < bottomLeft[0] + W) {
auto p2 = p1 - Vector3f(0, 0, W);
f(p1, p2);
auto p3 = p1 + step * stepDirection;
f(p3, p2);
p1 = p3;
while(p1[0] < bottomLeft[0] + W)
{
g(p1, p2);
p1 += stepDirection;
p2 += stepDirection;
}
}
background.first.ShaderName ="DefaultShader";
@ -194,10 +246,12 @@ void TMyApplication::InnerInit()
fabricRender.first.SamplerMap[CONST_STRING_NORMALMAP_UNIFORM] = "NormalMap.png";
fabricRender.first.SamplerMap[CONST_STRING_HEIGHTMAP_UNIFORM] = "HeightMap.png";
fabricRender.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "linesAll.png";
fabricRender.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "clean-fabric-texture-4-780x585.jpg";
background.second.RefreshBuffer();
fabricRender.second.RefreshBuffer();
glEnable(GL_DEPTH_TEST);
Inited = true;
}
@ -286,8 +340,7 @@ void TMyApplication::InnerDraw()
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
CheckGlError("");
auto mat1 = quatToMatrix(quat1);
@ -312,6 +365,8 @@ void TMyApplication::InnerDraw()
Renderer->DrawTriangleList(background.second);
}
//glEnable(GL_CULL_FACE);
{
TRenderParamsSetter params(fabricRender.first);

View File

@ -22,6 +22,7 @@
<ProjectGuid>{1CC98EEE-BBCB-4D79-B6D7-8511789172C5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>DoubleHitBallswin</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@ -48,7 +49,7 @@
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@ -150,7 +151,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;TARGET_WIN32;_WIN32_WINNT=0x0501;WIN32_LEAN_AND_MEAN;EIGEN_DONT_ALIGN_STATICALLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_63_0/;../../../../boost_1_63_0/bin.v2/libs/system/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/date_time/build/msvc-14.0/release/address-model-64/link-static/threading-multi/;../../../../boost_1_63_0/bin.v2/libs/regex/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/thread/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/chrono/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/signals/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_67_0/;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4503</DisableSpecificWarnings>
</ClCompile>
<Link>
@ -158,7 +159,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_63_0/stage/x64/lib;../../../../boost_1_63_0/bin.v2/libs/system/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/date_time/build/msvc-14.0/release/address-model-64/link-static/threading-multi/;../../../../boost_1_63_0/bin.v2/libs/regex/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/thread/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/chrono/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/signals/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510;../x64/Release</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_67_0/stage/lib;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510;../x64/Release</AdditionalLibraryDirectories>
<AdditionalDependencies>libjpeg.lib;libpng.lib;Engine.lib;opengl32.lib;glu32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -8,8 +8,8 @@ int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst,
LPSTR lpszCmdLine, int nCmdShow)
{
int width = 512;
int height = 512;
int width = 1024;
int height = 1024;
if (CreateEngine(width, height))