SVector4.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <ionConfig.h>
5 
6 #include "SVector.h"
7 #include "SVector3.h"
8 
9 
12 template <typename T>
13 class SVector4 : public SVector<T, 4, SVector4<T> >
14 {
15 
16 public:
17 
20 
21  T & X, & Y, & Z, & W;
22 
25  : X(Values[0]), Y(Values[1]), Z(Values[2]), W(Values[3])
26  {
27  set((T) 0);
28  }
29 
31  SVector4(T const in)
32  : X(Values[0]), Y(Values[1]), Z(Values[2]), W(Values[3])
33  {
34  set(in);
35  }
36 
38  SVector4(T const x, T const y, T const z, T const w)
39  : X(Values[0]), Y(Values[1]), Z(Values[2]), W(Values[3])
40  {
41  Values[0] = x;
42  Values[1] = y;
43  Values[2] = z;
44  Values[3] = w;
45  }
46 
48  template <typename U>
49  SVector4(glm::tvec4<U, glm::defaultp> const & v)
50  : X(Values[0]), Y(Values[1]), Z(Values[2]), W(Values[3])
51  {
52  Values[0] = (T) v.x;
53  Values[1] = (T) v.y;
54  Values[2] = (T) v.z;
55  Values[3] = (T) v.w;
56  }
57 
59  SVector4(SVector4<T> const & vec)
60  : X(Values[0]), Y(Values[1]), Z(Values[2]), W(Values[3])
61  {
62  set(vec);
63  }
64 
66  template <typename U, u32 OtherDimension>
68  : X(Values[0]), Y(Values[1]), Z(Values[2]), W(Values[3])
69  {
70  set(vec);
71  }
72 
74  SVector4(SVectorBase<T, 3> const & vec, T const W = 1)
75  : X(Values[0]), Y(Values[1]), Z(Values[2]), W(Values[3])
76  {
77  Values[0] = vec[0];
78  Values[1] = vec[1];
79  Values[2] = vec[2];
80  Values[3] = W;
81  }
82 
85  {
86  set(vec);
87 
88  return * this;
89  }
90 
92  template <typename U, u32 OtherDimension>
94  {
95  set(vec);
96 
97  return * this;
98  }
99 
100  glm::vec4 const ToGLM() const
101  {
102  return glm::vec4(X, Y, Z, W);
103  }
104 
105  static SVector4<T> FromGLM(glm::vec4 const & Vec)
106  {
107  return SVector4<T>(Vec.x, Vec.y, Vec.z, Vec.w);
108  }
109 
110  void Transform(glm::mat4 const & mat)
111  {
112  glm::vec4 v = ToGLM();
113  v = mat * v;
114  *this = FromGLM(v);
115  }
116 
117  SVector4<T> GetTransformed(glm::mat4 const & mat) const
118  {
119  glm::vec4 v = ToGLM();
120  v = mat * v;
121  return FromGLM(v);
122  }
123 
124  vec2<T> XY() const
125  {
126  return vec2<T>(X, Y);
127  }
128 
129  vec2<T> XZ() const
130  {
131  return vec2<T>(X, Z);
132  }
133 
134  vec2<T> XW() const
135  {
136  return vec2<T>(X, W);
137  }
138 
139  vec2<T> YZ() const
140  {
141  return vec2<T>(Y, Z);
142  }
143 
144  vec2<T> ZW() const
145  {
146  return vec2<T>(Z, W);
147  }
148 
149  vec3<T> XYZ() const
150  {
151  return vec3<T>(Values[0], Values[1], Values[2]);
152  }
153 
154 };
155 
156 
161 
162 typedef SVector4f vec4f;
163 typedef SVector4d vec4d;
164 typedef SVector4i vec4i;
165 typedef SVector4u vec4u;
166 
SVector4< f32 > SVector4f
Definition: SVector4.h:157
SVector4< s32 > SVector4i
Definition: SVector4.h:159
SVector4< u32 > SVector4u
Definition: SVector4.h:160
SVector4f vec4f
Definition: SVector4.h:162
vec3< T > XYZ() const
Definition: SVector4.h:149
3D vector
Definition: SVector3.h:15
SVector4< f64 > SVector4d
Definition: SVector4.h:158
T Values[Dimension]
Definition: SVector.h:23
2D vector
Definition: SVector2.h:11
SVector4i vec4i
Definition: SVector4.h:164
T & X
Definition: SVector4.h:21
T & Y
Definition: SVector4.h:21
glm::vec4 const ToGLM() const
Definition: SVector4.h:100
SVector4(glm::tvec4< U, glm::defaultp > const &v)
GLM constructor.
Definition: SVector4.h:49
SVector4< T > GetTransformed(glm::mat4 const &mat) const
Definition: SVector4.h:117
SVector4(SVectorBase< T, 3 > const &vec, T const W=1)
Generic vector constructor.
Definition: SVector4.h:74
SVector4(T const in)
Scalar constructor.
Definition: SVector4.h:31
Definition: SVector.h:8
vec2< T > ZW() const
Definition: SVector4.h:144
void Transform(glm::mat4 const &mat)
Definition: SVector4.h:110
SVector4(T const x, T const y, T const z, T const w)
Explicit constructor.
Definition: SVector4.h:38
vec2< T > XZ() const
Definition: SVector4.h:129
SVector4d vec4d
Definition: SVector4.h:163
static SVector4< T > FromGLM(glm::vec4 const &Vec)
Definition: SVector4.h:105
T & Z
Definition: SVector4.h:21
4D vector
Definition: SVector4.h:13
vec2< T > XY() const
Definition: SVector4.h:124
Definition: SVector.h:114
SVector4u vec4u
Definition: SVector4.h:165
vec2< T > XW() const
Definition: SVector4.h:134
SVector4(SVector4< T > const &vec)
Copy constructor.
Definition: SVector4.h:59
SVector4< T > & operator=(SVector4< T > const &vec)
Assignment operator.
Definition: SVector4.h:84
SVector4()
Default constructor.
Definition: SVector4.h:24
SVector4(SVectorBase< U, OtherDimension > const &vec)
Generic vector constructor.
Definition: SVector4.h:67
T & W
Definition: SVector4.h:21
vec2< T > YZ() const
Definition: SVector4.h:139