-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector2d.h
116 lines (77 loc) · 3.04 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef VECTOR_H
#define VECTOR_H
#include "stdafx.h"
#include <math.h>
#define PI 3.14159265
#define DEG_TO_RAD PI / 180.0f
class Vector2d {
public:
float x;
float y;
Vector2d();
Vector2d(float x, float y);
Vector2d(int x, int y);
~Vector2d();
void add( Vector2d vec );
void add( std::shared_ptr< Vector2d > vec );
void addX( float x );
void addY( float y );
float getX();
float getY();
float getX() const;
float getY() const;
void setX(float x);
void setX(int x);
void setY(float y);
void setY(int y);
float magnitude();
float lengthSqr();
void normalise();
// perproduct
// right hand normal of vector
std::shared_ptr< Vector2d > rightHNormal();
// left hand normal of vector
std::shared_ptr< Vector2d > leftHNormal();
Vector2d operator+(Vector2d& r);
Vector2d operator-(Vector2d& r);
Vector2d& operator+=(Vector2d& r);
Vector2d& operator-=(Vector2d& r);
std::shared_ptr< Vector2d > operator+( std::shared_ptr< Vector2d >& r );
std::shared_ptr< Vector2d > operator-(std::shared_ptr< Vector2d >& r);
void operator+=(std::shared_ptr< Vector2d > r);
void operator-=(std::shared_ptr< Vector2d > r);
Vector2d operator+(const Vector2d& r);
Vector2d operator-(const Vector2d& r);
Vector2d& operator+=(const Vector2d& r);
Vector2d& operator-=(const Vector2d& r);
/*Vector2d operator*(float scalar);
Vector2d& operator*=(float scalar);
Vector2d operator/(float scalar);
Vector2d& operator/=(float scalar);
*/
std::shared_ptr< Vector2d > operator*( float scalar );
void operator*=( float scalar );
std::shared_ptr< Vector2d > operator/( float scalar );
void operator/=( float scalar );
friend std::ostream& operator<<( std::ostream& out, const Vector2d& vec );
friend std::ostream& operator<<( std::ostream & out, std::shared_ptr< Vector2d > vec );
};
float distance( std::shared_ptr< Vector2d > vec1, std::shared_ptr < Vector2d > vec2 );
float distance( int x1, int y1, int x2, int y2 );
float distance( float x1, float y1, float x2, float y2 );
float distanceSquared( std::shared_ptr< Vector2d > vec1, std::shared_ptr < Vector2d > vec2 );
float distanceSquared( Vector2d& vec1, Vector2d& vec2 );
float distanceSquared( int x1, int y1, int x2, int y2 );
float distanceSquared(float x1, float y1, float x2, float y2);
float dotProduct( Vector2d& vec1, Vector2d& vec2 );
float dotProduct( std::shared_ptr< Vector2d > vec1, std::shared_ptr< Vector2d > vec2 );
float dotProduct( int x1, int y1, int x2, int y2 );
float dotProduct( float x1, float y1, float x2, float y2 );
std::shared_ptr< Vector2d > projection( std::shared_ptr< Vector2d > vec1, std::shared_ptr< Vector2d > vec2 );
float clamp( float n, float lower, float upper );
Vector2d RotateVector(Vector2d & vec, float angle);
const std::shared_ptr< Vector2d > vecUP = std::make_shared< Vector2d >(0.0f, -1.0f);
const std::shared_ptr< Vector2d > vecDOWN = std::make_shared< Vector2d >(0.0f, 1.0f);
const std::shared_ptr< Vector2d > vecRIGHT = std::make_shared< Vector2d >(1.0f, 0.0f);
const std::shared_ptr< Vector2d > vecLEFT = std::make_shared< Vector2d >(-1.0f, 0.0f);
#endif