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