renderer_opengl: Remove GLvec* types
* The common types already exist and provide all the functionality required, why invent new types?
This commit is contained in:
parent
e834f2b049
commit
e6137d7874
6 changed files with 170 additions and 144 deletions
|
@ -31,6 +31,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
#include <boost/serialization/access.hpp>
|
||||
|
||||
|
@ -60,6 +61,10 @@ public:
|
|||
return &x;
|
||||
}
|
||||
|
||||
const T* AsArray() const {
|
||||
return &x;
|
||||
}
|
||||
|
||||
constexpr Vec2() = default;
|
||||
constexpr Vec2(const T& x_, const T& y_) : x(x_), y(y_) {}
|
||||
|
||||
|
@ -123,6 +128,14 @@ public:
|
|||
return x * x + y * y;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool operator!=(const Vec2& other) const {
|
||||
return std::memcmp(AsArray(), other.AsArray(), sizeof(Vec2)) != 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool operator==(const Vec2& other) const {
|
||||
return std::memcmp(AsArray(), other.AsArray(), sizeof(Vec2)) == 0;
|
||||
}
|
||||
|
||||
// Only implemented for T=float
|
||||
[[nodiscard]] float Length() const;
|
||||
[[nodiscard]] float Normalize(); // returns the previous length, which is often useful
|
||||
|
@ -184,6 +197,8 @@ template <typename T, typename V>
|
|||
}
|
||||
|
||||
using Vec2f = Vec2<float>;
|
||||
using Vec2i = Vec2<int>;
|
||||
using Vec2u = Vec2<unsigned int>;
|
||||
|
||||
template <>
|
||||
inline float Vec2<float>::Length() const {
|
||||
|
@ -216,6 +231,10 @@ public:
|
|||
return &x;
|
||||
}
|
||||
|
||||
const T* AsArray() const {
|
||||
return &x;
|
||||
}
|
||||
|
||||
constexpr Vec3() = default;
|
||||
constexpr Vec3(const T& x_, const T& y_, const T& z_) : x(x_), y(y_), z(z_) {}
|
||||
|
||||
|
@ -280,6 +299,14 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool operator!=(const Vec3& other) const {
|
||||
return std::memcmp(AsArray(), other.AsArray(), sizeof(Vec3)) != 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool operator==(const Vec3& other) const {
|
||||
return std::memcmp(AsArray(), other.AsArray(), sizeof(Vec3)) == 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T Length2() const {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
@ -412,6 +439,8 @@ inline float Vec3<float>::Normalize() {
|
|||
}
|
||||
|
||||
using Vec3f = Vec3<float>;
|
||||
using Vec3i = Vec3<int>;
|
||||
using Vec3u = Vec3<unsigned int>;
|
||||
|
||||
template <typename T>
|
||||
class Vec4 {
|
||||
|
@ -434,6 +463,10 @@ public:
|
|||
return &x;
|
||||
}
|
||||
|
||||
const T* AsArray() const {
|
||||
return &x;
|
||||
}
|
||||
|
||||
constexpr Vec4() = default;
|
||||
constexpr Vec4(const T& x_, const T& y_, const T& z_, const T& w_)
|
||||
: x(x_), y(y_), z(z_), w(w_) {}
|
||||
|
@ -503,6 +536,14 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool operator!=(const Vec4& other) const {
|
||||
return std::memcmp(AsArray(), other.AsArray(), sizeof(Vec4)) != 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool operator==(const Vec4& other) const {
|
||||
return std::memcmp(AsArray(), other.AsArray(), sizeof(Vec4)) == 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T Length2() const {
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
@ -623,6 +664,8 @@ template <typename T, typename V>
|
|||
}
|
||||
|
||||
using Vec4f = Vec4<float>;
|
||||
using Vec4i = Vec4<int>;
|
||||
using Vec4u = Vec4<unsigned int>;
|
||||
|
||||
template <typename T>
|
||||
constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec2<T>& a, const Vec2<T>& b) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue