OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec3ub.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_VEC3UB
15 #define OSG_VEC3UB 1
16 
17 namespace osg {
18 
25 class Vec3ub
26 {
27  public:
28 
30  typedef unsigned char value_type;
31 
33  enum { num_components = 3 };
34 
35  value_type _v[3];
36 
38  Vec3ub() { _v[0]=0; _v[1]=0; _v[2]=0; }
39 
40  Vec3ub(value_type r, value_type g, value_type b) { _v[0]=r; _v[1]=g; _v[2]=b; }
41 
42  inline bool operator == (const Vec3ub& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
43 
44  inline bool operator != (const Vec3ub& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
45 
46  inline bool operator < (const Vec3ub& v) const
47  {
48  if (_v[0]<v._v[0]) return true;
49  else if (_v[0]>v._v[0]) return false;
50  else if (_v[1]<v._v[1]) return true;
51  else if (_v[1]>v._v[1]) return false;
52  else return (_v[2]<v._v[2]);
53  }
54 
55  inline value_type* ptr() { return _v; }
56  inline const value_type* ptr() const { return _v; }
57 
58  inline void set(value_type r, value_type g, value_type b)
59  {
60  _v[0]=r; _v[1]=g; _v[2]=b;
61  }
62 
63  inline void set( const Vec3ub& rhs)
64  {
65  _v[0]=rhs._v[0]; _v[1]=rhs._v[1]; _v[2]=rhs._v[2];
66  }
67 
68  inline value_type& operator [] (unsigned int i) { return _v[i]; }
69  inline value_type operator [] (unsigned int i) const { return _v[i]; }
70 
71  inline value_type& x() { return _v[0]; }
72  inline value_type& y() { return _v[1]; }
73  inline value_type& z() { return _v[2]; }
74 
75  inline value_type x() const { return _v[0]; }
76  inline value_type y() const { return _v[1]; }
77  inline value_type z() const { return _v[2]; }
78 
79  inline value_type& r() { return _v[0]; }
80  inline value_type& g() { return _v[1]; }
81  inline value_type& b() { return _v[2]; }
82 
83  inline value_type r() const { return _v[0]; }
84  inline value_type g() const { return _v[1]; }
85  inline value_type b() const { return _v[2]; }
86 
88  inline Vec3ub operator * (float rhs) const
89  {
90  Vec3ub col(*this);
91  col *= rhs;
92  return col;
93  }
94 
96  inline Vec3ub& 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  return *this;
102  }
103 
105  inline Vec3ub operator / (float rhs) const
106  {
107  Vec3ub col(*this);
108  col /= rhs;
109  return col;
110  }
111 
113  inline Vec3ub& operator /= (float rhs)
114  {
115  float div = 1.0f/rhs;
116  *this *= div;
117  return *this;
118  }
119 
121  inline Vec3ub operator + (const Vec3ub& rhs) const
122  {
123  return Vec3ub(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
124  _v[2]+rhs._v[2]);
125  }
126 
130  inline Vec3ub& operator += (const Vec3ub& rhs)
131  {
132  _v[0] += rhs._v[0];
133  _v[1] += rhs._v[1];
134  _v[2] += rhs._v[2];
135  return *this;
136  }
137 
139  inline Vec3ub operator - (const Vec3ub& rhs) const
140  {
141  return Vec3ub(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
142  _v[2]-rhs._v[2]);
143  }
144 
146  inline Vec3ub& operator -= (const Vec3ub& rhs)
147  {
148  _v[0]-=rhs._v[0];
149  _v[1]-=rhs._v[1];
150  _v[2]-=rhs._v[2];
151  return *this;
152  }
153 
154 }; // end of class Vec3ub
155 
157 inline Vec3ub componentMultiply(const Vec3ub& lhs, const Vec3ub& rhs)
158 {
159  return Vec3ub(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2]);
160 }
161 
163 inline Vec3ub componentDivide(const Vec3ub& lhs, const Vec3ub& rhs)
164 {
165  return Vec3ub(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2]);
166 }
167 
168 } // end of namespace osg
169 
170 #endif
value_type r() const
Definition: Vec3ub.h:83
const value_type * ptr() const
Definition: Vec3ub.h:56
value_type & z()
Definition: Vec3ub.h:73
Vec3ub operator-(const Vec3ub &rhs) const
Definition: Vec3ub.h:139
value_type _v[3]
Definition: Vec3ub.h:35
Vec3ub(value_type r, value_type g, value_type b)
Definition: Vec3ub.h:40
value_type * ptr()
Definition: Vec3ub.h:55
bool operator!=(const Vec3ub &v) const
Definition: Vec3ub.h:44
Vec3ub operator/(float rhs) const
Definition: Vec3ub.h:105
bool operator<(const Vec3ub &v) const
Definition: Vec3ub.h:46
Vec3ub()
Definition: Vec3ub.h:38
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
Definition: Vec2d.h:187
Vec3ub & operator+=(const Vec3ub &rhs)
Definition: Vec3ub.h:130
value_type g() const
Definition: Vec3ub.h:84
Vec3ub & operator*=(float rhs)
Definition: Vec3ub.h:96
void set(value_type r, value_type g, value_type b)
Definition: Vec3ub.h:58
Vec3ub & operator/=(float rhs)
Definition: Vec3ub.h:113
Vec3ub & operator-=(const Vec3ub &rhs)
Definition: Vec3ub.h:146
value_type y() const
Definition: Vec3ub.h:76
void set(const Vec3ub &rhs)
Definition: Vec3ub.h:63
Vec3ub operator+(const Vec3ub &rhs) const
Definition: Vec3ub.h:121
Vec3ub operator*(float rhs) const
Definition: Vec3ub.h:88
bool operator==(const Vec3ub &v) const
Definition: Vec3ub.h:42
value_type & r()
Definition: Vec3ub.h:79
Definition: AlphaFunc.h:19
value_type & operator[](unsigned int i)
Definition: Vec3ub.h:68
unsigned char value_type
Definition: Vec3ub.h:30
value_type & g()
Definition: Vec3ub.h:80
value_type & x()
Definition: Vec3ub.h:71
value_type b() const
Definition: Vec3ub.h:85
value_type & b()
Definition: Vec3ub.h:81
value_type & y()
Definition: Vec3ub.h:72
value_type z() const
Definition: Vec3ub.h:77
value_type x() const
Definition: Vec3ub.h:75
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
Definition: Vec2d.h:181