Level H Engine
Vec2.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "math.h"
4 
8 struct Vec2
9 {
11  float x, y;
12 
16  Vec2() : x(0.0f), y(0.0f) {}
17 
23  Vec2(float x, float y) : x(x), y(y) {}
24 
30  Vec2(int x, int y) : x((float)x), y((float)y) {}
31 
38  {
39  x += vecIn.x;
40  y += vecIn.y;
41  return this;
42  }
43 
50  {
51  x -= vecIn.x;
52  y -= vecIn.y;
53  return this;
54  }
55 
60  float getLength()
61  {
62  return float(sqrt((x*x) + (y*y)));
63  }
64 };
65 
71 inline Vec2 operator - (Vec2 vecIn)
72 {
73  Vec2 vecOut;
74  vecOut.x = -vecIn.x;
75  vecOut.y = -vecIn.y;
76  return vecOut;
77 }
78 
85 inline Vec2 operator - (Vec2 vecInA, Vec2 vecInB)
86 {
87  Vec2 vecOut;
88  vecOut.x = vecInA.x - vecInB.x;
89  vecOut.y = vecInA.y - vecInB.y;
90  return vecOut;
91 }
92 
99 inline Vec2 operator + (Vec2 vecInA, Vec2 vecInB)
100 {
101  Vec2 vecOut;
102  vecOut.x = vecInA.x + vecInB.x;
103  vecOut.y = vecInA.y + vecInB.y;
104  return vecOut;
105 }
106 
113 inline Vec2 operator / (Vec2 vecInA, float scalar)
114 {
115  Vec2 vecOut;
116  vecOut.x = vecInA.x / scalar;
117  vecOut.y = vecInA.y / scalar;
118  return vecOut;
119 }
120 
127 inline Vec2 operator * (Vec2 vecInA, float scalar)
128 {
129  Vec2 vecOut;
130  vecOut.x = vecInA.x * scalar;
131  vecOut.y = vecInA.y * scalar;
132  return vecOut;
133 }
134 
141 inline Vec2 operator * (Vec2 vecInA, Vec2 vecInB)
142 {
143  Vec2 vecOut;
144  vecOut.x = vecInA.x * vecInB.x;
145  vecOut.y = vecInA.y * vecInB.y;
146  return vecOut;
147 }
float x
Position variables.
Definition: Vec2.h:11
Vec2 operator+(Vec2 vecInA, Vec2 vecInB)
Overloads the + operator.
Definition: Vec2.h:99
Vec2()
Constructs the Vec2 setting the values to 0,0.
Definition: Vec2.h:16
Contains the Vec2 structure with functions and overloaded operators.
Definition: Vec2.h:8
Vec2(float x, float y)
Constructs the Vec2 setting the values to the input coordinates.
Definition: Vec2.h:23
Vec2 operator*(Vec2 vecInA, float scalar)
Overloads the * operator allowing a Vec2 to be multiplied by a scalar.
Definition: Vec2.h:127
Vec2 operator-(Vec2 vecIn)
Overloads the - operator allowing a Vec2 to be inverted.
Definition: Vec2.h:71
Vec2(int x, int y)
Constructs the Vec2 setting the values to the input coordinates.
Definition: Vec2.h:30
float y
Definition: Vec2.h:11
Vec2 operator/(Vec2 vecInA, float scalar)
Overloads the / operator allowing a Vec2 to be divided by a scalar.
Definition: Vec2.h:113
Vec2 * operator+=(Vec2 vecIn)
Overloads the += operator.
Definition: Vec2.h:37
float getLength()
Returns the length of the Vec2.
Definition: Vec2.h:60
Vec2 * operator-=(Vec2 vecIn)
Overloads the -= operator.
Definition: Vec2.h:49