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