TrueReality  v0.1.1912
Vec4f.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/Vec4f>
29 
30 #include <iostream>
31 #include <string>
32 
34 namespace osg
35 {
36  class Vec4d;
37 }
39 
40 namespace trBase
41 {
42  class Vec4d;
43 
48  {
49  public:
50 
52  using value_type = float;
53 
54  const static int NUM_OF_COMPONENTS;
55 
59  Vec4f();
60 
70 
76  Vec4f(const osg::Vec4f &v);
77 
83  Vec4f(const osg::Vec4d &v);
84 
88  const osg::Vec4f& 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 Vec4f& v);
195 
199  void SetRGBA(value_type r, value_type g, value_type b, value_type a);
200 
207  void Lerp(const Vec4f& to, value_type alpha);
208 
218  Vec4f Lerp(const Vec4f& from, const Vec4f& 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 Vec4f& v);
255 
259  void operator = (const Vec4d& v);
260 
264  void operator = (const osg::Vec4f& v);
265 
269  bool operator == (const Vec4f& v) const;
270 
274  bool operator != (const Vec4f& v) const;
275 
279  bool operator < (const Vec4f& v) const;
280 
284  bool operator > (const Vec4f& v) const;
285 
289  value_type operator * (const Vec4f& rhs) const;
290 
294  const Vec4f operator * (value_type rhs) const;
295 
299  Vec4f& operator *= (value_type rhs);
300 
304  const Vec4f operator / (value_type rhs) const;
305 
309  Vec4f& operator /= (value_type rhs);
310 
314  const Vec4f operator + (const Vec4f& rhs) const;
315 
320  Vec4f& operator += (const Vec4f& rhs);
321 
325  const Vec4f operator - (const Vec4f& rhs) const;
326 
330  Vec4f& operator -= (const Vec4f& rhs);
331 
335  const Vec4f operator - () const;
336 
340  operator osg::Vec4f() const;
341 
345  operator osg::Vec4f& ();
346 
350  operator const osg::Vec4f& () const;
351 
355  operator osg::Vec4f* ();
356 
357  protected:
358 
359  osg::Vec4f mVec;
360  };
361 
370  TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4f& vec);
371 
375  TR_BASE_EXPORT Vec4f ComponentMultiply(const Vec4f& lhs, const Vec4f& rhs);
376 
380  TR_BASE_EXPORT Vec4f ComponentDivide(const Vec4f& lhs, const Vec4f& rhs);
381 }
#define TR_BASE_EXPORT
Definition: trBase/Export.h:34
TR_BASE_EXPORT Vec4f ComponentDivide(const Vec4f &lhs, const Vec4f &rhs)
Divide rhs components by rhs vector components.
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
General purpose 3D float Vector.
Definition: Vec4f.h:47
bool operator!=(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:199
float value_type
Data type of vector components.
Definition: Vec4f.h:52
TR_BASE_EXPORT Vec4f ComponentMultiply(const Vec4f &lhs, const Vec4f &rhs)
Multiply individual vector components.
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
T Lerp(T from, T to, T alpha)
Linear Interpolation function.
Definition: Math.h:191
Definition: FrameStamp.h:37
static const int NUM_OF_COMPONENTS
Definition: Vec4f.h:54
osg::Vec4f mVec
Definition: Vec4f.h:359
TR_BASE_EXPORT std::ostream & operator<<(std::ostream &ios, const Vec4f &vec)
Stream insertion operator.