-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.cpp
More file actions
78 lines (66 loc) · 865 Bytes
/
Vector.cpp
File metadata and controls
78 lines (66 loc) · 865 Bytes
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
#include "stdafx.h"
#include "Vector.h"
#include <math.h>
Vector::Vector()
{
x = 0;
y = 0;
}
Vector::Vector(float xi, float yi)
{
x = xi;
y = yi;
}
float Vector::Magnitude(void)
{
return (float)sqrt(x*x + y*y);
}
void Vector::Normalize(void)
{
const float tol = 0.0001f;
float m = (float)sqrt(x*x + y*y);
if (m <= tol)
m = 1;
x /= m;
y /= m;
if (fabs(x) < tol)
x = 0.0f;
if (fabs(y) < tol)
y = 0.0f;
}
void Vector::Reverse(void)
{
x = -x;
y = -y;
}
Vector& Vector::operator+=(Vector u)
{
x += u.x;
y += u.y;
return *this;
}
Vector& Vector::operator-=(Vector u)
{
x -= u.x;
y -= u.y;
return *this;
}
Vector& Vector::operator*=(float s)
{
x *= s;
y *= s;
return *this;
}
Vector& Vector::operator/=(float s)
{
x /= s;
y /= s;
return *this;
}
Vector Vector::operator-(void)
{
return Vector(-x, -y);
}
Vector::~Vector()
{
}