nngn
Loading...
Searching...
No Matches
vec3.h
Go to the documentation of this file.
1#ifndef NNGN_MATH_VEC3_H
2#define NNGN_MATH_VEC3_H
3
4#include <cstdint>
5
6#include "vec.h"
7#include "vec2.h"
8
9namespace nngn {
10
11template<typename T>
12struct vec3_base : public vec<vec3_base, T, 3> {
13 T x, y, z;
14 constexpr vec3_base() = default;
15 explicit constexpr vec3_base(T v) : vec3_base{v, v, v} {}
16 constexpr vec3_base(T p_x, T p_y) : vec3_base{p_x, p_y, {}} {}
17 constexpr vec3_base(T p_x, T p_y, T p_z) : x{p_x}, y{p_y}, z{p_z} {}
18 explicit constexpr vec3_base(const vec2_base<T> &v)
19 : vec3_base{v.x, v.y, {}} {}
20 constexpr vec3_base(const vec2_base<T> &v, T p_z)
21 : vec3_base{v.x, v.y, p_z} {}
22 constexpr vec3_base(T p_x, const vec2_base<T> &v)
23 : vec3_base{p_x, v[0], v[1]} {}
24#define S(v0, v1) \
25 constexpr vec2_base<T> v0 ## v1() const { return {this->v0, this->v1}; }
26 S(x,x) S(x,y) S(x,z)
27 S(y,x) S(y,y) S(y,z)
28 S(z,x) S(z,y) S(z,z)
29#undef S
30#define S(v0, v1, v2) \
31 constexpr vec3_base<T> v0 ## v1 ## v2() const \
32 { return {this->v0, this->v1, this->v2}; }
33 S(x,x,x) S(x,x,y) S(x,x,z)
34 S(x,y,x) S(x,y,y) S(x,y,z)
35 S(x,z,x) S(x,z,y) S(x,z,z)
36 S(y,x,x) S(y,x,y) S(y,x,z)
37 S(y,y,x) S(y,y,y) S(y,y,z)
38 S(y,z,x) S(y,z,y) S(y,z,z)
39 S(z,x,x) S(z,x,y) S(z,x,z)
40 S(z,y,x) S(z,y,y) S(z,y,z)
41 S(z,z,x) S(z,z,y) S(z,z,z)
42#undef S
43};
44
45template<typename T>
46struct vec_type<T, 3> : std::type_identity<vec3_base<T>> {};
47
53
54static_assert(offsetof(ivec3, y) == sizeof(ivec3::type));
55static_assert(offsetof(uvec3, y) == sizeof(uvec3::type));
56static_assert(offsetof( vec3, y) == sizeof(vec3::type));
57static_assert(offsetof(dvec3, y) == sizeof(dvec3::type));
58static_assert(offsetof(ivec3, z) == sizeof(ivec3::type) * 2);
59static_assert(offsetof(uvec3, z) == sizeof(uvec3::type) * 2);
60static_assert(offsetof( vec3, z) == sizeof( vec3::type) * 2);
61static_assert(offsetof(dvec3, z) == sizeof(dvec3::type) * 2);
62
63}
64
65#endif
#define T(f0, f1, f2)
Definition audio.cpp:7
v[1]
Definition math.lua:22
Definition vec2.h:11
Definition vec3.h:12
constexpr vec3_base(T p_x, T p_y)
Definition vec3.h:16
T z
Definition vec3.h:13
constexpr vec3_base(const vec2_base< T > &v)
Definition vec3.h:18
T x
Definition vec3.h:13
constexpr vec3_base()=default
constexpr vec3_base(const vec2_base< T > &v, T p_z)
Definition vec3.h:20
constexpr vec3_base(T p_x, T p_y, T p_z)
Definition vec3.h:17
constexpr vec3_base(T p_x, const vec2_base< T > &v)
Definition vec3.h:22
T y
Definition vec3.h:13
constexpr vec3_base(T v)
Definition vec3.h:15
Definition vec.h:16
Definition vec.h:22
T type
Definition vec.h:23
#define S(v0, v1)
Definition vec3.h:24