-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector2.h
More file actions
52 lines (43 loc) · 730 Bytes
/
Vector2.h
File metadata and controls
52 lines (43 loc) · 730 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
#pragma once
#include <math.h>
class Vector2
{
public:
Vector2();
Vector2(float xx, float yy);
Vector2& operator += (const Vector2& v );
float Length();
Vector2 Normalize();
float x;
float y;
};
inline Vector2::Vector2() : x(0), y(0)
{
}
inline Vector2::Vector2(float xx, float yy)
{
x = xx;
y = yy;
}
inline Vector2& Vector2::operator += (const Vector2& v)
{
x += v.x;
y += v.y;
return *this;
}
inline Vector2 operator * (const Vector2& v, const float s)
{
return Vector2(v.x * s, v.y * s);
}
inline float Vector2::Length()
{
return sqrtf(x*x + y*y);
}
inline Vector2 Vector2::Normalize()
{
Vector2 t;
float len = Length();
t.x = x / len;
t.y = y / len;
return t;
}