-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector3D.cpp
172 lines (143 loc) · 3.4 KB
/
Vector3D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#pragma once
#include "Vector3D.h"
#include "Utils.h"
#include "Matrix.h"
using namespace Bladestick::Drawing;
//Óãîë ìåæäó âåêòîðàìè â ðàäèàíàõ
double Vector3D::getAngleBetween(Vector3D ^ v1, Vector3D ^ v2)
{
return System::Math::Acos(v1->scalarProduct(v2) / (v1->getMagnitude() * v2->getMagnitude()));
}
Vector3D::Vector3D(double x, double y, double z, double w, double mx, double my, double mz, double mw)
{
this->x = x;
this->y = y;
this->z = z;
this->w = w;
this->mx = mx;
this->my = my;
this->mz = mz;
this->mw = mw;
}
Vector3D::Vector3D(double x, double y, double z, double w) : Vector3D::Vector3D(x, y, z, w, x, y, z, w) {}
Vector3D::Vector3D(double x, double y, double z) : Vector3D::Vector3D(x, y, z, 1) {}
Vector3D::Vector3D(const Vector3D % vector) :
Vector3D::Vector3D(vector.x, vector.y, vector.z, vector.w, vector.mx, vector.my, vector.mz, vector.mw) {}
Vector3D::Vector3D() : Vector3D::Vector3D(0, 0, 0) {}
#pragma region Operators
Vector3D Vector3D::operator=(Vector3D vector)
{
this->x = x;
this->y = y;
this->z = z;
this->w = w;
this->mx = mx;
this->my = my;
this->mz = mz;
this->mw = mw;
return *this;
}
Vector3D ^ Vector3D::operator=(Vector3D ^ vector)
{
this->x = x;
this->y = y;
this->z = z;
this->w = w;
this->mx = mx;
this->my = my;
this->mz = mz;
this->mw = mw;
return this;
}
Vector3D ^ Vector3D::add(double x, double y, double z)
{
return gcnew Vector3D(this->x + x, this->y + y, this->z + z);
}
Vector3D ^ Vector3D::operator+(double x)
{
return add(x, x, x);
}
Vector3D ^ Vector3D::operator+(Vector3D ^ vector)
{
return add(vector->x, vector->y, vector->z);
}
Vector3D ^ Vector3D::subtract(double x, double y, double z)
{
return add(-x, -y, -z);
}
Vector3D ^ Vector3D::operator-(double x)
{
return operator+(-x);
}
Vector3D ^ Vector3D::operator-(Vector3D ^ vector)
{
return subtract(vector->x, vector->y, vector->z);
}
Vector3D ^ Vector3D::operator-()
{
return gcnew Vector3D(-this->x, -this->y, -this->z);
}
#pragma endregion
Vector3D ^ Vector3D::scale(double x, double y, double z)
{
return gcnew Vector3D(this->x * x, this->y * y, this->z * z);
}
Vector3D ^ Vector3D::scale(double x)
{
return scale(x, x, x);
}
double Vector3D::getMagnitude()
{
return System::Math::Sqrt(x * x + y * y + z * z);
}
Vector3D ^ Vector3D::normalized()
{
double m = getMagnitude();
return gcnew Vector3D(x / m, y / m, z / m);
}
double Vector3D::scalarProduct(double x, double y, double z)
{
return this->x * x + this->y * y + this->z * z;
}
double Vector3D::scalarProduct(Vector3D ^ v)
{
return scalarProduct(v->x, v->y, v->z);
}
Vector3D ^ Vector3D::vectorProduct(double x, double y, double z)
{
return gcnew Vector3D(this->y * z - this->z * y, this->z * x - this->x * z, this->x * y - this->y * x);
}
Vector3D ^ Vector3D::vectorProduct(Vector3D ^ v)
{
return vectorProduct(v->x, v->y, v->z);
}
Vector3D ^ Vector3D::clone()
{
return gcnew Vector3D(x, y, z, w, mx, my, mz, mw);
}
void Vector3D::modifiedToMain()
{
x = mx;
y = my;
z = mz;
w = mw;
}
void Vector3D::swapModifiedAndMain()
{
double buf = x;
x = mx;
mx = buf;
buf = y;
y = my;
my = buf;
buf = z;
z = mz;
mz = buf;
buf = w;
w = mw;
mw = buf;
}
bool Vector3D::Equals(Vector3D ^ v)
{
return this->x == v->x && this->y == v->y && this->z == v->z;
}