-
Notifications
You must be signed in to change notification settings - Fork 9
/
Vector2D.h
43 lines (32 loc) · 1.01 KB
/
Vector2D.h
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
#pragma once
#ifndef __Vector2D__
#define __Vector2D__
class Vector2D
{
float m_x;
float m_y;
public:
Vector2D () {} //default constructor
Vector2D(float x, float y): m_x(x), m_y(y) { }
float getX() { return m_x; }
float getY() { return m_y; }
void setX(float x) { m_x = x; }
void setY(float y) { m_y = y; }
//finding the length of the vector
float length();
//addition of two Vectors using + or +=
Vector2D operator + (const Vector2D& v2) const;
friend Vector2D& operator += (Vector2D& v1, const Vector2D& v2);
//multiplication of a vector with a scalar number using * or *=
Vector2D operator * (float scalar);
Vector2D& operator *= (float scalar);
//subtraction of two vector using - or -=
Vector2D operator - (const Vector2D& v2) const;
friend Vector2D& operator -= (Vector2D& v1, const Vector2D& v2);
//division of a vector by a scalar number using / or /=
Vector2D operator / (float scalar);
Vector2D& operator /= (float scalar);
//normalizing a vector
void normalize();
};
#endif //(__Vector2D__)