From aa5790807ad039c1c9db01f7a96f5f643dd56b45 Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Tue, 10 Nov 2020 01:27:33 +0300 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=82?= =?UTF-8?q?=D1=80=D0=B5=D1=82=D1=8C=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=205=D0=B9=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D1=87=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task05_3D/Guschin/MyForm.h | 46 ++++++++++++++++++++++--------------------- task05_3D/Guschin/Transform.h | 18 +++++++++++++++++ 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/task05_3D/Guschin/MyForm.h b/task05_3D/Guschin/MyForm.h index 7e76f41..369f2e8 100644 --- a/task05_3D/Guschin/MyForm.h +++ b/task05_3D/Guschin/MyForm.h @@ -10,11 +10,11 @@ namespace Guschin { using namespace System::Drawing; using namespace std; - vec2 Vc; - vec2 V; - vec2 Vc_work, V_work; - mat3 T; - mat3 initT; + vec3 Vc; + vec3 V; + vec3 Vc_work, V_work; + mat4 T; + mat4 initT; public ref class MyForm : public System::Windows::Forms::Form { @@ -75,16 +75,16 @@ namespace Guschin { } System::Void worldRectCalc() { - Vc_work = normalize(T * vec3(Vc, 1.f)); - V_work = mat2(T) * V; + Vc_work = normalize(T * vec4(Vc, 1.f)); + V_work = mat3(T) * V; } - float f(float x) + float f(float x, float z) { - return tan(x); + return x * sin(sqrtf(x * x + z * z)); } - bool f_exists(float x, float delta) + bool f_exists(float x, float z, float delta) { - return fabs(2.f * acos(cos(x)) - Math::PI) > delta; + return true; } private: System::Void MyForm_Resize(System::Object^ sender, System::EventArgs^ e) { @@ -103,15 +103,16 @@ namespace Guschin { float deltaX = V_work.x / Wx; bool hasStart, hasEnd; + float z = Vc_work.z; vec2 start, end; float x, y; start.x = Wcx; x = Vc_work.x; - hasStart = f_exists(x, deltaX); + hasStart = f_exists(x, z, deltaX); if (hasStart) { - y = f(x); + y = f(x, z); start.y = Wcy - (y - Vc_work.y) / V_work.y * Wy; } @@ -121,10 +122,10 @@ namespace Guschin { { end.x = start.x + 1.f; x += deltaX; - hasEnd = f_exists(x, deltaX); + hasEnd = f_exists(x, z, deltaX); if (hasEnd) { - y = f(x); + y = f(x, z); deltaY = (y - Vc_work.y) / V_work.y; end.y = Wcy - deltaY * Wy; } @@ -155,10 +156,10 @@ namespace Guschin { } private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) { - initT = mat3(1.f); + initT = mat4(1.f); T = initT; - Vc = vec2(-2.f, -2.f); - V = vec2(4.f, 4.f); + Vc = vec3(-2.f, -2.f, -2.f); + V = vec3(4.f, 4.f, 4.f); rectCalc(); worldRectCalc(); } @@ -166,18 +167,19 @@ namespace Guschin { System::Void MyForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) { float centerX = Vc_work.x + V_work.x / 2; float centerY = Vc_work.y + V_work.y / 2; + float centerZ = Vc_work.z + V_work.z / 2; switch (e->KeyCode) { case Keys::Escape: T = initT; break; case Keys::A: - T = translate(-V_work.x / Wx, 0.f) * T; + T = translate(-V_work.x / Wx, 0.f, 0.f) * T; break; case Keys::Z: - T = translate(-centerX, -centerY) * T; - T = scale(1.1) * T; - T = translate(centerX, centerY) * T; + T = translate(-centerX, -centerY, -centerZ) * T; + T = scale(1.1, 1.1, 1.1) * T; + T = translate(centerX, centerY, centerZ) * T; break; default: break; diff --git a/task05_3D/Guschin/Transform.h b/task05_3D/Guschin/Transform.h index d606647..474ffb4 100644 --- a/task05_3D/Guschin/Transform.h +++ b/task05_3D/Guschin/Transform.h @@ -8,6 +8,15 @@ mat3 translate(float Tx, float Ty) return *res; } +mat4 translate(float Tx, float Ty, float Tz) +{ + mat4* res = new mat4(1.f); + (*res)[0][3] = Tx; + (*res)[1][3] = Ty; + (*res)[2][3] = Tz; + return *res; +} + mat3 scale(float Sx, float Sy) { mat3* res = new mat3(1.f); @@ -16,6 +25,15 @@ mat3 scale(float Sx, float Sy) return *res; } +mat4 scale(float Sx, float Sy, float Sz) +{ + mat4* res = new mat4(1.f); + (*res)[0][0] = Sx; + (*res)[1][1] = Sy; + (*res)[2][2] = Sy; + return *res; +} + mat3 scale(float S) { return scale(S, S); -- cgit v1.2.3