TrueReality  v0.1.1912
Vec4d.h
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author Maxim Serebrennik
20 */
21 #pragma once
22 
23 #include <trBase/Export.h>
24 
25 #include <trUtil/StringUtils.h>
26 #include <trUtil/Math.h>
27 
28 #include <osg/Vec4d>
29 
30 #include <iostream>
31 #include <string>
32 
34 namespace osg
35 {
36  class Vec4f;
37 }
39 
40 namespace trBase
41 {
42  class Vec4f;
43 
48  {
49  public:
50 
52  using value_type = double;
53 
54  const static int NUM_OF_COMPONENTS;
55 
59  Vec4d();
60 
70 
76  Vec4d(const osg::Vec4d &v);
77 
83  Vec4d(const osg::Vec4f &v);
84 
88  const osg::Vec4d& GetOSGVector() const;
89 
93  value_type Length() const;
94 
98  value_type Length2() const;
99 
104  value_type Normalize();
105 
109  value_type& X();
110 
114  value_type& Y();
115 
119  value_type& Z();
120 
124  value_type& W();
125 
129  value_type X() const;
130 
134  value_type Y() const;
135 
139  value_type Z() const;
140 
144  value_type W() const;
145 
149  value_type& R();
150 
154  value_type& G();
155 
159  value_type& B();
160 
164  value_type& A();
165 
169  value_type R() const;
170 
174  value_type G() const;
175 
179  value_type B() const;
180 
184  value_type A() const;
185 
189  void Set(value_type x, value_type y, value_type z, value_type w);
190 
194  void Set(const Vec4d& v);
195 
199  void SetRGBA(value_type r, value_type g, value_type b, value_type a);
200 
207  void Lerp(const Vec4d& to, value_type alpha);
208 
218  Vec4d Lerp(const Vec4d& from, const Vec4d& to, value_type alpha);
219 
229  std::string ToString(int precision = -1);
230 
234  value_type* Ptr();
235 
239  const value_type* Ptr() const;
240 
244  value_type& operator [] (int i);
245 
249  value_type operator [] (int i) const;
250 
254  void operator = (const Vec4d& v);
255 
259  void operator = (const Vec4f& v);
260 
264  void operator = (const osg::Vec4d& v);
265 
269  bool operator == (const Vec4d& v) const;
270 
274  bool operator != (const Vec4d& v) const;
275 
279  bool operator < (const Vec4d& v) const;
280 
284  bool operator > (const Vec4d& v) const;
285 
289  value_type operator * (const Vec4d& rhs) const;
290 
294  const Vec4d operator * (value_type rhs) const;
295 
299  Vec4d& operator *= (value_type rhs);
300 
304  const Vec4d operator / (value_type rhs) const;
305 
309  Vec4d& operator /= (value_type rhs);
310 
314  const Vec4d operator + (const Vec4d& rhs) const;
315 
320  Vec4d& operator += (const Vec4d& rhs);
321 
325  const Vec4d operator - (const Vec4d& rhs) const;
326 
330  Vec4d& operator -= (const Vec4d& rhs);
331 
332 
336  const Vec4d operator - () const;
337 
341  operator osg::Vec4d() const;
342 
346  operator osg::Vec4d& ();
347 
351  operator const osg::Vec4d& () const;
352 
356  operator osg::Vec4d* ();
357 
358  protected:
359 
360  osg::Vec4d mVec;
361  };
362 
371  TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4d& vec);
372 
376  TR_BASE_EXPORT Vec4d ComponentMultiply(const Vec4d& lhs, const Vec4d& rhs);
377 
381  TR_BASE_EXPORT Vec4d ComponentDivide(const Vec4d& lhs, const Vec4d& rhs);
382 }
#define TR_BASE_EXPORT
Definition: trBase/Export.h:34
std::string operator+(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:193
bool operator==(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:187
TR_BASE_EXPORT Vec4d ComponentMultiply(const Vec4d &lhs, const Vec4d &rhs)
Multiply individual vector components.
General purpose 3D float Vector.
Definition: Vec4f.h:47
bool operator!=(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:199
TR_BASE_EXPORT std::ostream & operator<<(std::ostream &ios, const Vec4d &vec)
Stream insertion operator.
osg::Vec4d mVec
Definition: Vec4d.h:360
General purpose 3D double Vector.
Definition: Vec4d.h:47
std::string ToString(const T &t, int precision=-1)
A utility function to convert a basic type into a string.
Definition: StringUtils.h:334
double value_type
Data type of vector components.
Definition: Vec4d.h:52
T Lerp(T from, T to, T alpha)
Linear Interpolation function.
Definition: Math.h:191
static const int NUM_OF_COMPONENTS
Definition: Vec4d.h:54
Definition: FrameStamp.h:37
TR_BASE_EXPORT Vec4d ComponentDivide(const Vec4d &lhs, const Vec4d &rhs)
Divide rhs components by rhs vector components.