summaryrefslogtreecommitdiff
path: root/task05_3D
diff options
context:
space:
mode:
Diffstat (limited to 'task05_3D')
-rw-r--r--task05_3D/Guschin/MyForm.h46
-rw-r--r--task05_3D/Guschin/Transform.h18
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);