GCP Assignment 1
Vec4.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 Vec4
17  {
19  float x, y, z, w;
20 
24  Vec4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
25 
33  Vec4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
34 
42  Vec4(int x, int y, int z, int w) : x((float)x), y((float)y), z((float)z), w((float)w) {}
43 
50  {
51  x += vecIn.x;
52  y += vecIn.y;
53  z += vecIn.y;
54  w += vecIn.w;
55  return this;
56  }
57 
64  {
65  x -= vecIn.x;
66  y -= vecIn.y;
67  z -= vecIn.z;
68  w -= vecIn.w;
69  return this;
70  }
71 
76  float getLength()
77  {
78  return float(sqrt((w*w) + (x*x) + (y*y) + (z*z)));
79  }
80  };
81 
87  inline Vec4 operator - (Vec4 vecIn)
88  {
89  Vec4 vecOut;
90  vecOut.x = -vecIn.x;
91  vecOut.y = -vecIn.y;
92  vecOut.z = -vecIn.z;
93  vecOut.w = -vecIn.w;
94  return vecOut;
95  }
96 
103  inline Vec4 operator - (Vec4 vecInA, Vec4 vecInB)
104  {
105  Vec4 vecOut;
106  vecOut.x = vecInA.x - vecInB.x;
107  vecOut.y = vecInA.y - vecInB.y;
108  vecOut.z = vecInA.z - vecInB.z;
109  vecOut.w = vecInA.w - vecInB.w;
110  return vecOut;
111  }
112 
119  inline Vec4 operator + (Vec4 vecInA, Vec4 vecInB)
120  {
121  Vec4 vecOut;
122  vecOut.x = vecInA.x + vecInB.x;
123  vecOut.y = vecInA.y + vecInB.y;
124  vecOut.z = vecInA.z + vecInB.z;
125  vecOut.w = vecInA.w + vecInB.w;
126  return vecOut;
127  }
128 
135  inline Vec4 operator / (Vec4 vecInA, float scalar)
136  {
137  Vec4 vecOut;
138  vecOut.x = vecInA.x / scalar;
139  vecOut.y = vecInA.y / scalar;
140  vecOut.z = vecInA.z / scalar;
141  vecOut.w = vecInA.w / scalar;
142  return vecOut;
143  }
144 
151  inline Vec4 operator * (Vec4 vecInA, float scalar)
152  {
153  Vec4 vecOut;
154  vecOut.x = vecInA.x * scalar;
155  vecOut.y = vecInA.y * scalar;
156  vecOut.z = vecInA.z * scalar;
157  vecOut.w = vecInA.w * scalar;
158  return vecOut;
159  }
160 
167  inline Vec4 operator * (Vec4 vecInA, Vec4 vecInB)
168  {
169  Vec4 vecOut;
170  vecOut.x = vecInA.x * vecInB.x;
171  vecOut.y = vecInA.y * vecInB.y;
172  vecOut.z = vecInA.z * vecInB.z;
173  vecOut.w = vecInA.w * vecInB.w;
174  return vecOut;
175  }
176 
177 }// End of Maths namespace
float z
Definition: Vec4.h:19
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: Vec4.h:19
Vec4 * operator+=(Vec4 vecIn)
Overloads the += operator.
Definition: Vec4.h:49
float w
Definition: Vec4.h:19
Contains the Vec4 structure with functions and overloaded operators.
Definition: Vec4.h:16
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
Vec4()
Constructs the Vec4 setting the values to 0,0,0,0.
Definition: Vec4.h:24
float getLength()
Returns the length of the Vec4.
Definition: Vec4.h:76
Mat4 operator+(Mat4 mIn, float s)
Overloads the + operator allowing a Mat4 to be added to a scalar.
Definition: Mat4.h:184
float y
Definition: Vec4.h:19
Vec4(float x, float y, float z, float w)
Constructs the Vec4 setting the values to the input coordinates.
Definition: Vec4.h:33
Vec4(int x, int y, int z, int w)
Constructs the Vec4 setting the values to the input coordinates.
Definition: Vec4.h:42
The namespace for all maths code.
Definition: Convert.cpp:5
Vec4 * operator-=(Vec4 vecIn)
Overloads the -= operator.
Definition: Vec4.h:63