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/vec2.h>
56 constexpr t_vec3(
const t_vec3& v) :
57 value{v.x, v.y, v.z} {}
58 constexpr t_vec3& operator=(
const t_vec3&) =
default;
59 constexpr t_vec3(value_type in_x, value_type in_y, value_type in_z) :
60 value{in_x, in_y, in_z} {}
63 constexpr t_vec3(
const t_vec2<R>& v, value_type in_z) :
64 value{v.x, v.y, in_z} {}
67 constexpr explicit t_vec3(
const t_vec3<R>& v) :
68 value{
static_cast<T
>(v.x),
static_cast<T
>(v.y),
static_cast<T
>(v.z)} {}
70 constexpr std::size_t size()
const {
return 3; }
72 value_type& operator[](std::size_t i) {
return value[i]; }
73 value_type operator[](std::size_t i)
const {
return value[i]; }
76 t_vec3& operator=(
const t_vec3<R>& rhs)
78 value[0] =
static_cast<value_type
>(rhs[0]);
79 value[1] =
static_cast<value_type
>(rhs[1]);
80 value[2] =
static_cast<value_type
>(rhs[2]);
84 T* data() {
return value; }
85 const T* data()
const {
return value; }
87 void set(value_type in_x, value_type in_y, value_type in_z)
94 inline t_vec3& operator+=(
const t_vec3& rhs)
96 value[0] += rhs.value[0];
97 value[1] += rhs.value[1];
98 value[2] += rhs.value[2];
102 inline t_vec3& operator-=(
const t_vec3& rhs)
104 value[0] -= rhs.value[0];
105 value[1] -= rhs.value[1];
106 value[2] -= rhs.value[2];
110 inline t_vec3& operator*=(value_type rhs)
118 friend constexpr t_vec3<T> operator*(
const t_vec3<T>& lhs, T rhs)
120 return t_vec3<T>(lhs[0] * rhs, lhs[1] * rhs, lhs[2] * rhs);
123 friend constexpr t_vec3<T> operator*(T lhs,
const t_vec3<T>& rhs)
125 return t_vec3<T>(lhs * rhs[0], lhs * rhs[1], lhs * rhs[2]);
128 inline t_vec3& operator*=(
const t_vec3& rhs)
130 value[0] *= rhs.value[0];
131 value[1] *= rhs.value[1];
132 value[2] *= rhs.value[2];
136 inline t_vec3& operator/=(value_type rhs)
138 if constexpr (std::is_floating_point_v<value_type>)
140 value_type inv = numbers<value_type>::one() / rhs;
154 explicit operator bool()
const noexcept {
return value[0] != numbers<value_type>::zero() || value[1] != numbers<value_type>::zero() || value[2] != numbers<value_type>::zero(); }
167 VSG_type_name(vsg::vec3);
168 VSG_type_name(vsg::dvec3);
169 VSG_type_name(vsg::ldvec3);
170 VSG_type_name(vsg::bvec3);
171 VSG_type_name(vsg::svec3);
172 VSG_type_name(vsg::ivec3);
173 VSG_type_name(vsg::ubvec3);
174 VSG_type_name(vsg::usvec3);
175 VSG_type_name(vsg::uivec3);
180 return lhs[0] == rhs[0] && lhs[1] == rhs[1] && lhs[2] == rhs[2];
184 constexpr bool operator!=(
const t_vec3<T>& lhs,
const t_vec3<T>& rhs)
186 return lhs[0] != rhs[0] || lhs[1] != rhs[1] || lhs[2] != rhs[2];
192 if (lhs[0] < rhs[0])
return true;
193 if (lhs[0] > rhs[0])
return false;
194 if (lhs[1] < rhs[1])
return true;
195 if (lhs[1] > rhs[1])
return false;
196 return lhs[2] < rhs[2];
202 return t_vec3<T>(lhs[0] - rhs[0], lhs[1] - rhs[1], lhs[2] - rhs[2]);
214 return t_vec3<T>(lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2]);
220 return t_vec3<T>(lhs[0] * rhs[0], lhs[1] * rhs[1], lhs[2] * rhs[2]);
226 if constexpr (std::is_floating_point_v<T>)
228 T inv = numbers<T>::one() / rhs;
229 return t_vec3<T>(lhs[0] * inv, lhs[1] * inv, lhs[2] * inv);
233 return t_vec3<T>(lhs[0] / rhs, lhs[1] / rhs, lhs[2] / rhs);
240 return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
246 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
252 return v / length(v);
258 return lhs[0] * rhs[0] + lhs[1] * rhs[1] + lhs[2] * rhs[2];
264 return t_vec3<T>(lhs[1] * rhs[2] - rhs[1] * lhs[2],
265 lhs[2] * rhs[0] - rhs[2] * lhs[0],
266 lhs[0] * rhs[1] - rhs[0] * lhs[1]);
272 T one_minus_r = numbers<T>::one() - r;
273 return t_vec3<T>(start[0] * one_minus_r + end[0] * r,
274 start[1] * one_minus_r + end[1] * r,
275 start[2] * one_minus_r + end[2] * r);
282 auto abs_x = fabs(v.x);
283 auto abs_y = fabs(v.y);
284 auto abs_z = fabs(v.z);
287 if (abs_x < abs_z)
return {numbers<T>::zero(), v.z, -v.y};
289 else if (abs_y < abs_z)
291 return {-v.z, numbers<T>::zero(), v.x};
293 return {v.y, -v.x, numbers<T>::zero()};
298#if defined(__clang__)
299# pragma clang diagnostic pop
302# pragma GCC diagnostic pop
t_vec2 template class that represents a 2D vector
Definition vec2.h:39
t_vec3 template class that represents a 3D vector
Definition vec3.h:34