17# pragma GCC diagnostic push
18# pragma GCC diagnostic ignored "-Wpedantic"
21# pragma clang diagnostic push
22# pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
23# pragma clang diagnostic ignored "-Wnested-anon-types"
26#include <vsg/maths/vec3.h>
27#include <vsg/vk/vulkan.h>
43 value_type x, y, z, w;
47 value_type r, g, b, a;
51 value_type s, t, p, q;
59 value{
v.x,
v.y,
v.z,
v.w} {}
66 value{
static_cast<value_type
>(
v.float32[0]),
static_cast<value_type
>(
v.float32[1]),
static_cast<value_type
>(
v.float32[2]),
static_cast<value_type
>(
v.float32[3])} {}
70 value{
static_cast<T
>(
v.x),
static_cast<T
>(
v.y),
static_cast<T
>(
v.z),
static_cast<T
>(
v.w)} {}
74 value{
static_cast<T
>(
v.x),
static_cast<T
>(
v.y),
in_z,
in_w} {}
78 value{
static_cast<T
>(
v.x),
static_cast<T
>(
v.y),
static_cast<T
>(
v.z),
in_w} {}
80 constexpr std::size_t size()
const {
return 4; }
82 value_type& operator[](std::size_t
i) {
return value[
i]; }
83 value_type operator[](std::size_t
i)
const {
return value[
i]; }
88 value[0] =
static_cast<value_type
>(
rhs[0]);
89 value[1] =
static_cast<value_type
>(
rhs[1]);
90 value[2] =
static_cast<value_type
>(
rhs[2]);
91 value[3] =
static_cast<value_type
>(
rhs[3]);
97 value[0] =
static_cast<value_type
>(
v.float32[0]);
98 value[1] =
static_cast<value_type
>(
v.float32[1]);
99 value[2] =
static_cast<value_type
>(
v.float32[2]);
100 value[3] =
static_cast<value_type
>(
v.float32[3]);
104 T* data() {
return value; }
105 const T* data()
const {
return value; }
107 void set(value_type
in_x, value_type
in_y, value_type
in_z, value_type
in_w)
117 value[0] +=
rhs.value[0];
118 value[1] +=
rhs.value[1];
119 value[2] +=
rhs.value[2];
120 value[3] +=
rhs.value[3];
126 value[0] -=
rhs.value[0];
127 value[1] -=
rhs.value[1];
128 value[2] -=
rhs.value[2];
129 value[3] -=
rhs.value[3];
133 inline t_vec4& operator*=(value_type
rhs)
144 value[0] *=
rhs.value[0];
145 value[1] *=
rhs.value[1];
146 value[2] *=
rhs.value[2];
147 value[3] *=
rhs.value[3];
151 inline t_vec4& operator/=(value_type
rhs)
153 if constexpr (std::is_floating_point_v<value_type>)
155 value_type
inv =
static_cast<value_type
>(1.0) /
rhs;
173 explicit operator bool()
const noexcept {
return value[0] != 0.0 || value[1] != 0.0 || value[2] != 0.0 || value[3] != 0.0; }
201 constexpr bool operator!=(
const t_vec4<T>& lhs,
const t_vec4<T>& rhs)
203 return lhs[0] != rhs[0] || lhs[1] != rhs[1] || lhs[2] != rhs[2] || lhs[3] != rhs[3];
207 constexpr bool operator<(
const t_vec4<T>& lhs,
const t_vec4<T>& rhs)
209 if (lhs[0] < rhs[0])
return true;
210 if (lhs[0] > rhs[0])
return false;
211 if (lhs[1] < rhs[1])
return true;
212 if (lhs[1] > rhs[1])
return false;
213 if (lhs[2] < rhs[2])
return true;
214 if (lhs[2] > rhs[2])
return false;
215 return lhs[3] < rhs[3];
219 constexpr t_vec4<T> operator-(
const t_vec4<T>& lhs,
const t_vec4<T>& rhs)
221 return t_vec4<T>(lhs[0] - rhs[0], lhs[1] - rhs[1], lhs[2] - rhs[2], lhs[3] - rhs[3]);
225 constexpr t_vec4<T> operator-(
const t_vec4<T>& v)
227 return t_vec4<T>(-v[0], -v[1], -v[2], -v[3]);
231 constexpr t_vec4<T> operator+(
const t_vec4<T>& lhs,
const t_vec4<T>& rhs)
233 return t_vec4<T>(lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2], lhs[3] + rhs[3]);
237 constexpr t_vec4<T> operator*(
const t_vec4<T>& lhs, T rhs)
239 return t_vec4<T>(lhs[0] * rhs, lhs[1] * rhs, lhs[2] * rhs, lhs[3] * rhs);
243 constexpr t_vec4<T> operator*(
const t_vec4<T>& lhs,
const t_vec4<T>& rhs)
245 return t_vec4<T>(lhs[0] * rhs[0], lhs[1] * rhs[1], lhs[2] * rhs[2], lhs[3] * rhs[3]);
249 constexpr t_vec4<T> operator/(
const t_vec4<T>& lhs, T rhs)
251 if constexpr (std::is_floating_point_v<T>)
253 T inv =
static_cast<T
>(1.0) / rhs;
254 return t_vec4<T>(lhs[0] * inv, lhs[1] * inv, lhs[2] * inv, lhs[3] * inv);
258 return t_vec4<T>(lhs[0] / rhs, lhs[1] / rhs, lhs[2] / rhs, lhs[3] / rhs);
263 constexpr T length(
const t_vec4<T>& v)
265 return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]);
269 constexpr T length2(
const t_vec4<T>& v)
271 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
275 constexpr t_vec4<T> normalize(
const t_vec4<T>& v)
277 return v / length(v);
281 constexpr t_vec4<T> mix(
const t_vec4<T>& start,
const t_vec4<T>& end, T r)
283 T one_minus_r = 1 - r;
284 return t_vec4<T>(start[0] * one_minus_r + end[0] * r,
285 start[1] * one_minus_r + end[1] * r,
286 start[2] * one_minus_r + end[2] * r,
287 start[3] * one_minus_r + end[3] * r);
292#if defined(__clang__)
293# pragma clang diagnostic pop
296# pragma GCC diagnostic pop
std container adapter for allocating with MEMORY_AFFINITY_NODES
Definition Allocator.h:138
t_vec4 template class that represents a 4D vector
Definition vec4.h:35