OpenSceneGraph 3.6.5
Vec4ub
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/Vec4f>
18
19namespace osg {
20
27class Vec4ub
28{
29 public:
30
32 typedef unsigned char value_type;
33
35 enum { num_components = 4 };
36
39
41 Vec4ub() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
42
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
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& x() { return _v[0]; }
78 inline value_type& y() { return _v[1]; }
79 inline value_type& z() { return _v[2]; }
80 inline value_type& w() { return _v[3]; }
81
82 inline value_type x() const { return _v[0]; }
83 inline value_type y() const { return _v[1]; }
84 inline value_type z() const { return _v[2]; }
85 inline value_type w() const { return _v[3]; }
86
87 inline value_type& r() { return _v[0]; }
88 inline value_type& g() { return _v[1]; }
89 inline value_type& b() { return _v[2]; }
90 inline value_type& a() { return _v[3]; }
91
92 inline value_type r() const { return _v[0]; }
93 inline value_type g() const { return _v[1]; }
94 inline value_type b() const { return _v[2]; }
95 inline value_type a() const { return _v[3]; }
96
98 inline Vec4ub operator * (float rhs) const
99 {
100 Vec4ub col(*this);
101 col *= rhs;
102 return col;
103 }
104
106 inline Vec4ub& operator *= (float rhs)
107 {
108 _v[0]=(value_type)((float)_v[0]*rhs);
109 _v[1]=(value_type)((float)_v[1]*rhs);
110 _v[2]=(value_type)((float)_v[2]*rhs);
111 _v[3]=(value_type)((float)_v[3]*rhs);
112 return *this;
113 }
114
116 inline Vec4ub operator / (float rhs) const
117 {
118 Vec4ub col(*this);
119 col /= rhs;
120 return col;
121 }
122
124 inline Vec4ub& operator /= (float rhs)
125 {
126 float div = 1.0f/rhs;
127 *this *= div;
128 return *this;
129 }
130
132 inline Vec4ub operator + (const Vec4ub& rhs) const
133 {
134 return Vec4ub(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
135 _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
136 }
137
141 inline Vec4ub& operator += (const Vec4ub& rhs)
142 {
143 _v[0] += rhs._v[0];
144 _v[1] += rhs._v[1];
145 _v[2] += rhs._v[2];
146 _v[3] += rhs._v[3];
147 return *this;
148 }
149
151 inline Vec4ub operator - (const Vec4ub& rhs) const
152 {
153 return Vec4ub(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
154 _v[2]-rhs._v[2], _v[3]-rhs._v[3] );
155 }
156
158 inline Vec4ub& operator -= (const Vec4ub& rhs)
159 {
160 _v[0]-=rhs._v[0];
161 _v[1]-=rhs._v[1];
162 _v[2]-=rhs._v[2];
163 _v[3]-=rhs._v[3];
164 return *this;
165 }
166
167}; // end of class Vec4ub
168
169inline Vec4ub convertToRGBA8(const Vec4f& color)
170{
171 return Vec4ub(static_cast<unsigned char>(color.r()*255.0f),
172 static_cast<unsigned char>(color.g()*255.0f),
173 static_cast<unsigned char>(color.b()*255.0f),
174 static_cast<unsigned char>(color.a()*255.0f));
175
176}
177
178inline Vec4ub convertToRGBA8(float r, float g, float b, float a)
179{
180 return Vec4ub(static_cast<unsigned char>(r*255.0f),
181 static_cast<unsigned char>(g*255.0f),
182 static_cast<unsigned char>(b*255.0f),
183 static_cast<unsigned char>(a*255.0f));
184
185}
186
187} // end of namespace osg
188
189#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Vec4ub convertToRGBA8(const Vec4f &color)
Definition Vec4ub:169
General purpose float quad.
Definition Vec4f:28
value_type & r()
Definition Vec4f:97
value_type & g()
Definition Vec4f:98
value_type & a()
Definition Vec4f:100
value_type & b()
Definition Vec4f:99
General purpose float quad.
Definition Vec4ub:28
Vec4ub(value_type x, value_type y, value_type z, value_type w)
Definition Vec4ub:43
@ num_components
Definition Vec4ub:35
value_type & z()
Definition Vec4ub:79
value_type & g()
Definition Vec4ub:88
Vec4ub operator+(const Vec4ub &rhs) const
Binary vector add.
Definition Vec4ub:132
value_type & operator[](unsigned int i)
Definition Vec4ub:74
unsigned char value_type
Data type of vector components.
Definition Vec4ub:32
bool operator<(const Vec4ub &v) const
Definition Vec4ub:55
value_type _v[4]
Vec member variable.
Definition Vec4ub:38
value_type g() const
Definition Vec4ub:93
Vec4ub operator/(float rhs) const
Divide by scalar.
Definition Vec4ub:116
value_type & a()
Definition Vec4ub:90
value_type z() const
Definition Vec4ub:84
value_type & w()
Definition Vec4ub:80
Vec4ub operator-(const Vec4ub &rhs) const
Binary vector subtract.
Definition Vec4ub:151
void set(value_type r, value_type g, value_type b, value_type a)
Definition Vec4ub:69
Vec4ub & operator*=(float rhs)
Unary multiply by scalar.
Definition Vec4ub:106
value_type & y()
Definition Vec4ub:78
bool operator==(const Vec4ub &v) const
Definition Vec4ub:51
bool operator!=(const Vec4ub &v) const
Definition Vec4ub:53
value_type a() const
Definition Vec4ub:95
value_type & b()
Definition Vec4ub:89
const value_type * ptr() const
Definition Vec4ub:67
value_type & x()
Definition Vec4ub:77
value_type y() const
Definition Vec4ub:83
Vec4ub operator*(float rhs) const
Multiply by scalar.
Definition Vec4ub:98
Vec4ub & operator+=(const Vec4ub &rhs)
Unary vector add.
Definition Vec4ub:141
value_type b() const
Definition Vec4ub:94
value_type w() const
Definition Vec4ub:85
Vec4ub & operator-=(const Vec4ub &rhs)
Unary vector subtract.
Definition Vec4ub:158
Vec4ub & operator/=(float rhs)
Unary divide by scalar.
Definition Vec4ub:124
value_type r() const
Definition Vec4ub:92
value_type & r()
Definition Vec4ub:87
value_type x() const
Definition Vec4ub:82
value_type * ptr()
Definition Vec4ub:66
Vec4ub()
Constructor that sets all components of the vector to zero.
Definition Vec4ub:41

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.