Khangai Robot Play - Naive  01
THe naive play of the Khangai Robot
vec4.h
Go to the documentation of this file.
1 /*
2  * vec4.h
3  *
4  * Created : 1/9/2018
5  * Author : n-is
6  * email : 073bex422.nischal@pcampus.edu.np
7  */
8 
9 #ifndef _VEC4_H_
10 #define _VEC4_H_
11 
12 #include "vec4.h"
13 
14 template <class T>
15 class Vec4
16 {
17 public:
18  Vec4() { set_Values(0,0,0); }
19  Vec4(T x, T y, T z, T w) { set_Values(x,y,z,w); }
20 
21  Vec4(Vec4 &&) = default;
22  Vec4 &operator=(Vec4 &&) = default;
23  ~Vec4() { }
24 
25  T getX() const { return x_; }
26  T getY() const { return y_; }
27  T getZ() const { return z_; }
28  T getW() const { return w_; }
29  void setX(T x) { x_ = x; }
30  void setY(T y) { y_ = y; }
31  void setZ(T z) { z_ = z; }
32  void setW(T w) { w_ = w; }
33 
34  void set_Values(T x, T y, T z, T w) {
35  setX(x);
36  setY(y);
37  setZ(z);
38  setW(w);
39  }
40 
41 
42  Vec4 mult_EW(float num) {
43  Vec4 temp(*this);
44  temp.x_ *= num;
45  temp.y_ *= num;
46  temp.z_ *= num;
47  temp.w_ *= num;
48 
49  return temp;
50  }
51 
52  template <typename T1>
54  Vec4 temp(v);
55  temp.x_ *= x_;
56  temp.y_ *= y_;
57  temp.z_ *= z_;
58  temp.w_ *= w_;
59 
60  return temp;
61  }
62 
63 
64  Vec4 add_EW(float num) {
65  Vec4 temp(*this);
66  temp.x_ += num;
67  temp.y_ += num;
68  temp.z_ += num;
69  temp.w_ += num;
70 
71  return temp;
72  }
73 
74  template <typename T1>
76  Vec4 temp(v);
77  temp.x_ += x_;
78  temp.y_ += y_;
79  temp.z_ += z_;
80  temp.w_ += w_;
81 
82  return temp;
83  }
84 
85 
86  Vec4 sub_EW(float num) {
87  Vec4 temp(*this);
88  temp.x_ -= num;
89  temp.y_ -= num;
90  temp.z_ -= num;
91  temp.w_ -= num;
92 
93  return temp;
94  }
95 
96  template <typename T1>
98  Vec4 temp(v);
99  temp.x_ -= x_;
100  temp.y_ -= y_;
101  temp.z_ -= z_;
102  temp.w_ -= w_;
103 
104  return temp;
105  }
106 
107 
108  Vec4 div_EW(float num) {
109  Vec4 temp(*this);
110  temp.x_ /= (float)num;
111  temp.y_ /= (float)num;
112  temp.z_ /= (float)num;
113  temp.w_ /= (float)num;
114 
115  return temp;
116  }
117 
118  template <typename T1>
120  Vec4 temp(*this);
121  temp.x_ /= (float)v.x_;
122  temp.y_ /= (float)v.y_;
123  temp.z_ /= (float)v.z_;
124  temp.w_ /= (float)v.w_;
125 
126  return temp;
127  }
128 
129 
130  Vec4(const Vec4 &v) {
131  x_ = v.x_;
132  y_ = v.y_;
133  z_ = v.z_;
134  w_ = v.w_;
135  }
136 
137  Vec4 &operator=(const Vec4 &v) {
138  Vec4 temp(v);
139  swap(*this, temp);
140 
141  return *this;
142  }
143 
144  Vec4 &operator+=(const Vec4 &rhs) {
145  x_ += rhs.x_;
146  y_ += rhs.y_;
147  z_ += rhs.z_;
148  w_ += rhs.w_;
149 
150  return *this;
151  }
152 
153  Vec4 &operator-=(const Vec4 &rhs) {
154  x_ -= rhs.x_;
155  y_ -= rhs.y_;
156  z_ -= rhs.z_;
157  z_ -= rhs.w_;
158 
159  return *this;
160  }
161 
162  friend Vec4 operator+(Vec4 lhs, const Vec4 &rhs) {
163  lhs += rhs;
164  return lhs;
165  }
166 
167  friend Vec4 operator-(Vec4 lhs, const Vec4 &rhs) {
168  lhs -= rhs;
169  return lhs;
170  }
171 
172  void print() const {
173  printf("%ld, %ld, %ld", (int32_t)x_, (int32_t)y_, (int32_t)z_);
174  }
175 
176 private:
177  T x_,y_,z_,w_;
178 
179  friend void swap(Vec4 &first, Vec4 &second) {
180  swap_Element(first.x_, second.x_);
181  swap_Element(first.y_, second.y_);
182  swap_Element(first.z_, second.z_);
183  swap_Element(first.w_, second.w_);
184  }
185 };
186 
187 #endif // !_VEC4_H_
void set_Values(T x, T y, T z, T w)
Definition: vec4.h:34
void setZ(T z)
Definition: vec4.h:31
T x_
Definition: vec4.h:177
Vec4()
Definition: vec4.h:18
Vec4 div_EW(float num)
Definition: vec4.h:108
Vec4 & operator=(Vec4 &&)=default
Vec4 mult_EW(float num)
Definition: vec4.h:42
Vec4 & operator=(const Vec4 &v)
Definition: vec4.h:137
friend Vec4 operator+(Vec4 lhs, const Vec4 &rhs)
Definition: vec4.h:162
void swap_Element(T &first, T &second)
Definition: vec3.h:16
Vec4 mult_EW(Vec4< T1 > v)
Definition: vec4.h:53
Vec4(const Vec4 &v)
Definition: vec4.h:130
friend Vec4 operator-(Vec4 lhs, const Vec4 &rhs)
Definition: vec4.h:167
~Vec4()
Definition: vec4.h:23
T getY() const
Definition: vec4.h:26
void print() const
Definition: vec4.h:172
T getX() const
Definition: vec4.h:25
T y_
Definition: vec4.h:177
Vec4 & operator-=(const Vec4 &rhs)
Definition: vec4.h:153
void setX(T x)
Definition: vec4.h:29
Vec4 add_EW(Vec4< T1 > v)
Definition: vec4.h:75
Vec4 add_EW(float num)
Definition: vec4.h:64
T w_
Definition: vec4.h:177
Vec4 sub_EW(float num)
Definition: vec4.h:86
Vec4(T x, T y, T z, T w)
Definition: vec4.h:19
T getW() const
Definition: vec4.h:28
Vec4 & operator+=(const Vec4 &rhs)
Definition: vec4.h:144
Definition: vec4.h:15
T z_
Definition: vec4.h:177
friend void swap(Vec4 &first, Vec4 &second)
Definition: vec4.h:179
Vec4 div_EW(Vec4< T1 > v)
Definition: vec4.h:119
void setW(T w)
Definition: vec4.h:32
Vec4 sub_EW(Vec4< T1 > v)
Definition: vec4.h:97
T getZ() const
Definition: vec4.h:27
void setY(T y)
Definition: vec4.h:30