GCP Assignment 1
Vec2.h
Go to the documentation of this file.
1 //DISCLAMER - This is a modified version of code from one of my other assignments.
2 
3 #pragma once
4 
5 #include "math.h"
6 
10 namespace Maths
11 {
12 
16  struct Vec2
17  {
19  float x, y;
20 
24  Vec2() : x(0.0f), y(0.0f) {}
25 
31  Vec2(float x, float y) : x(x), y(y) {}
32 
38  Vec2(int x, int y) : x((float)x), y((float)y) {}
39 
46  {
47  x += vecIn.x;
48  y += vecIn.y;
49  return this;
50  }
51 
58  {
59  x -= vecIn.x;
60  y -= vecIn.y;
61  return this;
62  }
63 
68  float getLength()
69  {
70  return float(sqrt((x*x) + (y*y)));
71  }
72  };
73 
79  inline Vec2 operator - (Vec2 vecIn)
80  {
81  Vec2 vecOut;
82  vecOut.x = -vecIn.x;
83  vecOut.y = -vecIn.y;
84  return vecOut;
85  }
86 
93  inline Vec2 operator - (Vec2 vecInA, Vec2 vecInB)
94  {
95  Vec2 vecOut;
96  vecOut.x = vecInA.x - vecInB.x;
97  vecOut.y = vecInA.y - vecInB.y;
98  return vecOut;
99  }
100 
107  inline Vec2 operator + (Vec2 vecInA, Vec2 vecInB)
108  {
109  Vec2 vecOut;
110  vecOut.x = vecInA.x + vecInB.x;
111  vecOut.y = vecInA.y + vecInB.y;
112  return vecOut;
113  }
114 
121  inline Vec2 operator / (Vec2 vecInA, float scalar)
122  {
123  Vec2 vecOut;
124  vecOut.x = vecInA.x / scalar;
125  vecOut.y = vecInA.y / scalar;
126  return vecOut;
127  }
128 
135  inline Vec2 operator * (Vec2 vecInA, float scalar)
136  {
137  Vec2 vecOut;
138  vecOut.x = vecInA.x * scalar;
139  vecOut.y = vecInA.y * scalar;
140  return vecOut;
141  }
142 
149  inline Vec2 operator * (Vec2 vecInA, Vec2 vecInB)
150  {
151  Vec2 vecOut;
152  vecOut.x = vecInA.x * vecInB.x;
153  vecOut.y = vecInA.y * vecInB.y;
154  return vecOut;
155  }
156 
157 }// End of Maths namespace
Vec2()
Constructs the Vec2 setting the values to 0,0.
Definition: Vec2.h:24
Vec2(float x, float y)
Constructs the Vec2 setting the values to the input coordinates.
Definition: Vec2.h:31
Vec2 * operator+=(Vec2 vecIn)
Overloads the += operator.
Definition: Vec2.h:45
Mat4 operator-(Mat4 mInA, float s)
Overloads the - operator allowing a Mat4 to be added to a scalar.
Definition: Mat4.h:216
float x
Position variables.
Definition: Vec2.h:19
Vec2 operator/(Vec2 vecInA, float scalar)
Overloads the / operator allowing a Vec2 to be divided by a scalar.
Definition: Vec2.h:121
Mat4 operator*(Mat4 mInA, float s)
Overloads the * operator allowing a Mat4 to be multiplied to a scalar.
Definition: Mat4.h:248
float getLength()
Returns the length of the Vec2.
Definition: Vec2.h:68
Mat4 operator+(Mat4 mIn, float s)
Overloads the + operator allowing a Mat4 to be added to a scalar.
Definition: Mat4.h:184
Contains the Vec2 structure with functions and overloaded operators.
Definition: Vec2.h:16
float y
Definition: Vec2.h:19
The namespace for all maths code.
Definition: Convert.cpp:5
Vec2 * operator-=(Vec2 vecIn)
Overloads the -= operator.
Definition: Vec2.h:57
Vec2(int x, int y)
Constructs the Vec2 setting the values to the input coordinates.
Definition: Vec2.h:38