OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec4ub.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSG_VEC4UB
15 #define OSG_VEC4UB 1
16 
17 #include <osg/Vec3>
18 
19 namespace osg {
20 
27 class Vec4ub
28 {
29  public:
30 
32  typedef unsigned char value_type;
33 
35  enum { num_components = 4 };
36 
38  value_type _v[4];
39 
41  Vec4ub() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
42 
43  Vec4ub(value_type x, value_type y, value_type z, value_type w)
44  {
45  _v[0]=x;
46  _v[1]=y;
47  _v[2]=z;
48  _v[3]=w;
49  }
50 
51  inline bool operator == (const Vec4ub& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
52 
53  inline bool operator != (const Vec4ub& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
54 
55  inline bool operator < (const Vec4ub& v) const
56  {
57  if (_v[0]<v._v[0]) return true;
58  else if (_v[0]>v._v[0]) return false;
59  else if (_v[1]<v._v[1]) return true;
60  else if (_v[1]>v._v[1]) return false;
61  else if (_v[2]<v._v[2]) return true;
62  else if (_v[2]>v._v[2]) return false;
63  else return (_v[3]<v._v[3]);
64  }
65 
66  inline value_type* ptr() { return _v; }
67  inline const value_type* ptr() const { return _v; }
68 
69  inline void set(value_type r, value_type g, value_type b, value_type a)
70  {
71  _v[0]=r; _v[1]=g; _v[2]=b; _v[3]=a;
72  }
73 
74  inline value_type& operator [] (unsigned int i) { return _v[i]; }
75  inline value_type operator [] (unsigned int i) const { return _v[i]; }
76 
77  inline value_type& r() { return _v[0]; }
78  inline value_type& g() { return _v[1]; }
79  inline value_type& b() { return _v[2]; }
80  inline value_type& a() { return _v[3]; }
81 
82  inline value_type r() const { return _v[0]; }
83  inline value_type g() const { return _v[1]; }
84  inline value_type b() const { return _v[2]; }
85  inline value_type a() const { return _v[3]; }
86 
88  inline Vec4ub operator * (float rhs) const
89  {
90  Vec4ub col(*this);
91  col *= rhs;
92  return col;
93  }
94 
96  inline Vec4ub& operator *= (float rhs)
97  {
98  _v[0]=(value_type)((float)_v[0]*rhs);
99  _v[1]=(value_type)((float)_v[1]*rhs);
100  _v[2]=(value_type)((float)_v[2]*rhs);
101  _v[3]=(value_type)((float)_v[3]*rhs);
102  return *this;
103  }
104 
106  inline Vec4ub operator / (float rhs) const
107  {
108  Vec4ub col(*this);
109  col /= rhs;
110  return col;
111  }
112 
114  inline Vec4ub& operator /= (float rhs)
115  {
116  float div = 1.0f/rhs;
117  *this *= div;
118  return *this;
119  }
120 
122  inline Vec4ub operator + (const Vec4ub& rhs) const
123  {
124  return Vec4ub(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
125  _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
126  }
127 
131  inline Vec4ub& operator += (const Vec4ub& rhs)
132  {
133  _v[0] += rhs._v[0];
134  _v[1] += rhs._v[1];
135  _v[2] += rhs._v[2];
136  _v[3] += rhs._v[3];
137  return *this;
138  }
139 
141  inline Vec4ub operator - (const Vec4ub& rhs) const
142  {
143  return Vec4ub(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
144  _v[2]-rhs._v[2], _v[3]-rhs._v[3] );
145  }
146 
148  inline Vec4ub& operator -= (const Vec4ub& rhs)
149  {
150  _v[0]-=rhs._v[0];
151  _v[1]-=rhs._v[1];
152  _v[2]-=rhs._v[2];
153  _v[3]-=rhs._v[3];
154  return *this;
155  }
156 
157 }; // end of class Vec4ub
158 
159 } // end of namespace osg
160 
161 #endif
Vec4ub operator+(const Vec4ub &rhs) const
Definition: Vec4ub.h:122
const value_type * ptr() const
Definition: Vec4ub.h:67
bool operator!=(const Vec4ub &v) const
Definition: Vec4ub.h:53
value_type & a()
Definition: Vec4ub.h:80
unsigned char value_type
Definition: Vec4ub.h:32
value_type * ptr()
Definition: Vec4ub.h:66
Vec4ub()
Definition: Vec4ub.h:41
value_type r() const
Definition: Vec4ub.h:82
Vec4ub(value_type x, value_type y, value_type z, value_type w)
Definition: Vec4ub.h:43
void set(value_type r, value_type g, value_type b, value_type a)
Definition: Vec4ub.h:69
value_type & b()
Definition: Vec4ub.h:79
Vec4ub & operator-=(const Vec4ub &rhs)
Definition: Vec4ub.h:148
bool operator<(const Vec4ub &v) const
Definition: Vec4ub.h:55
Vec4ub & operator+=(const Vec4ub &rhs)
Definition: Vec4ub.h:131
Vec4ub operator-(const Vec4ub &rhs) const
Definition: Vec4ub.h:141
Vec4ub operator/(float rhs) const
Definition: Vec4ub.h:106
value_type & r()
Definition: Vec4ub.h:77
value_type & operator[](unsigned int i)
Definition: Vec4ub.h:74
value_type g() const
Definition: Vec4ub.h:83
Vec4ub operator*(float rhs) const
Definition: Vec4ub.h:88
value_type _v[4]
Definition: Vec4ub.h:38
Vec4ub & operator*=(float rhs)
Definition: Vec4ub.h:96
Definition: AlphaFunc.h:19
bool operator==(const Vec4ub &v) const
Definition: Vec4ub.h:51
value_type b() const
Definition: Vec4ub.h:84
value_type a() const
Definition: Vec4ub.h:85
Vec4ub & operator/=(float rhs)
Definition: Vec4ub.h:114
value_type & g()
Definition: Vec4ub.h:78