7 #ifndef __math_Vector4_h__ 8 #define __math_Vector4_h__ 13 typedef Vector<4,F64> Vector4d;
14 typedef Vector<4,F32> Vector4f;
15 typedef Vector<4,FE_UWORD> Vector4u;
16 typedef Vector<4,int> Vector4i;
17 typedef Vector<4,Real> Vector4;
29 { m_array[0]=vector[0];
32 m_array[3]=vector[3]; }
34 operator const T*(void)
const 62 Vector(T x,T y,T z=T(0),T w=T(0))
67 { memcpy(m_data,other.m_data,4*
sizeof(T));
70 {
return set4(other[0],other[1],other[2],other[3]); }
74 {
return set4((T)other[0],(T)other[1],(T)other[2],
79 { memcpy(m_data,other.m_data,3*
sizeof(T));
83 {
return set4(other[0],other[1],other[2],T(0)); }
87 {
return set4((T)other[0],(T)other[1],
92 { memcpy(m_data,other.m_data,2*
sizeof(T));
97 {
return set4(other[0],other[1],T(0),T(0)); }
101 {
return set4((T)other[0],(T)other[1],
105 #if FE_EXPLOIT_MEMCPY 106 { memcpy(m_data,array,4*
sizeof(T));
109 {
return set4(array[0],array[1],array[2],array[3]); }
113 const T& operator[](U32 index)
const;
114 T& operator[](U32 index);
116 Vector<4,T>& set4(T x=T(0),T y=T(0),T z=T(0),T w=T(0));
118 void get4(T array[4]);
120 const Raw temp(
void)
const 130 return m_data[index];
140 return m_data[index];
168 r.set4(T(0),T(0),T(0),T(0));
175 template<
typename T,
typename U>
178 r.set4(x,T(0),T(0),T(0));
185 template<
typename T,
typename U,
typename V>
188 r.set4(x,y,T(0),T(0));
195 template<
typename T,
typename U,
typename V,
typename W>
205 template<
typename T,
typename U,
typename V,
typename W,
typename X>
215 template<
typename T,
typename U>
242 return set(lhs,lhs[0]+rhs[0],lhs[1]+rhs[1],lhs[2]+rhs[2],lhs[3]+rhs[3]);
251 return set(lhs,lhs[0]-rhs[0],lhs[1]-rhs[1],lhs[2]-rhs[2],lhs[3]-rhs[3]);
261 return set(v,-rhs[0],-rhs[1],-rhs[2],-rhs[3]);
270 return set(lhs,lhs[0]*rhs[0],lhs[1]*rhs[1],lhs[2]*rhs[2],lhs[3]*rhs[3]);
276 template<
typename T,
typename U>
279 return set(lhs,lhs[0]*scale,lhs[1]*scale,lhs[2]*scale,lhs[3]*scale);
288 return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3]*rhs[3];
297 return rhs[0]*rhs[0]+rhs[1]*rhs[1]+rhs[2]*rhs[2]+rhs[3]*rhs[3];
318 feX(
"unit(Vector<4,T>)",
"attempt to normalize zero magnitude vector");
320 return vector*T(1.0/mag);
332 return vector*(T(1)/mag);
345 feX(
"normal",
"attempt to normalize zero magnitude vector");
346 return vector*=T(1.0/mag);
370 s.
sPrintf(
"%g %g %g %g",vector[0],vector[1],vector[2],vector[3]);
381 return set(v,lhs[0]+rhs[0],lhs[1]+rhs[1],lhs[2]+rhs[2],lhs[3]+rhs[3]);
391 return set(v,lhs[0]-rhs[0],lhs[1]-rhs[1],lhs[2]-rhs[2],lhs[3]-rhs[3]);
401 return set(v,lhs[0]*rhs[0],lhs[1]*rhs[1],lhs[2]*rhs[2],lhs[3]*rhs[3]);
407 template<
typename T,
typename U>
409 typename boost::enable_if<boost::is_arithmetic<U>,
Vector<4,T> >::type
413 return set(v,lhs*rhs[0],lhs*rhs[1],lhs*rhs[2],lhs*rhs[3]);
419 template<
typename T,
typename U>
421 typename boost::enable_if<boost::is_arithmetic<U>,
Vector<4,T> >::type
425 return set(v,lhs[0]*rhs,lhs[1]*rhs,lhs[2]*rhs,lhs[3]*rhs);
435 set(r, lhs[1] * rhs[2] - lhs[2] * rhs[1],
436 lhs[2] * rhs[0] - lhs[0] * rhs[2],
437 lhs[0] * rhs[1] - lhs[1] * rhs[0]);
448 return cross3(v, lhs, rhs);
String print(const Vector< 4, T > &vector)
Return text describing the Vector's state.
Definition: Vector4.h:367
Vector< 4, T > unitSafe(const Vector< 4, T > &vector)
Return the Vector direction scaled to unit length with zero check.
Definition: Vector4.h:327
Vector< 4, T > operator*(const Vector< 4, T > &lhs, const Vector< 4, T > &rhs)
Return a Vector of products of each component.
Definition: Vector4.h:398
Vector< 4, T > & normalize(Vector< 4, T > &vector)
Scale Vector to unit length.
Definition: Vector4.h:341
Vector< 4, T > operator+(const Vector< 4, T > &lhs, const Vector< 4, T > &rhs)
Return sum of Vectors.
Definition: Vector4.h:378
T dot(const Vector< 4, T > &lhs, const Vector< 4, T > &rhs)
Return dot product.
Definition: Vector4.h:286
kernel
Definition: namespace.dox:3
Vector< 4, T > & operator-=(Vector< 4, T > &lhs, const Vector< 4, T > &rhs)
Subtract from Vector in place.
Definition: Vector4.h:249
Vector< 4, T > & operator*=(Vector< 4, T > &lhs, const Vector< 4, T > &rhs)
Independently scale components in place.
Definition: Vector4.h:268
Dense vector - size fixed by template.
Definition: Vector.h:19
boost::enable_if< boost::is_arithmetic< U >, Vector< 4, T > >::type operator*(const U lhs, const Vector< 4, T > &rhs)
Return a uniformly scale Vector (pre)
Definition: Vector4.h:410
T magnitude(const Vector< 4, T > &rhs)
Return the Vector length.
Definition: Vector4.h:304
Vector< 4, T > & setAt(Vector< 4, T > &lhs, U32 index, U value)
Set indexed component.
Definition: Vector4.h:216
Vector< 4, T > operator-(const Vector< 4, T > &rhs)
Negate the Vector.
Definition: Vector4.h:258
String & sPrintf(const char *fmt,...)
Populate the string in the manner of sprintf().
Definition: String.cc:529
T magnitudeSquared(const Vector< 4, T > &rhs)
Return square of the Vector length.
Definition: Vector4.h:295
Automatically reference-counted string container.
Definition: String.h:128
Vector< 4, T > & cross3(Vector< 4, T > &r, const Vector< 4, T > &lhs, const Vector< 4, T > &rhs)
Return a cross product of Vectors.
Definition: Vector4.h:432
boost::enable_if< boost::is_arithmetic< U >, Vector< 4, T > >::type operator*(const Vector< 4, T > &lhs, const U rhs)
Return a uniformly scale Vector (post)
Definition: Vector4.h:422
Vector< 4, T > unit(const Vector< 4, T > &vector)
Return the Vector direction scaled to unit length.
Definition: Vector4.h:313
Vector< 4, T > operator-(const Vector< 4, T > &lhs, const Vector< 4, T > &rhs)
Return difference of Vectors.
Definition: Vector4.h:388
Vector< 4, T > & normalizeSafe(Vector< 4, T > &vector)
Scale Vector to unit length with zero check.
Definition: Vector4.h:353
T magnitude(const Vector< N, T > &rhs)
Frobenius norm operation.
Definition: Vector.h:785
T magnitudeSquared(const Vector< N, T > &rhs)
Square of the length.
Definition: Vector.h:794
Vector< 4, T > cross3(const Vector< 4, T > &lhs, const Vector< 4, T > &rhs)
Set the Vector as a cross product of Vectors.
Definition: Vector4.h:445
U32 size(const Vector< 4, T > &lhs)
Return the number of elements.
Definition: Vector4.h:231
Partially specialized 4-component vector intended for spatial use.
Definition: Vector4.h:21
Vector< 4, T > & operator*=(Vector< 4, T > &lhs, U scale)
Uniformly scale components in place.
Definition: Vector4.h:277
Vector< 4, T > & operator+=(Vector< 4, T > &lhs, const Vector< 4, T > &rhs)
Add to Vector in place.
Definition: Vector4.h:240