forked from cut-lip/DataGlyphDebug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvec2.h
63 lines (50 loc) · 1.32 KB
/
vec2.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
#pragma once
#include <math.h>
#include <QOpenGLFunctions>
//#include "GL/glut.h"
// A 2-D vector
class Vec2 {
public:
Vec2(GLfloat x, GLfloat y) { // Constructor
this->x = x;
this->y = y;
}
Vec2(const Vec2& vec) { // Copy constructor
this->x = vec.x;
this->y = vec.y;
}
GLfloat getx()
{
return this->x;
}
GLfloat gety()
{
return this->y;
}
float Length() { // Return length of vector
return sqrt(x * x + y * y);
}
void Normalize() { // Transform into normal vector in same direction
float len = this->Length();
this->x /= len;
this->y /= len;
}
void Perpendicu() { // Transform into vector perpendicular to current orientation
float _x = this->x;
this->x = -this->y;
this->y = _x;
}
Vec2 operator+(const Vec2& b) { // Overload + Operator
return Vec2(this->x + b.x, this->y + b.y);
}
Vec2 operator-(const Vec2& b) { // Overload - Operator
return Vec2(this->x - b.x, this->y - b.y);
}
Vec2 operator*(const GLint c) { // Overload * Operator for * by Constants
return Vec2(this->x * c, this->y * c);
}
private:
//Define vector
GLfloat x = 0.0;
GLfloat y = 0.0;
};