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

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

#include <SLVec3.h>

Public Member Functions

 SLVec3 ()
 
 SLVec3 (const T V)
 
 SLVec3 (const T X, const T Y, const T Z=0)
 
 SLVec3 (const T v[3])
 
 SLVec3 (const SLVec2< T > &v)
 
 SLVec3 (const SLVec3< T > &v)
 
 SLVec3 (const SLstring &threeFloatsWithDelimiter)
 
void set (const T X, const T Y, const T Z)
 
void set (const T X, const T Y)
 
void set (const T v[3])
 
void set (const SLVec2< T > &v)
 
void set (const SLVec3< T > &v)
 
SLbool operator== (const SLVec3 &v) const
 
SLbool operator!= (const SLVec3 &v) const
 
SLbool operator<= (const SLVec3 &v) const
 
SLbool operator>= (const SLVec3 &v) const
 
SLbool operator< (const SLVec3 &v) const
 
SLbool operator> (const SLVec3 &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
 
SLVec3 operator- () const
 
SLVec3 operator+ (const SLVec3 &v) const
 
SLVec3 operator- (const SLVec3 &v) const
 
operator* (const SLVec3 &v) const
 
SLVec3 operator^ (const SLVec3 &v) const
 
SLVec3 operator* (const T s) const
 
SLVec3 operator/ (const T s) const
 
SLVec3 operator& (const SLVec3 &v) const
 
SLVec3operator= (const SLVec2< T > &v)
 
SLVec3operator= (const SLVec3 &v)
 
SLVec3operator+= (const SLVec3 &v)
 
SLVec3operator-= (const SLVec3 &v)
 
SLVec3operator+= (const T s)
 
SLVec3operator-= (const T s)
 
SLVec3operator*= (const T s)
 
SLVec3operator/= (const T s)
 
SLVec3operator&= (const SLVec3 &v)
 
void add (const SLVec3 &a, const SLVec3 &b)
 
void add (const SLVec3 &a)
 
void sub (const SLVec3 &a, const SLVec3 &b)
 
void sub (const SLVec3 &a)
 
void scale (const T s)
 
dot (const SLVec3 &v) const
 
void cross (const SLVec3 &a, const SLVec3 &b)
 
length () const
 
lengthSqr () const
 
SLVec3normalize ()
 
SLVec3 normalized () const
 
void clampMinMax (const T min, const T max)
 
diff (const SLVec3 &v)
 
void mix (const SLVec3 &a, const SLVec3 &b, const T factor_b)
 
void setMin (const SLVec3 &v)
 
void setMax (const SLVec3 &v)
 
maxXYZ ()
 
minXYZ ()
 
maxXYZ (SLint &comp)
 
minXYZ (SLint &comp)
 
SLint maxComp ()
 
SLbool isZero ()
 
distance (const SLVec3 &p) const
 Calculate the distance to point p. More...
 
distSquared (const SLVec3 &q)
 Calculate the squared distance from the vector to point q. More...
 
void toSpherical (T &r, T &theta, T &phi)
 Calculates the spherical coords into r, theta & phi in radians. More...
 
void fromSpherical (T r, T theta, T phi)
 Calculates the vector from spherical coords r, theta & phi in radians. More...
 
void gammaCorrect (T oneOverGamma)
 Gamma correction. More...
 
void print (const SLchar *str=nullptr)
 Prints the vector to std out. More...
 
SLstring toString (SLstring delimiter=", ", int decimals=2)
 Conversion to string. More...
 
void fromString (const SLstring &threeFloatsWithDelimiter, SLchar delimiter=',')
 Conversion from string. More...
 
void hsv2rgb (const SLVec3 &hsv)
 HSV (0-1) to RGB (0-1) color conversion (http://www.rapidtables.com/convert/color/hsv-to-rgb.htm) More...
 
void ecef2LatLonAlt (const SLVec3 &ecef)
 Earth Centered Earth Fixed (ecef) to Latitude Longitude Altitude (LatLonAlt) using the WGS84 model. More...
 
void latlonAlt2ecef (const SLVec3 &latDegLonDegAltM)
 Latitude Longitude Altitude (LatLonAlt) to Earth Centered Earth Fixed (ecef) using the WGS84 model. More...
 

Public Attributes

union {
   struct {
      T   x
 
      T   y
 
      T   z
 
   } 
 
   struct {
      T   r
 
      T   g
 
      T   b
 
   } 
 
   struct {
      T   lat
 
      T   lon
 
      T   alt
 
   } 
 
   struct {
      T   comp [3]
 
   } 
 
}; 
 

Static Public Attributes

static SLVec3 ZERO = SLVec3<T>(0.0f, 0.0f, 0.0f)
 
static SLVec3 BLACK = SLVec3<T>(0.0f, 0.0f, 0.0f)
 
static SLVec3 GRAY = SLVec3<T>(0.5f, 0.5f, 0.5f)
 
static SLVec3 WHITE = SLVec3<T>(1.0f, 1.0f, 1.0f)
 
static SLVec3 RED = SLVec3<T>(1.0f, 0.0f, 0.0f)
 
static SLVec3 GREEN = SLVec3<T>(0.0f, 1.0f, 0.0f)
 
static SLVec3 BLUE = SLVec3<T>(0.0f, 0.0f, 1.0f)
 
static SLVec3 CYAN = SLVec3<T>(0.0f, 1.0f, 1.0f)
 
static SLVec3 MAGENTA = SLVec3<T>(1.0f, 0.0f, 1.0f)
 
static SLVec3 YELLOW = SLVec3<T>(1.0f, 1.0f, 0.0f)
 
static SLVec3 ORANGE = SLVec3<T>(0.5f, 0.5f, 0.0f)
 
static SLVec3 COLBFH = SLVec3<T>(0.8f, 0.5f, 0.0f)
 
static SLVec3 AXISX = SLVec3<T>(1.0f, 0.0f, 0.0f)
 
static SLVec3 AXISY = SLVec3<T>(0.0f, 1.0f, 0.0f)
 
static SLVec3 AXISZ = SLVec3<T>(0.0f, 0.0f, 1.0f)
 

Friends

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

Detailed Description

template<class T>
class SLVec3< T >

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

3D vector template class with type definitions for 3D vectors and colors:
Use SLVec3f for a specific float type vector
Use SLVec3d for a specific double type vector
Use SLVec3r for a precision independent real type.

Definition at line 39 of file SLVec3.h.

Constructor & Destructor Documentation

◆ SLVec3() [1/7]

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

Definition at line 49 of file SLVec3.h.

49 {x=0;y=0;z=0;}
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43
T z
Definition: SLVec3.h:43

◆ SLVec3() [2/7]

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

Definition at line 50 of file SLVec3.h.

50 {x=V; y=V; z=V;}

◆ SLVec3() [3/7]

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

Definition at line 51 of file SLVec3.h.

53  {x=X; y=Y; z=Z;}

◆ SLVec3() [4/7]

template<class T >
SLVec3< T >::SLVec3 ( const T  v[3])
inlineexplicit

Definition at line 54 of file SLVec3.h.

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

◆ SLVec3() [5/7]

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

Definition at line 55 of file SLVec3.h.

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

◆ SLVec3() [6/7]

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

Definition at line 56 of file SLVec3.h.

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

◆ SLVec3() [7/7]

template<class T >
SLVec3< T >::SLVec3 ( const SLstring threeFloatsWithDelimiter)
inlineexplicit

Definition at line 57 of file SLVec3.h.

57 {fromString(threeFloatsWithDelimiter);}
void fromString(const SLstring &threeFloatsWithDelimiter, SLchar delimiter=',')
Conversion from string.
Definition: SLVec3.h:206

Member Function Documentation

◆ add() [1/2]

template<class T >
void SLVec3< T >::add ( const SLVec3< T > &  a)
inline

Definition at line 112 of file SLVec3.h.

112 {x+=a.x; y+=a.y, z+=a.z;}

◆ add() [2/2]

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

Definition at line 110 of file SLVec3.h.

111  {x=a.x+b.x; y=a.y+b.y, z=a.z+b.z;}
T b
Definition: SLVec3.h:44

◆ clampMinMax()

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

Definition at line 131 of file SLVec3.h.

132  {x = (x>max)?max : (x<min)?min : x;
133  y = (y>max)?max : (y<min)?min : y;
134  z = (z>max)?max : (z<min)?min : z;}

◆ cross()

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

Definition at line 118 of file SLVec3.h.

119  {x = a.y*b.z - a.z*b.y;
120  y = a.z*b.x - a.x*b.z;
121  z = a.x*b.y - a.y*b.x;}

◆ diff()

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

Definition at line 135 of file SLVec3.h.

135  {return Utils::abs(x-v.x) +
136  Utils::abs(y-v.y) +
137  Utils::abs(z-v.z);}
T abs(T a)
Definition: Utils.h:249

◆ distance()

template<class T >
T SLVec3< T >::distance ( const SLVec3< T > &  p) const
inline

Calculate the distance to point p.

Definition at line 168 of file SLVec3.h.

168  {SLVec3 d(x-p.x, y-p.y, z-p.z);
169  return d.length();}
3D vector template class for standard 3D vector algebra.
Definition: SLVec3.h:40

◆ distSquared()

template<class T >
T SLVec3< T >::distSquared ( const SLVec3< T > &  q)
inline

Calculate the squared distance from the vector to point q.

Definition at line 172 of file SLVec3.h.

172  {SLVec3 dir(x,y,z); dir.normalize();
173  T t = dir.dot(q);
174  SLVec3 qPrime = t*dir;
175  SLVec3 v = q-qPrime;
176  T distanceSquared = v.dot(v);
177  return distanceSquared;}
T dot(const SLVec3 &v) const
Definition: SLVec3.h:117

◆ dot()

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

Definition at line 117 of file SLVec3.h.

117 {return x*v.x+y*v.y+z*v.z;}

◆ ecef2LatLonAlt()

template<class T >
void SLVec3< T >::ecef2LatLonAlt ( const SLVec3< T > &  ecef)
inline

Earth Centered Earth Fixed (ecef) to Latitude Longitude Altitude (LatLonAlt) using the WGS84 model.

Longitude and latitude are in decimal degrees and altitude in meters. The Cartesian ecef coordinates are in meters. See for more details: https://microem.ru/files/2012/08/GPS.G1-X-00006.pdf

Definition at line 243 of file SLVec3.h.

244  {
245  double a = EARTH_RADIUS_A;
246  double b = EARTH_RADIUS_B;
247  double esq = EARTH_ECCENTRICTIY_SQR;
248  double epsq = EARTH_ECCENTRICTIY2_SQR;
249 
250  double p = sqrt(ecef.x * ecef.x + ecef.y*ecef.y);
251  double th = atan2(a*ecef.z, b*p);
252 
253  double longitude = atan2(ecef.y, ecef.x);
254  double latitude = atan2((ecef.z + epsq*b*pow(sin(th),3.0)), (p - esq*a*pow(cos(th),3.0)) );
255  double N = a/(sqrt(1-esq*pow(sin(latitude),2)));
256  double altitude = p/cos(latitude) - N;
257 
258  lat = latitude * Utils::RAD2DEG;
259  lon = fmod(longitude,Utils::TWOPI) * Utils::RAD2DEG;
260  alt = altitude * Utils::RAD2DEG;
261  }
static const double EARTH_RADIUS_B
Definition: SLVec3.h:24
static const double EARTH_ECCENTRICTIY_SQR
Definition: SLVec3.h:23
static const double EARTH_RADIUS_A
Definition: SLVec3.h:20
static const double EARTH_ECCENTRICTIY2_SQR
Definition: SLVec3.h:27
T lat
Definition: SLVec3.h:45
T alt
Definition: SLVec3.h:45
T lon
Definition: SLVec3.h:45
static const float RAD2DEG
Definition: Utils.h:238
static const float TWOPI
Definition: Utils.h:240

◆ fromSpherical()

template<class T >
void SLVec3< T >::fromSpherical ( r,
theta,
phi 
)
inline

Calculates the vector from spherical coords r, theta & phi in radians.

Definition at line 185 of file SLVec3.h.

185  {T sin_theta = sin(theta);
186  x = r*sin_theta*cos(phi);
187  y = r*sin_theta*sin(phi);
188  z = r*cos(theta);}
T r
Definition: SLVec3.h:44

◆ fromString()

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

Conversion from string.

Definition at line 206 of file SLVec3.h.

207  { SLVstring components;
208  Utils::splitString(threeFloatsWithDelimiter, delimiter, components);
209  float f[3] = {0.0, 0.0f, 0.0f};
210  for (SLulong i=0; i<components.size(); ++i)
211  f[i] = (SLfloat)atof(components[i].c_str());
212  x = f[0]; y = f[1]; z = f[2];
213  }
float SLfloat
Definition: SL.h:173
unsigned long SLulong
Definition: SL.h:165
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 SLVec3< T >::gammaCorrect ( oneOverGamma)
inline

Gamma correction.

Definition at line 190 of file SLVec3.h.

190  {x= pow(x,oneOverGamma);
191  y= pow(y,oneOverGamma);
192  z= pow(z,oneOverGamma);}

◆ hsv2rgb()

template<class T >
void SLVec3< T >::hsv2rgb ( const SLVec3< T > &  hsv)
inline

HSV (0-1) to RGB (0-1) color conversion (http://www.rapidtables.com/convert/color/hsv-to-rgb.htm)

Definition at line 216 of file SLVec3.h.

217  {
218  T h = fmod(fmod(hsv.x, Utils::TWOPI) + Utils::TWOPI, Utils::TWOPI); // 0 deg <= H <= 360 deg
219  T s = clamp(hsv.y, 0.0f, 1.0f);
220  T v = clamp(hsv.z, 0.0f, 1.0f);
221  T a = clamp(hsv.x, 0.0f, 1.0f);
222 
223  T c = v * s;
224  T x = c * (1.0f - fabs(fmod(h*3.0f / Utils::PI, 2.0f) - 1.0f));
225  T m = v - c;
226 
227  switch (SLint(floor(h*3.0f * Utils::ONEOVERPI)))
228  { case 0: return set(m + c, m + x, m ); // [ 0 deg, 60 deg]
229  case 1: return set(m + x, m + c, m ); // [ 60 deg,120 deg]
230  case 2: return set(m , m + c, m + x); // [120 deg,180 deg]
231  case 3: return set(m , m + x, m + c); // [180 deg,240 deg]
232  case 4: return set(m + x, m , m + c); // [240 deg,300 deg]
233  case 5: return set(m + c, m , m + x); // [300 deg,360 deg]
234  }
235  }
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)
Definition: SLVec3.h:59
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

◆ isZero()

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

Definition at line 165 of file SLVec3.h.

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

◆ latlonAlt2ecef()

template<class T >
void SLVec3< T >::latlonAlt2ecef ( const SLVec3< T > &  latDegLonDegAltM)
inline

Latitude Longitude Altitude (LatLonAlt) to Earth Centered Earth Fixed (ecef) using the WGS84 model.

Latitude and longitude are in decimal degrees and altitude in meters. The Cartesian ecef coordinates are in meters. See for more details: https://microem.ru/files/2012/08/GPS.G1-X-00006.pdf

Definition at line 269 of file SLVec3.h.

270  {
271  double latitude = latDegLonDegAltM.lat * Utils::DEG2RAD;
272  double longitude = latDegLonDegAltM.lon * Utils::DEG2RAD;
273  double altitude = latDegLonDegAltM.alt;
274  double a = EARTH_RADIUS_A;
275  double esq = EARTH_ECCENTRICTIY_SQR;
276  double cosLat = cos(latitude);
277 
278  double N = a / sqrt(1 - esq * pow(sin(latitude),2));
279 
280  x = (N+altitude) * cosLat * cos(longitude);
281  y = (N+altitude) * cosLat * sin(longitude);
282  z = ((1-esq) * N + altitude) * sin(latitude);
283  }
static const float DEG2RAD
Definition: Utils.h:239

◆ length()

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

Definition at line 122 of file SLVec3.h.

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

◆ lengthSqr()

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

Definition at line 123 of file SLVec3.h.

123 {return (x*x+y*y+z*z);}

◆ maxComp()

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

Definition at line 162 of file SLVec3.h.

162  {if (x>=y && x>=z) return 0;
163  else if (y>=z) return 1;
164  else return 2;}

◆ maxXYZ() [1/2]

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

Definition at line 150 of file SLVec3.h.

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

◆ maxXYZ() [2/2]

template<class T >
T SLVec3< T >::maxXYZ ( SLint comp)
inline

Definition at line 156 of file SLVec3.h.

156  {if (x>=y && x>=z){comp=0; return x;}
157  else if (y>=z) {comp=1; return y;}
158  else {comp=2; return z;}}
T comp[3]
Definition: SLVec3.h:46

◆ minXYZ() [1/2]

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

Definition at line 153 of file SLVec3.h.

153  {if (x<=y && x<=z) return x;
154  else if (y<=z) return y;
155  else return z;}

◆ minXYZ() [2/2]

template<class T >
T SLVec3< T >::minXYZ ( SLint comp)
inline

Definition at line 159 of file SLVec3.h.

159  {if (x<=y && x<=z){comp=0; return x;}
160  else if (y<=z) {comp=1; return y;}
161  else {comp=2; return z;}}

◆ mix()

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

Definition at line 138 of file SLVec3.h.

140  {T factor_a = 1-factor_b;
141  x = a.x*factor_a + b.x*factor_b;
142  y = a.y*factor_a + b.y*factor_b;
143  z = a.z*factor_a + b.z*factor_b;}

◆ normalize()

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

Definition at line 124 of file SLVec3.h.

124  {T L=length();
125  if (L>0) {x/=L; y/=L; z/=L;}
126  return *this;}
T length() const
Definition: SLVec3.h:122

◆ normalized()

template<class T >
SLVec3 SLVec3< T >::normalized ( ) const
inline

Definition at line 127 of file SLVec3.h.

127  {T L=length();
128  SLVec3 ret(*this);
129  if(L>0) { ret.x /= L; ret.y /= L; ret.z /= L; }
130  return ret;}

◆ operator!=()

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

Definition at line 70 of file SLVec3.h.

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

◆ operator&()

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

Definition at line 90 of file SLVec3.h.

90 {return SLVec3(x*v.x, y*v.y, z*v.z);}
SLVec3()
Definition: SLVec3.h:49

◆ operator&=()

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

Definition at line 103 of file SLVec3.h.

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

◆ operator*() [1/2]

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

Definition at line 84 of file SLVec3.h.

84 {return x*v.x+y*v.y+z*v.z;} // dot

◆ operator*() [2/2]

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

Definition at line 88 of file SLVec3.h.

88 {return SLVec3(x*s, y*s, z*s);}

◆ operator*=()

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

Definition at line 101 of file SLVec3.h.

101 {x*=s; y*=s; z*=s; return *this;}

◆ operator+()

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

Definition at line 82 of file SLVec3.h.

82 {return SLVec3(x+v.x, y+v.y, z+v.z);}

◆ operator+=() [1/2]

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

Definition at line 97 of file SLVec3.h.

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

◆ operator+=() [2/2]

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

Definition at line 99 of file SLVec3.h.

99 {x+=s; y+=s; z+=s; return *this;}

◆ operator-() [1/2]

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

Definition at line 81 of file SLVec3.h.

81 {return SLVec3(-x, -y, -z);}

◆ operator-() [2/2]

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

Definition at line 83 of file SLVec3.h.

83 {return SLVec3(x-v.x, y-v.y, z-v.z);}

◆ operator-=() [1/2]

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

Definition at line 98 of file SLVec3.h.

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

◆ operator-=() [2/2]

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

Definition at line 100 of file SLVec3.h.

100 {x-=s; y-=s; z-=s; return *this;}

◆ operator/()

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

Definition at line 89 of file SLVec3.h.

89 {return SLVec3(x/s, y/s, z/s);}

◆ operator/=()

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

Definition at line 102 of file SLVec3.h.

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

◆ operator<() [1/2]

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

Definition at line 73 of file SLVec3.h.

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

◆ operator<() [2/2]

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

Definition at line 77 of file SLVec3.h.

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

◆ operator<=() [1/2]

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

Definition at line 71 of file SLVec3.h.

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

◆ operator<=() [2/2]

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

Definition at line 75 of file SLVec3.h.

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

◆ operator=() [1/2]

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

Definition at line 95 of file SLVec3.h.

95 {x=v.x; y=v.y; z=0; return *this;}

◆ operator=() [2/2]

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

Definition at line 96 of file SLVec3.h.

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

◆ operator==()

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

Definition at line 69 of file SLVec3.h.

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

◆ operator>() [1/2]

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

Definition at line 74 of file SLVec3.h.

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

◆ operator>() [2/2]

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

Definition at line 78 of file SLVec3.h.

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

◆ operator>=() [1/2]

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

Definition at line 72 of file SLVec3.h.

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

◆ operator>=() [2/2]

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

Definition at line 76 of file SLVec3.h.

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

◆ operator^()

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

Definition at line 85 of file SLVec3.h.

85  {return SLVec3(y*v.z-z*v.y, // cross
86  z*v.x-x*v.z,
87  x*v.y-y*v.x);}

◆ print()

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

Prints the vector to std out.

Definition at line 195 of file SLVec3.h.

195  {if (str) SLMATH_LOG("%s",str);
196  SLMATH_LOG("% 3.2f, % 3.2f, % 3.2f",x, y, z);}
#define SLMATH_LOG(...)
Definition: SLMath.h:70

◆ scale()

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

Definition at line 116 of file SLVec3.h.

116 {x*=s; y*=s; z*=s;}

◆ set() [1/5]

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

Definition at line 65 of file SLVec3.h.

65 {x=v.x; y=v.y; z=0;}

◆ set() [2/5]

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

Definition at line 66 of file SLVec3.h.

66 {x=v.x; y=v.y; z=v.z;}

◆ set() [3/5]

template<class T >
void SLVec3< T >::set ( const T  v[3])
inline

Definition at line 64 of file SLVec3.h.

64 {x=v[0]; y=v[1]; z=v[2];}

◆ set() [4/5]

template<class T >
void SLVec3< T >::set ( const T  X,
const T  Y 
)
inline

Definition at line 62 of file SLVec3.h.

63  {x=X; y=Y; z=0;}

◆ set() [5/5]

template<class T >
void SLVec3< T >::set ( const T  X,
const T  Y,
const T  Z 
)
inline

Definition at line 59 of file SLVec3.h.

61  {x=X; y=Y; z=Z;}

◆ setMax()

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

Definition at line 147 of file SLVec3.h.

147  {if (v.x > x) x=v.x;
148  if (v.y > y) y=v.y;
149  if (v.z > z) z=v.z;}

◆ setMin()

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

Definition at line 144 of file SLVec3.h.

144  {if (v.x < x) x=v.x;
145  if (v.y < y) y=v.y;
146  if (v.z < z) z=v.z;}

◆ sub() [1/2]

template<class T >
void SLVec3< T >::sub ( const SLVec3< T > &  a)
inline

Definition at line 115 of file SLVec3.h.

115 {x-=a.x; y-=a.y, z-=a.z;}

◆ sub() [2/2]

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

Definition at line 113 of file SLVec3.h.

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

◆ toSpherical()

template<class T >
void SLVec3< T >::toSpherical ( T &  r,
T &  theta,
T &  phi 
)
inline

Calculates the spherical coords into r, theta & phi in radians.

Definition at line 180 of file SLVec3.h.

180  {r = length();
181  theta = acos(z/r); // 0 < theta < pi
182  phi = atan2(y,x);} // -pi < phi < pi

◆ toString()

template<class T >
SLstring SLVec3< T >::toString ( SLstring  delimiter = ", ",
int  decimals = 2 
)
inline

Conversion to string.

Definition at line 199 of file SLVec3.h.

200  { return Utils::toString(x,decimals) + delimiter +
201  Utils::toString(y,decimals) + delimiter +
202  Utils::toString(z,decimals);
203  }
string toString(float f, int roundedDecimals)
Returns a string from a float with max. one trailing zero.
Definition: Utils.cpp:92

Friends And Related Function Documentation

◆ operator*

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

Definition at line 92 of file SLVec3.h.

92 {return SLVec3(v.x*s, v.y*s, v.z*s);}

◆ operator<<

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

Definition at line 106 of file SLVec3.h.

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

Member Data Documentation

◆ 

union { ... }

◆ alt

template<class T >
T SLVec3< T >::alt

Definition at line 45 of file SLVec3.h.

◆ AXISX

template<class T >
SLVec3< T > SLVec3< T >::AXISX = SLVec3<T>(1.0f, 0.0f, 0.0f)
static

Definition at line 297 of file SLVec3.h.

◆ AXISY

template<class T >
SLVec3< T > SLVec3< T >::AXISY = SLVec3<T>(0.0f, 1.0f, 0.0f)
static

Definition at line 298 of file SLVec3.h.

◆ AXISZ

template<class T >
SLVec3< T > SLVec3< T >::AXISZ = SLVec3<T>(0.0f, 0.0f, 1.0f)
static

Definition at line 299 of file SLVec3.h.

◆ b

template<class T >
T SLVec3< T >::b

Definition at line 44 of file SLVec3.h.

◆ BLACK

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

Definition at line 286 of file SLVec3.h.

◆ BLUE

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

Definition at line 291 of file SLVec3.h.

◆ COLBFH

template<class T >
SLVec3< T > SLVec3< T >::COLBFH = SLVec3<T>(0.8f, 0.5f, 0.0f)
static

Definition at line 296 of file SLVec3.h.

◆ comp

template<class T >
T SLVec3< T >::comp[3]

Definition at line 46 of file SLVec3.h.

◆ CYAN

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

Definition at line 292 of file SLVec3.h.

◆ g

template<class T >
T SLVec3< T >::g

Definition at line 44 of file SLVec3.h.

◆ GRAY

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

Definition at line 287 of file SLVec3.h.

◆ GREEN

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

Definition at line 290 of file SLVec3.h.

◆ lat

template<class T >
T SLVec3< T >::lat

Definition at line 45 of file SLVec3.h.

◆ lon

template<class T >
T SLVec3< T >::lon

Definition at line 45 of file SLVec3.h.

◆ MAGENTA

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

Definition at line 293 of file SLVec3.h.

◆ ORANGE

template<class T >
SLVec3< T > SLVec3< T >::ORANGE = SLVec3<T>(0.5f, 0.5f, 0.0f)
static

Definition at line 295 of file SLVec3.h.

◆ r

template<class T >
T SLVec3< T >::r

Definition at line 44 of file SLVec3.h.

◆ RED

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

Definition at line 289 of file SLVec3.h.

◆ WHITE

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

Definition at line 288 of file SLVec3.h.

◆ x

template<class T >
T SLVec3< T >::x

Definition at line 43 of file SLVec3.h.

◆ y

template<class T >
T SLVec3< T >::y

Definition at line 43 of file SLVec3.h.

◆ YELLOW

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

Definition at line 294 of file SLVec3.h.

◆ z

template<class T >
T SLVec3< T >::z

Definition at line 43 of file SLVec3.h.

◆ ZERO

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

Definition at line 285 of file SLVec3.h.


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