TrueReality  v0.1.1912
Vec4b.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/Vec4b>
29 
30 #include <iostream>
31 #include <string>
32 
33 namespace trBase
34 {
39  {
40  public:
41 
43  using value_type = signed char;
44 
45  const static int NUM_OF_COMPONENTS;
46 
50  Vec4b();
51 
61 
67  Vec4b(const osg::Vec4b &v);
68 
72  const osg::Vec4b& GetOSGVector() const;
73 
77  value_type Length() const;
78 
82  value_type Length2() const;
83 
88  value_type Normalize();
89 
93  value_type& X();
94 
98  value_type& Y();
99 
103  value_type& Z();
104 
108  value_type& W();
109 
113  value_type X() const;
114 
118  value_type Y() const;
119 
123  value_type Z() const;
124 
128  value_type W() const;
129 
133  value_type& R();
134 
138  value_type& G();
139 
143  value_type& B();
144 
148  value_type& A();
149 
153  value_type R() const;
154 
158  value_type G() const;
159 
163  value_type B() const;
164 
168  value_type A() const;
169 
173  void Set(value_type x, value_type y, value_type z, value_type w);
174 
178  void Set(const Vec4b& v);
179 
183  void SetRGBA(value_type r, value_type g, value_type b, value_type a);
184 
191  void Lerp(const Vec4b& to, value_type alpha);
192 
202  Vec4b Lerp(const Vec4b& from, const Vec4b& to, value_type alpha);
203 
213  std::string ToString(int precision = -1);
214 
218  value_type* Ptr();
219 
223  const value_type* Ptr() const;
224 
228  value_type& operator [] (int i);
229 
233  value_type operator [] (int i) const;
234 
238  void operator = (const Vec4b& v);
239 
243  void operator = (const osg::Vec4b& v);
244 
248  bool operator == (const Vec4b& v) const;
249 
253  bool operator != (const Vec4b& v) const;
254 
258  bool operator < (const Vec4b& v) const;
259 
263  bool operator > (const Vec4b& v) const;
264 
268  value_type operator * (const Vec4b& rhs) const;
269 
273  const Vec4b operator * (value_type rhs) const;
274 
278  Vec4b& operator *= (value_type rhs);
279 
283  const Vec4b operator / (value_type rhs) const;
284 
288  Vec4b& operator /= (value_type rhs);
289 
293  const Vec4b operator + (const Vec4b& rhs) const;
294 
299  Vec4b& operator += (const Vec4b& rhs);
300 
304  const Vec4b operator - (const Vec4b& rhs) const;
305 
309  Vec4b& operator -= (const Vec4b& rhs);
310 
314  const Vec4b operator - () const;
315 
319  operator osg::Vec4b() const;
320 
324  operator osg::Vec4b& ();
325 
329  operator const osg::Vec4b& () const;
330 
334  operator osg::Vec4b* ();
335 
336  protected:
337 
338  osg::Vec4b mVec;
339  };
340 
349  TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4b& vec);
350 
354  TR_BASE_EXPORT Vec4b ComponentMultiply(const Vec4b& lhs, const Vec4b& rhs);
355 
359  TR_BASE_EXPORT Vec4b ComponentDivide(const Vec4b& lhs, const Vec4b& rhs);
360 }
#define TR_BASE_EXPORT
Definition: trBase/Export.h:34
static const int NUM_OF_COMPONENTS
Definition: Vec4b.h:45
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::Vec4b mVec
Definition: Vec4b.h:338
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.
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.
General purpose 3D byte Vector.
Definition: Vec4b.h:38
TR_BASE_EXPORT Vec2b ComponentMultiply(const Vec2b &lhs, const Vec2b &rhs)
Multiply individual vector components.
signed char value_type
Data type of vector components.
Definition: Vec4b.h:43
T Lerp(T from, T to, T alpha)
Linear Interpolation function.
Definition: Math.h:191