summaryrefslogtreecommitdiff
path: root/task06/Guschin
diff options
context:
space:
mode:
authorAndrew Guschin <saintruler@gmail.com>2020-11-28 19:13:38 +0400
committerAndrew Guschin <saintruler@gmail.com>2020-11-28 19:13:38 +0400
commit9ac6d0e563ab6409fcb2a42d8ccff0dcf3008904 (patch)
tree5a8ecd709dbc7e56d1abf3e51b6af65544d91d84 /task06/Guschin
parent7be113983ed5e8a499ece4bcdf8463c33c9a7b1b (diff)
Добавил заготовку 6 задачи
Diffstat (limited to 'task06/Guschin')
-rw-r--r--task06/Guschin/Clip.h54
-rw-r--r--task06/Guschin/Figure.h27
-rw-r--r--task06/Guschin/Guschin.vcxproj144
-rw-r--r--task06/Guschin/Guschin.vcxproj.filters44
-rw-r--r--task06/Guschin/Guschin.vcxproj.user4
-rw-r--r--task06/Guschin/Matrix.h98
-rw-r--r--task06/Guschin/MyForm.cpp20
-rw-r--r--task06/Guschin/MyForm.h346
-rw-r--r--task06/Guschin/MyForm.resx123
-rw-r--r--task06/Guschin/Transform.h45
10 files changed, 905 insertions, 0 deletions
diff --git a/task06/Guschin/Clip.h b/task06/Guschin/Clip.h
new file mode 100644
index 0000000..10a613a
--- /dev/null
+++ b/task06/Guschin/Clip.h
@@ -0,0 +1,54 @@
+#pragma once
+#include "Matrix.h"
+#include <algorithm>
+
+unsigned int codeKS(vec2 P, float minX, float minY, float maxX, float maxY) {
+ unsigned int code = 0;
+
+ if (P.x < minX) {
+ code += 1;
+ }
+ else if (P.x > maxX) {
+ code += 2;
+ }
+ if (P.y < minY) {
+ code += 4;
+ }
+ else if (P.y > maxY) {
+ code += 8;
+ }
+
+ return code;
+}
+
+bool clip(vec2 & A, vec2 & B, float minX, float minY, float maxX, float maxY) {
+ unsigned int codeA = codeKS(A, minX, minY, maxX, maxY);
+ unsigned int codeB = codeKS(B, minX, minY, maxX, maxY);
+ while (codeA | codeB) {
+ if (codeA & codeB) {
+ return false;
+ }
+ if (codeA == 0) {
+ std::swap(A, B);
+ std::swap(codeA, codeB);
+ }
+ if (codeA & 1) {
+ A.y = A.y + (B.y - A.y) * (minX - A.x) / (B.x - A.x);
+ A.x = minX;
+ }
+ else if (codeA & 2) {
+ A.y = A.y + (B.y - A.y) * (maxX - A.x) / (B.x - A.x);
+ A.x = maxX;
+ }
+ else if (codeA & 4) {
+ A.x = A.x + (B.x - A.x) * (minY - A.y) / (B.y - A.y);
+ A.y = minY;
+ }
+ else {
+ A.x = A.x + (B.x - A.x) * (maxY - A.y) / (B.y - A.y);
+ A.y = maxY;
+ }
+ codeA = codeKS(A, minX, minY, maxX, maxY);
+ }
+ return true;
+}
diff --git a/task06/Guschin/Figure.h b/task06/Guschin/Figure.h
new file mode 100644
index 0000000..cf2a63e
--- /dev/null
+++ b/task06/Guschin/Figure.h
@@ -0,0 +1,27 @@
+#pragma once
+#include "Matrix.h"
+#include <vector>
+
+class path
+{
+public:
+ std::vector<vec2> vertices;
+ vec3 color;
+ float thickness;
+
+ path(std::vector<vec2> verts, vec3 col, float thickn)
+ {
+ vertices = verts;
+ color = col;
+ thickness = thickn;
+ }
+};
+
+class model {
+public:
+ std::vector<path> figure;
+ mat3 modelM;
+ model(std::vector<path> fig, mat3 mat) {
+ figure = fig; modelM = mat;
+ }
+}; \ No newline at end of file
diff --git a/task06/Guschin/Guschin.vcxproj b/task06/Guschin/Guschin.vcxproj
new file mode 100644
index 0000000..bbc67b9
--- /dev/null
+++ b/task06/Guschin/Guschin.vcxproj
@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>16.0</VCProjectVersion>
+ <ProjectGuid>{7FD831C6-82A0-4285-8C15-41D557E54312}</ProjectGuid>
+ <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+ <Keyword>ManagedCProj</Keyword>
+ <RootNamespace>Guschin</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <CLRSupport>true</CLRSupport>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <CLRSupport>true</CLRSupport>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <CLRSupport>true</CLRSupport>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <CLRSupport>true</CLRSupport>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup />
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <AdditionalDependencies />
+ <SubSystem>Windows</SubSystem>
+ <EntryPointSymbol>Main</EntryPointSymbol>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <AdditionalDependencies />
+ <SubSystem>Windows</SubSystem>
+ <EntryPointSymbol>Main</EntryPointSymbol>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <AdditionalDependencies />
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <AdditionalDependencies />
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="Clip.h" />
+ <ClInclude Include="Figure.h" />
+ <ClInclude Include="Matrix.h" />
+ <ClInclude Include="MyForm.h">
+ <FileType>CppForm</FileType>
+ </ClInclude>
+ <ClInclude Include="Transform.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Windows.Forms" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="MyForm.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="MyForm.resx">
+ <DependentUpon>MyForm.h</DependentUpon>
+ </EmbeddedResource>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/task06/Guschin/Guschin.vcxproj.filters b/task06/Guschin/Guschin.vcxproj.filters
new file mode 100644
index 0000000..a2f1835
--- /dev/null
+++ b/task06/Guschin/Guschin.vcxproj.filters
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Исходные файлы">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="Файлы заголовков">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
+ </Filter>
+ <Filter Include="Файлы ресурсов">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="MyForm.h">
+ <Filter>Файлы заголовков</Filter>
+ </ClInclude>
+ <ClInclude Include="Matrix.h">
+ <Filter>Файлы заголовков</Filter>
+ </ClInclude>
+ <ClInclude Include="Transform.h">
+ <Filter>Файлы заголовков</Filter>
+ </ClInclude>
+ <ClInclude Include="Figure.h">
+ <Filter>Файлы заголовков</Filter>
+ </ClInclude>
+ <ClInclude Include="Clip.h">
+ <Filter>Файлы заголовков</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="MyForm.cpp">
+ <Filter>Исходные файлы</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="MyForm.resx">
+ <Filter>Файлы ресурсов</Filter>
+ </EmbeddedResource>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/task06/Guschin/Guschin.vcxproj.user b/task06/Guschin/Guschin.vcxproj.user
new file mode 100644
index 0000000..824d5a9
--- /dev/null
+++ b/task06/Guschin/Guschin.vcxproj.user
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup />
+</Project> \ No newline at end of file
diff --git a/task06/Guschin/Matrix.h b/task06/Guschin/Matrix.h
new file mode 100644
index 0000000..3aa0bbf
--- /dev/null
+++ b/task06/Guschin/Matrix.h
@@ -0,0 +1,98 @@
+#pragma once
+
+class vec2
+{
+public:
+ float x, y;
+ vec2() {}
+ vec2(float a, float b) : x(a), y(b) {}
+};
+
+class vec3
+{
+public:
+ float x, y, z;
+ vec3() {}
+ vec3(float a, float b, float c) : x(a), y(b), z(c) {}
+ vec3(vec2 v, float c) : vec3(v.x, v.y, c) {}
+
+ vec3& operator*=(const vec3& v)
+ {
+ x *= v.x;
+ y *= v.y;
+ z *= v.z;
+ return *this;
+ }
+
+ const vec3 operator*(const vec3& v)
+ {
+ return vec3(*this) *= v;
+ }
+
+ float& operator[](int i)
+ {
+ return ((float*)this)[i];
+ }
+};
+
+float dot(vec3 v1, vec3 v2)
+{
+ vec3 tmp = v1 * v2;
+ return tmp.x + tmp.y + tmp.z;
+}
+
+class mat3
+{
+public:
+ vec3 row1, row2, row3;
+ mat3() {}
+ mat3(vec3 r1, vec3 r2, vec3 r3) : row1(r1), row2(r2), row3(r3) {}
+ mat3(float a)
+ {
+ row1 = vec3(a, 0.f, 0.f);
+ row2 = vec3(0.f, a, 0.f);
+ row3 = vec3(0.f, 0.f, a);
+ }
+
+ vec3& operator[](int i)
+ {
+ return ((vec3*)this)[i];
+ }
+
+ mat3 transpose()
+ {
+ mat3 tmp(*this);
+ for (int i = 0; i < 3; ++i)
+ for (int j = 0; j < 3; ++j)
+ (*this)[i][j] = tmp[j][i];
+ return *this;
+ }
+
+ const vec3 operator*(const vec3& v)
+ {
+ vec3* res = new(vec3);
+ for (int i = 0; i < 3; ++i)
+ (*res)[i] = dot((*this)[i], v);
+ return *res;
+ }
+
+ mat3& operator*=(const mat3& m)
+ {
+ mat3 A(*this), B(m);
+ B.transpose();
+ for (int i = 0; i < 3; ++i)
+ (*this)[i] = A * B[i];
+ return (*this).transpose();
+ }
+
+ const mat3 operator*(const mat3& m)
+ {
+ return mat3(*this) *= m;
+ }
+};
+
+vec2 normalize(vec3 v)
+{
+ return vec2(v.x / v.z, v.y / v.z);
+}
+
diff --git a/task06/Guschin/MyForm.cpp b/task06/Guschin/MyForm.cpp
new file mode 100644
index 0000000..a7e65d4
--- /dev/null
+++ b/task06/Guschin/MyForm.cpp
@@ -0,0 +1,20 @@
+#include "Matrix.h"
+#include <math.h>
+#include "Transform.h"
+#include "Figure.h"
+#include "Clip.h"
+#include <vector>
+#include <fstream>
+#include <sstream>
+#include "MyForm.h"
+
+using namespace System;
+using namespace System::Windows::Forms;
+
+[STAThreadAttribute]
+void Main(array<String^> ^ args) {
+ Application::EnableVisualStyles();
+ Application::SetCompatibleTextRenderingDefault(false);
+ Guschin::MyForm form;
+ Application::Run(% form);
+} \ No newline at end of file
diff --git a/task06/Guschin/MyForm.h b/task06/Guschin/MyForm.h
new file mode 100644
index 0000000..e63953e
--- /dev/null
+++ b/task06/Guschin/MyForm.h
@@ -0,0 +1,346 @@
+#pragma once
+
+namespace Guschin {
+
+ using namespace System;
+ using namespace System::ComponentModel;
+ using namespace System::Collections;
+ using namespace System::Windows::Forms;
+ using namespace System::Data;
+ using namespace System::Drawing;
+ using namespace std;
+
+ float Vx;
+ float Vy;
+ float aspectFig;
+ vector<model> models;
+ mat3 T;
+ mat3 initT;
+
+ public ref class MyForm : public System::Windows::Forms::Form
+ {
+ public:
+ MyForm(void)
+ {
+ InitializeComponent();
+ }
+
+ protected:
+ ~MyForm()
+ {
+ if (components)
+ {
+ delete components;
+ }
+ }
+
+ private:
+ System::Windows::Forms::OpenFileDialog^ openFileDialog;
+ System::Windows::Forms::Button^ btnOpen;
+ System::ComponentModel::Container ^components;
+
+#pragma region Windows Form Designer generated code
+ void InitializeComponent(void)
+ {
+ this->openFileDialog = (gcnew System::Windows::Forms::OpenFileDialog());
+ this->btnOpen = (gcnew System::Windows::Forms::Button());
+ this->SuspendLayout();
+ //
+ // openFileDialog
+ //
+ this->openFileDialog->DefaultExt = L"txt";
+ this->openFileDialog->Filter = L"Текстовые файлы (*.txt)|*.txt|Все файлы (*.*)|*.*";
+ this->openFileDialog->Title = L"Открыть файл";
+ //
+ // btnOpen
+ //
+ this->btnOpen->Location = System::Drawing::Point(16, 15);
+ this->btnOpen->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
+ this->btnOpen->Name = L"btnOpen";
+ this->btnOpen->Size = System::Drawing::Size(151, 48);
+ this->btnOpen->TabIndex = 0;
+ this->btnOpen->Text = L"Открыть";
+ this->btnOpen->UseVisualStyleBackColor = true;
+ this->btnOpen->Click += gcnew System::EventHandler(this, &MyForm::btnOpen_Click);
+ //
+ // MyForm
+ //
+ this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
+ this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
+ this->ClientSize = System::Drawing::Size(737, 686);
+ this->Controls->Add(this->btnOpen);
+ this->DoubleBuffered = true;
+ this->KeyPreview = true;
+ this->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
+ this->Name = L"MyForm";
+ this->Text = L"MyForm";
+ this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
+ this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::MyForm_Paint);
+ this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &MyForm::MyForm_KeyDown);
+ this->Resize += gcnew System::EventHandler(this, &MyForm::MyForm_Resize);
+ this->ResumeLayout(false);
+
+ }
+#pragma endregion
+ private:
+ float left = 30, right = 100, top = 20, bottom = 50;
+ float minX = left, maxX;
+ float minY = top, maxY;
+ float Wcx = left, Wcy;
+ float Wx, Wy;
+
+ private:
+ System::Void rectCalc() {
+ maxX = ClientRectangle.Width - right;
+ maxY = ClientRectangle.Height - bottom;
+ Wcy = maxY;
+ Wx = maxX - left;
+ Wy = maxY - top;
+ }
+ private:
+ System::Void MyForm_Resize(System::Object^ sender, System::EventArgs^ e) {
+ rectCalc();
+ Refresh();
+ }
+ private:
+ System::Void MyForm_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
+ Graphics^ g = e->Graphics;
+ g->Clear(Color::Aquamarine);
+
+ Pen^ rectPen = gcnew Pen(Color::Black, 2);
+ g->DrawRectangle(rectPen, left, top, Wx, Wy);
+ for (int k = 0; k < models.size(); k++) {
+ vector<path> figure = models[k].figure;
+ mat3 TM = T * models[k].modelM;
+ for (int i = 0; i < figure.size(); i++) {
+ path lines = figure[i];
+ Pen^ pen = gcnew Pen(Color::FromArgb(lines.color.x, lines.color.y, lines.color.z));
+ pen->Width = lines.thickness;
+
+ vec2 start = normalize(TM * vec3(lines.vertices[0], 1.0));
+ for (int j = 1; j < lines.vertices.size(); j++) {
+ vec2 end = normalize(TM * vec3(lines.vertices[j], 1.0));
+ vec2 tmpEnd = end;
+ if (clip(start, end, minX, minY, maxX, maxY)) {
+ g->DrawLine(pen, start.x, start.y, end.x, end.y);
+ }
+ start = tmpEnd;
+ }
+ }
+ }
+ }
+ private:
+ System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
+ rectCalc();
+ }
+ private:
+ System::Void MyForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
+ float Wcx = ClientRectangle.Width / 2.f;
+ float Wcy = ClientRectangle.Height / 2.f;
+
+ switch (e->KeyCode) {
+ case Keys::Escape:
+ T = initT;
+ break;
+ case Keys::Q :
+ T = translate(-Wcx, -Wcy) * T;
+ T = rotate(0.01f) * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+ case Keys::E :
+ T = translate(-Wcx, -Wcy) * T;
+ T = rotate(-0.01f) * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+
+ case Keys::W :
+ T = translate(0.f, -1.f) * T;
+ break;
+ case Keys::S :
+ T = translate(0.f, 1.f) * T;
+ break;
+ case Keys::A :
+ T = translate(-1.f, 0.f) * T;
+ break;
+ case Keys::D :
+ T = translate(1.f, 0.f) * T;
+ break;
+
+ case Keys::R:
+ T = translate(-Wcx, -Wcy) * T;
+ T = rotate(0.05f) * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+ case Keys::Y:
+ T = translate(-Wcx, -Wcy) * T;
+ T = rotate(-0.05f) * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+
+ case Keys::T:
+ T = translate(0.f, -10.f) * T;
+ break;
+ case Keys::G:
+ T = translate(0.f, 10.f) * T;
+ break;
+ case Keys::F:
+ T = translate(-10.f, 0.f) * T;
+ break;
+ case Keys::H:
+ T = translate(10.f, 0.f) * T;
+ break;
+
+ case Keys::Z:
+ T = translate(-Wcx, -Wcy) * T;
+ T = scale(1.1f) * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+ case Keys::X:
+ T = translate(-Wcx, -Wcy) * T;
+ T = scale(1 / 1.1f) * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+
+ case Keys::U:
+ T = translate(-Wcx, -Wcy) * T;
+ T = mirrorX() * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+ case Keys::J:
+ T = translate(-Wcx, -Wcy) * T;
+ T = mirrorY() * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+
+ case Keys::I:
+ T = translate(-Wcx, -Wcy) * T;
+ T = scale(1.1f, 1.f) * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+ case Keys::K:
+ T = translate(-Wcx, -Wcy) * T;
+ T = scale(1 / 1.1f, 1.f) * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+
+ case Keys::O:
+ T = translate(-Wcx, -Wcy) * T;
+ T = scale(1.f, 1.1f) * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+ case Keys::L:
+ T = translate(-Wcx, -Wcy) * T;
+ T = scale(1.f, 1 / 1.1f) * T;
+ T = translate(Wcx, Wcy) * T;
+ break;
+
+ default:
+ break;
+ }
+ Refresh();
+ }
+ private:
+ System::Void btnOpen_Click(System::Object^ sender, System::EventArgs^ e) {
+ if (openFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK) {
+ wchar_t fileName[1024];
+ for (int i = 0; i < openFileDialog->FileName->Length; i++)
+ fileName[i] = openFileDialog->FileName[i];
+ fileName[openFileDialog->FileName->Length] = '\0';
+
+ ifstream in;
+ in.open(fileName);
+ if (in.is_open()) {
+ models.clear();
+
+ mat3 M = mat3(1.f);
+ mat3 initM;
+ vector<mat3> transforms;
+ vector<path> figure;
+
+ float thickness = 2;
+ float r, g, b;
+ r = g = b = 0;
+ string cmd;
+ string str;
+ getline(in, str);
+ while (in) {
+ if ((str.find_first_not_of(" \t\r\n") != string::npos) && (str[0] != '#')) {
+ stringstream s(str);
+ s >> cmd;
+ if (cmd == "frame") {
+ s >> Vx >> Vy;
+ aspectFig = Vx / Vy;
+
+ float aspectRect = Wx / Wy;
+ mat3 T1 = translate(-Vx / 2, -Vy / 2);
+ float S = aspectFig < aspectRect ? Wy / Vy : Wx / Vx;
+ mat3 S1 = scale(S, -S);
+ mat3 T2 = translate(Wx / 2 + Wcx, Wcy - Wy / 2);
+ initT = T2 * (S1 * T1);
+
+ T = initT;
+ }
+ else if (cmd == "color") {
+ s >> r >> g >> b;
+ }
+ else if (cmd == "thickness") {
+ s >> thickness;
+ }
+ else if (cmd == "path") {
+ vector<vec2> vertices;
+ int N;
+ s >> N;
+ string str1;
+ while (N > 0) {
+ getline(in, str1);
+ if ((str1.find_first_not_of(" \t\r\n") != string::npos) && (str1[0] != '#')) {
+ float x, y;
+ stringstream s1(str1);
+ s1 >> x >> y;
+ vertices.push_back(vec2(x, y));
+ N--;
+ }
+ }
+ figure.push_back(path(vertices, vec3(r, g, b), thickness));
+ }
+ else if (cmd == "model") {
+ float mVcx, mVcy, mVx, mVy;
+ s >> mVcx >> mVcy >> mVx >> mVy;
+ float S = mVx / mVy < 1 ? 2.f / mVy : 2.f / mVx;
+ initM = scale(S) * translate(-mVcx, -mVcy);
+ figure.clear();
+ }
+ else if (cmd == "figure") {
+ models.push_back(model(figure, M * initM));
+ }
+ else if (cmd == "translate") {
+ float Tx, Ty;
+ s >> Tx >> Ty;
+ M = translate(Tx, Ty) * M;
+ }
+ else if (cmd == "scale") {
+ float S;
+ s >> S;
+ M = scale(S) * M;
+ }
+ else if (cmd == "rotate") {
+ float theta;
+ s >> theta;
+ M = rotate(-theta / 180.f * Math::PI) * M;
+ }
+ else if (cmd == "pushTransform") {
+ transforms.push_back(M);
+ }
+ else if (cmd == "popTransform") {
+ M = transforms.back();
+ transforms.pop_back();
+ }
+ }
+ getline(in, str);
+ }
+ Refresh();
+ }
+ }
+ }
+ };
+}
diff --git a/task06/Guschin/MyForm.resx b/task06/Guschin/MyForm.resx
new file mode 100644
index 0000000..f003e42
--- /dev/null
+++ b/task06/Guschin/MyForm.resx
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <value>17, 17</value>
+ </metadata>
+</root> \ No newline at end of file
diff --git a/task06/Guschin/Transform.h b/task06/Guschin/Transform.h
new file mode 100644
index 0000000..d606647
--- /dev/null
+++ b/task06/Guschin/Transform.h
@@ -0,0 +1,45 @@
+#pragma once
+
+mat3 translate(float Tx, float Ty)
+{
+ mat3* res = new mat3(1.f);
+ (*res)[0][2] = Tx;
+ (*res)[1][2] = Ty;
+ return *res;
+}
+
+mat3 scale(float Sx, float Sy)
+{
+ mat3* res = new mat3(1.f);
+ (*res)[0][0] = Sx;
+ (*res)[1][1] = Sy;
+ return *res;
+}
+
+mat3 scale(float S)
+{
+ return scale(S, S);
+}
+
+mat3 rotate(float theta)
+{
+ mat3* res = new mat3(1.f);
+ (*res)[0][0] = (*res)[1][1] = (float)cos(theta);
+ (*res)[0][1] = (float)sin(theta);
+ (*res)[1][0] = -(*res)[0][1];
+ return *res;
+}
+
+mat3 mirrorX()
+{
+ mat3* res = new mat3(1.f);
+ (*res)[1][1] = -1;
+ return *res;
+}
+
+mat3 mirrorY()
+{
+ mat3* res = new mat3(1.f);
+ (*res)[0][0] = -1;
+ return *res;
+} \ No newline at end of file