Level H Engine
Vec4.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "math.h"
4 
8 struct Vec4
9 {
11  float x, y, z, w;
12 
16  Vec4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
17 
25  Vec4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
26 
34  Vec4(int x, int y, int z, int w) : x((float)x), y((float)y), z((float)z), w((float)w) {}
35 
42  {
43  x += vecIn.x;
44  y += vecIn.y;
45  z += vecIn.y;
46  w += vecIn.w;
47  return this;
48  }
49 
56  {
57  x -= vecIn.x;
58  y -= vecIn.y;
59  z -= vecIn.z;
60  w -= vecIn.w;
61  return this;
62  }
63 
68  float getLength()
69  {
70  return float(sqrt((w*w) + (x*x) + (y*y) + (z*z)));
71  }
72 };
73 
79 inline Vec4 operator - (Vec4 vecIn)
80 {
81  Vec4 vecOut;
82  vecOut.x = -vecIn.x;
83  vecOut.y = -vecIn.y;
84  vecOut.z = -vecIn.z;
85  vecOut.w = -vecIn.w;
86  return vecOut;
87 }
88 
95 inline Vec4 operator - (Vec4 vecInA, Vec4 vecInB)
96 {
97  Vec4 vecOut;
98  vecOut.x = vecInA.x - vecInB.x;
99  vecOut.y = vecInA.y - vecInB.y;
100  vecOut.z = vecInA.z - vecInB.z;
101  vecOut.w = vecInA.w - vecInB.w;
102  return vecOut;
103 }
104 
111 inline Vec4 operator + (Vec4 vecInA, Vec4 vecInB)
112 {
113  Vec4 vecOut;
114  vecOut.x = vecInA.x + vecInB.x;
115  vecOut.y = vecInA.y + vecInB.y;
116  vecOut.z = vecInA.z + vecInB.z;
117  vecOut.w = vecInA.w + vecInB.w;
118  return vecOut;
119 }
120 
127 inline Vec4 operator / (Vec4 vecInA, float scalar)
128 {
129  Vec4 vecOut;
130  vecOut.x = vecInA.x / scalar;
131  vecOut.y = vecInA.y / scalar;
132  vecOut.z = vecInA.z / scalar;
133  vecOut.w = vecInA.w / scalar;
134  return vecOut;
135 }
136 
143 inline Vec4 operator * (Vec4 vecInA, float scalar)
144 {
145  Vec4 vecOut;
146  vecOut.x = vecInA.x * scalar;
147  vecOut.y = vecInA.y * scalar;
148  vecOut.z = vecInA.z * scalar;
149  vecOut.w = vecInA.w * scalar;
150  return vecOut;
151 }
152 
159 inline Vec4 operator * (Vec4 vecInA, Vec4 vecInB)
160 {
161  Vec4 vecOut;
162  vecOut.x = vecInA.x * vecInB.x;
163  vecOut.y = vecInA.y * vecInB.y;
164  vecOut.z = vecInA.z * vecInB.z;
165  vecOut.w = vecInA.w * vecInB.w;
166  return vecOut;
167 }
float y
Definition: Vec4.h:11
Vec4 operator*(Vec4 vecInA, float scalar)
Overloads the * operator allowing a Vec4 to be multiplied by a scalar.
Definition: Vec4.h:143
Vec4(float x, float y, float z, float w)
Constructs the Vec4 setting the values to the input coordinates.
Definition: Vec4.h:25
Contains the Vec4 structure with functions and overloaded operators.
Definition: Vec4.h:8
Vec4(int x, int y, int z, int w)
Constructs the Vec4 setting the values to the input coordinates.
Definition: Vec4.h:34
Vec4 operator/(Vec4 vecInA, float scalar)
Overloads the / operator allowing a Vec4 to be divided by a scalar.
Definition: Vec4.h:127
Vec4 * operator+=(Vec4 vecIn)
Overloads the += operator.
Definition: Vec4.h:41
float getLength()
Returns the length of the Vec4.
Definition: Vec4.h:68
float x
Position variables.
Definition: Vec4.h:11
Vec4()
Constructs the Vec4 setting the values to 0,0,0,0.
Definition: Vec4.h:16
float w
Definition: Vec4.h:11
float z
Definition: Vec4.h:11
Vec4 operator+(Vec4 vecInA, Vec4 vecInB)
Overloads the + operator.
Definition: Vec4.h:111
Vec4 operator-(Vec4 vecIn)
Overloads the - operator allowing a Vec4 to be inverted.
Definition: Vec4.h:79
Vec4 * operator-=(Vec4 vecIn)
Overloads the -= operator.
Definition: Vec4.h:55