TrueReality  v0.1.1912
Vec2f.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 
22 #pragma once
23 
24 #include <trBase/Export.h>
25 
26 #include <trUtil/StringUtils.h>
27 #include <trUtil/Math.h>
28 
29 #include <osg/Vec2f>
30 
31 #include <iostream>
32 #include <string>
33 
35 namespace osg
36 {
37  class Vec2d;
38 }
40 
41 namespace trBase
42 {
43  class Vec2d;
44 
49  {
50  public:
51 
53  using value_type = float;
54 
55  const static int NUM_OF_COMPONENTS;
56 
60  Vec2f();
61 
69 
75  Vec2f(const osg::Vec2f &v);
76 
82  Vec2f(const osg::Vec2d &v);
83 
87  const osg::Vec2f& 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 X() const;
119 
123  value_type Y() const;
124 
128  void Set(value_type x, value_type y);
129 
136  void Lerp(const Vec2f& to, value_type alpha);
137 
147  Vec2f Lerp(const Vec2f& from, const Vec2f& to, value_type alpha);
148 
158  std::string ToString(int precision = -1);
159 
163  value_type* Ptr();
164 
168  const value_type* Ptr() const;
169 
173  value_type& operator [] (int i);
174 
178  value_type operator [] (int i) const;
179 
183  void operator = (const Vec2f& v);
184 
188  void operator = (const Vec2d& v);
189 
193  void operator = (const osg::Vec2f& v);
194 
198  bool operator == (const Vec2f& v) const;
199 
203  bool operator != (const Vec2f& v) const;
204 
208  bool operator < (const Vec2f& v) const;
209 
213  bool operator > (const Vec2f& v) const;
214 
218  value_type operator * (const Vec2f& rhs) const;
219 
223  const Vec2f operator * (value_type rhs) const;
224 
228  Vec2f& operator *= (value_type rhs);
229 
233  const Vec2f operator / (value_type rhs) const;
234 
238  Vec2f& operator /= (value_type rhs);
239 
243  const Vec2f operator + (const Vec2f& rhs) const;
244 
249  Vec2f& operator += (const Vec2f& rhs);
250 
254  const Vec2f operator - (const Vec2f& rhs) const;
255 
259  Vec2f& operator -= (const Vec2f& rhs);
260 
264  const Vec2f operator - () const;
265 
269  operator osg::Vec2f() const;
270 
274  operator osg::Vec2f& ();
275 
279  operator const osg::Vec2f& () const;
280 
284  operator osg::Vec2f* ();
285 
286  protected:
287 
288  osg::Vec2f mVec;
289  };
290 
299  TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2f& vec);
300 
304  TR_BASE_EXPORT Vec2f ComponentMultiply(const Vec2f& lhs, const Vec2f& rhs);
305 
309  TR_BASE_EXPORT Vec2f ComponentDivide(const Vec2f& lhs, const Vec2f& rhs);
310 }
#define TR_BASE_EXPORT
Definition: trBase/Export.h:34
std::string operator+(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:193
General purpose 2D float Vector.
Definition: Vec2f.h:48
TR_BASE_EXPORT Vec2f ComponentDivide(const Vec2f &lhs, const Vec2f &rhs)
Divide rhs components by rhs vector components.
bool operator==(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:187
bool operator!=(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:199
General purpose 2D double Vector.
Definition: Vec2d.h:48
float value_type
Data type of vector components.
Definition: Vec2f.h:53
std::string ToString(const T &t, int precision=-1)
A utility function to convert a basic type into a string.
Definition: StringUtils.h:334
TR_BASE_EXPORT Vec2f ComponentMultiply(const Vec2f &lhs, const Vec2f &rhs)
Multiply individual vector components.
osg::Vec2f mVec
Definition: Vec2f.h:288
static const int NUM_OF_COMPONENTS
Definition: Vec2f.h:55
T Lerp(T from, T to, T alpha)
Linear Interpolation function.
Definition: Math.h:191
Definition: FrameStamp.h:37
TR_BASE_EXPORT std::ostream & operator<<(std::ostream &ios, const Vec2f &vec)
Stream insertion operator.