TrueReality  v0.1.1912
Vec3f.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/Vec3f>
29 
30 #include <iostream>
31 #include <string>
32 
34 namespace osg
35 {
36  class Vec3d;
37 }
39 
40 namespace trBase
41 {
42  class Vec3d;
43 
48  {
49  public:
50 
52  using value_type = float;
53 
54  const static int NUM_OF_COMPONENTS;
55 
59  Vec3f();
60 
69 
75  Vec3f(const osg::Vec3f &v);
76 
82  Vec3f(const osg::Vec3d &v);
83 
87  const osg::Vec3f& GetOSGVector() const;
88 
92  value_type Length() const;
93 
97  value_type Length2() const;
98 
103  value_type Normalize();
104 
108  value_type& X();
109 
113  value_type& Y();
114 
118  value_type& Z();
119 
123  value_type X() const;
124 
128  value_type Y() const;
129 
133  value_type Z() const;
134 
138  value_type& R();
139 
143  value_type& G();
144 
148  value_type& B();
149 
153  value_type R() const;
154 
158  value_type G() const;
159 
163  value_type B() const;
164 
168  void Set(value_type x, value_type y, value_type z);
169 
173  void Set(const Vec3f& v);
174 
178  void SetRGB(value_type r, value_type g, value_type b);
179 
186  void Lerp(const Vec3f& to, value_type alpha);
187 
197  Vec3f Lerp(const Vec3f& from, const Vec3f& to, value_type alpha);
198 
208  std::string ToString(int precision = -1);
209 
213  value_type* Ptr();
214 
218  const value_type* Ptr() const;
219 
223  value_type& operator [] (int i);
224 
228  value_type operator [] (int i) const;
229 
233  void operator = (const Vec3f& v);
234 
238  void operator = (const Vec3d& v);
239 
243  void operator = (const osg::Vec3f& v);
244 
248  bool operator == (const Vec3f& v) const;
249 
253  bool operator != (const Vec3f& v) const;
254 
258  bool operator < (const Vec3f& v) const;
259 
263  bool operator > (const Vec3f& v) const;
264 
268  value_type operator * (const Vec3f& rhs) const;
269 
273  const Vec3f operator * (value_type rhs) const;
274 
278  Vec3f& operator *= (value_type rhs);
279 
283  const Vec3f operator / (value_type rhs) const;
284 
288  Vec3f& operator /= (value_type rhs);
289 
293  const Vec3f operator + (const Vec3f& rhs) const;
294 
299  Vec3f& operator += (const Vec3f& rhs);
300 
304  const Vec3f operator - (const Vec3f& rhs) const;
305 
309  Vec3f& operator -= (const Vec3f& rhs);
310 
314  const Vec3f operator - () const;
315 
319  const Vec3f operator ^ (const Vec3f& rhs) const;
320 
324  operator osg::Vec3f() const;
325 
329  operator osg::Vec3f& ();
330 
334  operator const osg::Vec3f& () const;
335 
339  operator osg::Vec3f* ();
340 
341  protected:
342 
343  osg::Vec3f mVec;
344  };
345 
354  TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3f& vec);
355 
359  TR_BASE_EXPORT Vec3f ComponentMultiply(const Vec3f& lhs, const Vec3f& rhs);
360 
364  TR_BASE_EXPORT Vec3f ComponentDivide(const Vec3f& lhs, const Vec3f& rhs);
365 }
#define TR_BASE_EXPORT
Definition: trBase/Export.h:34
float value_type
Data type of vector components.
Definition: Vec3f.h:52
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 Vec3f ComponentDivide(const Vec3f &lhs, const Vec3f &rhs)
Divide rhs components by rhs vector components.
bool operator!=(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:199
General purpose 3D double Vector.
Definition: Vec3d.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
osg::Vec3f mVec
Definition: Vec3f.h:343
TR_BASE_EXPORT Vec3f ComponentMultiply(const Vec3f &lhs, const Vec3f &rhs)
Multiply individual vector components.
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: Vec3f.h:54
TR_BASE_EXPORT std::ostream & operator<<(std::ostream &ios, const Vec3f &vec)
Stream insertion operator.
General purpose 3D float Vector.
Definition: Vec3f.h:47