-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector2.cpp
More file actions
82 lines (69 loc) · 2.05 KB
/
Copy pathVector2.cpp
File metadata and controls
82 lines (69 loc) · 2.05 KB
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
//Vector2.cpp
#include "Vector2.h"
#include <math.h>
namespace sdlUtility {
/// operator= implementation.
/** Assigns the x, y values to the specified Vector2. */
void Vector2::operator=(Vector2 Vector) {
x = Vector.X();
y = Vector.Y();
}
/// operator+= implementation.
/** Increments the x, y values by the specified Vector2. */
void Vector2::operator+=(Vector2 Vector) {
x += Vector.X();
y += Vector.Y();
}
/// operator-= implementation.
/** Decrements the x, y values by the specified Vector2. */
void Vector2::operator-=(Vector2 Vector) {
x -= Vector.X();
y -= Vector.Y();
}
/// operator== implementation.
/** Compares the x, y values to the specified Vector2. */
bool Vector2::operator==(Vector2 Vector) {
return (x == Vector.X())&&(y == Vector.Y());
}
/// operator! implementation.
/** Returns true if (x, y) = (0, 0). */
bool Vector2::operator!(void) {
return !(x && y);
}
/// operator!= implementation.
/** Compares the x, y values to the specified Vector2. */
bool Vector2::operator!=(Vector2 Vector) {
return !(x == Vector.X() && y == Vector.Y());
}
/// Returns the angle of the vector.
/** Calculated in relation to the origin point (0, 0). */
float Vector2::Angle() {
return atan2(y, x);
}
/// Returns the magnitude of the vector.
float Vector2::Length() {
return sqrt(pow(x, 2)+pow(y, 2));
}
/// Returns the squared magnitude of the vector.
float Vector2::Length2() {
return pow(x, 2)+pow(y, 2);
}
/// Basic constructor.
/** @param X, Y Used to initialise the x, y of the vector. */
Vector2::Vector2(float X, float Y) {
x = X;
y = Y;
}
/// Returns the X component of the vector.
float Vector2::X() {
return x;
}
/// Returns the Y component of the vector.
float Vector2::Y() {
return y;
}
/// Basic destructor.
Vector2::~Vector2() {
x = y = 0;
}
}