SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLVec3.h
Go to the documentation of this file.
1 /**
2  * \file math/Math/SLVec3.h
3  * \brief 3 Component vector class
4  * \date July 2014
5  * \authors Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9 */
10 
11 #ifndef SLVEC3_H
12 #define SLVEC3_H
13 
14 #include <cmath>
15 #include <SLMath.h>
16 #include <SLVec2.h>
17 #include <Utils.h>
18 
19 // Some constants for ecef to lla conversions
20 static const double EARTH_RADIUS_A = 6378137;
21 static const double EARTH_ECCENTRICTIY = 8.1819190842622e-2;
24 static const double EARTH_RADIUS_B = sqrt(EARTH_RADIUS_A_SQR * (1 - EARTH_ECCENTRICTIY_SQR));
28 
29 //-----------------------------------------------------------------------------
30 //! 3D vector template class for standard 3D vector algebra.
31 /*!
32 3D vector template class with type definitions for 3D vectors and colors:
33 \n Use SLVec3f for a specific float type vector
34 \n Use SLVec3d for a specific double type vector
35 \n Use SLVec3r for a precision independent real type.
36 */
37 // clang-format off
38 template<class T>
39 class SLVec3
40 {
41  public:
42  union
43  { struct {T x, y, z;}; // 3D cartesian coordinates
44  struct {T r, g, b;}; // Red, green & blue color components
45  struct {T lat, lon, alt;}; // WGS84 latitude (deg), longitude (deg) & altitude (m)
46  struct {T comp[3];};
47  };
48 
49  SLVec3 () {x=0;y=0;z=0;}
50  explicit SLVec3 (const T V) {x=V; y=V; z=V;}
51  SLVec3 (const T X,
52  const T Y,
53  const T Z=0) {x=X; y=Y; z=Z;}
54  explicit SLVec3 (const T v[3]) {x=v[0]; y=v[1]; z=v[2];}
55  explicit SLVec3 (const SLVec2<T>& v) {x=v.x; y=v.y; z=0;}
56  SLVec3 (const SLVec3<T>& v) {x = v.x; y = v.y; z = v.z; }
57  explicit SLVec3 (const SLstring& threeFloatsWithDelimiter) {fromString(threeFloatsWithDelimiter);}
58 
59  void set (const T X,
60  const T Y,
61  const T Z) {x=X; y=Y; z=Z;}
62  void set (const T X,
63  const T Y) {x=X; y=Y; z=0;}
64  void set (const T v[3]) {x=v[0]; y=v[1]; z=v[2];}
65  void set (const SLVec2<T>& v) {x=v.x; y=v.y; z=0;}
66  void set (const SLVec3<T>& v) {x=v.x; y=v.y; z=v.z;}
67 
68  // Component wise compare
69  inline SLbool operator == (const SLVec3& v) const {return (x==v.x && y==v.y && z==v.z);}
70  inline SLbool operator != (const SLVec3& v) const {return (x!=v.x || y!=v.y || z!=v.z);}
71  inline SLbool operator <= (const SLVec3& v) const {return (x<=v.x && y<=v.y && z<=v.z);}
72  inline SLbool operator >= (const SLVec3& v) const {return (x>=v.x && y>=v.y && z>=v.z);}
73  inline SLbool operator < (const SLVec3& v) const {return (x< v.x && y< v.y && z< v.z);}
74  inline SLbool operator > (const SLVec3& v) const {return (x> v.x && y> v.y && z> v.z);}
75  inline SLbool operator <= (const T v) const {return (x<=v && y<=v && z<=v);}
76  inline SLbool operator >= (const T v) const {return (x>=v && y>=v && z>=v);}
77  inline SLbool operator < (const T v) const {return (x< v && y< v && z< v);}
78  inline SLbool operator > (const T v) const {return (x> v && y> v && z> v);}
79 
80  // Operators with temp. allocation
81  inline SLVec3 operator - () const {return SLVec3(-x, -y, -z);}
82  inline SLVec3 operator + (const SLVec3& v) const {return SLVec3(x+v.x, y+v.y, z+v.z);}
83  inline SLVec3 operator - (const SLVec3& v) const {return SLVec3(x-v.x, y-v.y, z-v.z);}
84  inline T operator * (const SLVec3& v) const {return x*v.x+y*v.y+z*v.z;} // dot
85  inline SLVec3 operator ^ (const SLVec3& v) const {return SLVec3(y*v.z-z*v.y, // cross
86  z*v.x-x*v.z,
87  x*v.y-y*v.x);}
88  inline SLVec3 operator * (const T s) const {return SLVec3(x*s, y*s, z*s);}
89  inline SLVec3 operator / (const T s) const {return SLVec3(x/s, y/s, z/s);}
90  inline SLVec3 operator & (const SLVec3& v) const {return SLVec3(x*v.x, y*v.y, z*v.z);}
91  friend
92  inline SLVec3 operator * (T s, const SLVec3& v) {return SLVec3(v.x*s, v.y*s, v.z*s);}
93 
94  // Assign operators
95  inline SLVec3& operator = (const SLVec2<T>& v) {x=v.x; y=v.y; z=0; return *this;}
96  inline SLVec3& operator = (const SLVec3& v) {x=v.x; y=v.y; z=v.z; return *this;}
97  inline SLVec3& operator += (const SLVec3& v) {x+=v.x; y+=v.y; z+=v.z; return *this;}
98  inline SLVec3& operator -= (const SLVec3& v) {x-=v.x; y-=v.y; z-=v.z; return *this;}
99  inline SLVec3& operator += (const T s) {x+=s; y+=s; z+=s; return *this;}
100  inline SLVec3& operator -= (const T s) {x-=s; y-=s; z-=s; return *this;}
101  inline SLVec3& operator *= (const T s) {x*=s; y*=s; z*=s; return *this;}
102  inline SLVec3& operator /= (const T s) {x/=s; y/=s; z/=s; return *this;}
103  inline SLVec3& operator &= (const SLVec3& v) {x*=v.x; y*=v.y; z*=v.z; return *this;}
104 
105  // Stream output operator
106  friend std::ostream& operator << (std::ostream& output,
107  const SLVec3& v) {output<<"["<<v.x<<","<<v.y<<","<<v.z<<"]"; return output;}
108 
109  // Operations without temp. allocation (use these for speed!)
110  inline void add (const SLVec3& a,
111  const SLVec3& b) {x=a.x+b.x; y=a.y+b.y, z=a.z+b.z;}
112  inline void add (const SLVec3& a) {x+=a.x; y+=a.y, z+=a.z;}
113  inline void sub (const SLVec3& a,
114  const SLVec3& b) {x=a.x-b.x; y=a.y-b.y, z=a.z-b.z;}
115  inline void sub (const SLVec3& a) {x-=a.x; y-=a.y, z-=a.z;}
116  inline void scale (const T s) {x*=s; y*=s; z*=s;}
117  inline T dot (const SLVec3& v) const {return x*v.x+y*v.y+z*v.z;}
118  inline void cross (const SLVec3& a,
119  const SLVec3& b) {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;}
122  inline T length () const {return (T)sqrt(x*x+y*y+z*z);}
123  inline T lengthSqr () const {return (x*x+y*y+z*z);}
124  inline SLVec3& normalize () {T L=length();
125  if (L>0) {x/=L; y/=L; z/=L;}
126  return *this;}
127  inline SLVec3 normalized () const {T L=length();
128  SLVec3 ret(*this);
129  if(L>0) { ret.x /= L; ret.y /= L; ret.z /= L; }
130  return ret;}
131  inline void clampMinMax (const T min,
132  const T max) {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;}
135  inline T diff (const SLVec3& v) {return Utils::abs(x-v.x) +
136  Utils::abs(y-v.y) +
137  Utils::abs(z-v.z);}
138  inline void mix (const SLVec3& a,
139  const SLVec3& b,
140  const T factor_b) {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;}
144  inline void setMin (const SLVec3& v) {if (v.x < x) x=v.x;
145  if (v.y < y) y=v.y;
146  if (v.z < z) z=v.z;}
147  inline void setMax (const SLVec3& v) {if (v.x > x) x=v.x;
148  if (v.y > y) y=v.y;
149  if (v.z > z) z=v.z;}
150  inline T maxXYZ () {if (x>=y && x>=z) return x;
151  else if (y>=z) return y;
152  else return z;}
153  inline T minXYZ () {if (x<=y && x<=z) return x;
154  else if (y<=z) return y;
155  else return z;}
156  inline T maxXYZ (SLint &comp) {if (x>=y && x>=z){comp=0; return x;}
157  else if (y>=z) {comp=1; return y;}
158  else {comp=2; return z;}}
159  inline T minXYZ (SLint &comp) {if (x<=y && x<=z){comp=0; return x;}
160  else if (y<=z) {comp=1; return y;}
161  else {comp=2; return z;}}
162  inline SLint maxComp () {if (x>=y && x>=z) return 0;
163  else if (y>=z) return 1;
164  else return 2;}
165  inline SLbool isZero () {return (x==0 && y==0 && z==0);}
166 
167  //! Calculate the distance to point p
168  T distance (const SLVec3& p) const {SLVec3 d(x-p.x, y-p.y, z-p.z);
169  return d.length();}
170 
171  //! Calculate the squared distance from the vector to point q
172  T distSquared (const SLVec3& q) {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;}
178 
179  //! Calculates the spherical coords into r, theta & phi in radians
180  void toSpherical (T& r, T& theta, T& phi){r = length();
181  theta = acos(z/r); // 0 < theta < pi
182  phi = atan2(y,x);} // -pi < phi < pi
183 
184  //! Calculates the vector from spherical coords r, theta & phi in radians
185  void fromSpherical(T r, T theta, T phi) {T sin_theta = sin(theta);
186  x = r*sin_theta*cos(phi);
187  y = r*sin_theta*sin(phi);
188  z = r*cos(theta);}
189  //! Gamma correction
190  void gammaCorrect(T oneOverGamma) {x= pow(x,oneOverGamma);
191  y= pow(y,oneOverGamma);
192  z= pow(z,oneOverGamma);}
193 
194  //! Prints the vector to std out
195  void print (const SLchar* str=nullptr){if (str) SLMATH_LOG("%s",str);
196  SLMATH_LOG("% 3.2f, % 3.2f, % 3.2f",x, y, z);}
197 
198  //! Conversion to string
199  SLstring toString (SLstring delimiter = ", ", int decimals = 2)
200  { return Utils::toString(x,decimals) + delimiter +
201  Utils::toString(y,decimals) + delimiter +
202  Utils::toString(z,decimals);
203  }
204 
205  //! Conversion from string
206  void fromString (const SLstring& threeFloatsWithDelimiter, SLchar delimiter = ',')
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  }
214 
215  //! HSV (0-1) to RGB (0-1) color conversion (http://www.rapidtables.com/convert/color/hsv-to-rgb.htm)
216  void hsv2rgb (const SLVec3 &hsv)
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  }
236 
237  //! Earth Centered Earth Fixed (ecef) to Latitude Longitude Altitude (LatLonAlt) using the WGS84 model
238  /*!
239  Longitude and latitude are in decimal degrees and altitude in meters.
240  The Cartesian ecef coordinates are in meters.
241  See for more details: https://microem.ru/files/2012/08/GPS.G1-X-00006.pdf
242  */
243  void ecef2LatLonAlt(const SLVec3 &ecef)
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  }
262 
263  //! Latitude Longitude Altitude (LatLonAlt) to Earth Centered Earth Fixed (ecef) using the WGS84 model
264  /*!
265  Latitude and longitude are in decimal degrees and altitude in meters.
266  The Cartesian ecef coordinates are in meters.
267  See for more details: https://microem.ru/files/2012/08/GPS.G1-X-00006.pdf
268  */
269  void latlonAlt2ecef(const SLVec3 &latDegLonDegAltM)
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  }
284 
285  static SLVec3 ZERO;
286  static SLVec3 BLACK;
287  static SLVec3 GRAY;
288  static SLVec3 WHITE;
289  static SLVec3 RED;
290  static SLVec3 GREEN;
291  static SLVec3 BLUE;
292  static SLVec3 CYAN;
293  static SLVec3 MAGENTA;
294  static SLVec3 YELLOW;
295  static SLVec3 ORANGE;
296  static SLVec3 COLBFH;
297  static SLVec3 AXISX;
298  static SLVec3 AXISY;
299  static SLVec3 AXISZ;
300 };
301 //-----------------------------------------------------------------------------
302 template<class T> SLVec3<T> SLVec3<T>::ZERO = SLVec3<T>(0.0f, 0.0f, 0.0f);
303 template<class T> SLVec3<T> SLVec3<T>::BLACK = SLVec3<T>(0.0f, 0.0f, 0.0f);
304 template<class T> SLVec3<T> SLVec3<T>::GRAY = SLVec3<T>(0.5f, 0.5f, 0.5f);
305 template<class T> SLVec3<T> SLVec3<T>::WHITE = SLVec3<T>(1.0f, 1.0f, 1.0f);
306 template<class T> SLVec3<T> SLVec3<T>::RED = SLVec3<T>(1.0f, 0.0f, 0.0f);
307 template<class T> SLVec3<T> SLVec3<T>::GREEN = SLVec3<T>(0.0f, 1.0f, 0.0f);
308 template<class T> SLVec3<T> SLVec3<T>::BLUE = SLVec3<T>(0.0f, 0.0f, 1.0f);
309 template<class T> SLVec3<T> SLVec3<T>::YELLOW = SLVec3<T>(1.0f, 1.0f, 0.0f);
310 template<class T> SLVec3<T> SLVec3<T>::ORANGE = SLVec3<T>(0.5f, 0.5f, 0.0f);
311 template<class T> SLVec3<T> SLVec3<T>::CYAN = SLVec3<T>(0.0f, 1.0f, 1.0f);
312 template<class T> SLVec3<T> SLVec3<T>::MAGENTA= SLVec3<T>(1.0f, 0.0f, 1.0f);
313 template<class T> SLVec3<T> SLVec3<T>::COLBFH = SLVec3<T>(0.8f, 0.5f, 0.0f);
314 template<class T> SLVec3<T> SLVec3<T>::AXISX = SLVec3<T>(1.0f, 0.0f, 0.0f);
315 template<class T> SLVec3<T> SLVec3<T>::AXISY = SLVec3<T>(0.0f, 1.0f, 0.0f);
316 template<class T> SLVec3<T> SLVec3<T>::AXISZ = SLVec3<T>(0.0f, 0.0f, 1.0f);
317 //-----------------------------------------------------------------------------
324 
325 typedef vector<SLVec3f> SLVVec3f;
326 typedef vector<SLCol3f> SLVCol3f;
327 typedef vector<SLVec3d> SLVVec3d;
328 
329 typedef vector<SLfloat> SLVfloat;
330 //-----------------------------------------------------------------------------
331 #endif
332 
333 
float SLfloat
Definition: SL.h:173
unsigned long SLulong
Definition: SL.h:165
char SLchar
Definition: SL.h:162
bool SLbool
Definition: SL.h:175
vector< SLstring > SLVstring
Definition: SL.h:201
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
#define SLMATH_LOG(...)
Definition: SLMath.h:70
SLScene * s
Definition: SLScene.h:31
static const double EARTH_RADIUS_B
Definition: SLVec3.h:24
vector< SLVec3f > SLVVec3f
Definition: SLVec3.h:325
vector< SLVec3d > SLVVec3d
Definition: SLVec3.h:327
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
static const double EARTH_ECCENTRICTIY_SQR
Definition: SLVec3.h:23
SLVec3< SLfloat > SLCol3f
Definition: SLVec3.h:319
vector< SLCol3f > SLVCol3f
Definition: SLVec3.h:326
static const double EARTH_RADIUS_A_SQR
Definition: SLVec3.h:22
static const double EARTH_RADIUS_A
Definition: SLVec3.h:20
static const double EARTH_ECCENTRICTIY2
Definition: SLVec3.h:26
vector< SLfloat > SLVfloat
Definition: SLVec3.h:329
SLVec3< SLint > SLVec3i
Definition: SLVec3.h:320
SLVec3< SLshort > SLVec3s
Definition: SLVec3.h:322
static const double EARTH_ECCENTRICTIY
Definition: SLVec3.h:21
static const double EARTH_ECCENTRICTIY2_SQR
Definition: SLVec3.h:27
static const double EARTH_RADIUS_B_SQR
Definition: SLVec3.h:25
SLVec3< double > SLVec3d
Definition: SLVec3.h:323
SLVec3< SLuint > SLVec3ui
Definition: SLVec3.h:321
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
2D vector template class for standard 2D vector algebra.
Definition: SLVec2.h:27
T y
Definition: SLVec2.h:30
T x
Definition: SLVec2.h:30
3D vector template class for standard 3D vector algebra.
Definition: SLVec3.h:40
SLVec3()
Definition: SLVec3.h:49
static SLVec3 CYAN
Definition: SLVec3.h:292
static SLVec3 BLACK
Definition: SLVec3.h:286
SLVec3(const T V)
Definition: SLVec3.h:50
SLVec3 operator^(const SLVec3 &v) const
Definition: SLVec3.h:85
void add(const SLVec3 &a)
Definition: SLVec3.h:112
static SLVec3 YELLOW
Definition: SLVec3.h:294
friend std::ostream & operator<<(std::ostream &output, const SLVec3 &v)
Definition: SLVec3.h:106
SLVec3 & operator&=(const SLVec3 &v)
Definition: SLVec3.h:103
SLVec3 operator&(const SLVec3 &v) const
Definition: SLVec3.h:90
static SLVec3 COLBFH
Definition: SLVec3.h:296
SLbool operator==(const SLVec3 &v) const
Definition: SLVec3.h:69
T comp[3]
Definition: SLVec3.h:46
void latlonAlt2ecef(const SLVec3 &latDegLonDegAltM)
Latitude Longitude Altitude (LatLonAlt) to Earth Centered Earth Fixed (ecef) using the WGS84 model.
Definition: SLVec3.h:269
SLstring toString(SLstring delimiter=", ", int decimals=2)
Conversion to string.
Definition: SLVec3.h:199
void fromString(const SLstring &threeFloatsWithDelimiter, SLchar delimiter=',')
Conversion from string.
Definition: SLVec3.h:206
SLVec3 operator-() const
Definition: SLVec3.h:81
static SLVec3 GREEN
Definition: SLVec3.h:290
void setMax(const SLVec3 &v)
Definition: SLVec3.h:147
void scale(const T s)
Definition: SLVec3.h:116
void add(const SLVec3 &a, const SLVec3 &b)
Definition: SLVec3.h:110
void set(const SLVec3< T > &v)
Definition: SLVec3.h:66
SLbool operator>=(const SLVec3 &v) const
Definition: SLVec3.h:72
void clampMinMax(const T min, const T max)
Definition: SLVec3.h:131
SLVec3 operator+(const SLVec3 &v) const
Definition: SLVec3.h:82
T y
Definition: SLVec3.h:43
SLVec3 & operator*=(const T s)
Definition: SLVec3.h:101
void mix(const SLVec3 &a, const SLVec3 &b, const T factor_b)
Definition: SLVec3.h:138
T diff(const SLVec3 &v)
Definition: SLVec3.h:135
static SLVec3 BLUE
Definition: SLVec3.h:291
SLVec3 normalized() const
Definition: SLVec3.h:127
T lat
Definition: SLVec3.h:45
static SLVec3 AXISY
Definition: SLVec3.h:298
void set(const T v[3])
Definition: SLVec3.h:64
SLbool operator<=(const SLVec3 &v) const
Definition: SLVec3.h:71
T alt
Definition: SLVec3.h:45
void cross(const SLVec3 &a, const SLVec3 &b)
Definition: SLVec3.h:118
T minXYZ()
Definition: SLVec3.h:153
SLbool operator<(const SLVec3 &v) const
Definition: SLVec3.h:73
T x
Definition: SLVec3.h:43
SLVec3 & normalize()
Definition: SLVec3.h:124
static SLVec3 ORANGE
Definition: SLVec3.h:295
SLbool operator!=(const SLVec3 &v) const
Definition: SLVec3.h:70
T b
Definition: SLVec3.h:44
SLbool operator>(const SLVec3 &v) const
Definition: SLVec3.h:74
T length() const
Definition: SLVec3.h:122
T minXYZ(SLint &comp)
Definition: SLVec3.h:159
static SLVec3 AXISX
Definition: SLVec3.h:297
SLVec3(const T v[3])
Definition: SLVec3.h:54
static SLVec3 MAGENTA
Definition: SLVec3.h:293
SLVec3(const SLVec2< T > &v)
Definition: SLVec3.h:55
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59
T operator*(const SLVec3 &v) const
Definition: SLVec3.h:84
T dot(const SLVec3 &v) const
Definition: SLVec3.h:117
SLbool isZero()
Definition: SLVec3.h:165
T r
Definition: SLVec3.h:44
void sub(const SLVec3 &a, const SLVec3 &b)
Definition: SLVec3.h:113
SLVec3 & operator-=(const SLVec3 &v)
Definition: SLVec3.h:98
static SLVec3 WHITE
Definition: SLVec3.h:288
T z
Definition: SLVec3.h:43
void toSpherical(T &r, T &theta, T &phi)
Calculates the spherical coords into r, theta & phi in radians.
Definition: SLVec3.h:180
void set(const T X, const T Y)
Definition: SLVec3.h:62
T maxXYZ(SLint &comp)
Definition: SLVec3.h:156
T distance(const SLVec3 &p) const
Calculate the distance to point p.
Definition: SLVec3.h:168
T distSquared(const SLVec3 &q)
Calculate the squared distance from the vector to point q.
Definition: SLVec3.h:172
T lon
Definition: SLVec3.h:45
void setMin(const SLVec3 &v)
Definition: SLVec3.h:144
static SLVec3 AXISZ
Definition: SLVec3.h:299
SLVec3(const SLstring &threeFloatsWithDelimiter)
Definition: SLVec3.h:57
SLVec3 & operator/=(const T s)
Definition: SLVec3.h:102
void set(const SLVec2< T > &v)
Definition: SLVec3.h:65
SLVec3(const T X, const T Y, const T Z=0)
Definition: SLVec3.h:51
SLVec3(const SLVec3< T > &v)
Definition: SLVec3.h:56
SLVec3 operator/(const T s) const
Definition: SLVec3.h:89
static SLVec3 RED
Definition: SLVec3.h:289
void fromSpherical(T r, T theta, T phi)
Calculates the vector from spherical coords r, theta & phi in radians.
Definition: SLVec3.h:185
void print(const SLchar *str=nullptr)
Prints the vector to std out.
Definition: SLVec3.h:195
T g
Definition: SLVec3.h:44
static SLVec3 ZERO
Definition: SLVec3.h:285
T maxXYZ()
Definition: SLVec3.h:150
void sub(const SLVec3 &a)
Definition: SLVec3.h:115
void ecef2LatLonAlt(const SLVec3 &ecef)
Earth Centered Earth Fixed (ecef) to Latitude Longitude Altitude (LatLonAlt) using the WGS84 model.
Definition: SLVec3.h:243
T lengthSqr() const
Definition: SLVec3.h:123
static SLVec3 GRAY
Definition: SLVec3.h:287
SLVec3 & operator+=(const SLVec3 &v)
Definition: SLVec3.h:97
SLint maxComp()
Definition: SLVec3.h:162
SLVec3 & operator=(const SLVec2< T > &v)
Definition: SLVec3.h:95
void hsv2rgb(const SLVec3 &hsv)
HSV (0-1) to RGB (0-1) color conversion (http://www.rapidtables.com/convert/color/hsv-to-rgb....
Definition: SLVec3.h:216
void gammaCorrect(T oneOverGamma)
Gamma correction.
Definition: SLVec3.h:190
static const float DEG2RAD
Definition: Utils.h:239
T abs(T a)
Definition: Utils.h:249
T clamp(T a, T min, T max)
Definition: Utils.h:253
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
static const float ONEOVERPI
Definition: Utils.h:241
T floor(T a)
Definition: Utils.h:246
static const float RAD2DEG
Definition: Utils.h:238
static const float PI
Definition: Utils.h:237
static const float TWOPI
Definition: Utils.h:240
string toString(float f, int roundedDecimals)
Returns a string from a float with max. one trailing zero.
Definition: Utils.cpp:92