-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector2D.cpp
More file actions
42 lines (31 loc) · 740 Bytes
/
Vector2D.cpp
File metadata and controls
42 lines (31 loc) · 740 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
#include "Vector2D.h"
Vector2D normalize(Vector2D& v){
float d=v.Length();
if(d==0){
d=0.1f;
}
v.x/=d;
v.y/=d;
return v;
}
Vector2D operator+(const Vector2D& v1,const Vector2D& v2){
return Vector2D(v1.x+v2.x,v1.y+v2.y);
}
Vector2D operator-(const Vector2D& v1,const Vector2D& v2){
return Vector2D(v1.x-v2.x,v1.y-v2.y);
}
Vector2D operator-(const Vector2D& v){
return Vector2D(-v.x,-v.y);
}
Vector2D operator*(const Vector2D& v,float l){
return Vector2D(v.x*l,v.y*l);
}
Vector2D operator*(float l, const Vector2D& v){
return Vector2D(v.x*l,v.y*l);
}
Vector2D operator/(const Vector2D& v,float l){
return Vector2D(v.x/l,v.y/l);
}
float operator^(const Vector2D& v1,const Vector2D& v2){
return v1.x*v2.x+v1.y*v2.y;
}