TrueReality  v0.1.1912
Vec3s.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/Vec3s>
29 
30 #include <iostream>
31 #include <string>
32 
33 namespace trBase
34 {
39  {
40  public:
41 
43  using value_type = short;
44 
45  const static int NUM_OF_COMPONENTS;
46 
50  Vec3s();
51 
60 
66  Vec3s(const osg::Vec3s &v);
67 
71  const osg::Vec3s& GetOSGVector() const;
72 
76  value_type Length() const;
77 
81  value_type Length2() const;
82 
87  value_type Normalize();
88 
92  value_type& X();
93 
97  value_type& Y();
98 
102  value_type& Z();
103 
107  value_type X() const;
108 
112  value_type Y() const;
113 
117  value_type Z() const;
118 
122  value_type& R();
123 
127  value_type& G();
128 
132  value_type& B();
133 
137  value_type R() const;
138 
142  value_type G() const;
143 
147  value_type B() const;
148 
152  void Set(value_type x, value_type y, value_type z);
153 
157  void Set(const Vec3s& v);
158 
162  void SetRGB(value_type r, value_type g, value_type b);
163 
170  void Lerp(const Vec3s& to, value_type alpha);
171 
181  Vec3s Lerp(const Vec3s& from, const Vec3s& to, value_type alpha);
182 
192  std::string ToString(int precision = -1);
193 
197  value_type* Ptr();
198 
202  const value_type* Ptr() const;
203 
207  value_type& operator [] (int i);
208 
212  value_type operator [] (int i) const;
213 
217  void operator = (const Vec3s& v);
218 
222  void operator = (const osg::Vec3s& v);
223 
227  bool operator == (const Vec3s& v) const;
228 
232  bool operator != (const Vec3s& v) const;
233 
237  bool operator < (const Vec3s& v) const;
238 
242  bool operator > (const Vec3s& v) const;
243 
247  value_type operator * (const Vec3s& rhs) const;
248 
252  const Vec3s operator * (value_type rhs) const;
253 
257  Vec3s& operator *= (value_type rhs);
258 
262  const Vec3s operator / (value_type rhs) const;
263 
267  Vec3s& operator /= (value_type rhs);
268 
272  const Vec3s operator + (const Vec3s& rhs) const;
273 
278  Vec3s& operator += (const Vec3s& rhs);
279 
283  const Vec3s operator - (const Vec3s& rhs) const;
284 
288  Vec3s& operator -= (const Vec3s& rhs);
289 
293  const Vec3s operator - () const;
294 
298  const Vec3s operator ^ (const Vec3s& rhs) const;
299 
303  operator osg::Vec3s() const;
304 
308  operator osg::Vec3s& ();
309 
313  operator const osg::Vec3s& () const;
314 
318  operator osg::Vec3s* ();
319 
320  protected:
321 
322  osg::Vec3s mVec;
323  };
324 
333  TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3s& vec);
334 
338  TR_BASE_EXPORT Vec3s ComponentMultiply(const Vec3s& lhs, const Vec3s& rhs);
339 
343  TR_BASE_EXPORT Vec3s ComponentDivide(const Vec3s& lhs, const Vec3s& rhs);
344 }
#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
osg::Vec3s mVec
Definition: Vec3s.h:322
bool operator!=(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:199
TR_BASE_EXPORT std::ostream & operator<<(std::ostream &ios, const Matrixd &q)
Stream insertion operator.
General purpose 3D short Vector.
Definition: Vec3s.h:38
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 Vec2b ComponentDivide(const Vec2b &lhs, const Vec2b &rhs)
Divide rhs components by rhs vector components.
TR_BASE_EXPORT Vec2b ComponentMultiply(const Vec2b &lhs, const Vec2b &rhs)
Multiply individual vector components.
short value_type
Data type of vector components.
Definition: Vec3s.h:43
T Lerp(T from, T to, T alpha)
Linear Interpolation function.
Definition: Math.h:191
static const int NUM_OF_COMPONENTS
Definition: Vec3s.h:45