SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLVec4< T > Class Template Reference

4D vector template class for standard 4D vector algebra. More...

#include <SLVec4.h>

Public Member Functions

 SLVec4 ()
 
 SLVec4 (const T V)
 
 SLVec4 (const T X, const T Y, const T Z=0, const T W=1)
 
 SLVec4 (const T v[4])
 
 SLVec4 (const SLVec2< T > &v)
 
 SLVec4 (const SLVec3< T > &v)
 
 SLVec4 (const SLVec4< T > &v)
 
 SLVec4 (const SLstring &fourFloatsWithDelimiter)
 
void set (const T X, const T Y, const T Z, const T W=1)
 
void set (const T xyz)
 
void set (const T v[4])
 
void set (const SLVec2< T > &v)
 
void set (const SLVec3< T > &v)
 
void set (const SLVec4< T > &v)
 
SLbool operator== (const SLVec4 &v) const
 
SLbool operator!= (const SLVec4 &v) const
 
SLbool operator<= (const SLVec4 &v) const
 
SLbool operator>= (const SLVec4 &v) const
 
SLbool operator< (const SLVec4 &v) const
 
SLbool operator> (const SLVec4 &v) const
 
SLbool operator<= (const T v) const
 
SLbool operator>= (const T v) const
 
SLbool operator< (const T v) const
 
SLbool operator> (const T v) const
 
SLVec4 operator+ (const SLVec4 &v) const
 
SLVec4 operator- (const SLVec4 &v) const
 
SLVec4 operator- () const
 
operator* (const SLVec4 &v) const
 
SLVec4 operator* (const T s) const
 
SLVec4 operator/ (const T s) const
 
SLVec4 operator& (const SLVec4 &v) const
 
SLVec4operator= (const SLVec2< T > &v)
 
SLVec4operator= (const SLVec3< T > &v)
 
SLVec4operator= (const SLVec4 &v)
 
SLVec4operator+= (const SLVec4 &v)
 
SLVec4operator+= (const SLVec3< T > &v)
 
SLVec4operator-= (const SLVec4 &v)
 
SLVec4operator-= (const SLVec3< T > &v)
 
SLVec4operator*= (const T s)
 
SLVec4operator/= (const T s)
 
SLVec4operator&= (const SLVec4 &v)
 
SLVec4operator&= (const SLVec3< T > &v)
 
void add (const SLVec4 &a, const SLVec4 &b)
 
void sub (const SLVec4 &a, const SLVec4 &b)
 
void scale (const T s)
 
dot (const SLVec4 &v)
 
void cross (const SLVec4 &a, const SLVec4 &b)
 
SLVec3< T > vec3 () const
 
SLVec2< T > vec2 () const
 
length () const
 
lengthSqr () const
 
SLVec4normalize ()
 
void wdiv ()
 
void clampMinMax (const T min, const T max)
 
diff (const SLVec4 &v)
 
diffRGB (const SLVec4 &v)
 
void mix (const SLVec4 &a, const SLVec4 &b, const T factor_b)
 
minXYZ ()
 
maxXYZ ()
 
minXYZW ()
 
maxXYZW ()
 
SLint maxComp ()
 
SLint minComp ()
 
SLbool isZero ()
 
void gammaCorrect (T oneOverGamma)
 Gamma correction. More...
 
void print (const SLchar *str=nullptr)
 
SLstring toString (SLstring delimiter=", ")
 Conversion to string. More...
 
void fromString (const SLstring &fourFloatsWithDelimiter, SLchar delimiter=',')
 Conversion from string. More...
 
void hsva2rgba (const SLVec4 &hsva)
 HSVA to RGBA color conversion (http://www.rapidtables.com/convert/color/hsv-to-rgb.htm) More...
 

Public Attributes

union {
   struct {
      T   x
 
      T   y
 
      T   z
 
      T   w
 
   } 
 
   struct {
      T   r
 
      T   g
 
      T   b
 
      T   a
 
   } 
 
   struct {
      T   comp [4]
 
   } 
 
}; 
 

Static Public Attributes

static SLVec4 ZERO = SLVec4<T>(0.0f, 0.0f, 0.0f, 1.0f)
 
static SLVec4 BLACK = SLVec4<T>(0.0f, 0.0f, 0.0f, 1.0f)
 
static SLVec4 GRAY = SLVec4<T>(0.5f, 0.5f, 0.5f, 1.0f)
 
static SLVec4 WHITE = SLVec4<T>(1.0f, 1.0f, 1.0f, 1.0f)
 
static SLVec4 RED = SLVec4<T>(1.0f, 0.0f, 0.0f, 1.0f)
 
static SLVec4 GREEN = SLVec4<T>(0.0f, 1.0f, 0.0f, 1.0f)
 
static SLVec4 BLUE = SLVec4<T>(0.0f, 0.0f, 1.0f, 1.0f)
 
static SLVec4 YELLOW = SLVec4<T>(1.0f, 1.0f, 0.0f, 1.0f)
 
static SLVec4 CYAN = SLVec4<T>(0.0f, 1.0f, 1.0f, 1.0f)
 
static SLVec4 MAGENTA = SLVec4<T>(1.0f, 0.0f, 1.0f, 1.0f)
 

Friends

SLVec4 operator* (T s, const SLVec4 &v)
 
std::ostream & operator<< (std::ostream &output, const SLVec4 &v)
 

Detailed Description

template<class T>
class SLVec4< T >

4D vector template class for standard 4D vector algebra.

4D vector template class with type definitions for 4D vectors and colors:
Use SLVec4f for a specific float type vector
Use SLVec4d for a specific double type vector
Use SLVec4r for a precision independent real type.

Definition at line 28 of file SLVec4.h.

Constructor & Destructor Documentation

◆ SLVec4() [1/8]

template<class T >
SLVec4< T >::SLVec4 ( )
inline

Definition at line 37 of file SLVec4.h.

37 {x=0;y=0;z=0;w=0;}
T w
Definition: SLVec4.h:32
T z
Definition: SLVec4.h:32
T y
Definition: SLVec4.h:32
T x
Definition: SLVec4.h:32

◆ SLVec4() [2/8]

template<class T >
SLVec4< T >::SLVec4 ( const T  V)
inlineexplicit

Definition at line 38 of file SLVec4.h.

38 {x=V; y=V; z=V; w=1;}

◆ SLVec4() [3/8]

template<class T >
SLVec4< T >::SLVec4 ( const T  X,
const T  Y,
const T  Z = 0,
const T  W = 1 
)
inline

Definition at line 39 of file SLVec4.h.

42  {x=X; y=Y; z=Z; w=W;}

◆ SLVec4() [4/8]

template<class T >
SLVec4< T >::SLVec4 ( const T  v[4])
inlineexplicit

Definition at line 43 of file SLVec4.h.

43 {x=v[0]; y=v[1]; z=v[2]; w=v[3];}

◆ SLVec4() [5/8]

template<class T >
SLVec4< T >::SLVec4 ( const SLVec2< T > &  v)
inlineexplicit

Definition at line 44 of file SLVec4.h.

44 {x=v.x; y=v.y; z=0; w=1;}
T y
Definition: SLVec2.h:30
T x
Definition: SLVec2.h:30

◆ SLVec4() [6/8]

template<class T >
SLVec4< T >::SLVec4 ( const SLVec3< T > &  v)
inlineexplicit

Definition at line 45 of file SLVec4.h.

45 {x=v.x; y=v.y; z=v.z; w=1;}
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43
T z
Definition: SLVec3.h:43

◆ SLVec4() [7/8]

template<class T >
SLVec4< T >::SLVec4 ( const SLVec4< T > &  v)
inline

Definition at line 46 of file SLVec4.h.

46 {x=v.x; y=v.y; z=v.z; w=v.w;}

◆ SLVec4() [8/8]

template<class T >
SLVec4< T >::SLVec4 ( const SLstring fourFloatsWithDelimiter)
inlineexplicit

Definition at line 47 of file SLVec4.h.

47 {fromString(fourFloatsWithDelimiter);}
void fromString(const SLstring &fourFloatsWithDelimiter, SLchar delimiter=',')
Conversion from string.
Definition: SLVec4.h:181

Member Function Documentation

◆ add()

template<class T >
void SLVec4< T >::add ( const SLVec4< T > &  a,
const SLVec4< T > &  b 
)
inline

Definition at line 100 of file SLVec4.h.

101  {x=a.x+b.x; y=a.y+b.y, z=a.z+b.z; w=a.w+b.w;}
T b
Definition: SLVec4.h:33
T a
Definition: SLVec4.h:33

◆ clampMinMax()

template<class T >
void SLVec4< T >::clampMinMax ( const T  min,
const T  max 
)
inline

Definition at line 119 of file SLVec4.h.

120  {x = (x>max)?max : (x<min)?min : x;
121  y = (y>max)?max : (y<min)?min : y;
122  z = (z>max)?max : (z<min)?min : z;
123  w = 1;}

◆ cross()

template<class T >
void SLVec4< T >::cross ( const SLVec4< T > &  a,
const SLVec4< T > &  b 
)
inline

Definition at line 106 of file SLVec4.h.

107  {x = a.y*b.z - a.z*b.y;
108  y = a.z*b.x - a.x*b.z;
109  z = a.x*b.y - a.y*b.x;
110  w = 1;}

◆ diff()

template<class T >
T SLVec4< T >::diff ( const SLVec4< T > &  v)
inline

Definition at line 124 of file SLVec4.h.

124  {return Utils::abs(x-v.x) +
125  Utils::abs(y-v.y) +
126  Utils::abs(z-v.z) +
127  Utils::abs(w-v.w);}
T abs(T a)
Definition: Utils.h:249

◆ diffRGB()

template<class T >
T SLVec4< T >::diffRGB ( const SLVec4< T > &  v)
inline

Definition at line 128 of file SLVec4.h.

128  {return Utils::abs(x-v.x) +
129  Utils::abs(y-v.y) +
130  Utils::abs(z-v.z);}

◆ dot()

template<class T >
T SLVec4< T >::dot ( const SLVec4< T > &  v)
inline

Definition at line 105 of file SLVec4.h.

105 {return x*v.x+y*v.y+z*v.z+w*v.w;}

◆ fromString()

template<class T >
void SLVec4< T >::fromString ( const SLstring fourFloatsWithDelimiter,
SLchar  delimiter = ',' 
)
inline

Conversion from string.

Definition at line 181 of file SLVec4.h.

182  { SLVstring components;
183  Utils::splitString(fourFloatsWithDelimiter, delimiter, components);
184  float f[4] = {0.0, 0.0f, 0.0f, 1.0f};
185  for (SLuint i=0; i<components.size(); ++i)
186  f[i] = (SLfloat)atof(components[i].c_str());
187  x = f[0]; y = f[1]; z = f[2]; w = f[3];
188  }
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
vector< SLstring > SLVstring
Definition: SL.h:201
void splitString(const string &s, char delimiter, vector< string > &splits)
Splits an input string at a delimiter character into a string vector.
Definition: Utils.cpp:152

◆ gammaCorrect()

template<class T >
void SLVec4< T >::gammaCorrect ( oneOverGamma)
inline

Gamma correction.

Definition at line 163 of file SLVec4.h.

163  {x= pow(x,oneOverGamma);
164  y= pow(y,oneOverGamma);
165  z= pow(z,oneOverGamma);}

◆ hsva2rgba()

template<class T >
void SLVec4< T >::hsva2rgba ( const SLVec4< T > &  hsva)
inline

HSVA to RGBA color conversion (http://www.rapidtables.com/convert/color/hsv-to-rgb.htm)

Definition at line 191 of file SLVec4.h.

192  {
193  T h = fmod(fmod(hsva.x, Utils::TWOPI) + Utils::TWOPI, Utils::TWOPI); // 0 deg <= H <= 360 deg
194  T s = Utils::clamp(hsva.y, 0.0f, 1.0f);
195  T v = Utils::clamp(hsva.z, 0.0f, 1.0f);
196  T a = Utils::clamp(hsva.w, 0.0f, 1.0f);
197 
198  T c = v * s;
199  T x = c * (1.0f - (T)fabs((T)fmod(h*3.0f / Utils::PI, 2.0f) - 1.0f));
200  T m = v - c;
201 
202  switch (SLint(floor(h*3.0f * Utils::ONEOVERPI)))
203  { case 0: return set(m + c, m + x, m , a); // [ 0 deg, 60 deg]
204  case 1: return set(m + x, m + c, m , a); // [ 60 deg,120 deg]
205  case 2: return set(m , m + c, m + x, a); // [120 deg,180 deg]
206  case 3: return set(m , m + x, m + c, a); // [180 deg,240 deg]
207  case 4: return set(m + x, m , m + c, a); // [240 deg,300 deg]
208  case 5: return set(m + c, m , m + x, a); // [300 deg,360 deg]
209  }
210  }
int SLint
Definition: SL.h:170
SLScene * s
Definition: SLScene.h:31
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
void set(const T X, const T Y, const T Z, const T W=1)
Definition: SLVec4.h:49
T clamp(T a, T min, T max)
Definition: Utils.h:253
static const float ONEOVERPI
Definition: Utils.h:241
T floor(T a)
Definition: Utils.h:246
static const float PI
Definition: Utils.h:237
static const float TWOPI
Definition: Utils.h:240

◆ isZero()

template<class T >
SLbool SLVec4< T >::isZero ( )
inline

Definition at line 160 of file SLVec4.h.

160 {return (x==0 && y==0 && z==0 && w==0);}

◆ length()

template<class T >
T SLVec4< T >::length ( ) const
inline

Definition at line 113 of file SLVec4.h.

113 {return (T)sqrt(x*x+y*y+z*z+w*w);}

◆ lengthSqr()

template<class T >
T SLVec4< T >::lengthSqr ( ) const
inline

Definition at line 114 of file SLVec4.h.

114 {return (x*x+y*y+z*z+w*w);}

◆ maxComp()

template<class T >
SLint SLVec4< T >::maxComp ( )
inline

Definition at line 152 of file SLVec4.h.

152  {if (x>=y && x>=z && x>=w) return 0;
153  else if (y>=z && y>=w) return 1;
154  else if (z>=w) return 2;
155  else return 3;}

◆ maxXYZ()

template<class T >
T SLVec4< T >::maxXYZ ( )
inline

Definition at line 141 of file SLVec4.h.

141  {if (x>=y && x>=z) return x;
142  else if (y>=z) return y;
143  else return z;}

◆ maxXYZW()

template<class T >
T SLVec4< T >::maxXYZW ( )
inline

Definition at line 148 of file SLVec4.h.

148  {if (x>=y && x>=z && x>=w) return x;
149  else if (y>=z && y>=w) return y;
150  else if (z>=w) return z;
151  else return w;}

◆ minComp()

template<class T >
SLint SLVec4< T >::minComp ( )
inline

Definition at line 156 of file SLVec4.h.

156  {if (x<=y && x<=z && x<=w) return 0;
157  else if (y<=z && y<=w) return 1;
158  else if (z<=w) return 2;
159  else return 3;}

◆ minXYZ()

template<class T >
T SLVec4< T >::minXYZ ( )
inline

Definition at line 138 of file SLVec4.h.

138  {if (x<=y && x<=z) return x;
139  else if (y<=z) return y;
140  else return z;}

◆ minXYZW()

template<class T >
T SLVec4< T >::minXYZW ( )
inline

Definition at line 144 of file SLVec4.h.

144  {if (x<=y && x<=z && x<=w) return x;
145  else if (y<=z && y<=w) return y;
146  else if (z<=w) return z;
147  else return w;}

◆ mix()

template<class T >
void SLVec4< T >::mix ( const SLVec4< T > &  a,
const SLVec4< T > &  b,
const T  factor_b 
)
inline

Definition at line 131 of file SLVec4.h.

133  {T factor_a = 1-factor_b;
134  x = a.x*factor_a + b.x*factor_b;
135  y = a.y*factor_a + b.y*factor_b;
136  z = a.z*factor_a + b.z*factor_b;
137  w = a.w*factor_a + b.w*factor_b;}

◆ normalize()

template<class T >
SLVec4& SLVec4< T >::normalize ( )
inline

Definition at line 115 of file SLVec4.h.

115  {T L = length();
116  if (L>0){x/=L; y/=L; z/=L; w/=L;}
117  return *this;}
T length() const
Definition: SLVec4.h:113

◆ operator!=()

template<class T >
SLbool SLVec4< T >::operator!= ( const SLVec4< T > &  v) const
inline

Definition at line 60 of file SLVec4.h.

60 {return (x!=v.x || y!=v.y || z!=v.z || w!=v.w);}

◆ operator&()

template<class T >
SLVec4 SLVec4< T >::operator& ( const SLVec4< T > &  v) const
inline

Definition at line 78 of file SLVec4.h.

78 {return SLVec4(x*v.x, y*v.y, z*v.z, w*v.w);}
SLVec4()
Definition: SLVec4.h:37

◆ operator&=() [1/2]

template<class T >
SLVec4& SLVec4< T >::operator&= ( const SLVec3< T > &  v)
inline

Definition at line 97 of file SLVec4.h.

97 {x*=v.x; y*=v.y; z*=v.z; w*=1; return *this;}

◆ operator&=() [2/2]

template<class T >
SLVec4& SLVec4< T >::operator&= ( const SLVec4< T > &  v)
inline

Definition at line 96 of file SLVec4.h.

96 {x*=v.x; y*=v.y; z*=v.z; w*=v.w; return *this;}

◆ operator*() [1/2]

template<class T >
T SLVec4< T >::operator* ( const SLVec4< T > &  v) const
inline

Definition at line 75 of file SLVec4.h.

75 {return x*v.x+y*v.y+z*v.z+w*v.w;}

◆ operator*() [2/2]

template<class T >
SLVec4 SLVec4< T >::operator* ( const T  s) const
inline

Definition at line 76 of file SLVec4.h.

76 {return SLVec4(x*s, y*s, z*s);}

◆ operator*=()

template<class T >
SLVec4& SLVec4< T >::operator*= ( const T  s)
inline

Definition at line 94 of file SLVec4.h.

94 {x*=s; y*=s; z*=s; w*=s; return *this;}

◆ operator+()

template<class T >
SLVec4 SLVec4< T >::operator+ ( const SLVec4< T > &  v) const
inline

Definition at line 72 of file SLVec4.h.

72 {return SLVec4(x+v.x, y+v.y, z+v.z, w+v.w);}

◆ operator+=() [1/2]

template<class T >
SLVec4& SLVec4< T >::operator+= ( const SLVec3< T > &  v)
inline

Definition at line 91 of file SLVec4.h.

91 {x+=v.x; y+=v.y; z+=v.z; w+=0; return *this;}

◆ operator+=() [2/2]

template<class T >
SLVec4& SLVec4< T >::operator+= ( const SLVec4< T > &  v)
inline

Definition at line 90 of file SLVec4.h.

90 {x+=v.x; y+=v.y; z+=v.z; w+=v.w; return *this;}

◆ operator-() [1/2]

template<class T >
SLVec4 SLVec4< T >::operator- ( ) const
inline

Definition at line 74 of file SLVec4.h.

74 {return SLVec4(-x, -y, -z, -w);}

◆ operator-() [2/2]

template<class T >
SLVec4 SLVec4< T >::operator- ( const SLVec4< T > &  v) const
inline

Definition at line 73 of file SLVec4.h.

73 {return SLVec4(x-v.x, y-v.y, z-v.z, w-v.w);}

◆ operator-=() [1/2]

template<class T >
SLVec4& SLVec4< T >::operator-= ( const SLVec3< T > &  v)
inline

Definition at line 93 of file SLVec4.h.

93 {x-=v.x; y-=v.y; z-=v.z; w-=0; return *this;}

◆ operator-=() [2/2]

template<class T >
SLVec4& SLVec4< T >::operator-= ( const SLVec4< T > &  v)
inline

Definition at line 92 of file SLVec4.h.

92 {x-=v.x; y-=v.y; z-=v.z; w-=v.w; return *this;}

◆ operator/()

template<class T >
SLVec4 SLVec4< T >::operator/ ( const T  s) const
inline

Definition at line 77 of file SLVec4.h.

77 {return SLVec4(x/s, y/s, z/s, w/s);}

◆ operator/=()

template<class T >
SLVec4& SLVec4< T >::operator/= ( const T  s)
inline

Definition at line 95 of file SLVec4.h.

95 {x/=s; y/=s; z/=s; w/=s; return *this;}

◆ operator<() [1/2]

template<class T >
SLbool SLVec4< T >::operator< ( const SLVec4< T > &  v) const
inline

Definition at line 63 of file SLVec4.h.

63 {return (x<v.x && y<v.y && z<v.z && w<v.w);}

◆ operator<() [2/2]

template<class T >
SLbool SLVec4< T >::operator< ( const T  v) const
inline

Definition at line 67 of file SLVec4.h.

67 {return (x<v && y<v && z<v && w<v);}

◆ operator<=() [1/2]

template<class T >
SLbool SLVec4< T >::operator<= ( const SLVec4< T > &  v) const
inline

Definition at line 61 of file SLVec4.h.

61 {return (x<=v.x && y<=v.y && z<=v.z && w<=v.w);}

◆ operator<=() [2/2]

template<class T >
SLbool SLVec4< T >::operator<= ( const T  v) const
inline

Definition at line 65 of file SLVec4.h.

65 {return (x<=v && y<=v && z<=v && w<=v);}

◆ operator=() [1/3]

template<class T >
SLVec4& SLVec4< T >::operator= ( const SLVec2< T > &  v)
inline

Definition at line 87 of file SLVec4.h.

87 {x=v.x; y=v.y; z=0; w=1; return *this;}

◆ operator=() [2/3]

template<class T >
SLVec4& SLVec4< T >::operator= ( const SLVec3< T > &  v)
inline

Definition at line 88 of file SLVec4.h.

88 {x=v.x; y=v.y; z=v.z; w=1; return *this;}

◆ operator=() [3/3]

template<class T >
SLVec4& SLVec4< T >::operator= ( const SLVec4< T > &  v)
inline

Definition at line 89 of file SLVec4.h.

89 {x=v.x; y=v.y; z=v.z; w=v.w; return *this;}

◆ operator==()

template<class T >
SLbool SLVec4< T >::operator== ( const SLVec4< T > &  v) const
inline

Definition at line 59 of file SLVec4.h.

59 {return (x==v.x && y==v.y && z==v.z && w==v.w);}

◆ operator>() [1/2]

template<class T >
SLbool SLVec4< T >::operator> ( const SLVec4< T > &  v) const
inline

Definition at line 64 of file SLVec4.h.

64 {return (x>v.x && y>v.y && z>v.z && w>v.w);}

◆ operator>() [2/2]

template<class T >
SLbool SLVec4< T >::operator> ( const T  v) const
inline

Definition at line 68 of file SLVec4.h.

68 {return (x>v && y>v && z>v && w>v);}

◆ operator>=() [1/2]

template<class T >
SLbool SLVec4< T >::operator>= ( const SLVec4< T > &  v) const
inline

Definition at line 62 of file SLVec4.h.

62 {return (x>=v.x && y>=v.y && z>=v.z && w>=v.w);}

◆ operator>=() [2/2]

template<class T >
SLbool SLVec4< T >::operator>= ( const T  v) const
inline

Definition at line 66 of file SLVec4.h.

66 {return (x>=v && y>=v && z>=v && w>=v);}

◆ print()

template<class T >
void SLVec4< T >::print ( const SLchar str = nullptr)
inline

Definition at line 167 of file SLVec4.h.

168  { if (str) SL_LOG("%s",str);
169  SL_LOG("% 3.3f, % 3.3f, % 3.3f, % 3.3f",x, y, z, w);
170  }
#define SL_LOG(...)
Definition: SL.h:233

◆ scale()

template<class T >
void SLVec4< T >::scale ( const T  s)
inline

Definition at line 104 of file SLVec4.h.

104 {x*=s; y*=s; z*=s; w*=s;}

◆ set() [1/6]

template<class T >
void SLVec4< T >::set ( const SLVec2< T > &  v)
inline

Definition at line 55 of file SLVec4.h.

55 {x=v.x; y=v.y; z=0; w=1;}

◆ set() [2/6]

template<class T >
void SLVec4< T >::set ( const SLVec3< T > &  v)
inline

Definition at line 56 of file SLVec4.h.

56 {x=v.x; y=v.y; z=v.z; w=1;}

◆ set() [3/6]

template<class T >
void SLVec4< T >::set ( const SLVec4< T > &  v)
inline

Definition at line 57 of file SLVec4.h.

57 {x=v.x; y=v.y; z=v.z; w=v.w;}

◆ set() [4/6]

template<class T >
void SLVec4< T >::set ( const T  v[4])
inline

Definition at line 54 of file SLVec4.h.

54 {x=v[0]; y=v[1]; z=v[2]; w=v[3];}

◆ set() [5/6]

template<class T >
void SLVec4< T >::set ( const T  X,
const T  Y,
const T  Z,
const T  W = 1 
)
inline

Definition at line 49 of file SLVec4.h.

52  {x=X; y=Y; z=Z; w=W;}

◆ set() [6/6]

template<class T >
void SLVec4< T >::set ( const T  xyz)
inline

Definition at line 53 of file SLVec4.h.

53 {x=xyz; y=xyz; z=xyz; w=1;}

◆ sub()

template<class T >
void SLVec4< T >::sub ( const SLVec4< T > &  a,
const SLVec4< T > &  b 
)
inline

Definition at line 102 of file SLVec4.h.

103  {x=a.x-b.x; y=a.y-b.y, z=a.z-b.z; w=a.w-b.w;}

◆ toString()

template<class T >
SLstring SLVec4< T >::toString ( SLstring  delimiter = ", ")
inline

Conversion to string.

Definition at line 173 of file SLVec4.h.

174  { return Utils::toString(x) + delimiter +
175  Utils::toString(y) + delimiter +
176  Utils::toString(z) + delimiter +
178  }
string toString(float f, int roundedDecimals)
Returns a string from a float with max. one trailing zero.
Definition: Utils.cpp:92

◆ vec2()

template<class T >
SLVec2<T> SLVec4< T >::vec2 ( ) const
inline

Definition at line 112 of file SLVec4.h.

112 {return SLVec2<T>(x,y);}
2D vector template class for standard 2D vector algebra.
Definition: SLVec2.h:27

◆ vec3()

template<class T >
SLVec3<T> SLVec4< T >::vec3 ( ) const
inline

Definition at line 111 of file SLVec4.h.

111 {return SLVec3<T>(x,y,z);}
3D vector template class for standard 3D vector algebra.
Definition: SLVec3.h:40

◆ wdiv()

template<class T >
void SLVec4< T >::wdiv ( )
inline

Definition at line 118 of file SLVec4.h.

118 {x/=w; y/=w; z/=w; w=1;}

Friends And Related Function Documentation

◆ operator*

template<class T >
SLVec4 operator* ( s,
const SLVec4< T > &  v 
)
friend

Definition at line 80 of file SLVec4.h.

80 {return SLVec4(v.x*s, v.y*s, v.z*s);}

◆ operator<<

template<class T >
std::ostream& operator<< ( std::ostream &  output,
const SLVec4< T > &  v 
)
friend

Definition at line 83 of file SLVec4.h.

84  {output<<"["<<v.x<<","<<v.y<<","<<v.z<<","<<v.w<<"]"; return output;}

Member Data Documentation

◆ 

union { ... }

◆ a

template<class T >
T SLVec4< T >::a

Definition at line 33 of file SLVec4.h.

◆ b

template<class T >
T SLVec4< T >::b

Definition at line 33 of file SLVec4.h.

◆ BLACK

template<class T >
SLVec4< T > SLVec4< T >::BLACK = SLVec4<T>(0.0f, 0.0f, 0.0f, 1.0f)
static

Definition at line 213 of file SLVec4.h.

◆ BLUE

template<class T >
SLVec4< T > SLVec4< T >::BLUE = SLVec4<T>(0.0f, 0.0f, 1.0f, 1.0f)
static

Definition at line 218 of file SLVec4.h.

◆ comp

template<class T >
T SLVec4< T >::comp[4]

Definition at line 34 of file SLVec4.h.

◆ CYAN

template<class T >
SLVec4< T > SLVec4< T >::CYAN = SLVec4<T>(0.0f, 1.0f, 1.0f, 1.0f)
static

Definition at line 220 of file SLVec4.h.

◆ g

template<class T >
T SLVec4< T >::g

Definition at line 33 of file SLVec4.h.

◆ GRAY

template<class T >
SLVec4< T > SLVec4< T >::GRAY = SLVec4<T>(0.5f, 0.5f, 0.5f, 1.0f)
static

Definition at line 214 of file SLVec4.h.

◆ GREEN

template<class T >
SLVec4< T > SLVec4< T >::GREEN = SLVec4<T>(0.0f, 1.0f, 0.0f, 1.0f)
static

Definition at line 217 of file SLVec4.h.

◆ MAGENTA

template<class T >
SLVec4< T > SLVec4< T >::MAGENTA = SLVec4<T>(1.0f, 0.0f, 1.0f, 1.0f)
static

Definition at line 221 of file SLVec4.h.

◆ r

template<class T >
T SLVec4< T >::r

Definition at line 33 of file SLVec4.h.

◆ RED

template<class T >
SLVec4< T > SLVec4< T >::RED = SLVec4<T>(1.0f, 0.0f, 0.0f, 1.0f)
static

Definition at line 216 of file SLVec4.h.

◆ w

template<class T >
T SLVec4< T >::w

Definition at line 32 of file SLVec4.h.

◆ WHITE

template<class T >
SLVec4< T > SLVec4< T >::WHITE = SLVec4<T>(1.0f, 1.0f, 1.0f, 1.0f)
static

Definition at line 215 of file SLVec4.h.

◆ x

template<class T >
T SLVec4< T >::x

Definition at line 32 of file SLVec4.h.

◆ y

template<class T >
T SLVec4< T >::y

Definition at line 32 of file SLVec4.h.

◆ YELLOW

template<class T >
SLVec4< T > SLVec4< T >::YELLOW = SLVec4<T>(1.0f, 1.0f, 0.0f, 1.0f)
static

Definition at line 219 of file SLVec4.h.

◆ z

template<class T >
T SLVec4< T >::z

Definition at line 32 of file SLVec4.h.

◆ ZERO

template<class T >
SLVec4< T > SLVec4< T >::ZERO = SLVec4<T>(0.0f, 0.0f, 0.0f, 1.0f)
static

Definition at line 212 of file SLVec4.h.


The documentation for this class was generated from the following file: