-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvec4.cpp
More file actions
63 lines (51 loc) · 1.96 KB
/
vec4.cpp
File metadata and controls
63 lines (51 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include "vec3.cpp"
#include <QVector4D>
template<typename T> struct vec4 : public vec3<T>
{
explicit vec4(T x = {}, T y = {}, T z = {}, T w = {}) noexcept: vec3<T>(x, y, z), w(w) { }
explicit vec4(const vec3<T>& v3, T w = {}) noexcept: vec3<T>(v3), w(w) {}
vec4(const vec4<T>& other) noexcept: vec3<T>(other.x, other.y, other.z), w(other.w) { }
vec4(const vec4<T>&& other) noexcept: vec3<T>(other.x, other.y, other.z), w(other.w) { }
explicit vec4(const QVector4D& v) noexcept: vec3<T>(v.x(), v.y(), v.z()), w(v.w()) { }
explicit vec4(const QVector4D&& v) noexcept: vec3<T>(v.x(), v.y(), v.z()), w(v.w()) { }
explicit operator QVector4D() const noexcept
{
return QVector4D(this->x, this->y, this->z, this->w);
}
explicit operator std::string() const noexcept
{
std::stringstream ss;
ss << std::setprecision(std::numeric_limits<T>::digits10) << static_cast<int>(this->x) << ';' << this->y << ';' << this->z << ';'<< this->w;
return ss.str();
}
explicit operator QString() const noexcept
{
std::stringstream ss;
ss << std::setprecision(std::numeric_limits<T>::digits10) << this->x << ';' << this->y << ';' << this->z << ';'<< this->w;
return QString(ss.str().data());
}
vec4<T>& operator = (const vec4<T>& other) noexcept
{
this->x = other.x;
this->y = other.y;
this->z = other.z;
return *this;
}
vec4<T>& operator = (const vec4<T>&& other) noexcept
{
this->x = other.x;
this->y = other.y;
this->z = other.z;
return *this;
}
bool operator == (const vec4& other) const noexcept
{
return this->x == other.x && this->y == other.y && this->z == other.z && this->w == other.w;
}
bool operator != (const vec4& other) const noexcept
{
return this->x != other.x || this->y != other.y || this->z != other.z || this->w != other.w;
}
T w;
};