CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Vector.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Forward.hpp"
12
14
15#include <glm/vec2.hpp>
16#include <glm/vec3.hpp>
17#include <glm/vec4.hpp>
18
19#define CE_EXTERN_VECTOR(D) \
20 extern template struct glm::vec<D, double, glm::highp>; \
21 extern template struct glm::vec<D, float, glm::highp>; \
22 extern template struct glm::vec<D, char, glm::highp>; \
23 extern template struct glm::vec<D, unsigned char, glm::highp>; \
24 extern template struct glm::vec<D, short, glm::highp>; \
25 extern template struct glm::vec<D, unsigned short, glm::highp>; \
26 extern template struct glm::vec<D, int, glm::highp>; \
27 extern template struct glm::vec<D, unsigned int, glm::highp>; \
28 extern template struct glm::vec<D, long, glm::highp>; \
29 extern template struct glm::vec<D, unsigned long, glm::highp>
33#undef CE_EXTERN_VECTOR
34
35namespace CeresEngine::inline Math {
36
39 template<glm::length_t D, typename T = double> using TVector = glm::vec<D, T, glm::highp>;
40
41 // ---------------------------------------------------------------------------------------------
42
45 template<typename T> using TVector2 = TVector<2, T>;
46
48 using Vector2 CE_SCRIPT_EXPORT(name = "Vector2", external = true, plain = true)
50
53 using Vector2f CE_SCRIPT_EXPORT(name = "Vector2", external = true, plain = true)
55
58 using Vector2i CE_SCRIPT_EXPORT(name = "Vector2", external = true, plain = true)
60
64
67 using Vector2b CE_SCRIPT_EXPORT(name = "Vector2", external = true, plain = true)
69
71 using Vec2 = Vector2;
72
74 using Vec2f = Vector2f;
75
76 // ---------------------------------------------------------------------------------------------
77
80 template<typename T> using TVector3 = TVector<3, T>;
81
83 using Vector3 CE_SCRIPT_EXPORT(name = "Vector3", external = true, plain = true)
85
88 using Vector3f CE_SCRIPT_EXPORT(name = "Vector3", external = true, plain = true)
90
93 using Vector3i CE_SCRIPT_EXPORT(name = "Vector3", external = true, plain = true)
95
99
102 using Vector3b CE_SCRIPT_EXPORT(name = "Vector3", external = true, plain = true)
104
106 using Vec3 = Vector3;
107
110
111 // ---------------------------------------------------------------------------------------------
112
115 template<typename T> using TVector4 = TVector<4, T>;
116
118 using Vector4 CE_SCRIPT_EXPORT(name = "Vector4", external = true, plain = true)
120
123 using Vector4f CE_SCRIPT_EXPORT(name = "Vector4", external = true, plain = true)
125
128 using Vector4i CE_SCRIPT_EXPORT(name = "Vector4", external = true, plain = true)
130
134
137 using Vector4b CE_SCRIPT_EXPORT(name = "Vector4", external = true, plain = true)
139
141 using Vec4 = Vector4;
142
145
152 template<std::size_t N, glm::length_t D, typename T> [[nodiscard]] T& get(TVector<D, T>& vector) noexcept { return vector[N]; }
153
155 template<std::size_t N, glm::length_t D, typename T> [[nodiscard]] const T& get(const TVector<D, T>& vector) noexcept { return vector[N]; }
156
157} // namespace CeresEngine::inline Math
158
159template<glm::length_t D, typename T> struct std::tuple_size<CeresEngine::TVector<D, T>> : std::integral_constant<std::size_t, D> {};
160
161template<std::size_t N, glm::length_t D, typename T> struct std::tuple_element<N, CeresEngine::TVector<D, T>> {
162 using type = decltype(std::declval<CeresEngine::TVector<D, T>>()[N]);
163};
164
165template<glm::length_t D, typename T> struct std::hash<CeresEngine::TVector<D, T>> {
166 using Type = CeresEngine::TVector<D, T>;
167 constexpr size_t operator()(const Type& obj) const {
168 using namespace CeresEngine;
169
170 size_t seed = 0;
171 for(glm::length_t i = 0; i < D; i++) {
172 combine(seed, obj[i]);
173 }
174 return seed;
175 }
176};
177
178#define REFL_DECLARE_CE_VECTOR(T) \
179 \
180 \
181
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
#define CE_EXTERN_VECTOR(D)
Definition Vector.hpp:19
#define REFL_DECLARE_CE_VECTOR(T)
Definition Vector.hpp:178
Definition Application.hpp:19
std::uint64_t UInt64
Definition DataTypes.hpp:26
decltype(auto) get(BezierPath::Element &element) noexcept
Decomposes a bezier path element.
Definition BezierPath.hpp:723
constexpr void combine(std::size_t &seed, const T &v)
Generates a new hash for the provided type using the default standard hasher and combines it with a p...
Definition Hash.hpp:32
std::int32_t Int32
Definition DataTypes.hpp:21
std::int64_t Int64
Definition DataTypes.hpp:24
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Angle.hpp:20
TVector3< unsigned int > Vector3ui
A three dimensional vector with (x, y, z) coordinates.
Definition Vector.hpp:98
Vector3 Vec3
A alias to a Vector3.
Definition Vector.hpp:106
Vector2f Vec2f
A alias to a Vector2f.
Definition Vector.hpp:74
TVector2< unsigned int > Vector2ui
A two dimensional vector with (x, y) coordinates.
Definition Vector.hpp:63
TVector2< double > Vector2
A two dimensional vector with (x, y) coordinates.
Definition Vector.hpp:49
TVector4< unsigned int > Vector4ui
A four dimensional vector with (x, y, z, w) coordinates.
Definition Vector.hpp:133
TVector3< double > Vector3
A three dimensional vector with (x, y, z) coordinates.
Definition Vector.hpp:84
Vector3f Vec3f
A alias to a Vector3f.
Definition Vector.hpp:109
TVector2< bool > Vector2b
A two dimensional vector with (x, y) coordinates.
Definition Vector.hpp:68
Vector2 Vec2
A alias to a Vector2.
Definition Vector.hpp:71
glm::vec< D, T, glm::highp > TVector
A D-dimensional vector type that uses a internal representation of type T
Definition Vector.hpp:39
TVector2< float > Vector2f
A two dimensional vector with (x, y) coordinates.
Definition Vector.hpp:54
Vector4 Vec4
A alias to a Vector4.
Definition Vector.hpp:141
TVector4< float > Vector4f
A four dimensional vector with (x, y, z, w) coordinates.
Definition Vector.hpp:124
Vector4f Vec4f
A alias to a Vector4f.
Definition Vector.hpp:144
TVector4< bool > Vector4b
A four dimensional vector with (x, y, z, w) coordinates.
Definition Vector.hpp:138
TVector< 4, T > TVector4
A four dimensional vector type that uses a internal representation of type T
Definition Vector.hpp:115
TVector3< int > Vector3i
A three dimensional vector with (x, y, z) coordinates.
Definition Vector.hpp:94
TVector3< bool > Vector3b
A three dimensional vector with (x, y, z) coordinates.
Definition Vector.hpp:103
TVector4< int > Vector4i
A four dimensional vector with (x, y, z, w) coordinates.
Definition Vector.hpp:129
TVector4< double > Vector4
A four dimensional vector with (x, y, z, w) coordinates.
Definition Vector.hpp:119
TVector2< int > Vector2i
A two dimensional vector with (x, y) coordinates.
Definition Vector.hpp:59
TVector< 2, T > TVector2
A two dimensional vector type that uses a internal representation of type T
Definition Vector.hpp:45
TVector< 3, T > TVector3
A three dimensional vector type that uses a internal representation of type T
Definition Vector.hpp:80
TVector3< float > Vector3f
A three dimensional vector with (x, y, z) coordinates.
Definition Vector.hpp:89